[GIS] CQL_filter parameter on WMS layer doesn’t work

cql-filtergeoserverwms

I am trying to filter my WMS layer using CQL_filter parameter as:

 wms_layer =  new OpenLayers.Layer.WMS( "Larisa","http://localhost/geoserver/gwc/service/wms",
            {
                layers: 'esot:clusternodes_', 
                format:  "image/png",
                CQL_FILTER: 'cluster=1',
                transparent: true,
                version: "1.1.1"
            },
            {
                displayOutsideMaxExtent: false,
                projection: new OpenLayers.Projection("EPSG:900913")
            }
        );

 map.addLayer(wms_layer); 

For some reason the filter doesn't work and all the layer is shown on the map.
I have checked the version and it must be correct. I use OpenLayers 2.12 and my GeoServer is 2.6.0.

I have tried to remove from the layer the workspace name ('esot') but then the layer fails completely to load.

Best Answer

You are actually making a GeoWebCache request not a simple WMS request so in general GWC ignores filters. The simple answer is to make your filtered request directly to GeoServer by changing http://localhost/geoserver/gwc/service/wms to http://localhost/geoserver/wms and all will work as you expect. This is the easiest answer as you are unlikely to want to cache the filtered layers anyway.

The other solution is to configure your cached layer to handle filters see this manual page for details.

Related Question