[OpenLayers-Users] erase drawn features

Tim Schaub noreply at geocartic.com
Fri Apr 6 12:59:56 EDT 2007


Mike Quentel wrote:
> Please, advice on implementing functionality to erase all drawn features?

All drawn features are associated with a layer.  To remove features from 
a layer (which will also erase them), use:

     // given a vector layer and an array of features
     layer.removeFeatures(features);

To remove all features from a layer, you could use:

     layer.removeFeatures(layer.features);

Note that this is currently broken - and will be until the patch for 
#645 is in [1].

The layer.removeFeatures method doesn't actually destroy the features 
that you send it - so you could be leaking memory if you use this 
regularly.  If you want to actually get rid of all the features in a 
layer, use:

     // erase features and get rid of the evidence
     layer.destroyFeatures();

The one thing that is missing here is an eraseFeature or eraseFeatures 
method.  This would only temporarily erase the visual representation of 
the features - leaving them as part of the layer.features array. 
(Perhaps this will come with 2.5.)

Let me know if that doesn't answer your question.

Tim

[1] http://trac.openlayers.org/ticket/645




More information about the Users mailing list