0

I have problem in zoom fitting the selected polygon of WMS Layer. For example, I have a World shapefile. I make a dropdown menu for country names, I did when I choose a country from dropdown menu only that polygon shown on map. But this selected polygon is not zoomed automatically.

When it is selected, I want it to zoom automatically. How can it be done?

I tried to implement L.wmsImage method of "Leaflet-geoserver-request" plugin for solving my problem, for the reference https://github.com/iamtekson/leaflet-geoserver-request. But not get any result, following is my sample code:

var wmsImage = L.Geoserver.wmsImage("http://localhost:8080/geoserver/hindi_wrkspc/wms",{
    wmsLayers: ["hindi_wrkspc:country",],
    wmsCQL_FILTER: ["country_name =='India'" ],
    wmsStyle: ["hindi_wrkspc:country",],
    format: "image/png",
    wmsId: "wmsImage",
    width: 600,
    height: 600,
    transparent: true,
  });

When I run it, there is no error showing in console as well as not get any result. How can I solve my problem?

7
  • does gis.stackexchange.com/a/55233/79 help?
    – Ian Turton
    Nov 16, 2021 at 11:29
  • Looking at docs.geoserver.org/latest/en/user/tutorials/cql/…, it appears that the CQL filter doesn't handle any particular zooming, rather it just shows or hides data. So what you have is expected behaviour. If you want to zoom I think you'll need to hold the BBOX for the countries, and then supply that as the BBOX for the GetMap request
    – nmtoken
    Nov 16, 2021 at 11:45
  • @nmtoken yes sir I read your suggested document "docs.geoserver.org/latest/en/user/tutorials/cql" . For zooming selected polygon I used "Leaflet-geoserver-request" plugin, here is the link for plugin github.com/iamtekson/leaflet-geoserver-request. In this plugin L.geoserver.wmsImage() method is used for Zooming to desired location, implement it in my code but didn't get any success. Nov 16, 2021 at 12:18
  • @Ian Turton - Sir it is helpful. But I need to to do it as wms not as wfs. Your solution is done on wfs layer. I want solution for wms Layer. I want to automatically zoomfit the polygon of wms layer which is selected. Nov 18, 2021 at 6:55
  • A WMS service returns a picture of the data you can not reliably extract meaningful information from it - if you require actual data you must use a WFS or WCS endpoint to fetch actual data.
    – Ian Turton
    Nov 18, 2021 at 12:04

1 Answer 1

1

1- Why do you use L.geoserver.wmsImage instead of leaflet WMS?

https://leafletjs.com/examples/wms/wms.html

2- You can use GetFeatureInfo WMS request at first and fetch the geom. Afterwards you can fit the bbox and wmsImage if you need the image.

https://docs.geoserver.org/stable/en/user/services/wms/reference.html?highlight=wms

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Nov 22, 2021 at 17:07

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.