Skip to content

Add period in plugins.timestamped_geojson #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2016
Merged
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
14 changes: 11 additions & 3 deletions folium/plugins/timestamped_geo_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
from folium.utilities import none_min, none_max, iter_points

class TimestampedGeoJson(MacroElement):
def __init__(self, data, transition_time=200, loop=True, auto_play=True):
def __init__(self, data, transition_time=200, loop=True, auto_play=True,
period="P1D"):
"""Creates a TimestampedGeoJson plugin to append into a map with
Map.add_children.

Expand Down Expand Up @@ -80,7 +81,13 @@ def __init__(self, data, transition_time=200, loop=True, auto_play=True):
Whether the animation shall loop.
auto_play : bool, default True
Whether the animation shall start automatically at startup.

period : str, default "P1D"
Used to construct the array of available times starting
from the first available time. Format: ISO8601 Duration
ex: "P1M" -> 1/month
"P1D" -> 1/day
"PT1H" -> 1/hour
"PT1M" -> 1/minute
"""
super(TimestampedGeoJson, self).__init__()
self._name = 'TimestampedGeoJson'
Expand All @@ -98,10 +105,11 @@ def __init__(self, data, transition_time=200, loop=True, auto_play=True):
self.transition_time = int(transition_time)
self.loop = bool(loop)
self.auto_play = bool(auto_play)
self.period = period

self._template = Template("""
{% macro script(this, kwargs) %}
{{this._parent.get_name()}}.timeDimension = L.timeDimension();
{{this._parent.get_name()}}.timeDimension = L.timeDimension({period:"{{this.period}}"});
{{this._parent.get_name()}}.timeDimensionControl = L.control.timeDimension({
position: 'bottomleft',
autoPlay: {{'true' if this.auto_play else 'false'}},
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/test_timestamped_geo_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_timestamped_geo_json():

# Verify that the script is okay.
tmpl = Template("""
{{this._parent.get_name()}}.timeDimension = L.timeDimension();
{{this._parent.get_name()}}.timeDimension = L.timeDimension({period:"{{this.period}}"});
{{this._parent.get_name()}}.timeDimensionControl = L.control.timeDimension({
position: 'bottomleft',
autoPlay: {{'true' if this.auto_play else 'false'}},
Expand Down