Skip to content

Commit

Permalink
Honour coords.z when passed to TileLayer.getTileUrl
Browse files Browse the repository at this point in the history
cf #6004 #6006

Before this change, `coords.z` would not taken into account, and
was always overriden by `this._tileZoom`.
In the normal flow, `coords.z` is anyway set from `this._tileZoom`
before `getTileUrl` is called (in GridLayer._update). But this
prevents using `getTileUrl` out of this `_update` method.
There are some scenarios where this is needed (see #5822), or
(which is the case in uMap) when wanting to display a tile as
a tilelayer preview.
  • Loading branch information
yohanboniface committed Dec 28, 2023
1 parent e32941d commit f28bf98
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 12 additions & 0 deletions spec/suites/layer/tile/TileLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,4 +479,16 @@ describe('TileLayer', function () {
}, 250);
});
});

describe('#getTileUrl', function () {
it('can call with static coords', function () {
// Layer is not added to the map
var layer = L.tileLayer('http://example.com/{z}/{x}/{y}.png');
var url = layer.getTileUrl({z: 1, x: 2, y: 3});
expect(url).to.equal('http://example.com/1/2/3.png');
layer.addTo(map)
var url = layer.getTileUrl({z: 1, x: 2, y: 3});
expect(url).to.equal('http://example.com/1/2/3.png');
});
});
});
11 changes: 5 additions & 6 deletions src/layer/tile/TileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export var TileLayer = GridLayer.extend({
s: this._getSubdomain(coords),
x: coords.x,
y: coords.y,
z: this._getZoomForUrl()
z: this._getZoomForUrl(coords.z)
};
if (this._map && !this._map.options.crs.infinite) {
var invertedY = this._globalTileRange.max.y - coords.y;
Expand Down Expand Up @@ -200,11 +200,10 @@ export var TileLayer = GridLayer.extend({
e.tile.onload = null;
},

_getZoomForUrl: function () {
var zoom = this._tileZoom,
maxZoom = this.options.maxZoom,
zoomReverse = this.options.zoomReverse,
zoomOffset = this.options.zoomOffset;
_getZoomForUrl: function (zoom) {
const maxZoom = this.options.maxZoom,
zoomReverse = this.options.zoomReverse,
zoomOffset = this.options.zoomOffset;

if (zoomReverse) {
zoom = maxZoom - zoom;
Expand Down

0 comments on commit f28bf98

Please sign in to comment.