From 18d96a220561ddb4c71fe9e110ebd02fa4961391 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Sat, 11 Jul 2020 20:32:54 +0200 Subject: [PATCH] Auto-grow tile cache from zero --- test/spec/ol/source/tile.test.js | 43 +++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/test/spec/ol/source/tile.test.js b/test/spec/ol/source/tile.test.js index 3c3f92f69c..435b891a24 100644 --- a/test/spec/ol/source/tile.test.js +++ b/test/spec/ol/source/tile.test.js @@ -1,9 +1,13 @@ +import Map from '../../../../src/ol/Map.js'; import Projection from '../../../../src/ol/proj/Projection.js'; import Source from '../../../../src/ol/source/Source.js'; import Tile from '../../../../src/ol/Tile.js'; +import TileDebugSource from '../../../../src/ol/source/TileDebug.js'; import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js'; +import TileLayer from '../../../../src/ol/layer/Tile.js'; import TileRange from '../../../../src/ol/TileRange.js'; import TileSource from '../../../../src/ol/source/Tile.js'; +import View from '../../../../src/ol/View.js'; import {getKeyZXY} from '../../../../src/ol/tilecoord.js'; import {get as getProjection} from '../../../../src/ol/proj.js'; @@ -53,23 +57,34 @@ describe('ol.source.Tile', function () { expect(source).to.be.a(Source); expect(source).to.be.a(TileSource); }); - it('sets a screen dependent cache size', function () { + it('sets 0 as initial cache size', function () { const source = new TileSource({}); - expect(source.tileCache.highWaterMark).to.be( - 4 * - Math.ceil(screen.availWidth / 256) * - Math.ceil(screen.availHeight / 256) - ); + expect(source.tileCache.highWaterMark).to.be(0); }); - it('ignores a cache size that is too small', function () { - const source = new TileSource({ - cacheSize: 1, + it('grows the cache', function () { + const source = new TileDebugSource(); + const layer = new TileLayer({ + source: source, }); - expect(source.tileCache.highWaterMark).to.be( - 4 * - Math.ceil(screen.availWidth / 256) * - Math.ceil(screen.availHeight / 256) - ); + const target = document.createElement('div'); + target.style.width = '100px'; + target.style.height = '100px'; + document.body.appendChild(target); + const map = new Map({ + layers: [layer], + view: new View({ + center: [0, 0], + zoom: 2, + }), + target: target, + }); + map.renderSync(); + expect( + source.getTileCacheForProjection(map.getView().getProjection()) + .highWaterMark + ).to.be(4); + map.setTarget(null); + document.body.removeChild(target); }); it('sets a custom cache size', function () { const projection = getProjection('EPSG:4326');