I have a CQL filter that only displays a certain number of points, however when I try to apply the CQL to my existing leaflet map through the options for a layer nothing displays. No errors are thrown in the console.

Any ideas?


Below is what I have tried

 var FilterWMSlayer= L.tileLayer.wms("http://Server.com/geoserver/Workspace/wms", 
        layers: 'Workspace:Layer',
        format: 'image/png',
        transparent: true,


   var FilterWMSlayer= L.tileLayer.wms("http://Server.com/geoserver/Workspace/wms", 
        layers: 'Workspace:Layer',
        format: 'image/png'&CQL_FILTER=NAME='Leeds',
        transparent: true

Try this:

 var FilterWMSlayer= L.tileLayer.wms("http://Server.com/geoserver/Workspace/wms", 
        layers: 'Workspace:Layer',
        format: 'image/png',
        transparent: true,



In case you want to query more params:



I've updated your fiddle. http://jsfiddle.net/ZkC5M/274/

The problem is the quotes.

cql_filter : "RMIGroup = 'Almond Catchment ARMI'"

Use double quotes " for the entire string you pass to cql_filter and single quotes for the value of the property.

  • No luck however I noticed CQL_FILTER=NAME=%27Almond%20Catchment%27 instead of CQL_FILTER=NAME='Almond Catchment' when I submit the URL which returns the working map – Environment Apr 12 '16 at 20:31
  • For some reason it displays properly without the CQL filter when using leaflet however when I add it the SRS gets set to srs:"EPSG:3857" but still a blank box – Environment Apr 12 '16 at 20:51
  • That's because the browser is scaping some character entities to format the URL. I think my approach is correct. Note that you have to pass a String to cql_filter. You're doing cql_filter : name='Almond Catchment' . The correct way is cql_filter : 'name=Almond Catchment'. – Jose Hermosilla Rodrigo Apr 12 '16 at 20:57
  • cql_filter : 'NAME=Almond Catchment' No luck, but the SRS does change from 27700 to 3857 as soon as I add the CQL filter. I may have to pull a JS fiddle together – Environment Apr 12 '16 at 21:10
  • Yes! It would help to answer your question. =) – Jose Hermosilla Rodrigo Apr 12 '16 at 21:12

Simply Set CQL Filter with onclick Function:

    var map = L.map('mapid').setView([39.998769, -75.1448316], 10);
    var wmsLayer = new L.TileLayer.WMS('http://localhost:8080/geoserver/IA/wms', {
        layers: 'IA:final_table',
        format: 'image/png',
        transparent: true,
        version: '1.3.0',
        crs: L.CRS.EPSG4326,
        maxZoom: 20,
        // set deafult cql_filter
        // cql_filter : "STATE_CODE = 'AL'" 

Onclick Function for CQL FIlter

    function filterUpdate(){
        // access global variable with wmsLayer and set the Prams with setParams Function
        wmsLayer.setParams({CQL_FILTER:"STATE_CODE = 'AL' AND update = FALSE"});

use it with HTML button or some other way with javascript

    <button onclick="filterUpdate()">CQL Filter Button</button>

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.