UNPKG

@allmaps/render

Version:

Render functions for WebGL and image buffers

113 lines (111 loc) 4.3 kB
import { CacheableTile, CachedTile } from './CacheableTile.js'; import { FetchableTile } from './FetchableTile.js'; import { FetchFn } from '@allmaps/types'; import { CacheableTileFactory, TileCacheOptions, MapPruneInfo } from '../shared/types.js'; /** * Class that fetches and caches IIIF tiles. */ export declare class TileCache<D> extends EventTarget { cacheableTileFactory: CacheableTileFactory<D>; fetchFn?: FetchFn; tileCacheForTilesFromSprites?: TileCache<D>; 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(cacheableTileFactory: CacheableTileFactory<D>, partialTileCacheOptions?: Partial<TileCacheOptions<D>>); /** * 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<D>>): 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; protected requestFetchableTile(fetchableTile: FetchableTile): void; protected addCacheableTile(cacheableTile: CacheableTile<D>): void; addCachedTile(cachedTile: CachedTile<D>): void; protected removeCacheableTileForMapId(tileUrl: string, mapId: string): void; protected tileFetched(event: Event): void; protected tileFetchError(event: Event): void; protected tilesFromSpriteTile(event: Event): void; protected passTilesFromSprites(tileUrl?: string): void; protected addMapIdForTileUrl(mapId: string, tileUrl: string): Set<string>; protected removeMapIdForTileUrl(mapId: string, tileUrl: string): Set<unknown>; protected addTileUrlForMapId(tileUrl: string, mapId: string): Set<string>; protected removeTileUrlForMapId(tileUrl: string, mapId: string): Set<unknown>; get finished(): boolean; protected updateTilesFetchingCount(delta: number): void; protected addEventListenersToCacheableTile(cacheableTile: CacheableTile<D>): void; protected removeEventListenersFromCacheableTile(cacheableTile: CacheableTile<D>): void; }