Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to organize groups in Layer Control #1712

Closed
JohnyCarrot opened this issue Jan 25, 2023 · 3 comments
Closed

How to organize groups in Layer Control #1712

JohnyCarrot opened this issue Jan 25, 2023 · 3 comments

Comments

@JohnyCarrot
Copy link

Greetings,

I have a polygons which are part of sub groups (FeatureGroupSubGroup) and these sub groups are part of Groups (FeatureGroup).

What i need is "listing" it like on this image:
grouping_folium
I need that my groups (shown as "Big group in image) will have sup groups shown like here and that i can either turn of / off whole group or turn off / on each sup group separatly even big groups are off for example. Currently, i have no idea how to do it.

Here is my code :

    chranene_oblasti = folium.FeatureGroup("Chránené oblasti",control=False)
    druhy_stupen = folium.plugins.FeatureGroupSubGroup(chranene_oblasti,name="II. stupeň ochrany")
    treti_stupen = folium.plugins.FeatureGroupSubGroup(chranene_oblasti, name='III. stupeň ochrany')
    stvrty_stupen = folium.plugins.FeatureGroupSubGroup(chranene_oblasti, name="IV. stupeň ochrany")
    piaty_stupen = folium.plugins.FeatureGroupSubGroup(chranene_oblasti, name="V. stupeň ochrany")
    m.add_child(chranene_oblasti)
    m.add_child(druhy_stupen)
    m.add_child(treti_stupen)
    m.add_child(stvrty_stupen)
    m.add_child(piaty_stupen)

Problem description

Problem with this code is that it will just add Feature group (big group) as normal "object" in Layer control and it will either turn it off / on, as individual sub groups (which are not shown like on image above, but on the same level) cant be controlled then.

Expected Output

grouping_folium

Output of folium.__version__

'0.14.0'

@IndigoWizard
Copy link

@JohnyCarrot
At the current moment there's no such way of having a sort of hierarchy display of layers on the layer panel. A recent addition to folium since version 0.14.0 was the GroupedLayerControl #1592 which allows to spawn a separate layer panel (on top/bottom of the main panel) and can contain multiple layers under a group title (just text, no actual hierarchy group layer control).

Link to official folium documentaion notebook example: GroupedLayerControl

image

Flaws

  • It can't add raster layers to the groups (e.g: "gee" google earth engine layers) as far as I tried.
  • If you want one "main big group" to control all sub groups it must be in the main layer panel (do add_to(m) instead of the plugin).
  • If you want Main Sub Group control of all layers in that subgroup, it needs to be the last one stacked in it's layer group (see image 2. "All Group A" / "All Group B" )
    image

NOTE:

The styling is not included in the plugin or folium. I done it to better illustrate and clarify the context.
You still can use Branca + CSS to tweak the style if wanted.

@JohnyCarrot
Copy link
Author

Thanks you so much...

This is it, even if i cant control sub groups, its not that big deal.

Love you

@zxdawn
Copy link

zxdawn commented Sep 14, 2023

Ha, it would be nice to have big groups to turn on/off all subgroups inside and each subgroup can be controlled independently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants