@allmaps/annotation

中文文档
1.0.0-beta.38发布于 2026/09/22MITES Module近 30 天下载 1.2万

Functions for generating and parsing IIIF georeference annotations

原始使用文档
文档目录22 节
  1. How it works
  2. Installation
  3. Usage
  4. License
  5. API
  6. Annotation
  7. AnnotationPage
  8. AnnotationPageSchema
  9. AnnotationSchema
  10. FeaturePropertiesSchema
  11. GCPSchema
  12. GeoreferencedMap
  13. GeoreferencedMapSchema
  14. GeoreferencedMapsSchema
  15. PartOf
  16. PartOfItem
  17. ResourceSchema
  18. SvgSelectorSchema
  19. generateAnnotation(mapOrMaps)
  20. parseAnnotation(annotation)
  21. validateAnnotation(annotation)
  22. validateGeoreferencedMap(mapOrMaps)

@allmaps/annotation

Parsing and Generating Georeference Annotations.

How it works

This module that can generate and parse Georeference Annotations.

A Georeference Annotation is a Web Annotation that stores the metadata needed to georeference a IIIF image. See this example.

A Georeference Annotation contains the following data:

  • The URI of an IIIF Image, as well as its dimensions in pixels.
  • A polygonal resource mask that defines the cartographic part of the image.
  • A list of ground control points (GCPs) that define the mapping between resource coordinates and geospatial coordinates.

Multiple maps can be defined in an Annotation Page (see spec).

Allmaps offers apps and packages for working with Georeference Annotations. Allmaps Viewer can for example warp IIIF maps in the browser, just by loading a Georeference Annotation.

A Georeferenced Map is the format Allmaps uses internally to describe a map and pass it between functions and packages. It contains the same information in a more practical form. See this example.

This module allows parsing Georeference Annotations to Georeferenced Maps and generating Georeference Annotations from Georeferenced Maps.

This module is written in TypeScript and is built using Zod.

Installation

This is an ESM-only module that works in browsers and in Node.js.

Node.js:

Install with pnpm:

pnpm install @allmaps/annotation

Browser:

<script type="module">
  import { Annotation } from 'https://unpkg.com/@allmaps/annotation?module'
</script>

Usage

import { parseAnnotation, generateAnnotation } from '@allmaps/annotation'

// Fetch an annotation
const annotation = await fetch(annoationUrl).then((response) => response.json())

// Create a georeferencedMap from the annotation
const georeferencedMaps = parseAnnotation(annotation)
const georeferencedMap = georeferencedMaps[0]

// Use or modify the georeferencedMap(s)
// ...

// Generate Georeference Annotation
// Note: returns an annotation or annotation page based on input
const georeferenceAnnotation = generateAnnotation(georeferencedMap)
const georeferenceAnnotationPage = generateAnnotation(georeferencedMaps)

See the API below for more details.

License

MIT

API

Annotation

Type
{ id?: string | undefined; type: "Annotation"; '@context'?: string | Array<string> | undefined; motivation?: string | undefined; created?: string | undefined; modified?: string | undefined; target: { ...; }; body: { ...; }; }

AnnotationPage

Type
{ id?: string | undefined; type: "AnnotationPage"; '@context'?: string | Array<string> | undefined; items: Array<{ id?: string | undefined; type: "Annotation"; '@context'?: string | Array<string> | undefined; motivation?: string | undefined; created?: string | undefined; modified?: string | undefined; target: { ...;...

AnnotationPageSchema

Type
AnnotationPage1Schema

AnnotationSchema

Type
Annotation1Schema

FeaturePropertiesSchema

Type
Annotation1FeaturePropertiesSchema

GCPSchema

Type
GeoreferencedMap2GCPSchema

GeoreferencedMap

Type
{ '@context'?: "https://schemas.allmaps.org/map/2/context.json" | undefined; type: "GeoreferencedMap"; id?: string | undefined; created?: string | undefined; modified?: string | undefined; ... 5 more ...; _allmaps?: unknown; }

GeoreferencedMapSchema

Type
GeoreferencedMap2Schema

GeoreferencedMapsSchema

Type
GeoreferencedMaps2Schema

PartOf

Type
Array<PartOfItemType>

PartOfItem

Type
{
  id: string
  type: string
  label?: z.infer<typeof LanguageValueSchema>
  partOf?: PartOfItemType[]
}

ResourceSchema

Type
GeoreferencedMap2ResourceSchema

SvgSelectorSchema

Type
SvgSelector1Schema

generateAnnotation(mapOrMaps)

Generates a Georeference Annotation from a single Georeferenced Map or an Annotation Page containing multiple Georeference Annotations from an array of Georeferenced Maps.

Parameters
  • mapOrMaps (unknown)
    • Single Georeferenced Map, or an array of Georeferenced Maps
Returns

Georeference Annotation or Annotation Page ({ id?: string | undefined; type: "Annotation"; '@context'?: string | Array<string> | undefined; motivation?: string | undefined; created?: string | undefined; modified?: string | undefined; target: { ...; }; body: { ...; }; } | { ...; }).

Examples
import fs from 'fs'
import { generateAnnotation } from '@allmaps/annotation'

const map = JSON.parse(fs.readFileSync('./examples/map.example.json'))
const annotation = generateAnnotation(map)

parseAnnotation(annotation)

Parses a Georeference Annotation or an Annotation Page containing multiple Georeference Annotations and returns an array of Georeferenced Maps.

Parameters
  • annotation (unknown)
    • Georeference Annotation or Annotation Page containing multiple Georeference Annotations
Returns

Array of maps (Array<{ '@context'?: "https://schemas.allmaps.org/map/2/context.json" | undefined; type: "GeoreferencedMap"; id?: string | undefined; created?: string | undefined; modified?: string | undefined; ... 5 more ...; _allmaps?: unknown; }>).

Examples
import fs from 'fs'
import { parseAnnotation } from '@allmaps/annotation'

const annotation = JSON.parse(fs.readFileSync('./examples/annotation.example.json'))
const maps = parseAnnotation(annotation)

validateAnnotation(annotation)

Parameters
  • annotation (unknown)
Returns

{ id?: string | undefined; type: "Annotation"; '@context'?: string | Array<string> | undefined; motivation?: string | undefined; created?: string | undefined; modified?: string | undefined; target: { ...; }; body: { ...; }; } | { ...; }.

validateGeoreferencedMap(mapOrMaps)

Parameters
  • mapOrMaps (unknown)
Returns

Array<{ '@context'?: "https://schemas.allmaps.org/map/2/context.json" | undefined; type: "GeoreferencedMap"; id?: string | undefined; created?: string | undefined; modified?: string | undefined; ... 5 more ...; _allmaps?: unknown; }> | { '@context'?: "https://schemas.allmaps.org/map/2/context.json" | undefined; type....

版本与发布记录

@allmaps/annotation 共发布 53 个版本,首次发布于 2021/01/28;过去 12 个月发布了 3 个版本。

版本发布日期距今
1.0.0-beta.38latest2026/09/221 个月前
1.0.0-beta.372026/05/295 个月前
1.0.0-beta.362025/11/1111 个月前
1.0.0-beta.352025/07/101.3 年前
1.0.0-beta.342025/07/071.3 年前
1.0.0-beta.33beta2025/05/221.5 年前

关于 @allmaps/annotation 的常见问题

@allmaps/annotation 是什么?

Functions for generating and parsing IIIF georeference annotations

如何安装 @allmaps/annotation?

在项目目录运行 npm install @allmaps/annotation,或使用 pnpm add / yarn add / bun add。

@allmaps/annotation 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/allmaps__annotation 是否存在。

@allmaps/annotation 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@allmaps/annotation 可以商用吗?

@allmaps/annotation 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@allmaps/annotation 的下载量有多少?

根据 npm 官方下载统计,@allmaps/annotation 在 2026/10/06 – 2026/11/04 这 30 天内被下载 11,936 次,日均约 398 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@allmaps/annotation 还在维护吗?

最新版本 1.0.0-beta.38 发布于 2026/09/22(1 个月前);至今共发布 53 个版本,其中过去 12 个月发布了 3 个;首次发布于 2021/01/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。