1

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?

http://SERVER.com/geoserver/Workspace/wms?VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=Workspace:Layer&STYLES=Point&BBOX=3026,2004,657587,1244444&SRS=EPSG:27700&WIDTH=570&HEIGHT=1035&FORMAT=image/png&TRANSPARENT=TRUE&CQL_FILTER=NAME='Leeds'

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,
        CQL_FILTER:NAME='Leeds'

    });



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

Try this:

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

    });

EDIT

In case you want to query more params:

CQL_FILTER:'param=value&param1=value1&...'

EDIT 2

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
0

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'" 
}).addTo(map);

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 hmtl button or some other way with javscript

<button onclick="filterUpdate()"> </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.