My data is made up of squares forming a grid where the value of each square changes with time. The times are equally spaced with 1 hour intervals, however, the data is only available for a certain number of hours each day (daylight). The data covers 365 days of a year and the time is stored with each feature (perhaps an inefficient way to store the time data).

I have already managed to show the animation for the first day (linked question). However, when loading data for 2 days, the first day plays well but the player doesn't stop at the end of the data for that particular day and keeps incrementing the time where there is no data.

I have tried to use TimeDimension timeDimensionOptions: times but with lack of usage examples, I fear that I got the syntax wrong. Here is the JavaScript code.

What would be the way to visualize my data with non-contiguous times using Leaflet TimeDimension?


Solution is actually quite simple. When creating time dimension layer with L.timeDimension.layer.geoJson method, just set updateTimeDimensionMode option to 'replace':

var timeSeriesLayer = L.geoJSON(timeSeriesGeoJSON, {style: style});
var geojson = L.timeDimension.layer.geoJson(timeSeriesLayer, {updateTimeDimensionMode: 'replace'});

Default value for this option is 'extremes', which means you get all the interval times between min and max time.

  • This solution did actually work, however, the problem is with the QGIS GeoJSON export. My data is in a PostGIS database and when exported with QGIS, the order of date is messed up which creates a problem with visualising with TimeDimension. I tried to set the data in order on a small subset and it worked, however, it is not practical for all my data. Right now, I'm trying to export right from PostGIS, but this is creating another issue with blank intervals. – Techie_Gus Apr 14 '19 at 18:38
  • Why don't you sort GeoJSON then? – TomazicM Apr 14 '19 at 19:05
  • Any suggestions how I can sort the GeoJSON data by time? – Techie_Gus Apr 14 '19 at 20:35
  • This QA could be helpful: gis.stackexchange.com/questions/68369/… (it took one internet search). – TomazicM Apr 15 '19 at 5:32
  • I saw that post but was wondering whether to sort on load or process the file before loading, knowing I have a very large dataset. As a side note, my Javascript skills are quite limited. – Techie_Gus Apr 15 '19 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.