Skip to content

Commit 16a300e

Browse files
authored
Fix for TimeSliderChoropleth control breaking when layer turned off and on (#1380)
* Fix for TimeSliderChoropleth control breaking when layer turned off and on * Removed whitespace, to satisfy stickler linter * Refactored code by calling onOverlayAdd instead of repetition * peksy whitespace again
1 parent b70efc6 commit 16a300e

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

folium/plugins/time_slider_choropleth.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class TimeSliderChoropleth(Layer):
3636
"""
3737
_template = Template(u"""
3838
{% macro script(this, kwargs) %}
39-
4039
var timestamps = {{ this.timestamps|tojson }};
4140
var styledict = {{ this.styledict|tojson }};
4241
var current_timestamp = timestamps[0];
@@ -80,9 +79,9 @@ class TimeSliderChoropleth(Layer):
8079
8180
d3.select("#slider").on("input", function() {
8281
current_timestamp = timestamps[this.value];
83-
var datestring = new Date(parseInt(current_timestamp)*1000).toDateString();
84-
d3.select("output#slider-value").text(datestring);
85-
fill_map();
82+
var datestring = new Date(parseInt(current_timestamp)*1000).toDateString();
83+
d3.select("output#slider-value").text(datestring);
84+
fill_map();
8685
});
8786
8887
{% if this.highlight %}
@@ -104,7 +103,6 @@ class TimeSliderChoropleth(Layer):
104103
}
105104
});
106105
};
107-
108106
{% endif %}
109107
110108
var {{ this.get_name() }} = L.geoJson(
@@ -120,17 +118,22 @@ class TimeSliderChoropleth(Layer):
120118
}
121119
});
122120
123-
{{ this.get_name() }}.eachLayer(function (layer) {
124-
layer._path.id = 'feature-' + layer.feature.id;
125-
});
121+
function onOverlayAdd(e) {
122+
{{ this.get_name() }}.eachLayer(function (layer) {
123+
layer._path.id = 'feature-' + layer.feature.id;
124+
});
125+
126+
d3.selectAll('path')
127+
.attr('stroke', 'white')
128+
.attr('stroke-width', 0.8)
129+
.attr('stroke-dasharray', '5,5')
130+
.attr('fill-opacity', 0);
126131
127-
d3.selectAll('path')
128-
.attr('stroke', 'white')
129-
.attr('stroke-width', 0.8)
130-
.attr('stroke-dasharray', '5,5')
131-
.attr('fill-opacity', 0);
132-
fill_map();
132+
fill_map();
133+
}
134+
{{ this._parent.get_name() }}.on('overlayadd', onOverlayAdd);
133135
136+
onOverlayAdd(); // fill map as layer is loaded
134137
{% endmacro %}
135138
""")
136139

0 commit comments

Comments
 (0)