O'Reilly logo

OpenLayers 2.10 by Erik Hazzard

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for Action – destroying features

Let's demonstrate the difference between removeFeatures and destroyFeatures.

  1. Open up the first example from the chapter. We'll use Firebug again.
  2. Before we remove features, we first need to add them to the map. We'll use the same code from the previous example. Let's create a feature object. In Firebug, type and execute:
    var feature_point = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(-72, 42));
  3. Now, let's add it to the map:
    map.layers[1].addFeatures([feature_point]);
  4. We have the feature on the map now, so let's see how removeFeatures works. We can call this function and either pass in a feature from the map.layers[1].features array, or pass in a feature object we've already created. Let's use the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required