On Aug 18, 2009, at 12:38 AM, Eric Lemoine wrote:
Hi John
Actually the to-be-added feature is already in the layer when
beforefeatureadded triggers, so calling destroyFeatures() in a
beforefeatureadded listener also destroys the to-be-added feature .
This looks like a bug to me, so I think a ticket should be open for
this. In the mean time you can do this:
function clearPreviousFeatures(evt) {
var i, len, toDestroy = []
for(i=0,len=vectors.features.length; i<len; i++) {
if(vectors.features[i] != evt.feature) {
toDestroy.push(vectors.features[i]);
}
}
vectors.removeFeatures(toDestroy);
for(i=toDestroy.length-1; i>=0; i--) {
toDestroy[i].destroy();
}
}
Hope this helps,
PS: thanks for the example you provided.
Thanks Eric, this works great!
I notice that there doesn't seem to be any difference between this:
vectors.removeFeatures(toDestroy);
for(i=toDestroy.length-1; i>=0; i--) {
toDestroy[i].destroy();
}
and this:
vectors.destroyFeatures(toDestroy);
Is that what you'd expect?
--john
_______________________________________________
Users mailing list
[email protected]
http://openlayers.org/mailman/listinfo/users