Search code examples
javascriptleafletmapswms

Get min zoomlevel of WMS in leaflet


I am implementing several external WMS services in my application. unfortunately, these WMS Services do not pass on information on the minimum zoom level of the tiles, only about the extend of the WMS layers. Is there a way to dervice the minimum zoom level, on which the WMS starts to display?


Solution

  • unfortunately, these WMS Services do not pass on information on the minimum zoom level of the tiles

    ...because WMS is not aware of the concept of tiles, but rather use arbitrary bounding boxes. Those services might include information about MinScaleDenominator and MaxScaleDenominator (please refer to the WMS 1.3.0 specification document, page 27, section 7.2.4.6.9).

    There are some caveats, though:

    • Leaflet does not query nor parse the WMS GetCapabilities document, so it does not get information about MinScaleDenominator or MaxScaleDenominator.
    • The scales in the WMS side of things are unit-less ratios (as they assume 1px = 0.28mm). In Leaflet, the scale of the map's CRS is pixels per 360 degrees of longitude (when using the default L.CRS.EPSG3857).

    So it's possible, but it requires the WMS service to expose the right data, and it requires you to handle the GetCapabilities document and perform some math on the scale factors.