[OpenLayers-Trac] [OpenLayers] #3389: Vector.getFeatureBy returns nothing, while firebug shows the data

OpenLayers trac-20090302 at openlayers.org
Tue Jun 28 07:44:48 EDT 2011


#3389: Vector.getFeatureBy returns nothing, while firebug shows the data
---------------------+------------------------------------------------------
 Reporter:  cspan    |       Owner:              
     Type:  bug      |      Status:  new         
 Priority:  minor    |   Milestone:  2.12 Release
Component:  general  |     Version:  2.10        
 Keywords:           |       State:              
---------------------+------------------------------------------------------
 I created an in-memory layer, with a single vector (a point) , basically
 an entire sample off site:

 var vector = new OpenLayers.Layer.Vector("testvectorlaag");
 var point = new OpenLayers.Geometry.Point(-72, 42);
 var feature_point = new OpenLayers.Feature.Vector(point,
 {loc_code:'AA0123456789'});
 vector.addFeatures([feature_point]);
 map.addLayer(vector);

 Now I made a second function to search for that specific point, using the
 getFeatureBy function:
 var feature = layer.getFeatureBy('loc_code', 'AA0123456789');

 It always returns null.

 I believe it's because of this line, line 843 in
 OpenLayers/Layer/Vector.js:
 if(this.features[i][property] == value) {

 "this.features[i][property]" returns undefined with firebug, whereas my
 watch shows everything filled.

 I still see the same code in 2.11 RC1, so I'm thinking it works the same
 there. (not tested though)

 Also, I would expect to be able to use getFeaturesBy to get an array of
 features. For instance, I would like to use that function to get all
 features with some field set to some value to select/highlight them. The
 current getFeatureBy only returns the first found feature.

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


More information about the Trac mailing list