Our application uses Leaflet to display various kinds of maps (TMS, WMS, WMTS, XYZ etc.) as well as GeoJSON objects on the map. The problem is in how we define and use the WMS maps and layers.
We're using a library to convert the XML response of the
GetCapabilities request to a JSON and then we parse with our own implementation the WMS version, BoundingBox, CRS,
minZoom (from MaxScaleDenominator and MinScaleDenominator) and layer names for the layers that we want to use. that we use when adding the WMS layers for Leaflet. We use Leaflet with the default CRS (
EPSG:3857). However, the BoundingBox for a couple WMS layers don't seem to work as I expect them to work. I have created some simple implementations for describing the issue:
The first test implementation can be found from this github gist. There are two files:
leaflet_with_epsg3857_bounds.html. With the
_no_bounds.html version the overlays are displayed on the Map as they should, but obviously Leaflet is loading new tiles every time the Map is panned or zoomed on, regardless of where we are panning (because the bounds are not defined for the layers if I'm not wrong?). With the
_epsg3857_bounds.html version I have a couple problems:
- Leaflet doesn't seem to request and render the
Map_With_Not_Working_Boundsat all, regardless of where I'm panning or zooming at.
Does anyone have any idea why not?
I manually copied and pasted the boundaries from the
GetCapabilities response to the
bounds object when creating and adding the layer to Leaflet
2. Leaflet STILL seems to request and render the
Map_With_Working_Bounds, regardless of where I'm panning or zooming at.
Am I wrong thinking that the bounds are there to let Leaflet know when it actually should request the tiles, and when not?
The second test implementation can be found from this github gist. Here we have three files:
leaflet_2_with_epsg3857_bounds.html. Problems with these:
- With the
_no_boundsversion Leaflet is requesting the tiles constantly when zooming and panning, but it works very inconsistently. Sometimes the tiles are returned from the service and rendered on the map, and sometimes not (try multiple different zoom levels and toggling the layers on and off).
_epsg4326_bounds.htmlversion works exactly the same (why is that? The Leaflet map is using
EPSG:4326, how and why do the
EPSG:4326boundaries work at all?)
_epsg_3857_bounds.htmlversion doesn't seem to request any tiles EVER.
Why could that be?
I've been trying to Google and read through the WMS documentation to resolve these issues and I feel like I can't research this any more on my own, hence I'm asking for help. I've also tried using all these layers in QGIS, and they seem to work better in QGIS, though QGIS seems to always request tiles with EPSG:4326 even though I've set the project and layers to use EPSG:3857, so I can't really tell if that helps much.
EDIT: I edited the Gist test implementations a bit, they were missing the
version definition and
crs as well in some cases (Leaflet uses 1.1.1 by default if not defined)