Skip to content

Commit 96fbf2a

Browse files
committed
Closes #2182.
Add the newly created layers to the drawnItems feature group.
1 parent 5c76331 commit 96fbf2a

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

folium/plugins/geoman.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class GeoMan(JSCSSMixin, MacroElement):
3434
{{ this._parent.get_name() }}
3535
);
3636
{%- endif %}
37+
3738
/* The global variable below is needed to prevent streamlit-folium
3839
from barfing :-(
3940
*/
@@ -42,6 +43,7 @@ class GeoMan(JSCSSMixin, MacroElement):
4243
{{this.get_name()}}.addControls(
4344
{{this.options|tojavascript}}
4445
)
46+
4547
drawnItems_{{ this.get_name() }}.eachLayer(function(layer){
4648
L.PM.reInitLayer(layer);
4749
{%- for event, handler in this.on.items() %}
@@ -52,7 +54,7 @@ class GeoMan(JSCSSMixin, MacroElement):
5254
{%- endfor %}
5355
});
5456
55-
{{ this._parent.get_name() }}.on("pm:create", function(e) {
57+
var new_element_handler_{{ this.get_name() }} = function(e) {
5658
var layer = e.layer,
5759
type = e.layerType;
5860
@@ -62,19 +64,11 @@ class GeoMan(JSCSSMixin, MacroElement):
6264
{{handler}}
6365
);
6466
{%- endfor %}
65-
});
67+
drawnItems_{{ this.get_name() }}.addLayer(layer);
68+
};
6669
67-
{{ this._parent.get_name() }}.on("pm:cut", function(e) {
68-
var layer = e.layer,
69-
type = e.layerType;
70-
71-
{%- for event, handler in this.on.items() %}
72-
layer.on(
73-
"{{event}}",
74-
{{handler}}
75-
);
76-
{%- endfor %}
77-
});
70+
{{ this._parent.get_name() }}.on("pm:create", new_element_handler_{{ this.get_name() }});
71+
{{ this._parent.get_name() }}.on("pm:cut", new_element_handler_{{ this.get_name() }});
7872
7973
{% endmacro %}
8074
"""

0 commit comments

Comments
 (0)