diff --git a/folium/plugins/timeline.py b/folium/plugins/timeline.py new file mode 100644 index 000000000..b8b4cb8a8 --- /dev/null +++ b/folium/plugins/timeline.py @@ -0,0 +1,69 @@ +from branca.element import MacroElement +from jinja2 import Template + +from folium.elements import JSCSSMixin +from folium.utilities import parse_options + + +class Timeline(JSCSSMixin, MacroElement): + """ + TODO + """ + + _template = Template( + """ + {% macro script(this, kwargs) %} + var {{ this.get_name() }} = L.timeline( + {{ this.data|tojson }}, + {{ this.options|tojson }} + ); + {{ this._parent.get_name() }}.addControl({{ this.get_name() }}); + {{ this.get_name() }}.addTo({{ this._parent.get_name() }}); + {% endmacro %} + """ + ) + + default_js = [ + ( + "timeline", + "https://skeate.dev/Leaflet.timeline/examples/leaflet.timeline.js", + ) + ] + + def __init__(self, data, **kwargs): + super().__init__() + self._name = "Timeline" + + self.data = data + self.options = parse_options(**kwargs) + + +class TimelineSliderControl(JSCSSMixin, MacroElement): + """ + TODO + """ + + _template = Template( + """ + {% macro script(this, kwargs) %} + var {{ this.get_name() }} = L.timelineSliderControl( + {{ this.options|tojson }} + ); + {{ this.get_name() }}.addTimelines(); + {{ this.get_name() }}.addTo({{ this._parent.get_name() }}); + {% endmacro %} + """ + ) + + default_js = [ + ( + "timeline", + "https://skeate.dev/Leaflet.timeline/examples/leaflet.timeline.js", + ) + ] + + def __init__(self, data, **kwargs): + super().__init__() + self._name = "TimelineSliderControl" + + self.options = parse_options(**kwargs)