第一次在这里发布。我在一个使用Angular7的项目中,对leaflet(ngx-leaflet)和leaflet.draw(ngx-leaflet-draw)使用angular指令,并试图在单击单个多边形时对其进行编辑,基本上是在单击一个多边形时,我将事件对象保存在变量中,当我单击自定义编辑按钮时,通过单击保存的多边形需要更改填充颜色,并使点可编辑
在我的组件上单击时,所有创建的多边形都会调用clickInPolygon函数。
const newPoli = L.polygon(points,{
color: '#1DB954',fillColor: '#1DB954',fillOpacity: 0.2
}
).addTo(this.allDrawnItems);
newPoli.on({
click: (function (ev) {
this.clickInPolygon(ev);
}).bind(this)
});
该函数会将最后单击的多边形保存在变量中
public clickInPolygon(e: any) {
this.polygonClicked = e;
}
在我的component.html上单击编辑时,此功能称为
public startEdit(){
this.editPolygon(this.polygonClicked);
}
它应该在这里开始编辑过程,并更改颜色
public editPolygon(poly){
if(poly == null)
return;
this.polyToAnalyze.push(poly);
var layerWithPoly = this.allDrawnItems.getLayer(this.poly.target._leaflet_id);
//i need to get the polygon contained in that layerWithPoly variable,enable his edit mode and change his fill color
}
谢谢,抱歉,英语不是我的母语。