I am using OpenLayers modify interaction with events modifystart
and modifyend
. I am trying to remember state of feature before it is modified.
I do it this way:
var modificirane_cestice=new Object()
modify.on('modifystart',function(e){
e.features.forEach(function(feature){
if(modificirane_cestice[ogc_fid]){
return }
else{
modificirane_cestice[ogc_fid]=new Array()
modificirane_cestice[ogc_fid].push(new ol.Feature({geometry:feature.getGeometry()}))
}
})
})
modify.on('modifyend',function(e){
e.features.forEach(function(feature){
izmjenjena_geometrija=feature.getGeometry()
modificirane_cestice[ogc_fid].push(new ol.Feature({geometry:izmjenjena_geometrija}))
posljednja_geometrija=modificirane_cestice[ogc_fid].length-1
pg_pov=ol.sphere.getArea(modificirane_cestice[ogc_fid][0].getGeometry())
zadnja_pov=ol.sphere.getArea(modificirane_cestice[ogc_fid][posljednja_geometrija].getGeometry())
console.log(pg_pov+".... zadnja pov...."+zadnja_pov)
postotak=pg_pov/zadnja_pov
console.log(postotak)
if(postotak<0.9){
console.log("postotak prelazi 10% i iznosi: "+(1-postotak)*100+"%")
}
})
})
I expected to get two different areas and features but in the end I got the same one. I know there is problem in referencing feature object but don't know how to solve it. I want to create a new object which are independent on their source object.
geometry:feature.getGeometry().clone()
otherwise the features will share the same geometry object and a change to one will change both