1

When i create a new Polygon, on "PM:DRAWSTART" i initialize event "pm:vertexadded"

It's allow me to detect if:

  • New point is inside an existing polygons, so i remove it. *
  • If last line created intersect with an existing polygons ( TurfJS lineIntersect ), i remove it.
  • If last line created "kinks" ( TurfJS also ) , i remove it.

  • I use : "map.pm.Draw["Polygon"]._removeLastVertex();" to remove last point.

My problem.

When polygon is closed (last point click on first one) "PM:DRAWEND" event is executed. So in this case i'm not able to check if the new polygon is overlaping an existing one as i do with event "pm:vertexadded".

Is it possible on event "PM:CREATE" if the new polygon is overlaping an existing one to go in edit mode ( polygon.toggleEdit() ) and go back on stage as i don't click on the last point to close the polygon.

Many thanks.

Shaan1974
  • 65
  • 1
  • 4

1 Answers1

2

You can reinit the draw polygon with the existing latlngs:

map.on('pm:create',function (e) {
  e.layer.removeFrom(map);
  setTimeout(function (){ //Needed because snapping
    map.pm.enableDraw('Polygon');
    var latlngs = e.layer.getLatLngs();
    if(!L.LineUtil.isFlat(latlngs)){
      latlngs = latlngs[0];
    }
    latlngs.forEach(function (latlng) {
      map.pm.Draw.Polygon._createVertex({latlng: latlng})
    })
  },100);
})

Example: https://jsfiddle.net/falkedesign/omw2pt34/ draw a polygon

Falke Design
  • 10,635
  • 3
  • 15
  • 30