[OpenLayers-Users] getFeatureByFid

Yves Moisan yves.moisan at boreal-is.com
Thu Dec 18 16:08:58 EST 2008


> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: getFeatureByFid.patch
Type: text/x-patch
Size: 906 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/openlayers-users/attachments/20081218/c62fb95a/getFeatureByFid.bin


More information about the Users mailing list