@@ -12,6 +12,9 @@ class Draw(JSCSSMixin, MacroElement):
12
12
----------
13
13
export : bool, default False
14
14
Add a small button that exports the drawn shapes as a geojson file.
15
+ feature_group : FeatureGroup, optional
16
+ The FeatureGroup object that will hold the editable figures. This can
17
+ be used to initialize the Draw plugin with predefined Layer objects.
15
18
filename : string, default 'data.geojson'
16
19
Name of geojson file
17
20
position : {'topleft', 'toprigth', 'bottomleft', 'bottomright'}
@@ -50,10 +53,17 @@ class Draw(JSCSSMixin, MacroElement):
50
53
draw: {{ this.draw_options|tojson }},
51
54
edit: {{ this.edit_options|tojson }},
52
55
}
53
- // FeatureGroup is to store editable layers.
54
- var drawnItems_{{ this.get_name() }} = new L.featureGroup().addTo(
55
- {{ this._parent.get_name() }}
56
- );
56
+ {%- if this.feature_group %}
57
+ var drawnItems_{{ this.get_name() }} =
58
+ {{ this.feature_group.get_name() }};
59
+ {%- else %}
60
+ // FeatureGroup is to store editable layers.
61
+ var drawnItems_{{ this.get_name() }} =
62
+ new L.featureGroup().addTo(
63
+ {{ this._parent.get_name() }}
64
+ );
65
+ {%- endif %}
66
+
57
67
options.edit.featureGroup = drawnItems_{{ this.get_name() }};
58
68
var {{ this.get_name() }} = new L.Control.Draw(
59
69
options
@@ -69,7 +79,7 @@ class Draw(JSCSSMixin, MacroElement):
69
79
});
70
80
{%- endif %}
71
81
drawnItems_{{ this.get_name() }}.addLayer(layer);
72
- });
82
+ });
73
83
{{ this._parent.get_name() }}.on('draw:created', function(e) {
74
84
drawnItems_{{ this.get_name() }}.addLayer(e.layer);
75
85
});
@@ -106,6 +116,7 @@ class Draw(JSCSSMixin, MacroElement):
106
116
def __init__ (
107
117
self ,
108
118
export = False ,
119
+ feature_group = None ,
109
120
filename = "data.geojson" ,
110
121
position = "topleft" ,
111
122
show_geometry_on_click = True ,
@@ -115,6 +126,7 @@ def __init__(
115
126
super ().__init__ ()
116
127
self ._name = "DrawControl"
117
128
self .export = export
129
+ self .feature_group = feature_group
118
130
self .filename = filename
119
131
self .position = position
120
132
self .show_geometry_on_click = show_geometry_on_click
0 commit comments