UNPKG

@allmaps/leaflet

Version:

Allmaps Leaflet plugin

438 lines (437 loc) 19 kB
import { WebGL2Renderer, WebGL2RenderOptions, WebGL2WarpedMap, WebGL2WarpedMapOptions } from '@allmaps/render/webgl2'; import { WarpedMapList, ProjectionOptions, AnimationOptions, BaseRenderOptions, Sprite } from '@allmaps/render'; import { BaseWarpedMapLayer } from '@allmaps/warpedmaplayer'; import { Point, Ring, Bbox, Gcp, Size } from '@allmaps/types'; import { TransformationType } from '@allmaps/transform'; import * as L from 'leaflet'; export type SpecificLeafletWarpedMapLayerOptions = { interactive: boolean; className: string; pane: string; zIndex?: number; }; export type LeafletWarpedMapLayerOptions = SpecificLeafletWarpedMapLayerOptions & Partial<WebGL2RenderOptions>; type SpecificWarpedMapLayerOptions = LeafletWarpedMapLayerOptions; /** * WarpedMapLayer class. * * Renders georeferenced maps of a Georeference Annotation on a Leaflet map. * WarpedMapLayer extends Leaflet's [L.Layer](https://leafletjs.com/reference.html#layer). */ export declare class WarpedMapLayer extends L.Layer implements BaseWarpedMapLayer<SpecificLeafletWarpedMapLayerOptions> { defaultSpecificWarpedMapLayerOptions: SpecificLeafletWarpedMapLayerOptions; options: SpecificLeafletWarpedMapLayerOptions & Partial<WebGL2RenderOptions>; container?: HTMLDivElement; canvas?: HTMLCanvasElement; gl: WebGL2RenderingContext | null | undefined; renderer?: WebGL2Renderer; _annotationOrAnnotationUrl: (unknown | string) | undefined; resizeObserver: ResizeObserver | undefined; /** * Creates a WarpedMapLayer * @param annotationOrAnnotationUrl - Georeference Annotation or URL of a Georeference Annotation * @param options - Options for the layer */ constructor(annotationOrAnnotationUrl: unknown, options?: Partial<LeafletWarpedMapLayerOptions>); initialize(annotationOrAnnotationUrl: unknown, options?: Partial<LeafletWarpedMapLayerOptions>): void; /** * Contains all code code that creates DOM elements for the layer and adds them to map panes where they belong. */ onAdd(map: L.Map): this; /** * Contains all cleanup code that removes the layer's elements from the DOM. */ onRemove(map: L.Map): this; /** * Returns the bounds of all visible maps (inside or outside of the Viewport), in latitude/longitude coordinates. * @returns - L.LatLngBounds in array form of all visible maps */ getBounds(): number[][] | undefined; /** * Brings the layer in front of other overlays (in the same map pane). */ bringToFront(): this; /** * Brings the layer to the back of other overlays (in the same map pane). */ bringToBack(): this; /** * Gets the z-index of the layer. */ getZIndex(): number | undefined; /** * Changes the z-index of the layer. * @param value - z-index */ setZIndex(value: number): this; _initGl(): void; _resized(entries: ResizeObserverEntry[]): void; _animateZoom(e: L.ZoomAnimEvent): void; _updateZIndex(): void; _update(): HTMLDivElement | undefined; _unload(): void; 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>): Promise<(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): Promise<(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, or an error */ addGeoreferencedMap(georeferencedMap: unknown, mapOptions?: Partial<WebGL2WarpedMapOptions>): Promise<string | Error>; /** * Removes a Georeferenced Map * * @param georeferencedMap - Georeferenced Map * @returns Map ID of the map that was removed, or an error */ removeGeoreferencedMap(georeferencedMap: unknown): Promise<string | Error>; /** * 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, or an error */ removeGeoreferencedMapById(mapId: string): Promise<string | Error | undefined>; /** * 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 selected maps * * Note: more selection options are available on this function of WarpedMapList */ getMapIds(): string[]; /** * Get the WarpedMap instances for selected maps * * Note: more selection options are available on this function of WarpedMapList * * @param mapIds - Map IDs */ getWarpedMaps(mapIds?: string[]): Iterable<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 the maps * * By default the result is returned in the list's projection, which is `EPSG:3857` by default * Use {definition: 'EPSG:4326'} to request the result in lon-lat `EPSG:4326` * * Note: more selection options are available on this function of WarpedMapList * * @param mapIds - Map IDs * @param projection - Projection in which to return the result * @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[], projectionOptions?: ProjectionOptions): Point | undefined; /** * Get the bounding box of the maps * * By default the result is returned in the list's projection, which is `EPSG:3857` by default * Use {definition: 'EPSG:4326'} to request the result in lon-lat `EPSG:4326` * * Note: more selection options are available on this function of WarpedMapList * * @param mapIds - Map IDs * @param projection - Projection in which to return the result * @returns The bbox of all selected maps, in the chosen projection, or undefined if there were no maps matching the selection. */ getMapsBbox(mapIds: string[], projectionOptions?: ProjectionOptions): Bbox | undefined; /** * Get the convex hull of the maps * * By default the result is returned in the list's projection, which is `EPSG:3857` by default * Use {definition: 'EPSG:4326'} to request the result in lon-lat `EPSG:4326` * * Note: more selection options are available on this function of WarpedMapList * * @param mapIds - Map IDs * @param projection - Projection in which to return the result * @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[], projectionOptions?: ProjectionOptions): 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 & 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 layer options * * @param layerOptions - Layer options to set * @param animationOptions - Animation options * @example * ```js * warpedMapLayer.setLayerOptions({ transformationType: 'thinPlateSpline' }) * ``` */ setLayerOptions(layerOptions: Partial<SpecificWarpedMapLayerOptions> | Partial<WebGL2RenderOptions>, 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 map-specific options of a map (and the layer options) * * 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 layerOptions - Layer options to set * @param animationOptions - Animation options * @example * ```js * warpedMapLayer.setMapOptions(myMapId, { transformationType: 'thinPlateSpline' }) * ``` */ setMapOptions(mapId: string, mapOptions: Partial<WebGL2WarpedMapOptions>, layerOptions?: Partial<SpecificWarpedMapLayerOptions> | Partial<WebGL2RenderOptions>, animationOptions?: Partial<AnimationOptions>): void; /** * Set the map-specific options of maps (and the layer options) * * 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 mapIds - Map IDs for which to set the options * @param mapOptions - Map-specific options to set * @param layerOptions - Layer options to set * @param animationOptions - Animation options * @example * ```js * warpedMapLayer.setMapsOptions([myMapId], { transformationType: 'thinPlateSpline' }) * ``` */ setMapsOptions(mapIds: string[], mapOptions: Partial<WebGL2WarpedMapOptions>, layerOptions?: Partial<SpecificWarpedMapLayerOptions> | Partial<WebGL2RenderOptions>, animationOptions?: Partial<AnimationOptions>): void; /** * Set the map-specific options of maps by map ID (and the layer options) * * 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 mapOptionsByMapId - Map-specific options to set by map ID * @param layerOptions - Layer options to set * @param animationOptions - Animation options */ setMapsOptionsByMapId(mapOptionsByMapId: Map<string, Partial<WebGL2WarpedMapOptions>>, layerOptions?: Partial<SpecificWarpedMapLayerOptions> | Partial<WebGL2RenderOptions>, animationOptions?: Partial<AnimationOptions>): void; /** * Reset the layer options * * An empty array resets all options, undefined resets no options. * Doesn't reset render options or specific warped map layer options * * @param layerOptionKeys - Keys of the options to reset * @param animationOptions - Animation options */ resetLayerOptions(layerOptionKeys?: string[], animationOptions?: Partial<AnimationOptions>): void; /** * Reset the map-specific options of maps (and the layer options) * * An empty array resets all options, undefined resets no options. * Doesn't reset render options or specific warped map layer options * * @param mapIds - Map IDs for which to reset the options * @param mapOptionKeys - Keys of the map-specific options to reset * @param layerOptionKeys - Keys of the layer options to reset * @param animationOptions - Animation options */ resetMapsOptions(mapIds: string[], mapOptionKeys?: string[], layerOptionKeys?: string[], animationOptions?: Partial<AnimationOptions>): void; /** * Reset the map-specific options of maps by map ID (and the layer options) * * An empty array or map resets all options (for all maps), undefined resets no options. * Doesn't reset render options or specific warped map layer options * * @param mapOptionkeysByMapId - Keys of map-specific options to reset by map ID * @param layerOptionKeys - Keys of the layer options to reset * @param animationOptions - Animation options */ resetMapsOptionsByMapId(mapOptionkeysByMapId: Map<string, string[]>, layerOptionKeys?: string[], animationOptions?: 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 {};