diff --git a/src/ol/TileCache.js b/src/ol/TileCache.js deleted file mode 100644 index 0772adf06b..0000000000 --- a/src/ol/TileCache.js +++ /dev/null @@ -1,23 +0,0 @@ -goog.provide('ol.TileCache'); - -goog.require('goog.structs.LinkedMap'); - -/** - * A cache of ol.Tile objects. - * @constructor - * @extends {goog.structs.LinkedMap} - * @param {number=} opt_size - */ -ol.TileCache = function(opt_size) { - goog.base(this, opt_size || 100, true /* cache mode */); -}; - -goog.inherits(ol.TileCache, goog.structs.LinkedMap); - -/** - * @inheritDoc - */ -ol.TileCache.prototype.removeNode = function(node) { - goog.base(this, 'removeNode', node); - node.value.destroy(); -}; diff --git a/src/ol/tilestore.js b/src/ol/tilestore.js index d2d708da90..2327c86d24 100644 --- a/src/ol/tilestore.js +++ b/src/ol/tilestore.js @@ -1,6 +1,7 @@ goog.provide('ol.TileStore'); goog.require('ol.Store'); +goog.require('ol.Tile'); goog.require('ol.TileCoord'); goog.require('ol.TileGrid'); goog.require('ol.TileUrlFunctionType'); @@ -12,8 +13,9 @@ goog.require('ol.TileUrlFunctionType'); * @extends {ol.Store} * @param {ol.TileGrid} tileGrid Tile grid. * @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL. + * @param {string=} opt_crossOrigin Cross origin. */ -ol.TileStore = function(tileGrid, tileUrlFunction) { +ol.TileStore = function(tileGrid, tileUrlFunction, opt_crossOrigin) { goog.base(this); @@ -29,10 +31,41 @@ ol.TileStore = function(tileGrid, tileUrlFunction) { */ this.tileUrlFunction_ = tileUrlFunction; + /** + * @private + * @type {string|undefined} + */ + this.crossOrigin_ = opt_crossOrigin; + + /** + * @private + * @type {Object.} + * FIXME will need to expire elements from this cache + * FIXME see elemoine's work with goog.structs.LinkedMap + */ + this.tileCache_ = {}; + }; goog.inherits(ol.TileStore, ol.Store); +/** + * @param {ol.TileCoord} tileCoord Tile coordinate. + * @return {ol.Tile} Tile. + */ +ol.TileStore.prototype.getTile = function(tileCoord) { + var key = tileCoord.toString(); + if (goog.object.containsKey(this.tileCache_, key)) { + return this.tileCache_[key]; + } else { + var tileUrl = this.getTileCoordUrl(tileCoord); + var tile = new ol.Tile(tileCoord, tileUrl, this.crossOrigin_); + this.tileCache_[key] = tile; + return tile; + } +}; + + /** * @param {ol.TileCoord} tileCoord Tile coordinate. * @return {string} Tile coord URL.