diff --git a/src/ol/TileCache.js b/src/ol/TileCache.js index 37f6113df7..57ad1ce3c0 100644 --- a/src/ol/TileCache.js +++ b/src/ol/TileCache.js @@ -7,7 +7,7 @@ import {fromKey, getKey} from './tilecoord.js'; class TileCache extends LRUCache { /** - * @param {!Object} usedTiles Used tiles. + * @param {!Object} usedTiles Used tiles. */ expireCache(usedTiles) { while (this.canExpireCache()) { diff --git a/src/ol/source/BingMaps.js b/src/ol/source/BingMaps.js index 8ddcdf50ec..b394cbd313 100644 --- a/src/ol/source/BingMaps.js +++ b/src/ol/source/BingMaps.js @@ -50,7 +50,7 @@ const TOS_ATTRIBUTION = '} usedTiles Used tiles. + * @param {!Object} usedTiles Used tiles. */ expireCache(projection, usedTiles) { const tileCache = this.getTileCacheForProjection(projection); diff --git a/src/ol/source/TileArcGISRest.js b/src/ol/source/TileArcGISRest.js index 5e81b927d6..cd347f3c5d 100644 --- a/src/ol/source/TileArcGISRest.js +++ b/src/ol/source/TileArcGISRest.js @@ -13,7 +13,7 @@ import {appendParams} from '../uri.js'; /** * @typedef {Object} Options * @property {import("./Source.js").AttributionLike} [attributions] Attributions. - * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small. + * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will be ignored if too small. * @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * you must provide a `crossOrigin` value if you want to access pixel data with the Canvas renderer. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail. diff --git a/src/ol/source/TileImage.js b/src/ol/source/TileImage.js index ac4ccf709e..7e32dd149b 100644 --- a/src/ol/source/TileImage.js +++ b/src/ol/source/TileImage.js @@ -17,7 +17,7 @@ import {getForProjection as getTileGridForProjection} from '../tilegrid.js'; * @typedef {Object} Options * @property {import("./Source.js").AttributionLike} [attributions] Attributions. * @property {boolean} [attributionsCollapsible=true] Attributions are collapsible. - * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small. + * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will be ignored if too small. * @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * you must provide a `crossOrigin` value if you want to access pixel data with the Canvas renderer. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail. diff --git a/src/ol/source/TileJSON.js b/src/ol/source/TileJSON.js index 6fe4877095..90887a2312 100644 --- a/src/ol/source/TileJSON.js +++ b/src/ol/source/TileJSON.js @@ -39,7 +39,7 @@ import {createXYZ, extentFromProjection} from '../tilegrid.js'; /** * @typedef {Object} Options * @property {import("./Source.js").AttributionLike} [attributions] Attributions. - * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small. + * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will be ignored if too small. * @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * you must provide a `crossOrigin` value if you want to access pixel data with the Canvas renderer. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail. diff --git a/src/ol/source/TileWMS.js b/src/ol/source/TileWMS.js index 513e7ae132..9ee929b63c 100644 --- a/src/ol/source/TileWMS.js +++ b/src/ol/source/TileWMS.js @@ -20,7 +20,7 @@ import {appendParams} from '../uri.js'; /** * @typedef {Object} Options * @property {import("./Source.js").AttributionLike} [attributions] Attributions. - * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small. + * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will be ignored if too small. * @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * you must provide a `crossOrigin` value if you want to access pixel data with the Canvas renderer. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail. diff --git a/src/ol/source/VectorTile.js b/src/ol/source/VectorTile.js index 737883fadb..42e4a1f4b9 100644 --- a/src/ol/source/VectorTile.js +++ b/src/ol/source/VectorTile.js @@ -227,6 +227,15 @@ class VectorTile extends UrlTile { this.sourceTileCache.clear(); } + /** + * @param {import("../proj/Projection.js").default} projection Projection. + * @param {!Object} usedTiles Used tiles. + */ + expireCache(projection, usedTiles) { + super.expireCache(projection, usedTiles); + this.sourceTileCache.expireCache({}); + } + /** * @param {number} pixelRatio Pixel ratio. * @param {import("../proj/Projection").default} projection Projection. @@ -328,7 +337,6 @@ class VectorTile extends UrlTile { tile.sourceTiles = sourceTiles; } } - this.sourceTileCache.expireCache({}); return sourceTiles; } diff --git a/src/ol/source/WMTS.js b/src/ol/source/WMTS.js index 603bc78e80..c8b11c9c32 100644 --- a/src/ol/source/WMTS.js +++ b/src/ol/source/WMTS.js @@ -15,7 +15,7 @@ import {appendParams} from '../uri.js'; /** * @typedef {Object} Options * @property {import("./Source.js").AttributionLike} [attributions] Attributions. - * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small. + * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will be ignored if too small. * @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * you must provide a `crossOrigin` value if you want to access pixel data with the Canvas renderer. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail. diff --git a/src/ol/source/XYZ.js b/src/ol/source/XYZ.js index 638bf5eb24..85b4ae595e 100644 --- a/src/ol/source/XYZ.js +++ b/src/ol/source/XYZ.js @@ -9,7 +9,7 @@ import {createXYZ, extentFromProjection} from '../tilegrid.js'; * @typedef {Object} Options * @property {import("./Source.js").AttributionLike} [attributions] Attributions. * @property {boolean} [attributionsCollapsible=true] Attributions are collapsible. - * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small. + * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will be ignored if too small. * @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * you must provide a `crossOrigin` value if you want to access pixel data with the Canvas renderer. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail. diff --git a/src/ol/source/Zoomify.js b/src/ol/source/Zoomify.js index 509a7e0ae2..23cb232203 100644 --- a/src/ol/source/Zoomify.js +++ b/src/ol/source/Zoomify.js @@ -80,7 +80,7 @@ export class CustomTile extends ImageTile { /** * @typedef {Object} Options * @property {import("./Source.js").AttributionLike} [attributions] Attributions. - * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small. + * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will be ignored if too small. * @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * you must provide a `crossOrigin` value you want to access pixel data with the Canvas renderer. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail. diff --git a/test/spec/ol/source/tile.test.js b/test/spec/ol/source/tile.test.js index f92cb9106b..d9db390d97 100644 --- a/test/spec/ol/source/tile.test.js +++ b/test/spec/ol/source/tile.test.js @@ -63,13 +63,19 @@ describe('ol.source.Tile', function() { const source = new TileSource({}); expect(source.tileCache.highWaterMark).to.be(4 * Math.ceil(screen.availWidth / 256) * Math.ceil(screen.availHeight / 256)); }); + it('ignores a cache size that is too small', function() { + const source = new TileSource({ + cacheSize: 1 + }); + expect(source.tileCache.highWaterMark).to.be(4 * Math.ceil(screen.availWidth / 256) * Math.ceil(screen.availHeight / 256)); + }); it('sets a custom cache size', function() { const projection = getProjection('EPSG:4326'); const source = new TileSource({ projection: projection, - cacheSize: 42 + cacheSize: 442 }); - expect(source.getTileCacheForProjection(projection).highWaterMark).to.be(42); + expect(source.getTileCacheForProjection(projection).highWaterMark).to.be(442); }); }); diff --git a/test/spec/ol/source/tileimage.test.js b/test/spec/ol/source/tileimage.test.js index cb9b85884c..b5a324ea0a 100644 --- a/test/spec/ol/source/tileimage.test.js +++ b/test/spec/ol/source/tileimage.test.js @@ -26,9 +26,9 @@ describe('ol.source.TileImage', function() { describe('#getTileCacheForProjection', function() { it('uses the cacheSize for reprojected tile caches', function() { - const source = createSource(undefined, undefined, 42); + const source = createSource(undefined, undefined, 442); const tileCache = source.getTileCacheForProjection(getProjection('EPSG:4326')); - expect(tileCache.highWaterMark).to.be(42); + expect(tileCache.highWaterMark).to.be(442); expect(tileCache).to.not.equal(source.getTileCacheForProjection(source.getProjection())); }); });