diff --git a/spec/suites/layer/tile/TileLayerSpec.js b/spec/suites/layer/tile/TileLayerSpec.js index 27a6a516c..49659974b 100644 --- a/spec/suites/layer/tile/TileLayerSpec.js +++ b/spec/suites/layer/tile/TileLayerSpec.js @@ -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', () => { diff --git a/src/layer/tile/TileLayer.js b/src/layer/tile/TileLayer.js index ca54ba705..8c56550a0 100644 --- a/src/layer/tile/TileLayer.js +++ b/src/layer/tile/TileLayer.js @@ -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) {