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?

4 Answers 4


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:

  • How do you provide one filter for all layers without repeating the filter in url?
    – Dariush
    Oct 17, 2017 at 9:38

You need to provide one filter for each layer (or a blank filter) each filter is separated by a ; - see http://ian01.geog.psu.edu:80/geoserver/wms?request=GetMap&layers=tiger:poly_landmarks,tiger:tiger_roads&styles=,&bbox=-73.97,40.74,-73.93,40.78&Format=image/png&width=344&height=500&srs=EPSG:4326&cql_Filter=LANAME%20=%20%27East%20River%27;NAME%20=%20%27West%20Rd%27 for example.


I am looking at this also. My problem is different since I am not sure how to address the correct layer. I found this: http://www.azavea.com/blogs/labs/2011/06/using-the-cql_filter-parameter-with-openlayers-wms-layers/

But I think I understand your problem. You would have to make a function that grabs the search term (or static search) and sends the call differently to each layer. I am using a search box and checkbox to where to search. Click the checkbox (MyRadios) and enter the search query. On the form have a submit trigger the function and supress default action. I use ExtJS but you would get the value of the checked radio button along with the input field. If you want the radio button option you can use an if statement to change the param according to the checked radio value.

 function CQLfilter(param){ //param here would be the search value
        // send different request to different layers
     req1 = "field1 LIKE '%" + param + "%'";
     req2 = "field2 LIKE '%" + param + "%'";
     req3 = "field3 LIKE '%" + param + "%'";  
     wms_layer1.mergeNewParams({'CQL_FILTER': req1});
     wms_layer2.mergeNewParams({'CQL_FILTER': req1});
     wms_layer3.mergeNewParams({'CQL_FILTER': req1})
function resetCQLfilters() {
    delete wms_layer1.params.CQL_FILTER;
    delete wms_layer2.params.CQL_FILTER;
    delete wms_layer3.params.CQL_FILTER;

This is just a shot. My problem is I am using a function to create and load the layers but do not know how I then get the layer name. Do you know what my layername would be in my example?

var createWmsLayer = function(name, url, params, options) {
        map.addLayer(new OpenLayers.Layer.WMS(name, url, params, options));

createWmsLayer("<span class='locc'>Ikke listet</span>", "http://localhost/geoserver/wms",
                {layers: 'gbif_ns:ikke_listet',format: 'image/png', transparent: 'true'}, {singleTile: true, ratio: 1, isBaseLayer:false, visibility: false}



I was trying to do something similar with the WMSGetFeatureInfo control and @JayCrossler's answer above pointed me in the correct direction. I found that for each layer that you want to include in the query you need to check if there is an existing CQL_FILTER and apply this filter to the vendorParams parameter. Note the usage of INCLUDE to represent an empty filter.

// Add filter for each layer where lyrs is an array of the layers to query
var filter = '';
for (var i = 0; i < lyrs.length; i++) {

    if (lyrs[i].params && lyrs[i].params.CQL_FILTER) {
        filter += lyrs[i].params.CQL_FILTER;
    } else {
        filter += 'INCLUDE';
    if (i < lyrs.length-1) {
        filter += ';';

new OpenLayers.Control.WMSGetFeatureInfo({
    vendorParams: {
        CQL_FILTER: filter
  • +1 for the use of INCLUDE as an empty filter. I couldn't manage to find that...
    – Auspex
    Mar 22, 2017 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.