From 40afeb17e484d6000ec928a0752194a333531b2a Mon Sep 17 00:00:00 2001 From: Vasiliev Vladislav <41839166+Qweaper@users.noreply.github.com> Date: Fri, 7 Jul 2023 18:20:09 +0300 Subject: [PATCH] Draw plugin: fix interaction with multiple instances (#1776) Co-authored-by: Vladislav --- folium/plugins/draw.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/folium/plugins/draw.py b/folium/plugins/draw.py index 75ceaef99..95155f8e1 100644 --- a/folium/plugins/draw.py +++ b/folium/plugins/draw.py @@ -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()}} ); @@ -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(