From 07d66ce655a1ac33398d359d928b6c63f86457e5 Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Thu, 12 May 2016 18:01:18 -0400 Subject: [PATCH] Restore applyConstraints to avoid panning when clicking at max zoom. --- src/viewport.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/viewport.js b/src/viewport.js index 3c08c594..ba65048b 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -474,6 +474,13 @@ $.Viewport.prototype = { } }, + // private + _applyZoomConstraints: function(zoom) { + return Math.max( + Math.min(zoom, this.getMaxZoom()), + this.getMinZoom()); + }, + /** * @function * @private @@ -563,7 +570,23 @@ $.Viewport.prototype = { * @fires OpenSeadragon.Viewer.event:constrain */ applyConstraints: function(immediately) { - this.fitBoundsWithConstraints(this.getBounds(), immediately); + var actualZoom = this.getZoom(); + var constrainedZoom = this._applyZoomConstraints(actualZoom); + + if (actualZoom !== constrainedZoom) { + this.zoomTo(constrainedZoom, this.zoomPoint, immediately); + } + + var bounds = this.getBoundsNoRotate(); + var constrainedBounds = this._applyBoundaryConstraints( + bounds, immediately); + + if (bounds.x !== constrainedBounds.x || + bounds.y !== constrainedBounds.y || + immediately) { + this.fitBounds(constrainedBounds.rotate(this.getRotation()), + immediately); + } return this; }, @@ -615,10 +638,7 @@ $.Viewport.prototype = { if (constraints) { var newBoundsAspectRatio = newBounds.getAspectRatio(); - var newConstrainedZoom = Math.max( - Math.min(newZoom, this.getMaxZoom()), - this.getMinZoom() - ); + var newConstrainedZoom = this._applyZoomConstraints(newZoom); if (newZoom !== newConstrainedZoom) { newZoom = newConstrainedZoom;