diff --git a/src/ol/renderer/layerrenderer.js b/src/ol/renderer/layerrenderer.js index 5dd3da9a29..e3d368b2e8 100644 --- a/src/ol/renderer/layerrenderer.js +++ b/src/ol/renderer/layerrenderer.js @@ -194,7 +194,8 @@ ol.renderer.Layer.prototype.scheduleExpireCache = */ function(tileSource, map, frameState) { var tileSourceKey = goog.getUid(tileSource).toString(); - tileSource.expireCache(frameState.usedTiles[tileSourceKey]); + tileSource.expireCache(frameState.viewState.projection, + frameState.usedTiles[tileSourceKey]); }, tileSource)); } }; @@ -327,7 +328,7 @@ ol.renderer.Layer.prototype.manageTilePyramid = function( opt_tileCallback.call(opt_this, tile); } } else { - tileSource.useTile(z, x, y); + tileSource.useTile(z, x, y, projection); } } } diff --git a/src/ol/source/tileimagesource.js b/src/ol/source/tileimagesource.js index 697d1c0afb..c06c4bc3bc 100644 --- a/src/ol/source/tileimagesource.js +++ b/src/ol/source/tileimagesource.js @@ -3,6 +3,7 @@ goog.provide('ol.source.TileImage'); goog.require('goog.asserts'); goog.require('goog.events'); goog.require('goog.events.EventType'); +goog.require('goog.object'); goog.require('ol.ImageTile'); goog.require('ol.TileCache'); goog.require('ol.TileCoord'); @@ -96,6 +97,34 @@ ol.source.TileImage.defaultTileLoadFunction = function(imageTile, src) { }; +/** + * @inheritDoc + */ +ol.source.TileImage.prototype.canExpireCache = function() { + var canExpire = this.tileCache.canExpireCache(); + if (canExpire) { + return true; + } else { + return goog.object.some(this.tileCacheForProjection, function(tileCache) { + return tileCache.canExpireCache(); + }); + } +}; + + +/** + * @inheritDoc + */ +ol.source.TileImage.prototype.expireCache = function(projection, usedTiles) { + var usedTileCache = this.getTileCacheForProjection(projection); + + this.tileCache.expireCache(this.tileCache == usedTileCache ? usedTiles : {}); + goog.object.forEach(this.tileCacheForProjection, function(tileCache) { + return tileCache.expireCache(tileCache == usedTileCache ? usedTiles : {}); + }); +}; + + /** * @inheritDoc */ @@ -274,9 +303,10 @@ ol.source.TileImage.prototype.setTileUrlFunction = function(tileUrlFunction) { /** * @inheritDoc */ -ol.source.TileImage.prototype.useTile = function(z, x, y) { +ol.source.TileImage.prototype.useTile = function(z, x, y, projection) { + var tileCache = this.getTileCacheForProjection(projection); var tileCoordKey = this.getKeyZXY(z, x, y); - if (this.tileCache.containsKey(tileCoordKey)) { - this.tileCache.get(tileCoordKey); + if (!goog.isNull(tileCache) && tileCache.containsKey(tileCoordKey)) { + tileCache.get(tileCoordKey); } }; diff --git a/src/ol/source/tilesource.js b/src/ol/source/tilesource.js index 55e96651bd..d2c8812d3f 100644 --- a/src/ol/source/tilesource.js +++ b/src/ol/source/tilesource.js @@ -98,10 +98,14 @@ ol.source.Tile.prototype.canExpireCache = function() { /** + * @param {ol.proj.Projection} projection * @param {Object.} usedTiles Used tiles. */ -ol.source.Tile.prototype.expireCache = function(usedTiles) { - this.tileCache.expireCache(usedTiles); +ol.source.Tile.prototype.expireCache = function(projection, usedTiles) { + var tileCache = this.getTileCacheForProjection(projection); + if (!goog.isNull(tileCache)) { + tileCache.expireCache(usedTiles); + } }; @@ -267,6 +271,7 @@ ol.source.Tile.prototype.getTileCoordForTileUrlFunction = * @param {number} z Tile coordinate z. * @param {number} x Tile coordinate x. * @param {number} y Tile coordinate y. + * @param {ol.proj.Projection} projection Projection. */ ol.source.Tile.prototype.useTile = ol.nullFunction;