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