add an ol.TileCache and use it in ol.TileLayer

This commit is contained in:
Éric Lemoine
2012-06-21 18:56:43 +02:00
parent a06de64f37
commit 1c7e0f8481
7 changed files with 92 additions and 1 deletions
+22
View File
@@ -1,6 +1,7 @@
goog.provide('ol.layer.TileLayer');
goog.require('ol.layer.Layer');
goog.require('ol.TileCache');
/**
* @constructor
@@ -68,6 +69,12 @@ ol.layer.TileLayer = function() {
*/
this.resolutions_ = null;
/**
* @private
* @type {ol.TileCache}
*/
this.cache_ = new ol.TileCache();
};
goog.inherits(ol.layer.TileLayer, ol.layer.Layer);
@@ -214,3 +221,18 @@ ol.layer.TileLayer.prototype.setNumZoomLevels = function(numZoomLevels) {
ol.layer.TileLayer.prototype.setResolutions = function(resolutions) {
this.resolutions_ = resolutions;
};
/**
* Get a tile from the cache, or create a tile and add to
* the cache.
* @param url {string}
* @param bounds {ol.Bounds}
*/
ol.layer.TileLayer.prototype.getTile = function(url, bounds) {
var tile = this.cache_.get(url);
if (!goog.isDef(tile)) {
tile = new ol.Tile(url, bounds);
this.cache_.set(tile.getUrl(), tile);
}
return tile;
};