diff --git a/src/layer/tile/TileLayer.js b/src/layer/tile/TileLayer.js index cdcccfe3..593778a6 100644 --- a/src/layer/tile/TileLayer.js +++ b/src/layer/tile/TileLayer.js @@ -102,7 +102,7 @@ L.TileLayer = L.GridLayer.extend({ // increase tile size when overscaling return zoomN && zoom > zoomN ? - Math.round(map.getZoomScale(zoom) / map.getZoomScale(zoomN) * options.tileSize) : + Math.round(map.getZoomScale(zoomN, zoom) * options.tileSize) : options.tileSize; }, diff --git a/src/map/Map.js b/src/map/Map.js index e76eddfe..2600c3ad 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -348,13 +348,15 @@ L.Map = L.Evented.extend({ // TODO replace with universal implementation after refactoring projections - getZoomScale: function (toZoom) { + getZoomScale: function (toZoom, fromZoom) { var crs = this.options.crs; - return crs.scale(toZoom) / crs.scale(this._zoom); + fromZoom = fromZoom === undefined ? this._zoom : fromZoom; + return crs.scale(toZoom) / crs.scale(fromZoom); }, - getScaleZoom: function (scale) { - return this._zoom + (Math.log(scale) / Math.LN2); + getScaleZoom: function (scale, fromZoom) { + fromZoom = fromZoom === undefined ? this._zoom : fromZoom; + return fromZoom + (Math.log(scale) / Math.LN2); }, diff --git a/src/map/anim/Map.ZoomPan.js b/src/map/anim/Map.ZoomPan.js index 65dd2302..c16c1eac 100644 --- a/src/map/anim/Map.ZoomPan.js +++ b/src/map/anim/Map.ZoomPan.js @@ -6,8 +6,9 @@ L.Map.include({ to = this.project(center), u1 = to.distanceTo(from), size = this.getSize(), + zoom = this._zoom, w0 = Math.max(size.x, size.y), - w1 = w0 * this.getZoomScale(this._zoom) / this.getZoomScale(targetZoom), + w1 = w0 * this.getZoomScale(targetZoom, zoom), rho = 1.42, rho2 = rho * rho; @@ -26,10 +27,11 @@ L.Map.include({ function u(s) { return w0 * (cosh(r0) * tanh(r0 + rho * s) - sinh(r0)) / rho2; } function step(s) { - var center = this.unproject(from.add(to.subtract(from).multiplyBy(u(s) / u1))), - zoom = this.getScaleZoom(this.getZoomScale(this._zoom) * w0 / w(s)); + var center = this.unproject(from.add(to.subtract(from).multiplyBy(u(s) / u1)), targetZoom), + newZoom = this.getScaleZoom(w0 / w(s), zoom); - this._animateZoom(center, zoom); + this._resetView(center, newZoom, true, true); + this._animateZoom(center, newZoom); } function easeOut(t) { return 1 - Math.pow(1 - t, 2); }