[OpenLayers-Users] erase drawn features

Mike Quentel mikequentel at yahoo.com
Wed Apr 18 16:48:16 EDT 2007


So, attaching an erase drawing features function to an onclick event of an icon (outside of the OL API) was simple, but how might I actually turn this into an OL control?  This is supposed to erase all drawn features upon the user clicking a button.  Would I need to implement a class that inherits from OpenLayers.Control?  Here is what I started...

OpenLayers.Control.EraseFeatures = OpenLayers.Class.create();
OpenLayers.Control.EraseFeatures.prototype = 
  OpenLayers.Class.inherit( OpenLayers.Control, {
    /** @type OpenLayers.Control.TYPES */
    type: OpenLayers.Control.TYPE_TOGGLE,

    destroyDrawingFeatures: function () {
      for(i = 0; i < map.layers.length; i++) { 
        var currentLayer = map.layers[i];
        if (currentLayer.isVector) {
          currentLayer.destroyFeatures();
        } //if (currentLayer...
      } // for (i = 0...
    },

    /** @final @type String */
    CLASS_NAME: "OpenLayers.Control.EraseFeatures"
});

Just not sure how to hook this up to a control panel so that features are erased upon the click event of the button.  Do I need a Handler class?  Not sure what to do next.

Thanks for any advice on this.

Mike Quentel

----- Original Message ----
From: Mike Quentel <mikequentel at yahoo.com>
To: users at openlayers.org
Sent: Friday, 6 April, 2007 3:45:26 PM
Subject: Re: [OpenLayers-Users] erase drawn features

Tim, thank you.

This seems to work well:

 function destroyDrawingLayer() {
   for(i = 0; i < map.layers.length; i++) { 
     var currentLayer = map.layers[i];
     if (currentLayer.isVector) {
       currentLayer.destroyFeatures();
     } //if (currentLayer...
   } // for (i = 0...
 } //function destroyDrawingLayer...

Mike Quentel

----- Original Message ----
From: Tim Schaub <noreply at geocartic.com>
To: users at openlayers.org
Sent: Friday, 6 April, 2007 10:59:56 AM
Subject: Re: [OpenLayers-Users] erase drawn features


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

_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users





        
___________________________________________________________ 
What kind of emailer are you? Find out today - get a free analysis of your email personality. Take the quiz at the Yahoo! Mail Championship. 
http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk 





      ___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/ 



More information about the Users mailing list