Force Leaflet popup to stay open when a draggable marker is moved

|▌冷眼眸甩不掉的悲伤 提交于 2020-02-03 02:01:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!