From 0f9d91d83937e36ef49e1d5a7f51726b7e843fce Mon Sep 17 00:00:00 2001 From: Goheer <145010056+xecanto@users.noreply.github.com> Date: Sat, 17 Oct 2026 16:28:42 +0500 Subject: [PATCH] Show pre-1970 features in TimestampedGeoJson Without a duration, Leaflet.TimeDimension uses 0 as the lower bound when it filters features, so a feature whose times are all before 1970 is never drawn. Use -Infinity instead when there is no duration. --- folium/plugins/timestamped_geo_json.py | 13 ++++++++++++- tests/plugins/test_timestamped_geo_json.py | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) 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