diff --git a/src/ol/imagetile.js b/src/ol/imagetile.js index 8b97d630b5..6457d7458f 100644 --- a/src/ol/imagetile.js +++ b/src/ol/imagetile.js @@ -7,6 +7,7 @@ goog.require('goog.events.EventType'); goog.require('goog.object'); goog.require('ol.Tile'); goog.require('ol.TileCoord'); +goog.require('ol.TileLoadFunctionType'); goog.require('ol.TileState'); @@ -18,8 +19,10 @@ goog.require('ol.TileState'); * @param {ol.TileState} state State. * @param {string} src Image source URI. * @param {?string} crossOrigin Cross origin. + * @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function. */ -ol.ImageTile = function(tileCoord, state, src, crossOrigin) { +ol.ImageTile = + function(tileCoord, state, src, crossOrigin, tileLoadFunction) { goog.base(this, tileCoord, state); @@ -52,6 +55,12 @@ ol.ImageTile = function(tileCoord, state, src, crossOrigin) { */ this.imageListenerKeys_ = null; + /** + * @private + * @type {ol.TileLoadFunctionType} + */ + this.tileLoadFunction_ = tileLoadFunction; + }; goog.inherits(ol.ImageTile, ol.Tile); @@ -127,7 +136,7 @@ ol.ImageTile.prototype.load = function() { goog.events.listenOnce(this.image_, goog.events.EventType.LOAD, this.handleImageLoad_, false, this) ]; - this.image_.src = this.src_; + this.tileLoadFunction_(this, this.src_); } }; diff --git a/src/ol/source/tileimagesource.js b/src/ol/source/tileimagesource.js index 338fbc5aa6..6a50826732 100644 --- a/src/ol/source/tileimagesource.js +++ b/src/ol/source/tileimagesource.js @@ -7,6 +7,7 @@ goog.require('ol.ImageTile'); goog.require('ol.Tile'); goog.require('ol.TileCache'); goog.require('ol.TileCoord'); +goog.require('ol.TileLoadFunctionType'); goog.require('ol.TileState'); goog.require('ol.TileUrlFunction'); goog.require('ol.TileUrlFunctionType'); @@ -22,6 +23,7 @@ goog.require('ol.tilegrid.TileGrid'); * opaque: (boolean|undefined), * projection: ol.proj.ProjectionLike, * tileGrid: (ol.tilegrid.TileGrid|undefined), + * tileLoadFunction: (ol.TileLoadFunctionType|undefined), * tileUrlFunction: (ol.TileUrlFunctionType|undefined)}} */ ol.source.TileImageOptions; @@ -65,10 +67,26 @@ ol.source.TileImage = function(options) { */ this.tileCache_ = new ol.TileCache(); + /** + * @private + * @type {ol.TileLoadFunctionType} + */ + this.tileLoadFunction_ = goog.isDef(options.tileLoadFunction) ? + options.tileLoadFunction : ol.source.TileImage.defaultTileLoadFunction; + }; goog.inherits(ol.source.TileImage, ol.source.Tile); +/** + * @param {ol.ImageTile} imageTile Image tile. + * @param {string} src Source. + */ +ol.source.TileImage.defaultTileLoadFunction = function(imageTile, src) { + imageTile.getImage().src = src; +}; + + /** * @inheritDoc */ @@ -100,7 +118,8 @@ ol.source.TileImage.prototype.getTile = function(z, x, y, projection) { tileCoord, goog.isDef(tileUrl) ? ol.TileState.IDLE : ol.TileState.EMPTY, goog.isDef(tileUrl) ? tileUrl : '', - this.crossOrigin_); + this.crossOrigin_, + this.tileLoadFunction_); this.tileCache_.set(tileCoordKey, tile); return tile; }