Use ol.TileCache in ol.source.ImageTileSource
This commit is contained in:
@@ -5,6 +5,7 @@ goog.require('ol.Attribution');
|
|||||||
goog.require('ol.Extent');
|
goog.require('ol.Extent');
|
||||||
goog.require('ol.ImageTile');
|
goog.require('ol.ImageTile');
|
||||||
goog.require('ol.Projection');
|
goog.require('ol.Projection');
|
||||||
|
goog.require('ol.TileCache');
|
||||||
goog.require('ol.TileCoord');
|
goog.require('ol.TileCoord');
|
||||||
goog.require('ol.TileUrlFunction');
|
goog.require('ol.TileUrlFunction');
|
||||||
goog.require('ol.TileUrlFunctionType');
|
goog.require('ol.TileUrlFunctionType');
|
||||||
@@ -55,32 +56,46 @@ ol.source.ImageTileSource = function(options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Object.<string, ol.ImageTile>}
|
* @type {ol.TileCache}
|
||||||
* FIXME will need to expire elements from this cache
|
|
||||||
* FIXME see elemoine's work with goog.structs.LinkedMap
|
|
||||||
*/
|
*/
|
||||||
this.tileCache_ = {};
|
this.tileCache_ = new ol.TileCache();
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.source.ImageTileSource, ol.source.TileSource);
|
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
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.source.ImageTileSource.prototype.getTile = function(tileCoord) {
|
ol.source.ImageTileSource.prototype.getTile = function(tileCoord) {
|
||||||
var key = tileCoord.toString();
|
var key = tileCoord.toString();
|
||||||
if (goog.object.containsKey(this.tileCache_, key)) {
|
if (this.tileCache_.containsKey(key)) {
|
||||||
return this.tileCache_[key];
|
return /** @type {ol.Tile} */ (this.tileCache_.get(key));
|
||||||
} else {
|
} else {
|
||||||
var tileUrl = this.getTileCoordUrl(tileCoord);
|
var tileUrl = this.getTileCoordUrl(tileCoord);
|
||||||
var tile;
|
var tile;
|
||||||
if (goog.isDef(tileUrl)) {
|
if (goog.isDef(tileUrl)) {
|
||||||
tile = new ol.ImageTile(tileCoord, tileUrl, this.crossOrigin_);
|
tile = new ol.ImageTile(tileCoord, tileUrl, this.crossOrigin_);
|
||||||
|
this.tileCache_.set(key, tile);
|
||||||
} else {
|
} else {
|
||||||
tile = null;
|
tile = null;
|
||||||
}
|
}
|
||||||
this.tileCache_[key] = tile;
|
|
||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user