Skip to content

How to organize groups in Layer Control #1712

Closed

Description

@JohnyCarrot

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'

Activity

  1. IndigoWizard commented on Jan 27, 2023

    @IndigoWizard

    @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.

  2. JohnyCarrot commented on Jan 29, 2023

    @JohnyCarrot
    Author

    Thanks you so much...

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

    Love you

  3. zxdawn commented on Sep 14, 2023

    @zxdawn

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions