Add CORS support to ImageTileSource

This commit is contained in:
Antoine Vandecreme 2015-11-01 13:25:25 -05:00
parent 9a4543cd73
commit 3316a55b97
2 changed files with 16 additions and 4 deletions

View File

@ -46,6 +46,7 @@
*/
$.ImageTileSource = function (options) {
this.options = options;
$.TileSource.apply(this, [options]);
};
@ -64,13 +65,13 @@
/**
*
* @function
* @param {Image} image - the actual image
* @param {Object} options - the options
* @param {String} dataUrl - the url the image was retreived from, if any.
* @return {Object} options - A dictionary of keyword arguments sufficient
* to configure this tile sources constructor.
*/
configure: function (image, dataUrl) {
return image;
configure: function (options, dataUrl) {
return options;
},
/**
* Responsible for retrieving, and caching the
@ -83,6 +84,13 @@
var image = new Image();
var _this = this;
if (this.options.crossOriginPolicy) {
image.crossOriginPolicy = this.options.crossOriginPolicy;
}
if (this.options.ajaxWithCredentials) {
image.useCredentials = this.options.ajaxWithCredentials;
}
image.addEventListener('load', function () {
_this.width = image.naturalWidth;
_this.height = image.naturalHeight;

View File

@ -2045,6 +2045,7 @@ function getTileSourceImplementation( viewer, tileSource, successCallback,
//If its still a string it means it must be a url at this point
tileSource = new $.TileSource({
url: tileSource,
crossOriginPolicy: viewer.crossOriginPolicy,
ajaxWithCredentials: viewer.ajaxWithCredentials,
success: function( event ) {
successCallback( event.tileSource );
@ -2054,7 +2055,10 @@ function getTileSourceImplementation( viewer, tileSource, successCallback,
failCallback( event );
} );
} else if ( $.isPlainObject( tileSource ) || tileSource.nodeType ) {
} else if ($.isPlainObject(tileSource) || tileSource.nodeType) {
if (!tileSource.crossOriginPolicy && viewer.crossOriginPolicy) {
tileSource.crossOriginPolicy = viewer.crossOriginPolicy;
}
if (tileSource.ajaxWithCredentials === undefined) {
tileSource.ajaxWithCredentials = viewer.ajaxWithCredentials;
}