2013-05-01 08:46:16 +04:00
|
|
|
/*
|
2013-05-14 08:00:24 +04:00
|
|
|
* OpenSeadragon - Viewport
|
2013-05-01 08:46:16 +04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2009 CodePlex Foundation
|
2013-05-14 07:32:09 +04:00
|
|
|
* Copyright (C) 2010-2013 OpenSeadragon contributors
|
2013-05-01 08:46:16 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* - Neither the name of CodePlex Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
(function( $ ){
|
2012-01-25 23:14:02 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-11-16 10:19:53 +04:00
|
|
|
* @class Viewport
|
2013-11-25 20:48:44 +04:00
|
|
|
* @classdesc Handles coordinate-related functionality (zoom, pan, rotation, etc.) for an {@link OpenSeadragon.Viewer}.
|
|
|
|
* A new instance is created for each TileSource opened (see {@link OpenSeadragon.Viewer#viewport}).
|
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @memberof OpenSeadragon
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
$.Viewport = function( options ) {
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
//backward compatibility for positional args while prefering more
|
2012-03-01 17:38:15 +04:00
|
|
|
//idiomatic javascript options object as the only argument
|
|
|
|
var args = arguments;
|
|
|
|
if( args.length && args[ 0 ] instanceof $.Point ){
|
2012-01-24 07:48:45 +04:00
|
|
|
options = {
|
2012-03-01 17:38:15 +04:00
|
|
|
containerSize: args[ 0 ],
|
|
|
|
contentSize: args[ 1 ],
|
|
|
|
config: args[ 2 ]
|
2012-01-24 07:48:45 +04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
//options.config and the general config argument are deprecated
|
|
|
|
//in favor of the more direct specification of optional settings
|
2013-05-20 20:39:57 +04:00
|
|
|
//being passed directly on the options object
|
2012-03-01 17:38:15 +04:00
|
|
|
if ( options.config ){
|
|
|
|
$.extend( true, options, options.config );
|
|
|
|
delete options.config;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.extend( true, this, {
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
//required settings
|
|
|
|
containerSize: null,
|
|
|
|
contentSize: null,
|
|
|
|
|
|
|
|
//internal state properties
|
|
|
|
zoomPoint: null,
|
2013-02-14 04:44:23 +04:00
|
|
|
viewer: null,
|
2012-03-01 17:38:15 +04:00
|
|
|
|
|
|
|
//configurable options
|
|
|
|
springStiffness: $.DEFAULT_SETTINGS.springStiffness,
|
|
|
|
animationTime: $.DEFAULT_SETTINGS.animationTime,
|
|
|
|
minZoomImageRatio: $.DEFAULT_SETTINGS.minZoomImageRatio,
|
|
|
|
maxZoomPixelRatio: $.DEFAULT_SETTINGS.maxZoomPixelRatio,
|
|
|
|
visibilityRatio: $.DEFAULT_SETTINGS.visibilityRatio,
|
|
|
|
wrapHorizontal: $.DEFAULT_SETTINGS.wrapHorizontal,
|
2013-02-06 06:26:40 +04:00
|
|
|
wrapVertical: $.DEFAULT_SETTINGS.wrapVertical,
|
|
|
|
defaultZoomLevel: $.DEFAULT_SETTINGS.defaultZoomLevel,
|
|
|
|
minZoomLevel: $.DEFAULT_SETTINGS.minZoomLevel,
|
2013-08-14 01:39:22 +04:00
|
|
|
maxZoomLevel: $.DEFAULT_SETTINGS.maxZoomLevel,
|
|
|
|
degrees: $.DEFAULT_SETTINGS.degrees
|
2012-03-01 17:38:15 +04:00
|
|
|
|
|
|
|
}, options );
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
this.centerSpringX = new $.Spring({
|
2013-06-19 21:33:25 +04:00
|
|
|
initial: 0,
|
2012-03-01 17:38:15 +04:00
|
|
|
springStiffness: this.springStiffness,
|
|
|
|
animationTime: this.animationTime
|
2012-01-05 03:14:20 +04:00
|
|
|
});
|
|
|
|
this.centerSpringY = new $.Spring({
|
2013-06-19 21:33:25 +04:00
|
|
|
initial: 0,
|
2012-03-01 17:38:15 +04:00
|
|
|
springStiffness: this.springStiffness,
|
|
|
|
animationTime: this.animationTime
|
2012-01-05 03:14:20 +04:00
|
|
|
});
|
2012-02-28 03:29:00 +04:00
|
|
|
this.zoomSpring = new $.Spring({
|
2013-06-19 21:33:25 +04:00
|
|
|
initial: 1,
|
2012-03-01 17:38:15 +04:00
|
|
|
springStiffness: this.springStiffness,
|
|
|
|
animationTime: this.animationTime
|
2012-01-05 03:14:20 +04:00
|
|
|
});
|
2012-02-28 03:29:00 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
this.resetContentSize( this.contentSize );
|
2012-01-05 04:45:47 +04:00
|
|
|
this.goHome( true );
|
2011-12-06 07:50:25 +04:00
|
|
|
this.update();
|
|
|
|
};
|
|
|
|
|
2013-11-16 10:19:53 +04:00
|
|
|
$.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
|
2012-01-25 23:14:02 +04:00
|
|
|
|
2013-02-14 04:44:23 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @return {OpenSeadragon.Viewport} Chainable.
|
2013-11-22 00:19:07 +04:00
|
|
|
* @fires OpenSeadragon.Viewer.event:reset-size
|
2013-02-14 04:44:23 +04:00
|
|
|
*/
|
2012-04-03 11:08:27 +04:00
|
|
|
resetContentSize: function( contentSize ){
|
|
|
|
this.contentSize = contentSize;
|
|
|
|
this.contentAspectX = this.contentSize.x / this.contentSize.y;
|
|
|
|
this.contentAspectY = this.contentSize.y / this.contentSize.x;
|
2013-01-31 21:30:13 +04:00
|
|
|
this.fitWidthBounds = new $.Rect( 0, 0, 1, this.contentAspectY );
|
|
|
|
this.fitHeightBounds = new $.Rect( 0, 0, this.contentAspectY, this.contentAspectY);
|
2012-08-29 22:46:34 +04:00
|
|
|
|
2013-01-31 21:30:13 +04:00
|
|
|
this.homeBounds = new $.Rect( 0, 0, 1, this.contentAspectY );
|
2013-02-14 04:44:23 +04:00
|
|
|
|
|
|
|
if( this.viewer ){
|
2013-11-16 10:19:53 +04:00
|
|
|
/**
|
2013-11-22 00:19:07 +04:00
|
|
|
* Raised when the viewer's content size is reset (see {@link OpenSeadragon.Viewport#resetContentSize}).
|
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @event reset-size
|
|
|
|
* @memberof OpenSeadragon.Viewer
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
|
|
|
|
* @property {OpenSeadragon.Point} contentSize
|
2013-11-18 18:56:32 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
2013-11-16 10:19:53 +04:00
|
|
|
*/
|
2013-06-19 21:33:25 +04:00
|
|
|
this.viewer.raiseEvent( 'reset-size', {
|
2013-10-11 04:00:15 +04:00
|
|
|
contentSize: contentSize
|
2013-02-14 04:44:23 +04:00
|
|
|
});
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-01-31 01:51:37 +04:00
|
|
|
return this;
|
2012-04-03 11:08:27 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-05 03:14:20 +04:00
|
|
|
getHomeZoom: function() {
|
2013-06-19 21:33:25 +04:00
|
|
|
var aspectFactor =
|
2012-08-30 04:48:45 +04:00
|
|
|
this.contentAspectX / this.getAspectRatio();
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2013-02-06 06:26:40 +04:00
|
|
|
if( this.defaultZoomLevel ){
|
|
|
|
return this.defaultZoomLevel;
|
|
|
|
} else {
|
2013-06-19 21:33:25 +04:00
|
|
|
return ( aspectFactor >= 1 ) ?
|
|
|
|
1 :
|
2013-02-06 06:26:40 +04:00
|
|
|
aspectFactor;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
|
|
|
getHomeBounds: function() {
|
|
|
|
var center = this.homeBounds.getCenter( ),
|
|
|
|
width = 1.0 / this.getHomeZoom( ),
|
|
|
|
height = width / this.getAspectRatio();
|
|
|
|
|
|
|
|
return new $.Rect(
|
2013-06-19 21:33:25 +04:00
|
|
|
center.x - ( width / 2.0 ),
|
2013-02-06 06:26:40 +04:00
|
|
|
center.y - ( height / 2.0 ),
|
2013-06-19 21:33:25 +04:00
|
|
|
width,
|
2013-02-06 06:26:40 +04:00
|
|
|
height
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Boolean} immediately
|
2013-11-22 00:19:07 +04:00
|
|
|
* @fires OpenSeadragon.Viewer.event:home
|
2013-02-06 06:26:40 +04:00
|
|
|
*/
|
|
|
|
goHome: function( immediately ) {
|
2013-02-14 04:44:23 +04:00
|
|
|
if( this.viewer ){
|
2013-11-16 10:19:53 +04:00
|
|
|
/**
|
2013-11-22 00:19:07 +04:00
|
|
|
* Raised when the "home" operation occurs (see {@link OpenSeadragon.Viewport#goHome}).
|
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @event home
|
|
|
|
* @memberof OpenSeadragon.Viewer
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
|
|
|
|
* @property {Boolean} immediately
|
2013-11-18 18:56:32 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
2013-11-16 10:19:53 +04:00
|
|
|
*/
|
2013-06-19 21:33:25 +04:00
|
|
|
this.viewer.raiseEvent( 'home', {
|
2013-10-11 04:00:15 +04:00
|
|
|
immediately: immediately
|
2013-02-14 04:44:23 +04:00
|
|
|
});
|
|
|
|
}
|
2013-02-06 06:26:40 +04:00
|
|
|
return this.fitBounds( this.getHomeBounds(), immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-05 03:14:20 +04:00
|
|
|
getMinZoom: function() {
|
2012-08-29 22:46:34 +04:00
|
|
|
var homeZoom = this.getHomeZoom(),
|
2013-06-19 21:33:25 +04:00
|
|
|
zoom = this.minZoomLevel ?
|
|
|
|
this.minZoomLevel :
|
2013-02-06 06:26:40 +04:00
|
|
|
this.minZoomImageRatio * homeZoom;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
return Math.min( zoom, homeZoom );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-05 03:14:20 +04:00
|
|
|
getMaxZoom: function() {
|
2013-02-06 06:26:40 +04:00
|
|
|
var zoom = this.maxZoomLevel ?
|
|
|
|
this.maxZoomLevel :
|
|
|
|
( this.contentSize.x * this.maxZoomPixelRatio / this.containerSize.x );
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
return Math.max( zoom, this.getHomeZoom() );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-05 03:14:20 +04:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
getAspectRatio: function() {
|
2012-01-05 03:14:20 +04:00
|
|
|
return this.containerSize.x / this.containerSize.y;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-05 03:14:20 +04:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
getContainerSize: function() {
|
2012-01-25 23:14:02 +04:00
|
|
|
return new $.Point(
|
2013-06-19 21:33:25 +04:00
|
|
|
this.containerSize.x,
|
2012-01-25 23:14:02 +04:00
|
|
|
this.containerSize.y
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2013-08-19 21:14:04 +04:00
|
|
|
* @param {Boolean} current - Pass true for the current location; defaults to false (target location).
|
2012-02-15 23:50:27 +04:00
|
|
|
*/
|
2012-01-05 04:45:47 +04:00
|
|
|
getBounds: function( current ) {
|
2012-01-25 23:14:02 +04:00
|
|
|
var center = this.getCenter( current ),
|
|
|
|
width = 1.0 / this.getZoom( current ),
|
2012-01-05 03:14:20 +04:00
|
|
|
height = width / this.getAspectRatio();
|
|
|
|
|
|
|
|
return new $.Rect(
|
2013-06-19 21:33:25 +04:00
|
|
|
center.x - ( width / 2.0 ),
|
2012-03-07 07:20:00 +04:00
|
|
|
center.y - ( height / 2.0 ),
|
2013-06-19 21:33:25 +04:00
|
|
|
width,
|
2012-01-05 03:14:20 +04:00
|
|
|
height
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2013-08-19 21:14:04 +04:00
|
|
|
* @param {Boolean} current - Pass true for the current location; defaults to false (target location).
|
2012-02-15 23:50:27 +04:00
|
|
|
*/
|
2012-01-05 04:45:47 +04:00
|
|
|
getCenter: function( current ) {
|
2011-12-17 02:56:38 +04:00
|
|
|
var centerCurrent = new $.Point(
|
2012-01-05 03:14:20 +04:00
|
|
|
this.centerSpringX.current.value,
|
|
|
|
this.centerSpringY.current.value
|
|
|
|
),
|
|
|
|
centerTarget = new $.Point(
|
|
|
|
this.centerSpringX.target.value,
|
|
|
|
this.centerSpringY.target.value
|
|
|
|
),
|
|
|
|
oldZoomPixel,
|
|
|
|
zoom,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
bounds,
|
|
|
|
newZoomPixel,
|
|
|
|
deltaZoomPixels,
|
|
|
|
deltaZoomPoints;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
if ( current ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return centerCurrent;
|
2012-01-25 23:14:02 +04:00
|
|
|
} else if ( !this.zoomPoint ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return centerTarget;
|
|
|
|
}
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
oldZoomPixel = this.pixelFromPoint(this.zoomPoint, true);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
zoom = this.getZoom();
|
|
|
|
width = 1.0 / zoom;
|
|
|
|
height = width / this.getAspectRatio();
|
|
|
|
bounds = new $.Rect(
|
|
|
|
centerCurrent.x - width / 2.0,
|
2013-06-19 21:33:25 +04:00
|
|
|
centerCurrent.y - height / 2.0,
|
|
|
|
width,
|
2012-01-05 03:14:20 +04:00
|
|
|
height
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
newZoomPixel = this.zoomPoint.minus(
|
|
|
|
bounds.getTopLeft()
|
|
|
|
).times(
|
|
|
|
this.containerSize.x / bounds.width
|
|
|
|
);
|
|
|
|
deltaZoomPixels = newZoomPixel.minus( oldZoomPixel );
|
|
|
|
deltaZoomPoints = deltaZoomPixels.divide( this.containerSize.x * zoom );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
return centerTarget.plus( deltaZoomPoints );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2013-08-19 21:14:04 +04:00
|
|
|
* @param {Boolean} current - Pass true for the current location; defaults to false (target location).
|
2012-02-15 23:50:27 +04:00
|
|
|
*/
|
2012-01-05 04:45:47 +04:00
|
|
|
getZoom: function( current ) {
|
|
|
|
if ( current ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
return this.zoomSpring.current.value;
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-05 03:14:20 +04:00
|
|
|
return this.zoomSpring.target.value;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2013-02-14 04:44:23 +04:00
|
|
|
* @return {OpenSeadragon.Viewport} Chainable.
|
2013-11-22 00:19:07 +04:00
|
|
|
* @fires OpenSeadragon.Viewer.event:constrain
|
2012-02-15 23:50:27 +04:00
|
|
|
*/
|
2012-01-05 04:45:47 +04:00
|
|
|
applyConstraints: function( immediately ) {
|
|
|
|
var actualZoom = this.getZoom(),
|
|
|
|
constrainedZoom = Math.max(
|
2013-06-19 21:33:25 +04:00
|
|
|
Math.min( actualZoom, this.getMaxZoom() ),
|
2012-01-05 04:45:47 +04:00
|
|
|
this.getMinZoom()
|
|
|
|
),
|
|
|
|
bounds,
|
|
|
|
horizontalThreshold,
|
|
|
|
verticalThreshold,
|
|
|
|
left,
|
|
|
|
right,
|
|
|
|
top,
|
|
|
|
bottom,
|
|
|
|
dx = 0,
|
2013-06-19 01:55:19 +04:00
|
|
|
dy = 0;
|
2012-01-05 04:45:47 +04:00
|
|
|
|
|
|
|
if ( actualZoom != constrainedZoom ) {
|
|
|
|
this.zoomTo( constrainedZoom, this.zoomPoint, immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-05 04:45:47 +04:00
|
|
|
bounds = this.getBounds();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 04:45:47 +04:00
|
|
|
horizontalThreshold = this.visibilityRatio * bounds.width;
|
|
|
|
verticalThreshold = this.visibilityRatio * bounds.height;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 04:45:47 +04:00
|
|
|
left = bounds.x + bounds.width;
|
|
|
|
right = 1 - bounds.x;
|
|
|
|
top = bounds.y + bounds.height;
|
2012-04-03 11:08:27 +04:00
|
|
|
bottom = this.contentAspectY - bounds.y;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
if ( this.wrapHorizontal ) {
|
2012-01-05 04:45:47 +04:00
|
|
|
//do nothing
|
2013-02-06 06:26:40 +04:00
|
|
|
} else {
|
|
|
|
if ( left < horizontalThreshold ) {
|
|
|
|
dx = horizontalThreshold - left;
|
2013-06-19 21:33:25 +04:00
|
|
|
}
|
2013-02-06 06:26:40 +04:00
|
|
|
if ( right < horizontalThreshold ) {
|
2013-06-19 21:33:25 +04:00
|
|
|
dx = dx ?
|
2013-02-06 06:26:40 +04:00
|
|
|
( dx + right - horizontalThreshold ) / 2 :
|
|
|
|
( right - horizontalThreshold );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
if ( this.wrapVertical ) {
|
2012-01-05 04:45:47 +04:00
|
|
|
//do nothing
|
2013-02-06 06:26:40 +04:00
|
|
|
} else {
|
|
|
|
if ( top < verticalThreshold ) {
|
|
|
|
dy = ( verticalThreshold - top );
|
2013-06-19 21:33:25 +04:00
|
|
|
}
|
2013-02-06 06:26:40 +04:00
|
|
|
if ( bottom < verticalThreshold ) {
|
2013-06-19 21:33:25 +04:00
|
|
|
dy = dy ?
|
2013-02-06 06:26:40 +04:00
|
|
|
( dy + bottom - verticalThreshold ) / 2 :
|
|
|
|
( bottom - verticalThreshold );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2013-02-06 06:26:40 +04:00
|
|
|
if ( dx || dy || immediately ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
bounds.x += dx;
|
|
|
|
bounds.y += dy;
|
2013-02-06 06:26:40 +04:00
|
|
|
if( bounds.width > 1 ){
|
|
|
|
bounds.x = 0.5 - bounds.width/2;
|
|
|
|
}
|
|
|
|
if( bounds.height > this.contentAspectY ){
|
|
|
|
bounds.y = this.contentAspectY/2 - bounds.height/2;
|
|
|
|
}
|
2012-01-05 04:45:47 +04:00
|
|
|
this.fitBounds( bounds, immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2013-02-14 04:44:23 +04:00
|
|
|
|
|
|
|
if( this.viewer ){
|
2013-11-16 10:19:53 +04:00
|
|
|
/**
|
2013-11-22 00:19:07 +04:00
|
|
|
* Raised when the viewport constraints are applied (see {@link OpenSeadragon.Viewport#applyConstraints}).
|
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @event constrain
|
|
|
|
* @memberof OpenSeadragon.Viewer
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
|
|
|
|
* @property {Boolean} immediately
|
2013-11-18 18:56:32 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
2013-11-16 10:19:53 +04:00
|
|
|
*/
|
2013-06-19 21:33:25 +04:00
|
|
|
this.viewer.raiseEvent( 'constrain', {
|
2013-10-11 04:00:15 +04:00
|
|
|
immediately: immediately
|
2013-02-14 04:44:23 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-01-31 01:51:37 +04:00
|
|
|
return this;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Boolean} immediately
|
|
|
|
*/
|
2012-01-05 04:45:47 +04:00
|
|
|
ensureVisible: function( immediately ) {
|
2013-02-06 06:26:40 +04:00
|
|
|
return this.applyConstraints( immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-15 23:50:27 +04:00
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Rect} bounds
|
|
|
|
* @param {Boolean} immediately
|
2013-02-14 04:44:23 +04:00
|
|
|
* @return {OpenSeadragon.Viewport} Chainable.
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2012-01-05 04:45:47 +04:00
|
|
|
fitBounds: function( bounds, immediately ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
var aspect = this.getAspectRatio(),
|
|
|
|
center = bounds.getCenter(),
|
|
|
|
newBounds = new $.Rect(
|
2013-06-19 21:33:25 +04:00
|
|
|
bounds.x,
|
|
|
|
bounds.y,
|
|
|
|
bounds.width,
|
2012-01-05 03:14:20 +04:00
|
|
|
bounds.height
|
|
|
|
),
|
|
|
|
oldBounds,
|
|
|
|
oldZoom,
|
|
|
|
newZoom,
|
2012-01-05 04:45:47 +04:00
|
|
|
referencePoint;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
if ( newBounds.getAspectRatio() >= aspect ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
newBounds.height = bounds.width / aspect;
|
2012-01-05 04:45:47 +04:00
|
|
|
newBounds.y = center.y - newBounds.height / 2;
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
|
|
|
newBounds.width = bounds.height * aspect;
|
2012-01-05 04:45:47 +04:00
|
|
|
newBounds.x = center.x - newBounds.width / 2;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
this.panTo( this.getCenter( true ), true );
|
|
|
|
this.zoomTo( this.getZoom( true ), null, true );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
oldBounds = this.getBounds();
|
|
|
|
oldZoom = this.getZoom();
|
|
|
|
newZoom = 1.0 / newBounds.width;
|
2012-01-25 23:14:02 +04:00
|
|
|
if ( newZoom == oldZoom || newBounds.width == oldBounds.width ) {
|
2013-02-06 06:26:40 +04:00
|
|
|
return this.panTo( center, immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
referencePoint = oldBounds.getTopLeft().times(
|
|
|
|
this.containerSize.x / oldBounds.width
|
2012-01-05 03:14:20 +04:00
|
|
|
).minus(
|
2013-06-19 21:33:25 +04:00
|
|
|
newBounds.getTopLeft().times(
|
|
|
|
this.containerSize.x / newBounds.width
|
2012-01-05 03:14:20 +04:00
|
|
|
)
|
|
|
|
).divide(
|
2013-06-19 21:33:25 +04:00
|
|
|
this.containerSize.x / oldBounds.width -
|
2012-01-05 03:14:20 +04:00
|
|
|
this.containerSize.x / newBounds.width
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2013-02-06 06:26:40 +04:00
|
|
|
return this.zoomTo( newZoom, referencePoint, immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Boolean} immediately
|
2013-02-14 04:44:23 +04:00
|
|
|
* @return {OpenSeadragon.Viewport} Chainable.
|
2012-04-03 11:08:27 +04:00
|
|
|
*/
|
|
|
|
fitVertically: function( immediately ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
var center = this.getCenter();
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
if ( this.wrapHorizontal ) {
|
2012-01-25 23:14:02 +04:00
|
|
|
center.x = ( 1 + ( center.x % 1 ) ) % 1;
|
|
|
|
this.centerSpringX.resetTo( center.x );
|
2012-01-05 03:14:20 +04:00
|
|
|
this.centerSpringX.update();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
if ( this.wrapVertical ) {
|
2012-01-25 23:14:02 +04:00
|
|
|
center.y = (
|
2012-04-03 11:08:27 +04:00
|
|
|
this.contentAspectY + ( center.y % this.contentAspectY )
|
|
|
|
) % this.contentAspectY;
|
2012-01-25 23:14:02 +04:00
|
|
|
this.centerSpringY.resetTo( center.y );
|
2012-01-05 03:14:20 +04:00
|
|
|
this.centerSpringY.update();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2013-02-06 06:26:40 +04:00
|
|
|
return this.fitBounds( this.fitHeightBounds, immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Boolean} immediately
|
2013-02-14 04:44:23 +04:00
|
|
|
* @return {OpenSeadragon.Viewport} Chainable.
|
2012-04-03 11:08:27 +04:00
|
|
|
*/
|
|
|
|
fitHorizontally: function( immediately ) {
|
|
|
|
var center = this.getCenter();
|
|
|
|
|
|
|
|
if ( this.wrapHorizontal ) {
|
2013-06-19 21:33:25 +04:00
|
|
|
center.x = (
|
|
|
|
this.contentAspectX + ( center.x % this.contentAspectX )
|
2012-04-03 11:08:27 +04:00
|
|
|
) % this.contentAspectX;
|
|
|
|
this.centerSpringX.resetTo( center.x );
|
|
|
|
this.centerSpringX.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.wrapVertical ) {
|
|
|
|
center.y = ( 1 + ( center.y % 1 ) ) % 1;
|
|
|
|
this.centerSpringY.resetTo( center.y );
|
|
|
|
this.centerSpringY.update();
|
|
|
|
}
|
|
|
|
|
2013-02-06 06:26:40 +04:00
|
|
|
return this.fitBounds( this.fitWidthBounds, immediately );
|
2012-04-03 11:08:27 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} delta
|
|
|
|
* @param {Boolean} immediately
|
2013-02-14 04:44:23 +04:00
|
|
|
* @return {OpenSeadragon.Viewport} Chainable.
|
2013-11-22 07:43:45 +04:00
|
|
|
* @fires OpenSeadragon.Viewer.event:pan
|
2012-02-15 23:50:27 +04:00
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
panBy: function( delta, immediately ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
var center = new $.Point(
|
|
|
|
this.centerSpringX.target.value,
|
|
|
|
this.centerSpringY.target.value
|
|
|
|
);
|
2013-08-14 01:39:22 +04:00
|
|
|
delta = delta.rotate( -this.degrees, new $.Point( 0, 0 ) );
|
2013-02-06 06:26:40 +04:00
|
|
|
return this.panTo( center.plus( delta ), immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} center
|
|
|
|
* @param {Boolean} immediately
|
2013-02-14 04:44:23 +04:00
|
|
|
* @return {OpenSeadragon.Viewport} Chainable.
|
2013-11-22 00:19:07 +04:00
|
|
|
* @fires OpenSeadragon.Viewer.event:pan
|
2012-02-15 23:50:27 +04:00
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
panTo: function( center, immediately ) {
|
|
|
|
if ( immediately ) {
|
|
|
|
this.centerSpringX.resetTo( center.x );
|
|
|
|
this.centerSpringY.resetTo( center.y );
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-25 23:14:02 +04:00
|
|
|
this.centerSpringX.springTo( center.x );
|
|
|
|
this.centerSpringY.springTo( center.y );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2013-01-31 01:51:37 +04:00
|
|
|
|
2013-02-14 04:44:23 +04:00
|
|
|
if( this.viewer ){
|
2013-11-16 10:19:53 +04:00
|
|
|
/**
|
2013-11-22 07:43:45 +04:00
|
|
|
* Raised when the viewport is panned (see {@link OpenSeadragon.Viewport#panBy} and {@link OpenSeadragon.Viewport#panTo}).
|
2013-11-22 00:19:07 +04:00
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @event pan
|
|
|
|
* @memberof OpenSeadragon.Viewer
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
|
|
|
|
* @property {OpenSeadragon.Point} center
|
|
|
|
* @property {Boolean} immediately
|
2013-11-18 18:56:32 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
2013-11-16 10:19:53 +04:00
|
|
|
*/
|
2013-06-19 21:33:25 +04:00
|
|
|
this.viewer.raiseEvent( 'pan', {
|
2013-02-14 04:44:23 +04:00
|
|
|
center: center,
|
2013-10-11 04:00:15 +04:00
|
|
|
immediately: immediately
|
2013-02-14 04:44:23 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-01-31 01:51:37 +04:00
|
|
|
return this;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2013-02-14 04:44:23 +04:00
|
|
|
* @return {OpenSeadragon.Viewport} Chainable.
|
2013-11-22 00:19:07 +04:00
|
|
|
* @fires OpenSeadragon.Viewer.event:zoom
|
2012-02-15 23:50:27 +04:00
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
zoomBy: function( factor, refPoint, immediately ) {
|
2013-10-04 23:09:58 +04:00
|
|
|
if( refPoint instanceof $.Point && !isNaN( refPoint.x ) && !isNaN( refPoint.y ) ) {
|
2013-08-14 01:39:22 +04:00
|
|
|
refPoint = refPoint.rotate(
|
|
|
|
-this.degrees,
|
|
|
|
new $.Point( this.centerSpringX.target.value, this.centerSpringY.target.value )
|
|
|
|
);
|
|
|
|
}
|
2013-02-06 06:26:40 +04:00
|
|
|
return this.zoomTo( this.zoomSpring.target.value * factor, refPoint, immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2013-02-14 04:44:23 +04:00
|
|
|
* @return {OpenSeadragon.Viewport} Chainable.
|
2013-11-22 00:19:07 +04:00
|
|
|
* @fires OpenSeadragon.Viewer.event:zoom
|
2012-02-15 23:50:27 +04:00
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
zoomTo: function( zoom, refPoint, immediately ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2013-10-04 20:12:47 +04:00
|
|
|
this.zoomPoint = refPoint instanceof $.Point &&
|
|
|
|
!isNaN(refPoint.x) &&
|
|
|
|
!isNaN(refPoint.y) ?
|
2013-06-19 21:33:25 +04:00
|
|
|
refPoint :
|
2013-01-31 01:51:37 +04:00
|
|
|
null;
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
if ( immediately ) {
|
|
|
|
this.zoomSpring.resetTo( zoom );
|
2013-06-19 21:33:25 +04:00
|
|
|
} else {
|
2012-01-25 23:14:02 +04:00
|
|
|
this.zoomSpring.springTo( zoom );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2013-02-14 04:44:23 +04:00
|
|
|
if( this.viewer ){
|
2013-11-16 10:19:53 +04:00
|
|
|
/**
|
2013-11-22 00:19:07 +04:00
|
|
|
* Raised when the viewport zoom level changes (see {@link OpenSeadragon.Viewport#zoomBy} and {@link OpenSeadragon.Viewport#zoomTo}).
|
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @event zoom
|
|
|
|
* @memberof OpenSeadragon.Viewer
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
|
|
|
|
* @property {Number} zoom
|
|
|
|
* @property {OpenSeadragon.Point} refPoint
|
|
|
|
* @property {Boolean} immediately
|
2013-11-18 18:56:32 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
2013-11-16 10:19:53 +04:00
|
|
|
*/
|
2013-06-19 21:33:25 +04:00
|
|
|
this.viewer.raiseEvent( 'zoom', {
|
2013-02-14 04:44:23 +04:00
|
|
|
zoom: zoom,
|
|
|
|
refPoint: refPoint,
|
2013-10-11 04:00:15 +04:00
|
|
|
immediately: immediately
|
2013-02-14 04:44:23 +04:00
|
|
|
});
|
|
|
|
}
|
2013-01-31 01:51:37 +04:00
|
|
|
|
|
|
|
return this;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2013-08-16 02:15:20 +04:00
|
|
|
/**
|
2013-08-20 02:27:00 +04:00
|
|
|
* Currently only 90 degree rotation is supported and it only works
|
|
|
|
* with the canvas. Additionally, the navigator does not rotate yet,
|
|
|
|
* debug mode doesn't rotate yet, and overlay rotation is only
|
|
|
|
* partially supported.
|
2013-08-16 02:15:20 +04:00
|
|
|
* @function
|
|
|
|
* @return {OpenSeadragon.Viewport} Chainable.
|
|
|
|
*/
|
2013-08-16 21:32:21 +04:00
|
|
|
setRotation: function( degrees ) {
|
|
|
|
if( !( this.viewer && this.viewer.drawer.canRotate() ) ) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-08-16 02:15:20 +04:00
|
|
|
degrees = ( degrees + 360 ) % 360;
|
2013-08-16 21:32:21 +04:00
|
|
|
if( degrees % 90 !== 0 ) {
|
2013-08-16 02:15:20 +04:00
|
|
|
throw new Error('Currently only 0, 90, 180, and 270 degrees are supported.');
|
|
|
|
}
|
|
|
|
this.degrees = degrees;
|
2013-12-09 18:26:36 +04:00
|
|
|
this.viewer.forceRedraw();
|
2013-08-20 02:27:00 +04:00
|
|
|
|
2013-08-16 02:15:20 +04:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2013-08-16 21:32:21 +04:00
|
|
|
/**
|
|
|
|
* Gets the current rotation in degrees.
|
|
|
|
* @function
|
|
|
|
* @return {Number} The current rotation in degrees.
|
|
|
|
*/
|
|
|
|
getRotation: function() {
|
|
|
|
return this.degrees;
|
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2013-02-14 04:44:23 +04:00
|
|
|
* @return {OpenSeadragon.Viewport} Chainable.
|
2013-11-22 00:19:07 +04:00
|
|
|
* @fires OpenSeadragon.Viewer.event:resize
|
2012-02-15 23:50:27 +04:00
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
resize: function( newContainerSize, maintain ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
var oldBounds = this.getBounds(),
|
|
|
|
newBounds = oldBounds,
|
2013-11-23 05:07:44 +04:00
|
|
|
widthDeltaFactor;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
this.containerSize = new $.Point(
|
2013-06-19 21:33:25 +04:00
|
|
|
newContainerSize.x,
|
2012-01-25 23:14:02 +04:00
|
|
|
newContainerSize.y
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2013-11-23 05:07:44 +04:00
|
|
|
if ( maintain ) {
|
|
|
|
widthDeltaFactor = newContainerSize.x / this.containerSize.x;
|
2012-01-18 03:30:41 +04:00
|
|
|
newBounds.width = oldBounds.width * widthDeltaFactor;
|
2011-12-06 07:50:25 +04:00
|
|
|
newBounds.height = newBounds.width / this.getAspectRatio();
|
|
|
|
}
|
|
|
|
|
2013-02-14 04:44:23 +04:00
|
|
|
if( this.viewer ){
|
2013-11-16 10:19:53 +04:00
|
|
|
/**
|
2013-11-22 00:19:07 +04:00
|
|
|
* Raised when the viewer is resized (see {@link OpenSeadragon.Viewport#resize}).
|
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @event resize
|
|
|
|
* @memberof OpenSeadragon.Viewer
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
|
|
|
|
* @property {OpenSeadragon.Point} newContainerSize
|
|
|
|
* @property {Boolean} maintain
|
2013-11-18 18:56:32 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
2013-11-16 10:19:53 +04:00
|
|
|
*/
|
2013-06-19 21:33:25 +04:00
|
|
|
this.viewer.raiseEvent( 'resize', {
|
2013-02-14 04:44:23 +04:00
|
|
|
newContainerSize: newContainerSize,
|
2013-10-11 04:00:15 +04:00
|
|
|
maintain: maintain
|
2013-02-14 04:44:23 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-02-06 06:26:40 +04:00
|
|
|
return this.fitBounds( newBounds, true );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
update: function() {
|
2012-01-05 03:14:20 +04:00
|
|
|
var oldCenterX = this.centerSpringX.current.value,
|
|
|
|
oldCenterY = this.centerSpringY.current.value,
|
|
|
|
oldZoom = this.zoomSpring.current.value,
|
|
|
|
oldZoomPixel,
|
|
|
|
newZoomPixel,
|
|
|
|
deltaZoomPixels,
|
|
|
|
deltaZoomPoints;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
if (this.zoomPoint) {
|
2012-01-25 23:14:02 +04:00
|
|
|
oldZoomPixel = this.pixelFromPoint( this.zoomPoint, true );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
this.zoomSpring.update();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
if (this.zoomPoint && this.zoomSpring.current.value != oldZoom) {
|
|
|
|
newZoomPixel = this.pixelFromPoint( this.zoomPoint, true );
|
2012-01-25 23:14:02 +04:00
|
|
|
deltaZoomPixels = newZoomPixel.minus( oldZoomPixel );
|
2012-01-05 03:14:20 +04:00
|
|
|
deltaZoomPoints = this.deltaPointsFromPixels( deltaZoomPixels, true );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
this.centerSpringX.shiftBy( deltaZoomPoints.x );
|
|
|
|
this.centerSpringY.shiftBy( deltaZoomPoints.y );
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
|
|
|
this.zoomPoint = null;
|
|
|
|
}
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
this.centerSpringX.update();
|
|
|
|
this.centerSpringY.update();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
return this.centerSpringX.current.value != oldCenterX ||
|
|
|
|
this.centerSpringY.current.value != oldCenterY ||
|
|
|
|
this.zoomSpring.current.value != oldZoom;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
2013-10-05 18:21:12 +04:00
|
|
|
* Convert a delta (translation vector) from pixels coordinates to viewport coordinates
|
2012-02-15 23:50:27 +04:00
|
|
|
* @function
|
2013-08-19 21:14:04 +04:00
|
|
|
* @param {Boolean} current - Pass true for the current location; defaults to false (target location).
|
2012-02-15 23:50:27 +04:00
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
deltaPixelsFromPoints: function( deltaPoints, current ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
return deltaPoints.times(
|
|
|
|
this.containerSize.x * this.getZoom( current )
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
2013-10-05 18:21:12 +04:00
|
|
|
* Convert a delta (translation vector) from viewport coordinates to pixels coordinates.
|
2012-02-15 23:50:27 +04:00
|
|
|
* @function
|
2013-08-19 21:14:04 +04:00
|
|
|
* @param {Boolean} current - Pass true for the current location; defaults to false (target location).
|
2012-02-15 23:50:27 +04:00
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
deltaPointsFromPixels: function( deltaPixels, current ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
return deltaPixels.divide(
|
|
|
|
this.containerSize.x * this.getZoom( current )
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
2013-10-04 01:26:44 +04:00
|
|
|
* Convert image pixel coordinates to viewport coordinates.
|
2012-02-15 23:50:27 +04:00
|
|
|
* @function
|
2013-08-19 21:14:04 +04:00
|
|
|
* @param {Boolean} current - Pass true for the current location; defaults to false (target location).
|
2012-02-15 23:50:27 +04:00
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
pixelFromPoint: function( point, current ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
var bounds = this.getBounds( current );
|
|
|
|
return point.minus(
|
|
|
|
bounds.getTopLeft()
|
|
|
|
).times(
|
|
|
|
this.containerSize.x / bounds.width
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
2013-10-04 01:26:44 +04:00
|
|
|
* Convert viewport coordinates to image pixel coordinates.
|
2012-02-15 23:50:27 +04:00
|
|
|
* @function
|
2013-08-19 21:14:04 +04:00
|
|
|
* @param {Boolean} current - Pass true for the current location; defaults to false (target location).
|
2012-02-15 23:50:27 +04:00
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
pointFromPixel: function( pixel, current ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
var bounds = this.getBounds( current );
|
|
|
|
return pixel.divide(
|
|
|
|
this.containerSize.x / bounds.width
|
|
|
|
).plus(
|
|
|
|
bounds.getTopLeft()
|
|
|
|
);
|
2013-02-11 07:53:51 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-09-06 03:26:00 +04:00
|
|
|
* Translates from OpenSeadragon viewer coordinate system to image coordinate system.
|
2013-09-04 22:13:25 +04:00
|
|
|
* 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.
|
2013-02-11 07:53:51 +04:00
|
|
|
*/
|
2013-09-04 22:13:25 +04:00
|
|
|
viewportToImageCoordinates: function( viewerX, viewerY ) {
|
2013-08-30 21:59:48 +04:00
|
|
|
if ( arguments.length == 1 ) {
|
|
|
|
//they passed a point instead of individual components
|
2013-09-04 22:13:25 +04:00
|
|
|
return this.viewportToImageCoordinates( viewerX.x, viewerX.y );
|
2013-08-30 21:59:48 +04:00
|
|
|
}
|
2013-09-04 22:13:25 +04:00
|
|
|
return new $.Point( viewerX * this.contentSize.x, viewerY * this.contentSize.y * this.contentAspectX );
|
2013-02-11 07:53:51 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-09-06 03:26:00 +04:00
|
|
|
* Translates from image coordinate system to OpenSeadragon viewer coordinate system
|
2013-09-04 22:13:25 +04:00
|
|
|
* 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.
|
2013-02-11 07:53:51 +04:00
|
|
|
*/
|
|
|
|
imageToViewportCoordinates: function( imageX, imageY ) {
|
2013-08-30 21:59:48 +04:00
|
|
|
if ( arguments.length == 1 ) {
|
|
|
|
//they passed a point instead of individual components
|
2013-09-04 22:13:25 +04:00
|
|
|
return this.imageToViewportCoordinates( imageX.x, imageX.y );
|
2013-08-30 21:59:48 +04:00
|
|
|
}
|
2013-09-04 22:13:25 +04:00
|
|
|
return new $.Point( imageX / this.contentSize.x, imageY / this.contentSize.y / this.contentAspectX );
|
2013-02-11 07:53:51 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-09-04 22:13:25 +04:00
|
|
|
* 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.
|
2013-02-11 07:53:51 +04:00
|
|
|
*/
|
|
|
|
imageToViewportRectangle: function( imageX, imageY, pixelWidth, pixelHeight ) {
|
|
|
|
var coordA,
|
|
|
|
coordB,
|
|
|
|
rect;
|
2013-08-30 21:59:48 +04:00
|
|
|
if( arguments.length == 1 ) {
|
2013-02-11 07:53:51 +04:00
|
|
|
//they passed a rectangle instead of individual components
|
|
|
|
rect = imageX;
|
2013-09-04 22:13:25 +04:00
|
|
|
return this.imageToViewportRectangle(
|
|
|
|
rect.x, rect.y, rect.width, rect.height
|
|
|
|
);
|
2013-02-11 07:53:51 +04:00
|
|
|
}
|
|
|
|
coordA = this.imageToViewportCoordinates(
|
|
|
|
imageX, imageY
|
|
|
|
);
|
|
|
|
coordB = this.imageToViewportCoordinates(
|
|
|
|
pixelWidth, pixelHeight
|
|
|
|
);
|
2013-06-19 21:33:25 +04:00
|
|
|
return new $.Rect(
|
2013-02-11 07:53:51 +04:00
|
|
|
coordA.x,
|
|
|
|
coordA.y,
|
2013-06-25 20:01:38 +04:00
|
|
|
coordB.x,
|
|
|
|
coordB.y
|
2013-02-11 07:53:51 +04:00
|
|
|
);
|
2013-08-30 21:59:48 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Translates from a rectangle which describes a portion of
|
|
|
|
* the viewport in point coordinates to image rectangle coordinates.
|
2013-09-04 22:13:25 +04:00
|
|
|
* 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.
|
2013-08-30 21:59:48 +04:00
|
|
|
*/
|
|
|
|
viewportToImageRectangle: function( viewerX, viewerY, pointWidth, pointHeight ) {
|
|
|
|
var coordA,
|
|
|
|
coordB,
|
|
|
|
rect;
|
|
|
|
if ( arguments.length == 1 ) {
|
|
|
|
//they passed a rectangle instead of individual components
|
|
|
|
rect = viewerX;
|
2013-09-04 22:13:25 +04:00
|
|
|
return this.viewportToImageRectangle(
|
|
|
|
rect.x, rect.y, rect.width, rect.height
|
|
|
|
);
|
2013-08-30 21:59:48 +04:00
|
|
|
}
|
2013-09-04 22:13:25 +04:00
|
|
|
coordA = this.viewportToImageCoordinates( viewerX, viewerY );
|
|
|
|
coordB = this.viewportToImageCoordinates( pointWidth, pointHeight );
|
2013-08-30 21:59:48 +04:00
|
|
|
return new $.Rect(
|
|
|
|
coordA.x,
|
|
|
|
coordA.y,
|
|
|
|
coordB.x,
|
|
|
|
coordB.y
|
|
|
|
);
|
2013-10-04 01:26:44 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-10-05 18:21:12 +04:00
|
|
|
* Convert pixel coordinates relative to the viewer element to image
|
2013-10-04 01:26:44 +04:00
|
|
|
* coordinates.
|
|
|
|
* @param {OpenSeadragon.Point} pixel
|
|
|
|
* @returns {OpenSeadragon.Point}
|
|
|
|
*/
|
|
|
|
viewerElementToImageCoordinates: function( pixel ) {
|
|
|
|
var point = this.pointFromPixel( pixel, true );
|
|
|
|
return this.viewportToImageCoordinates( point );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-10-05 18:21:12 +04:00
|
|
|
* Convert pixel coordinates relative to the image to
|
2013-10-04 01:26:44 +04:00
|
|
|
* viewer element coordinates.
|
2014-02-05 02:02:11 +04:00
|
|
|
* @param {OpenSeadragon.Point} pixel
|
2013-10-04 01:26:44 +04:00
|
|
|
* @returns {OpenSeadragon.Point}
|
|
|
|
*/
|
2014-02-05 02:02:11 +04:00
|
|
|
imageToViewerElementCoordinates: function( pixel ) {
|
|
|
|
var point = this.imageToViewportCoordinates( pixel );
|
|
|
|
return this.pixelFromPoint( point, true );
|
2013-10-04 01:26:44 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-10-05 18:21:12 +04:00
|
|
|
* Convert pixel coordinates relative to the window to image coordinates.
|
2013-10-04 01:26:44 +04:00
|
|
|
* @param {OpenSeadragon.Point} pixel
|
|
|
|
* @returns {OpenSeadragon.Point}
|
|
|
|
*/
|
|
|
|
windowToImageCoordinates: function( pixel ) {
|
|
|
|
var viewerCoordinates = pixel.minus(
|
|
|
|
OpenSeadragon.getElementPosition( this.viewer.element ));
|
|
|
|
return this.viewerElementToImageCoordinates( viewerCoordinates );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-10-05 18:21:12 +04:00
|
|
|
* Convert image coordinates to pixel coordinates relative to the window.
|
2013-10-04 01:26:44 +04:00
|
|
|
* @param {OpenSeadragon.Point} pixel
|
|
|
|
* @returns {OpenSeadragon.Point}
|
|
|
|
*/
|
|
|
|
imageToWindowCoordinates: function( pixel ) {
|
|
|
|
var viewerCoordinates = this.imageToViewerElementCoordinates( pixel );
|
|
|
|
return viewerCoordinates.plus(
|
|
|
|
OpenSeadragon.getElementPosition( this.viewer.element ));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-10-05 18:21:12 +04:00
|
|
|
* Convert pixel coordinates relative to the viewer element to viewport
|
2013-10-04 01:26:44 +04:00
|
|
|
* coordinates.
|
|
|
|
* @param {OpenSeadragon.Point} pixel
|
|
|
|
* @returns {OpenSeadragon.Point}
|
|
|
|
*/
|
|
|
|
viewerElementToViewportCoordinates: function( pixel ) {
|
|
|
|
return this.pointFromPixel( pixel, true );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-10-05 18:21:12 +04:00
|
|
|
* Convert viewport coordinates to pixel coordinates relative to the
|
2013-10-04 01:26:44 +04:00
|
|
|
* viewer element.
|
|
|
|
* @param {OpenSeadragon.Point} point
|
|
|
|
* @returns {OpenSeadragon.Point}
|
|
|
|
*/
|
|
|
|
viewportToViewerElementCoordinates: function( point ) {
|
|
|
|
return this.pixelFromPoint( point, true );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-10-05 18:21:12 +04:00
|
|
|
* Convert pixel coordinates relative to the window to viewport coordinates.
|
2013-10-04 01:26:44 +04:00
|
|
|
* @param {OpenSeadragon.Point} pixel
|
|
|
|
* @returns {OpenSeadragon.Point}
|
|
|
|
*/
|
|
|
|
windowToViewportCoordinates: function( pixel ) {
|
|
|
|
var viewerCoordinates = pixel.minus(
|
|
|
|
OpenSeadragon.getElementPosition( this.viewer.element ));
|
|
|
|
return this.viewerElementToViewportCoordinates( viewerCoordinates );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-10-05 18:21:12 +04:00
|
|
|
* Convert viewport coordinates to pixel coordinates relative to the window.
|
2013-10-04 01:26:44 +04:00
|
|
|
* @param {OpenSeadragon.Point} point
|
|
|
|
* @returns {OpenSeadragon.Point}
|
|
|
|
*/
|
|
|
|
viewportToWindowCoordinates: function( point ) {
|
|
|
|
var viewerCoordinates = this.viewportToViewerElementCoordinates( point );
|
|
|
|
return viewerCoordinates.plus(
|
|
|
|
OpenSeadragon.getElementPosition( this.viewer.element ));
|
|
|
|
},
|
2013-10-18 23:16:49 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a viewport zoom to an image zoom.
|
|
|
|
* Image zoom: ratio of the original image size to displayed image size.
|
|
|
|
* 1 means original image size, 0.5 half size...
|
|
|
|
* Viewport zoom: ratio of the displayed image's width to viewport's width.
|
|
|
|
* 1 means identical width, 2 means image's width is twice the viewport's width...
|
|
|
|
* @function
|
|
|
|
* @param {Number} viewportZoom The viewport zoom
|
|
|
|
* target zoom.
|
|
|
|
* @returns {Number} imageZoom The image zoom
|
|
|
|
*/
|
|
|
|
viewportToImageZoom: function( viewportZoom ) {
|
|
|
|
var imageWidth = this.viewer.source.dimensions.x;
|
|
|
|
var containerWidth = this.getContainerSize().x;
|
|
|
|
var viewportToImageZoomRatio = containerWidth / imageWidth;
|
|
|
|
return viewportZoom * viewportToImageZoomRatio;
|
|
|
|
},
|
|
|
|
|
2013-10-04 01:26:44 +04:00
|
|
|
/**
|
2013-10-18 23:16:49 +04:00
|
|
|
* Convert an image zoom to a viewport zoom.
|
|
|
|
* Image zoom: ratio of the original image size to displayed image size.
|
|
|
|
* 1 means original image size, 0.5 half size...
|
|
|
|
* Viewport zoom: ratio of the displayed image's width to viewport's width.
|
|
|
|
* 1 means identical width, 2 means image's width is twice the viewport's width...
|
2013-10-04 01:26:44 +04:00
|
|
|
* @function
|
2013-10-18 23:16:49 +04:00
|
|
|
* @param {Number} imageZoom The image zoom
|
2013-10-04 01:26:44 +04:00
|
|
|
* target zoom.
|
2013-10-18 23:16:49 +04:00
|
|
|
* @returns {Number} viewportZoom The viewport zoom
|
2013-10-04 01:26:44 +04:00
|
|
|
*/
|
2013-10-18 23:16:49 +04:00
|
|
|
imageToViewportZoom: function( imageZoom ) {
|
2013-10-04 01:26:44 +04:00
|
|
|
var imageWidth = this.viewer.source.dimensions.x;
|
|
|
|
var containerWidth = this.getContainerSize().x;
|
2013-10-18 23:16:49 +04:00
|
|
|
var viewportToImageZoomRatio = imageWidth / containerWidth;
|
|
|
|
return imageZoom * viewportToImageZoomRatio;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|