[GIS] Adding WMS layer with CQL filter

cql-filtergeoserverjavascriptleafletwms

I would like to add to my leaflet's web map layer from my WMS service (Geoserver), but I need to use CQL filter in GetMap link:

localhost/geoserver/my_location/wms?(...)&CQL_FILTER=[...]

Is it possible? Please, help 😉

edit:

var heatmap = L.tileLayer.wms('http://my_wms_adress:8080/geoserver/my_location/wms?service=WMS&version=1.1.0&request=GetMap&layers=my_location:my_location_history&styles=&bbox=54.406021,18.531216,54.497708,18.577851&width=768&height=390&srs=EPSG:4326&format=application/openlayers&CQL_FILTER=user_id=1', {layers: 'my_location_history', format: 'image/png',transparent: true})

As you can see I added all parameters, but IMHO it's wrong, but I am not sure how to do it. Can I skip parameters like bbox, width, height and add only CQL_FILTER?

Best Answer

Your code contains:

&CQL_FILTER=user_id=1

And I will guess that the two =s are messing up the URL.


In Leaflet WMS tilelayers, any extra options which are not defined will be passed to the WMS server as parameters in each request URL, so:

var layer = L.tileLayer.wms(
    'http://my_wms_adress:8080/geoserver/my_location/wms', 
    {
        layers: 'my_location_history',
        format: 'image/png',
        transparent: true,
        CQL_FILTER: 'user_id=1'
    }
)

Note that you do not need to specify the WMS version, request=GetMap or any other standard WMS parameters in the URL template.

Also, do check the Leaflet WMS tutorial.

Related Question