[OpenLayers-Trac] [OpenLayers] #3232: Use hash for getFeatureById() and getFeatureByFid()

OpenLayers trac-20090302 at openlayers.org
Thu Mar 31 11:17:25 EDT 2011


#3232: Use hash for getFeatureById() and getFeatureByFid()
---------------------------------------------------------------------------------------+
 Reporter:  vog                                                                        |       Owner:  crschmidt   
     Type:  feature                                                                    |      Status:  new         
 Priority:  minor                                                                      |   Milestone:  2.11 Release
Component:  Layer.Vector                                                               |     Version:  SVN         
 Keywords:  performance, featureagent, vector, layer, getfeaturebyid, getfeaturebyfid  |       State:  Review      
---------------------------------------------------------------------------------------+
 The attached patch changes the getFeatureById() and getFeatureByFid()
 methods to use a hash instead of iterating over all features.

 The gain in performance is especially notable when dealing with a large
 number of vector features, and calling getFeatureById() from a mousemove
 event handler.

 In other words, the FeatureAgent (see https://github.com/ahocevar/ol-
 performance) benefits a lot from this.

 Note that two minor changes to the API were necessary for an efficient
 implementation:

  * On failure, these functions return "undefined" instead of "null". This
 is in order to be able to use the hash (Object) directly without an
 additional strange "undefined → null" conversion. For consistency,
 getFeatureBy() and getFeatureFromEvent() will also return "undefined"
 instead of "null".
  * Neither feature.id nor feature.fid may change after feature has been
 added to the layer, as there is no chance for the hashes to be updated
 afterwards. Of course, in real applications this will always be the case.
 However, one of the test cases does change the feature.fid for some
 strange reason, so it has to be adjusted. (BTW, the blame goes to me as it
 was me who wrote that test case.)

 Please review the patch.

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


More information about the Trac mailing list