@allmaps/bearing

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

Compute bearing of georeferenced map

原始使用文档
文档目录9 节
  1. How it works
  2. Installation
  3. Usage
  4. License
  5. API
  6. BearingOptions
  7. DEFAULT_BEARING_OPTIONS
  8. computeGeoreferencedMapBearing(georeferencedMap, options)
  9. computeWarpedMapBearing(warpedMap, options)

@allmaps/bearing

Computes the bearing of a Georeferenced Map or Warped Map.

The bearing is returned in degrees, measured from the north line (by default) in the clockwise direction.

Example of a map with a bearing of 30°

How it works

The bearing is computed by taking a vertical and horizontal straight line between two points in resource space, transforming these to projected geographic space, and computing the clockwise (a.k.a. negative) angle they form with the respective vertical and horizontal axis in projected geographic space.

From the description above it follows that the bearing computed in this package is a grid bearing, computed relative to the map projection's vertical line. Since the default projection for warped maps (and their projected transformers) is WebMercator (see @allmaps/render) this vertical axis points to the true north and the resulting bearing is a classical absolute true bearing (clockwise angles from true north). For non-standard projections, specify a projection in the options to obtain the grid bearing in that projection, and correct with the true north bearing at the maps center to obtain the absolute true bearing.

For rendering purposes it is desirable to consider how both horizontal and vertical resource space lines are transformed and define the bearing as the (angular) mean between both angles. In some contexts, e.g. for skewed maps with polynomial transformation where vertical resource axis pointed north, one might be interested in only considering the vertical resource line. This can be specified in the options.

Installation

This package works in browsers and in Node.js as an ESM module.

Install with pnpm:

pnpm install @allmaps/bearing

Usage

import { parseAnnotation } from '@allmaps/annotation'
import { computeGeoreferencedMapBearing } from '@allmaps/bearing'

const annotation = await fetch(
  'https://annotations.allmaps.org/maps/95eeba91177d2a1d'
).then((response) => response.json())

const georeferencedMaps = parseAnnotation(annotation)
const georeferencedMap = georeferencedMaps[0]
const bearing = computeGeoreferencedMapBearing(georeferencedMap)
// bearing = 30.48243288240172

License

MIT

API

BearingOptions

Type
Partial<MaskOptions> & {orientation?: 'horizontal' | 'vertical'}

DEFAULT_BEARING_OPTIONS

Type
any

computeGeoreferencedMapBearing(georeferencedMap, options)

Compute the bearing of a Georeferenced Map.

Parameters
  • georeferencedMap ({ '@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; })
    • Georeferenced Map
  • options? (Partial<Partial<MaskOptions> & { orientation?: "horizontal" | "vertical"; } & { internalProjection: Projection; projection: Projection; } & { ...; } & { ...; } & MultiGeometryOptions & TransformationTypeInputs> | undefined)
Returns

The bearing of the map in degrees, measured in degrees from the north line in the clockwise (negative) direction (number).

computeWarpedMapBearing(warpedMap, options)

Compute the bearing of a Warped Map.

Parameters
  • warpedMap (WarpedMap)
    • Warped Map
  • options? (Partial<Partial<MaskOptions> & { orientation?: "horizontal" | "vertical"; } & { internalProjection: Projection; projection: Projection; } & { ...; } & { ...; } & MultiGeometryOptions & TransformationTypeInputs> | undefined)
Returns

The bearing of the map in degrees, measured in degrees from the north line in the clockwise (negative) direction (number).

版本与发布记录

@allmaps/bearing 共发布 12 个版本,首次发布于 2025/03/12;过去 12 个月发布了 6 个版本。

版本发布日期距今
1.0.0-beta.13latest2026/09/221 个月前
1.0.0-beta.122026/05/295 个月前
1.0.0-beta.112026/02/108 个月前
1.0.0-beta.102025/12/1010 个月前
1.0.0-beta.92025/11/2711 个月前
1.0.0-beta.82025/11/1111 个月前

其他发布通道:beta → 1.0.0-beta.4。

关于 @allmaps/bearing 的常见问题

@allmaps/bearing 是什么?

Compute bearing of georeferenced map

如何安装 @allmaps/bearing?

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

@allmaps/bearing 支持 TypeScript 吗?

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

@allmaps/bearing 支持 ESM 还是 CommonJS?

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

@allmaps/bearing 可以商用吗?

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

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

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

@allmaps/bearing 还在维护吗?

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