UNPKG

@allmaps/render

Version:

Render functions for WebGL and image buffers

109 lines (107 loc) 3.61 kB
import { CacheableTile, CachedTile } from './CacheableTile.js'; import { FetchableTile } from './FetchableTile.js'; import { FetchFn } from '@allmaps/types'; import { CachableTileFactory, TileCacheOptions, MapPruneInfo } from '../shared/types.js'; /** * Class that fetches and caches IIIF tiles. */ export declare class TileCache<D> extends EventTarget { cachableTileFactory: CachableTileFactory<D>; fetchFn?: FetchFn; protected tilesByTileUrl: Map<string, CacheableTile<D>>; protected mapIdsByTileUrl: Map<string, Set<string>>; protected tileUrlsByMapId: Map<string, Set<string>>; protected tilesFetchingCount: number; protected fetchableTiles: FetchableTile[]; constructor(cachableTileFactory: CachableTileFactory<D>, partialTileCacheOptions?: Partial<TileCacheOptions>); /** * Get the tiles in this cache * * @returns */ getCacheableTiles(): IterableIterator<CacheableTile<D>>; /** * Get a specific tile in this cache * * @param tileUrl - the URL of the requested tile * @returns */ getCacheableTile(tileUrl: string): CacheableTile<D> | undefined; /** * Get the tiles in this cache, corresponding to a specific map * * @param mapId - ID of the map * @returns */ getMapCacheableTiles(mapId: string): CacheableTile<D>[]; /** * Get the tiles in this cache that have been fetched * * @returns */ getCachedTiles(): CachedTile<D>[]; /** * Get a specific cached tile in this cache that has been fetched * * @param tileUrl - the URL of the requested tile * @returns */ getCachedTile(tileUrl: string): CachedTile<D> | undefined; /** * Get the tiles in this cache, corresponding to a specific map, that have been fetched * * @param mapId - ID of the map * @returns */ getMapCachedTiles(mapId: string): CachedTile<D>[]; /** * Get the URLs of tiles in this cache * * @returns */ getTileUrls(): IterableIterator<string>; /** * Get the URLs of tiles in this cache, corresponding to a specific map * * @param mapId - ID of the map * @returns */ getMapTileUrls(mapId: string): Set<string>; /** * Get the Tile Cache options * * @param partialTileCacheOptions - Options */ setOptions(partialTileCacheOptions?: Partial<TileCacheOptions>): void; /** * Process the request for new tiles to be added to this cache * * @param fetchableTiles */ requestFetchableTiles(fetchableTiles: FetchableTile[]): void; /** * Returns a promise that resolves when all requested tiles are loaded. * This could happen immidiately, in case there are no ongoing requests and the tilesFetchingCount is zero, * or in a while, when the count reaches zero and the ALLREQUESTEDTILESLOADED event is fired. */ allRequestedTilesLoaded(): Promise<void>; /** * Prune tiles in this cache using the provided prune info */ prune(pruneInfoByMapId: Map<string, MapPruneInfo>): void; clear(): void; destroy(): void; private requestFetchableTile; private addCacheableTile; private removeCacheableTileForMapId; private tileFetched; private tileFetchError; private addMapIdForTileUrl; private removeMapIdForTileUrl; private addTileUrlForMapId; private removeTileUrlForMapId; get finished(): boolean; private updateTilesFetchingCount; private addEventListenersToCacheableTile; private removeEventListenersFromCacheableTile; }