[OpenLayers-Users] limiting a Vector layer to the last feature added

John Cartwright john.c.cartwright at comcast.net
Wed Aug 19 00:52:04 EDT 2009


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

  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090818/cceaec36/attachment.html


More information about the Users mailing list