python - Folium,切换图层时使图例消失(LayerControl)
问题描述
我在这个答案中使用 InLaw(1) 的 html 示例创建了一些图例。从那个答案中,我还设法使用来自 Branca (2) 的 MacroElement获得了这个图例,其中 template 是一个 html 宏模板。我想要的是(任何)这些图例根据 LayerControl 从地图中出现和消失。
(1) map.get_root().html.add_child(folium.Element( legend_html ))
(2) macro = MacroElement()
macro._template = Template(template)
m.get_root().add_child(macro)
我尝试了什么?我尝试将 html 和 MacroElement 添加到 FeatureLayer 或 Choropleth 地图,但无济于事。在网上潜伏了一段时间后,我发现了这个使用 java 脚本的示例(我猜,我对 JS 有 -0 经验)使栏不可见。但是,当我将 LinearColormap 替换为上述任何内容时,图例并没有消失。例如,使用macro
(2) 中的变量,我尝试了这个:
m.add_child(BindColormap(FeatureGroup, macro))
m.add_child(BindColormap(Choropleth, macro))
为简单起见,为该示例命名的变量的名称在哪里FeatureGroup
和是这样命名的。Choropleth
我不知道我还能做什么。
解决方案
推荐阅读
- python - 在循环中解析嵌套的 json 数据
- sql - 仅选择一行,按值字段,排序
- python-3.x - 防止 if、elif、else 链(检查输入)
- python - dbsf 中的数据砖写入 xlsx(数据砖文件系统)
- python - 在 Python 中的单个图表中绘制来自不同数据帧的行
- vb.net - 如何捕捉应用程序崩溃/不正常退出?
- powerapps - 计算在 PowerApps 中输入的每个数量的总金额
- excel - 将系统从 Windows8 32 位更新到 Windows10 64 位后 Excel 宏不起作用
- python - 为什么pygame不显示创建的屏幕?
- typescript - ESLint 说即使在添加分号后也缺少分号