2014-08-07 00:48:18 +04:00
|
|
|
/*
|
|
|
|
* OpenSeadragon - World
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 CodePlex Foundation
|
|
|
|
* Copyright (C) 2010-2013 OpenSeadragon contributors
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class World
|
2014-08-20 02:02:04 +04:00
|
|
|
* @memberof OpenSeadragon
|
|
|
|
* @extends OpenSeadragon.EventSource
|
2014-11-04 22:53:39 +03:00
|
|
|
* @classdesc Keeps track of all of the tiled images in the scene.
|
|
|
|
* @param {Object} options - World options.
|
|
|
|
* @param {OpenSeadragon.Viewer} options.viewer - The Viewer that owns this World.
|
2014-08-20 02:02:04 +04:00
|
|
|
**/
|
2014-08-07 00:48:18 +04:00
|
|
|
$.World = function( options ) {
|
2014-11-13 03:44:11 +03:00
|
|
|
var _this = this;
|
|
|
|
|
2014-08-07 00:48:18 +04:00
|
|
|
$.console.assert( options.viewer, "[World] options.viewer is required" );
|
|
|
|
|
2014-08-20 02:02:04 +04:00
|
|
|
$.EventSource.call( this );
|
|
|
|
|
2014-08-07 00:48:18 +04:00
|
|
|
this.viewer = options.viewer;
|
|
|
|
this._items = [];
|
2014-12-02 22:44:02 +03:00
|
|
|
this._needsDraw = false;
|
2015-08-20 19:25:57 +03:00
|
|
|
this._autoRefigureSizes = true;
|
2015-09-12 00:35:36 +03:00
|
|
|
this._needsSizesFigured = false;
|
2014-11-13 03:44:11 +03:00
|
|
|
this._delegatedFigureSizes = function(event) {
|
2015-09-01 19:48:41 +03:00
|
|
|
if (_this._autoRefigureSizes) {
|
2015-08-20 19:25:57 +03:00
|
|
|
_this._figureSizes();
|
2015-09-12 00:35:36 +03:00
|
|
|
} else {
|
|
|
|
_this._needsSizesFigured = true;
|
2015-08-20 19:25:57 +03:00
|
|
|
}
|
2014-11-13 03:44:11 +03:00
|
|
|
};
|
|
|
|
|
2014-08-19 03:04:49 +04:00
|
|
|
this._figureSizes();
|
2014-08-07 00:48:18 +04:00
|
|
|
};
|
|
|
|
|
2014-08-20 02:02:04 +04:00
|
|
|
$.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.World.prototype */{
|
|
|
|
/**
|
|
|
|
* Add the specified item.
|
|
|
|
* @param {OpenSeadragon.TiledImage} item - The item to add.
|
2014-11-04 22:53:39 +03:00
|
|
|
* @param {Number} [options.index] - Index for the item. If not specified, goes at the top.
|
2014-08-20 02:02:04 +04:00
|
|
|
* @fires OpenSeadragon.World.event:add-item
|
2014-11-15 02:49:42 +03:00
|
|
|
* @fires OpenSeadragon.World.event:metrics-change
|
2014-08-20 02:02:04 +04:00
|
|
|
*/
|
|
|
|
addItem: function( item, options ) {
|
|
|
|
$.console.assert(item, "[World.addItem] item is required");
|
|
|
|
$.console.assert(item instanceof $.TiledImage, "[World.addItem] only TiledImages supported at this time");
|
|
|
|
|
|
|
|
options = options || {};
|
|
|
|
if (options.index !== undefined) {
|
|
|
|
var index = Math.max(0, Math.min(this._items.length, options.index));
|
|
|
|
this._items.splice(index, 0, item);
|
|
|
|
} else {
|
|
|
|
this._items.push( item );
|
|
|
|
}
|
|
|
|
|
2015-09-25 18:57:35 +03:00
|
|
|
if (this._autoRefigureSizes) {
|
|
|
|
this._figureSizes();
|
|
|
|
} else {
|
|
|
|
this._needsSizesFigured = true;
|
|
|
|
}
|
|
|
|
|
2014-12-02 22:44:02 +03:00
|
|
|
this._needsDraw = true;
|
2014-08-20 02:02:04 +04:00
|
|
|
|
2014-11-13 03:44:11 +03:00
|
|
|
item.addHandler('bounds-change', this._delegatedFigureSizes);
|
2016-08-28 15:39:14 +03:00
|
|
|
item.addHandler('clip-change', this._delegatedFigureSizes);
|
2014-11-12 04:14:48 +03:00
|
|
|
|
2014-08-20 02:02:04 +04:00
|
|
|
/**
|
|
|
|
* Raised when an item is added to the World.
|
|
|
|
* @event add-item
|
|
|
|
* @memberOf OpenSeadragon.World
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Viewer} eventSource - A reference to the World which raised the event.
|
2014-11-04 22:53:39 +03:00
|
|
|
* @property {OpenSeadragon.TiledImage} item - The item that has been added.
|
2014-08-20 02:02:04 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
|
|
|
*/
|
|
|
|
this.raiseEvent( 'add-item', {
|
|
|
|
item: item
|
|
|
|
} );
|
2014-08-07 00:48:18 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-08-20 02:02:04 +04:00
|
|
|
* Get the item at the specified index.
|
|
|
|
* @param {Number} index - The item's index.
|
|
|
|
* @returns {OpenSeadragon.TiledImage} The item at the specified index.
|
2014-08-07 00:48:18 +04:00
|
|
|
*/
|
2014-08-20 02:02:04 +04:00
|
|
|
getItemAt: function( index ) {
|
2014-12-19 02:21:48 +03:00
|
|
|
$.console.assert(index !== undefined, "[World.getItemAt] index is required");
|
2014-08-20 02:02:04 +04:00
|
|
|
return this._items[ index ];
|
2014-08-07 00:48:18 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-08-20 02:02:04 +04:00
|
|
|
* Get the index of the given item or -1 if not present.
|
|
|
|
* @param {OpenSeadragon.TiledImage} item - The item.
|
|
|
|
* @returns {Number} The index of the item or -1 if not present.
|
2014-08-07 00:48:18 +04:00
|
|
|
*/
|
2014-08-20 02:02:04 +04:00
|
|
|
getIndexOfItem: function( item ) {
|
|
|
|
$.console.assert(item, "[World.getIndexOfItem] item is required");
|
2014-08-07 00:48:18 +04:00
|
|
|
return $.indexOf( this._items, item );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {Number} The number of items used.
|
|
|
|
*/
|
|
|
|
getItemCount: function() {
|
|
|
|
return this._items.length;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-08-20 02:02:04 +04:00
|
|
|
* Change the index of a item so that it appears over or under others.
|
|
|
|
* @param {OpenSeadragon.TiledImage} item - The item to move.
|
|
|
|
* @param {Number} index - The new index.
|
2014-11-13 03:31:46 +03:00
|
|
|
* @fires OpenSeadragon.World.event:item-index-change
|
2014-08-07 00:48:18 +04:00
|
|
|
*/
|
2014-08-20 02:02:04 +04:00
|
|
|
setItemIndex: function( item, index ) {
|
|
|
|
$.console.assert(item, "[World.setItemIndex] item is required");
|
2014-12-19 02:21:48 +03:00
|
|
|
$.console.assert(index !== undefined, "[World.setItemIndex] index is required");
|
2014-08-07 00:48:18 +04:00
|
|
|
|
2014-08-20 02:02:04 +04:00
|
|
|
var oldIndex = this.getIndexOfItem( item );
|
|
|
|
|
|
|
|
if ( index >= this._items.length ) {
|
|
|
|
throw new Error( "Index bigger than number of layers." );
|
2014-08-07 00:48:18 +04:00
|
|
|
}
|
2014-08-20 02:02:04 +04:00
|
|
|
|
|
|
|
if ( index === oldIndex || oldIndex === -1 ) {
|
2014-08-07 00:48:18 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-08-20 02:02:04 +04:00
|
|
|
|
|
|
|
this._items.splice( oldIndex, 1 );
|
|
|
|
this._items.splice( index, 0, item );
|
2014-12-02 22:44:02 +03:00
|
|
|
this._needsDraw = true;
|
2014-08-07 00:48:18 +04:00
|
|
|
|
|
|
|
/**
|
2014-08-20 02:02:04 +04:00
|
|
|
* Raised when the order of the indexes has been changed.
|
2014-11-13 03:31:46 +03:00
|
|
|
* @event item-index-change
|
2014-08-20 02:02:04 +04:00
|
|
|
* @memberOf OpenSeadragon.World
|
2014-08-07 00:48:18 +04:00
|
|
|
* @type {object}
|
2014-08-20 02:02:04 +04:00
|
|
|
* @property {OpenSeadragon.World} eventSource - A reference to the World which raised the event.
|
|
|
|
* @property {OpenSeadragon.TiledImage} item - The item whose index has
|
2014-08-07 00:48:18 +04:00
|
|
|
* been changed
|
2014-08-20 02:02:04 +04:00
|
|
|
* @property {Number} previousIndex - The previous index of the item
|
|
|
|
* @property {Number} newIndex - The new index of the item
|
2014-08-07 00:48:18 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
|
|
|
*/
|
2014-11-13 03:31:46 +03:00
|
|
|
this.raiseEvent( 'item-index-change', {
|
2014-08-20 02:02:04 +04:00
|
|
|
item: item,
|
|
|
|
previousIndex: oldIndex,
|
|
|
|
newIndex: index
|
2014-08-07 00:48:18 +04:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-08-20 02:02:04 +04:00
|
|
|
* Remove an item.
|
|
|
|
* @param {OpenSeadragon.TiledImage} item - The item to remove.
|
|
|
|
* @fires OpenSeadragon.World.event:remove-item
|
2014-11-15 02:49:42 +03:00
|
|
|
* @fires OpenSeadragon.World.event:metrics-change
|
2014-08-07 00:48:18 +04:00
|
|
|
*/
|
|
|
|
removeItem: function( item ) {
|
2014-08-20 02:02:04 +04:00
|
|
|
$.console.assert(item, "[World.removeItem] item is required");
|
|
|
|
|
2014-12-04 23:00:04 +03:00
|
|
|
var index = $.indexOf(this._items, item );
|
2014-08-07 00:48:18 +04:00
|
|
|
if ( index === -1 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-13 03:44:11 +03:00
|
|
|
item.removeHandler('bounds-change', this._delegatedFigureSizes);
|
2016-08-28 15:39:14 +03:00
|
|
|
item.removeHandler('clip-change', this._delegatedFigureSizes);
|
2015-02-20 23:12:34 +03:00
|
|
|
item.destroy();
|
2014-08-07 00:48:18 +04:00
|
|
|
this._items.splice( index, 1 );
|
2014-08-19 03:04:49 +04:00
|
|
|
this._figureSizes();
|
2014-12-02 22:44:02 +03:00
|
|
|
this._needsDraw = true;
|
2014-09-25 00:58:09 +04:00
|
|
|
this._raiseRemoveItem(item);
|
|
|
|
},
|
2014-08-19 03:04:49 +04:00
|
|
|
|
2014-09-25 00:58:09 +04:00
|
|
|
/**
|
|
|
|
* Remove all items.
|
|
|
|
* @fires OpenSeadragon.World.event:remove-item
|
2014-11-15 02:49:42 +03:00
|
|
|
* @fires OpenSeadragon.World.event:metrics-change
|
2014-09-25 00:58:09 +04:00
|
|
|
*/
|
|
|
|
removeAll: function() {
|
2015-09-24 00:19:02 +03:00
|
|
|
// We need to make sure any pending images are canceled so the world items don't get messed up
|
|
|
|
this.viewer._cancelPendingImages();
|
2014-11-13 03:44:11 +03:00
|
|
|
var item;
|
2017-01-08 17:52:57 +03:00
|
|
|
var i;
|
|
|
|
for (i = 0; i < this._items.length; i++) {
|
2014-11-13 03:44:11 +03:00
|
|
|
item = this._items[i];
|
|
|
|
item.removeHandler('bounds-change', this._delegatedFigureSizes);
|
2016-08-28 15:39:14 +03:00
|
|
|
item.removeHandler('clip-change', this._delegatedFigureSizes);
|
2015-02-20 23:12:34 +03:00
|
|
|
item.destroy();
|
2014-11-13 03:44:11 +03:00
|
|
|
}
|
|
|
|
|
2014-09-25 00:58:09 +04:00
|
|
|
var removedItems = this._items;
|
|
|
|
this._items = [];
|
|
|
|
this._figureSizes();
|
2014-12-02 22:44:02 +03:00
|
|
|
this._needsDraw = true;
|
2014-09-25 00:58:09 +04:00
|
|
|
|
2014-11-13 03:44:11 +03:00
|
|
|
for (i = 0; i < removedItems.length; i++) {
|
|
|
|
item = removedItems[i];
|
|
|
|
this._raiseRemoveItem(item);
|
2014-09-25 00:58:09 +04:00
|
|
|
}
|
2014-08-07 00:48:18 +04:00
|
|
|
},
|
|
|
|
|
2014-08-20 02:02:04 +04:00
|
|
|
/**
|
|
|
|
* Clears all tiles and triggers updates for all items.
|
|
|
|
*/
|
|
|
|
resetItems: function() {
|
2014-08-13 03:04:55 +04:00
|
|
|
for ( var i = 0; i < this._items.length; i++ ) {
|
2014-08-12 04:04:20 +04:00
|
|
|
this._items[i].reset();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-08-20 02:02:04 +04:00
|
|
|
/**
|
2014-12-02 22:44:02 +03:00
|
|
|
* Updates (i.e. animates bounds of) all items.
|
2014-08-20 02:02:04 +04:00
|
|
|
*/
|
2014-08-07 00:48:18 +04:00
|
|
|
update: function() {
|
2014-12-02 22:44:02 +03:00
|
|
|
var animated = false;
|
2014-08-13 03:04:55 +04:00
|
|
|
for ( var i = 0; i < this._items.length; i++ ) {
|
2014-12-02 22:44:02 +03:00
|
|
|
animated = this._items[i].update() || animated;
|
2014-08-07 00:48:18 +04:00
|
|
|
}
|
2014-10-25 02:18:32 +04:00
|
|
|
|
2014-12-02 22:44:02 +03:00
|
|
|
return animated;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws all items.
|
|
|
|
*/
|
|
|
|
draw: function() {
|
|
|
|
for ( var i = 0; i < this._items.length; i++ ) {
|
|
|
|
this._items[i].draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
this._needsDraw = false;
|
2014-08-07 00:48:18 +04:00
|
|
|
},
|
|
|
|
|
2014-08-20 02:02:04 +04:00
|
|
|
/**
|
|
|
|
* @returns {Boolean} true if any items need updating.
|
|
|
|
*/
|
2014-12-02 22:44:02 +03:00
|
|
|
needsDraw: function() {
|
2014-08-13 03:04:55 +04:00
|
|
|
for ( var i = 0; i < this._items.length; i++ ) {
|
2014-12-02 22:44:02 +03:00
|
|
|
if ( this._items[i].needsDraw() ) {
|
2014-08-07 00:48:18 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-12-02 22:44:02 +03:00
|
|
|
return this._needsDraw;
|
2014-08-13 03:04:55 +04:00
|
|
|
},
|
|
|
|
|
2014-08-20 02:02:04 +04:00
|
|
|
/**
|
2014-11-24 22:59:06 +03:00
|
|
|
* @returns {OpenSeadragon.Rect} The smallest rectangle that encloses all items, in viewport coordinates.
|
2014-08-20 02:02:04 +04:00
|
|
|
*/
|
2014-08-13 03:04:55 +04:00
|
|
|
getHomeBounds: function() {
|
2014-08-19 03:04:49 +04:00
|
|
|
return this._homeBounds.clone();
|
|
|
|
},
|
|
|
|
|
2014-08-20 02:02:04 +04:00
|
|
|
/**
|
|
|
|
* To facilitate zoom constraints, we keep track of the pixel density of the
|
2014-11-24 22:59:06 +03:00
|
|
|
* densest item in the World (i.e. the item whose content size to viewport size
|
2014-08-20 02:02:04 +04:00
|
|
|
* ratio is the highest) and save it as this "content factor".
|
2014-11-24 22:59:06 +03:00
|
|
|
* @returns {Number} the number of content units per viewport unit.
|
2014-08-20 02:02:04 +04:00
|
|
|
*/
|
2014-08-19 03:04:49 +04:00
|
|
|
getContentFactor: function() {
|
|
|
|
return this._contentFactor;
|
|
|
|
},
|
|
|
|
|
2015-08-20 19:25:57 +03:00
|
|
|
/**
|
|
|
|
* As a performance optimization, setting this flag to false allows the bounds-change event handler
|
2015-09-15 01:14:32 +03:00
|
|
|
* on tiledImages to skip calculations on the world bounds. If a lot of images are going to be positioned in
|
|
|
|
* rapid succession, this is a good idea. When finished, setAutoRefigureSizes should be called with true
|
|
|
|
* or the system may behave oddly.
|
|
|
|
* @param {Boolean} [value] The value to which to set the flag.
|
2015-08-20 19:25:57 +03:00
|
|
|
*/
|
|
|
|
setAutoRefigureSizes: function(value) {
|
|
|
|
this._autoRefigureSizes = value;
|
2015-09-12 00:35:36 +03:00
|
|
|
if (value & this._needsSizesFigured) {
|
|
|
|
this._figureSizes();
|
|
|
|
this._needsSizesFigured = false;
|
|
|
|
}
|
2015-08-20 19:25:57 +03:00
|
|
|
},
|
|
|
|
|
2014-11-13 03:31:46 +03:00
|
|
|
/**
|
|
|
|
* Arranges all of the TiledImages with the specified settings.
|
|
|
|
* @param {Object} options - Specifies how to arrange.
|
2014-12-02 22:44:02 +03:00
|
|
|
* @param {Boolean} [options.immediately=false] - Whether to animate to the new arrangement.
|
2014-11-13 03:31:46 +03:00
|
|
|
* @param {String} [options.layout] - See collectionLayout in {@link OpenSeadragon.Options}.
|
|
|
|
* @param {Number} [options.rows] - See collectionRows in {@link OpenSeadragon.Options}.
|
2015-07-02 22:20:57 +03:00
|
|
|
* @param {Number} [options.columns] - See collectionColumns in {@link OpenSeadragon.Options}.
|
2014-11-13 03:31:46 +03:00
|
|
|
* @param {Number} [options.tileSize] - See collectionTileSize in {@link OpenSeadragon.Options}.
|
|
|
|
* @param {Number} [options.tileMargin] - See collectionTileMargin in {@link OpenSeadragon.Options}.
|
2014-11-15 02:49:42 +03:00
|
|
|
* @fires OpenSeadragon.World.event:metrics-change
|
2014-11-13 03:31:46 +03:00
|
|
|
*/
|
|
|
|
arrange: function(options) {
|
|
|
|
options = options || {};
|
2014-12-02 22:44:02 +03:00
|
|
|
var immediately = options.immediately || false;
|
2014-11-13 03:31:46 +03:00
|
|
|
var layout = options.layout || $.DEFAULT_SETTINGS.collectionLayout;
|
|
|
|
var rows = options.rows || $.DEFAULT_SETTINGS.collectionRows;
|
2015-07-02 22:20:57 +03:00
|
|
|
var columns = options.columns || $.DEFAULT_SETTINGS.collectionColumns;
|
2014-11-13 03:31:46 +03:00
|
|
|
var tileSize = options.tileSize || $.DEFAULT_SETTINGS.collectionTileSize;
|
|
|
|
var tileMargin = options.tileMargin || $.DEFAULT_SETTINGS.collectionTileMargin;
|
2014-11-13 02:48:38 +03:00
|
|
|
var increment = tileSize + tileMargin;
|
2015-07-02 22:20:57 +03:00
|
|
|
var wrap;
|
|
|
|
if (!options.rows && columns) {
|
|
|
|
wrap = columns;
|
|
|
|
} else {
|
|
|
|
wrap = Math.ceil(this._items.length / rows);
|
|
|
|
}
|
2014-11-12 04:14:48 +03:00
|
|
|
var x = 0;
|
|
|
|
var y = 0;
|
2014-11-13 02:48:38 +03:00
|
|
|
var item, box, width, height, position;
|
2015-08-20 19:25:57 +03:00
|
|
|
|
|
|
|
this.setAutoRefigureSizes(false);
|
2014-11-12 04:14:48 +03:00
|
|
|
for (var i = 0; i < this._items.length; i++) {
|
|
|
|
if (i && (i % wrap) === 0) {
|
|
|
|
if (layout === 'horizontal') {
|
2014-11-13 02:48:38 +03:00
|
|
|
y += increment;
|
2014-11-12 04:14:48 +03:00
|
|
|
x = 0;
|
|
|
|
} else {
|
2014-11-13 02:48:38 +03:00
|
|
|
x += increment;
|
2014-11-12 04:14:48 +03:00
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-13 02:48:38 +03:00
|
|
|
item = this._items[i];
|
2014-11-13 03:31:46 +03:00
|
|
|
box = item.getBounds();
|
2014-11-13 02:48:38 +03:00
|
|
|
if (box.width > box.height) {
|
|
|
|
width = tileSize;
|
|
|
|
} else {
|
|
|
|
width = tileSize * (box.width / box.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
height = width * (box.height / box.width);
|
|
|
|
position = new $.Point(x + ((tileSize - width) / 2),
|
|
|
|
y + ((tileSize - height) / 2));
|
|
|
|
|
2014-12-02 22:44:02 +03:00
|
|
|
item.setPosition(position, immediately);
|
|
|
|
item.setWidth(width, immediately);
|
2014-11-12 04:14:48 +03:00
|
|
|
|
|
|
|
if (layout === 'horizontal') {
|
2014-11-13 02:48:38 +03:00
|
|
|
x += increment;
|
2014-11-12 04:14:48 +03:00
|
|
|
} else {
|
2014-11-13 02:48:38 +03:00
|
|
|
y += increment;
|
2014-11-12 04:14:48 +03:00
|
|
|
}
|
|
|
|
}
|
2015-08-20 19:25:57 +03:00
|
|
|
this.setAutoRefigureSizes(true);
|
2014-11-12 04:14:48 +03:00
|
|
|
},
|
|
|
|
|
2014-11-04 22:53:39 +03:00
|
|
|
// private
|
2014-08-19 03:04:49 +04:00
|
|
|
_figureSizes: function() {
|
2014-11-12 04:14:48 +03:00
|
|
|
var oldHomeBounds = this._homeBounds ? this._homeBounds.clone() : null;
|
2014-11-15 02:49:42 +03:00
|
|
|
var oldContentSize = this._contentSize ? this._contentSize.clone() : null;
|
|
|
|
var oldContentFactor = this._contentFactor || 0;
|
2014-11-12 04:14:48 +03:00
|
|
|
|
2016-04-06 00:50:18 +03:00
|
|
|
if (!this._items.length) {
|
2014-08-19 03:04:49 +04:00
|
|
|
this._homeBounds = new $.Rect(0, 0, 1, 1);
|
|
|
|
this._contentSize = new $.Point(1, 1);
|
2014-11-18 03:24:40 +03:00
|
|
|
this._contentFactor = 1;
|
2014-11-12 04:14:48 +03:00
|
|
|
} else {
|
2016-04-06 00:50:18 +03:00
|
|
|
var item = this._items[0];
|
|
|
|
var bounds = item.getBounds();
|
|
|
|
this._contentFactor = item.getContentSize().x / bounds.width;
|
2016-08-28 13:10:35 +03:00
|
|
|
var clippedBounds = item.getClippedBounds().getBoundingBox();
|
2016-04-06 00:50:18 +03:00
|
|
|
var left = clippedBounds.x;
|
|
|
|
var top = clippedBounds.y;
|
|
|
|
var right = clippedBounds.x + clippedBounds.width;
|
|
|
|
var bottom = clippedBounds.y + clippedBounds.height;
|
|
|
|
for (var i = 1; i < this._items.length; i++) {
|
|
|
|
item = this._items[i];
|
|
|
|
bounds = item.getBounds();
|
|
|
|
this._contentFactor = Math.max(this._contentFactor,
|
|
|
|
item.getContentSize().x / bounds.width);
|
2016-08-28 13:10:35 +03:00
|
|
|
clippedBounds = item.getClippedBounds().getBoundingBox();
|
2016-04-06 00:50:18 +03:00
|
|
|
left = Math.min(left, clippedBounds.x);
|
|
|
|
top = Math.min(top, clippedBounds.y);
|
|
|
|
right = Math.max(right, clippedBounds.x + clippedBounds.width);
|
|
|
|
bottom = Math.max(bottom, clippedBounds.y + clippedBounds.height);
|
2014-11-12 04:14:48 +03:00
|
|
|
}
|
2014-08-13 03:04:55 +04:00
|
|
|
|
2016-04-06 00:50:18 +03:00
|
|
|
this._homeBounds = new $.Rect(left, top, right - left, bottom - top);
|
|
|
|
this._contentSize = new $.Point(
|
|
|
|
this._homeBounds.width * this._contentFactor,
|
2014-11-12 04:14:48 +03:00
|
|
|
this._homeBounds.height * this._contentFactor);
|
2014-08-13 03:04:55 +04:00
|
|
|
}
|
|
|
|
|
2016-04-06 00:50:18 +03:00
|
|
|
if (this._contentFactor !== oldContentFactor ||
|
|
|
|
!this._homeBounds.equals(oldHomeBounds) ||
|
|
|
|
!this._contentSize.equals(oldContentSize)) {
|
2014-11-12 04:14:48 +03:00
|
|
|
/**
|
2014-11-18 03:24:40 +03:00
|
|
|
* Raised when the home bounds or content factor change.
|
2014-11-15 02:49:42 +03:00
|
|
|
* @event metrics-change
|
2014-11-12 04:14:48 +03:00
|
|
|
* @memberOf OpenSeadragon.World
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.World} eventSource - A reference to the World which raised the event.
|
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
|
|
|
*/
|
2014-11-15 02:49:42 +03:00
|
|
|
this.raiseEvent('metrics-change', {});
|
2014-11-12 04:14:48 +03:00
|
|
|
}
|
2014-09-25 00:58:09 +04:00
|
|
|
},
|
|
|
|
|
2014-11-04 22:53:39 +03:00
|
|
|
// private
|
2014-09-25 00:58:09 +04:00
|
|
|
_raiseRemoveItem: function(item) {
|
|
|
|
/**
|
2014-11-12 04:14:48 +03:00
|
|
|
* Raised when an item is removed.
|
2014-09-25 00:58:09 +04:00
|
|
|
* @event remove-item
|
|
|
|
* @memberOf OpenSeadragon.World
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.World} eventSource - A reference to the World which raised the event.
|
|
|
|
* @property {OpenSeadragon.TiledImage} item - The item's underlying item.
|
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
|
|
|
*/
|
|
|
|
this.raiseEvent( 'remove-item', { item: item } );
|
2014-08-07 00:48:18 +04:00
|
|
|
}
|
2014-08-20 02:02:04 +04:00
|
|
|
});
|
2014-08-07 00:48:18 +04:00
|
|
|
|
|
|
|
}( OpenSeadragon ));
|