Allmaps Leaflet plugin
npm install @allmaps/leafletAllmaps plugin for Leaflet. This plugin allows displaying georeferenced IIIF images on a Leaflet map. The plugin works by loading Georeference Annotations and uses WebGL to transform images from a IIIF image server to overlay them on their correct geographical position. See allmaps.org for more information.
The development of the Allmaps plugin for Leaflet was funded by CLARIAH-VL.
The development of the Allmaps plugin for Leaflet was funded by CLARIAH-VL.

Examples:
* Observable notebook
* Observable notebook
This plugin exports the class WarpedMapLayer that extends L.Layer. You can add one or multiple Georeference Annotations (or AnnotationPages that contain multiple Georeference Annotations) to a WarpedMapLayer, and add the WarpedMapLayer to your Leaflet map. This will render all georeferenced maps defined by the Georeference Annotations.
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:
``sh`
npm install @allmaps/leaflet
You can optionally build this package locally by running:
`sh`
pnpm run build
Built for Leaflet 1.9, but should work with earlier versions as well.
Creating a WarpedMapLayer and adding it to a map looks like this:
`js
import { WarpedMapLayer } from '@allmaps/leaflet'
const map = L.map('map', {
center: [51.0518, 3.7278],
zoom: 14,
// Zoom animations for more than one zoom level are
// currently not supported by the Allmaps plugin for Leaflet
zoomAnimationThreshold: 1
})
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution:
'© OpenStreetMap contributors'
}).addTo(map)
const annotationUrl =
'https://annotations.allmaps.org/manifests/8f9faeba73d67031'
const warpedMapLayer = new WarpedMapLayer(annotationUrl).addTo(map)
`
When adding this WarpedMapLayer to the Leaflet map, the georeferenced map specified in the Georeference Annotation will be rendered on the Leaflet map.
Specifying a the URL Georeference Annotation when creating a WarpedMapLayer (as is done above) is optional. A Georeference Annotation can also be added at a later stage using the addGeoreferenceAnnotation and addGeoreferenceAnnotationByUrl functions:
`js`
fetch(annotationUrl)
.then((response) => response.json())
.then((annotation) => warpedMapLayer.addGeoreferenceAnnotation(annotation))
Or:
`js`
await warpedMapLayer.addGeoreferenceAnnotationByUrl(annotationUrl)
See the @allmaps/warpedmaplayer package for the API documentation of the methods inherited from the WarpedMapLayer class (shared by all Allmaps plugins). It includes a list of all options that can be set on instances of the class and all events which are passed to the native map instance hosting the layer instance.
You can set options on the entire layer, or on a specific map on the layer (overwriting layer options):
`js`
warpedMapLayer.setLayerOptions({ visible: true })
warpedMapLayer.setMapOptions(mapId, { visible: true })
You can listen to events in the typical way:
`js`
map.on('warpedmapadded', (event) => {
console.log(event.mapIds)
})
MIT
###### Type
`ts`
SpecificLeafletWarpedMapLayerOptions & Partial
###### Parameters
* type (WarpedMapEventType)data?
* (Partial)
###### Returns
WarpedMapEvent.
###### Extends
* Event
###### Type
`ts`
{
mapIds?: Array
tileUrl?: string | undefined
optionKeys?: Array
spritesInfo?: SpritesInfo | undefined
}
Creates a WarpedMapLayer
###### Parameters
* annotationOrAnnotationUrl (unknown)options?
* Georeference Annotation or URL of a Georeference Annotation
* (Partial)
* Options for the layer
###### Returns
WarpedMapLayer.
###### Extends
* BaseWarpedMapLayer
###### Parameters
* e (L.ZoomAnimEvent)
###### Returns
void.
###### Type
`ts`
unknown
###### Parameters
There are no parameters.
###### Returns
void.
###### Parameters
* entries (Array)
###### Returns
void.
###### Parameters
There are no parameters.
###### Returns
void.
###### Parameters
There are no parameters.
###### Returns
HTMLDivElement | undefined.
###### Parameters
There are no parameters.
###### Returns
void.
###### Parameters
There are no parameters.
###### Returns
void.
Adds a Georeference Annotation
###### Parameters
* annotation (unknown)mapOptions?
* Georeference Annotation
* (Partial)
* Map options
###### Returns
Map IDs of the maps that were added, or an error per map (Promise).
Adds a Georeference Annotation by URL
###### Parameters
* annotationUrl (string)mapOptions?
* URL of a Georeference Annotation
* (Partial)
* Map options
###### Returns
Map IDs of the maps that were added, or an error per map (Promise).
Adds a Georeferenced Map
###### Parameters
* georeferencedMap (unknown)mapOptions?
* Georeferenced Map
* (Partial)
* Map options
###### Returns
Map ID of the map that was added, or an error (Promise).
Adds image information to the WarpedMapList's image information cache
###### Parameters
* imageInfos (Array)
* Image informations
###### Returns
Image IDs of the image informations that were added (Array).
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.
###### Parameters
* sprites (Array)imageUrl
* Sprites
* (string)imageSize
* Image url
* ([number, number])
* Image size
###### Returns
Promise.
Bring maps forward
###### Parameters
* mapIds (Iterable)
* IDs of the maps
###### Returns
void.
Bring maps to front
###### Parameters
* mapIds (Iterable)
* IDs of the maps
###### Returns
void.
Brings the layer to the back of other overlays (in the same map pane).
###### Parameters
There are no parameters.
###### Returns
this.
Brings the layer in front of other overlays (in the same map pane).
###### Parameters
There are no parameters.
###### Returns
this.
###### Type
`ts`
HTMLCanvasElement
Removes all warped maps from the layer
###### Parameters
There are no parameters.
###### Returns
void.
###### Type
`ts`
HTMLDivElement
###### Parameters
* event (Event)
###### Returns
void.
###### Parameters
* event (Event)
###### Returns
void.
###### Type
`ts`
{
interactive: boolean
className: string
pane: string
zIndex?: number
}
Returns the bounds of all visible maps (inside or outside of the Viewport), in latitude/longitude coordinates.
###### Parameters
There are no parameters.
###### Returns
Array.
* L.LatLngBounds in array form of all visible maps
Get the default options the layer
###### Parameters
There are no parameters.
###### Returns
SpecificLeafletWarpedMapLayerOptions & Partial.
Get the layer options
###### Parameters
There are no parameters.
###### Returns
{ interactive?: boolean | undefined; className?: string | undefined; pane?: string | undefined; zIndex?: number | undefined; createRTree?: boolean | undefined; rtreeUpdatedOptions?: Array.
Get the default options of a map
These come from the default option settings for WebGL2WarpedMaps and the map's georeferenced map proporties
###### Parameters
* mapId (string)
* Map ID for which the options apply
###### Returns
WebGL2WarpedMapOptions | undefined.
Get mapIds for selected maps
Note: more selection options are available on this function of WarpedMapList
###### Parameters
There are no parameters.
###### Returns
Array.
Get the map-specific options of a map
###### Parameters
* mapId (string)
* Map ID for which the options apply
###### Returns
Partial.
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.
###### Parameters
* mapId (string)
* Map ID for which the options apply
###### Returns
WebGL2WarpedMapOptions | undefined.
Get the z-index of a map
###### Parameters
* mapId (string)
* Map ID for which to get the z-index
###### Returns
The z-index of a map (number | undefined).
Get the bounding box of the maps
By default the result is returned in the list's projection, which is EPSG:3857 by defaultEPSG:4326
Use {definition: 'EPSG:4326'} to request the result in lon-lat
Note: more selection options are available on this function of WarpedMapList
###### Parameters
* mapIds (Array)projectionOptions?
* Map IDs
* (ProjectionOptions | undefined)
###### Returns
The bbox of all selected maps, in the chosen projection, or undefined if there were no maps matching the selection (Bbox | 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 defaultEPSG:4326
Use {definition: 'EPSG:4326'} to request the result in lon-lat
Note: more selection options are available on this function of WarpedMapList
###### Parameters
* mapIds (Array)projectionOptions?
* Map IDs
* (ProjectionOptions | undefined)
###### Returns
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).
Get the convex hull of the maps
By default the result is returned in the list's projection, which is EPSG:3857 by defaultEPSG:4326
Use {definition: 'EPSG:4326'} to request the result in lon-lat
Note: more selection options are available on this function of WarpedMapList
###### Parameters
* mapIds (Array)projectionOptions?
* Map IDs
* (ProjectionOptions | undefined)
###### Returns
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)
###### Parameters
There are no parameters.
###### Returns
number.
Get the WarpedMap instance for a map
###### Parameters
* mapId (string)
* Map ID of the requested WarpedMap instance
###### Returns
WebGL2WarpedMap | undefined.
Get the WarpedMapList object that contains a list of the warped maps of all loaded maps
###### Parameters
There are no parameters.
###### Returns
WarpedMapList.
Get the WarpedMap instances for selected maps
Note: more selection options are available on this function of WarpedMapList
###### Parameters
* mapIds? (Array)
* Map IDs
###### Returns
Iterable.
Gets the z-index of the layer.
###### Parameters
There are no parameters.
###### Returns
number | undefined.
###### Type
`ts`
WebGL2RenderingContext | null | undefined
###### Parameters
* annotationOrAnnotationUrl (unknown)options?
* (Partial)
###### Returns
void.
###### Parameters
* event (Event)
###### Returns
void.
###### Parameters
There are no parameters.
###### Returns
void.
Contains all code code that creates DOM elements for the layer and adds them to map panes where they belong.
###### Parameters
* map (L.Map)
###### Returns
this.
Contains all cleanup code that removes the layer's elements from the DOM.
###### Parameters
* map (L.Map)
###### Returns
this.
###### Type
`ts`
SpecificLeafletWarpedMapLayerOptions & Partial
###### Parameters
There are no parameters.
###### Returns
void.
Removes a Georeference Annotation
###### Parameters
* annotation (unknown)
* Georeference Annotation
###### Returns
Map IDs of the maps that were removed, or an error per map (Promise).
Removes a Georeference Annotation by URL
###### Parameters
* annotationUrl (string)
* URL of a Georeference Annotation
###### Returns
Map IDs of the maps that were removed, or an error per map (Promise).
Removes a Georeferenced Map
###### Parameters
* georeferencedMap (unknown)
* Georeferenced Map
###### Returns
Map ID of the map that was removed, or an error (Promise).
Removes a Georeferenced Map by its ID
###### Parameters
* mapId (string)
* Map ID of the georeferenced map to remove
###### Returns
Map ID of the map that was removed, or an error (Promise).
###### Type
`ts`
WebGL2Renderer
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
###### Parameters
* layerOptionKeys? (Array)animationOptions?
* Keys of the options to reset
* (Partial)
* Animation options
###### Returns
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
###### Parameters
* mapIds (Array)mapOptionKeys?
* Map IDs for which to reset the options
* (Array)layerOptionKeys?
* Keys of the map-specific options to reset
* (Array)animationOptions?
* Keys of the layer options to reset
* (Partial)
* Animation options
###### Returns
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
###### Parameters
* mapOptionkeysByMapId (Map)layerOptionKeys?
* Keys of map-specific options to reset by map ID
* (Array)animationOptions?
* Keys of the layer options to reset
* (Partial)
* Animation options
###### Returns
void.
###### Type
`ts`
ResizeObserver | undefined
Send maps backward
###### Parameters
* mapIds (Iterable)
* IDs of the maps
###### Returns
void.
Send maps to back
###### Parameters
* mapIds (Array)
* IDs of the maps
###### Returns
void.
Set the layer options
###### Parameters
* layerOptions (Partial)animationOptions?
* Layer options to set
* (Partial)
* Animation options
###### Returns
void.
###### Examples
`ts`
warpedMapLayer.setLayerOptions({ transformationType: 'thinPlateSpline' })
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.
###### Parameters
* mapId (string)gcps
* Map ID for which to set the options
* (Array)animationOptions?
* GCPs to set
* (Partial)
* Animation options
###### Returns
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.
###### Parameters
* mapId (string)mapOptions
* Map ID for which to set the options
* ({ 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 | ...)layerOptions?
* Map-specific options to set
* ( | Partial
| Partial
| undefined)animationOptions?
* Layer options to set
* (Partial)
* Animation options
###### Returns
void.
###### Examples
`ts`
warpedMapLayer.setMapOptions(myMapId, { transformationType: 'thinPlateSpline' })
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.
###### Parameters
* mapId (string)resourceMask
* Map ID for which to set the options
* (Array)animationOptions?
* Resource mask to set
* (Partial)
* Animation options
###### Returns
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.
###### Parameters
* mapId (string)transformationType
* Map ID for which to set the options
* ( | 'straight'
| 'helmert'
| 'polynomial'
| 'polynomial1'
| 'polynomial2'
| 'polynomial3'
| 'thinPlateSpline'
| 'projective'
| 'linear')animationOptions?
* Transformation type to set
* (Partial)
* Animation options
###### Returns
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.
###### Parameters
* mapIds (Array)mapOptions
* Map IDs for which to set the options
* ({ 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 | ...)layerOptions?
* Map-specific options to set
* ( | Partial
| Partial
| undefined)animationOptions?
* Layer options to set
* (Partial)
* Animation options
###### Returns
void.
###### Examples
`ts`
warpedMapLayer.setMapsOptions([myMapId], { transformationType: 'thinPlateSpline' })
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.
###### Parameters
* mapOptionsByMapId (Map)layerOptions?
* Map-specific options to set by map ID
* ( | Partial
| Partial
| undefined)animationOptions?
* Layer options to set
* (Partial)
* Animation options
###### Returns
void.
Set the layer opacity
###### Parameters
* opacity (number)
* Layer opacity to set
###### Returns
void.
Changes the z-index of the layer.
###### Parameters
* value (number)
* z-index
###### Returns
this`.