rob-murray / os-leaflet

A Leafletjs TileLayer using Ordnance Survey OpenSpace web map service
http://rob-murray.github.io/os-leaflet/
MIT License
24 stars 8 forks source link

minNativeZoom: 0 and minZoom: negative int results in Uncaught Error: Attempted to load an infinite number of tiles #28

Closed jopfre closed 5 years ago

jopfre commented 5 years ago

When minNativeZoom: 0 and a negative minZoom value are set on the tile layer, zooming out results in Uncaught Error: Attempted to load an infinite number of tiles

To reproduce set options as follows in OSOpenSpace.js:

options = L.extend({
        crs: L.OSOpenSpace.CRS,
        tileSize: 200,
        minNativeZoom: 0,
        maxNativeZoom: 0,
        maxZoom: 0,
        minZoom: -2
}, options);`

Here are two minimal tests to show the issue. os-leaflet https://5amc.cf/test/os.html

open street maps with the same options passed scales the zoom level 0 tiles as expected. https://5amc.cf/test/l.html

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
          minNativeZoom: 0,
          maxNativeZoom: 0,
          maxZoom: 0,
          minZoom: -2
    }).addTo(map);

Any ideas what might be the cause? I'm happy to investigate but would appreciate pointers if you have any.

jopfre commented 5 years ago

The issue is actually to do with proj4leaflet, so I will close.

For those curious this post explains a bit https://github.com/kartena/Proj4Leaflet/issues/144#issuecomment-343730644

Essentially leaflet's default projection uses a scale factor rather than resolutions like proj4leaflet so can scale to arbitrary zoom levels.

In proj4leaflet each zoom level (resolution) must be defined first. So the solution in this case was to define an "imaginary" resolution in new L.Proj.CRS() and then set the minNativeZoom to a "real"resolution in L.OSOpenSpace.TileLayer options.