Add tile loading events to image tile sources
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
goog.provide('ol.source.TileImage');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.ImageTile');
|
||||
goog.require('ol.TileCache');
|
||||
goog.require('ol.TileCoord');
|
||||
@@ -17,6 +19,7 @@ goog.require('ol.source.Tile');
|
||||
* Base class for sources providing images divided into a tile grid.
|
||||
*
|
||||
* @constructor
|
||||
* @fires ol.source.TileEvent
|
||||
* @extends {ol.source.Tile}
|
||||
* @param {olx.source.TileImageOptions} options Image tile options.
|
||||
* @api
|
||||
@@ -118,6 +121,9 @@ ol.source.TileImage.prototype.getTile =
|
||||
goog.isDef(tileUrl) ? tileUrl : '',
|
||||
this.crossOrigin,
|
||||
this.tileLoadFunction);
|
||||
goog.events.listen(tile, goog.events.EventType.CHANGE,
|
||||
this.handleTileChange_, false, this);
|
||||
|
||||
this.tileCache.set(tileCoordKey, tile);
|
||||
return tile;
|
||||
}
|
||||
@@ -142,6 +148,30 @@ ol.source.TileImage.prototype.getTileUrlFunction = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Handle tile change events.
|
||||
* @param {goog.events.Event} event Event.
|
||||
* @private
|
||||
*/
|
||||
ol.source.TileImage.prototype.handleTileChange_ = function(event) {
|
||||
var tile = /** @type {ol.Tile} */ (event.target);
|
||||
switch (tile.getState()) {
|
||||
case ol.TileState.LOADING:
|
||||
this.dispatchEvent(
|
||||
new ol.source.TileEvent(ol.source.TileEventType.TILELOADSTART, tile));
|
||||
break;
|
||||
case ol.TileState.LOADED:
|
||||
this.dispatchEvent(
|
||||
new ol.source.TileEvent(ol.source.TileEventType.TILELOADEND, tile));
|
||||
break;
|
||||
case ol.TileState.ERROR:
|
||||
this.dispatchEvent(
|
||||
new ol.source.TileEvent(ol.source.TileEventType.TILELOADERROR, tile));
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function.
|
||||
* @api
|
||||
|
||||
Reference in New Issue
Block a user