I want to save the geometry data after I modify it, so I need an event that fire after I finish to modify the feature. I use the following from this post: listener modify interaction

    var selected_features = select.getFeatures();
// when a feature is selected...
selected_features.on('add', function (event) {
    // get the feature
    var feature = event.element;
    feature.on("change", function (event) {
            logStatus(feature.getId() + " has been changed!\n");

But this listener fires too many times in a single modification, and if I am using 'once' instead of 'on' its fires only the first little change and no more, so its not saving the real change. I need something like "changeend" or "modifyend" that will fire when I will finish to modify the feature, what can i use?


1 Answer 1


If you need a modifyend event why dont you use it within the modify interaction.(I guess you use a modify interaction) check this

console.log("feature id is",e.features.getArray()[0].getId());

This event is available in the latest versions of ol3. In my code snip, I assume you only modify one fetaure at once (getArray()[0]) . If you use more than one fetaure to modify at once then get the fetaures array and add a loop for further manipulation. Like so:

var features = e.features.getArray();
for (var i=0;i<features.length;i++){
console.log("feature changed id is",features[i].getId());
  • 5
    You should specify that modify is the name of the Modify Interaction and that your modifyend code comes after defining the Interaction : first var modify = new ol.interaction.Modify({ features: select.getFeatures() }); and then your code. select is the name of my Select Interaction. Also a developer can do e.features.getArray()[0].getGeometry().getCoordinates() or e.features.getArray()[0].getGeometry().getType() to get the coords or the type. Nice answer anyway dude.
    – slevin
    Oct 31, 2015 at 14:36
  • 4
    Maybe I'm doing something wrong, but with OL5 it would seem that e.features.getArray()[0].getId()) always returns the same id whatever the feature I am modifying is. Would there be another way to know which feature has been changed? Nov 13, 2018 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.