@allmaps/maplibre
Allmaps plugin for MapLibre GL. This plugin allows displaying georeferenced IIIF images on a MapLibre 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.
Examples:
How it works
Section titled “How it works”This plugin creates a new class WarpedMapLayer which extends MapLibre’s CustomLayerInterface. You can add one or multiple Georeference Annotations (or AnnotationPages with multiple Georeference Annotations) to a WarpedMapLayer, and add the WarpedMapLayer to your MapLibre map. This will render all georeferenced maps contained in the Georeference Annotation on your MapLibre map.
To understand what happens under the hood for each georeferenced map, see the @allmaps/render package.
Installation
Section titled “Installation”This package works in browsers and in Node.js as an ESM or an UMD module.
Install with pnpm:
pnpm install @allmaps/maplibreYou can optionally build this package locally by running:
pnpm run buildBuilt for MapLibre 4.0, but should work with earlier versions as well.
Loading a Georeference Annotation
Section titled “Loading a Georeference Annotation”Creating a WarpedMapLayer and adding it to a map looks like this:
import { WarpedMapLayer } from '@allmaps/maplibre'
// MapLibre map with base layerconst map = new maplibregl.Map({ container: 'map', style: 'https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json', center: [-73.9337, 40.8011], zoom: 11.5, // Pitch is currently not supported by the Allmaps plugin for MapLibre maxPitch: 0})
const annotationUrl = 'https://annotations.allmaps.org/images/d180902cb93d5bf2'const warpedMapLayer = new WarpedMapLayer()
map.on('load', () => { map.addLayer(warpedMapLayer) warpedMapLayer.addGeoreferenceAnnotationByUrl(annotationUrl)})WarpedMapLayer is implemented using MapLibre’s CustomLayerInterface. It can be added to a map like any other MapLibre layer, but there are some things to take into account:
WarpedMapLayerdoes not make use of a Source (although that could be implemented in the future, similar to @allmaps/openlayers).WarpedMapLayercurrently does not support pitch, so disable it on your map.- Just like other MapLibre layers, a WarpedMapLayer must have a unique
id. By default, theidhas the valuewarped-map-layer. When adding multiple WarpedMapLayers to your map, pass a uniqueidto their constructor: WarpedMapLayerdoes not make use of a Source (although that could be implemented in the future, similar to @allmaps/openlayers).WarpedMapLayercurrently does not support pitch, so disable it on your map.- Just like other MapLibre layers, a WarpedMapLayer must have a unique
id. By default, theidhas the valuewarped-map-layer. When adding multiple WarpedMapLayers to your map, pass a uniqueidto their constructor:
const warpedMapLayerWithUniqueId = new WarpedMapLayer({layerId: 'my-unique-id'})A Georeference Annotation can be added to a WarpedMapLayer using the addGeoreferenceAnnotation and addGeoreferenceAnnotationByUrl functions:
fetch(annotationUrl) .then((response) => response.json()) .then((annotation) => warpedMapLayer.addGeoreferenceAnnotation(annotation))Or:
await warpedMapLayer.addGeoreferenceAnnotationByUrl(annotationUrl)WarpedMapLayer API and Events
Section titled “WarpedMapLayer API and Events”See the @allmaps/warpedmaplayer package for the API documentation of the methods inherited from the WarpedMapLayer class (shared by all Allmaps plugins) and a list of events emitted by a WarpedMapLayer.
You can listen to them in the typical MapLibre way. Here’s an example:
warpedMapLayer.on('warpedmapadded', (event) => { console.log(event.mapIds, warpedMapLayer.getBounds())})License
Section titled “License”MIT
MapLibreWarpedMapLayerOptions
Section titled “MapLibreWarpedMapLayerOptions”SpecificMapLibreWarpedMapLayerOptions & Partial<WebGL2RenderOptions>new WarpedMapEvent(type, data)
Section titled “new WarpedMapEvent(type, data)”Parameters
Section titled “Parameters”type(WarpedMapEventType)data?(Partial<WarpedMapEventData> | undefined)
Returns
Section titled “Returns”WarpedMapEvent.
Extends
Section titled “Extends”Event
WarpedMapEvent#data?
Section titled “WarpedMapEvent#data?”{ mapIds?: Array<string> | undefined tileUrl?: string | undefined optionKeys?: Array<string> | undefined}new WarpedMapLayer(options)
Section titled “new WarpedMapLayer(options)”Creates a WarpedMapLayer instance
Parameters
Section titled “Parameters”options?(Partial<MapLibreWarpedMapLayerOptions> | undefined)- options
Returns
Section titled “Returns”WarpedMapLayer.
Extends
Section titled “Extends”BaseWarpedMapLayerCustomLayerInterface
WarpedMapLayer#getBounds()
Section titled “WarpedMapLayer#getBounds()”Get the bounding box of all maps as a MapLibre LngLatBoundsLike object
This is the default MapLibre getBounds() function
Result is in longitude/latitude EPSG:4326 coordinates.
Parameters
Section titled “Parameters”There are no parameters.
Returns
Section titled “Returns”bounding box of all warped maps (LngLatBoundsLike | undefined).
WarpedMapLayer#id
Section titled “WarpedMapLayer#id”stringWarpedMapLayer#map?
Section titled “WarpedMapLayer#map?”MaplibreMapWarpedMapLayer#nativePassWarpedMapEvent(event)
Section titled “WarpedMapLayer#nativePassWarpedMapEvent(event)”Pass events
Parameters
Section titled “Parameters”event(Event)
Returns
Section titled “Returns”void.
WarpedMapLayer#nativeUpdate()
Section titled “WarpedMapLayer#nativeUpdate()”Trigger the native update function of the map
Parameters
Section titled “Parameters”There are no parameters.
Returns
Section titled “Returns”void.
WarpedMapLayer#onAdd(map, gl)
Section titled “WarpedMapLayer#onAdd(map, gl)”Method called when the layer has been added to the Map.
Parameters
Section titled “Parameters”map(MaplibreMap)- The Map this custom layer was just added to.
gl(WebGL2RenderingContext)- The WebGL 2 context for the map.
Returns
Section titled “Returns”void.
WarpedMapLayer#onRemove()
Section titled “WarpedMapLayer#onRemove()”Method called when the layer has been removed from the Map.
Parameters
Section titled “Parameters”There are no parameters.
Returns
Section titled “Returns”void.
WarpedMapLayer#render()
Section titled “WarpedMapLayer#render()”Render the layer.
Parameters
Section titled “Parameters”There are no parameters.
Returns
Section titled “Returns”void.
WarpedMapLayer#renderingMode
Section titled “WarpedMapLayer#renderingMode”'2d'WarpedMapLayer#type
Section titled “WarpedMapLayer#type”'custom'