Merge pull request #1036 from twpayne/async-tile-load
Asynchronos tile URL calculation
This commit is contained in:
@@ -654,6 +654,8 @@
|
|||||||
* @property {number|undefined} maxZoom Optional max zoom level. The default is
|
* @property {number|undefined} maxZoom Optional max zoom level. The default is
|
||||||
* 18.
|
* 18.
|
||||||
* @property {number|undefined} minZoom Unsupported (TODO: remove this).
|
* @property {number|undefined} minZoom Unsupported (TODO: remove this).
|
||||||
|
* @property {ol.TileLoadFunctionType|undefined} tileLoadFunction Optional
|
||||||
|
* function to load a tile given a URL.
|
||||||
* @property {ol.TileUrlFunctionType|undefined} tileUrlFunction Optional
|
* @property {ol.TileUrlFunctionType|undefined} tileUrlFunction Optional
|
||||||
* function to get tile URL given a tile coordinate and the projection.
|
* function to get tile URL given a tile coordinate and the projection.
|
||||||
* Required if url or urls are not provided.
|
* Required if url or urls are not provided.
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
@exportProperty ol.ImageTile.prototype.getImage
|
||||||
+11
-2
@@ -7,6 +7,7 @@ goog.require('goog.events.EventType');
|
|||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
goog.require('ol.Tile');
|
goog.require('ol.Tile');
|
||||||
goog.require('ol.TileCoord');
|
goog.require('ol.TileCoord');
|
||||||
|
goog.require('ol.TileLoadFunctionType');
|
||||||
goog.require('ol.TileState');
|
goog.require('ol.TileState');
|
||||||
|
|
||||||
|
|
||||||
@@ -18,8 +19,10 @@ goog.require('ol.TileState');
|
|||||||
* @param {ol.TileState} state State.
|
* @param {ol.TileState} state State.
|
||||||
* @param {string} src Image source URI.
|
* @param {string} src Image source URI.
|
||||||
* @param {?string} crossOrigin Cross origin.
|
* @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);
|
goog.base(this, tileCoord, state);
|
||||||
|
|
||||||
@@ -52,6 +55,12 @@ ol.ImageTile = function(tileCoord, state, src, crossOrigin) {
|
|||||||
*/
|
*/
|
||||||
this.imageListenerKeys_ = null;
|
this.imageListenerKeys_ = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.TileLoadFunctionType}
|
||||||
|
*/
|
||||||
|
this.tileLoadFunction_ = tileLoadFunction;
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.ImageTile, ol.Tile);
|
goog.inherits(ol.ImageTile, ol.Tile);
|
||||||
|
|
||||||
@@ -127,7 +136,7 @@ ol.ImageTile.prototype.load = function() {
|
|||||||
goog.events.listenOnce(this.image_, goog.events.EventType.LOAD,
|
goog.events.listenOnce(this.image_, goog.events.EventType.LOAD,
|
||||||
this.handleImageLoad_, false, this)
|
this.handleImageLoad_, false, this)
|
||||||
];
|
];
|
||||||
this.image_.src = this.src_;
|
this.tileLoadFunction_(this, this.src_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ goog.require('ol.ImageTile');
|
|||||||
goog.require('ol.Tile');
|
goog.require('ol.Tile');
|
||||||
goog.require('ol.TileCache');
|
goog.require('ol.TileCache');
|
||||||
goog.require('ol.TileCoord');
|
goog.require('ol.TileCoord');
|
||||||
|
goog.require('ol.TileLoadFunctionType');
|
||||||
goog.require('ol.TileState');
|
goog.require('ol.TileState');
|
||||||
goog.require('ol.TileUrlFunction');
|
goog.require('ol.TileUrlFunction');
|
||||||
goog.require('ol.TileUrlFunctionType');
|
goog.require('ol.TileUrlFunctionType');
|
||||||
@@ -22,6 +23,7 @@ goog.require('ol.tilegrid.TileGrid');
|
|||||||
* opaque: (boolean|undefined),
|
* opaque: (boolean|undefined),
|
||||||
* projection: ol.proj.ProjectionLike,
|
* projection: ol.proj.ProjectionLike,
|
||||||
* tileGrid: (ol.tilegrid.TileGrid|undefined),
|
* tileGrid: (ol.tilegrid.TileGrid|undefined),
|
||||||
|
* tileLoadFunction: (ol.TileLoadFunctionType|undefined),
|
||||||
* tileUrlFunction: (ol.TileUrlFunctionType|undefined)}}
|
* tileUrlFunction: (ol.TileUrlFunctionType|undefined)}}
|
||||||
*/
|
*/
|
||||||
ol.source.TileImageOptions;
|
ol.source.TileImageOptions;
|
||||||
@@ -65,10 +67,26 @@ ol.source.TileImage = function(options) {
|
|||||||
*/
|
*/
|
||||||
this.tileCache_ = new ol.TileCache();
|
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);
|
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
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
@@ -100,7 +118,8 @@ ol.source.TileImage.prototype.getTile = function(z, x, y, projection) {
|
|||||||
tileCoord,
|
tileCoord,
|
||||||
goog.isDef(tileUrl) ? ol.TileState.IDLE : ol.TileState.EMPTY,
|
goog.isDef(tileUrl) ? ol.TileState.IDLE : ol.TileState.EMPTY,
|
||||||
goog.isDef(tileUrl) ? tileUrl : '',
|
goog.isDef(tileUrl) ? tileUrl : '',
|
||||||
this.crossOrigin_);
|
this.crossOrigin_,
|
||||||
|
this.tileLoadFunction_);
|
||||||
this.tileCache_.set(tileCoordKey, tile);
|
this.tileCache_.set(tileCoordKey, tile);
|
||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ ol.source.XYZ = function(options) {
|
|||||||
logo: options.logo,
|
logo: options.logo,
|
||||||
projection: projection,
|
projection: projection,
|
||||||
tileGrid: tileGrid,
|
tileGrid: tileGrid,
|
||||||
|
tileLoadFunction: options.tileLoadFunction,
|
||||||
tileUrlFunction: ol.TileUrlFunction.nullTileUrlFunction
|
tileUrlFunction: ol.TileUrlFunction.nullTileUrlFunction
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
@exportProperty ol.Tile.prototype.getTileCoord
|
||||||
@@ -70,6 +70,14 @@ ol.Tile.prototype.getKey = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {ol.TileCoord}
|
||||||
|
*/
|
||||||
|
ol.Tile.prototype.getTileCoord = function() {
|
||||||
|
return this.tileCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {ol.TileState} State.
|
* @return {ol.TileState} State.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
@exportProperty ol.TileCoord.prototype.getZXY
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
goog.provide('ol.TileCoord');
|
goog.provide('ol.TileCoord');
|
||||||
|
|
||||||
goog.require('goog.array');
|
goog.require('goog.array');
|
||||||
|
goog.require('goog.asserts');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,6 +114,23 @@ ol.TileCoord.getKeyZXY = function(z, x, y) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Array.<number>=} opt_result Optional array to reuse.
|
||||||
|
* @return {Array.<number>} Array of z, x, y.
|
||||||
|
*/
|
||||||
|
ol.TileCoord.prototype.getZXY = function(opt_result) {
|
||||||
|
if (goog.isDef(opt_result)) {
|
||||||
|
goog.asserts.assert(opt_result.length == 3);
|
||||||
|
opt_result[0] = this.z;
|
||||||
|
opt_result[1] = this.x;
|
||||||
|
opt_result[2] = this.y;
|
||||||
|
return opt_result;
|
||||||
|
} else {
|
||||||
|
return [this.z, this.x, this.y];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {number} Hash.
|
* @return {number} Hash.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
goog.provide('ol.TileLoadFunctionType');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {function(ol.ImageTile, string)}
|
||||||
|
*/
|
||||||
|
ol.TileLoadFunctionType;
|
||||||
Reference in New Issue
Block a user