使用OpenLayers 3修改特征,如何获取修改后的特征?
var features = new ol.Collection(editableLayer.getSource().getFeatures());
var modifyInteraction = new ol.interaction.Modify({
features: features
})
map.addInteraction(modifyInteraction);
modifyInteraction.on("modifyend", modifyFeature, this);
Run Code Online (Sandbox Code Playgroud)
当我去获取该功能时:
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
}
Run Code Online (Sandbox Code Playgroud)
我的问题是如何获得已修改的实际功能的参考?
根据 api 文档 ol.interaction.Modify 不提供 get Featueres 选项。一种方法是在每个功能上添加一个公共更改事件 - .on('change:'... - 在该事件触发后,您应该获得目标功能。否则您可以检查修订计数器,该计数器会增加一更改后的每个功能(但我不推荐这样做)