Adjust tile cache size when too small

This commit is contained in:
ahocevar
2019-03-12 00:19:13 +01:00
parent c0d4cdbabf
commit 0f217392d7
12 changed files with 33 additions and 11 deletions

View File

@@ -7,6 +7,7 @@ import TileState from '../../TileState.js';
import {createEmpty, getIntersection, getTopLeft} from '../../extent.js'; import {createEmpty, getIntersection, getTopLeft} from '../../extent.js';
import CanvasLayerRenderer from './Layer.js'; import CanvasLayerRenderer from './Layer.js';
import {apply as applyTransform, compose as composeTransform, makeInverse, toString as transformToString} from '../../transform.js'; import {apply as applyTransform, compose as composeTransform, makeInverse, toString as transformToString} from '../../transform.js';
import {assign} from '../../obj.js';
/** /**
* @classdesc * @classdesc
@@ -304,6 +305,7 @@ class CanvasTileLayerRenderer extends CanvasLayerRenderer {
this.manageTilePyramid(frameState, tileSource, tileGrid, pixelRatio, this.manageTilePyramid(frameState, tileSource, tileGrid, pixelRatio,
projection, extent, z, tileLayer.getPreload()); projection, extent, z, tileLayer.getPreload());
this.updateCacheSize_(frameState, tileSource);
this.scheduleExpireCache(frameState, tileSource); this.scheduleExpireCache(frameState, tileSource);
this.postRender(context, frameState); this.postRender(context, frameState);
@@ -383,6 +385,26 @@ class CanvasTileLayerRenderer extends CanvasLayerRenderer {
return /** @type {import("../../ImageTile.js").default} */ (tile).getImage(); return /** @type {import("../../ImageTile.js").default} */ (tile).getImage();
} }
/**
* Check if the cache is big enough, and increase its size if necessary.
* @param {import("../../PluggableMap.js").FrameState} frameState Frame state.
* @param {import("../../source/Tile.js").default} tileSource Tile source.
* @private
*/
updateCacheSize_(frameState, tileSource) {
const tileSourceKey = getUid(tileSource);
const keys = assign({}, frameState.usedTiles[tileSourceKey]);
if (tileSourceKey in frameState.wantedTiles) {
assign(keys, frameState.wantedTiles[tileSourceKey]);
}
const size = Object.keys(keys).length;
const tileCache = tileSource.tileCache;
if (tileCache.highWaterMark < size) {
tileCache.highWaterMark = size;
}
}
/**
} }

View File

@@ -50,7 +50,7 @@ const TOS_ATTRIBUTION = '<a class="ol-attribution-bing-tos" ' +
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {number} [cacheSize] Tile cache size. Default is four times as many tiles as a fullscreen map needs. * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small.
* @property {boolean} [hidpi=false] If `true` hidpi tiles will be requested. * @property {boolean} [hidpi=false] If `true` hidpi tiles will be requested.
* @property {string} [culture='en-us'] Culture code. * @property {string} [culture='en-us'] Culture code.
* @property {string} key Bing Maps API key. Get yours at http://www.bingmapsportal.com/. * @property {string} key Bing Maps API key. Get yours at http://www.bingmapsportal.com/.

View File

@@ -9,7 +9,7 @@ import XYZ from './XYZ.js';
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions. * @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {number} [cacheSize] Tile cache size. Default is four times as many tiles as a fullscreen map needs. * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small.
* @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * @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. * 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. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail.

View File

@@ -20,7 +20,7 @@ export const ATTRIBUTION = '&#169; ' +
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions. * @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {number} [cacheSize] Tile cache size. Default is four times as many tiles as a fullscreen map needs. * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small.
* @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * @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. * 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. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail.

View File

@@ -90,7 +90,7 @@ const ProviderConfig = {
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {number} [cacheSize] Tile cache size. Default is four times as many tiles as a fullscreen map needs. * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small.
* @property {string} layer Layer name. * @property {string} layer Layer name.
* @property {number} [minZoom] Minimum zoom. * @property {number} [minZoom] Minimum zoom.
* @property {number} [maxZoom] Maximum zoom. * @property {number} [maxZoom] Maximum zoom.

View File

@@ -13,7 +13,7 @@ import {appendParams} from '../uri.js';
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions. * @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {number} [cacheSize] Tile cache size. Default is four times as many tiles as a fullscreen map needs. * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small.
* @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * @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. * 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. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail.

View File

@@ -18,7 +18,7 @@ import {getForProjection as getTileGridForProjection} from '../tilegrid.js';
* @typedef {Object} Options * @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions. * @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {boolean} [attributionsCollapsible=true] Attributions are collapsible. * @property {boolean} [attributionsCollapsible=true] Attributions are collapsible.
* @property {number} [cacheSize] Tile cache size. Default is four times as many tiles as a fullscreen map needs. * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small.
* @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * @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. * 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. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail.

View File

@@ -39,7 +39,7 @@ import {createXYZ, extentFromProjection} from '../tilegrid.js';
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions. * @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {number} [cacheSize] Tile cache size. Default is four times as many tiles as a fullscreen map needs. * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small.
* @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * @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. * 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. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail.

View File

@@ -20,7 +20,7 @@ import {appendParams} from '../uri.js';
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions. * @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {number} [cacheSize] Tile cache size. Default is four times as many tiles as a fullscreen map needs. * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small.
* @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * @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. * 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. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail.

View File

@@ -15,7 +15,7 @@ import {appendParams} from '../uri.js';
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions. * @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {number} [cacheSize] Tile cache size. Default is four times as many tiles as a fullscreen map needs. * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small.
* @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * @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. * 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. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail.

View File

@@ -9,7 +9,7 @@ import {createXYZ, extentFromProjection} from '../tilegrid.js';
* @typedef {Object} Options * @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions. * @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {boolean} [attributionsCollapsible=true] Attributions are collapsible. * @property {boolean} [attributionsCollapsible=true] Attributions are collapsible.
* @property {number} [cacheSize] Tile cache size. Default is four times as many tiles as a fullscreen map needs. * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small.
* @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * @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. * 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. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail.

View File

@@ -82,7 +82,7 @@ export class CustomTile extends ImageTile {
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions. * @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {number} [cacheSize] Tile cache size. Default is four times as many tiles as a fullscreen map needs. * @property {number} [cacheSize] Tile cache size. The default depends on the screen size. Will increase if too small.
* @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * @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. * 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. * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail.