@geolonia/embed

中文文档
6.0.1发布于 2026/11/12MITTypeScriptCommonJS构建来源已验证近 30 天下载 3477

Geolonia embed JS API

原始使用文档
文档目录13 节
  1. Features
  2. Examples
  3. Usage
  4. Using with npm (for React, Next.js, Astro, Fresh, etc.)
  5. Content Security Policy
  6. Using External Styles Without API Key
  7. Development
  8. Requirements
  9. How to build
  10. Dependency updates
  11. Run Bundle analyzer
  12. Snapshot testing
  13. preparation

@geolonia/embed

build

JS embed API for Geolonia service.

Features

  • webGL vector map rendering
  • simple configuration
  • map lazy rendering

Examples

https://geolonia.github.io/embed/

Usage

Specify .geolonia class for target elements.

<!DOCTYPE html>
<html>
  <body>
    <div class="geolonia" ...></div>
    <script src="https://cdn.geolonia.com/embed/v5/embed?geolonia-api-key=YOUR-API-KEY"></script>
  </body>
</html>

Or

<!DOCTYPE html>
<html>
  <body>
    <div class="geolonia" data-key="YOUR-API-KEY" ...></div>
    <script src="https://cdn.geolonia.com/embed/v5/embed"></script>
  </body>
</html>

Using with npm (for React, Next.js, Astro, Fresh, etc.)

For modern web frameworks, use @geolonia/embed/core — an entry point designed for programmatic use.

npm install @geolonia/embed
import { GeoloniaMap, keyring } from "@geolonia/embed/core";

keyring.setApiKey("YOUR-API-KEY");

const map = new GeoloniaMap({
  container: "#map",
  style: "geolonia/gsi",
  center: [139.7671, 35.6812],
  zoom: 14,
});

Unlike the default @geolonia/embed entry point, /core does not automatically scan the DOM or set window.geolonia. This makes it safe to use in SSR environments and avoids double-initialization issues in frameworks like React, Preact, and Vue. (Its only import-time side effect is registering the bundled MapLibre worker, which is skipped outside the browser.)

Content Security Policy

@geolonia/embed ships as a single file, so the MapLibre worker is embedded in the bundle and started from a blob: URL. If your page sets a Content Security Policy, allow blob: as a worker source:

Content-Security-Policy: worker-src blob:;

Using External Styles Without API Key

You can use external style.json URLs without a Geolonia API key. This is useful when:

  • Using open-source tile servers like OpenStreetMap Japan
  • Self-hosting your own tiles and styles
  • Distributing maps without API key dependencies

Note: Geolonia API key is only required when using Geolonia's hosted styles and tiles.

<!DOCTYPE html>
<html>
  <body>
    <!-- Using OpenStreetMap Japan tiles (no API key needed) -->
    <!-- Note: tile.openstreetmap.jp is for non-commercial use only -->
    <div
      class="geolonia"
      data-lat="35.6812"
      data-lng="139.7671"
      data-zoom="14"
      data-style="https://tile.openstreetmap.jp/styles/osm-bright/style.json"
    ></div>
    <script src="https://cdn.geolonia.com/embed/v5/embed"></script>
  </body>
</html>

You can also use npm/unpkg/jsDelivr for self-hosted or CDN distribution:

<!-- Using npm CDN (unpkg) -->
<script src="https://unpkg.com/@geolonia/embed@latest/dist/embed.js"></script>

<!-- Using jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/@geolonia/embed@latest/dist/embed.js"></script>

data-style attribute

The data-style attribute accepts:

  • Geolonia style names: geolonia/basic, geolonia/gsi (requires API key)
  • Full URLs: https://example.com/style.json
  • Relative paths: ./custom-style.json, /styles/my-style.json
  • Files ending in .json: Automatically resolved to absolute URLs

data-lang attribute

The data-lang attribute controls the language of map labels:

  • ja — Japanese labels
  • en (or any other non-Japanese value) — English labels
  • auto — follow the browser language (navigator.languages)
  • omitted — same as auto (follows the browser language)

Only ja / ja-jp resolve to Japanese; every other value resolves to English.

Important: when neither data-lang nor lang is specified, the language follows the browser setting. On a non-Japanese browser this loads the English style (en.json). Set it explicitly to force a language:

<div class="geolonia" data-lang="ja" ...></div>

When using the JavaScript API (new GeoloniaMap({...})), pass lang in the options instead of a data-lang attribute:

const map = new GeoloniaMap({ container: "#map", lang: "ja" });

You can see more examples at https://geolonia.github.io/embed/.

Contributing

Development

Requirements

  • node.js >= 22.22.2 (the floor required by jsdom 30; .tool-versions pins the latest 22.x)

How to build

This project uses pnpm. The version is pinned in two places, which must be kept in sync: the packageManager field of package.json (used by Corepack and by pnpm/action-setup in CI) and .tool-versions (used by asdf and mise). pnpm-workspace.yaml sets pmOnFail: ignore, so pnpm itself will not correct a mismatch; the build workflow compares the two pins instead and fails if they disagree.

$ git clone [email protected]:geolonia/embed.git
$ cd embed
$ pnpm install
$ pnpm start # run dev server
$ pnpm test # run tests
$ pnpm run e2e # run e2e tests (run `pnpm run build` first to include the production-bundle test)
$ pnpm run build # build production bundle

Then you can see http://localhost:3000/.

Dependency updates

Dependencies are updated by Dependabot, configured in .github/dependabot.yml. Minor and patch updates arrive as one grouped weekly PR. Major version updates are ignored for now — there is a backlog of them and each needs its own plan — but security updates still arrive for any version, major included, because an ignore on version-update:semver-major only scopes version updates.

pnpm-workspace.yaml sets pmOnFail: ignore, and that line is load-bearing: without it pnpm 12 writes pnpm-lock.yaml as two YAML documents, GitHub's dependency-graph parser reads only the first one (which holds nothing but pnpm itself), and no npm package ever reaches the graph — so no Dependabot alert is raised. See pnpm-workspace.yaml and dependabot-core#15904. Keep the lockfile a single YAML document.

To check by hand:

$ pnpm audit            # vulnerabilities
$ pnpm outdated         # available updates
$ pnpm why maplibre-gl  # who pulls a package in

Run Bundle analyzer

$ pnpm run analyze

Snapshot testing

preparation

$ cp .envrc.sample .envrc
$ vi .envrc
$ pnpm run build
$ docker build . -t geolonia/embed

版本与发布记录

@geolonia/embed 共发布 146 个版本,首次发布于 2019/12/13;过去 12 个月发布了 12 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
6.0.1latest2026/11/124 天前
6.0.02026/11/114 天前
6.0.0-pre.6next2026/10/3017 天前
6.0.0-pre.52026/10/151 个月前
6.0.0-pre.42026/10/051 个月前
6.0.0-pre.32026/08/073 个月前

关于 @geolonia/embed 的常见问题

@geolonia/embed 是什么?

Geolonia embed JS API

如何安装 @geolonia/embed?

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

@geolonia/embed 支持 TypeScript 吗?

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

@geolonia/embed 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@geolonia/embed 可以商用吗?

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

@geolonia/embed 的下载量有多少?

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

@geolonia/embed 还在维护吗?

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