Skip to content

@allmaps/warpedmaplayer

Base class for Allmaps plugins. This class contains the main logic for the WarpedMapLayer class exported by the Leaflet, OpenLayers and MapLibre plugins for Allmaps, which allow displaying georeferenced IIIF images on a webmap. These plugins work by loading Georeference Annotations and use WebGL to transform images from a IIIF image server to overlay them on their correct geographical position.

This plugin creates a new class WarpedMapLayer which extends or is implemented by the Layer classes of the webmap libraries Leaflet, OpenLayers and MapLibre. Where it extends (MapLibre), the methods defined in this package are inherited automatically. Where it is implemented (Leaflet and OpenLayers) any changes to these methods should be copy-pasted to the implementing classes (see comments in the code).

To understand what happens under the hood for each georeferenced map, see the @allmaps/render package.

This package works in browsers and in Node.js as an ESM or an UMD module.

Install with pnpm:

Terminal window
pnpm install @allmaps/warpedmaplayer

You can optionally build this package locally by running:

Terminal window
pnpm run build

This package contains the main logic for the WarpedMapLayer class exported by the Allmaps plugins for Leaflet, OpenLayers and MapLibre. It should not be used directly. See the readme of the plugins for more usage information.

Use this readme to understand the API of the WarpedMapLayer methods shared between the plugins, including event types emitted by a WarpedMapLayer instance and a list of available options.

The following events are emitted to inform you of the state of the WarpedMapLayer.

TypeDescription
georeferenceannotationaddedA georeference annotation has been added to the warped map list
georeferenceannotationremovedA georeference annotation has been removed from the warped map list
warpedmapaddedA warped map has been added to the warped map list
warpedmapremovedA warped map has been removed from the warped map list
warpedmapenteredA warped map has entered the viewport
warpedmapleftA warped map has left the viewport
imageloadedAn image was loaded for a map from cache or by fetching image info
maptileloadedA tile has been loaded to the tile cache for a map
maptiledeletedA tile has been deleted from the tile cache for a map
firstmaptileloadedThe cache loaded a first tile of a map
allrequestedtilesloadedAll tiles requested for the current viewport have been loaded
clearedThe warped map list has been cleared
preparechangeAn upcoming options change has been prepared for a specific map (by mixing previous and new properties if the animation was ongoing)
immediatechangeAn options change has been processed immediately
animatedchangeAn options change has been processed with an animation

Event data follows the Partial<WarpedMapEventData> type:

export type WarpedMapEventData = {
mapIds: string[]
tileUrl: string
optionKeys: string[]
}

Options can be set on a WarpedMapLayer both as layer options, which apply to all maps, or as individual map options. For each map, the final options that are applied to it result from merging the default options, options specified in the georeference annotation (like resourceMask, transformationType, internalProjection and gcps), layer options and map options. When merging options, undefined options are neglected, so setting a layer or map option to undefined effectively resets it.

The following options are available:

KeyDescriptionDefault
applyMaskApply the resource mask (if false, the full mask is used)true
colorizeColorize the mapfalse
colorizeColorColor to colorize the map"#ff56ba"
debugTilesDebug: show the tile boundariesfalse
debugTrianglesDebug: show the triangulation trianglesfalse
debugTriangulationDebug: show the triangulation triangle pointsfalse
distortionColor00First color in the 'log2sigma' distortion"#fe5e60"
distortionColor01Second color in the 'log2sigma' distortion"#3b44ad"
distortionColor1Color in the 'twoOmega' distortion"#64c18f"
distortionColor2Color in the 'airyKavr' distortion"#ffc742"
distortionColor3Color in the 'signDetJ' distortion"#fe5e60"
distortionMeasuresDistortion measures to be computed['log2sigma', 'twoOmega']
gcpsGround control points[] (overwritten by the GCPs in the georeference annotation)
internalProjectionInternal projection (see @allmaps/project)WebMercatorProjection (possibly overwritten by the internal projection in the georeference annotation)
opacityOpacity1
projectionProjection (see @allmaps/project)WebMercatorProjection
removeColorRemove colorfalse
removeColorColorColor to remove"#222222"
removeColorHardnessHardness when removing color0.7
removeColorThresholdThreshold when removing color0
renderAppliableMaskRender the appliable mask, which is the resource mask as specified in the georeferenced annotation (or options), even when the mask is not applied (see the applyMask option) and the full mask is usedfalse
renderAppliableMaskColorColor when rendering the appliable mask"#ff56ba"
renderAppliableMaskSizeSize in viewport pixels when rendering the appliable mask8
renderFullMaskRender the full maskfalse
renderFullMaskColorColor when rendering the full mask"#64c18f"
renderFullMaskSizeSize in viewport pixels when rendering the full mask8
renderGcpsRender the GCPsfalse
renderGcpsColorColor when rendering the GCPs"#63d8e6"
renderGcpsSizeSize in viewport pixels when rendering the GCPs16
renderGridRender the gridfalse
renderGridColorColor when rendering the grid"#222222"
renderMaskRender the maskfalse
renderMaskColorColor when rendering the mask"#ff56ba"
renderMaskSizeSize in viewport pixels when rendering the mask8
renderTransformedGcpsRender the transformed GCPsfalse
renderTransformedGcpsColorColor when rendering the transformed GCPs"#ff56ba"
renderTransformedGcpsSizeSize in viewport pixels when rendering the transformed GCPs16
renderVectorsRender the vectors connecting each GCP with its respective transformed GCPfalse
renderVectorsColorColor when rendering the vectors"#222222"
renderVectorsSizeSize in viewport pixels when rendering the vectors6
resourceMaskResource mask[] (overwritten by the resource mask in the georeference annotation)
saturationSaturation1
transformationTypeTransformation type"polynomial" (possibly overwritten by the transformation type in the georeference annotation)
visibleVisibletrue

Leaflet, OpenLayer and MapLibre each have their concept of a ‘map’ as the central class their API (see Leaflet Map, OpenLayers Map and MapLibre Map). It generally refers to a <div> an a page where tiles or WebGL logic is used to render a projection of the world.

In Allmaps the concept ‘map’ is rather related to a Georeference Annotation. There are different classes named ‘map’, one for each phase a map takes through the Allmaps rendering pipeline:

  • When a Georeference Annotation is parsed, an instance of the GeoreferencedMap class is created from it.
  • When this map is loaded into an application for rendering, an instance of the WarpedMap class is created from it.
  • Inside the WebGL2 Renderer, the WebGL2WarpedMap class is used to render the map.

All these map phases originating from the same Georeference Annotation have the same unique mapId property. This string value is used though-out Allmaps (and in the API below) to identify a map. It is returned after adding a georeference annotation to a warpedMapLayer, so you can use it later to call functions on a specific map.

Note that since a WarpedMapLayer can load multiple Georeference Annotations, we could have multiple Allmaps ‘maps’ on e.g. one Leaflet ‘map’.

MIT

new BaseWarpedMapLayer(defaultSpecificWarpedMapLayerOptions, options)

Section titled “new BaseWarpedMapLayer(defaultSpecificWarpedMapLayerOptions, options)”

Creates a WarpedMapLayer instance

  • defaultSpecificWarpedMapLayerOptions (SpecificWarpedMapLayerOptions)
  • options? ( | Partial<SpecificWarpedMapLayerOptions & Partial<WebGL2RenderOptions>> | undefined)
    • options

BaseWarpedMapLayer<SpecificWarpedMapLayerOptions>.

There are no parameters.

void.

BaseWarpedMapLayer#addGeoreferenceAnnotation(annotation, mapOptions)

Section titled “BaseWarpedMapLayer#addGeoreferenceAnnotation(annotation, mapOptions)”

Adds a Georeference Annotation

  • annotation (unknown)
    • Georeference Annotation
  • mapOptions? (Partial<WebGL2WarpedMapOptions> | undefined)
    • Map options

Map IDs of the maps that were added, or an error per map (Promise<Array<string | Error>>).

BaseWarpedMapLayer#addGeoreferenceAnnotationByUrl(annotationUrl, mapOptions)

Section titled “BaseWarpedMapLayer#addGeoreferenceAnnotationByUrl(annotationUrl, mapOptions)”

Adds a Georeference Annotation by URL

  • annotationUrl (string)
    • URL of a Georeference Annotation
  • mapOptions? (Partial<WebGL2WarpedMapOptions> | undefined)
    • Map options

Map IDs of the maps that were added, or an error per map (Promise<Array<string | Error>>).

BaseWarpedMapLayer#addGeoreferencedMap(georeferencedMap, mapOptions)

Section titled “BaseWarpedMapLayer#addGeoreferencedMap(georeferencedMap, mapOptions)”

Adds a Georeferenced Map

  • georeferencedMap (unknown)
    • Georeferenced Map
  • mapOptions? (Partial<WebGL2WarpedMapOptions> | undefined)
    • Map options

Map ID of the map that was added, or an error (Promise<string | Error>).

BaseWarpedMapLayer#addImageInfos(imageInfos)

Section titled “BaseWarpedMapLayer#addImageInfos(imageInfos)”

Adds image information to the WarpedMapList’s image information cache

  • imageInfos (Array<unknown>)
    • Image informations

Image IDs of the image informations that were added (Array<string>).

BaseWarpedMapLayer#bringMapsForward(mapIds)

Section titled “BaseWarpedMapLayer#bringMapsForward(mapIds)”

Bring maps forward

  • mapIds (Iterable<string>)
    • IDs of the maps

void.

BaseWarpedMapLayer#bringMapsToFront(mapIds)

Section titled “BaseWarpedMapLayer#bringMapsToFront(mapIds)”

Bring maps to front

  • mapIds (Iterable<string>)
    • IDs of the maps

void.

HTMLCanvasElement

Removes all warped maps from the layer

There are no parameters.

void.

HTMLDivElement
  • event (Event)

void.

  • event (Event)

void.

BaseWarpedMapLayer#defaultSpecificWarpedMapLayerOptions

Section titled “BaseWarpedMapLayer#defaultSpecificWarpedMapLayerOptions”
SpecificWarpedMapLayerOptions

Get the default options the layer

There are no parameters.

SpecificWarpedMapLayerOptions & object & SpecificWarpedMapListOptions & Partial<WebGL2WarpedMapOptions> & SpecificWebGL2WarpedMapOptions & SpecificTriangulatedWarpedMapOptions & WarpedMapOptions.

Get the layer options

There are no parameters.

{ [P in keyof (SpecificWarpedMapLayerOptions & Partial<WebGL2RenderOptions>)]?: (SpecificWarpedMapLayerOptions & Partial<...>)[P] | undefined; }.

BaseWarpedMapLayer#getMapDefaultOptions(mapId)

Section titled “BaseWarpedMapLayer#getMapDefaultOptions(mapId)”

Get the default options of a map

These come from the default option settings for WebGL2WarpedMaps and the map’s georeferenced map proporties

  • mapId (string)
    • Map ID for which the options apply

WebGL2WarpedMapOptions | undefined.

Get mapIds for selected maps

Note: more selection options are available on this function of WarpedMapList

There are no parameters.

Array<string>.

BaseWarpedMapLayer#getMapMapOptions(mapId)

Section titled “BaseWarpedMapLayer#getMapMapOptions(mapId)”

Get the map-specific options of a map

  • mapId (string)
    • Map ID for which the options apply

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.

  • mapId (string)
    • Map ID for which the options apply

WebGL2WarpedMapOptions | undefined.

Get the z-index of a map

  • mapId (string)
    • Map ID for which to get the z-index

The z-index of a map (number | undefined).

BaseWarpedMapLayer#getMapsBbox(mapIds, projectionOptions)

Section titled “BaseWarpedMapLayer#getMapsBbox(mapIds, projectionOptions)”

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

  • mapIds (Array<string>)
    • Map IDs
  • projectionOptions? (ProjectionOptions | undefined)

The bbox of all selected maps, in the chosen projection, or undefined if there were no maps matching the selection (Bbox | undefined).

BaseWarpedMapLayer#getMapsCenter(mapIds, projectionOptions)

Section titled “BaseWarpedMapLayer#getMapsCenter(mapIds, projectionOptions)”

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

  • mapIds (Array<string>)
    • Map IDs
  • projectionOptions? (ProjectionOptions | undefined)

The center of the bbox of all selected maps, in the chosen projection, or undefined if there were no maps matching the selection (Point | undefined).

BaseWarpedMapLayer#getMapsConvexHull(mapIds, projectionOptions)

Section titled “BaseWarpedMapLayer#getMapsConvexHull(mapIds, projectionOptions)”

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

  • mapIds (Array<string>)
    • Map IDs
  • projectionOptions? (ProjectionOptions | undefined)

The convex hull of all selected maps, in the chosen projection, or undefined if there were no maps matching the selection (Ring | undefined).

Get the layer opacity

Returns a number between 0 and 1 (the default)

There are no parameters.

number.

Get the WarpedMap instance for a map

  • mapId (string)
    • Map ID of the requested WarpedMap instance

WebGL2WarpedMap | undefined.

Get the WarpedMapList object that contains a list of the warped maps of all loaded maps

There are no parameters.

WarpedMapList<WebGL2WarpedMap>.

Get the WarpedMap instances for selected maps

Note: more selection options are available on this function of WarpedMapList

  • mapIds? (Array<string> | undefined)
    • Map IDs

Iterable<WebGL2WarpedMap>.

WebGL2RenderingContext | null | undefined

BaseWarpedMapLayer#nativePassWarpedMapEvent(event)

Section titled “BaseWarpedMapLayer#nativePassWarpedMapEvent(event)”
  • event (Event)

void.

There are no parameters.

void.

SpecificWarpedMapLayerOptions & Partial<WebGL2RenderOptions>

There are no parameters.

void.

BaseWarpedMapLayer#removeGeoreferenceAnnotation(annotation)

Section titled “BaseWarpedMapLayer#removeGeoreferenceAnnotation(annotation)”

Removes a Georeference Annotation

  • annotation (unknown)
    • Georeference Annotation

Map IDs of the maps that were removed, or an error per map (Promise<Array<string | Error>>).

BaseWarpedMapLayer#removeGeoreferenceAnnotationByUrl(annotationUrl)

Section titled “BaseWarpedMapLayer#removeGeoreferenceAnnotationByUrl(annotationUrl)”

Removes a Georeference Annotation by URL

  • annotationUrl (string)
    • URL of a Georeference Annotation

Map IDs of the maps that were removed, or an error per map (Promise<Array<string | Error>>).

BaseWarpedMapLayer#removeGeoreferencedMap(georeferencedMap)

Section titled “BaseWarpedMapLayer#removeGeoreferencedMap(georeferencedMap)”

Removes a Georeferenced Map

  • georeferencedMap (unknown)
    • Georeferenced Map

Map ID of the map that was removed, or an error (Promise<string | Error>).

BaseWarpedMapLayer#removeGeoreferencedMapById(mapId)

Section titled “BaseWarpedMapLayer#removeGeoreferencedMapById(mapId)”

Removes a Georeferenced Map by its ID

  • mapId (string)
    • Map ID of the georeferenced map to remove

Map ID of the map that was removed, or an error (Promise<string | Error | undefined>).

WebGL2Renderer

BaseWarpedMapLayer#resetLayerOptions(layerOptionKeys, animationOptions)

Section titled “BaseWarpedMapLayer#resetLayerOptions(layerOptionKeys, animationOptions)”

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

  • layerOptionKeys? (Array<string> | undefined)
    • Keys of the options to reset
  • animationOptions? (Partial<AnimationOptions> | undefined)
    • Animation options

void.

BaseWarpedMapLayer#resetMapsOptions(mapIds, mapOptionKeys, layerOptionKeys, animationOptions)

Section titled “BaseWarpedMapLayer#resetMapsOptions(mapIds, mapOptionKeys, layerOptionKeys, animationOptions)”

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

  • mapIds (Array<string>)
    • Map IDs for which to reset the options
  • mapOptionKeys? (Array<string> | undefined)
    • Keys of the map-specific options to reset
  • layerOptionKeys? (Array<string> | undefined)
    • Keys of the layer options to reset
  • animationOptions? (Partial<AnimationOptions> | undefined)
    • Animation options

void.

BaseWarpedMapLayer#resetMapsOptionsByMapId(mapOptionkeysByMapId, layerOptionKeys, animationOptions)

Section titled “BaseWarpedMapLayer#resetMapsOptionsByMapId(mapOptionkeysByMapId, layerOptionKeys, animationOptions)”

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

  • mapOptionkeysByMapId (Map<string, Array<string>>)
    • Keys of map-specific options to reset by map ID
  • layerOptionKeys? (Array<string> | undefined)
    • Keys of the layer options to reset
  • animationOptions? (Partial<AnimationOptions> | undefined)
    • Animation options

void.

BaseWarpedMapLayer#sendMapsBackward(mapIds)

Section titled “BaseWarpedMapLayer#sendMapsBackward(mapIds)”

Send maps backward

  • mapIds (Iterable<string>)
    • IDs of the maps

void.

Send maps to back

  • mapIds (Array<string>)
    • IDs of the maps

void.

BaseWarpedMapLayer#setLayerOptions(layerOptions, animationOptions)

Section titled “BaseWarpedMapLayer#setLayerOptions(layerOptions, animationOptions)”

Set the layer options

  • layerOptions (Partial<WebGL2RenderOptions> | Partial<SpecificWarpedMapLayerOptions>)
    • Layer options to set
  • animationOptions? (Partial<AnimationOptions> | undefined)
    • Animation options

void.

warpedMapLayer.setLayerOptions({ transformationType: 'thinPlateSpline' })

BaseWarpedMapLayer#setMapGcps(mapId, gcps, animationOptions)

Section titled “BaseWarpedMapLayer#setMapGcps(mapId, gcps, animationOptions)”

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.

  • mapId (string)
    • Map ID for which to set the options
  • gcps (Array<Gcp>)
    • GCPs to set
  • animationOptions? (Partial<AnimationOptions> | undefined)
    • Animation options

void.

BaseWarpedMapLayer#setMapOptions(mapId, mapOptions, layerOptions, animationOptions)

Section titled “BaseWarpedMapLayer#setMapOptions(mapId, mapOptions, layerOptions, animationOptions)”

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.

  • mapId (string)
    • Map ID for which to set the options
  • mapOptions ({ renderMaps?: boolean | undefined; renderLines?: boolean | undefined; renderPoints?: boolean | undefined; renderGcps?: boolean | undefined; renderGcpsColor?: string | undefined; renderGcpsSize?: number | undefined; renderGcpsBorderColor?: string | undefined; ... 54 more ...; distortionMeasure?: DistortionMeasure | ...)
    • Map-specific options to set
  • layerOptions? ( | Partial<WebGL2RenderOptions> | Partial<SpecificWarpedMapLayerOptions> | undefined)
    • Layer options to set
  • animationOptions? (Partial<AnimationOptions> | undefined)
    • Animation options

void.

warpedMapLayer.setMapOptions(myMapId, { transformationType: 'thinPlateSpline' })

BaseWarpedMapLayer#setMapResourceMask(mapId, resourceMask, animationOptions)

Section titled “BaseWarpedMapLayer#setMapResourceMask(mapId, resourceMask, animationOptions)”

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.

  • mapId (string)
    • Map ID for which to set the options
  • resourceMask (Array<Point>)
    • Resource mask to set
  • animationOptions? (Partial<AnimationOptions> | undefined)
    • Animation options

void.

BaseWarpedMapLayer#setMapTransformationType(mapId, transformationType, animationOptions)

Section titled “BaseWarpedMapLayer#setMapTransformationType(mapId, transformationType, animationOptions)”

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.

  • mapId (string)
    • Map ID for which to set the options
  • transformationType ( | 'straight' | 'helmert' | 'polynomial' | 'polynomial1' | 'polynomial2' | 'polynomial3' | 'thinPlateSpline' | 'projective' | 'linear')
    • Transformation type to set
  • animationOptions? (Partial<AnimationOptions> | undefined)
    • Animation options

void.

BaseWarpedMapLayer#setMapsOptions(mapIds, mapOptions, layerOptions, animationOptions)

Section titled “BaseWarpedMapLayer#setMapsOptions(mapIds, mapOptions, layerOptions, animationOptions)”

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.

  • mapIds (Array<string>)
    • Map IDs for which to set the options
  • mapOptions ({ renderMaps?: boolean | undefined; renderLines?: boolean | undefined; renderPoints?: boolean | undefined; renderGcps?: boolean | undefined; renderGcpsColor?: string | undefined; renderGcpsSize?: number | undefined; renderGcpsBorderColor?: string | undefined; ... 54 more ...; distortionMeasure?: DistortionMeasure | ...)
    • Map-specific options to set
  • layerOptions? ( | Partial<WebGL2RenderOptions> | Partial<SpecificWarpedMapLayerOptions> | undefined)
    • Layer options to set
  • animationOptions? (Partial<AnimationOptions> | undefined)
    • Animation options

void.

warpedMapLayer.setMapsOptions([myMapId], { transformationType: 'thinPlateSpline' })

BaseWarpedMapLayer#setMapsOptionsByMapId(mapOptionsByMapId, layerOptions, animationOptions)

Section titled “BaseWarpedMapLayer#setMapsOptionsByMapId(mapOptionsByMapId, layerOptions, animationOptions)”

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.

  • mapOptionsByMapId (Map<string, Partial<WebGL2WarpedMapOptions>>)
    • Map-specific options to set by map ID
  • layerOptions? ( | Partial<WebGL2RenderOptions> | Partial<SpecificWarpedMapLayerOptions> | undefined)
    • Layer options to set
  • animationOptions? (Partial<AnimationOptions> | undefined)
    • Animation options

void.

Set the layer opacity

  • opacity (number)
    • Layer opacity to set

void.

  • canvas? (HTMLCanvasElement | undefined)

void.

BaseWarpedMapLayer.assertRenderer(renderer)

Section titled “BaseWarpedMapLayer.assertRenderer(renderer)”
  • renderer? (WebGL2Renderer | undefined)

void.