_globalTileRange is not recalculated on getTileUrl()
See original GitHub issueHow to reproduce
- Leaflet version I’m using: 1.3.1
- Browser (with version) I’m using: Chrome 65
- OS/Platform (with version) I’m using: macOS High Sierra
- Create simple tile TMS layer
- Run getTileUrl() for different zoom levels
What behaviour I’m expecting and which behaviour I’m seeing
Expecting: correct tile URLs
Observed behaviour: invalid tile URLs
Reason: please consider following piece of code from Leaflet with comment:
getTileUrl: function (coords) {
...
if (this._map && !this._map.options.crs.infinite) {
// Following line of code is invalid - the _globalTileRange is updated only when
// _setView() is called, which does not happen when calling getTileUrl()
// for different tile layers
var invertedY = this._globalTileRange.max.y - coords.y;
if (this.options.tms) {
data['y'] = invertedY;
}
data['-y'] = invertedY;
}
return template(this._url, extend(data, this.options));
}
The bug happens only for TMS layers, as only TMS layers go into the if (this.options.tms) { }
condition. The problem is that URLs of new tiles with zoom level, that is different from the current one (like in example, we are going from zoomMin=10
to zoomMax=12
), are not calculated correctly because of the irrelevant _globalTileRange
.
The _globalTileRange
needs to be somehow updated if the coords.z
parameter of the getTileUrl()
is different from the internal value of zoom, I think.
Minimal example reproducing the issue
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ghybs Thank you very much for the reply!
Indeed, using the
L.Util.template()
(assuming that coordinates are already known) really solved the issue! Final code:Hi,
Unfortunately, the
getTileUrl
method, while its name might be a bit misleading, is not meant to be used externally to generate URL from arbitrarycoords
input. As stated in the docs (emphasis mine):As you noticed, the
z
(zoom) property is discarded and only the current Tile Layer zoom (_tileZoom
) is used instead. I guess it is so because of the_globalTileRange
that is also dependent on zoom. While this scheme may be discussed, I do not have the history behind it to be able to determine whether this is for a reason or if it is unnecessarily complicated.But in your case, you really do not need to use
getTileUrl
at all: given that you already know thecoords
of the tiles you want to fetch, you only need they
reversal to fit your TMS scheme, then apply those coordinates to your URL template:Updated JSBin: https://jsbin.com/faditemita/1/edit?html,console,output