diff --git a/folium/plugins/timestamped_geo_json.py b/folium/plugins/timestamped_geo_json.py index 11d1deae63..11023bfca1 100644 --- a/folium/plugins/timestamped_geo_json.py +++ b/folium/plugins/timestamped_geo_json.py @@ -138,7 +138,18 @@ class TimestampedGeoJson(JSCSSMixin, MacroElement): addlastPoint: {{ this.add_last_point|tojson }}, duration: {{ this.duration }}, } - ).addTo({{this._parent.get_name()}}); + ); + // Without a duration Leaflet.TimeDimension starts at time 0, which + // hides features whose times are all before 1970. + {{this.get_name()}}._getFeatureBetweenDates = function(feature, minTime, maxTime) { + if (!this._duration) { + minTime = -Infinity; + } + return L.TimeDimension.Layer.GeoJson.prototype._getFeatureBetweenDates.call( + this, feature, minTime, maxTime + ); + }; + {{this.get_name()}}.addTo({{this._parent.get_name()}}); {% endmacro %} """) # noqa diff --git a/tests/plugins/test_timestamped_geo_json.py b/tests/plugins/test_timestamped_geo_json.py index 24ee9a12dc..dbe4199be0 100644 --- a/tests/plugins/test_timestamped_geo_json.py +++ b/tests/plugins/test_timestamped_geo_json.py @@ -190,7 +190,18 @@ def test_timestamped_geo_json(): addlastPoint: {{ this.add_last_point|tojson }}, duration: {{ this.duration }}, } - ).addTo({{this._parent.get_name()}}); + ); + // Without a duration Leaflet.TimeDimension starts at time 0, which + // hides features whose times are all before 1970. + {{this.get_name()}}._getFeatureBetweenDates = function(feature, minTime, maxTime) { + if (!this._duration) { + minTime = -Infinity; + } + return L.TimeDimension.Layer.GeoJson.prototype._getFeatureBetweenDates.call( + this, feature, minTime, maxTime + ); + }; + {{this.get_name()}}.addTo({{this._parent.get_name()}}); """) # noqa expected = normalize(tmpl.render(this=tgj)) assert expected in out