Navigator following host viewer's world events

This commit is contained in:
Ian Gilman 2014-09-24 13:58:09 -07:00
parent e02209092c
commit a08e361512
3 changed files with 69 additions and 25 deletions

View File

@ -229,6 +229,21 @@ $.Navigator = function( options ){
_this.viewport.goHome(true); _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 */{ $.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, /** @lends OpenSeadragon.Navigator.prototype */{

View File

@ -409,6 +409,26 @@ $.Viewer = function( options ) {
this.bindStandardControls(); this.bindStandardControls();
this.bindSequenceControls(); 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 ) { if ( initialTileSource ) {
this.open( initialTileSource ); this.open( initialTileSource );
@ -544,7 +564,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
this.source = null; this.source = null;
this.drawer = null; this.drawer = null;
this.world = null;
this.world.removeAll();
this.viewport = this.preserveViewport ? this.viewport : null; this.viewport = this.preserveViewport ? this.viewport : null;
@ -1896,20 +1917,6 @@ function openTileSource( viewer, source, options ) {
maxImageCacheCount: _this.maxImageCacheCount 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({ _this.drawer = new $.Drawer({
viewer: _this, viewer: _this,
viewport: _this.viewport, viewport: _this.viewport,

View File

@ -175,17 +175,22 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
this._items.splice( index, 1 ); this._items.splice( index, 1 );
this._figureSizes(); this._figureSizes();
this._raiseRemoveItem(item);
},
/** /**
* Raised when a item is removed. * Remove all items.
* @event remove-item * @function
* @memberOf OpenSeadragon.World * @fires OpenSeadragon.World.event:remove-item
* @type {object} */
* @property {OpenSeadragon.World} eventSource - A reference to the World which raised the event. removeAll: function() {
* @property {OpenSeadragon.TiledImage} item - The item's underlying item. var removedItems = this._items;
* @property {?Object} userData - Arbitrary subscriber-defined object. this._items = [];
*/ this._figureSizes();
this.raiseEvent( 'remove-item', { item: item } );
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._homeBounds = new $.Rect( left, top, right - left, bottom - top );
this._contentSize = new $.Point(this._homeBounds.width * this._contentFactor, this._contentSize = new $.Point(this._homeBounds.width * this._contentFactor,
this._homeBounds.height * 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 } );
} }
}); });