mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 14:46:10 +03:00
Add viewportToImageRectangle method and add support to pass a point to viewportToImageCoordinates and imageToViewportCoordinates
This commit is contained in:
parent
7f88bf78b6
commit
bfa76e471b
@ -726,7 +726,11 @@ $.Viewport.prototype = {
|
|||||||
* system to image coordinate system
|
* system to image coordinate system
|
||||||
*/
|
*/
|
||||||
viewportToImageCoordinates: function(viewerX, viewerY) {
|
viewportToImageCoordinates: function(viewerX, viewerY) {
|
||||||
return new $.Point(viewerX * this.contentSize.x, viewerY * this.contentSize.y * this.contentAspectX);
|
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);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -734,7 +738,11 @@ $.Viewport.prototype = {
|
|||||||
* Seajax viewer coordinate system
|
* Seajax viewer coordinate system
|
||||||
*/
|
*/
|
||||||
imageToViewportCoordinates: function( imageX, imageY ) {
|
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);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -746,7 +754,7 @@ $.Viewport.prototype = {
|
|||||||
var coordA,
|
var coordA,
|
||||||
coordB,
|
coordB,
|
||||||
rect;
|
rect;
|
||||||
if( arguments.length == 1 ){
|
if( arguments.length == 1 ) {
|
||||||
//they passed a rectangle instead of individual components
|
//they passed a rectangle instead of individual components
|
||||||
rect = imageX;
|
rect = imageX;
|
||||||
return this.imageToViewportRectangle(rect.x, rect.y, rect.width, rect.height);
|
return this.imageToViewportRectangle(rect.x, rect.y, rect.width, rect.height);
|
||||||
@ -763,6 +771,29 @@ $.Viewport.prototype = {
|
|||||||
coordB.x,
|
coordB.x,
|
||||||
coordB.y
|
coordB.y
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translates from a rectangle which describes a portion of
|
||||||
|
* the viewport in point coordinates to image rectangle coordinates.
|
||||||
|
*/
|
||||||
|
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