From 974706bb1247bd71a1be5b54916f0d6814b62902 Mon Sep 17 00:00:00 2001 From: Volodymyr Borysenko Date: Sat, 21 Nov 2026 03:23:46 -0800 Subject: [PATCH] Pass layer options through in Timeline --- folium/plugins/timeline.py | 16 ++++++++++++++-- tests/plugins/test_timeline.py | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/folium/plugins/timeline.py b/folium/plugins/timeline.py index a48ca36e56..69bf840ea2 100644 --- a/folium/plugins/timeline.py +++ b/folium/plugins/timeline.py @@ -42,6 +42,15 @@ class Timeline(GeoJson): If `get_interval` is not provided, 'start' and 'end' properties are assumed to be present on each feature. + name : string, default None + The name of the Layer, as it will appear in LayerControls. + overlay : bool, default True + Adds the layer as an optional overlay (True) or the base layer (False). + control : bool, default True + Whether the Layer will be included in LayerControls. + show: bool, default True + Whether the layer will be shown on opening. + Examples -------- >>> from folium.plugins import Timeline, TimelineSlider @@ -86,7 +95,6 @@ class Timeline(GeoJson): {{ this.data|tojson }}, {{ this.get_name() }}_options ); - {{ this.get_name() }}.addTo({{ this._parent.get_name() }}); {% endmacro %} """) @@ -105,9 +113,13 @@ def __init__( self, data: dict | str | TextIO, get_interval: JsCode | None = None, + name: str | None = None, + overlay: bool = True, + control: bool = True, + show: bool = True, **kwargs, ): - super().__init__(data) + super().__init__(data, name=name, overlay=overlay, control=control, show=show) self._name = "Timeline" if get_interval is not None: diff --git a/tests/plugins/test_timeline.py b/tests/plugins/test_timeline.py index a511946f97..ebdfced0be 100644 --- a/tests/plugins/test_timeline.py +++ b/tests/plugins/test_timeline.py @@ -79,3 +79,29 @@ def test_timeline(): """) # noqa expected = normalize(tmpl.render(this=slider)) assert expected in out + + +def test_timeline_layer_options(): + m = folium.Map() + data = { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {"start": 1, "end": 2}, + "geometry": {"type": "Point", "coordinates": [0, 0]}, + } + ], + } + hidden = plugins.Timeline(data, name="Hidden", show=False).add_to(m) + shown = plugins.Timeline(data, name="Shown").add_to(m) + plugins.Timeline(data, name="Not in control", control=False).add_to(m) + layer_control = folium.LayerControl().add_to(m) + + out = normalize(m._parent.render()) + + assert hidden.layer_name == "Hidden" + assert '"name"' not in out + assert f"{hidden.get_name()}.addTo(" not in out + assert out.count(f"{shown.get_name()}.addTo(") == 1 + assert list(layer_control.overlays) == ["Hidden", "Shown"]