6

I have a problem with OL3 and it's ol.interaction.Modify Event. Whenever I modify a feature, just one, it returns all features inside the layer. Currently I have 77 features (polygons) and I can modify them with the modify interaction. Inside the callback function it returns the event with the feature member array and this seems to be buggy:

modify.on('modifyend', function(e) {

    console.log('=== Modify end ===');
    var modifiedFeature = e.features.item(0);

    //Why do I get 77 modified features if I have only touched one?
    // e.features size is = 77
    console.log(e.features);
});

Do you know a working way to get the one modified feature?

8

I guess you pass all the features to the modify interaction. That is why it returns all of them (If you dont provide your code I can only guess). You can always use a select interaction and the pass the selected feature to modify interction. For your case you may iterate through your features and check for the revision, each time a feature is modified, its version number will be incremented.

So do something like this

var modifiedFeatures;
modify.on('modifyend', function(e) {
    var features = e.features.getArray();
    console.log(features.length);
    for (var i = 0; i < features.length; i++) {
        var rev = features[i].getRevision();
        if (rev > 1) {
            console.log("feature with revision:" + rev + " has been modified");
            modifiedFeatures.push(features[i]);
        }
    }
});

check this fiddle.

  • Hi Pavlos, yes your are right, I pass all features and so it returns all features. Thanks very much for the hint with the Revision number. This resolved my problem. – Brain Jan 7 '16 at 8:46
  • glad to help amigo!! – pavlos Jan 7 '16 at 9:13
  • It's becoming horrible when you have to save the features. The revision indexes increase each time, then you cannot count on it. Too bad there isn't a more simple solution... – F3L1X79 Sep 11 '18 at 11:49
  • You can create an array of ids and place the modified feature ids there. Then each time you save you may empty the array. The example provided presents a way to catch the modified fetaure, there are several ways to achieve your goal but it depends on your logic – pavlos Sep 12 '18 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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