Skip to content

Commit 73c31e6

Browse files
committed
Merge pull request #326 from BibMartin/timestamped_geojson
Add period in plugins.timestamped_geojson
2 parents 9d49f26 + 74fe76a commit 73c31e6

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

folium/plugins/timestamped_geo_json.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
from folium.utilities import none_min, none_max, iter_points
2727

2828
class TimestampedGeoJson(MacroElement):
29-
def __init__(self, data, transition_time=200, loop=True, auto_play=True):
29+
def __init__(self, data, transition_time=200, loop=True, auto_play=True,
30+
period="P1D"):
3031
"""Creates a TimestampedGeoJson plugin to append into a map with
3132
Map.add_children.
3233
@@ -80,7 +81,13 @@ def __init__(self, data, transition_time=200, loop=True, auto_play=True):
8081
Whether the animation shall loop.
8182
auto_play : bool, default True
8283
Whether the animation shall start automatically at startup.
83-
84+
period : str, default "P1D"
85+
Used to construct the array of available times starting
86+
from the first available time. Format: ISO8601 Duration
87+
ex: "P1M" -> 1/month
88+
"P1D" -> 1/day
89+
"PT1H" -> 1/hour
90+
"PT1M" -> 1/minute
8491
"""
8592
super(TimestampedGeoJson, self).__init__()
8693
self._name = 'TimestampedGeoJson'
@@ -98,10 +105,11 @@ def __init__(self, data, transition_time=200, loop=True, auto_play=True):
98105
self.transition_time = int(transition_time)
99106
self.loop = bool(loop)
100107
self.auto_play = bool(auto_play)
108+
self.period = period
101109

102110
self._template = Template("""
103111
{% macro script(this, kwargs) %}
104-
{{this._parent.get_name()}}.timeDimension = L.timeDimension();
112+
{{this._parent.get_name()}}.timeDimension = L.timeDimension({period:"{{this.period}}"});
105113
{{this._parent.get_name()}}.timeDimensionControl = L.control.timeDimension({
106114
position: 'bottomleft',
107115
autoPlay: {{'true' if this.auto_play else 'false'}},

tests/plugins/test_timestamped_geo_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def test_timestamped_geo_json():
111111

112112
# Verify that the script is okay.
113113
tmpl = Template("""
114-
{{this._parent.get_name()}}.timeDimension = L.timeDimension();
114+
{{this._parent.get_name()}}.timeDimension = L.timeDimension({period:"{{this.period}}"});
115115
{{this._parent.get_name()}}.timeDimensionControl = L.control.timeDimension({
116116
position: 'bottomleft',
117117
autoPlay: {{'true' if this.auto_play else 'false'}},

0 commit comments

Comments
 (0)