mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-21 20:56:09 +03:00
Merge pull request #212 from avandecreme/master
Add viewportToImageRectangle method
This commit is contained in:
commit
a221477eb3
@ -722,34 +722,65 @@ $.Viewport.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Translates from Seajax viewer coordinate
|
||||
* system to image coordinate system
|
||||
* Translates from Seajax viewer coordinate system to image coordinate system.
|
||||
* This method can be called either by passing X,Y coordinates or an
|
||||
* OpenSeadragon.Point
|
||||
* @function
|
||||
* @param {OpenSeadragon.Point} viewerX the point in viewport coordinate system.
|
||||
* @param {Number} viewerX X coordinate in viewport coordinate system.
|
||||
* @param {Number} viewerY Y coordinate in viewport coordinate system.
|
||||
* @return {OpenSeadragon.Point} a point representing the coordinates in the image.
|
||||
*/
|
||||
viewportToImageCoordinates: function(viewerX, viewerY) {
|
||||
return new $.Point(viewerX * this.contentSize.x, viewerY * this.contentSize.y * this.contentAspectX);
|
||||
viewportToImageCoordinates: function( viewerX, viewerY ) {
|
||||
if ( arguments.length == 1 ) {
|
||||
//they passed a point instead of individual components
|
||||
return this.viewportToImageCoordinates( viewerX.x, viewerX.y );
|
||||
}
|
||||
return new $.Point( viewerX * this.contentSize.x, viewerY * this.contentSize.y * this.contentAspectX );
|
||||
},
|
||||
|
||||
/**
|
||||
* Translates from image coordinate system to
|
||||
* Seajax viewer coordinate system
|
||||
* Translates from image coordinate system to Seajax viewer coordinate system
|
||||
* This method can be called either by passing X,Y coordinates or an
|
||||
* OpenSeadragon.Point
|
||||
* @function
|
||||
* @param {OpenSeadragon.Point} imageX the point in image coordinate system.
|
||||
* @param {Number} imageX X coordinate in image coordinate system.
|
||||
* @param {Number} imageY Y coordinate in image coordinate system.
|
||||
* @return {OpenSeadragon.Point} a point representing the coordinates in the viewport.
|
||||
*/
|
||||
imageToViewportCoordinates: function( imageX, imageY ) {
|
||||
return new $.Point( imageX / this.contentSize.x, imageY / this.contentSize.y / this.contentAspectX);
|
||||
if ( arguments.length == 1 ) {
|
||||
//they passed a point instead of individual components
|
||||
return this.imageToViewportCoordinates( imageX.x, imageX.y );
|
||||
}
|
||||
return new $.Point( imageX / this.contentSize.x, imageY / this.contentSize.y / this.contentAspectX );
|
||||
},
|
||||
|
||||
/**
|
||||
* Translates from a rectangle which describes a portion of
|
||||
* the image in pixel coordinates to OpenSeadragon viewport
|
||||
* rectangle coordinates.
|
||||
* Translates from a rectangle which describes a portion of the image in
|
||||
* pixel coordinates to OpenSeadragon viewport rectangle coordinates.
|
||||
* This method can be called either by passing X,Y,width,height or an
|
||||
* OpenSeadragon.Rect
|
||||
* @function
|
||||
* @param {OpenSeadragon.Rect} imageX the rectangle in image coordinate system.
|
||||
* @param {Number} imageX the X coordinate of the top left corner of the rectangle
|
||||
* in image coordinate system.
|
||||
* @param {Number} imageY the Y coordinate of the top left corner of the rectangle
|
||||
* in image coordinate system.
|
||||
* @param {Number} pixelWidth the width in pixel of the rectangle.
|
||||
* @param {Number} pixelHeight the height in pixel of the rectangle.
|
||||
*/
|
||||
imageToViewportRectangle: function( imageX, imageY, pixelWidth, pixelHeight ) {
|
||||
var coordA,
|
||||
coordB,
|
||||
rect;
|
||||
if( arguments.length == 1 ){
|
||||
if( arguments.length == 1 ) {
|
||||
//they passed a rectangle instead of individual components
|
||||
rect = imageX;
|
||||
return this.imageToViewportRectangle(rect.x, rect.y, rect.width, rect.height);
|
||||
return this.imageToViewportRectangle(
|
||||
rect.x, rect.y, rect.width, rect.height
|
||||
);
|
||||
}
|
||||
coordA = this.imageToViewportCoordinates(
|
||||
imageX, imageY
|
||||
@ -763,6 +794,41 @@ $.Viewport.prototype = {
|
||||
coordB.x,
|
||||
coordB.y
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Translates from a rectangle which describes a portion of
|
||||
* the viewport in point coordinates to image rectangle coordinates.
|
||||
* This method can be called either by passing X,Y,width,height or an
|
||||
* OpenSeadragon.Rect
|
||||
* @function
|
||||
* @param {OpenSeadragon.Rect} viewerX the rectangle in viewport coordinate system.
|
||||
* @param {Number} viewerX the X coordinate of the top left corner of the rectangle
|
||||
* in viewport coordinate system.
|
||||
* @param {Number} imageY the Y coordinate of the top left corner of the rectangle
|
||||
* in viewport coordinate system.
|
||||
* @param {Number} pointWidth the width of the rectangle in viewport coordinate system.
|
||||
* @param {Number} pointHeight the height of the rectangle in viewport coordinate system.
|
||||
*/
|
||||
viewportToImageRectangle: function( viewerX, viewerY, pointWidth, pointHeight ) {
|
||||
var coordA,
|
||||
coordB,
|
||||
rect;
|
||||
if ( arguments.length == 1 ) {
|
||||
//they passed a rectangle instead of individual components
|
||||
rect = viewerX;
|
||||
return this.viewportToImageRectangle(
|
||||
rect.x, rect.y, rect.width, rect.height
|
||||
);
|
||||
}
|
||||
coordA = this.viewportToImageCoordinates( viewerX, viewerY );
|
||||
coordB = this.viewportToImageCoordinates( pointWidth, pointHeight );
|
||||
return new $.Rect(
|
||||
coordA.x,
|
||||
coordA.y,
|
||||
coordB.x,
|
||||
coordB.y
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user