diff --git a/src/viewer.js b/src/viewer.js index 16d5cfa1..30900ba7 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1393,6 +1393,31 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, } ); }, + /** + * Add a simple image to the viewer. + * The options are the same than {@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; diff --git a/test/modules/multi-image.js b/test/modules/multi-image.js index 5d4b21bd..bf1b03ae 100644 --- a/test/modules/multi-image.js +++ b/test/modules/multi-image.js @@ -189,4 +189,22 @@ ]); }); + 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 not set using addSimpleImage'); + start(); + }); + + viewer.addSimpleImage({ + url: '/test/data/A.png', + opacity: 0.5 + }); + }); + viewer.open('/test/data/testpattern.dzi'); + }); + })();