TileLayer: fix getTileUrl parameter regression (#9766)

This commit is contained in:
Simon Legner
2025-07-06 20:11:22 +02:00
committed by GitHub
parent 3fd10ee0a3
commit 181f6c3807
2 changed files with 23 additions and 3 deletions

View File

@ -440,6 +440,26 @@ describe('TileLayer', () => {
i++;
});
});
it('consults options.foo for {foo}', () => {
const OSMLayer = TileLayer.extend({options: {foo: 'bar'}});
const layer = new OSMLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png?{foo}').addTo(map);
map.options.zoomSnap = 0;
map._resetView(new LatLng(0, 0), 2.3);
const urls = [
'https://tile.openstreetmap.org/2/1/1.png?bar',
'https://tile.openstreetmap.org/2/2/1.png?bar',
'https://tile.openstreetmap.org/2/1/2.png?bar',
'https://tile.openstreetmap.org/2/2/2.png?bar'
];
let i = 0;
eachImg(layer, (img) => {
expect(img.src).to.eql(urls[i]);
i++;
});
});
});
describe('crossOrigin option', () => {

View File

@ -187,14 +187,14 @@ export const TileLayer = GridLayer.extend({
// Called only internally, returns the URL for a tile given its coordinates.
// Classes extending `TileLayer` can override this function to provide custom tile URL naming schemes.
getTileUrl(coords) {
const data = {
...this.options,
const data = Object.create(this.options);
Object.assign(data, {
r: Browser.retina ? '@2x' : '',
s: this._getSubdomain(coords),
x: coords.x,
y: coords.y,
z: this._getZoomForUrl()
};
});
if (this._map && !this._map.options.crs.infinite) {
const invertedY = this._globalTileRange.max.y - coords.y;
if (this.options.tms) {