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;
},
canRotate: function() {
return USE_CANVAS;
}
};

View File

@ -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();

View File

@ -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.