我在我的ASP.NET MVC5应用程序中使用了叶子标记。
我需要将应用程序外部的标记拖到一个div元素中,在那里我想获取它的id以执行进一步的操作。
marker=new L.marker([latNumber,longNumber], {draggable:'true'});
marker.id = "ABC";
$('#'+ marker.id).draggable(); // draggable jquery UI
marker.on('dragend', function(event){
var marker = event.target;
var position = marker.getLatLng();
console.log(position);
marker.setLatLng(position,{draggable:'true'}).bindPopup(position).update();
});
另一方面,我使用jquery UI的droppable元素
$("#navs").droppable({
drop: function (event, ui) {
alert('dropped')
}
});
当我将navs元素放在它上面时,它不会出现drop事件。我需要做哪些改变才能让它工作。
如果有人能进一步解释this,也会有很大的帮助。
发布于 2017-06-23 09:35:17
实际上,似乎有一种变通方法。将标记添加到地图后,叶标记将事件称为"add“,并变为可见。在这种情况下,您可以在对应于该标记的图标上初始化可拖动对象。
m=L.marker([lat,lng],{
title:title,
draggable:true
});
m.on("add",function(){
$(this._icon).data("marker",this);
$(this._icon).draggable({
appendTo:"body",
helper:"clone",
zIndex:1000
});
});
在传单面板外部拖动时需要使用"appendTo“。zIndex应该比leaflet地图的zIndex高(不确定它是否被修复,在我的页面上是600 )。你可能需要一个辅助功能来复制一个图标,我已经定制了我的辅助功能(标记可以通过数据“标记”来访问)。
我在小叶1.0.3中使用了这一点。
发布于 2016-11-20 15:42:34
不能将传单标记拖动到地图外部。
标记的可拖动选项和jQuery的可拖动概念是完全不同的。
如上所述,您可以通过使用标记的图像并将其放置在地图上来假装标记被拖动:它不是地图的一部分,但它看起来像(这就是您提到的链接所指的)
<div>
<div id='map'></div>
<img style="position: absolute; left: 300px; top: 200px; z-index: 1000" id="fakeMarker" src="https://unpkg.com/leaflet@1.0.1/dist/images/marker-icon.png"></img>
</div>
<ul id="liste">
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
</ul>
<div id="log"></div>
<script>
$( function() {
$("#fakeMarker").draggable();
$( "#liste li" ).droppable({
accept: "#fakeMarker",
drop: function( event, ui ) {
$( "#log" ).html("dropped on " + $(this).html());
}
});
} );
</script>
下面是一个示例:https://yafred.github.io/leaflet-tests/20161120-drag-and-drop-outside-map/
https://stackoverflow.com/questions/40701763
复制相似问题