我正在使用Leaflet.VectorGrid插件加载pbf矢量瓦片到一个小叶地图上。我检索向量tiles的API需要传递一个authorization头。在Mapbox GL js中,这可以通过使用transformRequest选项来解决。示例:
var baseLayer = L.mapboxGL({
accessToken: token,
style: 'myStyle',
transformRequest: (url, resourceType)=> {
if(resourceType == 'Tile' && url.startsWith(TILE_SERVER_HOST)) {
return {
url: url,
headers: { 'Authorization': 'Basic ' + key }
};
}
}
}).addTo(leafletMap);我如何在Leaflet中做类似的事情,以绕过我收到的401授权消息?
对于插件中的引用向量层构造函数:
var vectorTileOptions = {
rendererFactory: L.canvas.tile
};
var pbfLayer = L.vectorGrid.protobuf(vectorTileUrl, VectorTileOptions).addTo(leafletMap);发布于 2020-08-27 18:40:40
这个Github issue https://github.com/Leaflet/Leaflet.VectorGrid/issues/89描述了一个fetchOptions属性,您可以在实例化您的层时传递该属性,该属性将用作fetch options to retrieve the tiles。
你应该能够做到
var vectorTileOptions = {
rendererFactory: L.canvas.tile,
fetchOptions: {
headers: {
Authorization: 'Basic ' + key
}
}
};
var pbfLayer = L.vectorGrid.protobuf(vectorTileUrl, VectorTileOptions).addTo(leafletMap);https://stackoverflow.com/questions/63613788
复制相似问题