3

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?

1 Answer 1

5

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

1
  • Thank you very much for your help and the awesome example. This is what I really wanted. :)
    – Ra Ka
    Commented Nov 9, 2015 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.