I use OpenLayers and have a layer for my Map and one vector layer. In this vector layer, I use the DrawFeature control to draw a square. I have a listener waiting to add a function and then delete any existing functions (I want only one square at a time), for example:
polygonLayer.events.register("beforefeatureadded", feature, function(evt){
console.log("Clearing existing polygons");
console.log(polygonLayer.features.length);
polygonLayer.destroyFeatures();
polygonLayer.redraw();
});
When I check my layer.features.size, I see that it is always 1, as expected, but the squares on the screen are still showing. Even when I call .redraw () on the layer, the squares still exist.
Is there any extra step that I am missing?
Edit: here you can find my code: http://pastie.org/909644
Edit: I just realized: if I draw a square from the previously existing coordinates, I can clear it just fine. It seems these are just the squares extracted from the controller, which are the problem?
Jenny source
share