@johnmorrisdotca/chikyu-earth

中文文档
0.2.0发布于 2026/11/01MITTypeScriptES Module

Chikyu Earth 地球: a line-drawn globe with country outlines that turns at the Earth's own rate and opens centred on where you are. Country codes and names come from kuni; the outlines are Natural Earth's, drawn with d3-geo. SVG, no canvas.

原始使用文档
文档目录5 节
  1. One minute
  2. Draw one as a string
  3. The element
  4. The data
  5. The rest

Chikyu Earth 地球

A line-drawn globe that turns at the Earth's own rate, and opens centred on where you are.
Country outlines in the same thin-line style as Hako Devices and Uchusen Rockets: an orthographic disc, the countries drawn on it, and the rim. One SVG, no canvas.

CI MIT licence TypeScript

One minute

npm install @johnmorrisdotca/chikyu-earth
<script type="module">
  import "@johnmorrisdotca/kazoku-ui/view-controls/define";
  import "@johnmorrisdotca/chikyu-earth/element";
</script>

<div id="globe" tabindex="0">
  <chikyu-earth size="420"></chikyu-earth>
</div>
<kazoku-view-controls id="controls" for="globe" address tilt-max="90" speed="0.004178" autoplay></kazoku-view-controls>

<script type="module">
  const earth = document.querySelector("chikyu-earth");
  document.getElementById("controls").addEventListener("kazoku-viewchange", (event) => {
    earth.setView(event.detail, event.detail.final);
  });
</script>

The globe appears, centred on the reader (the browser asks for their location; until they answer, and if they decline, it starts on the Greenwich meridian). The shared control bar turns, tips, zooms and pans it. Auto-turn moves at the Earth's own rate: 0.004178 degrees a second, one sidereal day — 23 h 56 min 4.0905 s — per revolution.

Centre it yourself instead:

<chikyu-earth center="139.7,35.7" style="thick" graticule></chikyu-earth>

Draw one as a string

globe() returns the SVG markup, so a server, a build step or a test can draw the same globe with no DOM:

import { globe } from "@johnmorrisdotca/chikyu-earth";

const svg = globe({ size: 320, rotation: [-139.7, -35.7], style: "line" });

The rotation is the pair d3-geo's rotate takes: [-longitude, -latitude] centres that place. The helpers in rotate.ts do the time maths — SIDEREAL_DAY_MS, spinAt(ms), centreRotation(point) and rotationAt(centre, now, start).

The element

AttributeWhat it doesDefault
sizeWidth and height of the square SVG, in pixels.320
center"longitude,latitude" to centre on. Wins over geolocation.the reader's location, else 0,0
styleline or thick.line
graticuleDraw a light graticule under the countries.off

setView(view, final = true) applies a shared controller's { yaw, tilt, zoom, panX, panY }. Every call updates the state; pass final: false for the cheap relative transform during a gesture and final: true for the full projection redraw. projectionView(centre, size, view) is the same mapping as a pure function: yaw is added to the home longitude, tilt is subtracted from its latitude, zoom multiplies the scale, and pan offsets the translation. Front is therefore the home centre; Fit is 1x with no pan.

The data

Every country the globe draws is in the package, baked in at build time — nothing is fetched at runtime. The outlines are Natural Earth's (public domain), and each carries its English and Japanese name and ISO alpha-2 code from kuni. COUNTRIES is the GeoJSON, and countryList() is just the names and codes:

import { countryList } from "@johnmorrisdotca/chikyu-earth";

countryList().find((c) => c.alpha2 === "JP"); // { name: "Japan", ja: "日本", alpha2: "JP" }

To refresh the outlines after a Natural Earth or kuni update, run pnpm countries and commit src/data/countries.ts.

The rest

CONTRIBUTING.md · docs/ · NOTICE.md · CHANGELOG.md · MIT licence. Projection by d3-geo; shared view controls by kazoku-ui.

版本与发布记录

@johnmorrisdotca/chikyu-earth 共发布 2 个版本,首次发布于 2026/11/01;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.2.0latest2026/11/012 天前
0.0.0-stage2026/11/012 天前

关于 @johnmorrisdotca/chikyu-earth 的常见问题

@johnmorrisdotca/chikyu-earth 是什么?

地球千球:一个有国家轮廓的线条地球仪,它以地球自己的速度旋转,并以你所在的地方为中心打开。国家代码和名称来自kuni;轮廓是自然地球,用3d -geo绘制。SVG,没有画布。

如何安装 @johnmorrisdotca/chikyu-earth?

在项目目录运行 npm install @johnmorrisdotca/chikyu-earth,或使用 pnpm add / yarn add / bun add。

@johnmorrisdotca/chikyu-earth 支持 TypeScript 吗?

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

@johnmorrisdotca/chikyu-earth 支持 ESM 还是 CommonJS?

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

@johnmorrisdotca/chikyu-earth 需要什么版本的 Node.js?

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

@johnmorrisdotca/chikyu-earth 可以商用吗?

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

@johnmorrisdotca/chikyu-earth 还在维护吗?

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