@johnmorrisdotca/chikyu-earth 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.18.0 - 2026-11-08
6
+
7
+ - **Every live view zooms, pans and turns by itself** (MODULES-643): `<chikyu-earth>`, `<chikyu-earth-realistic>` and `<chikyu-space>` carry kazoku-ui's controls through `carryControls`: drag, two-finger pinch, Ctrl and the wheel (a plain wheel at Fit scrolls the page), the keys, with no bar. `controls="none"` takes them off; `zoom-min`, `zoom-max`, `tilt-max` change the range; `element.controller` is the controller behind them. A `<kazoku-view-controls for="...">` on the element takes the hands over and reads the element's range. The ranges (tilt to either pole): the line globe 0.1 to 20 times (Natural Earth 1:110m, redrawn at each zoom; about 640 km across at 20 times); the realistic Earth 0.1 to 5, raised to 20 by the element itself when its `tiles` are found; the space view a millionth to 2.5, and 0.5 to 6 while riding from a body (the element sets and removes `zoom-min` and `zoom-max` itself, unless the page set them). The line globe's `setView` redraws the Auto-turn about once a second by itself, so a page no longer keeps that clock. The demo's bar is now `for` the element (not a wrapper), the code builder's preview frame and the example pages carry the hands, and `examples/controls.html` is the new pattern. The embed page takes the hands by default (as wakusei-planets' does): drag, pinch, Ctrl and the wheel, the keys, with a plain wheel at Fit scrolling the host page, in a frame of any size; `hands=0` makes it a still picture, `turn=auto` still turns it by itself and `turn=1` is accepted and does nothing more, and the code builder's preview frame and iframe code need no `turn`. `@johnmorrisdotca/kazoku-ui` (^0.21.1) is now a dependency, not an optional peer. Guide in English and Japanese: `docs/guides/zoom-and-pan.md`. Tests: `e2e/zoom.demo.ts` (demo, builder, embed, at desk and phone sizes), `e2e/zoom.gl.ts` (the 3D looks and the tile limit), the usage script's CDN, Vite and space examples; all through `e2e/hands.ts`.
8
+
5
9
  ## 0.17.0 - 2026-11-08
6
10
 
7
11
  - **Sharp close zoom on the realistic Earth, from finer map tiles** (MODULES-645, the loader): `<chikyu-earth-realistic tiles="/tiles/">` (also `earth.tiles`) reads the tile set's `manifest.json`, picks the level from the zoom and the canvas (about one texel to a device pixel; day level 3 then 4, night level 2 then 3), loads only the tiles in view, six at a time, the middle first, and lays them over the package's pictures, which stay as the far view and the fallback. At most 48 tiles are held (about 70 MB of graphics memory); a tile that leaves view is kept 4 seconds and then freed, the oldest first when over the limit; the level drops when the tiles in view would be more. Each tile that arrives asks for one draw (30 a second at most, eight new tiles to a draw); nothing is drawn at rest or out of sight, a lost context comes back with the held tiles, and without the option, without a manifest or for a tile that fails the Earth is drawn as before. A device with no 4096 picture (`max-texture` under 4096, or 2 GB or less of memory) uses no tiles. `earth.stats.tiles` and the `chikyu-tiles` event say what it is doing. New pure parts in `/realistic`: `tileLevel`, `tilesInView`, `coveringTile`, `pointOnEarth`, `tileRect`, `tileColumns`, `tileRows`, `parseManifest`, `TEXEL_SLACK`, `TILE_LIMIT`, `TILE_KEEP_MS`. **The demo's zoom limit on the realistic look goes from 5 to 20** when its tiles are found (the finest tile level is 4 times the widest picture) and stays 5 when they are not. Tests: the level and tile maths (the antimeridian, the poles, a tile bigger than the box) in `test/tiles.test.ts`; a made-up tile set in `e2e/tiles.gl.ts` (requests, drawing over the base, freeing after zoom-out, night tiles, failed tiles, a lost context, batching); a tiles round in `pnpm test:freeze` (GPU objects flat over six zoom rounds). Guide in English and Japanese: `docs/guides/earth-tiles.md`.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <p align="center"><strong>A line-drawn globe that turns at the Earth's own rate, and opens centred on where you are.</strong><br>
6
6
  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.</p>
7
7
 
8
- <p align="center">Part of <strong>SpaceProgramX (SPX)</strong>, the space packages: <a href="https://github.com/johnmorrisdotca/wakusei-planets">Wakusei Planets</a> · <a href="https://github.com/johnmorrisdotca/hoshi-stars">Hoshi Stars</a> · <a href="https://github.com/johnmorrisdotca/chikyu-earth">Chikyu Earth</a> · <a href="https://github.com/johnmorrisdotca/uchusen-rockets">Uchusen Rockets</a></p>
8
+ <p align="center">Part of <strong>Space Program X (SPX)</strong>, the space packages: <a href="https://github.com/johnmorrisdotca/wakusei-planets">Wakusei Planets</a> · <a href="https://github.com/johnmorrisdotca/hoshi-stars">Hoshi Stars</a> · <a href="https://github.com/johnmorrisdotca/chikyu-earth">Chikyu Earth</a> · <a href="https://github.com/johnmorrisdotca/uchusen-rockets">Uchusen Rockets</a></p>
9
9
 
10
10
  <p align="center">
11
11
  <a href="https://github.com/johnmorrisdotca/chikyu-earth/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/johnmorrisdotca/chikyu-earth/actions/workflows/ci.yml/badge.svg"></a>
@@ -32,7 +32,7 @@ Country outlines in the same thin-line style as Hako Devices and Uchusen Rockets
32
32
  - The Sun, the Moon and the planets where they are on a date and time (`/space`), and satellites at the places SGP4 puts them (`/satellites`), with a camera that rides along.
33
33
  - Markers with labels, groups, clusters and events (`/markers`), on either globe.
34
34
  - Pure parts that run on a server: `globe()`, the rotation and view maths, `COUNTRIES` and `countryList()`.
35
- - The shared kazoku-ui view controls: drag, tilt, zoom, pan, pinch, Front and Fit, with the view kept in the address.
35
+ - Every live view zooms, pans and turns by itself, with no bar: drag, two-finger pinch, Ctrl and the wheel (a plain wheel at Fit scrolls the page) and the keys, through kazoku-ui's controls, from a tenth of Fit to 20 times on the line globe ([each range and why](docs/guides/zoom-and-pan.md)). Add `<kazoku-view-controls>` for buttons and the address.
36
36
  - Names in English and Japanese, and a strict content security policy is enough.
37
37
 
38
38
  ## Install and use
@@ -62,11 +62,11 @@ One script tag from [jsDelivr](https://www.jsdelivr.com/package/npm/@johnmorrisd
62
62
  </html>
63
63
  ```
64
64
 
65
- The globe appears centred where you say; with no `center` it centres on the reader (the browser asks for their location; until they answer, and if they decline, it starts on the Greenwich meridian). `look` is `line` or `thick`.
65
+ The globe appears centred where you say; with no `center` it centres on the reader (the browser asks for their location; until they answer, and if they decline, it starts on the Greenwich meridian). `look` is `line` or `thick`. It also zooms and turns: drag, pinch, Ctrl and the wheel, the arrow keys (`controls="none"` takes that off).
66
66
 
67
67
  ### With the shared controls
68
68
 
69
- The [kazoku-ui](https://github.com/johnmorrisdotca/kazoku-ui) view controls turn, tip, zoom and pan it, and keep the view in the address. One listener passes their camera on:
69
+ The [kazoku-ui](https://github.com/johnmorrisdotca/kazoku-ui) view controls bar adds buttons and a slider and keeps the view in the address. One listener passes its camera on:
70
70
 
71
71
  ```html
72
72
  <!doctype html>
@@ -86,10 +86,8 @@ The [kazoku-ui](https://github.com/johnmorrisdotca/kazoku-ui) view controls turn
86
86
  </script>
87
87
  </head>
88
88
  <body>
89
- <div id="globe" tabindex="0">
90
- <chikyu-earth size="420" look="thick" center="139.7,35.7"></chikyu-earth>
91
- </div>
92
- <kazoku-view-controls for="globe" address grab-radius="fit" controls="advanced" tilt-max="90" speed="0.004178"></kazoku-view-controls>
89
+ <chikyu-earth id="earth" size="420" look="thick" center="139.7,35.7" tabindex="0"></chikyu-earth>
90
+ <kazoku-view-controls for="earth" address grab-radius="fit" controls="advanced" tilt-max="90" speed="0.004178"></kazoku-view-controls>
93
91
  </body>
94
92
  </html>
95
93
  ```
@@ -211,13 +209,24 @@ markers.add({ id: "tokyo", lon: 139.69, lat: 35.69, label: "Tokyo", group: "Citi
211
209
 
212
210
  ## Controls
213
211
 
214
- The shared [kazoku-ui view controls](https://github.com/johnmorrisdotca/kazoku-ui) supply every hand and button:
215
- drag to turn, tilt up to either pole, zoom, pan, touch pinch, Front and Fit. Chikyu does not draw its own zoom,
212
+ The elements carry the shared [kazoku-ui view controls](https://github.com/johnmorrisdotca/kazoku-ui) themselves, so
213
+ every live view zooms, pans and turns with no bar: drag to turn (and move, once zoomed), touch pinch, Ctrl and the
214
+ wheel to zoom (a plain wheel at Fit scrolls the page), the arrow keys, `+`, `-` and `0` once the element is focused.
215
+ `controls="none"` takes the hands off; `zoom-min` and `zoom-max` change the range. Chikyu does not draw its own zoom,
216
216
  rotate or drag controls.
217
217
 
218
+ | Element | Zoom range | Why it stops there |
219
+ | --- | --- | --- |
220
+ | `<chikyu-earth>` | 0.1 to 20 times | Natural Earth 1:110m outlines, redrawn at each zoom; at 20 times the view is about 640 km across and a coast is a few straight segments |
221
+ | `<chikyu-earth-realistic>` | 0.1 to 5 times; 20 with `tiles` found | the package's pictures are 4096 pixels across at most; the finest tile level is 4 times that |
222
+ | `<chikyu-space>` | a millionth to 2.5 times; 0.5 to 6 riding from a body | the zoom is the camera's distance (the whole solar system needs a millionth); close in, the Earth's picture and the textures stay sharp to 2.5 |
223
+
224
+ [Zoom, pan and turn](docs/guides/zoom-and-pan.md) says more. For buttons, a slider, Auto-turn and the address, add the
225
+ bar for the element (give it an `id` and a `tabindex`); it takes the hands over and the page applies its events:
226
+
218
227
  ```html
219
- <div id="globe" tabindex="0"><chikyu-earth size="420"></chikyu-earth></div>
220
- <kazoku-view-controls id="controls" for="globe" address grab-radius="fit" controls="advanced" tilt-max="90" speed="0.004178" autoplay></kazoku-view-controls>
228
+ <chikyu-earth id="earth" size="420" tabindex="0"></chikyu-earth>
229
+ <kazoku-view-controls id="controls" for="earth" address grab-radius="fit" controls="advanced" tilt-max="90" speed="0.004178" autoplay></kazoku-view-controls>
221
230
  ```
222
231
 
223
232
  ```ts no-run
@@ -259,6 +268,8 @@ The rotation is the pair d3-geo's `rotate` takes: `[-longitude, -latitude]` cent
259
268
  | `center` | `"longitude,latitude"` to centre on. Wins over geolocation. | the reader's location, else `0,0` |
260
269
  | `look` | `line` or `thick`. (`style` is the older name for it: a framework reads `style` as CSS, so use `look` there.) | `line` |
261
270
  | `graticule` | Draw a light graticule under the countries. | off |
271
+ | `controls` | `none` takes off the drag, pinch, wheel and keys the element carries. | on |
272
+ | `zoom-min`, `zoom-max` | The zoom range, over the element's own (0.1 to 20). | 0.1, 20 |
262
273
 
263
274
  `setView(view, final = true)` applies a shared controller's `{ yaw, tilt, zoom, panX, panY }`. Every call updates
264
275
  the state; pass `final: false` for the cheap relative transform during a gesture and `final: true` for the full
@@ -375,6 +386,7 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
375
386
  | [The realistic Earth and markers](docs/guides/realistic-and-markers.md) | The Earth from space, markers |
376
387
  | [Satellites](docs/guides/satellites.md) | SGP4 and the space view |
377
388
  | [Ride along](docs/guides/ride-along.md) | A camera on a moving body |
389
+ | [Zoom, pan and turn](docs/guides/zoom-and-pan.md) | The hands every view carries, each zoom range and why |
378
390
  | [Why two packages](docs/guides/two-packages.md) | This package and wakusei-planets: which to install, alone and together |
379
391
  | [How it stays light](docs/guides/how-it-works.md) | The budget |
380
392
  | [Architecture](docs/guides/architecture.md) | How the layers fit |
package/dist/element.d.ts CHANGED
@@ -1,7 +1,9 @@
1
+ import { type ViewController } from "@johnmorrisdotca/kazoku-ui/view-controls";
1
2
  import type { OverlayHost } from "./markers/layer.ts";
2
3
  import type { GeoPoint, GlobeView } from "./types.ts";
3
4
  /**
4
5
  * The `<chikyu-earth>` custom element: the line globe, drawn as SVG in its shadow root. Importing this entry point registers the tag once. It takes the attributes `size` (pixels, 320 by default), `center` (`"lon,lat"`; wins over the browser's location), `look` (`line` or `thick`; `style` is the older name for it, and a framework that reads `style` as CSS cannot use it) and `graticule`, and a shared view controller's camera through `setView`.
6
+ * It carries kazoku-ui's controls itself: a drag turns it, two fingers pinch, Ctrl and the wheel zoom (a plain wheel at Fit scrolls the page) and the arrow keys, + and - work once it is focused, from a tenth of Fit to 20 times. `controls="none"` turns them off; `zoom-min` and `zoom-max` change the range. A `<kazoku-view-controls for="...">` on the element takes the hands over, and the page applies its events with `setView`.
5
7
  *
6
8
  * @example
7
9
  * ```ts no-run
@@ -16,6 +18,8 @@ import type { GeoPoint, GlobeView } from "./types.ts";
16
18
  export declare class ChikyuEarth extends HTMLElement {
17
19
  #private;
18
20
  static observedAttributes: string[];
21
+ /** The controller behind the element's own hands (`play`, `set`, `fit`, `state`), while it is in a page. */
22
+ get controller(): ViewController | undefined;
19
23
  /** Where the view is centred now: the `center` attribute, else the reader's place once the browser has answered. */
20
24
  get centre(): GeoPoint;
21
25
  /** A box laid over the globe for markers (see `@johnmorrisdotca/chikyu-earth/markers`): where it is, the pose of the last drawing, and a way to hear the next. */
package/dist/element.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // <chikyu-earth>: the globe as a web component. A shared view controller supplies its yaw, tilt, zoom and pan;
2
2
  // it opens centred on where you are (the `center` attribute wins over geolocation). Importing registers it once.
3
+ import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
3
4
  import { adoptStyles } from "./adopt.js";
4
5
  import { globe } from "./globe.js";
5
6
  import { cleanStyle } from "./styles.js";
@@ -16,9 +17,14 @@ const readCentre = (value) => {
16
17
  };
17
18
  /** The least time between two redraws of the projection while a hand is turning the globe: 30 a second at most. */
18
19
  const LIVE_MS = 1000 / 30;
20
+ /** The automatic turn is slow enough that one redraw a second is smooth. */
21
+ const AUTO_MS = 1000;
22
+ /** Tilt to the poles; zoom from a tenth of Fit, which leaves the whole globe small in the view, to 20 times: the outlines are Natural Earth 1:110m, and past about 20 times their straight segments are longer than the view is wide. */
23
+ const LIMITS = { tiltMax: 90, zoomMin: 0.1, zoomMax: 20 };
19
24
  const STYLE = ":host{display:block;position:relative}.holder svg{display:block;width:100%;height:auto}.overlay{position:absolute;inset:0;pointer-events:none;transform-origin:50% 50%}";
20
25
  /**
21
26
  * The `<chikyu-earth>` custom element: the line globe, drawn as SVG in its shadow root. Importing this entry point registers the tag once. It takes the attributes `size` (pixels, 320 by default), `center` (`"lon,lat"`; wins over the browser's location), `look` (`line` or `thick`; `style` is the older name for it, and a framework that reads `style` as CSS cannot use it) and `graticule`, and a shared view controller's camera through `setView`.
27
+ * It carries kazoku-ui's controls itself: a drag turns it, two fingers pinch, Ctrl and the wheel zoom (a plain wheel at Fit scrolls the page) and the arrow keys, + and - work once it is focused, from a tenth of Fit to 20 times. `controls="none"` turns them off; `zoom-min` and `zoom-max` change the range. A `<kazoku-view-controls for="...">` on the element takes the hands over, and the page applies its events with `setView`.
22
28
  *
23
29
  * @example
24
30
  * ```ts no-run
@@ -40,6 +46,11 @@ export class ChikyuEarth extends HTMLElement {
40
46
  #pose = null;
41
47
  #liveTimer;
42
48
  #liveAt = 0;
49
+ #hands;
50
+ /** The controller behind the element's own hands (`play`, `set`, `fit`, `state`), while it is in a page. */
51
+ get controller() {
52
+ return this.#hands?.controller;
53
+ }
43
54
  /** Where the view is centred now: the `center` attribute, else the reader's place once the browser has answered. */
44
55
  get centre() {
45
56
  return { ...this.#centre };
@@ -59,11 +70,19 @@ export class ChikyuEarth extends HTMLElement {
59
70
  disconnectedCallback() {
60
71
  clearTimeout(this.#liveTimer);
61
72
  this.#liveTimer = undefined;
73
+ this.#hands?.unbind();
74
+ this.#hands = undefined;
62
75
  }
63
76
  connectedCallback() {
64
77
  this.#centre = readCentre(this.getAttribute("center")) ?? { lon: 0, lat: 0 };
65
78
  this.#render();
66
79
  this.#locate();
80
+ this.#hands = carryControls(this, {
81
+ initial: this.#view,
82
+ grabRadius: "fit",
83
+ limits: LIMITS,
84
+ onChange: (state, info) => this.setView(state, info.final, info.reason !== "auto"),
85
+ });
67
86
  }
68
87
  attributeChangedCallback(name, _old, value) {
69
88
  if (name === "center")
@@ -85,12 +104,16 @@ export class ChikyuEarth extends HTMLElement {
85
104
  this.#render();
86
105
  return;
87
106
  }
107
+ const turned = view.yaw !== this.#drawn.yaw || view.tilt !== this.#drawn.tilt;
108
+ if (!live && turned && performance.now() - this.#liveAt >= AUTO_MS) {
109
+ this.#render();
110
+ return;
111
+ }
88
112
  this.#transform();
89
- if (live && (view.yaw !== this.#drawn.yaw || view.tilt !== this.#drawn.tilt) && this.#liveTimer === undefined) {
113
+ if (live && turned && this.#liveTimer === undefined) {
90
114
  const wait = Math.max(0, LIVE_MS - (performance.now() - this.#liveAt));
91
115
  this.#liveTimer = setTimeout(() => {
92
116
  this.#liveTimer = undefined;
93
- this.#liveAt = performance.now();
94
117
  this.#render();
95
118
  }, wait);
96
119
  }
@@ -149,6 +172,7 @@ export class ChikyuEarth extends HTMLElement {
149
172
  listener(pose);
150
173
  }
151
174
  #render() {
175
+ this.#liveAt = performance.now();
152
176
  const size = Number(this.getAttribute("size")) || 320;
153
177
  const style = cleanStyle(this.getAttribute("look") ?? this.getAttribute("style"));
154
178
  const svg = globe({ size, style, centre: this.#centre, view: this.#view, graticule: this.hasAttribute("graticule") });
@@ -1,3 +1,4 @@
1
+ import { type ViewController } from "@johnmorrisdotca/kazoku-ui/view-controls";
1
2
  import type { GeoPoint, GlobeView } from "../types.ts";
2
3
  import { type LightMode } from "./earth.ts";
3
4
  import { setSharedRenderer, setThreeLoader } from "./shared.ts";
@@ -53,6 +54,8 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
53
54
  connectedCallback(): void;
54
55
  disconnectedCallback(): void;
55
56
  attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
57
+ /** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
58
+ get controller(): ViewController | undefined;
56
59
  /** Where the finer map tiles are served from (a folder with `manifest.json`), or `null` for none; the attribute `tiles`. The Earth loads only the tiles in view, over its own pictures. */
57
60
  get tiles(): string | null;
58
61
  set tiles(value: string | null);
@@ -1,8 +1,9 @@
1
1
  // <chikyu-earth-realistic>: the Earth from space as a web component, drawn by kazoku-ui's shared 3D renderer (one WebGL context for the
2
2
  // page) with three.js, which is the page's own. Optional entry point: the flat `<chikyu-earth>` needs neither. It draws only when something
3
3
  // changes, at most 30 times a second, and nothing at all while it is out of sight or the tab is hidden.
4
+ import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
4
5
  import { adoptStyles } from "../adopt.js";
5
- import { createEarthItem, lookAt, newModel } from "./earth.js";
6
+ import { createEarthItem, discRadius, lookAt, newModel } from "./earth.js";
6
7
  import { createGate, frameCap } from "./gate.js";
7
8
  import { setSharedRenderer, setThreeLoader, takeRenderer } from "./shared.js";
8
9
  export { setSharedRenderer, setThreeLoader };
@@ -12,6 +13,10 @@ const RAD = Math.PI / 180;
12
13
  /** The Sun and the clouds are re-placed this often while the time is "now": 15 degrees an hour is 0.25 degree a minute. */
13
14
  const LIVE_TICK_MS = 60_000;
14
15
  const MIN_TICK_MS = 1000;
16
+ /** Tilt to the poles; zoom from a tenth of Fit, which leaves the whole Earth small in the view, to 5 times: the package's own pictures are sharp to about 5 times. */
17
+ const LIMITS = { tiltMax: 90, zoomMin: 0.1, zoomMax: 5 };
18
+ /** With the finer tiles the detail runs 4 times further: the finest level is 4 times wider than the widest picture. */
19
+ const TILES_ZOOM_MAX = "20";
15
20
  const readCentre = (value) => {
16
21
  if (!value)
17
22
  return null;
@@ -74,6 +79,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
74
79
  #overlay;
75
80
  #pose = null;
76
81
  #listeners = new Set();
82
+ #hands;
83
+ #reach = null;
77
84
  #onContext = (state) => {
78
85
  if (state === "unavailable")
79
86
  this.#fail("WebGL is not available");
@@ -116,10 +123,18 @@ export class ChikyuEarthRealistic extends HTMLElement {
116
123
  textureBase: () => this.#textureBase(),
117
124
  cap: () => this.#textureCap(),
118
125
  tiles: () => this.tiles ?? undefined,
119
- onTiles: (layers) => this.dispatchEvent(new CustomEvent("chikyu-tiles", { detail: { layers } })),
126
+ onTiles: (layers) => {
127
+ if (!this.hasAttribute("zoom-max") || this.getAttribute("zoom-max") === this.#reach) {
128
+ this.#reach = TILES_ZOOM_MAX;
129
+ this.setAttribute("zoom-max", TILES_ZOOM_MAX);
130
+ }
131
+ this.dispatchEvent(new CustomEvent("chikyu-tiles", { detail: { layers } }));
132
+ },
120
133
  drift: 1.5,
121
134
  invalidate: () => this.#gate?.soon(),
122
135
  onPose: (pose) => {
136
+ if (this.#hands)
137
+ this.#hands.controller.grabRadius = discRadius(pose.width, pose.height, 1);
123
138
  this.#pose = { ...pose, transform: "" };
124
139
  for (const listener of this.#listeners)
125
140
  listener(this.#pose);
@@ -143,12 +158,18 @@ export class ChikyuEarthRealistic extends HTMLElement {
143
158
  });
144
159
  this.addEventListener("pointerdown", this.#take);
145
160
  this.addEventListener("focusin", this.#take);
161
+ this.#hands = carryControls(this, { initial: this.#model.view, limits: LIMITS, onChange: (state, info) => this.setView(state, info.final) });
146
162
  this.#startTick();
147
163
  this.#locate();
148
164
  }
149
165
  disconnectedCallback() {
150
166
  this.removeEventListener("pointerdown", this.#take);
151
167
  this.removeEventListener("focusin", this.#take);
168
+ this.#hands?.unbind();
169
+ this.#hands = undefined;
170
+ if (this.#reach !== null && this.getAttribute("zoom-max") === this.#reach)
171
+ this.removeAttribute("zoom-max");
172
+ this.#reach = null;
152
173
  clearInterval(this.#tick);
153
174
  this.#tick = undefined;
154
175
  this.#gate?.cancel();
@@ -173,6 +194,10 @@ export class ChikyuEarthRealistic extends HTMLElement {
173
194
  else if (name === "tiles")
174
195
  this.#gate?.soon();
175
196
  }
197
+ /** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
198
+ get controller() {
199
+ return this.#hands?.controller;
200
+ }
176
201
  /** Where the finer map tiles are served from (a folder with `manifest.json`), or `null` for none; the attribute `tiles`. The Earth loads only the tiles in view, over its own pictures. */
177
202
  get tiles() {
178
203
  const given = this.getAttribute("tiles");
@@ -1,3 +1,4 @@
1
+ import { type ViewController } from "@johnmorrisdotca/kazoku-ui/view-controls";
1
2
  import type { GeoPoint } from "../types.ts";
2
3
  import { setThreeLoader } from "../realistic/shared.ts";
3
4
  import type { LightMode } from "../realistic/earth.ts";
@@ -117,6 +118,8 @@ type SatelliteStats = {
117
118
  /**
118
119
  * The `<chikyu-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`, `time` (`now` or an ISO date), `speed` (1 is real time, 0 holds, 86400 is a day a second, negative runs backwards), `scale` (`compressed` or `true`), `labels` and `orbits` (`off` hides them); positions are computed in the browser by astronomy-engine, an optional peer dependency. It draws only when something changes, and nothing while it is out of sight.
119
120
  *
121
+ * It carries kazoku-ui's controls itself: a drag turns the view, two fingers pinch, Ctrl and the wheel zoom (a plain wheel at Fit scrolls the page) and the arrow keys, + and - work once it is focused. The zoom runs from a millionth of Fit (the whole solar system) to 2.5 times, and from 0.5 to 6 times while riding from a body. `controls="none"` turns the hands off; `zoom-min` and `zoom-max` change the range. A `<kazoku-view-controls for="...">` on the element takes the hands over, and the page applies its events with `setView`.
122
+ *
120
123
  * @example
121
124
  * ```ts no-run
122
125
  * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
@@ -130,6 +133,8 @@ type SatelliteStats = {
130
133
  export declare class ChikyuSpace extends HTMLElement {
131
134
  #private;
132
135
  static observedAttributes: string[];
136
+ /** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
137
+ get controller(): ViewController | undefined;
133
138
  connectedCallback(): void;
134
139
  disconnectedCallback(): void;
135
140
  attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
@@ -1,3 +1,4 @@
1
+ import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
1
2
  import { adoptStyles } from "../adopt.js";
2
3
  import { createGate, frameCap } from "../realistic/gate.js";
3
4
  import { setThreeLoader, takeRenderer } from "../realistic/shared.js";
@@ -38,6 +39,12 @@ const EARTH_RATE = 360 / 86_164.0905;
38
39
  const SATELLITE_RATE = 360 / (88 * 60);
39
40
  const SATELLITE_COLORS = ["#ffd54f", "#7fd4ff", "#ff8fa3", "#9ef0a8"];
40
41
  const REAL_TIME_TICK_MS = 60_000;
42
+ /**
43
+ * Tilt to the poles. The zoom is the camera's distance: a millionth of Fit takes in the whole solar system (the views of the planets and their distances need that much), and 2.5 times is as close as the Earth's 4096 pixel picture and the body textures stay sharp.
44
+ * Riding at a body looking at the Earth, the zoom only narrows the camera's field a little either way: 0.5 to 6.
45
+ */
46
+ const LIMITS = { tiltMax: 90, zoomMin: 0.000001, zoomMax: 2.5 };
47
+ const RIDE_ZOOM = { "zoom-min": "0.5", "zoom-max": "6" };
41
48
  const readCentre = (value) => {
42
49
  if (!value)
43
50
  return null;
@@ -56,6 +63,8 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
56
63
  /**
57
64
  * The `<chikyu-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`, `time` (`now` or an ISO date), `speed` (1 is real time, 0 holds, 86400 is a day a second, negative runs backwards), `scale` (`compressed` or `true`), `labels` and `orbits` (`off` hides them); positions are computed in the browser by astronomy-engine, an optional peer dependency. It draws only when something changes, and nothing while it is out of sight.
58
65
  *
66
+ * It carries kazoku-ui's controls itself: a drag turns the view, two fingers pinch, Ctrl and the wheel zoom (a plain wheel at Fit scrolls the page) and the arrow keys, + and - work once it is focused. The zoom runs from a millionth of Fit (the whole solar system) to 2.5 times, and from 0.5 to 6 times while riding from a body. `controls="none"` turns the hands off; `zoom-min` and `zoom-max` change the range. A `<kazoku-view-controls for="...">` on the element takes the hands over, and the page applies its events with `setView`.
67
+ *
59
68
  * @example
60
69
  * ```ts no-run
61
70
  * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
@@ -87,6 +96,12 @@ export class ChikyuSpace extends HTMLElement {
87
96
  #names = {};
88
97
  #hint = "choose to look at it";
89
98
  #tiers = {};
99
+ #hands;
100
+ #ridden = {};
101
+ /** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
102
+ get controller() {
103
+ return this.#hands?.controller;
104
+ }
90
105
  connectedCallback() {
91
106
  this.#model.centre = readCentre(this.getAttribute("center")) ?? this.#model.centre;
92
107
  this.#mode = readTime(this.getAttribute("time"));
@@ -148,10 +163,14 @@ export class ChikyuSpace extends HTMLElement {
148
163
  this.#last = performance.now();
149
164
  this.#schedule();
150
165
  this.addEventListener("pointerdown", this.#down);
166
+ this.#hands = carryControls(this, { initial: this.#model.view, limits: LIMITS, onChange: (state, info) => this.setView(state, info.final) });
151
167
  this.#labelBox.addEventListener("click", this.#labelClick);
152
168
  this.#labelBox.addEventListener("focusin", this.#labelFocus);
153
169
  }
154
170
  disconnectedCallback() {
171
+ this.#hands?.unbind();
172
+ this.#hands = undefined;
173
+ this.#zoomRange(false);
155
174
  this.removeEventListener("pointerdown", this.#down);
156
175
  window.removeEventListener("pointerup", this.#up, true);
157
176
  clearTimeout(this.#timer);
@@ -320,6 +339,7 @@ export class ChikyuSpace extends HTMLElement {
320
339
  else if (wasRiding)
321
340
  model.focus = this.#focusBeforeRide;
322
341
  }
342
+ this.#zoomRange(model.ride?.view === "from");
323
343
  this.#lostTold = false;
324
344
  const pose = model.pose;
325
345
  model.transition = (options.smooth ?? true) && !reduced && pose.valid ? { start: performance.now(), duration: 1200, from: { p: [pose.p[0], pose.p[1], pose.p[2]], q: [pose.q[0], pose.q[1], pose.q[2], pose.q[3]], fov: pose.fov } } : null;
@@ -328,6 +348,23 @@ export class ChikyuSpace extends HTMLElement {
328
348
  this.#gate?.request();
329
349
  this.dispatchEvent(new CustomEvent("chikyu-ride", { detail: this.riding }));
330
350
  }
351
+ /** From a body the zoom only narrows the field a little, so the range is 0.5 to 6: the `zoom-min` and `zoom-max` attributes, unless the page set them itself. */
352
+ #zoomRange(from) {
353
+ for (const name of ["zoom-min", "zoom-max"]) {
354
+ const mine = this.#ridden[name];
355
+ if (this.hasAttribute(name) && this.getAttribute(name) !== mine)
356
+ continue;
357
+ if (from) {
358
+ this.#ridden[name] = RIDE_ZOOM[name];
359
+ this.setAttribute(name, RIDE_ZOOM[name]);
360
+ }
361
+ else {
362
+ if (mine !== undefined)
363
+ this.removeAttribute(name);
364
+ delete this.#ridden[name];
365
+ }
366
+ }
367
+ }
331
368
  /** What the camera is riding along with now, or null. */
332
369
  get riding() {
333
370
  const ride = this.#model.ride;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/chikyu-earth",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "Chikyu Earth 地球 — A line-drawn globe for the web: country outlines that turn at the Earth's own rate, centred on where you are, with an optional realistic Earth from space (three.js), the Sun, Moon and planets, satellites on their orbits, and markers for any place. A web component and an SVG string.",
5
5
  "keywords": [
6
6
  "earth",
@@ -39,6 +39,7 @@
39
39
  "starlink",
40
40
  "celestrak",
41
41
  "spaceprogramx",
42
+ "space-program-x",
42
43
  "spx",
43
44
  "space",
44
45
  "satellite",
@@ -162,19 +163,16 @@
162
163
  },
163
164
  "dependencies": {
164
165
  "@johnmorrisdotca/chizu": "^1.6.0",
166
+ "@johnmorrisdotca/kazoku-ui": "^0.21.1",
165
167
  "d3-geo": "^3.1.1"
166
168
  },
167
169
  "peerDependencies": {
168
- "@johnmorrisdotca/kazoku-ui": ">=0.9.0",
169
170
  "three": ">=0.160.0",
170
171
  "astronomy-engine": ">=2.1.0",
171
172
  "satellite.js": ">=6.0.0",
172
173
  "@johnmorrisdotca/wakusei-planets": ">=0.5.0"
173
174
  },
174
175
  "peerDependenciesMeta": {
175
- "@johnmorrisdotca/kazoku-ui": {
176
- "optional": true
177
- },
178
176
  "three": {
179
177
  "optional": true
180
178
  },
@@ -194,7 +192,6 @@
194
192
  "@angular/core": "^22.2.4",
195
193
  "@angular/platform-browser": "^22.2.4",
196
194
  "@eslint/js": "^9.0.0",
197
- "@johnmorrisdotca/kazoku-ui": "^0.21.0",
198
195
  "@johnmorrisdotca/wakusei-planets": "^0.5.0",
199
196
  "@playwright/test": "1.64.0",
200
197
  "@sveltejs/vite-plugin-svelte": "^7.3.1",