From 767c897e7fce32650cd7252dba66da435f926e42 Mon Sep 17 00:00:00 2001 From: Robert Hickman Date: Fri, 16 Aug 2013 11:32:21 -0600 Subject: [PATCH] Revisions to rotate after second code review. --- src/drawer.js | 4 ++++ src/rectangle.js | 7 ++++++- src/viewport.js | 26 +++++++++++++++++++++----- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/drawer.js b/src/drawer.js index abc7969d..4a198e8c 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -403,6 +403,10 @@ $.Drawer.prototype = { } return loading; + }, + + canRotate: function() { + return USE_CANVAS; } }; diff --git a/src/rectangle.js b/src/rectangle.js index 32fc20dc..a3b1c7dd 100644 --- a/src/rectangle.js +++ b/src/rectangle.js @@ -182,7 +182,12 @@ $.Rect.prototype = { } if( degrees === 0 ){ - return this; + return new $.Rect( + this.x, + this.y, + this.width, + this.height + ); } pivot = pivot || this.getCenter(); diff --git a/src/viewport.js b/src/viewport.js index 074011d3..e79492e5 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -533,7 +533,7 @@ $.Viewport.prototype = { * @return {OpenSeadragon.Viewport} Chainable. */ zoomBy: function( factor, refPoint, immediately ) { - if( typeof refPoint != 'undefined' ) { + if( refPoint ) { refPoint = refPoint.rotate( -this.degrees, new $.Point( this.centerSpringX.target.value, this.centerSpringY.target.value ) @@ -574,19 +574,35 @@ $.Viewport.prototype = { * Currently only supports 90 degree rotation. * Currently only works with canvas. * @function - * @name OpenSeadragon.Viewport.prototype.rotate + * @name OpenSeadragon.Viewport.prototype.setRotation * @return {OpenSeadragon.Viewport} Chainable. */ - setRotation: function(degrees){ + setRotation: function( degrees ) { + if( !( this.viewer && this.viewer.drawer.canRotate() ) ) { + return this; + } + 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.'); } this.degrees = degrees; - this.viewer.drawer.update(); + if( this.viewer ) { + this.viewer.drawer.update(); + } 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 * @return {OpenSeadragon.Viewport} Chainable.