[OpenLayers-Users] Is there a way to dynamically get the feature id of a feature from a WMS layer?

cgp carina_palanca at forcorp.com
Fri Dec 18 17:29:45 EST 2009


Sorry, I got my variable names wrong and I didn't explain that very well. But
anyway, I figured it out. 

You can access the following from any vector layer:
The "fid" with vector_layer.feature.fid, which should look something like
"layer_prefix.layer_name.n", where n is an integer.
The "id" with vector_layer.feature.id, which should look something like
"OpenLayers.Feature.Vector_n", where n is an integer.

My problem was trying to get the "id" so I can use the function
vector_layer.getFeatureById(id). I don't know the "id" in advance, but I can
get the "fid" from a WMS layer.

All I did was have a for-loop that will look for the feature with the
particular "fid" and get the "id" from there:
                var feature_id = layer_prefix.layer_name.n; <-- here is the
FID
		var layer_features = vector_layer.features;
		for (var i=0; i<layer_features.length;i++){
		    if (layer_features[i].fid==feature_id) {
		    	var layer_id = layer_features[i].id;    <--- here is the ID
		    	return layer_id;
		    }
		}


Now I have another problem, which I posted on a different thread 
http://n2.nabble.com/Trouble-with-accessing-vector-WFS-layer-features-td4189252.html
here 



Stephen Woodbridge wrote:
> 
> cgp wrote:
>> I've been trying this for about a week now but I can't find anything.
>> Maybe
>> I'm missing something?
>> 
>> It seems that the "feature id" and the "fid" are different. I can get the
>> "fid" dynamically (from getfeatureinfo on a WMS layer) but not the
>> "Feature_id".
> 
> I think a little more info is needed.
> 
> Where is "Feature_id" defined?
> What is the layer definition?
> Is if common from mapserver? Show us the mapfile LAYER definition.
> What have you tried so far?
> 
> -Steve W
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> 

-- 
View this message in context: http://n2.nabble.com/Is-there-a-way-to-dynamically-get-the-feature-id-of-a-feature-from-a-WMS-layer-tp4183834p4189257.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list