Merge tile cache into TileStore
This commit is contained in:
@@ -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();
|
|
||||||
};
|
|
||||||
+34
-1
@@ -1,6 +1,7 @@
|
|||||||
goog.provide('ol.TileStore');
|
goog.provide('ol.TileStore');
|
||||||
|
|
||||||
goog.require('ol.Store');
|
goog.require('ol.Store');
|
||||||
|
goog.require('ol.Tile');
|
||||||
goog.require('ol.TileCoord');
|
goog.require('ol.TileCoord');
|
||||||
goog.require('ol.TileGrid');
|
goog.require('ol.TileGrid');
|
||||||
goog.require('ol.TileUrlFunctionType');
|
goog.require('ol.TileUrlFunctionType');
|
||||||
@@ -12,8 +13,9 @@ goog.require('ol.TileUrlFunctionType');
|
|||||||
* @extends {ol.Store}
|
* @extends {ol.Store}
|
||||||
* @param {ol.TileGrid} tileGrid Tile grid.
|
* @param {ol.TileGrid} tileGrid Tile grid.
|
||||||
* @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL.
|
* @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);
|
goog.base(this);
|
||||||
|
|
||||||
@@ -29,10 +31,41 @@ ol.TileStore = function(tileGrid, tileUrlFunction) {
|
|||||||
*/
|
*/
|
||||||
this.tileUrlFunction_ = tileUrlFunction;
|
this.tileUrlFunction_ = tileUrlFunction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {string|undefined}
|
||||||
|
*/
|
||||||
|
this.crossOrigin_ = opt_crossOrigin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {Object.<string, ol.Tile>}
|
||||||
|
* 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);
|
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.
|
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||||
* @return {string} Tile coord URL.
|
* @return {string} Tile coord URL.
|
||||||
|
|||||||
Reference in New Issue
Block a user