Skip to content

Pass layer options through in Timeline - #2375

Open
VolodymyrLinuxovich wants to merge 1 commit into
python-visualization:mainfrom
VolodymyrLinuxovich:timeline-layer-options
Open

VolodymyrLinuxovich wants to merge 1 commit into
python-visualization:mainfrom
VolodymyrLinuxovich:timeline-layer-options

Conversation

@VolodymyrLinuxovich

Copy link
Copy Markdown

Timeline subclasses GeoJson, but it calls super().__init__(data) without the layer arguments. So name, show, control and overlay end up in **kwargs and are written into the L.timeline options instead.

m = folium.Map()
t = plugins.Timeline(data, name="Quakes", show=False, control=False).add_to(m)
folium.LayerControl().add_to(m)

On main, t.layer_name is macro_element_... rather than "Quakes", "name": "Quakes" shows up in the JS options, and the layer still appears in the LayerControl. The template also calls .addTo(parent) itself. That means show=False can never work, and a shown layer is added twice, once by the template and once by Layer.render.

This passes the four layer arguments to GeoJson and drops the hardcoded .addTo, so Layer.render adds the layer only when show=True. The docstring gets the same parameter text as GeoJson.

test_timeline_layer_options checks the layer name, that no name leaks into the options, that a hidden layer is not added, that a shown one is added once, and that control=False keeps a layer out of the LayerControl. It fails on main and passes here. The plugin tests pass and pre-commit is clean.

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