[OpenLayers-Trac] [OpenLayers] #1587: undefined feature after (OpenLayers.Control.SelectFeature) unselectAll

OpenLayers trac at openlayers.org
Tue Jun 17 09:15:19 EDT 2008


#1587: undefined feature after (OpenLayers.Control.SelectFeature)  unselectAll
------------------------+---------------------------------------------------
 Reporter:  openlayers  |       Owner:     
     Type:  bug         |      Status:  new
 Priority:  minor       |   Milestone:     
Component:  general     |     Version:  2.6
 Keywords:              |       State:     
------------------------+---------------------------------------------------
 (OpenLayers.Control.SelectFeature) unselectAll loops over the
 selectedFeatures Array and (indirectly, by means of unselect(feature))
 removes features from that Array in the mean time. This may result in an
 undefined feature.

 We modified the code as follows:


     /**
      * Method: unselectAll
      * Unselect all selected features.  To unselect all except for a
 single
      *     feature, set the options.except property to the feature.
      *
      * Parameters:
      * options - {Object} Optional configuration object.
      */
     unselectAll: function(options) {
         // we'll want an option to supress notification here
         var feature;
         for(var i=this.layer.selectedFeatures.length-1; i>=0; --i) {
             feature = this.layer.selectedFeatures[i];
             if(!options || options.except != feature) {
                 // Don't call unselect feature because it will removeItem
 from
                 // this.layer.selectedFeatures which may result in a
 undefined feature
                 //this.unselect(feature);
                 // Instead copy the relevant code from: unselect(feature);
                 this.layer.drawFeature(feature, "default");
                 this.layer.events.triggerEvent("featureunselected",
 {feature: feature});
                 this.onUnselect(feature);
             }
         }
         // Be sure to remove all items from this.layer.selectedFeatures
         this.layer.selectedFeatures = [];
     },

-- 
Ticket URL: <http://trac.openlayers.org/ticket/1587>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer


More information about the Trac mailing list