You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何设置Folium底图在LayerControl中默认取消勾选?

解决Folium底图LayerControl默认全勾选问题

要让添加的底图在LayerControl中默认处于未勾选状态,只需在调用add_to()方法时传入**show=False**参数即可,该参数用于控制图层初始加载时的显示状态。

代码示例

如果希望保留一个默认显示的底图(推荐,避免地图加载后空白),其余底图默认隐藏:

basemaps['Google Maps'].add_to(map)
basemaps['Google Satellite Hybrid'].add_to(map, show=False)
basemaps['Google Terrain'].add_to(map, show=False)
basemaps['Esri Satellite'].add_to(map, show=False)
folium.LayerControl().add_to(map)

如果需要所有底图默认都不显示(注意:此时地图初始加载会呈现空白状态):

basemaps['Google Maps'].add_to(map, show=False)
basemaps['Google Satellite Hybrid'].add_to(map, show=False)
basemaps['Google Terrain'].add_to(map, show=False)
basemaps['Esri Satellite'].add_to(map, show=False)
folium.LayerControl().add_to(map)

补充说明

  • 这些底图默认属于Base Layer组,在LayerControl中是单选模式,同一时间仅能激活一个底图。
  • 若需将底图设为可多选的Overlay图层,可额外传入overlay=True参数,但这不符合底图的常规使用场景。

内容的提问来源于stack exchange,提问作者Ridwan Nurzeha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 23:53:18