UNPKG

@allmaps/render

Version:

Render functions for WebGL and image buffers

282 lines (280 loc) 11.9 kB
import { Image } from '@allmaps/iiif-parser'; import { RTree } from './RTree.js'; import { WarpedMap } from './WarpedMap.js'; import { Ring, Bbox, Point } from '@allmaps/types'; import { GetWarpedMapOptions, ProjectionOptions, SelectionOptions, AnimationOptions, WarpedMapFactory, WarpedMapListOptions } from '../shared/types.js'; /** * An ordered list of WarpedMaps. This class contains an optional RTree * for quickly looking up maps using their Bbox * @template W - The type of WarpedMap objects in this list */ export declare class WarpedMapList<W extends WarpedMap> extends EventTarget { warpedMapFactory: WarpedMapFactory<W>; /** * Maps in this list, indexed by their ID */ warpedMapsById: Map<string, W>; zIndices: Map<string, number>; imagesById: Map<string, Image>; rtree?: RTree; options: WarpedMapListOptions; /** * Creates an instance of a WarpedMapList * * @constructor * @param warpedMapFactory - Factory function for creating WarpedMap objects * @param options - Options of this list, which will be set on newly added maps as their list options */ constructor(warpedMapFactory: WarpedMapFactory<W>, options?: Partial<WarpedMapListOptions>); /** * Adds a georeferenced map to this list * * @param georeferencedMap - Georeferenced Map * @param mapOptions - Map options * @returns Map ID of the map that was added */ addGeoreferencedMap(georeferencedMap: unknown, mapOptions?: Partial<GetWarpedMapOptions<W>>): Promise<string>; /** * Removes a georeferenced map from this list * * @param georeferencedMap * @returns Map ID of the removed map, or an error */ removeGeoreferencedMap(georeferencedMap: unknown): Promise<string | Error>; /** * Removes a georeferenced map from the list by its ID * * @param mapId - Map ID * @returns Map ID of the removed map, or an error */ removeGeoreferencedMapById(mapId: string): Promise<string | Error | undefined>; /** * Parses an annotation and adds its georeferenced map to this list * * @param annotation - Annotation * @param mapOptions - Map options * @returns Map IDs of the maps that were added, or an error per map */ addGeoreferenceAnnotation(annotation: unknown, mapOptions?: Partial<GetWarpedMapOptions<W>>): Promise<(string | Error)[]>; /** * Parses an annotation and removes its georeferenced map from this list * * @param annotation * @returns Map IDs of the maps that were removed, or an error per map */ removeGeoreferenceAnnotation(annotation: unknown): Promise<(string | Error)[]>; /** * Adds image informations, parses them to images and adds them to the image cache * * @param imageInfos - Image informations * @returns Image IDs of the image informations that were added */ addImageInfos(imageInfos: unknown[]): string[]; /** * Get mapIds for selected maps * * The selectionOptions allow a.o. to: * - filter for visible maps * - filter for specific mapIds * - filter for maps whose geoBbox overlap with the specified geoBbox * - filter for maps that overlap with a given geoPoint * * @param partialSelectionOptions - Selection options (e.g. mapIds), defaults to all visible maps * @returns mapIds */ getMapIds(partialSelectionOptions?: Partial<SelectionOptions>): string[]; /** * Get the WarpedMap instances for selected maps * * The selectionOptions allow a.o. to: * - filter for visible maps * - filter for specific mapIds * - filter for maps whose geoBbox overlap with the specified geoBbox * - filter for maps that overlap with a given geoPoint * * @param partialSelectionOptions - Selection options (e.g. mapIds), defaults to all visible maps * @returns WarpedMap instances */ getWarpedMaps(partialSelectionOptions?: Partial<SelectionOptions>): Iterable<W>; /** * Get the WarpedMap instance for a map * * @param mapId - Map ID of the requested WarpedMap instance * @returns WarpedMap instance, or undefined */ getWarpedMap(mapId: string): W | undefined; /** * Get the center of the bounding box of the maps in this list * * The result is returned in the list's projection, `EPSG:3857` by default * Use `{ projection: { definition: 'EPSG:4326' } }` to request the result in lon-lat `EPSG:4326` * * @param partialSelectionAndProjectionOptions - Selection (e.g. mapIds) and projection options, defaults to all visible maps and current projection * @returns The center of the bbox of all selected maps, in the chosen projection, or undefined if there were no maps matching the selection. */ getMapsCenter(partialSelectionAndProjectionOptions?: Partial<SelectionOptions & ProjectionOptions>): Point | undefined; /** * Get the bounding box of the maps in this list * * The result is returned in the list's projection, `EPSG:3857` by default * Use `{ projection: { definition: 'EPSG:4326' } }` to request the result in lon-lat `EPSG:4326` * * @param partialSelectionAndProjectionOptions - Selection (e.g. mapIds) and projection options, defaults to all visible maps and current projection * @returns The bbox of all selected maps, in the chosen projection, or undefined if there were no maps matching the selection. */ getMapsBbox(partialSelectionAndProjectionOptions?: Partial<SelectionOptions & ProjectionOptions>): Bbox | undefined; /** * Get the convex hull of the maps in this list * * The result is returned in the list's projection, `EPSG:3857` by default * Use `{ projection: { definition: 'EPSG:4326' } }` to request the result in lon-lat `EPSG:4326` * * @param partialSelectionAndProjectionOptions - Selection (e.g. mapIds) and projection options, defaults to all visible maps and current projection * @returns The convex hull of all selected maps, in the chosen projection, or undefined if there were no maps matching the selection. */ getMapsConvexHull(partialSelectionAndProjectionOptions?: Partial<SelectionOptions & ProjectionOptions>): Ring | undefined; /** * Get the z-index of a map * * @param mapId - Map ID for which to get the z-index */ getMapZIndex(mapId: string): number | undefined; /** * Get the default options of the list */ getDefaultOptions(): WarpedMapListOptions & GetWarpedMapOptions<W>; /** * Get the default options of a map * * These come from the default option settings for WebGL2WarpedMaps and the map's georeferenced map proporties * * @param mapId - Map ID for which the options apply */ getMapDefaultOptions(mapId: string): GetWarpedMapOptions<W> | undefined; /** * Get the options of this list */ getOptions(): Partial<WarpedMapListOptions>; /** * Get the map-specific options of a map * * @param mapId - Map ID for which the options apply */ getMapMapOptions(mapId: string): Partial<GetWarpedMapOptions<W>> | undefined; /** * Get the options of a map * * These options are the result of merging the default, georeferenced map, * layer and map-specific options of that map. * * @param mapId - Map ID for which the options apply */ getMapOptions(mapId: string): GetWarpedMapOptions<W> | undefined; /** * Set the options of this list * * Note: Map-specific options set here will be passed to newly added maps. * * @param options - List Options * @param animationOptions - Animation options */ setOptions(options?: Partial<WarpedMapListOptions>, animationOptions?: Partial<AnimationOptions>): void; /** * Set the map-specific options of maps (and the list options) * * @param mapIds - Map IDs for which the options apply * @param mapOptions - Map-specific options * @param listOptions - list options * @param animationOptions - Animation options */ setMapsOptions(mapIds: string[], mapOptions?: Partial<WarpedMapListOptions>, listOptions?: Partial<WarpedMapListOptions>, animationOptions?: Partial<AnimationOptions>): void; /** * Set the map-specific options of maps by map ID (and the list options) * * This is useful when when multiple (and possibly different) * map-specific options are changed at once, * but only one animation should be fired * * @param mapOptionsByMapId - Map-specific options by map ID * @param listOptions - List options * @param animationOptions - Animation options */ setMapsOptionsByMapId(mapOptionsByMapId?: Map<string, Partial<WarpedMapListOptions>>, listOptions?: Partial<WarpedMapListOptions>, animationOptions?: Partial<AnimationOptions>): void; /** * Resets the list options * * An empty array resets all options, undefined resets no options. * * @param listOptionKeys - Keys of the list options to reset * @param animationOptions - Animation options */ resetOptions(listOptionKeys?: string[], animationOptions?: Partial<AnimationOptions>): void; /** * Resets the map-specific options of maps (and the list options) * * An empty array resets all options, undefined resets no options. * * @param mapIds - Map IDs for which to reset the options * @param mapOptionKeys - Keys of the map-specific options to reset * @param listOptionKeys - Keys of the list options to reset * @param animationOptions - Animation options */ resetMapsOptions(mapIds: string[], mapOptionKeys?: string[], listOptionKeys?: string[], animationOptions?: Partial<AnimationOptions>): void; /** * Resets the map-specific options of maps by map ID (and the list options) * * An empty array or map resets all options (for all maps), undefined resets no options. * * @param mapOptionkeysByMapId - Keys of map-specific options to reset by map ID * @param listOptionKeys - Keys of the list options to reset * @param animationOptions - Animation options */ resetMapsOptionsByMapId(mapOptionkeysByMapId?: Map<string, string[]>, listOptionKeys?: string[], animationOptions?: Partial<AnimationOptions>): void; /** * Changes the z-index of the specified maps to bring them to front * * @param mapIds - Map IDs */ bringMapsToFront(mapIds: Iterable<string>): void; /** * Changes the z-index of the specified maps to send them to back * * @param mapIds - Map IDs */ sendMapsToBack(mapIds: Iterable<string>): void; /** * Changes the z-index of the specified maps to bring them forward * * @param mapIds - Map IDs */ bringMapsForward(mapIds: Iterable<string>): void; /** * Changes the zIndex of the specified maps to send them backward * * @param mapIds - Map IDs */ sendMapsBackward(mapIds: Iterable<string>): void; /** * Order mapIds * * Use this as anonymous sort function in Array.prototype.sort() */ orderMapIdsByZIndex(mapId0: string, mapId1: string): number; clear(): void; destroy(): void; private addGeoreferencedMapInternal; private removeGeoreferencedMapInternal; private removeGeoreferencedMapByIdInternal; private getOrComputeMapId; private getProjectedGeoMaskPoints; /** * Internal set map options */ private internalSetMapsOptionsByMapId; private addToOrUpdateRtree; private removeFromRtree; private removeZIndexHoles; private imageLoaded; private addEventListenersToWarpedMap; private removeEventListenersFromWarpedMap; }