2014-10-09 3 views
2

내 앱에서 임시 드래그 가능한 마커를지도에 추가하고 팝업을 엽니 다. 마커를 드래그하면 팝업이 닫히는 것을 발견했습니다. 이 해결하기 위해 나는 또한 사용자가 수동으로 팝업을 닫으면 있는지 확인하려면, Force Leaflet popup to stay open when a draggable marker is moved마커를 드래그하는 도중 리플릿 팝업 팝업이 울림

var marker = new L.Marker([setLat, setLng], {icon:questionIcon, draggable:true}); 
marker.bindPopup("popup content").addTo(map).openPopup(); 
marker.on('dragend', function(e) { 
    marker.openPopup(); 
}); 

그러나 당 코드를 추가 ('X'표준을 사용하여 오른쪽 상단) 임시 마커입니다 지도에서 삭제되었습니다. 그래서 ...

marker.on('popupclose', function(e) { 
    map.removeLayer(marker); 
}); 

...하지만 마커를 끌 때도 실행됩니다. 따라서 사용자가 마커를 드래그하여 위치를 변경하면 마커가 완전히 사라집니다.

두 가지 이벤트를 구별 할 수있는 방법이 있습니까? 다르게 처리 할 수 ​​있습니까? 또는 원래의 질문으로 돌아가서 마커를 드래그하면 팝업 클로즈가 비활성화됩니다.

답변

2

비슷한 문제가 발생했습니다. 내 솔루션은 여기에

var IsDragging = false; 

marker.on('dragstart', function (event) { 
    IsDragging = true; 
}); 

marker.on('dragend', function (event) { 
    marker.openPopup(); 
    IsDragging = false; 
}); 

map.on('popupclose', function(e) { 
    setTimeout(function(){ 
     if(LS.Send.IsDragging == false){ 
      map.removeLayer(LS.Send.Marker); 
     } 
    },300); 
});