Search code examples
leafletgeoserverwms

How can I zoomed to the cql_filter feature?


I am using geoserver. I write the following code;

const mywms = L.tileLayer.wms("http://localhost:8080/geoserver/taj/wms", {
    layers: 'taj:country',
    format: 'image/png',
    CQL_FILTER: 'name=pana'
    transparent: true,
    opacity: 0.4,
    version: '1.1.0',
    attribution: "country layer"
});

All is good. The layer get filtered. But I need the selected feature to zoom full extend. I tried to center the mywms layer using this code; map.fitBounds(mywms.GetBounds());. But it shows the error; mywms.getBOunds is not a function. Any help?


Solution

  • As is pointed out in the comments WMS requests contain the bounding box of the map in the request and so will always cover the whole of the map area.

    To get the extent of a single feature you need to make a WFS request with the filter included and then zoom to the extent of that feature when it is returned.