add an ol.TileCache and use it in ol.TileLayer
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user