[ol.layer.TileLayer] add a getTileForXYZ func

This commit is contained in:
Éric Lemoine
2012-06-22 15:16:46 +02:00
parent 976239816e
commit 71a804c5e0
3 changed files with 51 additions and 10 deletions
+20 -1
View File
@@ -42,7 +42,7 @@ ol.layer.TileLayer = function() {
/**
* @protected
* @type {function(new:ol.Tile, string, ol.Bounds)}
* @type {function(new:ol.Tile, string, ol.Bounds=)}
*/
this.Tile = ol.Tile.createConstructor(this.tileWidth_, this.tileHeight_);
@@ -285,6 +285,25 @@ ol.layer.TileLayer.prototype.getTile = function(url, bounds) {
return tile;
};
/**
* Get a tile from the cache, or create a tile and add to
* the cache.
* @param {number} x
* @param {number} y
* @param {number} z
*/
ol.layer.TileLayer.prototype.getTileForXYZ = function(x, y, z) {
var url = this.url_.replace('{x}', x + '')
.replace('{y}', y + '')
.replace('{z}', z + '');
var tile = this.cache_.get(url);
if (!goog.isDef(tile)) {
tile = new this.Tile(url);
this.cache_.set(tile.getUrl(), tile);
}
return tile;
};
/**
* Get data from the layer. This is the layer's main API function.
* @param {ol.Bounds} bounds