问题
I am working on a crowdsourcing app aimed at geotagging old pictures. I display a grid of image thumbnails and when I click on one it places a draggable marker on the map and opens the popup containing the image and associated details. This is done with:
L.marker([newlat, newlng], {
icon: movableIcon,
draggable:true
}).addTo(map).bindPopup(popupContent).openPopup();
This works, but as soon as a user drags the marker the popup closes, hiding the very thing that they are trying to set at the correct location.
Does anyone know how to keep the popup open?
Thanks
回答1:
I believe as you are dragging you have to keep setting the latLng of the popup. Otherwise it doesn't know where to place the popup on the map. This looks like it might be helpful to you.
回答2:
In the end I sorted this simply using
marker.bindPopup("popup content").addTo(map).openPopup();
marker.on('dragend', function(e) {
marker.openPopup();
});
The popup disappears whilst dragging, but then reappears when the user stops. Which is actually quite a nice user experience in my application.
来源:https://stackoverflow.com/questions/25653813/force-leaflet-popup-to-stay-open-when-a-draggable-marker-is-moved