Time for Action – destroying features
Let's demonstrate the difference between removeFeatures
and destroyFeatures
.
Open up the first example from the chapter. We'll use Firebug again.
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));
Now, let's add it to the map:
map.layers[1].addFeatures([feature_point]);
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 themap.layers[1].features
array, or pass in a feature object we've already created. Let's use the second method:map.layers[1].removeFeatures([feature_point]);
Now you should not see any features on your map. If we check the
map.layers[1].features
array, it should be empty:>>>map.layers[1].features; []
So, as we expected, the feature we originally...