Merge branch 'master' into ig-test

This commit is contained in:
Ian Gilman 2022-11-28 14:26:56 -08:00
commit 87f90c05b4
4 changed files with 912 additions and 2768 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ instrumented/
/nbproject/private/ /nbproject/private/
.directory .directory
local-test local-test
.DS_Store

View File

@ -1,11 +1,12 @@
OPENSEADRAGON CHANGELOG OPENSEADRAGON CHANGELOG
======================= =======================
3.2.0: (in progress) 3.2.0: (in progress...)
* NEW BEHAVIOR: Setting the viewport rotation now animates by default (pass false for the new immediately parameter to disable) (#2136 @jonasengelmann) * NEW BEHAVIOR: Setting the viewport rotation now animates by default (pass false for the new immediately parameter to disable) (#2136 @jonasengelmann)
* DEPRECATION: Don't access the viewport's degrees property directly anymore; instead use setRotation and getRotation (#2136 @jonasengelmann) * DEPRECATION: Don't access the viewport's degrees property directly anymore; instead use setRotation and getRotation (#2136 @jonasengelmann)
* New gesture: Double-click and drag to zoom (on by default for touch) (#2225 @HamzaTatheer) * New gesture: Double-click and drag to zoom (on by default for touch) (#2225 @HamzaTatheer)
* You can now provide a pivot point when rotating the viewport (#2233 @ pearcetm)
* Improved the constraints that keep the image in the viewer, specifically when zoomed out a lot (#2160 @joedf) * Improved the constraints that keep the image in the viewer, specifically when zoomed out a lot (#2160 @joedf)
* You can now provide an element for the navigator (as an alternative to an ID) (#1303 @cameronbaney, #2166 #2175 @joedf) * You can now provide an element for the navigator (as an alternative to an ID) (#1303 @cameronbaney, #2166 #2175 @joedf)
* Now supporting IIIF "id" and "identifier" in addition to "@id" (#2173 @ahankinson) * Now supporting IIIF "id" and "identifier" in addition to "@id" (#2173 @ahankinson)

3568
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -97,6 +97,7 @@ $.Viewport = function( options ) {
//internal state properties //internal state properties
zoomPoint: null, zoomPoint: null,
rotationPivot: null,
viewer: null, viewer: null,
//configurable options //configurable options
@ -164,8 +165,8 @@ $.Viewport.prototype = {
// deprecated // deprecated
set degrees (degrees) { set degrees (degrees) {
$.console.warn('Setting [Viewport.degrees] is deprecated. Use viewport.setRotation instead.'); $.console.warn('Setting [Viewport.degrees] is deprecated. Use viewport.rotateTo, viewport.rotateBy, or viewport.setRotation instead.');
this.setRotation(degrees); this.rotateTo(degrees);
}, },
/** /**
@ -923,15 +924,43 @@ $.Viewport.prototype = {
return this; return this;
}, },
/**
* Rotates this viewport to the angle specified. Alias for rotateTo.
* @function
* @param {Number} degrees The degrees to set the rotation to.
* @param {OpenSeadragon.Point} [pivot] (Optional) point in viewport coordinates
* around which the rotation should be performed. Defaults to the center of the viewport.
* @param {Boolean} [immediately=false] Whether to animate to the new angle
* or rotate immediately.
* * @returns {OpenSeadragon.Viewport} Chainable.
*/
setRotation: function(degrees, pivot, immediately) {
return this.rotateTo(degrees, pivot, immediately);
},
/**
* Gets the current rotation in degrees.
* @function
* @param {Boolean} [current=false] True for current rotation, false for target.
* @returns {Number} The current rotation in degrees.
*/
getRotation: function(current) {
return current ?
this.degreesSpring.current.value :
this.degreesSpring.target.value;
},
/** /**
* Rotates this viewport to the angle specified. * Rotates this viewport to the angle specified.
* @function * @function
* @param {Number} degrees The degrees to set the rotation to. * @param {Number} degrees The degrees to set the rotation to.
* @param {OpenSeadragon.Point} [pivot] (Optional) point in viewport coordinates
* around which the rotation should be performed. Defaults to the center of the viewport.
* @param {Boolean} [immediately=false] Whether to animate to the new angle * @param {Boolean} [immediately=false] Whether to animate to the new angle
* or rotate immediately. * or rotate immediately.
* @returns {OpenSeadragon.Viewport} Chainable. * @returns {OpenSeadragon.Viewport} Chainable.
*/ */
setRotation: function(degrees, immediately) { rotateTo: function(degrees, pivot, immediately){
if (!this.viewer || !this.viewer.drawer.canRotate()) { if (!this.viewer || !this.viewer.drawer.canRotate()) {
return this; return this;
} }
@ -940,8 +969,22 @@ $.Viewport.prototype = {
this.degreesSpring.isAtTargetValue()) { this.degreesSpring.isAtTargetValue()) {
return this; return this;
} }
this.rotationPivot = pivot instanceof $.Point &&
!isNaN(pivot.x) &&
!isNaN(pivot.y) ?
pivot :
null;
if (immediately) { if (immediately) {
if(this.rotationPivot){
var changeInDegrees = degrees - this._oldDegrees;
if(!changeInDegrees){
this.rotationPivot = null;
return this;
}
this._rotateAboutPivot(degrees);
} else{
this.degreesSpring.resetTo(degrees); this.degreesSpring.resetTo(degrees);
}
} else { } else {
var normalizedFrom = $.positiveModulo(this.degreesSpring.current.value, 360); var normalizedFrom = $.positiveModulo(this.degreesSpring.current.value, 360);
var normalizedTo = $.positiveModulo(degrees, 360); var normalizedTo = $.positiveModulo(degrees, 360);
@ -970,22 +1013,26 @@ $.Viewport.prototype = {
* @type {object} * @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event. * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {Number} degrees - The number of degrees the rotation was set to. * @property {Number} degrees - The number of degrees the rotation was set to.
* @property {Boolean} immediately - Whether the rotation happened immediately or was animated
* @property {OpenSeadragon.Point} pivot - The point in viewport coordinates around which the rotation (if any) happened
* @property {?Object} userData - Arbitrary subscriber-defined object. * @property {?Object} userData - Arbitrary subscriber-defined object.
*/ */
this.viewer.raiseEvent('rotate', {degrees: degrees}); this.viewer.raiseEvent('rotate', {degrees: degrees, immediately: !!immediately, pivot: this.rotationPivot || this.getCenter()});
return this; return this;
}, },
/** /**
* Gets the current rotation in degrees. * Rotates this viewport by the angle specified.
* @function * @function
* @param {Boolean} [current=false] True for current rotation, false for target. * @param {Number} degrees The degrees by which to rotate the viewport.
* @returns {Number} The current rotation in degrees. * @param {OpenSeadragon.Point} [pivot] (Optional) point in viewport coordinates
* around which the rotation should be performed. Defaults to the center of the viewport.
* * @param {Boolean} [immediately=false] Whether to animate to the new angle
* or rotate immediately.
* @returns {OpenSeadragon.Viewport} Chainable.
*/ */
getRotation: function(current) { rotateBy: function(degrees, pivot, immediately){
return current ? return this.rotateTo(this.degreesSpring.target.value + degrees, pivot, immediately);
this.degreesSpring.current.value :
this.degreesSpring.target.value;
}, },
/** /**
@ -1040,7 +1087,7 @@ $.Viewport.prototype = {
}, },
/** /**
* Update the zoom and center (X and Y) springs. * Update the zoom, degrees, and center (X and Y) springs.
* @function * @function
* @returns {Boolean} True if any change has been made, false otherwise. * @returns {Boolean} True if any change has been made, false otherwise.
*/ */
@ -1049,11 +1096,19 @@ $.Viewport.prototype = {
this._adjustCenterSpringsForZoomPoint(function() { this._adjustCenterSpringsForZoomPoint(function() {
_this.zoomSpring.update(); _this.zoomSpring.update();
}); });
if(this.degreesSpring.isAtTargetValue()){
this.rotationPivot = null;
}
this.centerSpringX.update(); this.centerSpringX.update();
this.centerSpringY.update(); this.centerSpringY.update();
if(this.rotationPivot){
this._rotateAboutPivot(true);
}
else{
this.degreesSpring.update(); this.degreesSpring.update();
}
var changed = this.centerSpringX.current.value !== this._oldCenterX || var changed = this.centerSpringX.current.value !== this._oldCenterX ||
this.centerSpringY.current.value !== this._oldCenterY || this.centerSpringY.current.value !== this._oldCenterY ||
@ -1069,6 +1124,27 @@ $.Viewport.prototype = {
return changed; return changed;
}, },
// private - pass true to use spring, or a number for degrees for immediate rotation
_rotateAboutPivot: function(degreesOrUseSpring){
var useSpring = degreesOrUseSpring === true;
var delta = this.rotationPivot.minus(this.getCenter());
this.centerSpringX.shiftBy(delta.x);
this.centerSpringY.shiftBy(delta.y);
if(useSpring){
this.degreesSpring.update();
} else {
this.degreesSpring.resetTo(degreesOrUseSpring);
}
var changeInDegrees = this.degreesSpring.current.value - this._oldDegrees;
var rdelta = delta.rotate(changeInDegrees * -1).times(-1);
this.centerSpringX.shiftBy(rdelta.x);
this.centerSpringY.shiftBy(rdelta.y);
},
// private
_adjustCenterSpringsForZoomPoint: function(zoomSpringHandler) { _adjustCenterSpringsForZoomPoint: function(zoomSpringHandler) {
if (this.zoomPoint) { if (this.zoomPoint) {
var oldZoomPixel = this.pixelFromPoint(this.zoomPoint, true); var oldZoomPixel = this.pixelFromPoint(this.zoomPoint, true);