2013-05-01 08:46:16 +04:00
|
|
|
/*
|
2013-05-14 08:00:24 +04:00
|
|
|
* OpenSeadragon - Overlay
|
2013-05-01 08:46:16 +04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2009 CodePlex Foundation
|
2024-07-09 16:08:58 +03:00
|
|
|
* Copyright (C) 2010-2024 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.
|
|
|
|
*/
|
|
|
|
|
2016-03-25 23:49:58 +03:00
|
|
|
(function($) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2014-02-05 23:57:47 +04:00
|
|
|
* An enumeration of positions that an overlay may be assigned relative to
|
|
|
|
* the viewport.
|
2016-03-22 22:50:48 +03:00
|
|
|
* It is identical to OpenSeadragon.Placement but is kept for backward
|
|
|
|
* compatibility.
|
2013-11-16 10:19:53 +04:00
|
|
|
* @member OverlayPlacement
|
|
|
|
* @memberof OpenSeadragon
|
2017-01-06 06:30:09 +03:00
|
|
|
* @see OpenSeadragon.Placement
|
2012-01-25 23:14:02 +04:00
|
|
|
* @static
|
2016-04-11 02:01:30 +03:00
|
|
|
* @readonly
|
2013-11-22 00:19:07 +04:00
|
|
|
* @type {Object}
|
|
|
|
* @property {Number} CENTER
|
|
|
|
* @property {Number} TOP_LEFT
|
|
|
|
* @property {Number} TOP
|
|
|
|
* @property {Number} TOP_RIGHT
|
|
|
|
* @property {Number} RIGHT
|
|
|
|
* @property {Number} BOTTOM_RIGHT
|
|
|
|
* @property {Number} BOTTOM
|
|
|
|
* @property {Number} BOTTOM_LEFT
|
|
|
|
* @property {Number} LEFT
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2016-03-22 22:50:48 +03:00
|
|
|
$.OverlayPlacement = $.Placement;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2016-03-29 00:06:59 +03:00
|
|
|
/**
|
|
|
|
* An enumeration of possible ways to handle overlays rotation
|
2016-04-11 02:01:30 +03:00
|
|
|
* @member OverlayRotationMode
|
2016-03-29 00:06:59 +03:00
|
|
|
* @memberOf OpenSeadragon
|
|
|
|
* @static
|
2016-04-11 02:01:30 +03:00
|
|
|
* @readonly
|
2016-03-29 00:06:59 +03:00
|
|
|
* @property {Number} NO_ROTATION The overlay ignore the viewport rotation.
|
|
|
|
* @property {Number} EXACT The overlay use CSS 3 transforms to rotate with
|
|
|
|
* the viewport. If the overlay contains text, it will get rotated as well.
|
|
|
|
* @property {Number} BOUNDING_BOX The overlay adjusts for rotation by
|
|
|
|
* taking the size of the bounding box of the rotated bounds.
|
|
|
|
* Only valid for overlays with Rect location and scalable in both directions.
|
|
|
|
*/
|
2016-04-11 02:01:30 +03:00
|
|
|
$.OverlayRotationMode = $.freezeObject({
|
2016-03-29 00:06:59 +03:00
|
|
|
NO_ROTATION: 1,
|
|
|
|
EXACT: 2,
|
|
|
|
BOUNDING_BOX: 3
|
2016-04-11 02:01:30 +03:00
|
|
|
});
|
2016-03-29 00:06:59 +03:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2013-11-16 10:19:53 +04:00
|
|
|
* @class Overlay
|
2013-11-25 20:48:44 +04:00
|
|
|
* @classdesc Provides a way to float an HTML element on top of the viewer element.
|
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @memberof OpenSeadragon
|
2013-11-25 20:48:44 +04:00
|
|
|
* @param {Object} options
|
|
|
|
* @param {Element} options.element
|
2014-02-05 23:57:47 +04:00
|
|
|
* @param {OpenSeadragon.Point|OpenSeadragon.Rect} options.location - The
|
|
|
|
* location of the overlay on the image. If a {@link OpenSeadragon.Point}
|
2016-03-30 22:12:50 +03:00
|
|
|
* is specified, the overlay will be located at this location with respect
|
|
|
|
* to the placement option. If a {@link OpenSeadragon.Rect} is specified,
|
|
|
|
* the overlay will be placed at this location with the corresponding width
|
|
|
|
* and height and placement TOP_LEFT.
|
2016-03-22 22:50:48 +03:00
|
|
|
* @param {OpenSeadragon.Placement} [options.placement=OpenSeadragon.Placement.TOP_LEFT]
|
2016-03-30 22:12:50 +03:00
|
|
|
* Defines what part of the overlay should be at the specified options.location
|
2014-03-20 23:39:31 +04:00
|
|
|
* @param {OpenSeadragon.Overlay.OnDrawCallback} [options.onDraw]
|
|
|
|
* @param {Boolean} [options.checkResize=true] Set to false to avoid to
|
2018-09-01 11:59:20 +03:00
|
|
|
* check the size of the overlay every time it is drawn in the directions
|
2016-03-30 22:12:50 +03:00
|
|
|
* which are not scaled. It will improve performances but will cause a
|
|
|
|
* misalignment if the overlay size changes.
|
|
|
|
* @param {Number} [options.width] The width of the overlay in viewport
|
|
|
|
* coordinates. If specified, the width of the overlay will be adjusted when
|
|
|
|
* the zoom changes.
|
|
|
|
* @param {Number} [options.height] The height of the overlay in viewport
|
|
|
|
* coordinates. If specified, the height of the overlay will be adjusted when
|
|
|
|
* the zoom changes.
|
2016-03-29 00:06:59 +03:00
|
|
|
* @param {Boolean} [options.rotationMode=OpenSeadragon.OverlayRotationMode.EXACT]
|
|
|
|
* How to handle the rotation of the viewport.
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2016-03-25 23:49:58 +03:00
|
|
|
$.Overlay = function(element, location, placement) {
|
2013-07-16 06:04:37 +04:00
|
|
|
|
2013-11-25 20:48:44 +04:00
|
|
|
/**
|
|
|
|
* onDraw callback signature used by {@link OpenSeadragon.Overlay}.
|
|
|
|
*
|
|
|
|
* @callback OnDrawCallback
|
|
|
|
* @memberof OpenSeadragon.Overlay
|
|
|
|
* @param {OpenSeadragon.Point} position
|
|
|
|
* @param {OpenSeadragon.Point} size
|
|
|
|
* @param {Element} element
|
|
|
|
*/
|
|
|
|
|
2013-07-16 06:04:37 +04:00
|
|
|
var options;
|
2016-03-25 23:49:58 +03:00
|
|
|
if ($.isPlainObject(element)) {
|
2013-07-16 06:04:37 +04:00
|
|
|
options = element;
|
2014-02-05 23:57:47 +04:00
|
|
|
} else {
|
2013-07-16 06:04:37 +04:00
|
|
|
options = {
|
|
|
|
element: element,
|
|
|
|
location: location,
|
|
|
|
placement: placement
|
|
|
|
};
|
|
|
|
}
|
2014-11-04 04:14:17 +03:00
|
|
|
|
2016-03-30 22:12:50 +03:00
|
|
|
this.element = options.element;
|
2024-07-12 00:08:37 +03:00
|
|
|
this.element.innerHTML = "<div>" + this.element.innerHTML + "</div>";
|
2016-03-25 23:49:58 +03:00
|
|
|
this.style = options.element.style;
|
2016-03-30 22:12:50 +03:00
|
|
|
this._init(options);
|
2011-12-14 02:38:36 +04:00
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2016-01-25 00:09:18 +03:00
|
|
|
/** @lends OpenSeadragon.Overlay.prototype */
|
|
|
|
$.Overlay.prototype = {
|
2016-04-01 20:31:36 +03:00
|
|
|
|
2016-03-30 22:12:50 +03:00
|
|
|
// private
|
|
|
|
_init: function(options) {
|
|
|
|
this.location = options.location;
|
|
|
|
this.placement = options.placement === undefined ?
|
|
|
|
$.Placement.TOP_LEFT : options.placement;
|
|
|
|
this.onDraw = options.onDraw;
|
|
|
|
this.checkResize = options.checkResize === undefined ?
|
|
|
|
true : options.checkResize;
|
2016-03-31 22:45:44 +03:00
|
|
|
|
|
|
|
// When this.width is not null, the overlay get scaled horizontally
|
2016-03-30 22:12:50 +03:00
|
|
|
this.width = options.width === undefined ? null : options.width;
|
2016-03-31 22:45:44 +03:00
|
|
|
|
|
|
|
// When this.height is not null, the overlay get scaled vertically
|
2016-03-30 22:12:50 +03:00
|
|
|
this.height = options.height === undefined ? null : options.height;
|
2016-03-31 22:45:44 +03:00
|
|
|
|
2016-03-30 22:12:50 +03:00
|
|
|
this.rotationMode = options.rotationMode || $.OverlayRotationMode.EXACT;
|
|
|
|
|
2016-03-31 22:45:44 +03:00
|
|
|
// Having a rect as location is a syntactic sugar
|
2016-03-30 22:12:50 +03:00
|
|
|
if (this.location instanceof $.Rect) {
|
|
|
|
this.width = this.location.width;
|
|
|
|
this.height = this.location.height;
|
|
|
|
this.location = this.location.getTopLeft();
|
|
|
|
this.placement = $.Placement.TOP_LEFT;
|
|
|
|
}
|
2016-04-05 20:05:32 +03:00
|
|
|
|
|
|
|
// Deprecated properties kept for backward compatibility.
|
|
|
|
this.scales = this.width !== null && this.height !== null;
|
|
|
|
this.bounds = new $.Rect(
|
|
|
|
this.location.x, this.location.y, this.width, this.height);
|
|
|
|
this.position = this.location;
|
2016-03-30 22:12:50 +03:00
|
|
|
},
|
2016-04-01 20:31:36 +03:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
2016-03-30 22:12:50 +03:00
|
|
|
* Internal function to adjust the position of an overlay
|
|
|
|
* depending on it size and placement.
|
2012-02-15 23:50:27 +04:00
|
|
|
* @function
|
2016-03-22 22:50:48 +03:00
|
|
|
* @param {OpenSeadragon.Point} position
|
2012-02-15 23:50:27 +04:00
|
|
|
* @param {OpenSeadragon.Point} size
|
|
|
|
*/
|
2016-03-22 22:50:48 +03:00
|
|
|
adjust: function(position, size) {
|
|
|
|
var properties = $.Placement.properties[this.placement];
|
|
|
|
if (!properties) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (properties.isHorizontallyCentered) {
|
|
|
|
position.x -= size.x / 2;
|
|
|
|
} else if (properties.isRight) {
|
|
|
|
position.x -= size.x;
|
|
|
|
}
|
|
|
|
if (properties.isVerticallyCentered) {
|
|
|
|
position.y -= size.y / 2;
|
|
|
|
} else if (properties.isBottom) {
|
|
|
|
position.y -= size.y;
|
2011-12-14 02:38:36 +04:00
|
|
|
}
|
|
|
|
},
|
2016-04-01 20:31:36 +03:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-14 02:38:36 +04:00
|
|
|
destroy: function() {
|
2016-03-25 23:49:58 +03:00
|
|
|
var element = this.element;
|
|
|
|
var style = this.style;
|
2011-12-14 02:38:36 +04:00
|
|
|
|
2016-03-25 23:49:58 +03:00
|
|
|
if (element.parentNode) {
|
|
|
|
element.parentNode.removeChild(element);
|
2013-02-11 07:53:51 +04:00
|
|
|
//this should allow us to preserve overlays when required between
|
|
|
|
//pages
|
2016-03-25 23:49:58 +03:00
|
|
|
if (element.prevElementParent) {
|
2013-02-11 07:53:51 +04:00
|
|
|
style.display = 'none';
|
2013-06-19 21:33:25 +04:00
|
|
|
//element.prevElementParent.insertBefore(
|
2013-02-11 07:53:51 +04:00
|
|
|
// element,
|
|
|
|
// element.prevNextSibling
|
|
|
|
//);
|
2016-03-25 23:49:58 +03:00
|
|
|
document.body.appendChild(element);
|
2013-02-11 07:53:51 +04:00
|
|
|
}
|
2011-12-14 02:38:36 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2013-08-07 04:54:20 +04:00
|
|
|
// clear the onDraw callback
|
|
|
|
this.onDraw = null;
|
|
|
|
|
2011-12-14 02:38:36 +04:00
|
|
|
style.top = "";
|
|
|
|
style.left = "";
|
|
|
|
style.position = "";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2016-03-30 22:12:50 +03:00
|
|
|
if (this.width !== null) {
|
|
|
|
style.width = "";
|
|
|
|
}
|
|
|
|
if (this.height !== null) {
|
|
|
|
style.height = "";
|
|
|
|
}
|
|
|
|
var transformOriginProp = $.getCssPropertyWithVendorPrefix(
|
|
|
|
'transformOrigin');
|
|
|
|
var transformProp = $.getCssPropertyWithVendorPrefix(
|
|
|
|
'transform');
|
|
|
|
if (transformOriginProp && transformProp) {
|
|
|
|
style[transformOriginProp] = "";
|
|
|
|
style[transformProp] = "";
|
2011-12-14 02:38:36 +04:00
|
|
|
}
|
|
|
|
},
|
2016-04-01 20:31:36 +03:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Element} container
|
|
|
|
*/
|
2016-03-25 23:49:58 +03:00
|
|
|
drawHTML: function(container, viewport) {
|
|
|
|
var element = this.element;
|
|
|
|
if (element.parentNode !== container) {
|
2013-02-11 07:53:51 +04:00
|
|
|
//save the source parent for later if we need it
|
2016-03-25 23:49:58 +03:00
|
|
|
element.prevElementParent = element.parentNode;
|
|
|
|
element.prevNextSibling = element.nextSibling;
|
|
|
|
container.appendChild(element);
|
2016-03-31 22:45:44 +03:00
|
|
|
|
2017-02-01 07:06:14 +03:00
|
|
|
// have to set position before calculating size, fix #1116
|
|
|
|
this.style.position = "absolute";
|
2016-03-31 22:45:44 +03:00
|
|
|
// this.size is used by overlays which don't get scaled in at
|
|
|
|
// least one direction when this.checkResize is set to false.
|
2016-03-25 23:49:58 +03:00
|
|
|
this.size = $.getElementSize(element);
|
2011-12-14 02:38:36 +04:00
|
|
|
}
|
2016-03-30 22:12:50 +03:00
|
|
|
var positionAndSize = this._getOverlayPositionAndSize(viewport);
|
|
|
|
var position = positionAndSize.position;
|
2016-03-25 23:49:58 +03:00
|
|
|
var size = this.size = positionAndSize.size;
|
2024-07-12 00:08:37 +03:00
|
|
|
var outerScale = "";
|
2024-07-16 10:38:39 +03:00
|
|
|
if (viewport.overlayPreserveContentDirection) {
|
2024-07-12 00:08:37 +03:00
|
|
|
outerScale = viewport.flipped ? " scaleX(-1)" : " scaleX(1)";
|
2024-06-18 12:57:55 +03:00
|
|
|
}
|
2024-07-12 00:08:37 +03:00
|
|
|
var rotate = viewport.flipped ? -positionAndSize.rotate : positionAndSize.rotate;
|
|
|
|
var scale = viewport.flipped ? " scaleX(-1)" : "";
|
2014-03-20 23:39:31 +04:00
|
|
|
// call the onDraw callback if it exists to allow one to overwrite
|
2013-08-01 07:36:00 +04:00
|
|
|
// the drawing/positioning/sizing of the overlay
|
2016-03-25 23:49:58 +03:00
|
|
|
if (this.onDraw) {
|
|
|
|
this.onDraw(position, size, this.element);
|
2013-07-31 11:01:48 +04:00
|
|
|
} else {
|
2016-03-25 23:49:58 +03:00
|
|
|
var style = this.style;
|
2024-07-12 22:36:11 +03:00
|
|
|
var innerElement = element.firstChild;
|
|
|
|
var innerStyle = innerElement.style;
|
2016-03-25 23:49:58 +03:00
|
|
|
style.left = position.x + "px";
|
|
|
|
style.top = position.y + "px";
|
2016-03-30 22:12:50 +03:00
|
|
|
if (this.width !== null) {
|
|
|
|
style.width = size.x + "px";
|
|
|
|
}
|
|
|
|
if (this.height !== null) {
|
|
|
|
style.height = size.y + "px";
|
2015-06-24 01:08:18 +03:00
|
|
|
}
|
2016-03-30 18:16:29 +03:00
|
|
|
var transformOriginProp = $.getCssPropertyWithVendorPrefix(
|
|
|
|
'transformOrigin');
|
|
|
|
var transformProp = $.getCssPropertyWithVendorPrefix(
|
|
|
|
'transform');
|
|
|
|
if (transformOriginProp && transformProp) {
|
2024-07-09 12:37:51 +03:00
|
|
|
if (rotate && !viewport.flipped) {
|
2024-07-12 22:36:11 +03:00
|
|
|
innerStyle[transformProp] = "";
|
2016-03-30 18:16:29 +03:00
|
|
|
style[transformOriginProp] = this._getTransformOrigin();
|
2024-07-09 12:37:51 +03:00
|
|
|
style[transformProp] = "rotate(" + rotate + "deg)";
|
2024-06-18 12:57:55 +03:00
|
|
|
} else if (!rotate && viewport.flipped) {
|
2024-07-12 22:36:11 +03:00
|
|
|
innerStyle[transformProp] = outerScale;
|
2024-06-18 12:57:55 +03:00
|
|
|
style[transformOriginProp] = this._getTransformOrigin();
|
2024-07-09 12:37:51 +03:00
|
|
|
style[transformProp] = scale;
|
|
|
|
} else if (rotate && viewport.flipped){
|
2024-07-12 22:36:11 +03:00
|
|
|
innerStyle[transformProp] = outerScale;
|
2024-07-09 12:37:51 +03:00
|
|
|
style[transformOriginProp] = this._getTransformOrigin();
|
|
|
|
style[transformProp] = "rotate(" + rotate + "deg)" + scale;
|
2016-03-30 18:16:29 +03:00
|
|
|
} else {
|
2024-07-12 22:36:11 +03:00
|
|
|
innerStyle[transformProp] = "";
|
2016-03-30 18:16:29 +03:00
|
|
|
style[transformOriginProp] = "";
|
|
|
|
style[transformProp] = "";
|
|
|
|
}
|
2016-03-29 00:06:59 +03:00
|
|
|
}
|
2020-07-29 12:02:25 +03:00
|
|
|
style.display = 'block';
|
2013-07-16 06:04:37 +04:00
|
|
|
}
|
2011-12-14 02:38:36 +04:00
|
|
|
},
|
2016-04-01 20:31:36 +03:00
|
|
|
|
2016-03-25 23:49:58 +03:00
|
|
|
// private
|
2016-03-30 22:12:50 +03:00
|
|
|
_getOverlayPositionAndSize: function(viewport) {
|
|
|
|
var position = viewport.pixelFromPoint(this.location, true);
|
2016-03-31 23:59:26 +03:00
|
|
|
var size = this._getSizeInPixels(viewport);
|
2016-03-31 23:53:19 +03:00
|
|
|
this.adjust(position, size);
|
|
|
|
|
|
|
|
var rotate = 0;
|
2022-03-29 17:50:18 +03:00
|
|
|
if (viewport.getRotation(true) &&
|
2016-03-31 23:53:19 +03:00
|
|
|
this.rotationMode !== $.OverlayRotationMode.NO_ROTATION) {
|
|
|
|
// BOUNDING_BOX is only valid if both directions get scaled.
|
|
|
|
// Get replaced by EXACT otherwise.
|
|
|
|
if (this.rotationMode === $.OverlayRotationMode.BOUNDING_BOX &&
|
|
|
|
this.width !== null && this.height !== null) {
|
|
|
|
var rect = new $.Rect(position.x, position.y, size.x, size.y);
|
2022-03-29 17:50:18 +03:00
|
|
|
var boundingBox = this._getBoundingBox(rect, viewport.getRotation(true));
|
2016-03-31 23:53:19 +03:00
|
|
|
position = boundingBox.getTopLeft();
|
|
|
|
size = boundingBox.getSize();
|
|
|
|
} else {
|
2022-03-29 17:50:18 +03:00
|
|
|
rotate = viewport.getRotation(true);
|
2016-03-31 23:53:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-18 12:57:55 +03:00
|
|
|
if (viewport.flipped) {
|
|
|
|
position.x = (viewport.getContainerSize().x - position.x);
|
|
|
|
}
|
2016-03-31 23:53:19 +03:00
|
|
|
return {
|
|
|
|
position: position,
|
|
|
|
size: size,
|
|
|
|
rotate: rotate
|
|
|
|
};
|
|
|
|
},
|
2016-04-01 20:31:36 +03:00
|
|
|
|
2016-03-31 23:53:19 +03:00
|
|
|
// private
|
2016-03-31 23:59:26 +03:00
|
|
|
_getSizeInPixels: function(viewport) {
|
2016-03-30 22:12:50 +03:00
|
|
|
var width = this.size.x;
|
|
|
|
var height = this.size.y;
|
|
|
|
if (this.width !== null || this.height !== null) {
|
|
|
|
var scaledSize = viewport.deltaPixelsFromPointsNoRotate(
|
|
|
|
new $.Point(this.width || 0, this.height || 0), true);
|
|
|
|
if (this.width !== null) {
|
|
|
|
width = scaledSize.x;
|
|
|
|
}
|
|
|
|
if (this.height !== null) {
|
|
|
|
height = scaledSize.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.checkResize &&
|
|
|
|
(this.width === null || this.height === null)) {
|
|
|
|
var eltSize = this.size = $.getElementSize(this.element);
|
|
|
|
if (this.width === null) {
|
|
|
|
width = eltSize.x;
|
|
|
|
}
|
|
|
|
if (this.height === null) {
|
|
|
|
height = eltSize.y;
|
|
|
|
}
|
|
|
|
}
|
2016-03-31 23:53:19 +03:00
|
|
|
return new $.Point(width, height);
|
|
|
|
},
|
2016-04-01 20:31:36 +03:00
|
|
|
|
2016-03-31 23:53:19 +03:00
|
|
|
// private
|
|
|
|
_getBoundingBox: function(rect, degrees) {
|
2016-04-01 20:29:09 +03:00
|
|
|
var refPoint = this._getPlacementPoint(rect);
|
|
|
|
return rect.rotate(degrees, refPoint).getBoundingBox();
|
|
|
|
},
|
2016-04-01 20:31:36 +03:00
|
|
|
|
2016-04-01 20:29:09 +03:00
|
|
|
// private
|
|
|
|
_getPlacementPoint: function(rect) {
|
|
|
|
var result = new $.Point(rect.x, rect.y);
|
2016-03-31 23:53:19 +03:00
|
|
|
var properties = $.Placement.properties[this.placement];
|
|
|
|
if (properties) {
|
|
|
|
if (properties.isHorizontallyCentered) {
|
2016-04-01 20:29:09 +03:00
|
|
|
result.x += rect.width / 2;
|
2016-03-31 23:53:19 +03:00
|
|
|
} else if (properties.isRight) {
|
2016-04-01 20:29:09 +03:00
|
|
|
result.x += rect.width;
|
2016-03-31 23:53:19 +03:00
|
|
|
}
|
|
|
|
if (properties.isVerticallyCentered) {
|
2016-04-01 20:29:09 +03:00
|
|
|
result.y += rect.height / 2;
|
2016-03-31 23:53:19 +03:00
|
|
|
} else if (properties.isBottom) {
|
2016-04-01 20:29:09 +03:00
|
|
|
result.y += rect.height;
|
2016-03-31 23:53:19 +03:00
|
|
|
}
|
2016-03-29 00:06:59 +03:00
|
|
|
}
|
2016-04-01 20:29:09 +03:00
|
|
|
return result;
|
2016-03-25 23:49:58 +03:00
|
|
|
},
|
2016-04-01 20:31:36 +03:00
|
|
|
|
2016-03-29 00:06:59 +03:00
|
|
|
// private
|
|
|
|
_getTransformOrigin: function() {
|
|
|
|
var result = "";
|
|
|
|
var properties = $.Placement.properties[this.placement];
|
|
|
|
if (!properties) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (properties.isLeft) {
|
|
|
|
result = "left";
|
|
|
|
} else if (properties.isRight) {
|
|
|
|
result = "right";
|
|
|
|
}
|
|
|
|
if (properties.isTop) {
|
|
|
|
result += " top";
|
|
|
|
} else if (properties.isBottom) {
|
|
|
|
result += " bottom";
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
2016-04-01 20:31:36 +03:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
2016-03-30 22:12:50 +03:00
|
|
|
* Changes the overlay settings.
|
2012-02-15 23:50:27 +04:00
|
|
|
* @function
|
2016-03-30 22:12:50 +03:00
|
|
|
* @param {OpenSeadragon.Point|OpenSeadragon.Rect|Object} location
|
|
|
|
* If an object is specified, the options are the same than the constructor
|
|
|
|
* except for the element which can not be changed.
|
2017-01-06 06:30:09 +03:00
|
|
|
* @param {OpenSeadragon.Placement} placement
|
2012-02-15 23:50:27 +04:00
|
|
|
*/
|
2016-03-25 23:49:58 +03:00
|
|
|
update: function(location, placement) {
|
2016-03-30 22:12:50 +03:00
|
|
|
var options = $.isPlainObject(location) ? location : {
|
|
|
|
location: location,
|
|
|
|
placement: placement
|
|
|
|
};
|
|
|
|
this._init({
|
|
|
|
location: options.location || this.location,
|
|
|
|
placement: options.placement !== undefined ?
|
|
|
|
options.placement : this.placement,
|
|
|
|
onDraw: options.onDraw || this.onDraw,
|
|
|
|
checkResize: options.checkResize || this.checkResize,
|
|
|
|
width: options.width !== undefined ? options.width : this.width,
|
|
|
|
height: options.height !== undefined ? options.height : this.height,
|
|
|
|
rotationMode: options.rotationMode || this.rotationMode
|
|
|
|
});
|
2016-02-18 01:43:53 +03:00
|
|
|
},
|
2016-04-01 20:31:36 +03:00
|
|
|
|
2016-02-18 01:43:53 +03:00
|
|
|
/**
|
2016-03-30 22:12:50 +03:00
|
|
|
* Returns the current bounds of the overlay in viewport coordinates
|
2016-02-18 01:43:53 +03:00
|
|
|
* @function
|
2016-04-06 16:10:51 +03:00
|
|
|
* @param {OpenSeadragon.Viewport} viewport the viewport
|
2016-02-18 01:43:53 +03:00
|
|
|
* @returns {OpenSeadragon.Rect} overlay bounds
|
|
|
|
*/
|
2016-03-30 22:12:50 +03:00
|
|
|
getBounds: function(viewport) {
|
2016-04-06 19:55:50 +03:00
|
|
|
$.console.assert(viewport,
|
|
|
|
'A viewport must now be passed to Overlay.getBounds.');
|
2016-03-30 22:12:50 +03:00
|
|
|
var width = this.width;
|
|
|
|
var height = this.height;
|
|
|
|
if (width === null || height === null) {
|
2016-03-31 20:25:59 +03:00
|
|
|
var size = viewport.deltaPointsFromPixelsNoRotate(this.size, true);
|
2016-03-30 22:12:50 +03:00
|
|
|
if (width === null) {
|
|
|
|
width = size.x;
|
|
|
|
}
|
|
|
|
if (height === null) {
|
|
|
|
height = size.y;
|
|
|
|
}
|
|
|
|
}
|
2016-03-31 20:25:59 +03:00
|
|
|
var location = this.location.clone();
|
|
|
|
this.adjust(location, new $.Point(width, height));
|
2016-04-01 20:29:09 +03:00
|
|
|
return this._adjustBoundsForRotation(
|
|
|
|
viewport, new $.Rect(location.x, location.y, width, height));
|
|
|
|
},
|
|
|
|
|
2016-04-06 19:55:50 +03:00
|
|
|
// private
|
2016-04-01 20:29:09 +03:00
|
|
|
_adjustBoundsForRotation: function(viewport, bounds) {
|
|
|
|
if (!viewport ||
|
2022-03-29 17:50:18 +03:00
|
|
|
viewport.getRotation(true) === 0 ||
|
2016-04-01 20:29:09 +03:00
|
|
|
this.rotationMode === $.OverlayRotationMode.EXACT) {
|
|
|
|
return bounds;
|
|
|
|
}
|
2016-04-01 22:46:43 +03:00
|
|
|
if (this.rotationMode === $.OverlayRotationMode.BOUNDING_BOX) {
|
|
|
|
// If overlay not fully scalable, BOUNDING_BOX falls back to EXACT
|
|
|
|
if (this.width === null || this.height === null) {
|
|
|
|
return bounds;
|
|
|
|
}
|
|
|
|
// It is easier to just compute the position and size and
|
|
|
|
// convert to viewport coordinates.
|
|
|
|
var positionAndSize = this._getOverlayPositionAndSize(viewport);
|
|
|
|
return viewport.viewerElementToViewportRectangle(new $.Rect(
|
|
|
|
positionAndSize.position.x,
|
|
|
|
positionAndSize.position.y,
|
|
|
|
positionAndSize.size.x,
|
|
|
|
positionAndSize.size.y));
|
2016-04-01 20:29:09 +03:00
|
|
|
}
|
2016-04-01 22:46:43 +03:00
|
|
|
|
|
|
|
// NO_ROTATION case
|
2022-03-29 17:50:18 +03:00
|
|
|
return bounds.rotate(-viewport.getRotation(true),
|
2016-04-01 20:29:09 +03:00
|
|
|
this._getPlacementPoint(bounds));
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2011-12-14 02:38:36 +04:00
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2016-03-25 23:49:58 +03:00
|
|
|
}(OpenSeadragon));
|