diff --git a/spec/suites/layer/tile/TileLayerSpec.js b/spec/suites/layer/tile/TileLayerSpec.js index 2b1f702aa..8cac36369 100644 --- a/spec/suites/layer/tile/TileLayerSpec.js +++ b/spec/suites/layer/tile/TileLayerSpec.js @@ -1,5 +1,5 @@ import {expect} from 'chai'; -import {Browser, CRS, DomUtil, Map, TileLayer, Util} from 'leaflet'; +import {Browser, CRS, DomUtil, Map, TileLayer, Util, LatLng} from 'leaflet'; import sinon from 'sinon'; import {createContainer, removeMapContainer} from '../../SpecHelper.js'; @@ -418,6 +418,26 @@ describe('TileLayer', () => { expect(layer.options.attribution).to.eql(''); }); + it('requests tiles with an integer {z} when the map\'s zoom level is fractional', () => { + const layer = new TileLayer('http://example.com/{z}/{y}/{x}.png').addTo(map); + map.options.zoomSnap = 0; + map._resetView(new LatLng(0, 0), 2.3); + + layer.redraw(); + + const urls = [ + 'http://example.com/2/1/1.png', + 'http://example.com/2/1/2.png', + 'http://example.com/2/2/1.png', + 'http://example.com/2/2/2.png', + ]; + + let i = 0; + eachImg(layer, (img) => { + expect(img.src).to.eql(urls[i]); + i++; + }); + }); }); const _describe = 'crossOrigin' in DomUtil.create('img') ? describe : describe.skip; // skip in IE<11 diff --git a/src/layer/tile/TileLayer.js b/src/layer/tile/TileLayer.js index b7e97dc54..09ba7a032 100644 --- a/src/layer/tile/TileLayer.js +++ b/src/layer/tile/TileLayer.js @@ -224,8 +224,8 @@ export const TileLayer = GridLayer.extend({ _getZoomForUrl() { let zoom = this._tileZoom; const maxZoom = this.options.maxZoom, - zoomReverse = this.options.zoomReverse, - zoomOffset = this.options.zoomOffset; + zoomReverse = this.options.zoomReverse, + zoomOffset = this.options.zoomOffset; if (zoomReverse) { zoom = maxZoom - zoom; @@ -281,6 +281,10 @@ export const TileLayer = GridLayer.extend({ } return GridLayer.prototype._tileReady.call(this, coords, err, tile); + }, + + _clampZoom(zoom) { + return Math.round(GridLayer.prototype._clampZoom.call(this, zoom)); } });