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")


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.

  • Does the same request work if you send the request directly to GeoServer, rather than using OpenLayers to construct it first? – nmtoken Jan 20 '16 at 13:21
  • Nope. If I execute the request on my browser I get again all the layer: localhost:8080/geoserver/gwc/service/… – user1919 Jan 20 '16 at 13:25

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.

  • Thank you so much. I was fighting with this so much time. I have tried everything but couldn't figure it out. I even tried to send the request without the 'gwc' part but I have left the 'service'. Now it works perfectly and a big questionmark in my head has disappeared! Thanks :) – user1919 Jan 20 '16 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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