如何制作传单circleMarker可拖动? [英] How to make a leaflet circleMarker draggable?

查看:172
本文介绍了如何制作传单circleMarker可拖动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用传单,我创建了一个 L.circleMarker ,我希望它可以拖动:

Using leaflet, I created a L.circleMarker and I want it to be draggable:

var marker = L.circleMarker(new L.LatLng(48.94603, 2.25912), {
    draggable: true
})
.bindPopup('Circle marker draggable')
.addTo(map)
.on('dragstart', onMarkerDragStart)
.on('dragend', onMarkerDragEnd);

不幸的是,我没有接到任何关于 onMarkerDragStart / End的调用拖动标记时的功能。但是,如果我们使用 L.marker 而不是 L.circleMarker ,它可以正常工作。

Unfortunately, I don't get any call of onMarkerDragStart/End functions when I drag the marker. However, if we use L.marker instead of L.circleMarker, it works.

那么,有没有人知道如何使 L.circleMarker 可拖动?

So, does anyone know how to make the L.circleMarker draggable?

推荐答案

我将Leaflet.draw插件分叉以支持圆圈标记。你可以这里

I forked the Leaflet.draw plugin to support circle markers. You can get it here

我像这样启用绘图:

drawCircleMarker: function () {
            this.currentHandler = new L.Draw.CircleMarker(this.map, this.drawControl.options.circleMarker);
            this.currentHandler.enable();
        },

您需要依次连接地图的draw:created事件获取已添加的图层。

You will need to hook up to the map's draw:created event in order to get the layer that was added.

要启用拖动,只需获取已添加的图层并在其上启用编辑,如下所示:

To enable dragging, simply take that layer that was added and enable editing on it like this:

pathToEdit.editing.enable();

这篇关于如何制作传单circleMarker可拖动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆