jjimenezshaw / Leaflet.Control.Layers.Tree

a Tree Layers Control for Leaflet
https://jjimenezshaw.github.io/Leaflet.Control.Layers.Tree/examples/basic.html
BSD 3-Clause "New" or "Revised" License
146 stars 36 forks source link

Getting layer states and switching layer states by js #54

Open wambacher opened 3 years ago

wambacher commented 3 years ago

Hi,

my old application used to save the layer tree state (which layers are selected, which submenues have been opened or closed, which children are open, the complete tree layout) using cookies or localStorage. This happens when the user is closing the page (something like "$(window).on("unload", function(e){ .. save tree state });") and the next time the tree will be opened like before.

You may check the old project https://wambachers-osm.website/Emergency.html to see, what i'm talking about. (Only data for Germany, Austria and Switzerland)

Tracking, which base layer or overlay layer is changing, is quite simple using map.on(baselayerchange) or map.on (overlayadd, overlayremove), but i need the full state of the tree.

Is there any way to do this using Leaflet.Control.Layers.Tree?

Regards walter

jjimenezshaw commented 2 years ago

What is selected in the tree is consistent with the map. If you add a baselayer (that is in the tree) to the map, it will appear marked in the tree. The same for the overlays. If you care about how the tree is expanded when you create it, there is a method that may help you:expandSelected