mirror of
https://github.com/openseadragon/openseadragon.git
synced 2025-02-20 00:33:13 +03:00
Slight API tweaks; added checks to rotationPivot
This commit is contained in:
parent
aea62de752
commit
7f2725ba49
117
src/viewport.js
117
src/viewport.js
@ -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
|
||||||
@ -924,16 +925,43 @@ $.Viewport.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotates this viewport to the angle specified.
|
* Rotates this viewport to the angle specified. Almost an 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
|
* @param {Boolean} [immediately=false] Whether to animate to the new angle
|
||||||
* or rotate immediately.
|
* or rotate immediately.
|
||||||
* @param {OpenSeadragon.Point} [pivot=false] (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.
|
* @returns {OpenSeadragon.Viewport} Chainable.
|
||||||
*/
|
*/
|
||||||
setRotation: function(degrees, immediately, pivot) {
|
setRotation: function(degrees, immediately, pivot) {
|
||||||
|
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.
|
||||||
|
* @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.
|
||||||
|
*/
|
||||||
|
rotateTo: function(degrees, pivot, immediately){
|
||||||
if (!this.viewer || !this.viewer.drawer.canRotate()) {
|
if (!this.viewer || !this.viewer.drawer.canRotate()) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -942,20 +970,19 @@ $.Viewport.prototype = {
|
|||||||
this.degreesSpring.isAtTargetValue()) {
|
this.degreesSpring.isAtTargetValue()) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
this.rotationPivot = pivot;
|
this.rotationPivot = pivot instanceof $.Point &&
|
||||||
|
!isNaN(pivot.x) &&
|
||||||
|
!isNaN(pivot.y) ?
|
||||||
|
pivot :
|
||||||
|
null;
|
||||||
if (immediately) {
|
if (immediately) {
|
||||||
if(pivot){
|
if(this.rotationPivot){
|
||||||
var changeInDegrees = degrees - this._oldDegrees;
|
var changeInDegrees = degrees - this._oldDegrees;
|
||||||
if(!changeInDegrees){
|
if(!changeInDegrees){
|
||||||
|
this.rotationPivot = null;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
var delta = pivot.minus(this.getCenter());
|
this._rotateAboutPivot(true, degrees);
|
||||||
this.centerSpringX.shiftBy(delta.x);
|
|
||||||
this.centerSpringY.shiftBy(delta.y);
|
|
||||||
this.degreesSpring.resetTo(degrees);
|
|
||||||
var rdelta = delta.rotate(changeInDegrees * -1).times(-1);
|
|
||||||
this.centerSpringX.shiftBy(rdelta.x);
|
|
||||||
this.centerSpringY.shiftBy(rdelta.y);
|
|
||||||
} else{
|
} else{
|
||||||
this.degreesSpring.resetTo(degrees);
|
this.degreesSpring.resetTo(degrees);
|
||||||
}
|
}
|
||||||
@ -991,47 +1018,21 @@ $.Viewport.prototype = {
|
|||||||
* @property {OpenSeadragon.Point} pivot - The point in viewport coordinates around which the rotation (if any) happened
|
* @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, immediately: !!immediately, pivot: pivot || this.getCenter()});
|
this.viewer.raiseEvent('rotate', {degrees: degrees, immediately: !!immediately, pivot: this.rotationPivot || this.getCenter()});
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* 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. Alias for setRotation to be consistent with with pan and zoom API
|
|
||||||
* @function
|
|
||||||
* @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=false] (Optional) point in viewport coordinates
|
|
||||||
* around which the rotation should be performed. Defaults to the center of the viewport.
|
|
||||||
* @returns {OpenSeadragon.Viewport} Chainable.
|
|
||||||
*/
|
|
||||||
rotateTo: function(degrees, immediately, pivot){
|
|
||||||
return this.setRotation(degrees, immediately, pivot);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotates this viewport by the angle specified.
|
* Rotates this viewport by the angle specified.
|
||||||
* @function
|
* @function
|
||||||
* @param {Number} degrees The degrees by which to rotate the viewport.
|
* @param {Number} degrees The degrees by which to rotate 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.
|
||||||
* @param {OpenSeadragon.Point} [pivot=false] (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.
|
* @returns {OpenSeadragon.Viewport} Chainable.
|
||||||
*/
|
*/
|
||||||
rotateBy: function(degrees, immediately, pivot){
|
rotateBy: function(degrees, pivot, immediately){
|
||||||
return this.setRotation(this.degreesSpring.target.value + degrees, immediately, pivot);
|
return this.setRotation(this.degreesSpring.target.value + degrees, immediately, pivot);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1096,24 +1097,20 @@ $.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.degreesSpring.current.value !== this.degreesSpring.target.value){
|
if(this.rotationPivot){
|
||||||
var delta = this.rotationPivot.minus(this.getCenter());
|
this._rotateAboutPivot();
|
||||||
this.centerSpringX.shiftBy(delta.x);
|
|
||||||
this.centerSpringY.shiftBy(delta.y);
|
|
||||||
this.degreesSpring.update();
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
else{
|
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 ||
|
||||||
this.zoomSpring.current.value !== this._oldZoom ||
|
this.zoomSpring.current.value !== this._oldZoom ||
|
||||||
@ -1128,6 +1125,26 @@ $.Viewport.prototype = {
|
|||||||
return changed;
|
return changed;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// private
|
||||||
|
_rotateAboutPivot: function(immediately, degrees){
|
||||||
|
//immediately defaults to false; degrees are ignored for immediately==false
|
||||||
|
var delta = this.rotationPivot.minus(this.getCenter());
|
||||||
|
this.centerSpringX.shiftBy(delta.x);
|
||||||
|
this.centerSpringY.shiftBy(delta.y);
|
||||||
|
|
||||||
|
if(immediately){
|
||||||
|
this.degreesSpring.resetTo(degrees);
|
||||||
|
} else {
|
||||||
|
this.degreesSpring.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user