From e02209092c099f6cacc00bd997675e99d9597b8c Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Tue, 23 Sep 2014 16:15:03 -0700 Subject: [PATCH] Navigator now works with multiple images --- src/navigator.js | 18 +++++++++++------- src/viewer.js | 15 +++++++++++---- test/demo/collections/main.js | 11 ++++++++++- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/navigator.js b/src/navigator.js index 9e18d6ca..9d0ec8d7 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -83,7 +83,7 @@ $.Navigator = function( options ){ options.controlOptions.width = options.width; } } - + } else { this.element = document.getElementById( options.id ); options.controlOptions = { @@ -216,21 +216,25 @@ $.Navigator = function( options ){ unneededElement.parentNode.removeChild(unneededElement); } - if (options.navigatorRotate) - { + if (options.navigatorRotate) { options.viewer.addHandler("rotate", function (args) { _setTransformRotate(_this.displayRegionContainer, args.degrees); _setTransformRotate(_this.displayRegion, -args.degrees); _this.viewport.setRotation(args.degrees); }); - } + + this.addHandler("reset-size", function() { + if (_this.viewport) { + _this.viewport.goHome(true); + } + }); }; $.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, /** @lends OpenSeadragon.Navigator.prototype */{ /** - * Used to notify the navigator when its size has changed. + * Used to notify the navigator when its size has changed. * Especially useful when {@link OpenSeadragon.Options}.navigatorAutoResize is set to false and the navigator is resizable. * @function */ @@ -313,7 +317,7 @@ $.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, /* }, - open: function( source ) { + open: function(source, options) { this.updateSize(); var containerSize = this.viewer.viewport.containerSize.times( this.sizeRatio ); var ts = source.getTileSize(source.maxLevel); @@ -322,7 +326,7 @@ $.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, /* } else { this.minPixelRatio = this.viewer.minPixelRatio; } - return $.Viewer.prototype.open.apply( this, [ source ] ); + return $.Viewer.prototype.open.apply( this, [source, options] ); } }); diff --git a/src/viewer.js b/src/viewer.js index 388d6b1e..589c7582 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1112,6 +1112,14 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, _this.world.addItem( tiledImage, { index: options.index }); + + if (_this.navigator) { + var optionsClone = $.extend({}, options, { + tileSource: tileSource + }); + + _this.navigator.addTiledImage(optionsClone); + } }, function( event ) { event.options = options; raiseAddItemFailed(event); @@ -1956,9 +1964,7 @@ function openTileSource( viewer, source, options ) { if ( _this.showNavigator && !_this.collectionMode ){ // Note: By passing the fully parsed source, the navigator doesn't // have to load it again. - if ( _this.navigator ) { - _this.navigator.open( source ); - } else { + if (!_this.navigator) { _this.navigator = new $.Navigator({ id: _this.navigatorId, position: _this.navigatorPosition, @@ -1969,13 +1975,14 @@ function openTileSource( viewer, source, options ) { width: _this.navigatorWidth, height: _this.navigatorHeight, autoResize: _this.navigatorAutoResize, - tileSources: source, tileHost: _this.tileHost, prefixUrl: _this.prefixUrl, viewer: _this, navigatorRotate: _this.navigatorRotate }); } + + _this.navigator.open(source, options); } //Instantiate a referencestrip if configured diff --git a/test/demo/collections/main.js b/test/demo/collections/main.js index 9eeb757c..b1438450 100644 --- a/test/demo/collections/main.js +++ b/test/demo/collections/main.js @@ -9,7 +9,7 @@ this.viewer = OpenSeadragon( { debugMode: true, zoomPerScroll: 1.02, - // showNavigator: true, + showNavigator: true, id: "contentDiv", prefixUrl: "../../../build/openseadragon/images/" } ); @@ -87,6 +87,15 @@ y: 0, width: 1 }); + }, + + // ---------- + bigTest: function() { + this.viewer.open("../../data/testpattern.dzi", { + x: -2, + y: -2, + width: 6 + }); } };