Allmaps 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.
Examples:
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:
npm install @allmaps/leafletYou can optionally build this package locally by running:
pnpm run buildAs an alternative to loading using import, ESM and UMD bundled versions of the code are also provided under /dist/bundled (once the code is built). These are also published online, so can load them directly in a HTML script tag using a CDN. They require Leaflet to be loaded as L, so place them after loading Leaflet.
<script src="https://cdn.jsdelivr.net/npm/@allmaps/leaflet/dist/bundled/allmaps-leaflet-1.9.umd.js"></script>When loading the bundled package, its classes are available under the Allmaps global variable:
const warpedMapLayer = new Allmaps.WarpedMapLayer(annotationUrl)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:
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 Leafet
zoomAnimationThreshold: 1
})
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution:
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> 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:
fetch(annotationUrl)
.then((response) => response.json())
.then((annotation) => warpedMapLayer.addGeoreferenceAnnotation(annotation))Or:
await warpedMapLayer.addGeoreferenceAnnotationByUrl(annotationUrl)The following events are emitted to inform you of the state of the WarpedMapLayer.
| Description | Type | Data |
|---|---|---|
| A warped map has been added to the warped map list | warpedmapadded |
mapId: string |
| A warped map has been removed from the warped map list | warpedmapremoved |
mapId: string |
| A warped map enters the viewport | warpedmapenter |
mapId: string |
| A warped map leaves the viewport | warpedmapleave |
mapId: string |
| The visibility of some warped maps has changed | visibilitychanged |
mapIds: string[] |
| The cache loaded a first tile of a map | firstmaptileloaded |
{mapId: string, tileUrl: string} |
| All tiles requested for the current viewport have been loaded | allrequestedtilesloaded |
You can listen to them in the typical Leaflet way. Here's an example:
map.on('warpedmapadded', (event) => {
console.log(event.mapId, WarpedMapLayer.getBounds())
})Some of the functions specified in the API only make sense once a warped map is loaded into the WarpedMapLayer. You can use such listeners to make sure function are run e.g. only after a warped map has been added.
A Leaflet map is an instance of the Leaflet Map class, the central class of the Leaflet API, used to create a map on a page and manipulate it.
In Allmaps there are multiple classes describing maps, one for each phase a map takes through the Allmaps rendering pipeline:
- When a Georeference Annotation is parsed, an instance of the
GeoreferencedMapclass is created from it. - When this map is loaded into an application for rendering, an instance of the
WarpedMapclass is created from it. - Inside the WebGL2 rendering package, the
WebGL2WarpedMapclass is used to render the map.
All these map phases originate from the same Georeference Annotation have the same unique mapId property. This string value is used thoughout 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.
WarpedMapListOptions & WarpedMapOptions & { imageInformations: ImageInformations; fetchFn: FetchFn; } & { opacity: number; ... 4 more ...; imageInformations?: ImageInformations; }type(WarpedMapEventType)data?(unknown)
WarpedMapEvent.
Event
unknownCreates a WarpedMapLayer
annotationOrAnnotationUrl(unknown)- Georeference Annotation or URL of a Georeference Annotation
options?(Partial<LeafletWarpedMapLayerOptions> | undefined)- Options for the layer
WarpedMapLayer.
Layer
There are no parameters.
void.
e(ZoomAnimEvent)
void.
unknownevent(Event)
void.
event(Event)
void.
There are no parameters.
void.
event(Event)
void.
There are no parameters.
void.
entries(Array<ResizeObserverEntry>)
void.
There are no parameters.
void.
There are no parameters.
HTMLDivElement | undefined.
There are no parameters.
void.
Adds a Georeference Annotation.
annotation(unknown)- Georeference Annotation
Promise<Array<string | Error>>.
- the map IDs of the maps that were added, or an error per map
Adds a Georeference Annotation by URL.
annotationUrl(string)- Georeference Annotation
The map IDs of the maps that were added, or an error per map (Promise<Array<string | Error>>).
Adds a Georeferenced map.
georeferencedMap(unknown)- Georeferenced map
The map ID of the map that was added, or an error (Promise<string | Error>).
Bring maps forward
mapIds(Iterable<string>)- IDs of the maps
void.
Bring maps to front
mapIds(Iterable<string>)- IDs of the maps
void.
Brings the layer to the back of other overlays (in the same map pane).
There are no parameters.
this.
Brings the layer in front of other overlays (in the same map pane).
There are no parameters.
this.
HTMLCanvasElement | undefinedRemoves all warped maps from the layer
There are no parameters.
this.
HTMLDivElement | undefinedReturns the bounds of all visible maps (inside or outside of the Viewport), in latitude/longitude coordinates.
There are no parameters.
Array<Array<number>> | undefined.
- L.LatLngBounds in array form of all visible maps
Gets the HTML canvas element of the layer
There are no parameters.
HTML Canvas Element (HTMLCanvasElement | undefined).
Gets the HTML container element of the layer
There are no parameters.
HTML Div Element (HTMLDivElement | undefined).
Gets the opacity of a single map
mapId(string)- ID of the map
opacity of the map (number | undefined).
Returns the z-index of a single map
mapId(string)- ID of the map
number | undefined.
- z-index of the map
Gets the opacity of the layer
There are no parameters.
Layer opacity (number).
Gets the pane name the layer is attached to. Defaults to 'tilePane'
There are no parameters.
Pane name (string).
Returns a single map's warped map
mapId(string)- ID of the map
the warped map (WebGL2WarpedMap | undefined).
Returns the WarpedMapList object that contains a list of the warped maps of all loaded maps
There are no parameters.
WarpedMapList<WebGL2WarpedMap>.
Gets the z-index of the layer.
There are no parameters.
number | undefined.
WebGL2RenderingContext | null | undefinedMake a single map invisible
mapId(string)- ID of the map
void.
Make multiple maps invisible
mapIds(Iterable<string>)- IDs of the maps
void.
annotationOrAnnotationUrl(unknown)options?(Partial<LeafletWarpedMapLayerOptions> | undefined)
void.
Returns the visibility of a single map
mapId(string)
boolean | undefined.
- whether the map is visible
Contains all code code that creates DOM elements for the layer and adds them to map panes where they belong.
map(Map)
this.
Contains all cleanup code that removes the layer's elements from the DOM.
map(Map)
this.
className(string)interactive(false)opacity(number)pane(string)zIndex(number)
Removes a Georeference Annotation.
annotation(unknown)- Georeference Annotation
Promise<Array<string | Error>>.
- the map IDs of the maps that were removed, or an error per map
Removes a Georeference Annotation by URL.
annotationUrl(string)- Georeference Annotation
The map IDs of the maps that were removed, or an error per map (Promise<Array<string | Error>>).
Removes a Georeferenced map.
georeferencedMap(unknown)- Georeferenced map
The map ID of the map that was removed, or an error (Promise<string | Error>).
WebGL2Renderer | undefinedResets the colorization for all maps
There are no parameters.
this.
Resets the colorization of a single map
mapId(string)- ID of the map
this.
Resets the opacity of a single map to 1
mapId(string)- ID of the map
this.
Resets the color removal for a single map
mapId(string)- ID of the map
this.
Resets the saturation of a single map to the original colors
mapId(string)- ID of the map
this.
Resets the opacity of the layer to fully opaque
There are no parameters.
this.
Resets the color removal for all maps
There are no parameters.
this.
Resets the saturation of a single map to the original colors
There are no parameters.
this.
ResizeObserver | undefinedSend maps backward
mapIds(Iterable<string>)- IDs of the maps
void.
Send maps to back
mapIds(Array<string>)- IDs of the maps
void.
Sets the colorization for all maps
hexColor(string)- desired hex color
this.
Sets the object that caches image information
imageInformations(globalThis.Map<string, unknown>)- Object that caches image information
void.
Sets the colorization for a single map
mapId(string)- ID of the map
hexColor(string)- desired hex color
this.
Sets the opacity of a single map
mapId(string)- ID of the map
opacity(number)- opacity between 0 and 1, where 0 is fully transparent and 1 is fully opaque
this.
Removes a color from a single map
mapId(string)- ID of the map
options({ hexColor?: string | undefined threshold?: number | undefined hardness?: number | undefined })- remove color options
this.
Sets the resource mask of a single map
mapId(string)- ID of the map
resourceMask(Array<Point>)- new resource mask
void.
Sets the saturation of a single map
mapId(string)- ID of the map
saturation(number)- saturation between 0 and 1, where 0 is grayscale and 1 are the original colors
this.
Sets the distortion measure of multiple maps
mapIds(Iterable<string>)- IDs of the maps
distortionMeasure?(DistortionMeasure | undefined)- new transformation type
void.
Sets the transformation type of multiple maps
mapIds(Iterable<string>)- IDs of the maps
transformation(| 'straight' | 'helmert' | 'polynomial' | 'polynomial1' | 'polynomial2' | 'polynomial3' | 'projective' | 'thinPlateSpline')- new transformation type
void.
Sets the opacity of the layer
opacity(number)- Layer opacity
this.
Removes a color from all maps
options({ hexColor?: string | undefined threshold?: number | undefined hardness?: number | undefined })- remove color options
this.
Sets the saturation of a single map
saturation(number)- saturation between 0 and 1, where 0 is grayscale and 1 are the original colors
this.
Changes the z-index of the layer.
value(number)- z-index
this.
Make a single map visible
mapId(string)- ID of the map
void.
Make multiple maps visible
mapIds(Iterable<string>)- IDs of the maps
void.
