@@ -144,6 +144,9 @@ class LayerControl(MacroElement):
144144 autoZIndex : bool, default True
145145 If true the control assigns zIndexes in increasing order to all of
146146 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.
147150 **kwargs
148151 Additional (possibly inherited) options. See
149152 https://leafletjs.com/reference.html#control-layers
@@ -153,7 +156,7 @@ class LayerControl(MacroElement):
153156 _template = Template (
154157 """
155158 {% macro script(this,kwargs) %}
156- var {{ this.get_name() }} = {
159+ var {{ this.get_name() }}_layers = {
157160 base_layers : {
158161 {%- for key, val in this.base_layers.items() %}
159162 {{ key|tojson }} : {{val}},
@@ -165,12 +168,16 @@ class LayerControl(MacroElement):
165168 {%- endfor %}
166169 },
167170 };
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,
171174 {{ this.options|tojson }}
172175 ).addTo({{this._parent.get_name()}});
173176
177+ {%- if this.draggable %}
178+ new L.Draggable({{ this.get_name() }}.getContainer()).enable();
179+ {%- endif %}
180+
174181 {% endmacro %}
175182 """
176183 )
@@ -180,13 +187,15 @@ def __init__(
180187 position : str = "topright" ,
181188 collapsed : bool = True ,
182189 autoZIndex : bool = True ,
190+ draggable : bool = False ,
183191 ** kwargs : TypeJsonValue ,
184192 ):
185193 super ().__init__ ()
186194 self ._name = "LayerControl"
187195 self .options = parse_options (
188196 position = position , collapsed = collapsed , autoZIndex = autoZIndex , ** kwargs
189197 )
198+ self .draggable = draggable
190199 self .base_layers : OrderedDict [str , str ] = OrderedDict ()
191200 self .overlays : OrderedDict [str , str ] = OrderedDict ()
192201
0 commit comments