In previous versions of OpenLayers, we could filter WMS services with CQL. However, I can't filter my WMS services using CQL or other.

How do I do that in OpenLayers 3?

 var wmsLayer = new ol.layer.Tile({
    source: new ol.source.TileWMS({
        url: 'http://localhost:8282/geoserver/Isemri/wms',
        params: { 'LAYERS': 'Isemri:mahalleler' },
        serverType: 'geoserver',
        //query: 'OBJECTID_1=262'
        cql_filter: 'OBJECTID_1=237'

CQL filter is a vendor parameter provided by GeoServer, therefore you have to include the cql_filter in the params string object. OpenLayers 3's ol.source.TileWMS object only supports options you can see in the corresponding API page.

Also, in OpenLayers 2 you had to include cql_filter in the params object. Because of its limited input options, you didn't have to define the params parameter, just enter them between braces after the url parameter. You can read more about this in the OpenLayers 2 OpenLayers.Layer.WMS API page.

  • 2
    very very thanks bro ,I tried your suggestion and it worked ;) ` params: { 'LAYERS': 'Isemri:mahalleler', 'cql_filter': "OBJECTID_1=263" },` – Mürsel Dogrusözlü Sep 26 '14 at 11:23
  • I'm glad that it worked, you're welcome. :) – Gabor Farkas Sep 26 '14 at 11:24
  • guys does this work in OL3? Not in my case – user1919 Nov 13 '17 at 10:54

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.