udo
udo

Reputation: 5190

geoman - how to listen to a feature change in edit mode after the feature has been created in draw mode

I am listening to adding a vertex during "draw mode" as documented in docs https://github.com/geoman-io/leaflet-geoman#draw-mode

map.on('pm:drawstart', ({ workingLayer }) => {  
  workingLayer.on('pm:vertexadded', e => {  
    console.log(e);  
  });
});

at some point I am done drawing and "draw mode" is ended.

i then want to edit the geometry and enable "edit mode".

how can I listen to edits of the "workingLayer" in which I just draw the geometries?

I tried the following without success...

map.on('pm:drawstart', ({ workingLayer }) => {  
  workingLayer.on('pm:vertexadded', e => {  
    console.log(e);
  });
  workingLayer.on('pm:edit', e => {
    console.log(e);
  });
});

update: I then turned on my brain and came up with the following

map.on('pm:globaleditmodetoggled', e => {
  e.map.pm.getGeomanDrawLayers(true).on('pm:edit', e => {
    console.log(e)
  });
});

is this the way to do it or does a more efficient way exist'?

Upvotes: 2

Views: 3306

Answers (1)

Falke Design
Falke Design

Reputation: 11338

Use the listener pm:create and add to the new created layer the pm:edit listener. Then the event pm:edit will be fired when a edit happens on the new layer.

map.on('pm:create', ({ layer}) => {  
  layer.on('pm:edit', e => {
    console.log(e);
  });
});

Upvotes: 4

Related Questions