Skip to content

Commit

Permalink
Draw plugin: fix interaction with multiple instances (#1776)
Browse files Browse the repository at this point in the history
Co-authored-by: Vladislav <VSerVasilyev@sberbank.ru>
  • Loading branch information
Qweaper and Vladislav committed Jul 7, 2023
1 parent 0054bcd commit 40afeb1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions folium/plugins/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class Draw(JSCSSMixin, MacroElement):
edit: {{ this.edit_options|tojson }},
}
// FeatureGroup is to store editable layers.
var drawnItems = new L.featureGroup().addTo(
var drawnItems_{{ this.get_name() }} = new L.featureGroup().addTo(
{{ this._parent.get_name() }}
);
options.edit.featureGroup = drawnItems;
options.edit.featureGroup = drawnItems_{{ this.get_name() }};
var {{ this.get_name() }} = new L.Control.Draw(
options
).addTo( {{this._parent.get_name()}} );
Expand All @@ -68,14 +68,14 @@ class Draw(JSCSSMixin, MacroElement):
console.log(coords);
});
{%- endif %}
drawnItems.addLayer(layer);
drawnItems_{{ this.get_name() }}.addLayer(layer);
});
{{ this._parent.get_name() }}.on('draw:created', function(e) {
drawnItems.addLayer(e.layer);
drawnItems_{{ this.get_name() }}.addLayer(e.layer);
});
{% if this.export %}
document.getElementById('export').onclick = function(e) {
var data = drawnItems.toGeoJSON();
var data = drawnItems_{{ this.get_name() }}.toGeoJSON();
var convertedData = 'text/json;charset=utf-8,'
+ encodeURIComponent(JSON.stringify(data));
document.getElementById('export').setAttribute(
Expand Down

0 comments on commit 40afeb1

Please sign in to comment.