简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM