# Store geometry change on modify interaction OpenLayers

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())
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.

• I think you will need to use geometry:feature.getGeometry().clone() otherwise the features will share the same geometry object and a change to one will change both – Mike Jun 11 at 10:32
• @Mike Thanks, it works now :) – Goran Jun 11 at 10:36
• @Mike Please, put your comment as an answer so it can be accepted. – TomazicM Jun 11 at 12:42

You need to use geometry:feature.getGeometry().clone() otherwise the features will share the same geometry object and a change to one will change both.