From 09ec4449587c2294181bc27ab45929518e3687eb Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Wed, 23 Jan 2013 14:28:49 +0100 Subject: [PATCH] Use ol.TileCache in ol.source.ImageTileSource --- src/ol/source/imagetilesource.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/ol/source/imagetilesource.js b/src/ol/source/imagetilesource.js index 5baea4539f..b025985f00 100644 --- a/src/ol/source/imagetilesource.js +++ b/src/ol/source/imagetilesource.js @@ -5,6 +5,7 @@ goog.require('ol.Attribution'); goog.require('ol.Extent'); goog.require('ol.ImageTile'); goog.require('ol.Projection'); +goog.require('ol.TileCache'); goog.require('ol.TileCoord'); goog.require('ol.TileUrlFunction'); goog.require('ol.TileUrlFunctionType'); @@ -55,32 +56,46 @@ ol.source.ImageTileSource = function(options) { /** * @private - * @type {Object.} - * FIXME will need to expire elements from this cache - * FIXME see elemoine's work with goog.structs.LinkedMap + * @type {ol.TileCache} */ - this.tileCache_ = {}; + this.tileCache_ = new ol.TileCache(); }; goog.inherits(ol.source.ImageTileSource, ol.source.TileSource); +/** + * @inheritDoc + */ +ol.source.ImageTileSource.prototype.canExpireCache = function() { + return this.tileCache_.canExpireCache(); +}; + + +/** + * @inheritDoc + */ +ol.source.ImageTileSource.prototype.expireCache = function(usedTiles) { + this.tileCache_.expireCache(usedTiles); +}; + + /** * @inheritDoc */ ol.source.ImageTileSource.prototype.getTile = function(tileCoord) { var key = tileCoord.toString(); - if (goog.object.containsKey(this.tileCache_, key)) { - return this.tileCache_[key]; + if (this.tileCache_.containsKey(key)) { + return /** @type {ol.Tile} */ (this.tileCache_.get(key)); } else { var tileUrl = this.getTileCoordUrl(tileCoord); var tile; if (goog.isDef(tileUrl)) { tile = new ol.ImageTile(tileCoord, tileUrl, this.crossOrigin_); + this.tileCache_.set(key, tile); } else { tile = null; } - this.tileCache_[key] = tile; return tile; } };