[GIS] WMS GetFeatureInfo and CQL on Multiple Layers

geoservergetfeatureinfoopenlayers-2

I am having issues with querying CQL filtered layers with OpenLayers and GeoServer, using the GetFeatureInfo control. It is ignoring the CQL filter and just querying the entire layer (as evidenced by both the results and the request it sends to GeoServer).

I've seen examples where the CQL filter is passed to GeoServer along with the GetFeatureInfo request, but I have several layers visible and each of them has a different CQL filter; so I'm not sure how/if I can handle this by appending my filter to the request URL.

Does anyone have any ideas how I can solve or work around this issue?

Best Answer

As stated above, you add an extra ;-separated CQL query for each layer. 1st query aligns to the 1st layer, 2nd to 2nd, etc. So, even if you want the same query on each layer, it'd be something like:

https://server.com/geoserver/site/wms?service=WMS&version=1.1.0&request=GetMap
&styles=&bbox=-180.0,-90.0,180.0,90.0&width=660&height=330&srs=EPSG:4326&format=kml
&layers=site:layer1,site:layer2,site:layer3,site:layer4
&CQL_FILTER=aoi_id=2;aoi_id=2;aoi_id=2;aoi_id=2