Skip to content

LayerControl: optional persistence of layer selection in localStorage - #2332

Open
DresdenGman wants to merge 1 commit into
python-visualization:mainfrom
DresdenGman:fix-1636-layer-control-local-storage
Open

DresdenGman wants to merge 1 commit into
python-visualization:mainfrom
DresdenGman:fix-1636-layer-control-local-storage

Conversation

@DresdenGman

Copy link
Copy Markdown

Implements the request in #1636 in an opt-in form.

LayerControl gains a use_local_storage option (default False). It is a folium-side option, in the same style as draggable, and is not passed through to the Leaflet control. When enabled, the rendered map includes a small script that stores the selected base layer and active overlays in localStorage, keyed by layer name and page path, restores them on load, and updates the stored state on baselayerchange, overlayadd, and overlayremove. With the option off — the default — the rendered output is unchanged.

I saw in the #1636 discussion that there was some hesitation about whether this belongs in folium itself, so I kept it strictly opt-in and self-contained. Happy to adjust the shape, or to close this if you would rather it live outside core.

Notes and limits:

  • Layers are keyed by name, so two layers with the same name are not distinguished.
  • The JavaScript is covered by rendering tests rather than a browser test, as my environment has no selenium stack. Test suite: 397 passed against a baseline of 395, with the same 4 pre-existing failures as the baseline (3 selenium import errors and 1 time_slider failure).

Save the user's layer control choices (the active base layer and the
visible overlays) to the browser's local storage and restore them when
the page is loaded again, so the choices survive a refresh. Opt-in,
defaults to off and renders nothing extra when disabled.

Fixes python-visualization#1636

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant