Allow tile load function to be overridden

This commit is contained in:
Tom Payne
2013-09-18 13:39:42 +01:00
parent 0085623eee
commit 6896e920f9
2 changed files with 31 additions and 3 deletions

View File

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

View File

@@ -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;
}