2

How can I get the new feature geometry after its modification in Openlayers 6? I'm listening to the modifyend event.

The source contains around 100 features. How can I do this?

var modify = new ol.interaction.Modify({
       source: map_features_source
});

modify.on('modifyend', function (evt) {
       console.log(evt.target);
});

map.addInteraction(modify);

I tried this:

evt.features.getArray()[0].getGeometry().getCoordinates()

but it's not working as I have many elements in the array evt.features.getArray(). I need to find the one that was modified.

Philiz
  • 429
  • 5
  • 25
  • `evt.feattures[0],getGeometry()` - if features overlap it is possible to modify more than one feature in one operation, so you may need to loop through the array. – Mike Nov 08 '21 at 18:59
  • I have updated the question after having tried your solution. – Philiz Nov 08 '21 at 20:57
  • 2
    Which version of OpenLayers are you using? Before 6.6.0 all features in the source were returned, which was not useful. – Mike Nov 08 '21 at 22:33
  • You are right, I was using version 6.1. Working now. You can write as the answer if you want. – Philiz Nov 09 '21 at 09:55

1 Answers1

0

As Mike described in comment, before the version 6.6.0 all features in the source were returned in the modifyend event. Just need to upgrade to that version minimum and this will match the modified feature:

evt.features.getArray()[0].getGeometry().getCoordinates() 
Philiz
  • 429
  • 5
  • 25