Make tile cache smaller and screen size dependant
This commit is contained in:
@@ -50,7 +50,7 @@ const TOS_ATTRIBUTION = '<a class="ol-attribution-bing-tos" ' +
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} Options
|
* @typedef {Object} Options
|
||||||
* @property {number} [cacheSize=2048] Cache size.
|
* @property {number} [cacheSize] Tile cache size. Default is twice as many tiles as a fullscreen map needs.
|
||||||
* @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/.
|
||||||
|
|||||||
@@ -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=2048] Cache size.
|
* @property {number} [cacheSize] Tile cache size. Default is twice as many tiles as a fullscreen map needs.
|
||||||
* @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.
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export const ATTRIBUTION = '© ' +
|
|||||||
/**
|
/**
|
||||||
* @typedef {Object} Options
|
* @typedef {Object} Options
|
||||||
* @property {import("./Source.js").AttributionLike} [attributions] Attributions.
|
* @property {import("./Source.js").AttributionLike} [attributions] Attributions.
|
||||||
* @property {number} [cacheSize=2048] Cache size.
|
* @property {number} [cacheSize] Tile cache size. Default is twice as many tiles as a fullscreen map needs.
|
||||||
* @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.
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ const ProviderConfig = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} Options
|
* @typedef {Object} Options
|
||||||
* @property {number} [cacheSize=2048] Cache size.
|
* @property {number} [cacheSize] Tile cache size. Default is twice as many tiles as a fullscreen map needs.
|
||||||
* @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.
|
||||||
|
|||||||
@@ -68,11 +68,23 @@ class TileSource extends Source {
|
|||||||
*/
|
*/
|
||||||
this.tileGrid = options.tileGrid !== undefined ? options.tileGrid : null;
|
this.tileGrid = options.tileGrid !== undefined ? options.tileGrid : null;
|
||||||
|
|
||||||
|
let cacheSize = options.cacheSize;
|
||||||
|
if (cacheSize === undefined) {
|
||||||
|
const tileSize = [256, 256];
|
||||||
|
const tileGrid = options.tileGrid;
|
||||||
|
if (tileGrid) {
|
||||||
|
toSize(tileGrid.getTileSize(tileGrid.getMinZoom()), tileSize);
|
||||||
|
}
|
||||||
|
const width = screen ? (screen.availWidth || screen.width) : 1920;
|
||||||
|
const height = screen ? (screen.availHeight || screen.height) : 1080;
|
||||||
|
cacheSize = 2 * Math.ceil(width / tileSize[0]) * Math.ceil(height / tileSize[1]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
* @type {import("../TileCache.js").default}
|
* @type {import("../TileCache.js").default}
|
||||||
*/
|
*/
|
||||||
this.tileCache = new TileCache(options.cacheSize);
|
this.tileCache = new TileCache(cacheSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
|
|||||||
@@ -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=2048] Cache size.
|
* @property {number} [cacheSize] Tile cache size. Default is twice as many tiles as a fullscreen map needs.
|
||||||
* @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.
|
||||||
|
|||||||
@@ -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=2048] Cache size.
|
* @property {number} [cacheSize] Tile cache size. Default is twice as many tiles as a fullscreen map needs.
|
||||||
* @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.
|
||||||
|
|||||||
@@ -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=2048] Cache size.
|
* @property {number} [cacheSize] Tile cache size. Default is twice as many tiles as a fullscreen map needs.
|
||||||
* @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.
|
||||||
|
|||||||
@@ -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=2048] Cache size.
|
* @property {number} [cacheSize] Tile cache size. Default is twice as many tiles as a fullscreen map needs.
|
||||||
* @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.
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class VectorTile extends UrlTile {
|
|||||||
|
|
||||||
super({
|
super({
|
||||||
attributions: options.attributions,
|
attributions: options.attributions,
|
||||||
cacheSize: options.cacheSize !== undefined ? options.cacheSize : 128,
|
cacheSize: options.cacheSize,
|
||||||
opaque: false,
|
opaque: false,
|
||||||
projection: projection,
|
projection: projection,
|
||||||
state: options.state,
|
state: options.state,
|
||||||
|
|||||||
@@ -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=2048] Cache size.
|
* @property {number} [cacheSize] Tile cache size. Default is twice as many tiles as a fullscreen map needs.
|
||||||
* @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.
|
||||||
|
|||||||
@@ -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=2048] Cache size.
|
* @property {number} [cacheSize] Tile cache size. Default is twice as many tiles as a fullscreen map needs.
|
||||||
* @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.
|
||||||
|
|||||||
@@ -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=2048] Cache size.
|
* @property {number} [cacheSize] Tile cache size. Default is twice as many tiles as a fullscreen map needs.
|
||||||
* @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.
|
||||||
|
|||||||
Reference in New Issue
Block a user