UNPKG

@allmaps/render

Version:

Render functions for WebGL and image buffers

352 lines (350 loc) 17.2 kB
import { GeoreferencedMap } from '@allmaps/annotation'; import { Image } from '@allmaps/iiif-parser'; import { ProjectedGcpTransformer, ProjectedGcpTransformerOptions, Projection } from '@allmaps/project'; import { Gcp, Point, Ring, Rectangle, Bbox, TileZoomLevel, Size } from '@allmaps/types'; import { TransformationType, DistortionMeasure } from '@allmaps/transform'; import { AnimationOptions, AnimationOptionsInternal, WarpedMapListOptions, WarpedMapOptions } from '../shared/types.js'; import { Viewport } from '../viewport/Viewport.js'; import { FetchableTile } from '../tilecache/FetchableTile.js'; export declare const UNDEFINED_GEOREFERENCED_MAP_OPTIONS: { transformationType: undefined; internalProjection: undefined; }; export declare const DEFAULT_WARPED_MAP_OPTIONS: { gcps: never[]; resourceMask: never[]; transformationType: TransformationType; internalProjection: Projection<string>; projection: Projection<string>; visible: boolean; applyMask: boolean; distortionMeasure: undefined; }; export declare function createWarpedMapFactory(): (mapId: string, georeferencedMap: GeoreferencedMap, listOptions?: Partial<WarpedMapListOptions>, mapOptions?: Partial<WarpedMapOptions>) => WarpedMap; /** * Class for warped maps. * This class describes how a georeferenced map is warped using a specific transformation. * * @param mapId - ID of the map * @param georeferencedMap - Georeferenced map used to construct the WarpedMap * @param defaultOptions - Default options * @param georeferencedMapOptions - Options from georeferenced map * @param listOptions - Options from warped map list * @param mapOptions - Options specific to this map * @param options - Result of merging default, georeferenced map, list and specific map options * @param fetchingImageInfo - Whether the image information is loading * @param image - Parsed IIIF image * @param tileSize - Size of the tiles * @param mixed - Wether the options were last set by mixing previous and new properties, i.e. when rerendering during an ongoing animation * @param gcps - Ground control points used for warping this map, from resource coordinates to geospatial coordinates * @param projectedGcps - Projected ground control points, from resource coordinates to projected geospatial coordinates * @param resourcePoints - The resource coordinates of the ground control points * @param geoPoints - The geospatial coordinates of the ground control points * @param projectedGeoPoints - The projected geospatial coordinates of the projected ground control points * @param projectedGeoPreviousTransformedResourcePoints - The projectedGeoTransformedResourcePoints of the previous transformation type, used during transformation transitions * @param projectedGeoTransformedResourcePoints - The resource coordinates of the ground control points, transformed to projected geospatial coordinates using the projected transformer * @param resourceFullMask - Resource full mask (describing the entire extent of the image) * @param resourceFullMaskBbox - Bbox of the resource full mask * @param resourceFullMaskRectangle - Rectangle of the resource full mask bbox * @param resourceAppliableMask - Resource appliable mask. In case 'applyMask' is true, the resourceMask and the resourceAppliableMask are the same. In case 'applyMask' is false, the resourceMask is set to the resourceFullMask, but first a copy of the resourceMask is kept as the resourceAppliableMask. * @param resourceAppliableMaskBbox - Bbox of the resourceAppliableMask * @param resourceAppliableMaskRectangle - Rectangle of the resourceAppliableMaskBbox * @param resourceMask - Resource mask * @param resourceMaskBbox - Bbox of the resourceMask * @param resourceMaskRectangle - Rectangle of the resourceMaskBbox * @param previousTransformationType - Previous transformation type * @param transformationType - Transformation type used in the transfomer. This is loaded from the georeference annotation. * @param previousInternalProjection - Previous internal projection * @param internalProjection - Internal projection used in the projected transformer * @param projection - Projection of the projected geospatial coordinates space * @param projectedPreviousTransformer - Previous transformer used for warping this map from resource coordinates to projected geospatial coordinates * @param projectedTransformer - Transformer used for warping this map from resource coordinates to projected geospatial coordinates * @param geoFullMask - resourceAppliableMask in geospatial coordinates * @param geoFullMaskBbox - Bbox of the geoFullMask * @param geoFullMaskRectangle - resourceFullMaskRectangle in geospatial coordinates * @param geoAppliableMask - resourceAppliableMask in geospatial coordinates * @param geoAppliableMaskBbox - Bbox of the geoFullMask * @param geoAppliableMaskRectangle - resourceAppliableMaskRectangle in geospatial coordinates * @param geoMask - resourceMask in geospatial coordinates * @param geoMaskBbox - Bbox of the geoMask * @param geoMaskRectangle - resourceMaskRectangle in geospatial coordinates * @param projectedGeoFullMask - resourceFullMask in projected geospatial coordinates * @param projectedGeoFullMaskBbox - Bbox of the projectedGeoFullMask * @param projectedGeoFullMaskRectangle - resourceFullMaskRectangle in projected geospatial coordinates * @param projectedGeoAppliableMask - resourceAppliableMask in projected geospatial coordinates * @param projectedGeoAppliableMaskBbox - Bbox of the projectedGeoAppliableMask * @param projectedGeoAppliableMaskRectangle - resourceAppliableMaskRectangle in projected geospatial coordinates * @param projectedGeoMask - resourceMask in projected geospatial coordinates * @param projectedGeoMaskBbox - Bbox of the projectedGeoMask * @param projectedGeoMaskRectangle - resourceMaskRectanglee in projected geospatial coordinates * @param resourceToProjectedGeoScale - Scale of the warped map, in resource pixels per projected geospatial coordinates * @param previousDistortionMeasure - Previous distortion measure displayed for this map * @param distortionMeasure - Distortion measure displayed for this map * @param tileZoomLevelForViewport - The tile zoom level, for the current viewport * @param overviewTileZoomLevelForViewport - The overview tile zoom level, for the current viewport * @param projectedGeoBufferedViewportRectangleForViewport - The (buffered) viewport in projected geospatial coordinates, for the current viewport * @param projectedGeoBufferedViewportRectangleBboxForViewport - Bbox of the projectedGeoBufferedViewportRectangle * @param resourceBufferedViewportRingForViewport - The (buffered) viewport transformed back to resource coordinates, for the current viewport * @param resourceBufferedViewportRingBboxForViewport - Bbox of the resourceViewportRing * @param resourceBufferedViewportRingBboxAndResourceMaskBboxIntersectionForViewport - The intersection of the bbox of the (buffered) viewport transformed back to resource coordinates and the bbox of the resource mask, for the current viewport * @param fetchableTilesForViewport - The fetchable tiles for displaying this map, for the current viewport * @param overviewFetchableTilesForViewport - The overview fetchable tiles, for the current viewport */ export declare class WarpedMap extends EventTarget { mapId: string; georeferencedMap: GeoreferencedMap; defaultOptions: WarpedMapOptions; georeferencedMapOptions: Partial<WarpedMapOptions>; listOptions: Partial<WarpedMapListOptions>; mapOptions: Partial<WarpedMapOptions>; options: WarpedMapOptions; fetchingImageInfo: boolean; image?: Image; tileSize?: Size; protected abortController?: AbortController; mixed: boolean; gcps: Gcp[]; projectedGcps: Gcp[]; resourcePoints: Point[]; geoPoints: Point[]; projectedGeoPoints: Point[]; projectedGeoPreviousTransformedResourcePoints: Point[]; projectedGeoTransformedResourcePoints: Point[]; resourceFullMask: Ring; resourceFullMaskBbox: Bbox; resourceFullMaskRectangle: Rectangle; resourceAppliableMask: Ring; resourceAppliableMaskBbox: Bbox; resourceAppliableMaskRectangle: Rectangle; resourceMask: Ring; resourceMaskBbox: Bbox; resourceMaskRectangle: Rectangle; previousTransformationType: TransformationType; transformationType: TransformationType; previousInternalProjection: Projection; internalProjection: Projection; projection: Projection; projectedPreviousTransformer: ProjectedGcpTransformer; projectedTransformer: ProjectedGcpTransformer; protected projectedTransformerCache: Map<TransformationType, ProjectedGcpTransformer>; protected projectedTransformerDoubleCache: Map<TransformationType, Map<string, ProjectedGcpTransformer>>; geoFullMask: Ring; geoFullMaskBbox: Bbox; geoFullMaskRectangle: Rectangle; geoAppliableMask: Ring; geoAppliableMaskBbox: Bbox; geoAppliableMaskRectangle: Rectangle; geoMask: Ring; geoMaskBbox: Bbox; geoMaskRectangle: Rectangle; projectedGeoFullMask: Ring; projectedGeoFullMaskBbox: Bbox; projectedGeoFullMaskRectangle: Rectangle; projectedGeoAppliableMask: Ring; projectedGeoAppliableMaskBbox: Bbox; projectedGeoAppliableMaskRectangle: Rectangle; projectedGeoMask: Ring; projectedGeoMaskBbox: Bbox; projectedGeoMaskRectangle: Rectangle; resourceToProjectedGeoScale: number; previousDistortionMeasure?: DistortionMeasure; distortionMeasure?: DistortionMeasure; tileZoomLevelForViewport?: TileZoomLevel; overviewTileZoomLevelForViewport?: TileZoomLevel; projectedGeoBufferedViewportRectangleForViewport?: Rectangle; projectedGeoBufferedViewportRectangleBboxForViewport?: Bbox; resourceBufferedViewportRingForViewport?: Ring; resourceBufferedViewportRingBboxForViewport?: Bbox; resourceBufferedViewportRingBboxAndResourceMaskBboxIntersectionForViewport?: Bbox; fetchableTilesForViewport: FetchableTile[]; overviewFetchableTilesForViewport: FetchableTile[]; /** * Creates an instance of WarpedMap. * * @param mapId - ID of the map * @param georeferencedMap - Georeferenced map used to construct the WarpedMap * @param options - options */ constructor(mapId: string, georeferencedMap: GeoreferencedMap, listOptions?: Partial<WarpedMapListOptions>, mapOptions?: Partial<WarpedMapOptions>); /** * Get default options */ static getDefaultOptions(): WarpedMapOptions; /** * Get default and georeferenced map options */ getDefaultAndGeoreferencedMapOptions(): WarpedMapOptions; /** * Get scale of the warped map, in resource pixels per viewport pixels. * * @param viewport - the current viewport * @returns */ getResourceToViewportScale(viewport: Viewport): number; /** * Get scale of the warped map, in resource pixels per canvas pixels. * * @param viewport - the current viewport * @returns */ getResourceToCanvasScale(viewport: Viewport): number; /** * Get the reference scaling from the forward transformation of the projected Helmert transformer * * @returns */ getReferenceScale(): number; /** * Get a projected transformer of the given transformation type. * * Uses cashed projected transformers by transformation type, * and only computes a new projected transformer if none found. * * Returns a projected transformer in the current projection, * even if the cached transformer was computed in a different projection. * * Default settings apply for the options. * * @params transformationType - the transformation type * @params partialProjectedGcpTransformerOptions - options * @params useCache - whether to use the cached projected transformers previously computed * @returns A projected transformer */ getProjectedTransformer(transformationType: TransformationType, partialProjectedGcpTransformerOptions?: Partial<ProjectedGcpTransformerOptions>): ProjectedGcpTransformer; setMapOptions(mapOptions?: Partial<WarpedMapOptions>, listOptions?: Partial<WarpedMapOptions>, animationOptions?: Partial<AnimationOptions & AnimationOptionsInternal>): object; setListOptions(listOptions?: Partial<WarpedMapOptions>, animationOptions?: Partial<AnimationOptions>): object; setDefaultOptions(): void; protected applyOptions(animationOptions?: Partial<AnimationOptions & AnimationOptionsInternal>): object; shouldRenderMap(): boolean; shouldRenderLines(): boolean; shouldRenderPoints(): boolean; /** * Update the ground control points loaded from a georeferenced map to new ground control points. * * @param gcps */ protected setGcps(gcps: Gcp[]): void; /** * Update the resource mask loaded from a georeferenced map to a new mask. * * @param resourceMask */ protected setResourceMask(resourceFullMask: Ring, resourceAppliableMask: Ring, resourceMask: Ring): void; /** * Set the transformationType * * @param transformationType */ protected setTransformationType(transformationType: TransformationType): void; /** * Set the distortionMeasure * * @param distortionMeasure - the disortion measure */ protected setDistortionMeasure(distortionMeasure?: DistortionMeasure): void; /** * Set the internal projection * * @param projection - the internal projection */ protected setInternalProjection(projection?: Projection): void; /** * Set the projection * * @param projection - the projection */ protected setProjection(projection?: Projection): void; /** * Set the tile zoom level for the current viewport * * @param tileZoomLevel - tile zoom level for the current viewport */ setTileZoomLevelForViewport(tileZoomLevel?: TileZoomLevel): void; /** * Set the overview tile zoom level for the current viewport * * @param tileZoomLevel - tile zoom level for the current viewport */ setOverviewTileZoomLevelForViewport(tileZoomLevel?: TileZoomLevel): void; /** * Set projectedGeoBufferedViewportRectangle for the current viewport * * @param projectedGeoBufferedViewportRectangle */ setProjectedGeoBufferedViewportRectangleForViewport(projectedGeoBufferedViewportRectangle?: Rectangle): void; /** * Set resourceBufferedViewportRing for the current viewport * * @param resourceBufferedViewportRing */ setResourceBufferedViewportRingForViewport(resourceBufferedViewportRing?: Ring): void; /** * Set resourceBufferedViewportRingBboxAndResourceMaskBboxIntersection for the current viewport * * @param resourceBufferedViewportRingBboxAndResourceMaskBboxIntersection */ setResourceBufferedViewportRingBboxAndResourceMaskBboxIntersectionForViewport(resourceBufferedViewportRingBboxAndResourceMaskBboxIntersection?: Bbox): void; /** * Set tiles for the current viewport * * @param fetchableTiles */ setFetchableTilesForViewport(fetchableTiles: FetchableTile[]): void; /** * Set overview tiles for the current viewport * * @param overviewFetchableTiles */ setOverviewFetchableTilesForViewport(overviewFetchableTiles: FetchableTile[]): void; /** * Reset the properties for the current values */ resetForViewport(): void; /** * Reset previous transform properties to new ones (when completing an animation). */ resetPrevious(): void; /** * Mix previous transform properties with new ones (when changing an ongoing animation). * * @param t - animation progress */ mixPreviousAndNew(t: number): void; /** * Check if this instance has parsed image * * @returns */ hasImage(): this is WarpedMapWithImage; /** * Load the parsed image from cache, or fetch and parse the image info to create it * * @returns */ loadImage(imagesById?: Map<string, Image>): Promise<void>; private updateResourceMaskProperties; private getResourceFullMask; private updateGeoMaskProperties; private updateProjectedGeoMaskProperties; protected updateProjectedTransformerProperties(): void; private updateProjectedTransformer; private updateFullGeoMask; private updateAppliableGeoMask; private updateGeoMask; private updateProjectedFullGeoMask; private updateProjectedAppliableGeoMask; private updateProjectedGeoMask; private updateResourceToProjectedGeoScale; private updateGcpsProperties; protected clearProjectedTransformerCaches(): void; destroy(): void; } /** * Class for warped maps with image ID and parsed IIIF image. */ export declare class WarpedMapWithImage extends WarpedMap { imageId: string; image: Image; tileSize: Size; constructor(mapId: string, georeferencedMap: GeoreferencedMap, options?: Partial<WarpedMapOptions>); }