Skip to content

Commit 40afeb1

Browse files
QweaperVladislav
andauthored
Draw plugin: fix interaction with multiple instances (#1776)
Co-authored-by: Vladislav <VSerVasilyev@sberbank.ru>
1 parent 0054bcd commit 40afeb1

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

folium/plugins/draw.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ class Draw(JSCSSMixin, MacroElement):
5151
edit: {{ this.edit_options|tojson }},
5252
}
5353
// FeatureGroup is to store editable layers.
54-
var drawnItems = new L.featureGroup().addTo(
54+
var drawnItems_{{ this.get_name() }} = new L.featureGroup().addTo(
5555
{{ this._parent.get_name() }}
5656
);
57-
options.edit.featureGroup = drawnItems;
57+
options.edit.featureGroup = drawnItems_{{ this.get_name() }};
5858
var {{ this.get_name() }} = new L.Control.Draw(
5959
options
6060
).addTo( {{this._parent.get_name()}} );
@@ -68,14 +68,14 @@ class Draw(JSCSSMixin, MacroElement):
6868
console.log(coords);
6969
});
7070
{%- endif %}
71-
drawnItems.addLayer(layer);
71+
drawnItems_{{ this.get_name() }}.addLayer(layer);
7272
});
7373
{{ this._parent.get_name() }}.on('draw:created', function(e) {
74-
drawnItems.addLayer(e.layer);
74+
drawnItems_{{ this.get_name() }}.addLayer(e.layer);
7575
});
7676
{% if this.export %}
7777
document.getElementById('export').onclick = function(e) {
78-
var data = drawnItems.toGeoJSON();
78+
var data = drawnItems_{{ this.get_name() }}.toGeoJSON();
7979
var convertedData = 'text/json;charset=utf-8,'
8080
+ encodeURIComponent(JSON.stringify(data));
8181
document.getElementById('export').setAttribute(

0 commit comments

Comments
 (0)