[OpenLayers-Users] removeFeatures vs. destroyFeatures behavior

Ian iansgis at gmail.com
Tue Jul 22 17:56:11 EDT 2008


Hello,

I am drawing "highlight" circles in a vector layer as users select/deselect
features from another layer. After reading the docs and list I got the
impression that removeFeatures would remove a feature from the map but that
it would continue to exist in the features array and could lead to memory
leaks if overused. destroyFeatures on the other hand sounded like it would
permanently remove the feature from the map and array.

However I'm getting the opposite behavior. removeFeatures deletes the
feature and it is gone from the features array (redrawing the layer also
confirms this). destroyFeatures removes the feature from the map, but the
feature remains in the features array and redrawing the layer redraws the
deleted feature as well. Am I missing something?

Code snippets:

selFeatures = new OpenLayers.Layer.Vector("Selected Features", {style:""});

function updateSavedFeatures (name) {
  ...
  // Add highlight
  highlight = new OpenLayers.Feature.Vector(new
OpenLayers.Geometry.Point(saved[name].lon, saved[name].lat));
  highlight.fid = name;
  selFeatures.addFeatures(highlight);
  ...
  // Remove highlight
  for (var key in selFeatures.features) {
    if (selFeatures.features[key].fid == name) {
      selFeatures.removeFeatures(selFeatures.features[key]);
      //selFeatures.destroyFeatures(selFeatures.features[key]);
    }
  }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20080722/7fb39601/attachment.html


More information about the Users mailing list