Search code examples
openlayersopenlayers-6

Openlayers 6 get geometry of a modified feature


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.


Solution

  • 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()