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

Getting layer states and switching layer states by js #54

Open
wambacher opened this issue Jul 24, 2021 · 1 comment
Open

Getting layer states and switching layer states by js #54

wambacher opened this issue Jul 24, 2021 · 1 comment

Comments

@wambacher
Copy link

wambacher commented Jul 24, 2021

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
Copy link
Owner

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

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

2 participants