geoman-io / leaflet-geoman

🍂🗺️ The most powerful leaflet plugin for drawing and editing geometry layers
https://geoman.io
MIT License
2.21k stars 433 forks source link

Do not fire pm:edit after drag marker end in a huge polygon #1501

Closed dvaltrick closed 2 months ago

dvaltrick commented 3 months ago

Hi, everyone!

I am facing an interesting problem with the library. It only happens with one specific polygon, this polygon has more than 5K points but I have polygons with 6K points that work well. The problem is, that I am editing the polygon, and when the drag ends it returns a console.log "listener not found" for each point of the polygon and does not fire pm:edit, debugging I saw that the console message was for "dragend" event.

here we have a video showing the problem

https://github.com/geoman-io/leaflet-geoman/assets/7021959/577fe155-846c-43a3-a405-fe3ebe701836

image

Here how we are enabling edition and setting pm:edit listener

    map.eachLayer((layer) => {
      if (layer.options?.payload?.zoneId && layer?.options?.payload?.zoneId === zoneId) {
        layer.pm?.enable({
          allowSelfIntersection: false,
          snappable,
          limitMarkersToCount: 100,
          limitMarkersToViewport: true,
        });

        layer.on('pm:edit', (e) => {
          const { id } = e.layer.options.payload;
          const points = e.layer.getLatLngs()[0];

          editedLayers.set(id, { id, points });
          onEdited(editedLayers);
        });
      }
    });

Polygon

londrina.txt

Falke-Design commented 3 months ago

Your polygon has self-intersection. This is the reason why the vertex jumps back and no pm:edit is fired (because no edit was done). You can disable this with setting the option allowSelfIntersection to true.

You can find the intersecting points with that:

layer.on('pm:intersect', (e) => {
        L.geoJSON(e.intersection).addTo(map)
});
layer.pm.enable();

I was not able to reproduce the "listener not found" warning. Which version of Geoman and Leaflet are you using?

dvaltrick commented 3 months ago

Thank you for being so helpful @Falke-Design I tested in here and allowed self-intersection of the polygon edit normally. I will understand where the intersection is to remove it.

About the versions I am using leaflet: 1.8.0 leaflet-geoman-free: 2.14.2

Falke-Design commented 3 months ago

Then I can close the issue?

btw. I strongly suggest to update to Leaflet 1.9.4.