From de9fa90facd751a7b3a931c89108b38209c0782d Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Thu, 18 Feb 2016 15:44:00 -0800 Subject: [PATCH] Viewport.zoomTo and zoomBy now respect ref point even when immediately = true --- src/viewport.js | 55 +++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/src/viewport.js b/src/viewport.js index 63b4dcaf..edbd13a6 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -765,7 +765,9 @@ $.Viewport.prototype = { null; if ( immediately ) { - this.zoomSpring.resetTo( zoom ); + this._updateZoom({ + resetTo: zoom + }); } else { this.zoomSpring.springTo( zoom ); } @@ -891,27 +893,7 @@ $.Viewport.prototype = { * @function */ update: function() { - var oldZoomPixel, - newZoomPixel, - deltaZoomPixels, - deltaZoomPoints; - - if (this.zoomPoint) { - oldZoomPixel = this.pixelFromPoint( this.zoomPoint, true ); - } - - this.zoomSpring.update(); - - if (this.zoomPoint && this.zoomSpring.current.value != this._oldZoom) { - newZoomPixel = this.pixelFromPoint( this.zoomPoint, true ); - deltaZoomPixels = newZoomPixel.minus( oldZoomPixel ); - deltaZoomPoints = this.deltaPointsFromPixels( deltaZoomPixels, true ); - - this.centerSpringX.shiftBy( deltaZoomPoints.x ); - this.centerSpringY.shiftBy( deltaZoomPoints.y ); - } else { - this.zoomPoint = null; - } + this._updateZoom(); this.centerSpringX.update(); this.centerSpringY.update(); @@ -927,6 +909,35 @@ $.Viewport.prototype = { return changed; }, + // private + _updateZoom: function(options) { + var oldZoomPixel, + newZoomPixel, + deltaZoomPixels, + deltaZoomPoints; + + if (this.zoomPoint) { + oldZoomPixel = this.pixelFromPoint( this.zoomPoint, true ); + } + + if (options && options.resetTo) { + this.zoomSpring.resetTo(options.resetTo); + } else { + this.zoomSpring.update(); + } + + if (this.zoomPoint && this.zoomSpring.current.value != this._oldZoom) { + newZoomPixel = this.pixelFromPoint( this.zoomPoint, true ); + deltaZoomPixels = newZoomPixel.minus( oldZoomPixel ); + deltaZoomPoints = this.deltaPointsFromPixels( deltaZoomPixels, true ); + + this.centerSpringX.shiftBy( deltaZoomPoints.x ); + this.centerSpringY.shiftBy( deltaZoomPoints.y ); + } else { + this.zoomPoint = null; + } + }, + /** * Convert a delta (translation vector) from viewport coordinates to pixels * coordinates. This method does not take rotation into account.