You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
After trying combine DualMap with Draw I get incorrect work of rectangles displaying. If I draw a rectangle on the left viewport(Map) it displays on right display instead of the original one.
Expected behavior
I wanted that I can draw rects on each viewpotrs. I get rects that draw on right viewport only independently of place where i draw.
Environment (please complete the following information):
Browser: firefox
HTML
Python version 3.8
folium version '0.14.0'
branca version '0.6.0'
Possible solutions
I solved it locally by changing name generating in class Draw in the template. Original code generates a single drawnItems name, which use for every map in DualMap, that is why it rewrites after first usage and cause drawing figures on the last layer that have been created.
Attach my code as solution, because I'm not sure about codestyle, but its works.
here original code:
_template=Template(
""" {% macro script(this, kwargs) %} var options = { position: {{ this.position|tojson }}, draw: {{ this.draw_options|tojson }}, edit: {{ this.edit_options|tojson }}, } // FeatureGroup is to store editable layers. var drawnItems = new L.featureGroup().addTo( {{ this._parent.get_name() }} ); options.edit.featureGroup = drawnItems; var {{ this.get_name() }} = new L.Control.Draw( options ).addTo( {{this._parent.get_name()}} ); {{ this._parent.get_name() }}.on(L.Draw.Event.CREATED, function(e) { var layer = e.layer, type = e.layerType; var coords = JSON.stringify(layer.toGeoJSON()); {%- if this.show_geometry_on_click %} layer.on('click', function() { alert(coords); console.log(coords); }); {%- endif %} drawnItems.addLayer(layer); }); {{ this._parent.get_name() }}.on('draw:created', function(e) { drawnItems.addLayer(e.layer); }); {% if this.export %} document.getElementById('export').onclick = function(e) { var data = drawnItems.toGeoJSON(); var convertedData = 'text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(data)); document.getElementById('export').setAttribute( 'href', 'data:' + convertedData ); document.getElementById('export').setAttribute( 'download', {{ this.filename|tojson }} ); } {% endif %} {% endmacro %} """
)
my fixed code:
_template=Template(
""" {% macro script(this, kwargs) %} var options = { position: {{ this.position|tojson }}, draw: {{ this.draw_options|tojson }}, edit: {{ this.edit_options|tojson }}, } // FeatureGroup is to store editable layers. var drawnItems_{{ this.get_name() }} = new L.featureGroup().addTo( {{ this._parent.get_name() }} ); options.edit.featureGroup = drawnItems_{{ this.get_name() }}; var {{ this.get_name() }} = new L.Control.Draw( options ).addTo( {{this._parent.get_name()}} ); {{ this._parent.get_name() }}.on(L.Draw.Event.CREATED, function(e) { var layer = e.layer, type = e.layerType; var coords = JSON.stringify(layer.toGeoJSON()); {%- if this.show_geometry_on_click %} layer.on('click', function() { alert(coords); console.log(coords); }); {%- endif %} drawnItems_{{ this.get_name() }}.addLayer(layer); }); {{ this._parent.get_name() }}.on('draw:created', function(e) { drawnItems_{{ this.get_name() }}.addLayer(e.layer); }); {% if this.export %} document.getElementById('export').onclick = function(e) { var data = drawnItems_{{ this.get_name() }}.toGeoJSON(); var convertedData = 'text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(data)); document.getElementById('export').setAttribute( 'href', 'data:' + convertedData ); document.getElementById('export').setAttribute( 'download', {{ this.filename|tojson }} ); } {% endif %} {% endmacro %} """
)
The text was updated successfully, but these errors were encountered:
Great issue description. Though we generally don’t support different plugins working together, I think here it’s clear that drawn_items shouldn’t be a single global variable. Your solutions looks good to me and is in line with how things work more commonly in Folium. Would you mind creating a PR?
Describe the bug
After trying combine DualMap with Draw I get incorrect work of rectangles displaying. If I draw a rectangle on the left viewport(Map) it displays on right display instead of the original one.
To Reproduce
Expected behavior
I wanted that I can draw rects on each viewpotrs. I get rects that draw on right viewport only independently of place where i draw.
Environment (please complete the following information):
Possible solutions
I solved it locally by changing name generating in class Draw in the template. Original code generates a single drawnItems name, which use for every map in DualMap, that is why it rewrites after first usage and cause drawing figures on the last layer that have been created.
Attach my code as solution, because I'm not sure about codestyle, but its works.
here original code:
my fixed code:
The text was updated successfully, but these errors were encountered: