Leaflet – How to Drag Scale

drag and dropleafletscale

Is it possible to drag the scale on a Leaflet map ?

L.control.scale({'position':'bottomleft', 'metric':true,'imperial':false}).addTo(map);

I used this possibility for a wind rose with this code

north.onAdd = function(map) {
    var div = L.DomUtil.create("div", "info legend");
    div.innerHTML = '<img src="/gps/images/compas-120.png">';
    var draggable = new L.Draggable(div);
    draggable.enable()
    return div;
}
north.addTo(map); 

Best Answer

Yes , it's actually quite simple. Get the container of the scale control with the .getContainer() method and then make it draggable:

var controlScale = L.control.scale({'position':'bottomleft', 'metric':true,'imperial':false}).addTo(map);
var scaleContainer = controlScale.getContainer();

var draggable = new L.Draggable(scaleContainer);
draggable.enable();
Related Question