mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 14:46:10 +03:00
Navigator following host viewer's world events
This commit is contained in:
parent
e02209092c
commit
a08e361512
@ -229,6 +229,21 @@ $.Navigator = function( options ){
|
||||
_this.viewport.goHome(true);
|
||||
}
|
||||
});
|
||||
|
||||
this.addHandler("reset-size", function() {
|
||||
if (_this.viewport) {
|
||||
_this.viewport.goHome(true);
|
||||
}
|
||||
});
|
||||
|
||||
this.world.addHandler("item-index-changed", function(event) {
|
||||
var item = _this.world.getItemAt(event.previousIndex);
|
||||
_this.world.setItemIndex(item, event.newIndex);
|
||||
});
|
||||
|
||||
this.world.addHandler("remove-item", function(event) {
|
||||
// TODO
|
||||
});
|
||||
};
|
||||
|
||||
$.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, /** @lends OpenSeadragon.Navigator.prototype */{
|
||||
|
@ -409,6 +409,26 @@ $.Viewer = function( options ) {
|
||||
this.bindStandardControls();
|
||||
this.bindSequenceControls();
|
||||
|
||||
this.world = new $.World({
|
||||
viewer: this
|
||||
});
|
||||
|
||||
this.world.addHandler('add-item', function(event) {
|
||||
if (_this.viewport) {
|
||||
_this.viewport.setHomeBounds(_this.world.getHomeBounds(), _this.world.getContentFactor());
|
||||
}
|
||||
|
||||
THIS[ _this.hash ].forceRedraw = true;
|
||||
});
|
||||
|
||||
this.world.addHandler('remove-item', function(event) {
|
||||
if (_this.viewport) {
|
||||
_this.viewport.setHomeBounds(_this.world.getHomeBounds(), _this.world.getContentFactor());
|
||||
}
|
||||
|
||||
THIS[ _this.hash ].forceRedraw = true;
|
||||
});
|
||||
|
||||
if ( initialTileSource ) {
|
||||
this.open( initialTileSource );
|
||||
|
||||
@ -544,7 +564,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
||||
|
||||
this.source = null;
|
||||
this.drawer = null;
|
||||
this.world = null;
|
||||
|
||||
this.world.removeAll();
|
||||
|
||||
this.viewport = this.preserveViewport ? this.viewport : null;
|
||||
|
||||
@ -1896,20 +1917,6 @@ function openTileSource( viewer, source, options ) {
|
||||
maxImageCacheCount: _this.maxImageCacheCount
|
||||
});
|
||||
|
||||
_this.world = new $.World({
|
||||
viewer: _this
|
||||
});
|
||||
|
||||
_this.world.addHandler('add-item', function(event) {
|
||||
_this.viewport.setHomeBounds(_this.world.getHomeBounds(), _this.world.getContentFactor());
|
||||
THIS[ _this.hash ].forceRedraw = true;
|
||||
});
|
||||
|
||||
_this.world.addHandler('remove-item', function(event) {
|
||||
_this.viewport.setHomeBounds(_this.world.getHomeBounds(), _this.world.getContentFactor());
|
||||
THIS[ _this.hash ].forceRedraw = true;
|
||||
});
|
||||
|
||||
_this.drawer = new $.Drawer({
|
||||
viewer: _this,
|
||||
viewport: _this.viewport,
|
||||
|
42
src/world.js
42
src/world.js
@ -175,17 +175,22 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
|
||||
|
||||
this._items.splice( index, 1 );
|
||||
this._figureSizes();
|
||||
this._raiseRemoveItem(item);
|
||||
},
|
||||
|
||||
/**
|
||||
* Raised when a item is removed.
|
||||
* @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 } );
|
||||
/**
|
||||
* Remove all items.
|
||||
* @function
|
||||
* @fires OpenSeadragon.World.event:remove-item
|
||||
*/
|
||||
removeAll: function() {
|
||||
var removedItems = this._items;
|
||||
this._items = [];
|
||||
this._figureSizes();
|
||||
|
||||
for (var i = 0; i < removedItems.length; i++) {
|
||||
this._raiseRemoveItem(removedItems[i]);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@ -270,6 +275,23 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
|
||||
this._homeBounds = new $.Rect( left, top, right - left, bottom - top );
|
||||
this._contentSize = new $.Point(this._homeBounds.width * this._contentFactor,
|
||||
this._homeBounds.height * this._contentFactor);
|
||||
},
|
||||
|
||||
/**
|
||||
* @function
|
||||
* @private
|
||||
*/
|
||||
_raiseRemoveItem: function(item) {
|
||||
/**
|
||||
* Raised when a item is removed.
|
||||
* @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 } );
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user