Skip to content

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

Conversation

andy23512
Copy link
Contributor

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?

Copy link
Member

@Conengmo Conengmo left a 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
Copy link
Member

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'}}}
Copy link
Member

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
Copy link
Member

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'

@andy23512
Copy link
Contributor Author

andy23512 commented Jun 24, 2018

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

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

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,

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

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

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

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

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W291 trailing whitespace

@Conengmo Conengmo merged commit b65e002 into python-visualization:master Jun 24, 2018
@Conengmo
Copy link
Member

Merged. Thanks for your contribution @andy23512!

@kncrane
Copy link

kncrane commented Jul 9, 2018

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

@Conengmo
Copy link
Member

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 print(folium.__version__). You should install folium from the git master branch.

@kncrane
Copy link

kncrane commented Jul 10, 2018

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.

@andy23512 andy23512 deleted the add_duration_to_timestamped_geo_json branch July 19, 2018 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants