@@ -144,6 +144,9 @@ class LayerControl(MacroElement):
144
144
autoZIndex : bool, default True
145
145
If true the control assigns zIndexes in increasing order to all of
146
146
its layers so that the order is preserved when switching them on/off.
147
+ draggable: bool, default False
148
+ By default the layer control has a fixed position. Set this argument
149
+ to True to allow dragging the control around.
147
150
**kwargs
148
151
Additional (possibly inherited) options. See
149
152
https://leafletjs.com/reference.html#control-layers
@@ -153,7 +156,7 @@ class LayerControl(MacroElement):
153
156
_template = Template (
154
157
"""
155
158
{% macro script(this,kwargs) %}
156
- var {{ this.get_name() }} = {
159
+ var {{ this.get_name() }}_layers = {
157
160
base_layers : {
158
161
{%- for key, val in this.base_layers.items() %}
159
162
{{ key|tojson }} : {{val}},
@@ -165,12 +168,16 @@ class LayerControl(MacroElement):
165
168
{%- endfor %}
166
169
},
167
170
};
168
- L.control.layers(
169
- {{ this.get_name() }}.base_layers,
170
- {{ this.get_name() }}.overlays,
171
+ let {{ this.get_name() }} = L.control.layers(
172
+ {{ this.get_name() }}_layers .base_layers,
173
+ {{ this.get_name() }}_layers .overlays,
171
174
{{ this.options|tojson }}
172
175
).addTo({{this._parent.get_name()}});
173
176
177
+ {%- if this.draggable %}
178
+ new L.Draggable({{ this.get_name() }}.getContainer()).enable();
179
+ {%- endif %}
180
+
174
181
{% endmacro %}
175
182
"""
176
183
)
@@ -180,13 +187,15 @@ def __init__(
180
187
position : str = "topright" ,
181
188
collapsed : bool = True ,
182
189
autoZIndex : bool = True ,
190
+ draggable : bool = False ,
183
191
** kwargs : TypeJsonValue ,
184
192
):
185
193
super ().__init__ ()
186
194
self ._name = "LayerControl"
187
195
self .options = parse_options (
188
196
position = position , collapsed = collapsed , autoZIndex = autoZIndex , ** kwargs
189
197
)
198
+ self .draggable = draggable
190
199
self .base_layers : OrderedDict [str , str ] = OrderedDict ()
191
200
self .overlays : OrderedDict [str , str ] = OrderedDict ()
192
201
0 commit comments