More

How to change leaflet marker options dynamically?


I want to change the draggable state of leaflet marker on some event. Now, we use marker.options.draggable to get the draggable state of that marker. However, I want to set/change that draggable state in some event.

marker = L.marker([lat,lng],{draggable:true}); draggable_state = marker.options.draggable;

But, below is not working:

marker.options.draggable=false;

How can achieve this?


Marker's have a property calleddraggingwhich is an instance of Draggable. You can usemarker.dragging.enable()andmarker.dragging.disable()to turn dragging on and off. Here's an example: http://jsbin.com/sowere/edit?html,output