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

How to avoid pm:edit after pm:cut???? #826

Closed ingkiller closed 3 years ago

ingkiller commented 3 years ago

I have recently started using this fantastic tool (leaflet-geoman). I have noticed that after the cut event an edit event is also fired (as the doc refers to). The situation is the following, I have implemented a logic that after editing / moving some layer I make a call to the backend to update the new change (so far everything correctly),but when I cut a layer in the pm: cut event I get layer and originalLayer, send the new layer data, when doing a pm: cut it also triggers a pm: edit. How can you avoid this behavior or know that pm: edit was called by a pm: cut?

 const theCollection = L.geoJson(jsData,{...}).addTo(map)

theCollection.on('pm:edit', ({layer,shape}) => {
//call back end
        });

        theCollection.on('pm:cut', ({layer,originalLayer,shape}) => {
//call back end
        });

Saludos

Falke-Design commented 3 years ago

You can add a flag to the cutted layer:

  // listen to changes on the cutted layer
  e.layer.on('pm:cut', function(x) {
    console.log('cut', x.originalLayer)
    x.originalLayer.cutted = true;
  });

  // listen to changes on the new layer
  e.layer.on('pm:edit', function(x) {
    console.log('edit', x.layer.cutted)
  });
ingkiller commented 3 years ago

Thank you very much, just what I needed, I had tried something similar only in layer not in originalLayer, thank you very much. Saludos