How can I drag a marker out of the map

2019-07-20 08:05发布

问题:

I would like to be able to drag a marker out of the map area onto some other (drop-enabled) element on the page (to include it in a list for example). How can I do this with leaflet? If I try to drag a marker out of the map, it just disappears underneath the area surrounding the map...

回答1:

You won't be able to do this with leaflet functionality. One approach could be:

  1. Listen for event on marker. You don't actually want the markers draggable in terms of changing locations so you probably want to change that setting within the marker and use the mouse down event or something.
  2. Create element to drag and drop outside of map but set its z-index and other css properties to so it appears to be a marker.
  3. Use drag and drop from html5/jquery/etc to place in container.

FYI: Here is the opposite approach of having a draggable object moved on to the map and then inserted as a marker.



标签: leaflet