mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-29 00:26:10 +03:00
Navigator now updates for item index changes and removals
This commit is contained in:
parent
a08e361512
commit
3e1870cde0
@ -236,13 +236,21 @@ $.Navigator = function( options ){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.world.addHandler("item-index-changed", function(event) {
|
viewer.world.addHandler("item-index-changed", function(event) {
|
||||||
var item = _this.world.getItemAt(event.previousIndex);
|
var item = _this.world.getItemAt(event.previousIndex);
|
||||||
_this.world.setItemIndex(item, event.newIndex);
|
_this.world.setItemIndex(item, event.newIndex);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.world.addHandler("remove-item", function(event) {
|
viewer.world.addHandler("remove-item", function(event) {
|
||||||
// TODO
|
var count = _this.world.getItemCount();
|
||||||
|
var item;
|
||||||
|
for (var i = 0; i < count; i++) {
|
||||||
|
item = _this.world.getItemAt(i);
|
||||||
|
if (item._originalForNavigator === event.item) {
|
||||||
|
_this.world.removeItem(item);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -332,7 +340,16 @@ $.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, /*
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overrides Viewer.open
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
open: function(source, options) {
|
open: function(source, options) {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
var original = options.originalTiledImage;
|
||||||
|
delete options.original;
|
||||||
|
|
||||||
this.updateSize();
|
this.updateSize();
|
||||||
var containerSize = this.viewer.viewport.containerSize.times( this.sizeRatio );
|
var containerSize = this.viewer.viewport.containerSize.times( this.sizeRatio );
|
||||||
var ts = source.getTileSize(source.maxLevel);
|
var ts = source.getTileSize(source.maxLevel);
|
||||||
@ -341,9 +358,31 @@ $.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, /*
|
|||||||
} else {
|
} else {
|
||||||
this.minPixelRatio = this.viewer.minPixelRatio;
|
this.minPixelRatio = this.viewer.minPixelRatio;
|
||||||
}
|
}
|
||||||
return $.Viewer.prototype.open.apply( this, [source, options] );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
this.addHandler('open', function openHandler() {
|
||||||
|
_this.removeHandler(openHandler);
|
||||||
|
_this.world.getItemAt(0)._originalForNavigator = original;
|
||||||
|
});
|
||||||
|
|
||||||
|
return $.Viewer.prototype.open.apply( this, [source, options] );
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overrides Viewer.addTiledImage
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
addTiledImage: function(options) {
|
||||||
|
var original = options.originalTiledImage;
|
||||||
|
delete options.original;
|
||||||
|
|
||||||
|
var optionsClone = $.extend({}, options, {
|
||||||
|
success: function(item) {
|
||||||
|
item._originalForNavigator = original;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return $.Viewer.prototype.addTiledImage.apply(this, [optionsClone]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1067,6 +1067,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
|||||||
* @param {Number} [options.y=0] The Y position for the image in world coordinates.
|
* @param {Number} [options.y=0] The Y position for the image in world coordinates.
|
||||||
* @param {Number} [options.width=1] The width for the image in world coordinates.
|
* @param {Number} [options.width=1] The width for the image in world coordinates.
|
||||||
* @param {Number} [options.height] The height for the image in world coordinates.
|
* @param {Number} [options.height] The height for the image in world coordinates.
|
||||||
|
* @param {Function} [options.success] A function that gets called when the image is
|
||||||
|
* successfully added. It's passed a single parameter: the resulting TiledImage.
|
||||||
* @fires OpenSeadragon.World.event:add-item
|
* @fires OpenSeadragon.World.event:add-item
|
||||||
* @fires OpenSeadragon.Viewer.event:add-item-failed
|
* @fires OpenSeadragon.Viewer.event:add-item-failed
|
||||||
*/
|
*/
|
||||||
@ -1136,11 +1138,16 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
|||||||
|
|
||||||
if (_this.navigator) {
|
if (_this.navigator) {
|
||||||
var optionsClone = $.extend({}, options, {
|
var optionsClone = $.extend({}, options, {
|
||||||
|
originalTiledImage: tiledImage,
|
||||||
tileSource: tileSource
|
tileSource: tileSource
|
||||||
});
|
});
|
||||||
|
|
||||||
_this.navigator.addTiledImage(optionsClone);
|
_this.navigator.addTiledImage(optionsClone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.success) {
|
||||||
|
options.success(tiledImage);
|
||||||
|
}
|
||||||
}, function( event ) {
|
}, function( event ) {
|
||||||
event.options = options;
|
event.options = options;
|
||||||
raiseAddItemFailed(event);
|
raiseAddItemFailed(event);
|
||||||
@ -1989,7 +1996,11 @@ function openTileSource( viewer, source, options ) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_this.navigator.open(source, options);
|
var optionsClone = $.extend({}, options, {
|
||||||
|
originalTiledImage: tiledImage
|
||||||
|
});
|
||||||
|
|
||||||
|
_this.navigator.open(source, optionsClone);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Instantiate a referencestrip if configured
|
//Instantiate a referencestrip if configured
|
||||||
|
@ -51,6 +51,7 @@ $.World = function( options ) {
|
|||||||
|
|
||||||
this.viewer = options.viewer;
|
this.viewer = options.viewer;
|
||||||
this._items = [];
|
this._items = [];
|
||||||
|
this._needsUpdate = false;
|
||||||
this._figureSizes();
|
this._figureSizes();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -74,6 +75,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._figureSizes();
|
this._figureSizes();
|
||||||
|
this._needsUpdate = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Raised when an item is added to the World.
|
* Raised when an item is added to the World.
|
||||||
@ -139,6 +141,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
|
|||||||
|
|
||||||
this._items.splice( oldIndex, 1 );
|
this._items.splice( oldIndex, 1 );
|
||||||
this._items.splice( index, 0, item );
|
this._items.splice( index, 0, item );
|
||||||
|
this._needsUpdate = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Raised when the order of the indexes has been changed.
|
* Raised when the order of the indexes has been changed.
|
||||||
@ -175,6 +178,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
|
|||||||
|
|
||||||
this._items.splice( index, 1 );
|
this._items.splice( index, 1 );
|
||||||
this._figureSizes();
|
this._figureSizes();
|
||||||
|
this._needsUpdate = true;
|
||||||
this._raiseRemoveItem(item);
|
this._raiseRemoveItem(item);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -187,6 +191,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
|
|||||||
var removedItems = this._items;
|
var removedItems = this._items;
|
||||||
this._items = [];
|
this._items = [];
|
||||||
this._figureSizes();
|
this._figureSizes();
|
||||||
|
this._needsUpdate = true;
|
||||||
|
|
||||||
for (var i = 0; i < removedItems.length; i++) {
|
for (var i = 0; i < removedItems.length; i++) {
|
||||||
this._raiseRemoveItem(removedItems[i]);
|
this._raiseRemoveItem(removedItems[i]);
|
||||||
@ -211,6 +216,8 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
|
|||||||
for ( var i = 0; i < this._items.length; i++ ) {
|
for ( var i = 0; i < this._items.length; i++ ) {
|
||||||
this._items[i].update();
|
this._items[i].update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._needsUpdate = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -223,7 +230,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return this._needsUpdate;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
prefixUrl: "../../../build/openseadragon/images/"
|
prefixUrl: "../../../build/openseadragon/images/"
|
||||||
} );
|
} );
|
||||||
|
|
||||||
this.gridTest();
|
this.crossTest();
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
|
Loading…
Reference in New Issue
Block a user