folium icon indicating copy to clipboard operation
folium copied to clipboard

User guide `LayerControl` example (controlling `TileLayer`) doesn't work

Open elliot-100 opened this issue 9 months ago • 0 comments

Describe the bug At https://python-visualization.github.io/folium/latest/user_guide/ui_elements/layer_control.html, the text says 'add a control to the map to show or hide layers'. But the demo (or local HTML produced by equivalent code on my machine) seems to have incorrect code, which adds the control but has no effect on the TileLayer.

To Reproduce / Expected behavior

  • View demo at https://python-visualization.github.io/folium/latest/user_guide/ui_elements/layer_control.html
  • Initially the 'openstreetmap' control isn't selected (as expected), but OpenStreet map tiles are visible (expected not visible)
  • The 'openstreetmap' control can be selected with no effect, but not deselected.

Environment (please complete the following information):

  • Browser: Chrome or Edge
  • Jupyter Notebook or html files? User guide uses Notebook; local env: HTML
  • Python version: local env: sys.version_info(major=3, minor=12, micro=5, releaselevel='final', serial=0)
  • folium version: local env: 0.19.4
  • branca version: local env 0.8.1

Additional context/Possible solutions If I change this in my local env:

folium.TileLayer("OpenStreetMap").add_to(m)
folium.TileLayer(show=False).add_to(m)

To:

folium.TileLayer("OpenStreetMap", show=False).add_to(m)

This partially fixes the problem - the OpenStreet map tiles are not initially visible, and the 'openstreetmap' control can be selected to make them visible, however the control cannot be deselected and so the tiles cannot be hidden again.

[Edit: I have only encountered this with a TileLayer - no issues controlling a FeatureGroup with a LayerControl]

folium is maintained by volunteers. Can you help making a fix for this issue? Maybe, depending on complex the docs setup is; need to understand root issue first.

elliot-100 avatar Feb 18 '25 11:02 elliot-100