From ce01ee88b6da508794b46af9dcb5d0823ade201a Mon Sep 17 00:00:00 2001 From: Volodymyr Borysenko Date: Sun, 29 Nov 2026 03:40:44 -0800 Subject: [PATCH] Only restyle own paths in TimeSliderChoropleth The overlay add handler selected every path on the page and reset its stroke and fill opacity. Other GeoJson layers on the same map lost their style and the Leaflet attribution flag went blank. Select only the paths that belong to this layer. --- folium/plugins/time_slider_choropleth.py | 2 +- tests/plugins/test_time_slider_choropleth.py | 31 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/folium/plugins/time_slider_choropleth.py b/folium/plugins/time_slider_choropleth.py index fa2a1ac221..d063434c17 100644 --- a/folium/plugins/time_slider_choropleth.py +++ b/folium/plugins/time_slider_choropleth.py @@ -147,7 +147,7 @@ class TimeSliderChoropleth(JSCSSMixin, Layer): $("#slider_{{ this.get_name() }}").show(); - d3.selectAll('path') + d3.selectAll('path[id^="{{ this.get_name() }}-feature-"]') .attr('stroke', '{{ this.stroke_color }}') .attr('stroke-width', {{ this.stroke_width }}) .attr('stroke-dasharray', '5,5') diff --git a/tests/plugins/test_time_slider_choropleth.py b/tests/plugins/test_time_slider_choropleth.py index cd03797d14..4a07e02995 100644 --- a/tests/plugins/test_time_slider_choropleth.py +++ b/tests/plugins/test_time_slider_choropleth.py @@ -120,3 +120,34 @@ def test_slider_overlays_map(): rendered = plugin._template.module.script(plugin) assert '.style("position", "absolute")' in rendered + + +def test_stroke_style_only_targets_own_features(): + # the stroke and fill reset must not restyle paths of other layers + geojson = json.dumps( + { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "id": "0", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], + }, + } + ], + } + ) + styledict = {"0": {"1420070400": {"color": "#ff0000", "opacity": 0.5}}} + + m = folium.Map((0, 0), zoom_start=2) + folium.GeoJson(geojson, name="other").add_to(m) + plugin = TimeSliderChoropleth(geojson, styledict) + plugin.add_to(m) + rendered = plugin._template.module.script(plugin) + + assert "d3.selectAll('path')" not in rendered + selector = f"d3.selectAll('path[id^=\"{plugin.get_name()}-feature-\"]')" + assert selector in rendered