@bitbaum/geo-kit

中文文档
0.3.0发布于 2026/10/31MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 2257

Versioned, on-demand geography resources and sourced boundary assertions for web applications, and a Canvas 2D renderer for them (globe or map).

原始使用文档
文档目录6 节
  1. Install
  2. Ownership
  3. Data loading
  4. Drawing it: @bitbaum/geo-kit/map
  5. Assertions and proposed boundaries
  6. Verify

@bitbaum/geo-kit

Country-neutral contracts for sharing versioned geography data across applications, and one renderer for it (@bitbaum/geo-kit/map). The package owns no country packs, political claims, source choices, personal data, HTTP server, or UI framework.

Install

pnpm add @bitbaum/geo-kit

Install releases from npm, not a commit: a semver range is what lets a fix reach every product. @bitbaum/[email protected] is on npm; later releases are published by this repository's publish.yml.

Ownership

  • Solon is the authoritative owner of public places, source records, historical assertions, decisions, and published boundary resources.
  • OrangeCat remains the owner of private residence and account data.
  • Substrata and other clients consume public, versioned data and choose the layers they need. They do not copy Solon's geography database.
  • Application policy supplies accepted licences and controls whether a proposal is approved. This package does not make that decision.

Data loading

Publish a small manifest beside content-addressed GeoJSON or TopoJSON resources. Each resource identifies its source, geography, open-ended layer and level keys, validity period, optional map viewpoint, URL, SHA-256 digest, size and feature count. Resources can reference multiple sources, with each source's licence and attribution checked independently. Viewpoints have names, descriptions and source references, so a client can explain which representation it displays. A client asks for one or more geography/resource IDs, a date, and (when needed) a viewpoint. The default view includes only resources with no explicit viewpoint. selectGeographyResources rejects broad accidental loads by default and enforces byte/resource limits before any request is made.

loadGeographyResources fetches selected same-origin URLs only, without cookies and without following redirects. It checks the decoded file size, SHA-256, GeoJSON/TopoJSON structure and feature count before returning parsed data. It accepts an injected cache, fetch implementation and abort signal so each app can use its own HTTP cache, IndexedDB policy and retry interface. Requests are bounded-concurrency and results use deterministic geography/kind/level/id order.

loadGeographyManifest uses the same transport protections for the manifest, including a decoded byte limit enforced while streaming (64 KiB by default). An abort cancels a stalled body and also stops loads served from a cache.

Resource selection can include a WGS84 bbox in west/south/east/north order. Only intersecting resources with known bounds are selected. Resources without bounds remain eligible, so missing metadata cannot silently hide coverage. West greater than east represents an antimeridian crossing. Geographic, time, viewpoint and download-budget selectors continue to apply together.

import { loadGeographyManifest, loadGeographyResources } from '@bitbaum/geo-kit';

const controller = new AbortController();
const options = {
  baseUrl: window.location.origin,
  licensePolicy: [{ spdx: 'CC0-1.0', requiresAttribution: false }],
  signal: controller.signal, // AbortController owned by the application
};
const manifest = await loadGeographyManifest('/geography/manifest.json', options);
const layers = await loadGeographyResources(manifest, {
  geographyIds: ['selected-geography'],
  asOf: '2026-09-30', // the date displayed by the application
  levelKeys: ['subdivision'],
  bbox: [7, 46, 9, 48],
  maxBytes: 512 * 1024,
}, options);

Layer keys and geographic IDs in this example come from the application's data. Country packs, detailed subdivision datasets and a border drawing UI are separate deliverables owned by the applications; this package does not invent or publish them.

The library never reads the system clock. Pass the date displayed by the app to support historical maps deterministically. An explicit viewpoint is opt-in; the library does not treat any boundary representation as the default truth.

Drawing it: @bitbaum/geo-kit/map

One map for every product: an orthographic globe on Canvas 2D (d3-geo). Zoomed far in, the globe is a flat map of the place in front of the reader, so the world, a country and a commune are one projection and one renderer. Canvas 2D rather than WebGL: a few thousand path segments a frame fit a phone's frame budget, and it runs wherever the page runs.

pnpm add @bitbaum/geo-kit d3-geo topojson-client

d3-geo (and topojson-client, for TopoJSON) are optional peer dependencies: a product that only loads data does not install them.

import { cameraForBounds, createMap, shapesFromTopology } from "@bitbaum/geo-kit/map";

const shapes = shapesFromTopology(topology, { object: "communes", idOf: (f) => String(f.id) });
const limits = { minZoom: 1, maxZoom: 2000, maxTilt: 80 };
const map = createMap(canvas, {
  shapes,
  palette: { sphere: "#fff", land: "#eee", border: "#999", hover: "#555", selected: "#000" },
  fills: new Map([["261", "#08519c"]]),
  limits,
  onSelect: (id) => console.log(id),
});
map.resize(390, 600);
map.flyTo(cameraForBounds([5.96, 45.82, 10.49, 47.81], limits));
  • Framework-free. createMap takes a <canvas> and returns methods (resize, setFills, setSelected, flyTo, zoomBy, destroy, …); a React or other page wraps it in a few lines and keeps no map state of its own.
  • Input. One finger or the mouse turns it, two pinch, the wheel zooms, a tap selects, a flick coasts. The keyboard treats the canvas as one control: arrows turn, + and − zoom, Home resets, Enter selects what faces the reader.
  • Cost. It draws only when something changes; in motion it paints the coarse shapes (every third vertex of each shared arc, so neighbours still meet), and full detail the frame after. Features on the far side, or off the canvas when zoomed, are not drawn.
  • Reduced motion. Under prefers-reduced-motion a flight is a cut, a flick does not coast and the idle turn never starts.
  • Layers. The palette's sphere, graticule, glow and limb shade are each optional, so a lit globe of the world and a plain map where the data is the picture are the same painter. over draws the caller's own layer (sites, routes, figures) on top each frame, with the frame's projection, and pickFirst lets that layer take a tap or a hover before the features.
  • Pure parts. The camera, motion, culling, picking and the fast projection are exported and tested without a browser.

Assertions and proposed boundaries

AreaAssertion follows Solon's sourced claims, administers, and proposes records. summarizeAreaAssertions filters those records by an explicit date and reports distinct claimants, administrators and proposers. Its disputed flag is a mechanical summary of competing claims or a mismatch between claimant and administrator; it is not a legal conclusion.

validateBoundaryDraft checks a proposal's polygon, WGS84 coordinates, closed rings, input limits, source/license metadata and validity interval. Publication stays blocked until the consuming app provides both a full geometry-topology validator and an approval check for the draft's proposal. The draft contains a shape and its provenance only; claims about who owns or administers it are separate sourced assertions.

Verify

pnpm install --frozen-lockfile
pnpm run verify

Runtime code has no dependencies and targets modern browsers plus Node.js 20 or later. The package ships JavaScript and declarations built from the TypeScript source, so consumers do not need a TypeScript-aware runtime loader.

版本与发布记录

@bitbaum/geo-kit 共发布 5 个版本,首次发布于 2026/10/26;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.0latest2026/10/318 天前
0.2.02026/10/318 天前
0.1.22026/10/2811 天前
0.1.12026/10/2613 天前
0.0.0-stage2026/10/2613 天前

关于 @bitbaum/geo-kit 的常见问题

@bitbaum/geo-kit 是什么?

Versioned, on-demand geography resources and sourced boundary assertions for web applications, and a Canvas 2D renderer for them (globe or map).

如何安装 @bitbaum/geo-kit?

在项目目录运行 npm install @bitbaum/geo-kit,或使用 pnpm add / yarn add / bun add。

@bitbaum/geo-kit 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bitbaum/geo-kit 支持 ESM 还是 CommonJS?

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

@bitbaum/geo-kit 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bitbaum/geo-kit 可以商用吗?

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

@bitbaum/geo-kit 的下载量有多少?

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

@bitbaum/geo-kit 还在维护吗?

最新版本 0.3.0 发布于 2026/10/31(8 天前);至今共发布 5 个版本,其中过去 12 个月发布了 5 个;首次发布于 2026/10/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。