[OpenLayers-Users] getFeatureInfo() Only Works on One Layer?

Christopher Schmidt crschmidt at metacarta.com
Tue Jan 27 16:59:56 EST 2009


On Tue, Jan 27, 2009 at 02:59:10PM -0700, Bill Thoen wrote:
> I've got a WMS layer that has two sub-layers in it and I'm trying to get 
> attribute information from them via a getFeatureInfo request, but I can 
> only get one of them to respond at a time. I've looked at the docs at  
> http://trac.openlayers.org/wiki/GetFeatureInfo and noticed that you can 
> specify several layers with the QUERY_LAYERS parameter, but I'm finding 
> that only the one listed first is active. Also, it's not clear what 
> layer you specify at the root of the request, but it looks like it's 
> supposed to be different from the layers you're querying. Anyway, here's 
> what I'm trying:
> 
> I open and load the combined layer like so:
>   base = new OpenLayers.Layer.WMS(
>     "Base",
>     "http://192.168.0.250/cgi-bin/mapserv?map=base.map",       
>     { layers: ["us_states", "us_interstate"] }
>   );
>   map.addLayer(base);
> 
> 
> And here's the request string I'm sending to MapServer:
> 
> var url = base.getFullRequestString({
>   REQUEST: "GetFeatureInfo",
>   EXCEPTIONS: "application/vnd.ogc.se_xml",
>   FORMAT: 'png',
>   BBOX: map.getExtent().toBBOX(),
>   X: event.xy.x,
>   Y: event.xy.y,
>   INFO_FORMAT: 'text/plain',
>   QUERY_LAYERS: "us_interstate, us_states",
>   FEATURE_COUNT: 1,
>   WIDTH: map.size.w,
>   HEIGHT: map.size.h},
>   "http://192.168.0.250/cgi-bin/mapserv?map=base.map&");
>  OpenLayers.loadURL(url, '', this, setHTML);
> 
> Note the QUERY_LAYERS line. As shown here, it responds with interstate 
> attributes only when I click on an interstate roadway feature, but I get 
> nothing when I click on a state. If I reverse the order of these layers 
> in the list, then clicking on a state returns attributes from the 
> us_states table only. Even if I click on a spot where features in both 
> layers coincide, it returns only the attributes for the layer listed first.

You've got 'feature_count' set to 1. If you want the possibility of
multiple features, I would recommend setting that to something higher. I
believe that if this is '1', it will also limit the number of layers
queried. 

I recommend that if you need further assistance on getting a URL to
return content that you want, the MapServer list may be better suited:
OpenLayers contributors are generally speaking going to be more
knowledgable about how to get the browser to send the URL in question,
while MapServer contributors are more likely to be able to answer why a
given URL returns what it does.

Best Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list