Leaflet.TileLayer.Fallback
Leaflet.TileLayer.Fallback copied to clipboard
Fix out-of-range tile indices for tms
Closes #13.
Hi,
Thank you so much for this PR! :+1: Sorry for the delay in reviewing it...
Thinking further about it, I do not know how computation intensive are the calls to map.getPixelWorldBounds
and this._pxBoundsToTileRange
, but it looks like a waste calling them for every tile with getTileUrl
, whereas in Leaflet GridLayer they are called only once per view update.
As you pinpointed it from the beginning, we actually need to call them when the zoom changes, i.e. in the case of this plugin, when it tries requesting tiles from a lower zoom to replace a missing tile.
Therefore it seems to me that we would basically need instead to compute them once for each zoom, and possibly cache their result in a dictionary {[zoom]: maxY}
.
I suspect the result is dependent only on the zoom value (to be checked).
I missed this issue/pr, the options.tms bug threw me for a loop for a bit, and I came up with my own approach, though it wouldn't surprise me if it's naïve in ways I don't understand. If the tile range is fixed by zoom level, then the calculation is simple:
if (this.options.tms) {
var zDifference = this._getZoomForUrl() - coords.z;
tmsY = ((this._globalTileRange.max.y + 1) / Math.pow(2, zDifference)) - 1 - coords.y;
}