updated setRotation param order to match rotateBy/rotateTo, deprecation warning for setting degrees, and private API

This commit is contained in:
Tom 2022-11-16 18:07:56 -05:00
parent 2f174ad552
commit 7454d4323d

View File

@ -165,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);
}, },
/** /**
@ -925,17 +925,16 @@ $.Viewport.prototype = {
}, },
/** /**
* Rotates this viewport to the angle specified. Almost an alias for rotateTo, * Rotates this viewport to the angle specified. Alias for rotateTo.
* but with a different order of arguments to maintain backwards compatibility.
* @function * @function
* @param {Number} degrees The degrees to set the rotation to. * @param {Number} degrees The degrees to set the rotation to.
* @param {Boolean} [immediately=false] Whether to animate to the new angle
* or rotate immediately.
* @param {OpenSeadragon.Point} [pivot] (Optional) point in viewport coordinates * @param {OpenSeadragon.Point} [pivot] (Optional) point in viewport coordinates
* around which the rotation should be performed. Defaults to the center of the viewport. * around which the rotation should be performed. Defaults to the center of the viewport.
* @returns {OpenSeadragon.Viewport} Chainable. * @param {Boolean} [immediately=false] Whether to animate to the new angle
* or rotate immediately.
* * @returns {OpenSeadragon.Viewport} Chainable.
*/ */
setRotation: function(degrees, immediately, pivot) { setRotation: function(degrees, pivot, immediately) {
return this.rotateTo(degrees, pivot, immediately); return this.rotateTo(degrees, pivot, immediately);
}, },
@ -982,7 +981,7 @@ $.Viewport.prototype = {
this.rotationPivot = null; this.rotationPivot = null;
return this; return this;
} }
this._rotateAboutPivot(true, degrees); this._rotateAboutPivot(degrees);
} else{ } else{
this.degreesSpring.resetTo(degrees); this.degreesSpring.resetTo(degrees);
} }
@ -1104,7 +1103,7 @@ $.Viewport.prototype = {
this.centerSpringY.update(); this.centerSpringY.update();
if(this.rotationPivot){ if(this.rotationPivot){
this._rotateAboutPivot(); this._rotateAboutPivot(true);
} }
else{ else{
this.degreesSpring.update(); this.degreesSpring.update();
@ -1125,17 +1124,18 @@ $.Viewport.prototype = {
return changed; return changed;
}, },
// private // private - pass true to use spring, or a number for degrees for immediate rotation
_rotateAboutPivot: function(immediately, degrees){ _rotateAboutPivot: function(degreesOrUseSpring){
//immediately defaults to false; degrees are ignored for immediately==false var useSpring = degreesOrUseSpring === true;
var delta = this.rotationPivot.minus(this.getCenter()); var delta = this.rotationPivot.minus(this.getCenter());
this.centerSpringX.shiftBy(delta.x); this.centerSpringX.shiftBy(delta.x);
this.centerSpringY.shiftBy(delta.y); this.centerSpringY.shiftBy(delta.y);
if(immediately){ if(useSpring){
this.degreesSpring.resetTo(degrees);
} else {
this.degreesSpring.update(); this.degreesSpring.update();
} else {
this.degreesSpring.resetTo(degreesOrUseSpring);
} }
var changeInDegrees = this.degreesSpring.current.value - this._oldDegrees; var changeInDegrees = this.degreesSpring.current.value - this._oldDegrees;