gpt4 book ai didi

javascript - Leaflet顶点点击事件

转载 作者:行者123 更新时间:2023-11-28 02:33:34 25 4
gpt4 key购买 nike

如何触发/监听来自 L.Polygon 顶点的点击事件?

用户使用以下方式制作多边形:

fobDrawPolygon: function(iobMap) {
var obPolygon = new L.Draw.Polygon(iobMap, {
allowIntersection: false,
showArea: true,
shapeOptions: {
color: '#000'
}
//repeatMode: true
});
obPolygon.options.touchIcon.options.iconSize = [12, 12];
obPolygon.enable();
return obPolygon;
},

创建多边形后,可以编辑其顶点:

onDrawFeature: function(iobMap, iobFeatureGroup) {
var me = this;
iobMap.on(L.Draw.Event.CREATED, function(event) {
var obLayer = event.layer;
obLayer.options.editing = {};
obLayer.editing.enable();
iobFeatureGroup.addLayer(obLayer);
});
}

所以,多边形已经绘制好了,我想听听它们顶点的咔嗒声

Leaflet 1.3.1

Plugin Leaflet.Draw

Notice I don't use control toolbars

最佳答案

在寻找它之后,我发现了一个轻量级的库来控制传单中几何图形的编辑:

首先,给 map 添加editable属性

var map = L.map('map', {
editable: true,
editOptions: {…} //not required
});

然后,启用功能版

onDrawFeature: function(iobMap, iobFeatureGroup) {
var me = this;
iobMap.on(L.Draw.Event.CREATED, function(event) {
var obLayer = event.layer;
iobLayer.enableEdit(iobMap); //enable edition
me.cacheLayer = iobLayer;
iobFeatureGroup.addLayer(obLayer);
});
}

最后听听多边形的顶点点击

me.cacheLayer.on({
"editable:vertex:click": function(e){console.log("You touch me", e)}
});

在这里找到图书馆:

If someone has another way of doing it, please share it, thank you!

关于javascript - Leaflet顶点点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48872077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com