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 authored and Falke-Design committed Jul 7, 2024
1 parent 35d79e0 commit a3ea289
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 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 @@ -511,4 +511,16 @@ describe('TileLayer', () => {
layer.setUrl(placeKitten);
});
});

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');
});
});
});
5 changes: 2 additions & 3 deletions src/layer/tile/TileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const 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) {
const invertedY = this._globalTileRange.max.y - coords.y;
Expand Down Expand Up @@ -210,8 +210,7 @@ export const TileLayer = GridLayer.extend({
e.tile.onload = null;
},

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

0 comments on commit a3ea289

Please sign in to comment.