1.0.0-beta.66 • Published 2 months ago

@allmaps/openlayers v1.0.0-beta.66

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
2 months ago

@allmaps/openlayers

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.

Example of the Allmaps plugin for OpenLayers

Examples:

How it works

This plugin exports the classes WarpedMapLayer and WarpedMapSource. You can add one or multiple Georeference Annotations (or AnnotationPages that contain multiple Georeference Annotations) to a WarpedMapSource, add this WarpedMapSource to a WarpedMapLayer and this 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.

Installation

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 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 warpedMapSource = new Allmaps.WarpedMapSource()

Usage

Built for OpenLayers 8, but should work with OpenLayers 6 and OpenLayers 7 as well.

Loading a Georeference Annotation

Creating a WarpedMapLayer and WarpedMapSource and adding them to a map looks like this:

import { WarpedMapLayer, WarpedMapSource } 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 WarpedMapSource and WarpedMapLayer
const warpedMapSource = new allmapsOpenLayers.WarpedMapSource()
const warpedMapLayer = new allmapsOpenLayers.WarpedMapLayer({
  source: warpedMapSource
})

// Add layer to map and Georeference Annotation to source
const annotationUrl = 'https://annotations.allmaps.org/maps/a9458d2f895dcdfb'
map.addLayer(warpedMapLayer)
warpedMapSource.addGeoreferenceAnnotationByUrl(annotationUrl)

A Georeference Annotation can be added to a WarpedMapSource using the addGeoreferenceAnnotation and addGeoreferenceAnnotationByUrl functions:

fetch(annotationUrl)
  .then((response) => response.json())
  .then((annotation) => warpedMapSource.addGeoreferenceAnnotation(annotation))

Or:

await warpedMapSource.addGeoreferenceAnnotationByUrl(annotationUrl)

Events

The following events are emitted to inform you of the state of the WarpedMapLayer, WarpedMapSource and rendering.

DescriptionTypeData
A warped map has been added to the warped map listwarpedmapaddedmapId: string
A warped map has been removed from the warped map listwarpedmapremovedmapId: string
A warped map enters the viewportwarpedmapentermapId: string
A warped map leaves the viewportwarpedmapleavemapId: string
The visibility of some warpedMaps has changedvisibilitychangedmapIds: string[]
The cache loaded a first tile of a mapfirstmaptileloaded{mapId: string, tileUrl: string}
All tiles requested for the current viewport have been loadedallrequestedtilesloaded

You can listen to them in the typical OpenLayers way. Here's an example:

map.on(
  'warpedmapadded',
  (event) => {
    console.log(event.mapId, warpedMapSource.getExtent())
  },
  map
)

Some of the functions specified in the API only make sense once a warped map is loaded into the WarpedMapSource. You can use such listeners to make sure function are run e.g. only after a warped map has been added.

What is a map?

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 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.

API

Table of Contents

Point

Point

Type: [number, number]

Bbox

Bounding box

Type: [number, number, number, number]

TransformationType

Transformation type

Type: ("helmert" | "polynomial" | "polynomial1" | "polynomial2" | "polynomial3" | "projective" | "thinPlateSpline")

WarpedMapLayer

WarpedMapLayer class.

Together with a WarpedMapSource, this class renders georeferenced maps of a IIIF Georeference Annotation on an OpenLayers map. WarpedMapLayer is a subclass of Layer.

getContainer

Gets the HTML container element of the layer

Returns HTMLElement HTML Div Element

getCanvas

Gets the HTML canvas element of the layer

Returns (HTMLCanvasElement | null) HTML Canvas Element

getMapOpacity

Gets the opacity of a single map

Parameters

Returns (number | undefined) opacity of the map

setMapOpacity

Sets the opacity of a single map

Parameters
  • mapId string ID of the map
  • opacity number opacity between 0 and 1, where 0 is fully transparent and 1 is fully opaque

resetMapOpacity

Resets the opacity of a single map to fully opaque

Parameters

setSaturation

Sets the saturation of a single map

Parameters
  • saturation number saturation between 0 and 1, where 0 is grayscale and 1 are the original colors

resetSaturation

Resets the saturation of a single map to the original colors

setMapSaturation

Sets the saturation of a single map

Parameters
  • mapId string ID of the map
  • saturation number saturation between 0 and 1, where 0 is grayscale and 1 are the original colors

resetMapSaturation

Resets the saturation of a single map to the original colors

Parameters

setRemoveColor

Removes a color from all maps

Parameters
  • options Object remove color options

    • options.hexColor string? hex color to remove
    • options.threshold number? threshold between 0 and 1
    • options.hardness number? hardness between 0 and 1

resetRemoveColor

Resets the color removal for all maps

setMapRemoveColor

Removes a color from a single map

Parameters
  • mapId string ID of the map
  • options Object remove color options

    • options.hexColor string? hex color to remove
    • options.threshold number? threshold between 0 and 1
    • options.hardness number? hardness between 0 and 1

resetMapRemoveColor

Resets the color for a single map

Parameters

setColorize

Sets the colorization for all maps

Parameters
  • hexColor string desired hex color

resetColorize

Resets the colorization for all maps

setMapColorize

Sets the colorization for a single mapID of the map

Parameters

resetMapColorize

Resets the colorization of a single map

Parameters

dispose

Disposes all WebGL resources and cached tiles

render

Render the layer.

Parameters
  • frameState

Returns HTMLElement The rendered element

WarpedMapSource

WarpedMapSource class. Together with a WarpedMapLayer, this class renders a warped map on an OpenLayers map.

addGeoreferenceAnnotation

Adds a Georeference Annotation.

Parameters
  • annotation any Georeference Annotation

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

removeGeoreferenceAnnotation

Removes a Georeference Annotation.

Parameters
  • annotation any Georeference Annotation

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

addGeoreferenceAnnotationByUrl

Adds a Georeference Annotation by URL.

Parameters
  • annotationUrl string Georeference Annotation

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

removeGeoreferenceAnnotationByUrl

Removes a Georeference Annotation by URL.

Parameters
  • annotationUrl string Georeference Annotation

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

addGeoreferencedMap

Adds a Georeferenced map.

Parameters
  • georeferencedMap unknown Georeferenced map

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

removeGeoreferencedMap

Removes a Georeferenced map.

Parameters
  • georeferencedMap unknown Georeferenced map

Returns Promise<(string | Error)> the map ID of the map that was remvoed, or an error

getWarpedMapList

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

Returns WarpedMapList the warped map list

getWarpedMap

Returns a single map's warped map

Parameters

Returns (WarpedMap | undefined) the warped map

showMap

Make a single map visible

Parameters

showMaps

Make multiple maps visible

Parameters

hideMap

Make a single map invisible

Parameters

hideMaps

Make multiple maps invisible

Parameters

isMapVisible

Returns the visibility of a single map

Parameters
  • mapId

Returns (boolean | undefined) whether the map is visible

setMapResourceMask

Sets the resource mask of a single map

Parameters
  • mapId string ID of the map
  • resourceMask Ring new resource mask

setMapsTransformationType

Sets the transformation type of multiple maps

Parameters

getLonLatExtent

Return the bounding box of all visible maps in the layer (inside or outside of the Viewport), in longitude/latitude coordinates.

Returns (Bbox | undefined) Bounding box of all warped maps

getExtent

Return the bounding box of all visible maps in the layer (inside or outside of the Viewport), in projected coordinates.

Returns (Bbox | undefined) bounding box of all warped maps

bringMapsToFront

Bring maps to front

Parameters

sendMapsToBack

Send maps to back

Parameters

bringMapsForward

Bring maps forward

Parameters

sendMapsBackward

Send maps backward

Parameters

getMapZIndex

Returns the z-index of a single map

Parameters
  • mapId string ID of the warped map

Returns (number | undefined) z-index of the warped map

setImageInfoCache

Sets the image info Cache of the WarpedMapList

Parameters
  • cache Cache the image info cache

clear

Clears the source, removes all maps

1.0.0-beta.66

2 months ago

1.0.0-beta.64

2 months ago

1.0.0-beta.65

2 months ago

1.0.0-beta.62

2 months ago

1.0.0-beta.60

2 months ago

1.0.0-beta.59

2 months ago

1.0.0-beta.55

3 months ago

1.0.0-beta.56

3 months ago

1.0.0-beta.53

3 months ago

1.0.0-beta.54

3 months ago

1.0.0-beta.51

3 months ago

1.0.0-beta.52

3 months ago

1.0.0-beta.57

3 months ago

1.0.0-beta.58

3 months ago

1.0.0-beta.50

3 months ago

1.0.0-beta.49

3 months ago

1.0.0-beta.48

4 months ago

1.0.0-beta.47

4 months ago

1.0.0-beta.44

6 months ago

1.0.0-beta.45

6 months ago

1.0.0-beta.43

7 months ago

1.0.0-beta.40

7 months ago

1.0.0-beta.41

7 months ago

1.0.0-beta.34

9 months ago

1.0.0-beta.39

7 months ago

1.0.0-beta.38

8 months ago

1.0.0-beta.35

9 months ago

1.0.0-beta.36

8 months ago

1.0.0-beta.33

12 months ago

1.0.0-beta.32

1 year ago

1.0.0-beta.22

1 year ago

1.0.0-beta.28

1 year ago

1.0.0-beta.29

1 year ago

1.0.0-beta.26

1 year ago

1.0.0-beta.27

1 year ago

1.0.0-beta.24

1 year ago

1.0.0-beta.31

1 year ago

1.0.0-beta.30

1 year ago

1.0.0-beta.20

2 years ago

1.0.0-beta.21

1 year ago

1.0.0-beta.19

2 years ago

1.0.0-beta.18

2 years ago

1.0.0-beta.16

2 years ago

1.0.0-beta.14

2 years ago

1.0.0-beta.13

2 years ago

1.0.0-beta.12

2 years ago

1.0.0-beta.11

2 years ago

1.0.0-beta.10

2 years ago

1.0.0-beta.9

2 years ago

1.0.0-beta.8

2 years ago

1.0.0-beta.7

2 years ago

1.0.0-beta.6

2 years ago

1.0.0-beta.5

2 years ago

1.0.0-beta.4

2 years ago

1.0.0-beta.3

2 years ago