-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add duration to timestamped geo json #894
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
Add duration to timestamped geo json #894
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a straight forward addition! I haven't tested it, but it looks good. I have two comments, hope you can look at them.
If you have the time, you could add an example in the relevant Notebook.
One more thing is that the test_timestamped_geo_json
test is now failing. Can you take a look at it? You probably have to add your edit in there.
@@ -41,6 +41,10 @@ class TimestampedGeoJson(MacroElement): | |||
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, and'PT1M' -> 1/minute | |||
duration: str, default None | |||
Period of time which the features will be shown on the map after their time | |||
has passed. If null, all previous times will be shown. Format: ISO8601 Duration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null -> None
@@ -110,14 +114,14 @@ class TimestampedGeoJson(MacroElement): | |||
}) | |||
|
|||
var {{this.get_name()}} = L.timeDimension.layer.geoJson(geoJsonLayer, | |||
{updateTimeDimension: true,addlastPoint: {{'true' if this.add_last_point else 'false'}}} | |||
{updateTimeDimension: true,addlastPoint: {{'true' if this.add_last_point else 'false'}},duration: {{"\""+this.duration+"\"" if this.duration else 'undefined'}}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move the if-statement to the Python code? Where self.duration
is set. Makes it easier to read IMO. That way here you can just include it like duration: "{{ this.duration }}"}
@@ -133,6 +137,7 @@ def __init__(self, data, transition_time=200, loop=True, auto_play=True, add_las | |||
self.add_last_point = bool(add_last_point) | |||
self.period = period | |||
self.date_options = date_options | |||
self.duration = duration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then this could be self.duration = duration if duration is not None else 'undefined'
Thanks for the suggestions. The code, doc and test suite has been updated, and duration option has been added to existing example. |
* it contains only features of types LineString, MultiPoint, MultiLineString and MultiPolygon. | ||
* each feature has a 'times' property with the same length as the coordinates array. | ||
* each element of each 'times' property is a timestamp in ms since epoch, or in ISO string. | ||
* it contains only features of types LineString, MultiPoint, MultiLineString |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
* each element of each 'times' property is a timestamp in ms since epoch, or in ISO string. | ||
* it contains only features of types LineString, MultiPoint, MultiLineString | ||
and MultiPolygon. | ||
* each feature has a 'times' property with the same length as the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
and MultiPolygon. | ||
* each feature has a 'times' property with the same length as the | ||
coordinates array. | ||
* each element of each 'times' property is a timestamp in ms since epoch, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
|
||
Eventually, you may have Point features with a 'times' property being an array of length 1. | ||
Eventually, you may have Point features with a 'times' property being an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
|
||
Parameters | ||
---------- | ||
data: file, dict or str. | ||
The timestamped geo-json data you want to plot. | ||
* If file, then data will be read in the file and fully embedded in Leaflet's javascript. | ||
* If dict, then data will be converted to json and embedded in the javascript. | ||
* If file, then data will be read in the file and fully embedded in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
* If dict, then data will be converted to json and embedded in the javascript. | ||
* If file, then data will be read in the file and fully embedded in | ||
Leaflet's javascript. | ||
* If dict, then data will be converted to json and embedded in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
ex: 'P1M' -> 1/month, 'P1D' -> 1/day, 'PT1H' -> 1/hour, and'PT1M' -> 1/minute | ||
ex: 'P1M' 1/month, 'P1D' 1/day, 'PT1H' 1/hour, and 'PT1M' 1/minute | ||
duration: str, default None | ||
Period of time which the features will be shown on the map after their |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
ex: 'P1M' 1/month, 'P1D' 1/day, 'PT1H' 1/hour, and 'PT1M' 1/minute | ||
duration: str, default None | ||
Period of time which the features will be shown on the map after their | ||
time has passed. If None, all previous times will be shown. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
Merged. Thanks for your contribution @andy23512! |
Hello, I am getting the error message "TypeError: init() got an unexpected keyword argument 'duration' " when using the duration parameter. Are you able to help with this? I want the markers to only show for the associated timestamp but, at the minute, new markers are just getting added on top of old markers. Kirsten |
Hi @KirstenCrane8005, are you sure you got a recent version? Your error message suggests you don't have a recent version with this PR merged in it. You can check your current version with |
Hi, I spoke to @andy23512 and he helped me install the most recent development version. I had used pip to install so only had the latest released version 0.5.0. Thanks for your response! If anyone knows whether it is possible to pass a folium marker or folium icon such as BeautifyIcon to the 'icon' parameter under 'properties' when you're creating the geoJSON feature objects that would be a big help. I just get the error message folium marker not JSON serializable. Aim is to display a number on each marker, pulled from my pandas dataframe. |
Add duration option from L.timeDimension.layer.geoJson ( https://github.com/socib/Leaflet.TimeDimension/tree/520cb80f645112e242c5160cb44b7d5f2cae380d#options-3 ), in order to control the shown duration of feature.
Is there anything else I need to do?