mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-26 07:06:10 +03:00
Add support to open an ImageTileSource with it constructor.
This commit is contained in:
parent
67b0d9bd99
commit
b85d0674e6
@ -38,6 +38,13 @@
|
|||||||
* @class ImageTileSource
|
* @class ImageTileSource
|
||||||
* @classdesc The ImageTileSource allows a simple image to be loaded
|
* @classdesc The ImageTileSource allows a simple image to be loaded
|
||||||
* into an OpenSeadragon Viewer.
|
* into an OpenSeadragon Viewer.
|
||||||
|
* There are 2 ways to open an ImageTileSource:
|
||||||
|
* 1. viewer.open({type: 'image', url: fooUrl});
|
||||||
|
* 2. viewer.open(new OpenSeadragon.ImageTileSource({url: fooUrl}));
|
||||||
|
*
|
||||||
|
* With the first syntax, the crossOriginPolicy, ajaxWithCredentials and
|
||||||
|
* useCanvas options are inherited from the viewer if they are not
|
||||||
|
* specified directly in the options object.
|
||||||
*
|
*
|
||||||
* @memberof OpenSeadragon
|
* @memberof OpenSeadragon
|
||||||
* @extends OpenSeadragon.TileSource
|
* @extends OpenSeadragon.TileSource
|
||||||
@ -45,20 +52,22 @@
|
|||||||
* @param {String} options.url URL of the image
|
* @param {String} options.url URL of the image
|
||||||
* @param {Boolean} [options.buildPyramid=true] If set to true (default), a
|
* @param {Boolean} [options.buildPyramid=true] If set to true (default), a
|
||||||
* pyramid will be built internally to provide a better downsampling.
|
* pyramid will be built internally to provide a better downsampling.
|
||||||
* @param {String|Boolean} options.crossOriginPolicy Valid values are
|
* @param {String|Boolean} [options.crossOriginPolicy=false] Valid values are
|
||||||
* 'Anonymous', 'use-credentials', and false. If false, image requests will
|
* 'Anonymous', 'use-credentials', and false. If false, image requests will
|
||||||
* not use CORS preventing internal pyramid building for images from other
|
* not use CORS preventing internal pyramid building for images from other
|
||||||
* domains. Inherited from the viewer if not set.
|
* domains.
|
||||||
* @param {String|Boolean} options.ajaxWithCredentials Whether to set the
|
* @param {String|Boolean} [options.ajaxWithCredentials=false] Whether to set
|
||||||
* withCredentials XHR flag for AJAX requests (when loading tile sources).
|
* the withCredentials XHR flag for AJAX requests (when loading tile sources).
|
||||||
* Inherited from the viewer if not set.
|
* @param {Boolean} [options.useCanvas=true] Set to false to prevent any use
|
||||||
* @param {Boolean} options.useCanvas Set to false to prevent any use of
|
* of the canvas API.
|
||||||
* the canvas API. Inherited from the viewer if not set.
|
|
||||||
*/
|
*/
|
||||||
$.ImageTileSource = function (options) {
|
$.ImageTileSource = function (options) {
|
||||||
|
|
||||||
options = $.extend({
|
options = $.extend({
|
||||||
buildPyramid: true
|
buildPyramid: true,
|
||||||
|
crossOriginPolicy: false,
|
||||||
|
ajaxWithCredentials: false,
|
||||||
|
useCanvas: true
|
||||||
}, options);
|
}, options);
|
||||||
$.TileSource.apply(this, [options]);
|
$.TileSource.apply(this, [options]);
|
||||||
|
|
||||||
|
@ -2040,6 +2040,22 @@ function getTileSourceImplementation( viewer, tileSource, successCallback,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function waitUntilReady(tileSource, originalTileSource) {
|
||||||
|
if (tileSource.ready) {
|
||||||
|
successCallback(tileSource);
|
||||||
|
} else {
|
||||||
|
tileSource.addHandler('ready', function () {
|
||||||
|
successCallback(tileSource);
|
||||||
|
});
|
||||||
|
tileSource.addHandler('open-failed', function (event) {
|
||||||
|
failCallback({
|
||||||
|
message: event.message,
|
||||||
|
source: originalTileSource
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
if ( $.type( tileSource ) == 'string' ) {
|
if ( $.type( tileSource ) == 'string' ) {
|
||||||
//If its still a string it means it must be a url at this point
|
//If its still a string it means it must be a url at this point
|
||||||
@ -2083,24 +2099,11 @@ function getTileSourceImplementation( viewer, tileSource, successCallback,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var options = $TileSource.prototype.configure.apply( _this, [ tileSource ] );
|
var options = $TileSource.prototype.configure.apply( _this, [ tileSource ] );
|
||||||
var readySource = new $TileSource(options);
|
waitUntilReady(new $TileSource(options), tileSource);
|
||||||
if (readySource.ready) {
|
|
||||||
successCallback(readySource);
|
|
||||||
} else {
|
|
||||||
readySource.addHandler('ready', function () {
|
|
||||||
successCallback(readySource);
|
|
||||||
});
|
|
||||||
readySource.addHandler('open-failed', function (event) {
|
|
||||||
failCallback({
|
|
||||||
message: event.message,
|
|
||||||
source: tileSource
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//can assume it's already a tile source implementation
|
//can assume it's already a tile source implementation
|
||||||
successCallback( tileSource );
|
waitUntilReady(tileSource, tileSource);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user