Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

migrated from stackoverflow.com May 3 '12 at 19:57

This question came from our site for professional and enthusiast programmers.

4 Answers

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;
    wms_layer1.redraw();
    delete wms_layer2.params.CQL_FILTER;
    wms_layer2.redraw();
    delete wms_layer3.params.CQL_FILTER;
    wms_layer3.redraw();
    }

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}
                        );

~asle

share|improve this answer
add comment

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
share|improve this answer
add comment

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
    }
});
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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