> Because we haven't gotten a patch yet.

I stole the getFeaturebyFid at
http://openlayers.org/pipermail/commits/2007-October/003290.html and
plucked into a Layer.Vector object as follows :


pts_gps = new OpenLayers.Layer.Vector("GeoJSON", {
        strategies: [new OpenLayers.Strategy.BBOX()],
    protocol: new OpenLayers.Protocol.HTTP({
    url: fs_path + "/PGTEST4326",
     format: new OpenLayers.Format.GeoJSON()
      }),

    getFeatureByFid: function(fid) {
        var layer = this;
        if (!layer) {
                return null;
        }
        var features = layer.features;
        if (!features) {
                return null;
        }
        for (var i = 0; i < features.length; ++i) {
                if (features[i].fid == fid) {
                        return features[i];
                }
        }
},
        
styleMap: styleMap
         
});

In the Firebug console I can do 

selectControl.select(pts_gps.getFeatureByFid(1417))

and I'm all set.

Anyhow, I modified Layer.Vectors to pluck the method in, erased it in my
layer definition above and checked that it works.  Patch included, but
please test :-)

Yves
Index: Vector.js
===================================================================
--- Vector.js	(revision 8515)
+++ Vector.js	(working copy)
@@ -681,6 +681,32 @@
         }
         return feature;
     },
+   /**
+     * APIMethod: getFeatureByFid
+     * Given a fid, return the feature if it exists in the features array
+     *
+     * Parameters:
+     * featureFid - {String} (works with Number too, but don“t know why) 
+     *
+     * Returns:
+     * {<OpenLayers.Feature.Vector>} A feature corresponding to the given
+     * featureFid
+     */
+	getFeatureByFid: function(fid) {
+		var layer = this;
+		if (!layer) {
+			return null;
+		}
+		var features = layer.features;
+		if (!features) {
+			return null;
+		}
+		for (var i = 0; i < features.length; ++i) {
+			if (features[i].fid == fid) {
+				return features[i];
+			}
+		}
+	},
     
     /**
      * Unselect the selected features
_______________________________________________
Users mailing list
[email protected]
http://openlayers.org/mailman/listinfo/users

Reply via email to