Revisions to rotate after second code review.

This commit is contained in:
Robert Hickman 2013-08-16 11:32:21 -06:00
parent 54e8d8c43f
commit 767c897e7f
3 changed files with 31 additions and 6 deletions

View File

@ -403,6 +403,10 @@ $.Drawer.prototype = {
} }
return loading; return loading;
},
canRotate: function() {
return USE_CANVAS;
} }
}; };

View File

@ -182,7 +182,12 @@ $.Rect.prototype = {
} }
if( degrees === 0 ){ if( degrees === 0 ){
return this; return new $.Rect(
this.x,
this.y,
this.width,
this.height
);
} }
pivot = pivot || this.getCenter(); pivot = pivot || this.getCenter();

View File

@ -533,7 +533,7 @@ $.Viewport.prototype = {
* @return {OpenSeadragon.Viewport} Chainable. * @return {OpenSeadragon.Viewport} Chainable.
*/ */
zoomBy: function( factor, refPoint, immediately ) { zoomBy: function( factor, refPoint, immediately ) {
if( typeof refPoint != 'undefined' ) { if( refPoint ) {
refPoint = refPoint.rotate( refPoint = refPoint.rotate(
-this.degrees, -this.degrees,
new $.Point( this.centerSpringX.target.value, this.centerSpringY.target.value ) new $.Point( this.centerSpringX.target.value, this.centerSpringY.target.value )
@ -574,19 +574,35 @@ $.Viewport.prototype = {
* Currently only supports 90 degree rotation. * Currently only supports 90 degree rotation.
* Currently only works with canvas. * Currently only works with canvas.
* @function * @function
* @name OpenSeadragon.Viewport.prototype.rotate * @name OpenSeadragon.Viewport.prototype.setRotation
* @return {OpenSeadragon.Viewport} Chainable. * @return {OpenSeadragon.Viewport} Chainable.
*/ */
setRotation: function(degrees){ setRotation: function( degrees ) {
if( !( this.viewer && this.viewer.drawer.canRotate() ) ) {
return this;
}
degrees = ( degrees + 360 ) % 360; degrees = ( degrees + 360 ) % 360;
if(degrees % 90 !== 0){ if( degrees % 90 !== 0 ) {
throw new Error('Currently only 0, 90, 180, and 270 degrees are supported.'); throw new Error('Currently only 0, 90, 180, and 270 degrees are supported.');
} }
this.degrees = degrees; this.degrees = degrees;
if( this.viewer ) {
this.viewer.drawer.update(); this.viewer.drawer.update();
}
return this; return this;
}, },
/**
* Gets the current rotation in degrees.
* @function
* @name OpenSeadragon.Viewport.prototype.setRotation
* @return {Number} The current rotation in degrees.
*/
getRotation: function() {
return this.degrees;
},
/** /**
* @function * @function
* @return {OpenSeadragon.Viewport} Chainable. * @return {OpenSeadragon.Viewport} Chainable.