From 07d4492ece38308e1bf5672be0e22cef0a7ac037 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Wed, 22 Mar 2017 15:50:58 +0100 Subject: [PATCH] Respect cacheSize for reprojected caches --- src/ol/source/tileimage.js | 2 +- src/ol/tilecache.js | 5 ++--- test/spec/ol/source/tile.test.js | 8 ++++++++ test/spec/ol/source/tileimage.test.js | 12 +++++++++++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/ol/source/tileimage.js b/src/ol/source/tileimage.js index 4eaa6b3ee9..20a80a6af0 100644 --- a/src/ol/source/tileimage.js +++ b/src/ol/source/tileimage.js @@ -194,7 +194,7 @@ ol.source.TileImage.prototype.getTileCacheForProjection = function(projection) { } else { var projKey = ol.getUid(projection).toString(); if (!(projKey in this.tileCacheForProjection)) { - this.tileCacheForProjection[projKey] = new ol.TileCache(); + this.tileCacheForProjection[projKey] = new ol.TileCache(this.tileCache.highWaterMark); } return this.tileCacheForProjection[projKey]; } diff --git a/src/ol/tilecache.js b/src/ol/tilecache.js index 5402e3b6c4..35c7fa42da 100644 --- a/src/ol/tilecache.js +++ b/src/ol/tilecache.js @@ -15,10 +15,9 @@ ol.TileCache = function(opt_highWaterMark) { ol.structs.LRUCache.call(this); /** - * @private * @type {number} */ - this.highWaterMark_ = opt_highWaterMark !== undefined ? opt_highWaterMark : 2048; + this.highWaterMark = opt_highWaterMark !== undefined ? opt_highWaterMark : 2048; }; ol.inherits(ol.TileCache, ol.structs.LRUCache); @@ -28,7 +27,7 @@ ol.inherits(ol.TileCache, ol.structs.LRUCache); * @return {boolean} Can expire cache. */ ol.TileCache.prototype.canExpireCache = function() { - return this.getCount() > this.highWaterMark_; + return this.getCount() > this.highWaterMark; }; diff --git a/test/spec/ol/source/tile.test.js b/test/spec/ol/source/tile.test.js index 0eaa0d6fd9..36fb5db22a 100644 --- a/test/spec/ol/source/tile.test.js +++ b/test/spec/ol/source/tile.test.js @@ -20,6 +20,14 @@ describe('ol.source.Tile', function() { expect(source).to.be.a(ol.source.Source); expect(source).to.be.a(ol.source.Tile); }); + it('sets a custom cache size', function() { + var projection = ol.proj.get('EPSG:4326'); + var source = new ol.source.Tile({ + projection: projection, + cacheSize: 42 + }); + expect(source.getTileCacheForProjection(projection).highWaterMark).to.be(42); + }); }); describe('#setKey()', function() { diff --git a/test/spec/ol/source/tileimage.test.js b/test/spec/ol/source/tileimage.test.js index 9f19ee045b..183dc8bd58 100644 --- a/test/spec/ol/source/tileimage.test.js +++ b/test/spec/ol/source/tileimage.test.js @@ -12,9 +12,10 @@ goog.require('ol.tilegrid'); describe('ol.source.TileImage', function() { - function createSource(opt_proj, opt_tileGrid) { + function createSource(opt_proj, opt_tileGrid, opt_cacheSize) { var proj = opt_proj || 'EPSG:3857'; return new ol.source.TileImage({ + cacheSize: opt_cacheSize, projection: proj, tileGrid: opt_tileGrid || ol.tilegrid.createForProjection(proj, undefined, [2, 2]), @@ -23,6 +24,15 @@ describe('ol.source.TileImage', function() { }); } + describe('#getTileCacheForProjection', function() { + it('uses the cacheSize for reprojected tile caches', function() { + var source = createSource(undefined, undefined, 42); + var tileCache = source.getTileCacheForProjection(ol.proj.get('EPSG:4326')); + expect(tileCache.highWaterMark).to.be(42); + expect(tileCache).to.not.equal(source.getTileCacheForProjection(source.getProjection())); + }); + }); + describe('#setTileGridForProjection', function() { it('uses the tilegrid for given projection', function() { var source = createSource();