Allmaps plugin for OpenLayers. Plugin that uses WebGL to show warped IIIF images on an OpenLayers map. The plugin works by loading Georeference Annotations.
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.
Examples:
This plugin exports the class WarpedMapLayer
. You can add one or multiple Georeference Annotations (or AnnotationPages that contain multiple Georeference Annotations) to a WarpedMapLayer and add the WarpedMapLayer to your OpenLayers 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:
pnpm install @allmaps/openlayers
You can optionally build this package locally by running:
pnpm run build
As 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.
<script src="https://cdn.jsdelivr.net/npm/@allmaps/openlayers/dist/bundled/allmaps-openlayers-8.umd.js"></script>
When loading the bundled package, its classes are available under the Allmaps
global variable:
const warpedMapLayer = new Allmaps.WarpedMapLayer()
Built for OpenLayers 8, but should work with OpenLayers 6 and OpenLayers 7 as well.
Creating a WarpedMapLayer
and adding a Georeference Annotation to an OpenLayers map looks like this:
import { WarpedMapLayer } from '@allmaps/openlayers'
const map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([-71.00661, 42.37124]),
zoom: 14
})
})
// Create WarpedMapLayer
const warpedMapLayer = new WarpedMapLayer()
// Add the WarpedMapLayer to the map and load a Georeference Annotation
const annotationUrl = 'https://annotations.allmaps.org/maps/a9458d2f895dcdfb'
map.addLayer(warpedMapLayer)
warpedMapLayer.addGeoreferenceAnnotationByUrl(annotationUrl)
A Georeference Annotation can be added 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 warpedMaps 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 OpenLayers way. Here's an example:
warpedMapLayer.on('warpedmapadded', (event) => {
console.log(event.mapId, warpedMapLayer.getExtent())
})
An OpenLayers map is an instance of the OpenLayers Map
class, the central class of the OpenLayers 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 Georeferenced Map class is created from it.
- When this map is loaded into an application for rendering, an instance of the Warped Map class is created from it.
- Inside the WebGL2 rendering package, 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 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.
type
(string
)data
(unknown
)
OLWarpedMapEvent
.
Event
unknown
type
(WarpedMapEventType
)data?
(unknown
)
WarpedMapEvent
.
Event
unknown
Creates a WarpedMapLayer instance
options?
(Partial<RendererOptions> | undefined
)- the WebGL2 renderer options
WarpedMapLayer
.
Layer
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
Promise<Array<string | Error>>
.
- the map IDs of the maps that were added, or an error per map
Adds a Georeferenced map.
georeferencedMap
(unknown
)- Georeferenced map
Promise<string | Error>
.
- the map ID of the map that was added, or an error
Bring maps forward
mapIds
(Iterable<string>
)- IDs of the maps
void
.
Bring maps to front
mapIds
(Iterable<string>
)- IDs of the maps
void
.
HTMLCanvasElement
[number, number]
Clears: removes all maps
There are no parameters.
void
.
HTMLElement
event
(Event
)
void
.
event
(Event
)
void
.
Disposes all WebGL resources and cached tiles
There are no parameters.
void
.
Gets the HTML canvas element of the layer
There are no parameters.
HTML Canvas element (HTMLCanvasElement | null
).
Gets the HTML container element of the layer
There are no parameters.
HTML element (HTMLElement
).
Return the bounding box of all visible maps in the layer (inside or outside of the Viewport), in projected coordinates.
There are no parameters.
Extent | undefined
.
- bounding box of all warped maps
Return the bounding box of all visible maps in the layer (inside or outside of the Viewport), in longitude/latitude coordinates.
There are no parameters.
Extent | undefined
.
- Bounding box of all warped maps
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 warped map
number | undefined
.
- z-index of the warped map
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.
the warped map list (WarpedMapList<WebGL2WarpedMap>
).
WebGL2RenderingContext
Make a single map invisible
mapId
(string
)- ID of the map
void
.
Make multiple maps invisible
mapIds
(Iterable<string>
)- IDs of the maps
void
.
Returns the visibility of a single map
mapId
(string
)
boolean | undefined
.
- whether the map is visible
event
(Event
)
void
.
There are no parameters.
void
.
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
Promise<Array<string | Error>>
.
- the map IDs of the maps that were removed, or an error per map
Removes a Georeferenced map.
georeferencedMap
(unknown
)- Georeferenced map
Promise<string | Error>
.
- the map ID of the map that was remvoed, or an error
mapId
(string
)
void
.
Render the layer.
frameState
({ pixelRatio: number; time: number; viewState: State; animate: boolean; coordinateToPixelTransform: Transform; ... 14 more ...; renderTargets: { [x: string]: boolean; }; }
)- OpenLayers frame state
The rendered element (HTMLElement
).
WebGL2Renderer
Resets the colorization for all maps
There are no parameters.
void
.
Resets the grid for all maps
There are no parameters.
void
.
Resets the colorization of a single map
mapId
(string
)- ID of the map
void
.
Resets the grid of a single map
mapId
(string
)- ID of the map
void
.
Resets the opacity of a single map to fully opaque
mapId
(string
)- ID of the map
void
.
Resets the color for a single map
mapId
(string
)- ID of the map
void
.
Resets the saturation of a single map to the original colors
mapId
(string
)- ID of the map
void
.
Resets the color removal for all maps
There are no parameters.
void
.
Resets the saturation of a single map to the original colors
There are no parameters.
void
.
canvas
(HTMLCanvasElement
)undefined
([number, number]
)
boolean
.
ResizeObserver
entries
(Array<ResizeObserverEntry>
)
void
.
Send 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
void
.
Sets the grid for all maps
enabled
(boolean
)- whether to show the grid
void
.
Sets the object that caches image information
imageInformations
(Map<string, unknown>
)- Object that caches image information
void
.
Sets the colorization for a single mapID of the map
mapId
(string
)- ID of the map
hexColor
(string
)- desired hex color
void
.
Sets the GCOs of a single map
mapId
(string
)- ID of the map
gcps
(Array<Gcp>
)
void
.
Sets the grid for a single mapID of the map
mapId
(string
)- ID of the map
enabled
(boolean
)- whether to show the grid
void
.
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
void
.
Removes a color from a single map
mapId
(string
)- ID of the map
options
({ hexColor?: string | undefined threshold?: number | undefined hardness?: number | undefined }
)
void
.
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
void
.
Sets the transformation type of a single map
mapId
(string
)- ID of the map
transformation
(| 'straight' | 'helmert' | 'polynomial' | 'polynomial1' | 'polynomial2' | 'polynomial3' | 'projective' | 'thinPlateSpline'
)- new transformation type
void
.
Sets the distortion measure of multiple maps
mapIds
(Iterable<string>
)- IDs of the maps
distortionMeasure?
(DistortionMeasure | undefined
)- new distortion measure
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
.
Removes a color from all maps
options
({ hexColor?: string | undefined threshold?: number | undefined hardness?: number | undefined }
)
void
.
Sets the saturation of a single map
saturation
(number
)- saturation between 0 and 1, where 0 is grayscale and 1 are the original colors
void
.
Make a single map visible
mapId
(string
)- ID of the map
void
.
Make multiple maps visible
mapIds
(Iterable<string>
)- IDs of the maps
void
.