OpenLayers eraseFeatures doesn't erase features from map screen.
Posted
by Jenny
on Stack Overflow
See other posts from Stack Overflow
or by Jenny
Published on 2010-04-08T17:23:15Z
Indexed on
2010/04/08
18:33 UTC
Read the original article
Hit count: 163
openlayers
I'm using OpenLayers, and have a layer for my Map, and a single Vector Layer. In this vector layer, I am using the DrawFeature control to draw a square. I have a listener waiting for a feature to be added, and then deleting any existing features (I only want one square at a time), like so:
polygonLayer.events.register("beforefeatureadded", feature, function(evt){
console.log("Clearing existing polygons");
console.log(polygonLayer.features.length);
polygonLayer.destroyFeatures();
polygonLayer.redraw();
});//end attempt at events registration
When I check my layer.features.size, I can see that it's always 1, just like I expect, but the squares on the screen are still displayed. Even when I call .redraw() on the layer, the squares are still there.
Is there some extra step I'm missing?
Edit: You can find my code here: http://pastie.org/909644
Edit: Just realized: If I draw a square from previously existing coordinates, I can clear it just fine. It seems to be just the squares drawn from the controller that are an issue?
© Stack Overflow or respective owner