我正在尝试使用Python中的“folium”库创建一个html文件,然后使用“Mapillary”api应用覆盖图块,但在应用该层时它没有显示。
这是我的代码:
生成 html:
`def create_map(): my_map = folium.Map(location=[50, 0], Zoom_start=8)
vector_tile_url = "https://tiles.mapillary.com/maps/vtp/mly1_public/{z}/{x}/{y}?access_token=" + os.getenv(
"MAPILLARY_API_KEY")
attribution = "Map data © <a href='https://mapillary.com'>Mapillary</a> contributors"
folium.TileLayer(vector_tile_url, name="mapillary", attr=attribution, overlay=True).add_to(my_map)
folium.LayerControl().add_to(my_map)
my_map.save("map_with_vector_tiles.html")
print("Map with vector tiles saved as map_with_vector_tiles.html")`
似乎 Mapillary 使用了协议缓冲区。所以,也许您需要一个
VectorGridProtobuf
?
import os
import folium
m = folium.Map(location=[0,0], zoom_start=2, width="80%", height="70%")
url = (
"https://tiles.mapillary.com/maps/vtp/"
"mly1_public/2/{z}/{x}/{y}?access_token={token}"
)
options = {
"token": os.getenv("MAPILLARY_API_KEY"),
"vectorTileLayerStyles": {
"overview": {
"fill": True,
"radius": 5,
"color": "#e87147",
"opacity": 0.6,
},
},
}
pbf = folium.plugins.VectorGridProtobuf(url, "mapillary", options)
pbf.__dict__["overlay"] = True # otherwise, TypeError
pbf.add_to(m)
folium.LayerControl().add_to(m)
NB:随意添加另外两个图层的样式:序列和图像。
输出(
m
,在 Jupyter):