[OpenLayers-Users] VectorLayer destroyFeatures doesn't
workproperly?
Arnd Wippermann
arnd.wippermann at web.de
Sat Apr 10 11:07:58 EDT 2010
Hi,
It seems, that 'beforefeatureadded' not works as one would expect.
I would think, that the feature is already in the layers features array, but
still drawn on a temporary layer. Deleting the feature(s) works, but obvious
do not clear the temporary layer.
function clearCircles(){
console.log("Clearing existing circles");
console.log(polygonLayer.features.length);
polygonLayer.destroyFeatures(polygonLayer.features);
polygonLayer.redraw();
}//end clearCircles
You have to control, if there are more then one feature in the layer array.
Then you can delete the first.
polygonLayer.events.register("beforefeatureadded", polygonLayer,
function(evt){
if(polygonLayer.features.length>1)
{
console.log("B:" + polygonLayer.features.length);
polygonLayer.removeFeatures(polygonLayer.features[0]);
console.log("--Clearing existing circles--");
console.log("C:" + polygonLayer.features.length);
}
console.log("A:" + polygonLayer.features.length);
});//end attempt at events registration
As an better solution I would suggest to delete the previous feature, when
the drawing starts.
polygonLayer.events.on({
sketchstarted: function(evt)
{ if(polygonLayer.features[0])
polygonLayer.removeFeatures(polygonLayer.features[0]);
}
});
http://gis.ibbeck.de/olclient/examples/sketchstarted.html
Arnd
More information about the Users
mailing list