5

Using OpenLayers 3 to modify features, how do I get the modified feature?

var features = new ol.Collection(editableLayer.getSource().getFeatures());
var modifyInteraction = new ol.interaction.Modify({
  features: features
})
map.addInteraction(modifyInteraction);
modifyInteraction.on("modifyend", modifyFeature, this);

When I go to get the feature:

function modifyFeature(event)
{
    var feature1 = event.features.getArray()[0]; //this brings back all features
                                                //I want to know which specific
                                                //features was modified

    var feature2 = modifyInteraction.getFeatures(); //this did not work at all
}

My question is how do I get a reference the actual feature that was modified?

Robert Smith
  • 779
  • 1
  • 10
  • 28

1 Answers1

2

According to the api docs ol.interaction.Modify doens't provide a get Featueres Option. One approach is to add a common change event - .on('change:'... - on each feature, and after the event is fired you should get the target Feature. Otherwise you can check the revision counter which is increased by one on every feature after a change (but i wouldn't recommend this)

foedchr
  • 123
  • 1
  • 9
  • Thank you Foed, I had thought of doing that work-around but was trying to avoid it. – Robert Smith Jan 15 '16 at 13:31
  • Ok just tried it an it did not work. When checking the modified feature inside modifyFeature function, it still has the old geometry. – Robert Smith Jan 15 '16 at 15:26
  • Did you do it before or after the ol.interaction.Modify:ModifyEnd Event was fired. Because i think during the modification process the feature is cloned in an Sketch Overlay and only after the event gets fired the origin feature get the updated geometry. After this the feature itself should fires the change event and you should get the changed feature in the event scope. Can ypu provide a jsfiddle? – foedchr Jan 15 '16 at 15:48
  • Did it after the ModifyEnd event. Is this a bug? – Robert Smith Jan 19 '16 at 17:34