Is it possible to request the bounding box of a WMS from GeoServer?
In my case I have a WMS that I show with L.TileLayer.WMS
in a Leaflet map. I like to center and zoom my map to the WMS.
1 Answer
If you check the response of the GetCapabilities request, you'll see that each layer has a Bounding Box property, which gives its extent.
For example, you'll get something like:
<LatLonBoundingBox minx="-123.042" miny="42.251" maxx="-122.772" maxy="42.438" />
<BoundingBox SRS="EPSG:4326" minx="-123.042" miny="42.251" maxx="-122.772" maxy="42.438" />
You will have to parse this yourself, using pure JavaScript Code. Leaflet doesn't have anything for parsing this.
-
can you give me a quick demo? I just tried the
getCapabilities
request, it shows the errorAccess to XMLHttpRequest at 'http://localhost:8080/geoserver/wms?service=wms&version=2.0.1&request=GetCapabilities' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
how can I solve this error Commented Dec 16, 2019 at 10:05