Create tile cache for all tile sources

This commit is contained in:
Tim Schaub
2015-02-16 12:22:15 -07:00
parent eb1a46cf7d
commit 2cf1fe5552
4 changed files with 21 additions and 79 deletions

View File

@@ -1,7 +1,6 @@
goog.provide('ol.source.TileDebug');
goog.require('ol.Tile');
goog.require('ol.TileCache');
goog.require('ol.TileCoord');
goog.require('ol.TileState');
goog.require('ol.dom');
@@ -89,42 +88,20 @@ ol.source.TileDebug = function(options) {
tileGrid: options.tileGrid
});
/**
* @private
* @type {ol.TileCache}
*/
this.tileCache_ = new ol.TileCache();
};
goog.inherits(ol.source.TileDebug, ol.source.Tile);
/**
* @inheritDoc
*/
ol.source.TileDebug.prototype.canExpireCache = function() {
return this.tileCache_.canExpireCache();
};
/**
* @inheritDoc
*/
ol.source.TileDebug.prototype.expireCache = function(usedTiles) {
this.tileCache_.expireCache(usedTiles);
};
/**
* @inheritDoc
*/
ol.source.TileDebug.prototype.getTile = function(z, x, y) {
var tileCoordKey = this.getKeyZXY(z, x, y);
if (this.tileCache_.containsKey(tileCoordKey)) {
return /** @type {!ol.DebugTile_} */ (this.tileCache_.get(tileCoordKey));
if (this.tileCache.containsKey(tileCoordKey)) {
return /** @type {!ol.DebugTile_} */ (this.tileCache.get(tileCoordKey));
} else {
var tile = new ol.DebugTile_([z, x, y], this.tileGrid);
this.tileCache_.set(tileCoordKey, tile);
this.tileCache.set(tileCoordKey, tile);
return tile;
}
};

View File

@@ -2,7 +2,6 @@ goog.provide('ol.source.TileImage');
goog.require('goog.asserts');
goog.require('ol.ImageTile');
goog.require('ol.TileCache');
goog.require('ol.TileCoord');
goog.require('ol.TileLoadFunctionType');
goog.require('ol.TileState');
@@ -50,12 +49,6 @@ ol.source.TileImage = function(options) {
this.crossOrigin =
goog.isDef(options.crossOrigin) ? options.crossOrigin : null;
/**
* @protected
* @type {ol.TileCache}
*/
this.tileCache = new ol.TileCache();
/**
* @protected
* @type {ol.TileLoadFunctionType}
@@ -84,22 +77,6 @@ ol.source.TileImage.defaultTileLoadFunction = function(imageTile, src) {
};
/**
* @inheritDoc
*/
ol.source.TileImage.prototype.canExpireCache = function() {
return this.tileCache.canExpireCache();
};
/**
* @inheritDoc
*/
ol.source.TileImage.prototype.expireCache = function(usedTiles) {
this.tileCache.expireCache(usedTiles);
};
/**
* @inheritDoc
*/

View File

@@ -4,6 +4,7 @@ goog.provide('ol.source.TileOptions');
goog.require('goog.functions');
goog.require('ol.Attribution');
goog.require('ol.Extent');
goog.require('ol.TileCache');
goog.require('ol.TileRange');
goog.require('ol.source.Source');
goog.require('ol.tilecoord');
@@ -64,6 +65,12 @@ ol.source.Tile = function(options) {
*/
this.tileGrid = goog.isDef(options.tileGrid) ? options.tileGrid : null;
/**
* @protected
* @type {ol.TileCache}
*/
this.tileCache = new ol.TileCache();
};
goog.inherits(ol.source.Tile, ol.source.Source);
@@ -71,13 +78,17 @@ goog.inherits(ol.source.Tile, ol.source.Source);
/**
* @return {boolean} Can expire cache.
*/
ol.source.Tile.prototype.canExpireCache = goog.functions.FALSE;
ol.source.Tile.prototype.canExpireCache = function() {
return this.tileCache.canExpireCache();
};
/**
* @param {Object.<string, ol.TileRange>} usedTiles Used tiles.
*/
ol.source.Tile.prototype.expireCache = goog.abstractMethod;
ol.source.Tile.prototype.expireCache = function(usedTiles) {
this.tileCache.expireCache(usedTiles);
};
/**

View File

@@ -7,7 +7,6 @@ goog.require('goog.events.EventType');
goog.require('goog.net.Jsonp');
goog.require('ol.Attribution');
goog.require('ol.Tile');
goog.require('ol.TileCache');
goog.require('ol.TileState');
goog.require('ol.TileUrlFunction');
goog.require('ol.extent');
@@ -46,12 +45,6 @@ ol.source.TileUTFGrid = function(options) {
*/
this.tileUrlFunction_ = ol.TileUrlFunction.nullTileUrlFunction;
/**
* @private
* @type {!ol.TileCache}
*/
this.tileCache_ = new ol.TileCache();
/**
* @private
* @type {string|undefined}
@@ -64,22 +57,6 @@ ol.source.TileUTFGrid = function(options) {
goog.inherits(ol.source.TileUTFGrid, ol.source.Tile);
/**
* @inheritDoc
*/
ol.source.TileUTFGrid.prototype.canExpireCache = function() {
return this.tileCache_.canExpireCache();
};
/**
* @inheritDoc
*/
ol.source.TileUTFGrid.prototype.expireCache = function(usedTiles) {
this.tileCache_.expireCache(usedTiles);
};
/**
* @return {string|undefined} The template from TileJSON.
* @api
@@ -195,8 +172,8 @@ ol.source.TileUTFGrid.prototype.handleTileJSONResponse = function(tileJSON) {
ol.source.TileUTFGrid.prototype.getTile =
function(z, x, y, pixelRatio, projection) {
var tileCoordKey = this.getKeyZXY(z, x, y);
if (this.tileCache_.containsKey(tileCoordKey)) {
return /** @type {!ol.Tile} */ (this.tileCache_.get(tileCoordKey));
if (this.tileCache.containsKey(tileCoordKey)) {
return /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
} else {
goog.asserts.assert(projection);
var tileCoord = [z, x, y];
@@ -207,7 +184,7 @@ ol.source.TileUTFGrid.prototype.getTile =
goog.isDef(tileUrl) ? tileUrl : '',
this.tileGrid.getTileCoordExtent(tileCoord),
this.preemptive_);
this.tileCache_.set(tileCoordKey, tile);
this.tileCache.set(tileCoordKey, tile);
return tile;
}
};
@@ -218,8 +195,8 @@ ol.source.TileUTFGrid.prototype.getTile =
*/
ol.source.TileUTFGrid.prototype.useTile = function(z, x, y) {
var tileCoordKey = this.getKeyZXY(z, x, y);
if (this.tileCache_.containsKey(tileCoordKey)) {
this.tileCache_.get(tileCoordKey);
if (this.tileCache.containsKey(tileCoordKey)) {
this.tileCache.get(tileCoordKey);
}
};