一、folium默认地图源
文中的folium版本为0.14.0
,官方文档中说明内置的地图源为:
默认情况下均为OpenStreetMap,不过由于网络原因OpenStreetMap加载有时会存在一定问题。此外,根据官方的源码,其中有一些类型的tiles
不支持使用keyword来直接添加。
if tiles_flat in {"cloudmade", "mapbox", "mapboxbright", "mapboxcontrolroom"}:
# added in May 2020 after v0.11.0, remove in a future release
raise ValueError(
"Built-in templates for Mapbox and Cloudmade have been removed. "
"You can still use these providers by passing a URL to the `tiles` "
"argument. See the documentation of the `TileLayer` class."
)
二、使用xyzservices.TileProvider切换地图源
官方文档中提供了一个免费的源:http://leaflet-extras.github.io/leaflet-providers/preview/,获取想要地图的tiles和attr。
或者通过https://xyzservices.readthedocs.io/en/latest/introduction.html,也能获取到。
folium使用TileLayer
则可添加栅格图层,即可完成不同类型底图的展示。
import webbrowser
import folium
my_map = folium.Map(location=[32, 113], tiles=None, zoom_start=4) # 默认地图中心点和缩放等级
layer = folium.TileLayer(
tiles='http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}',
attr='© <a href="http://www.gaode.com/">Gaode.com</a>',
min_zoom=0,
max_zoom=19,
name='test'
).add_to(my_map)
folium.LayerControl(position='bottomright', collapsed=False).add_to(my_map)
# 存储地图
my_map.save('test.html')
# 默认浏览器打开
webbrowser.open('test.html')