Add Viewer.addSimpleImage method. Fix #818

This commit is contained in:
Antoine Vandecreme 2016-01-26 18:02:11 -05:00
parent 8d453b5755
commit ea6addb4c8
2 changed files with 43 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 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;

View File

@ -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');
});
})();