Merge pull request #827 from avandecreme/addsimpleimage

Add Viewer.addSimpleImage method. Fix #818
This commit is contained in:
Ian Gilman 2016-01-28 11:35:02 -08:00
commit 949740d030
2 changed files with 44 additions and 0 deletions

View File

@ -1393,6 +1393,31 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
} );
},
/**
* Add a simple image to the viewer.
* The options are the same as the ones in {@link OpenSeadragon.Viewer#addTiledImage}
* except for options.tileSource which is replaced by options.url.
* @function
* @param {Object} options - See {@link OpenSeadragon.Viewer#addTiledImage}
* for all the options
* @param {String} options.url - The URL of the image to add.
* @fires OpenSeadragon.World.event:add-item
* @fires OpenSeadragon.Viewer.event:add-item-failed
*/
addSimpleImage: function(options) {
$.console.assert(options, "[Viewer.addSimpleImage] options is required");
$.console.assert(options.url, "[Viewer.addSimpleImage] options.url is required");
var opts = $.extend({}, options, {
tileSource: {
type: 'image',
url: options.url
}
});
delete opts.url;
this.addTiledImage(opts);
},
// deprecated
addLayer: function( options ) {
var _this = this;

View File

@ -189,4 +189,23 @@
]);
});
asyncTest('Viewer.addSimpleImage', function() {
viewer.addHandler("open", function openHandler() {
viewer.removeHandler("open", openHandler);
viewer.world.addHandler('add-item', function itemAdded(event) {
viewer.world.removeHandler('add-item', itemAdded);
equal(event.item.opacity, 0.5,
'Opacity option should be set when using addSimpleImage');
start();
});
viewer.addSimpleImage({
url: '/test/data/A.png',
opacity: 0.5
});
});
viewer.open('/test/data/testpattern.dzi');
});
})();