UNPKG

@allmaps/openlayers

Version:

OpenLayers classes for Allmaps

577 lines (575 loc) 27.5 kB
import { default as Layer } from 'ol/layer/Layer.js'; import { WebGL2Renderer, WebGL2RenderOptions, WebGL2WarpedMap, WebGL2WarpedMapOptions } from '@allmaps/render/webgl2'; import { BaseWarpedMapLayer } from '@allmaps/warpedmaplayer'; import { FrameState } from 'ol/Map.js'; import { Extent } from 'ol/extent'; import { BaseRenderOptions, MaskOptions, ProjectionOptions, AnimationOptions, WarpedMapList, Sprite, WarpedMapListOptions } from '@allmaps/render'; import { Bbox, Gcp, Point, Ring, Size } from '@allmaps/types'; import { TransformationType } from '@allmaps/transform'; import { Projection } from '@allmaps/project'; export type SpecificOpenLayersWarpedMapLayerOptions = object; type SpecificWarpedMapLayerOptions = SpecificOpenLayersWarpedMapLayerOptions; export type OpenLayersWarpedMapLayerOptions = SpecificOpenLayersWarpedMapLayerOptions & Partial<WebGL2RenderOptions>; /** * WarpedMapLayer class. * * This class renders georeferenced maps from a Georeference Annotation on an OpenLayers map. * WarpedMapLayer is a subclass of [Layer](https://openlayers.org/en/latest/apidoc/module-ol_layer_Layer-Layer.html). */ export declare class WarpedMapLayer extends Layer implements BaseWarpedMapLayer<SpecificOpenLayersWarpedMapLayerOptions> { #private; defaultSpecificWarpedMapLayerOptions: SpecificOpenLayersWarpedMapLayerOptions; options: SpecificOpenLayersWarpedMapLayerOptions & Partial<WebGL2RenderOptions>; container: HTMLDivElement; canvas: HTMLCanvasElement; gl?: WebGL2RenderingContext; renderer: WebGL2Renderer; canvasSize: [number, number]; registeredProjections: Map<string, Projection>; /** * Creates a WarpedMapLayer instance * @param options - the WebGL2 renderer options */ constructor(options?: Partial<OpenLayersWarpedMapLayerOptions>); /** * Return the bounding box of all visible maps in the layer (inside or outside of the Viewport), in longitude/latitude coordinates. * @returns - Bounding box of all warped maps */ getLonLatExtent(): Extent | undefined; /** * Keep a list of registered projections. * * Can optionally be used to complement OpenLayer's `register(proj4)` function. * * To use viewport projections in OpenLayers, add projections to proj4 and register proj4 * (Example: https://openlayers.org/en/latest/examples/scaleline-indiana-east.html). * WarpedMapLayer reads the view's projections code, gets its definition from proj4.defs * (thanks to the register() function) and constructs a new Projection type (defined in @allmap/project). * * Using this function on top of OpenLayer's `register()`, * WarpedMapLayer will look up the code in the registered projections first for a matching `id` * and, if found, use this projection. This ways relavant projection information (id, name, ...) * can be passed and used to all Allmaps packages. * * Newly registered projection overwrite older ones with the same id. */ registerProjections(projections: Projection[]): void; /** * Disposes all WebGL resources and cached tiles */ dispose(): void; /** * Render the layer. * @param frameState - OpenLayers frame state * @returns The rendered element */ render(frameState: FrameState): HTMLElement; private resized; private resizeCanvas; nativeUpdate(): void; nativePassWarpedMapEvent(event: Event): void; /** * Adds a Georeference Annotation * * @param annotation - Georeference Annotation * @param mapOptions - Map options * @returns Map IDs of the maps that were added, or an error per map */ addGeoreferenceAnnotation(annotation: unknown, mapOptions?: Partial<WebGL2WarpedMapOptions>): (string | Error)[]; /** * Removes a Georeference Annotation * * @param annotation - Georeference Annotation * @returns Map IDs of the maps that were removed, or an error per map */ removeGeoreferenceAnnotation(annotation: unknown): (string | Error)[]; /** * Adds a Georeference Annotation by URL * * @param annotationUrl - URL of a Georeference Annotation * @param mapOptions - Map options * @returns Map IDs of the maps that were added, or an error per map */ addGeoreferenceAnnotationByUrl(annotationUrl: string, mapOptions?: Partial<WebGL2WarpedMapOptions>): Promise<(string | Error)[]>; /** * Removes a Georeference Annotation by URL * * @param annotationUrl - URL of a Georeference Annotation * @returns Map IDs of the maps that were removed, or an error per map */ removeGeoreferenceAnnotationByUrl(annotationUrl: string): Promise<(string | Error)[]>; /** * Adds a Georeferenced Map * * @param georeferencedMap - Georeferenced Map * @param mapOptions - Map options * @returns Map ID of the map that was added */ addGeoreferencedMap(georeferencedMap: unknown, mapOptions?: Partial<WebGL2WarpedMapOptions>): string; /** * Removes a Georeferenced Map * * @param georeferencedMap - Georeferenced Map * @returns Map ID of the map that was removed */ removeGeoreferencedMap(georeferencedMap: unknown): string; /** * Removes a Georeferenced Map by its ID * * @param mapId - Map ID of the georeferenced map to remove * @returns Map ID of the map that was removed */ removeGeoreferencedMapById(mapId: string): string; /** * Adds image information to the WarpedMapList's image information cache * * @param imageInfos - Image informations * @returns Image IDs of the image informations that were added */ addImageInfos(imageInfos: unknown[]): string[]; /** * Adds sprites to the Renderer's sprite tile cache * * This adds tiles from sprites to warped maps in WarpedMapList. Load maps before running this function. * This uses the image info of related maps. When using addImageInfos(), call it before calling this function. * * @param sprites - Sprites * @param imageUrl - Image url * @param imageSize - Image size */ addSprites(sprites: Sprite[], imageUrl: string, imageSize: Size): Promise<void>; /** * Get the WarpedMapList object that contains a list of the warped maps of all loaded maps */ getWarpedMapList(): WarpedMapList<WebGL2WarpedMap>; /** * Get mapIds for all maps in the layer * * Note: more selection options are available on this function of WarpedMapList * * @returns The mapIds of all maps */ getMapIds(): string[]; /** * Get the WarpedMap instances for all maps, or all selected maps * * If no argument is passed, the WarpedMap instance of all maps in the layer is passed * * Note: more selection options are available on this function of WarpedMapList * * @param mapIds - Map IDs * @returns The WarpedMap instance of all (selected) map */ getWarpedMaps(mapIds?: string[]): Array<WebGL2WarpedMap>; /** * Get the WarpedMap instance for a map * * @param mapId - Map ID of the requested WarpedMap instance */ getWarpedMap(mapId: string): WebGL2WarpedMap | undefined; /** * Get the center of the bounding box of all maps in the layer * * The result is returned in lon-lat `EPSG:4326` by default. * * Note: more selection options are available on this function of WarpedMapList * * @param options - Mask and projection options, defaults to applied mask and current projection * @returns The center of the bbox of all maps, in the chosen projection, or undefined if there were no maps. */ getCenter(options?: Partial<ProjectionOptions & MaskOptions>): Point | undefined; /** * Get the center of the bounding box of all selected maps * * The result is returned in lon-lat `EPSG:4326` by default. * * Note: more selection options are available on this function of WarpedMapList * * @param mapIds - Map IDs * @param options - Mask and projection options, defaults to applied mask 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(mapIds: string[], options?: Partial<ProjectionOptions & MaskOptions>): Point | undefined; /** * Get the bounding box of all maps in the layer * * The result is returned in lon-lat `EPSG:4326` by default. * * Note: more selection options are available on this function of WarpedMapList * * @param options - Mask and projection options, defaults to applied mask and current projection * @returns The bbox of all maps, in the chosen projection, or undefined if there were no maps. */ getBbox(options?: Partial<ProjectionOptions & MaskOptions>): Bbox | undefined; /** * Get the bounding box of all selected maps * * The result is returned in lon-lat `EPSG:4326` by default. * * Note: more selection options are available on this function of WarpedMapList * * @param mapIds - Map IDs * @param options - Mask and projection options, defaults to applied mask 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(mapIds: string[], options?: Partial<ProjectionOptions & MaskOptions>): Bbox | undefined; /** * Get the convex hull of all maps in the layer * * The result is returned in lon-lat `EPSG:4326` by default. * * Note: more selection options are available on this function of WarpedMapList * * @param mapIds - Map IDs * @param options - Mask and projection options, defaults to applied mask and current projection * @returns The convex hull of all maps, in the chosen projection, or undefined if there were no maps. */ getConvexHull(options?: Partial<ProjectionOptions & MaskOptions>): Ring | undefined; /** * Get the convex hull of all selected maps maps * * The result is returned in lon-lat `EPSG:4326` by default. * * Note: more selection options are available on this function of WarpedMapList * * @param mapIds - Map IDs * @param options - Mask and projection options, defaults to applied mask 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(mapIds: string[], options?: Partial<ProjectionOptions & MaskOptions>): Ring | undefined; /** * Get the z-index of a map * * @param mapId - Map ID for which to get the z-index * @returns The z-index of a map */ getMapZIndex(mapId: string): number | undefined; /** * Get the layer opacity * * Returns a number between 0 and 1 (the default) */ getOpacity(): number; /** * Get the default options the layer */ getDefaultOptions(): SpecificWarpedMapLayerOptions & BaseRenderOptions<WebGL2WarpedMap> & WebGL2WarpedMapOptions; /** * 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): WebGL2WarpedMapOptions | undefined; /** * Get the layer options */ getLayerOptions(): Partial<SpecificWarpedMapLayerOptions & Partial<WebGL2RenderOptions>>; /** * Get the map-specific options of a map * * @param mapId - Map ID for which the options apply */ getMapMapOptions(mapId: string): Partial<WebGL2WarpedMapOptions> | 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): WebGL2WarpedMapOptions | undefined; /** * Set the layer opacity * * @param opacity - Layer opacity to set */ setOpacity(opacity: number): void; /** * Set the options * * @param options - Options to set */ setOptions(options?: Partial<SpecificWarpedMapLayerOptions> | Partial<WebGL2RenderOptions>): void; /** * Set the layer options * * Doesn't set render options or specific warped map layer options. Use setOptions() instead. * * @param layerOptions - Layer options to set * @param animationOptions - Animation options * ```js * warpedMapLayer.setLayerOptions({ transformationType: 'thinPlateSpline' }) * ``` */ setLayerOptions(layerOptions?: Partial<WarpedMapListOptions<WebGL2WarpedMap>>, animationOptions?: Partial<AnimationOptions>): void; /** * Set the transformation type of the layer * * @param transformationType - Transformation type to set * @param animationOptions - Animation options */ setLayerTransformationType(transformationType?: TransformationType, animationOptions?: Partial<AnimationOptions>): void; /** * Set the GCPs of a map * * This only sets the map-specific `gcps` option of the map * (or more specifically of the warped map used for rendering), * overwriting the original GCPs inferred from the Georeference Annotation. * * The original GCPs can be reset by resetting the map-specific GCPs option, * and stay accessible in the warped map's `map` property. * * @param mapId - Map ID for which to set the options * @param gcps - GCPs to set * @param animationOptions - Animation options */ setMapGcps(mapId: string, gcps: Gcp[], animationOptions?: Partial<AnimationOptions>): void; /** * Set the resource mask of a map * * This only sets the map-specific `resourceMask` option of the map * (or more specifically of the warped map used for rendering), * overwriting the original resource mask inferred from the Georeference Annotation. * * The original resource mask can be reset by resetting the map-specific resource mask option, * and stays accessible in the warped map's `map` property. * * @param mapId - Map ID for which to set the options * @param resourceMask - Resource mask to set * @param animationOptions - Animation options */ setMapResourceMask(mapId: string, resourceMask: Ring, animationOptions?: Partial<AnimationOptions>): void; /** * Set the transformation type of a map * * This only sets the map-specific `transformationType` option of the map * (or more specifically of the warped map used for rendering), * overwriting the original transformation type inferred from the Georeference Annotation. * * The original transformation type can be reset by resetting the map-specific transformation type option, * and stays accessible in the warped map's `map` property. * * @param mapId - Map ID for which to set the options * @param transformationType - Transformation type to set * @param animationOptions - Animation options */ setMapTransformationType(mapId: string, transformationType?: TransformationType, animationOptions?: Partial<AnimationOptions>): void; /** * Set the transformation type of maps * * This only sets the map-specific `transformationType` option of the map * (or more specifically of the warped map used for rendering), * overwriting the original transformation type inferred from the Georeference Annotation. * * The original transformation type can be reset by resetting the map-specific transformation type option, * and stays accessible in the warped map's `map` property. * * @param mapIds - Map IDs for which to set the options * @param transformationType - Transformation type to set * @param animationOptions - Animation options */ setMapsTransformationType(mapIds: string[], transformationType?: TransformationType, animationOptions?: Partial<AnimationOptions>): void; /** * Set the map-specific options of a map * * In general setting a map-specific option * also sets the corresponding option of the map, * since these are the result of merging the default, georeferenced map, * layer and map-specific options of that map. * * A special case is setting a map-specific option to `undefined`: * then the corresponding option is derived from the default, georeferenced map or layer option. * This is equivalent to using the reset function for map-specific option. * * @param mapId - Map ID for which to set the options * @param mapOptions - Map-specific options to set * @param animationOptions - Animation options * @example * ```js * warpedMapLayer.setMapOptions(myMapId, { transformationType: 'thinPlateSpline' }) * ``` */ setMapOptions(mapId: string, mapOptions: Partial<WebGL2WarpedMapOptions>, animationOptions?: Partial<AnimationOptions>): void; /** * Set the map-specific options of the specified maps * * In general setting a map-specific option * also sets the corresponding option of the map, * since these are the result of merging the default, georeferenced map, * layer and map-specific options of that map. * * A special case is setting a map-specific option to `undefined`: * then the corresponding option is derived from the default, georeferenced map or layer option. * This is equivalent to using the reset function for map-specific option. * * Useful when map-specific options are changed for multiple maps at once, * but only one animation should be fired. * * @param mapIds - Map IDs of the maps whose options to set * @param mapsOptions - Map-specific options to apply to each of those maps * @param animationOptions - Animation options * @example * ```js * warpedMapLayer.setMapsOptions([myMapId], { transformationType: 'thinPlateSpline' }) * ``` */ setMapsOptions(mapIds: string[], mapsOptions?: Partial<WebGL2WarpedMapOptions>, animationOptions?: Partial<AnimationOptions>): void; /** * Set the map-specific options of all maps using a per-map callback * * In general setting a map-specific option * also sets the corresponding option of the map, * since these are the result of merging the default, georeferenced map, * layer and map-specific options of that map. * * A special case is setting a map-specific option to `undefined`: * then the corresponding option is derived from the default, georeferenced map or layer option. * This is equivalent to using the reset function for map-specific option. * * Useful when map-specific options are changed for multiple maps at once * (with possibly different options for different maps), but only one animation should be fired. * * The callback receives each map's ID and returns the options to apply, * or `undefined` to leave that map unchanged. * * @param mapsOptionsCallbackFn - Callback returning the options to apply for a given map * @param animationOptions - Animation options * @example * ```js * warpedMapLayer.setMapsOptions((mapId) => mapId == myMapId ? { transformationType: 'thinPlateSpline' } : undefined) * ``` */ setMapsOptions(mapsOptionsCallbackFn: (mapId: string) => Partial<WebGL2WarpedMapOptions> | undefined, animationOptions?: Partial<AnimationOptions>): void; /** * Set the map-specific options of the specified maps, and the layer options * * Useful when map-specific options are changed for multiple maps at once, * together with the layer options, but only one animation should be fired. * * Doesn't set render options or specific warped map layer options. Use setOptions() instead. * * @param mapIds - IDs of the maps whose options to set * @param mapsOptions - Map-specific options to apply to each of those maps * @param layerOptions - Layer options to apply * @param animationOptions - Animation options * @example * ```js * warpedMapLayer.setMapsAndLayerOptions([myMapId], { transformationType: 'thinPlateSpline' }, { visible: true }) * ``` */ setMapsAndLayerOptions(mapIds: string[], mapsOptions?: Partial<WebGL2WarpedMapOptions>, layerOptions?: Partial<WarpedMapListOptions<WebGL2WarpedMap>>, animationOptions?: Partial<AnimationOptions>): void; /** * Set the map-specific options of all maps using a per-map callback, and the layer options * * Useful when map-specific options are changed for multiple maps at once (with possibly different options for different maps), * together with the layer options, but only one animation should be fired. * * The callback receives each map's ID and returns the options to apply, * or `undefined` to leave that map unchanged. * * Doesn't set render options or specific warped map layer options. Use setOptions() instead. * * @param mapsOptionsCallbackFn - Callback returning the options to apply for a given map * @param layerOptions - Layer options to apply * @param animationOptions - Animation options * @example * ```js * warpedMapLayer.setMapsOptions((mapId) => mapId == myMapId ? { transformationType: 'thinPlateSpline' } : undefined, {visible: true}) * ``` */ setMapsAndLayerOptions(mapsOptionsCallbackFn: (mapId: string) => Partial<WebGL2WarpedMapOptions> | undefined, layerOptions?: Partial<WarpedMapListOptions<WebGL2WarpedMap>>, animationOptions?: Partial<AnimationOptions>): void; setMapsAndLayerOptions(mapIds: string[], mapsOptions?: Partial<WebGL2WarpedMapOptions>, layerOptions?: Partial<WarpedMapListOptions<WebGL2WarpedMap>>, animationOptions?: Partial<AnimationOptions>): void; setMapsAndLayerOptions(mapsOptionsCallbackFn: (mapId: string) => Partial<WebGL2WarpedMapOptions> | undefined, layerOptions?: Partial<WarpedMapListOptions<WebGL2WarpedMap>>, animationOptions?: Partial<AnimationOptions>): void; setMapsAndLayerOptions(firstArgument: string[] | ((mapId: string) => Partial<WebGL2WarpedMapOptions> | undefined), secondArgument?: Partial<WebGL2WarpedMapOptions> | Partial<WarpedMapListOptions<WebGL2WarpedMap>>, thirdArgument?: Partial<WarpedMapListOptions<WebGL2WarpedMap>> | Partial<AnimationOptions>, fourthArgument?: Partial<AnimationOptions>): void; /** * Reset the layer options * * Undefined option keys reset all options * * Doesn't reset render options or specific warped map layer options. Use setOptions() instead. * * @param layerOptionKeys - Keys of the layer options to reset * @param animationOptions - Animation options */ resetLayerOptions(layerOptionKeys?: string[], animationOptions?: Partial<AnimationOptions>): void; /** * Reset the map-specific options of the specified maps * * Omitting `mapsOptionKeys` resets all options; passing an empty array resets none. * * @param mapIds - IDs of the maps whose options to reset * @param mapsOptionKeys - Keys of the options to reset * @param animationOptions - Animation options */ resetMapsOptions(mapIds: string[], mapsOptionKeys?: Array<keyof WebGL2WarpedMapOptions>, animationOptions?: Partial<AnimationOptions>): void; /** * Reset the map-specific options of all maps using a per-map callback * * The callback receives each map's ID and returns the keys to reset for that map. * Returning `undefined` from the callback resets all options for that map, returning an empty array resets none. * * @param mapsOptionKeysCallbackFn - Callback returning the option keys to reset for a given map * @param animationOptions - Animation options */ resetMapsOptions(mapsOptionKeysCallbackFn: (mapId: string) => Array<keyof WebGL2WarpedMapOptions> | undefined, animationOptions?: Partial<AnimationOptions>): void; resetMapsOptions(firstArgument?: string[] | ((mapId: string) => Array<keyof WebGL2WarpedMapOptions> | undefined), secondArgument?: Array<keyof WebGL2WarpedMapOptions> | Partial<AnimationOptions>, thirdArgument?: Partial<AnimationOptions>): void; /** * Reset the map-specific options of the specified maps, and the layer options * * Omitting `mapsOptionKeys` or `layerOptionKeys` resets all options for that scope; * passing an empty array resets none. * * @param mapIds - IDs of the maps whose options to reset * @param mapsOptionKeys - Keys of the map-specific options to reset * @param layerOptionKeys - Keys of the layer options to reset * @param animationOptions - Animation options */ resetMapsAndListOptions(mapIds: string[], mapsOptionKeys?: Array<keyof WebGL2WarpedMapOptions>, layerOptionKeys?: Array<keyof WebGL2WarpedMapOptions>, animationOptions?: Partial<AnimationOptions>): void; /** * Reset the map-specific options of all maps using a per-map callback, and the layer options * * The callback receives each map's ID and returns the keys to reset for that map. * Returning `undefined` from the callback resets all options for that map, returning an empty array resets none. * Omitting `layerOptionKeys` resets all layer options. * * Doesn't reset render options or specific warped map layer options. Use setOptions() instead. * * @param mapsOptionKeysCallbackFn - Callback returning the option keys to reset for a given map * @param layerOptionKeys - Keys of the layer options to reset * @param animationOptions - Animation options */ resetMapsAndListOptions(mapsOptionKeysCallbackFn: (mapId: string) => Array<keyof WebGL2WarpedMapOptions> | undefined, layerOptionKeys?: Array<keyof WebGL2WarpedMapOptions>, animationOptions?: Partial<AnimationOptions>): void; resetMapsAndListOptions(firstArgument?: string[] | ((mapId: string) => Array<keyof WebGL2WarpedMapOptions> | undefined), secondArgument?: Array<keyof WebGL2WarpedMapOptions>, thirdArgument?: Array<keyof WebGL2WarpedMapOptions> | Partial<AnimationOptions>, fourthArgument?: Partial<AnimationOptions>): void; /** * Bring maps to front * @param mapIds - IDs of the maps */ bringMapsToFront(mapIds: Iterable<string>): void; /** * Send maps to back * @param mapIds - IDs of the maps */ sendMapsToBack(mapIds: string[]): void; /** * Bring maps forward * @param mapIds - IDs of the maps */ bringMapsForward(mapIds: Iterable<string>): void; /** * Send maps backward * @param mapIds - IDs of the maps */ sendMapsBackward(mapIds: Iterable<string>): void; /** * Removes all warped maps from the layer */ clear(): void; contextLost(event: Event): void; contextRestored(event: Event): void; addEventListeners(): void; removeEventListeners(): void; } export {};