Tek Kshetri
Tek Kshetri

Reputation: 2347

How to filter required data from leafletjs in WMS

I am using leaflet and geoserver. I want to fetch only required region using Web Map Service (WMS). I am able to fetch all of the region from geoserver. But what if I need only one region. I write the following code for show all the data;

//load data form geoserver
var mywms = L.tileLayer.wms("http://localhost:8080/geoserver/tajikistan/wms", {
    layers: 'tajikistan:country1',
    format: 'image/png',
    transparent: true,
    version: '1.1.0',
    attribution: "country layer"
});
mywms.addTo(map);

I want to add only one region (named as centre) from this server. I think I have to add the query in this dataset. But I don't know how can I query. Any help?

Upvotes: 0

Views: 1482

Answers (1)

Tek Kshetri
Tek Kshetri

Reputation: 2347

The WMS layer can be filtered by CQL_FILTER. Put option CQL_FILTER in code to filter required data;

L.tileLayer.wms("http://localhost:8080/geoserver/tajikistan/wms", {
    layers: 'tajikistan:country1',
    format: 'image/png',
    transparent: true,
    version: '1.1.0',
    attribution: "country layer",
    CQL_FILTER: "name_rg='centre'",
  });

Upvotes: 3

Related Questions