3

Along with Mapbox layers, we are also adding layers from WMS and ArcGIS servers hosted by our customers to display map data relevant to them. Is there any way to figure out what the max zoom for a layer is through code so the maxNativeZoom can be set to that so they always display even at zoom levels higher than their max zoom?

Another thing I've noticed is that certain areas of Canada have satellite imagery up to zoom level 17 while others have it up to 18. When moving to a specific location on the map, is it possible to figure out what the max zoom is in that area and then set the maxNativeZoom appropriately?

1

Not sure you can dynamically determine the maximum native zoom of a tile source (other than assuming it from 404 errors), if your server does not provide some meta-data on its service where this information would be provided.

A workaround would be to use Leaflet.TileLayer.Fallback plugin, which would "act" like maxNativeZoom option in the sense that when the server does not serve a tile (but returns a 404 error instead), the plugin will use a tile from a lower zoom level and scale it up as replacement.

Replaces missing Tiles (HTTP 404 Not Found Error) by scaled up equivalent Tiles from lower zooms.

By replacing tiles individually when needed (rather than all tiles past the maxNativeZoom level), this plugin would also naturally cover your second use case where only some areas are available at higher zoom levels.

Demo page: http://ghybs.github.io/Leaflet.TileLayer.Fallback/examples/tileLayerFallback-demo.html

However this plugin would not work as intended if your server does return a placeholder / error tile when no image is available, rather than returning a 404 error. The plugin would not be able to see the difference with a normal tile.

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.