Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions folium/plugins/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,7 +95,6 @@ class Timeline(GeoJson):
{{ this.data|tojson }},
{{ this.get_name() }}_options
);
{{ this.get_name() }}.addTo({{ this._parent.get_name() }});
{% endmacro %}
""")

Expand All @@ -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:
Expand Down
26 changes: 26 additions & 0 deletions tests/plugins/test_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]