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 bbd2647 commit 5eab3d4
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
Expand Up @@ -509,4 +509,16 @@ describe('TileLayer', () => {
layer.setUrl(placeKitten);
});
});

describe('#getTileUrl', function () {

Check failure on line 513 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected function expression

Check failure on line 513 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected function expression
it('can call with static coords', function () {

Check failure on line 514 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected function expression

Check failure on line 514 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected function expression
// Layer is not added to the map
var layer = L.tileLayer('http://example.com/{z}/{x}/{y}.png');

Check failure on line 516 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected var, use let or const instead

Check failure on line 516 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

'L' is not defined

Check failure on line 516 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected var, use let or const instead

Check failure on line 516 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

'L' is not defined
var url = layer.getTileUrl({z: 1, x: 2, y: 3});

Check failure on line 517 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected var, use let or const instead

Check failure on line 517 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected var, use let or const instead
expect(url).to.equal('http://example.com/1/2/3.png');
layer.addTo(map)

Check failure on line 519 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon

Check failure on line 519 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon
var url = layer.getTileUrl({z: 1, x: 2, y: 3});

Check failure on line 520 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected var, use let or const instead

Check failure on line 520 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

'url' is already defined

Check failure on line 520 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected var, use let or const instead

Check failure on line 520 in spec/suites/layer/tile/TileLayerSpec.js

View workflow job for this annotation

GitHub Actions / lint

'url' is already defined
expect(url).to.equal('http://example.com/1/2/3.png');
});
});
});
5 changes: 2 additions & 3 deletions src/layer/tile/TileLayer.js
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) {

Check failure on line 213 in src/layer/tile/TileLayer.js

View workflow job for this annotation

GitHub Actions / lint

Expected method shorthand

Check failure on line 213 in src/layer/tile/TileLayer.js

View workflow job for this annotation

GitHub Actions / lint

Expected method shorthand
const maxZoom = this.options.maxZoom,
zoomReverse = this.options.zoomReverse,
zoomOffset = this.options.zoomOffset;
Expand Down

0 comments on commit 5eab3d4

Please sign in to comment.