diff --git a/README.md b/README.md index f8564916..92b6fb86 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # OpenSeadragon -[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/openseadragon/openseadragon?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://secure.travis-ci.org/openseadragon/openseadragon.png?branch=master)](http://travis-ci.org/openseadragon/openseadragon) +[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/openseadragon/openseadragon?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://secure.travis-ci.org/openseadragon/openseadragon.png?branch=master)](http://travis-ci.org/openseadragon/openseadragon) An open-source, web-based viewer for zoomable images, implemented in pure JavaScript. diff --git a/changelog.txt b/changelog.txt index 725bfdc0..e63036f5 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,7 +1,11 @@ OPENSEADRAGON CHANGELOG ======================= -2.2.0: (in progress) +2.2.1: (in progress) + +* Fixed problems with zoom/pan constraints with certain extreme settings (#965) + +2.2.0: * BREAKING CHANGE: Viewport.homeBounds, Viewport.contentSize, Viewport.contentAspectX and Viewport.contentAspectY have been removed. (#846) @@ -47,6 +51,7 @@ OPENSEADRAGON CHANGELOG * Fixed an issue with simultaneous touch events (#930) * Avoid loading clipped out tiles (#939) * Improved precision for subtle moves with fitBounds (#939) +* Fixed an issue in viewer.addTiledImage with replace:true when viewer has navigator (#948) 2.1.0: diff --git a/package.json b/package.json index 7da958cc..245288c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openseadragon", - "version": "2.1.0", + "version": "2.2.0", "description": "Provides a smooth, zoomable user interface for HTML/Javascript.", "keywords": ["image", "zoom", "pan", "openseadragon", "seadragon", "deepzoom", "dzi", "iiif", "osm", "tms"], "homepage": "http://openseadragon.github.io/", diff --git a/src/viewer.js b/src/viewer.js index 6ed18bc0..d64bda51 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1397,6 +1397,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, if (_this.navigator) { optionsClone = $.extend({}, queueItem.options, { + replace: false, // navigator already removed the layer, nothing to replace originalTiledImage: tiledImage, tileSource: queueItem.tileSource }); diff --git a/src/viewport.js b/src/viewport.js index da2ce761..2ac499d4 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -495,51 +495,40 @@ $.Viewport.prototype = { bounds.width, bounds.height); - var horizontalThreshold = this.visibilityRatio * newBounds.width; - var verticalThreshold = this.visibilityRatio * newBounds.height; - if (this.wrapHorizontal) { //do nothing } else { - var dx = 0; - var thresholdLeft = newBounds.x + (newBounds.width - horizontalThreshold); - if (this._contentBoundsNoRotate.x > thresholdLeft) { - dx = this._contentBoundsNoRotate.x - thresholdLeft; - } - + var horizontalThreshold = this.visibilityRatio * newBounds.width; + var boundsRight = newBounds.x + newBounds.width; var contentRight = this._contentBoundsNoRotate.x + this._contentBoundsNoRotate.width; - var thresholdRight = newBounds.x + horizontalThreshold; - if (contentRight < thresholdRight) { - var newDx = contentRight - thresholdRight; - if (dx) { - dx = (dx + newDx) / 2; - } else { - dx = newDx; - } + var leftDx = this._contentBoundsNoRotate.x - boundsRight + horizontalThreshold; + var rightDx = contentRight - newBounds.x - horizontalThreshold; + + if (horizontalThreshold > this._contentBoundsNoRotate.width) { + newBounds.x += (leftDx + rightDx) / 2; + } else if (rightDx < 0) { + newBounds.x += rightDx; + } else if (leftDx > 0) { + newBounds.x += leftDx; } - newBounds.x += dx; } if (this.wrapVertical) { //do nothing } else { - var dy = 0; - var thresholdTop = newBounds.y + (newBounds.height - verticalThreshold); - if (this._contentBoundsNoRotate.y > thresholdTop) { - dy = this._contentBoundsNoRotate.y - thresholdTop; - } - + var verticalThreshold = this.visibilityRatio * newBounds.height; + var boundsBottom = newBounds.y + newBounds.height; var contentBottom = this._contentBoundsNoRotate.y + this._contentBoundsNoRotate.height; - var thresholdBottom = newBounds.y + verticalThreshold; - if (contentBottom < thresholdBottom) { - var newDy = contentBottom - thresholdBottom; - if (dy) { - dy = (dy + newDy) / 2; - } else { - dy = newDy; - } + var topDy = this._contentBoundsNoRotate.y - boundsBottom + verticalThreshold; + var bottomDy = contentBottom - newBounds.y - verticalThreshold; + + if (verticalThreshold > this._contentBoundsNoRotate.height) { + newBounds.y += (topDy + bottomDy) / 2; + } else if (bottomDy < 0) { + newBounds.y += bottomDy; + } else if (topDy > 0) { + newBounds.y += topDy; } - newBounds.y += dy; } if (this.viewer) { diff --git a/test/modules/events.js b/test/modules/events.js index 30dc28a2..ccfbab26 100644 --- a/test/modules/events.js +++ b/test/modules/events.js @@ -820,8 +820,8 @@ Util.assessNumericValue(zoom, 0.002, epsilon, "Zoom should not be prevented"); Util.assertRectangleEquals( + new OpenSeadragon.Rect(-249.5, -0.25, 500, 0.5), bounds, - new OpenSeadragon.Rect(-250, -0.25, 500, 0.5), epsilon, 'Pan should not be prevented'); diff --git a/test/modules/viewport.js b/test/modules/viewport.js index f39473cf..fb94d11d 100644 --- a/test/modules/viewport.js +++ b/test/modules/viewport.js @@ -437,8 +437,8 @@ viewport.applyConstraints(true); var bounds = viewport.getBounds(); Util.assertRectangleEquals( - bounds, new OpenSeadragon.Rect(0.7, 0.7, 1, 1), + bounds, EPSILON, "Viewport.applyConstraints should move viewport."); start(); @@ -447,6 +447,27 @@ viewer.open(DZI_PATH); }); + asyncTest('applyConstraints with visibilityRatio = 1 shouldn\'t bounce around', function() { + var openHandler = function() { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + viewport.visibilityRatio = 1; + viewport.zoomTo(0.5, undefined, true); + viewport.panBy(new OpenSeadragon.Point(0.75, 0), true); + viewport.applyConstraints(true); + var bounds = viewport.getBounds(); + Util.assertRectangleEquals( + new OpenSeadragon.Rect(-0.5, 1, 2, 2), + bounds, + EPSILON, + "Viewport.applyConstraints should move viewport to the center, not to a side."); + start(); + }; + viewer.addHandler('open', openHandler); + viewer.open(TALL_PATH); + }); + asyncTest('applyConstraints with rotation', function() { var openHandler = function() { viewer.removeHandler('open', openHandler);