[英]Leaflet vertex click event
How to fire/listen a click event from a L.Polygon vertex ? 如何从L.Polygon顶点触发/监听click事件?
The user make a Polygon using: 用户使用以下方法制作多边形:
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;
},
and when the polygon is created it is enabled to edit its vertex: 创建多边形后,可以编辑其顶点:
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);
});
}
So, the polygon is already drawn and I want to listen the clicks of their vertex 因此,多边形已经绘制完毕,我想听听其顶点的点击声
Leaflet 1.3.1
传单1.3.1
Plugin Leaflet.Draw
插件传单
Notice I don't use control toolbars
注意我不使用控制工具栏
After looking for it I found a lightweight library to control editing of geometries in leaflet: 查找之后,我发现了一个轻量级的库来控制传单中几何的编辑:
First, add the editable property to the map 首先,将editable属性添加到地图
var map = L.map('map', {
editable: true,
editOptions: {…} //not required
});
then, to enable feature edition 然后,启用功能版本
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);
});
}
And finally listen the vertex clicks of the polygon 最后听多边形的顶点点击
me.cacheLayer.on({
"editable:vertex:click": function(e){console.log("You touch me", e)}
});
Find the library in here: 在这里找到图书馆:
If someone has another way of doing it, please share it, thank you!
如果有人有其他方法,请分享,谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.