On Wednesday, August 19, 2009, John Cartwright <[email protected]> wrote: > > 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?
You are correct. And using destroyFeatures is better IMO - less code on the application side. Cheers, -- Eric Lemoine Camptocamp France SAS Savoie Technolac, BP 352 73377 Le Bourget du Lac, Cedex Tel : 00 33 4 79 44 44 96 Mail : [email protected] http://www.camptocamp.com _______________________________________________ Users mailing list [email protected] http://openlayers.org/mailman/listinfo/users
