简体   繁体   English

Python folium - Markercluster 不可使用 GroupedLayerControl 迭代

[英]Python folium - Markercluster not iterable with GroupedLayerControl

I would like to group my 2 marker cluster layers, where one is reliant on the other by providing a separate styling.我想将我的 2 个标记簇层分组,其中一个通过提供单独的样式依赖于另一个。 Hence the second one is set as control=False.因此第二个设置为 control=False。 Nevertheless, I want to have it disappear when the first one is switched off.不过,我想让它在第一个关闭时消失。

Along with the new Python folium issue v.0.14 I found, that the new feature has been provided, which potentially could resolve my issue:除了我发现的新 Python folium issue v.0.14 之外,还提供了新功能,这可能会解决我的问题:

https://github.com/ikoojoshi/Folium-GroupedLayerControl https://github.com/ikoojoshi/Folium-GroupedLayerControl

Allow only one layer at a time in Folium LayerControl 在 Folium LayerControl 中一次只允许一层

and I've applied the following code:我应用了以下代码:

df = pd.read_csv("or_geo.csv")
fo=FeatureGroup(name="OR")
or_cluster = MarkerCluster(name="Or", overlay=True, visible=True).add_to(map)

or_status = MarkerCluster(overlay=True,
                            control=False,
                             visible=False,
                             disableClusteringAtZoom=16,
                             ).add_to(map)

 GroupedLayerControl(
 groups={'OrB': or_cluster, 'OrC': or_status},
 collapsed=False,
 ).add_to(map)

and the console throws the following error:并且控制台抛出以下错误:

TypeError: 'MarkerCluster' object is not iterable TypeError: 'MarkerCluster' object 不可迭代

How could I switch off 2 layer groups at once?我怎样才能一次关闭 2 个图层组?

在此处输入图像描述

UPDATE:更新:

The answer below provides the code, which seems to work but not in the way I need.下面的答案提供了代码,它似乎可以工作但不是我需要的方式。

df = pd.read_csv("or_geo.csv")
fo=FeatureGroup(name="Or",overlay = True)
or_cluster = MarkerCluster(name="Or").add_to(map)

or_status = MarkerCluster(control=False,
                             visible=True,
                             disableClusteringAtZoom=16,
                             ).add_to(map)

# definition of or_marker
# definition of or_stat_marker

or_cluster.add_child(or_marker)
or_status.add_child(or_stat_marker)

GroupedLayerControl(
groups={"Or": [or_cluster, or_status]},
collapsed=False,
exclusive_group=False,
    ).add_to(map)

在此处输入图像描述

I have a separate box instead, but what is worst I can just switch between one layer and another whereas I would like to have them reliant on the main group.我有一个单独的盒子,但最糟糕的是我只能在一层和另一层之间切换,而我想让它们依赖于主要组。 The exclusive_groups option allows me to untick both of them but I am looking for something, which would allow me to switch off two of them at once (place the thick box on the major group instead). exclusive_groups 选项允许我取消选中它们,但我正在寻找可以让我一次关闭其中两个的东西(将粗框放在主要组上)。 Is it possible to have something like this?有可能有这样的东西吗?

Try passing your markerclusters as a list to the GroupedLayerControl, not one by one.尝试将您的标记簇作为列表传递给 GroupedLayerControl,而不是一个一个地传递。 This is described here: https://nbviewer.org/github/chansooligans/folium/blob/plugins-groupedlayercontrol/examples/plugin-GroupedLayerControl.ipynb这在这里描述: https://nbviewer.org/github/chansooligans/folium/blob/plugins-groupedlayercontrol/examples/plugin-GroupedLayerControl.ipynb

 GroupedLayerControl(
 groups={'OrB': [or_cluster, or_status]},
 collapsed=False,
 ).add_to(map)

Update I更新我

I see what you mean, that was definitely nonsense as it splits groups instead of joining them.我明白你的意思,这绝对是胡说八道,因为它分裂了小组而不是加入小组。 so, back to topic那么,回到主题

We had a similar discussion here and I am still convinced that the FeatureSubGroup should solve this issue.我们在这里进行了类似的讨论,我仍然相信FeatureSubGroup应该可以解决这个问题。 I use it in exact that way that I enable/disable a MarkerCluster in the legend and multiple FeatureGroupSubGroups (which are added not to the map but to the MarkerCluster) appear/disappear.我使用它的方式与我启用/禁用图例中的 MarkerCluster 和多个 FeatureGroupSubGroup(不是添加到 map,而是添加到 MarkerCluster)出现/消失的方式完全相同。 Perhaps you try that again也许你再试一次

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM