npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@allmaps/openlayers

v1.0.0-beta.73

Published

OpenLayers classes for Allmaps

Downloads

204

Readme

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

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 warpedMapLayer = new Allmaps.WarpedMapLayer()

Usage

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

Loading a Georeference Annotation

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)

Events

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())
})

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

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.

This class renders georeferenced maps from a Georeference Annotation on an OpenLayers map. WarpedMapLayer is a subclass of Layer.

Parameters

  • options WebGL2RendererOptions? the WebGL2 renderer options

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 (WebGL2WarpedMap | undefined) the warped map

showMap

Make a single map visible

Parameters

showMaps

Make multiple maps visible

Parameters
  • mapIds Iterable<string> IDs of the maps

hideMap

Make a single map invisible

Parameters

hideMaps

Make multiple maps invisible

Parameters
  • mapIds Iterable<string> IDs of the maps

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

setMapsDistortionMeasure

Sets the distortion measure of multiple maps

Parameters
  • mapIds Iterable<string> IDs of the maps
  • distortionMeasure DistortionMeasure new distortion measure

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
  • mapIds Iterable<string> IDs of the maps

sendMapsToBack

Send maps to back

Parameters
  • mapIds Iterable<string> IDs of the maps

bringMapsForward

Bring maps forward

Parameters
  • mapIds Iterable<string> IDs of the maps

sendMapsBackward

Send maps backward

Parameters
  • mapIds Iterable<string> IDs of the maps

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

setImageInformations

Sets the object that caches image information

Parameters
  • imageInformations ImageInformations Object that caches image information

getContainer

Gets the HTML container element of the layer

Returns HTMLElement HTML 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

  • transformOptions Object remove color options

    • transformOptions.hexColor string? hex color to remove
    • transformOptions.threshold number? threshold between 0 and 1
    • transformOptions.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

  • transformOptions Object remove color options

    • transformOptions.hexColor string? hex color to remove
    • transformOptions.threshold number? threshold between 0 and 1
    • transformOptions.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

setGrid

Sets the grid for all maps

Parameters
  • enabled boolean whether to show the grid

resetGrid

Resets the grid for all maps

setMapGrid

Sets the grid for a single mapID of the map

Parameters
  • mapId string ID of the map
  • enabled boolean whether to show the grid

resetMapGrid

Resets the grid of a single map

Parameters

dispose

Disposes all WebGL resources and cached tiles

clear

Clears: removes all maps

render

Render the layer.

Parameters
  • frameState

Returns HTMLElement The rendered element