@johnmorrisdotca/chikyu-earth 0.16.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,18 @@
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
+
9
+ ## 0.17.0 - 2026-11-08
10
+
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`.
12
+ - The demo moves to kazoku-ui ^0.21.0, whose default zoom range is 0.1x to 50x; the flat globe and the embed page keep their 1x to 5x with `zoom-min` and `zoom-max`.
13
+ - **Earth tile pyramid, the data** (MODULES-645, first phase): `scripts/make-earth-tiles.py` (`pnpm tiles`, `pnpm test:tiles`) cuts NASA's Blue Marble Next Generation (September 2004, with bathymetry, 21600 x 10800) and Black Marble 2016 (3 km, 13500 x 6750) into 512 px WebP tiles, day to level 4 (16384 x 8192), night to level 3 (8192 x 4096): 852 tiles, 10.3 MB. Seamless at the antimeridian, tested on a made-up map in CI. Built by `pages.yml` and served at `/tiles/` beside the demo; never in git, never in the npm package. Guide in English and Japanese (`docs/guides/earth-tiles.md`); sources and terms in NOTICE.md.
14
+ - **Why two packages** (MODULES-521): a guide in English and Japanese (`docs/guides/two-packages.md`), a README section and a Guides row say that chikyu-earth is for the Earth only, that the solar system is wakusei-planets', and that the dependency runs one way. Two tested examples: the two packages on one page (`examples/together/`, built and opened by `pnpm test:usage`) and every entry point bundled with wakusei-planets missing.
15
+ - Tests: the ride's glide is measured on the page's own clock, and the Auto-turn step of the drag-rule test turns by an angle read from the controller, not by a 1.5 s stopwatch; the docs site's browser test is the family's newer one (WebKit on a Mac is pressed with Alt+Tab) (MODULES-629).
16
+
5
17
  ## 0.16.0 - 2026-11-08
6
18
 
7
19
  - **Space Shuttle flights and the Hubble visits** (MODULES-623), in `@johnmorrisdotca/chikyu-earth/satellites`: `missions()` (the 135 flights, STS-1 to STS-135, with orbiter, liftoff and landing in UTC, the people NASA lists, the main payload in English and Japanese, the catalogue number, and `hubble` on STS-31, 61, 82, 103, 109 and 125), `missionOf(id)` (`"STS-31"`, `"31"`, `31`), `missionElements(file)` and `missionPosition(sets, ms, flight?)` (latitude, longitude, height and speed of the craft at a moment, from the element set nearest in time, by the same SGP4 as `createSatellites`; nothing before liftoff or after landing; nothing from elements over two days away). New types `Mission`, `MissionPosition`, `MissionFile`, `Orbiter` and `HubbleVisit`. Facts: NASA's mission pages (public domain, read 2026-11-08, listed in NOTICE.md).
package/NOTICE.md CHANGED
@@ -33,6 +33,19 @@ material, so no other licence applies. This package is not endorsed by NASA and
33
33
  The credit names are NASA's usual lines for these series; the Visible Earth pages (now at science.nasa.gov/earth/earth-observatory) did not show a credit line in the
34
34
  text read on 2026-11-02, so check them if you need the exact wording for print.
35
35
 
36
+ ## The Earth tiles
37
+
38
+ `scripts/make-earth-tiles.py` cuts two bigger NASA maps into a pyramid of 512 px WebP tiles (docs/guides/earth-tiles.md). The tiles are built in CI and served by GitHub Pages beside the demo at `/tiles/`; they are not in git and not in the npm package. Terms, read on 2026-11-08 at https://www.nasa.gov/nasa-brand-center/images-and-media/ (NASA Images and Media Usage Guidelines): "NASA content – images, audio, video, and media files used in the rendition of 3-dimensional models, such as texture maps and polygon data in any format – generally are not subject to copyright in the United States." and "NASA should be acknowledged as the source of the material." The same page says third-party material NASA uses with permission is marked as copyright protected with the holder's name; neither source below is marked so. Not endorsed by NASA; no NASA insignia or logotype is used.
39
+
40
+ | Layer | Source | Credit |
41
+ |---|---|---|
42
+ | `day` (levels 0 to 4, up to 16384 x 8192) | Blue Marble: Next Generation with topography and bathymetry, September 2004, 21600 x 10800 (https://assets.science.nasa.gov/content/dam/science/esd/eo/images/bmng/bmng-topography-bathymetry/september/world.topo.bathy.200409.3x21600x10800.jpg, SHA-256 863036b622ba3dab4eb4ffb7149730b02cfa433ce49672e9b7267022051e04a2); the same month as `day-*.webp` | "NASA Earth Observatory": the page https://science.nasa.gov/earth/earth-observatory/blue-marble-next-generation/ (read 2026-11-08) says "Anyone using or republishing Blue Marble: Next Generation please credit “NASA Earth Observatory.”" It was produced by Reto Stöckli, NASA Earth Observatory (NASA Goddard Space Flight Center). |
43
+ | `night` (levels 0 to 3, up to 8192 x 4096) | Earth at Night, Black Marble 2016 colour map at 3 km, 13500 x 6750 (https://assets.science.nasa.gov/content/dam/science/esd/eo/images/imagerecords/144000/144898/BlackMarble_2016_3km.jpg, SHA-256 230aac448ae68c358be433dd518888cccb3a85ccf66f7b44326441c324ad6725; page https://science.nasa.gov/earth/earth-observatory/earth-at-night/maps/, read 2026-11-08) | NASA Earth Observatory, Suomi NPP VIIRS data (the page names no further credit line in its text; check it for print) |
44
+
45
+ The bathymetry-free Blue Marble maps (base map, and base map with topography, on the same Blue Marble page) fall under the same NASA terms; the tiles use the one with bathymetry, as `day-*.webp` does. The clouds are not tiled: NASA's sharper cloud files (Visible Earth 57747, once at eoimages.gsfc.nasa.gov) are no longer served, and the Blue Marble 2002 page (https://science.nasa.gov/earth/earth-observatory/the-blue-marble-true-color-global-imagery-at-1km-resolution/) offers only the 2048 picture already in `clouds-2048.webp`.
46
+
47
+ Where the pyramid is hosted: GitHub Pages of this public repository, which costs nothing (docs/guides/earth-tiles.md). It adds 852 files and 10.3 MB to the site.
48
+
36
49
  ## The Moon's picture
37
50
 
38
51
  `moon-*.webp` is made by `scripts/make-textures.py` from NASA's Scientific Visualization Studio item 4720, "Moon: LROC colour mosaic" (https://svs.gsfc.nasa.gov/4720/,
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
  ```
@@ -131,6 +129,22 @@ export function ChikyuEarth({ center = "139.7,35.7", look = "thick" }: { center?
131
129
 
132
130
  The guides are also in Japanese (日本語), one language to a page: [docs/guides/ja/](docs/guides/ja/getting-started.md).
133
131
 
132
+ ## Two packages: the Earth here, the rest in wakusei-planets
133
+
134
+ Chikyu Earth is for someone who cares about the Earth only: the countries, day and night, city lights, clouds, markers and the satellites round it. The Sun, the other planets and the moons, where each one is on a date, and the solar system as a scene are [wakusei-planets](https://github.com/johnmorrisdotca/wakusei-planets). The dependency runs one way: wakusei-planets may use chikyu-earth, and chikyu-earth never needs wakusei-planets. A page about a city or a flight installs only this one, a page about Saturn only the other, and a page about the Earth in the solar system both; with both, wakusei-planets' line Earth is this package's globe with the countries:
135
+
136
+ ```sh
137
+ npm install @johnmorrisdotca/chikyu-earth @johnmorrisdotca/wakusei-planets
138
+ ```
139
+
140
+ ```ts no-run
141
+ import "@johnmorrisdotca/chikyu-earth/element";
142
+ import "@johnmorrisdotca/wakusei-planets/element";
143
+ import "@johnmorrisdotca/wakusei-planets/earth";
144
+ ```
145
+
146
+ The full page, the rule and what lives where, each example run by `pnpm test:usage`: [Why two packages](docs/guides/two-packages.md).
147
+
134
148
  ## The Earth from space
135
149
 
136
150
  An optional second look, for a page with room for a real picture: day and night by the real Sun, cities' lights, a sun glint on the sea, a cloud layer and the
@@ -146,14 +160,15 @@ atmosphere at the rim, drawn with three.js through kazoku-ui's shared renderer.
146
160
  ```
147
161
 
148
162
  Needs `three` and `@johnmorrisdotca/kazoku-ui` (both optional peers) and the pictures (1.6 MB, from NASA, in `dist/textures/`). It draws nothing while nothing changes,
149
- at most 30 times a second while it does, in one WebGL context, with textures that grow as you zoom and are freed after. All of it, the budget and the tests:
163
+ at most 30 times a second while it does, in one WebGL context, with textures that grow as you zoom and are freed after. With `tiles="/tiles/"` (a folder of NASA map
164
+ tiles, [how](docs/guides/earth-tiles.md)) it loads only the finer tiles in view, so you can zoom in to 20 times and stay sharp. All of it, the budget and the tests:
150
165
  [docs/realistic.md](docs/realistic.md).
151
166
 
152
167
  ## The Sun, the Moon and the planets
153
168
 
154
169
  `<chikyu-space>` (`@johnmorrisdotca/chikyu-earth/space/element`) places the Earth, the Moon, the Sun, the planets and Pluto (the real ones, with their moons, when [wakusei-planets](https://github.com/johnmorrisdotca/wakusei-planets) is installed: [guide](docs/guides/the-real-planets.md)) where they are at a date and time, with the Moon's phase and the Earth's day side
155
170
  from the light, a compressed scale you can read (and a true one that shows how empty it is), time that runs forwards or backwards, and a zoom from the Earth to the solar system. Positions are
156
- computed in the browser by astronomy-engine (MIT), nothing is fetched. [docs/space.md](docs/space.md).
171
+ computed in the browser by astronomy-engine (MIT), nothing is fetched. [docs/space.md](docs/space.md). The solar system is wakusei-planets' to own, so this view is moving there; this package keeps the Earth and its satellites ([why two packages](docs/guides/two-packages.md)).
157
172
 
158
173
  <p align="center"><img alt="The solar system on 2 November 2026 in the compressed scale: orbits round the Sun, the planets named" src="docs/images/space-solar.png" width="420"></p>
159
174
 
@@ -194,13 +209,24 @@ markers.add({ id: "tokyo", lon: 139.69, lat: 35.69, label: "Tokyo", group: "Citi
194
209
 
195
210
  ## Controls
196
211
 
197
- The shared [kazoku-ui view controls](https://github.com/johnmorrisdotca/kazoku-ui) supply every hand and button:
198
- 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,
199
216
  rotate or drag controls.
200
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
+
201
227
  ```html
202
- <div id="globe" tabindex="0"><chikyu-earth size="420"></chikyu-earth></div>
203
- <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>
204
230
  ```
205
231
 
206
232
  ```ts no-run
@@ -242,6 +268,8 @@ The rotation is the pair d3-geo's `rotate` takes: `[-longitude, -latitude]` cent
242
268
  | `center` | `"longitude,latitude"` to centre on. Wins over geolocation. | the reader's location, else `0,0` |
243
269
  | `look` | `line` or `thick`. (`style` is the older name for it: a framework reads `style` as CSS, so use `look` there.) | `line` |
244
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 |
245
273
 
246
274
  `setView(view, final = true)` applies a shared controller's `{ yaw, tilt, zoom, panX, panY }`. Every call updates
247
275
  the state; pass `final: false` for the cheap relative transform during a gesture and `final: true` for the full
@@ -358,6 +386,8 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
358
386
  | [The realistic Earth and markers](docs/guides/realistic-and-markers.md) | The Earth from space, markers |
359
387
  | [Satellites](docs/guides/satellites.md) | SGP4 and the space view |
360
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 |
390
+ | [Why two packages](docs/guides/two-packages.md) | This package and wakusei-planets: which to install, alone and together |
361
391
  | [How it stays light](docs/guides/how-it-works.md) | The budget |
362
392
  | [Architecture](docs/guides/architecture.md) | How the layers fit |
363
393
  | [Troubleshooting](docs/guides/troubleshooting.md) | Something does not appear |
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") });
@@ -4,6 +4,7 @@ import type { GeoPoint, GlobeView } from "../types.ts";
4
4
  import { lookAt } from "../view.ts";
5
5
  import type { Layer } from "./tiers.ts";
6
6
  import { type ThreeParts } from "./textures.ts";
7
+ import { type TileSet } from "./tile-set.ts";
7
8
  export type { ThreeParts };
8
9
  type Three = ThreeParts;
9
10
  /**
@@ -48,6 +49,8 @@ export interface EarthModel {
48
49
  radius: number;
49
50
  centre: GeoPoint;
50
51
  } | null;
52
+ /** The map tiles laid over the pictures while the scene is built: what they are doing, for a page or a test. */
53
+ tiles: TileSet | null;
51
54
  /** The pixel ratio the textures are chosen for. */
52
55
  ratio(): number;
53
56
  }
@@ -57,6 +60,10 @@ export interface EarthDeps {
57
60
  textureBase: () => string;
58
61
  /** The widest texture, 4096 at most. */
59
62
  cap: () => number;
63
+ /** Where the finer map tiles are (a URL ending with a slash), or `undefined`: the Earth then keeps the package's own pictures. */
64
+ tiles?: () => string | undefined;
65
+ /** Told once when the tile set has been read: the width in pixels of the finest level of each of its layers. */
66
+ onTiles?: (layers: Record<string, number>) => void;
60
67
  /** Clouds' eastward drift against the ground, degrees an hour. */
61
68
  drift: number;
62
69
  invalidate: () => void;
@@ -2,6 +2,7 @@ import { HOME_VIEW, lookAt } from "../view.js";
2
2
  import { ATMOSPHERE_FRAG, ATMOSPHERE_VERT, CLOUD_FRAG, SURFACE_FRAG, SURFACE_VERT } from "./shaders.js";
3
3
  import { subsolarPoint, unitVector } from "./sun.js";
4
4
  import { createTextureSet } from "./textures.js";
5
+ import { createTileSet } from "./tile-set.js";
5
6
  const RAD = Math.PI / 180;
6
7
  /**
7
8
  * The glow reaches this many radii from the centre; the globe at 1x is drawn to fit inside it.
@@ -24,6 +25,7 @@ export const newModel = () => ({
24
25
  lights: true,
25
26
  light: "sun",
26
27
  drawn: null,
28
+ tiles: null,
27
29
  ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
28
30
  });
29
31
  /**
@@ -113,6 +115,8 @@ export function createEarthItem(model, deps) {
113
115
  });
114
116
  const turned = new three.Group();
115
117
  const earth = new three.Mesh(grid, surface);
118
+ const tiles = createTileSet(three, turned, { sunDir, lights: surface.uniforms["lights"], boost: surface.uniforms["boost"], ortho: surface.uniforms["ortho"], water: uniform.water, night: uniform.night }, { assets: deps.assets, base: () => deps.tiles?.(), cap: deps.cap, invalidate: deps.invalidate, ...(deps.onTiles ? { onManifest: deps.onTiles } : {}) });
119
+ model.tiles = tiles;
116
120
  const clouds = new three.Mesh(grid, cloudMaterial);
117
121
  clouds.scale.setScalar(CLOUD_RADIUS);
118
122
  clouds.renderOrder = 2;
@@ -148,6 +152,7 @@ export function createEarthItem(model, deps) {
148
152
  camera.updateProjectionMatrix();
149
153
  model.drawn = { view: { ...view }, time: model.time, radius, centre: { ...model.centre } };
150
154
  textures.sync(radius * model.ratio());
155
+ tiles.sync({ lon: look.lon, lat: look.lat, width: size.width, height: size.height, panX: view.panX, panY: view.panY, radius }, [sunDir.value.x, sunDir.value.y, sunDir.value.z], true, model.ratio());
151
156
  deps.onPose?.({ lon: look.lon, lat: look.lat, radius, cx: size.width / 2 + view.panX, cy: size.height / 2 + view.panY, width: size.width, height: size.height });
152
157
  return false;
153
158
  },
@@ -155,6 +160,8 @@ export function createEarthItem(model, deps) {
155
160
  size = { width: next, height: nextHeight };
156
161
  },
157
162
  dispose() {
163
+ model.tiles = null;
164
+ tiles.dispose();
158
165
  textures.dispose();
159
166
  grid.dispose();
160
167
  surface.dispose();
@@ -1,9 +1,11 @@
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";
4
5
  export { setSharedRenderer, setThreeLoader };
5
6
  import type { OverlayHost } from "../markers/layer.ts";
6
7
  import { type Layer } from "./tiers.ts";
8
+ import type { TileStats } from "./tile-set.ts";
7
9
  type EarthLayer = Extract<Layer, "day" | "night" | "clouds" | "water">;
8
10
  /**
9
11
  * What the realistic Earth is doing: `loading` its pictures, `live` and drawing, `unavailable` (no WebGL), `lost` (the GPU took the context; it comes back by itself) or `idle` (another view has the page's one WebGL context; press or focus it to take it).
@@ -32,7 +34,7 @@ export type EarthState = "loading" | "live" | "unavailable" | "lost" | "idle";
32
34
  */
33
35
  export declare const readTime: (value: string | null) => number | "now";
34
36
  /**
35
- * The `<chikyu-earth-realistic>` custom element: the Earth from space, drawn with three.js through kazoku-ui's shared renderer (one WebGL context for the page). It takes `center` (`"lon,lat"`), `time` (`now` or an ISO date; the real Sun at that moment), `clouds="off"`, `lights="off"`, `live-seconds`, `texture-base` (where the pictures are served from) and `max-ratio` (the most device pixels to a CSS pixel the canvas is drawn at, 2 at most, and `0.5` draws at half the size and scales it up: for a background; read when the element connects, and it is the shared renderer's cap for the whole page), and a shared view controller's camera through `setView`. It draws only when something changes, at most 30 times a second, and nothing while it is out of sight or the tab is hidden.
37
+ * The `<chikyu-earth-realistic>` custom element: the Earth from space, drawn with three.js through kazoku-ui's shared renderer (one WebGL context for the page). It takes `center` (`"lon,lat"`), `time` (`now` or an ISO date; the real Sun at that moment), `clouds="off"`, `lights="off"`, `live-seconds`, `texture-base` (where the pictures are served from), `tiles` (where a set of finer map tiles is served from, see the Earth tiles guide: only the tiles in view are loaded, over the package's own pictures, which stay as the far view and the fallback; without it, or when a tile cannot be fetched, the Earth is drawn as before) and `max-ratio` (the most device pixels to a CSS pixel the canvas is drawn at, 2 at most, and `0.5` draws at half the size and scales it up: for a background; read when the element connects, and it is the shared renderer's cap for the whole page), and a shared view controller's camera through `setView`. It draws only when something changes, at most 30 times a second, and nothing while it is out of sight or the tab is hidden.
36
38
  *
37
39
  * @example
38
40
  * ```ts no-run
@@ -42,6 +44,7 @@ export declare const readTime: (value: string | null) => number | "now";
42
44
  * earth.setAttribute("center", "139.7,35.7");
43
45
  * earth.setAttribute("time", "2026-06-21T03:00Z");
44
46
  * earth.setAttribute("texture-base", "/textures/");
47
+ * earth.setAttribute("tiles", "/tiles/");
45
48
  * document.body.append(earth);
46
49
  * ```
47
50
  */
@@ -51,6 +54,11 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
51
54
  connectedCallback(): void;
52
55
  disconnectedCallback(): void;
53
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;
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. */
60
+ get tiles(): string | null;
61
+ set tiles(value: string | null);
54
62
  /** A box laid over the Earth for markers (see `@johnmorrisdotca/chikyu-earth/markers`): where it is, the pose of the last draw, and a way to hear the next. */
55
63
  get overlay(): OverlayHost;
56
64
  /** Where the view starts: longitude and latitude; the shared controls' yaw and tilt turn it from there. */
@@ -66,10 +74,11 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
66
74
  set light(value: LightMode);
67
75
  get lights(): boolean;
68
76
  set lights(value: boolean);
69
- /** What the element is doing, for a page or a test: its state, the texture widths held, the draws made. */
77
+ /** What the element is doing, for a page or a test: its state, the texture widths held, the map tiles held, the draws made. */
70
78
  get stats(): {
71
79
  state: EarthState;
72
80
  tiers: Record<EarthLayer, number>;
81
+ tiles: TileStats;
73
82
  draws: number;
74
83
  contexts: number;
75
84
  canvas: {
@@ -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;
@@ -46,7 +51,7 @@ export const readTime = (value) => {
46
51
  return Number.isFinite(ms) ? ms : "now";
47
52
  };
48
53
  /**
49
- * The `<chikyu-earth-realistic>` custom element: the Earth from space, drawn with three.js through kazoku-ui's shared renderer (one WebGL context for the page). It takes `center` (`"lon,lat"`), `time` (`now` or an ISO date; the real Sun at that moment), `clouds="off"`, `lights="off"`, `live-seconds`, `texture-base` (where the pictures are served from) and `max-ratio` (the most device pixels to a CSS pixel the canvas is drawn at, 2 at most, and `0.5` draws at half the size and scales it up: for a background; read when the element connects, and it is the shared renderer's cap for the whole page), and a shared view controller's camera through `setView`. It draws only when something changes, at most 30 times a second, and nothing while it is out of sight or the tab is hidden.
54
+ * The `<chikyu-earth-realistic>` custom element: the Earth from space, drawn with three.js through kazoku-ui's shared renderer (one WebGL context for the page). It takes `center` (`"lon,lat"`), `time` (`now` or an ISO date; the real Sun at that moment), `clouds="off"`, `lights="off"`, `live-seconds`, `texture-base` (where the pictures are served from), `tiles` (where a set of finer map tiles is served from, see the Earth tiles guide: only the tiles in view are loaded, over the package's own pictures, which stay as the far view and the fallback; without it, or when a tile cannot be fetched, the Earth is drawn as before) and `max-ratio` (the most device pixels to a CSS pixel the canvas is drawn at, 2 at most, and `0.5` draws at half the size and scales it up: for a background; read when the element connects, and it is the shared renderer's cap for the whole page), and a shared view controller's camera through `setView`. It draws only when something changes, at most 30 times a second, and nothing while it is out of sight or the tab is hidden.
50
55
  *
51
56
  * @example
52
57
  * ```ts no-run
@@ -56,11 +61,12 @@ export const readTime = (value) => {
56
61
  * earth.setAttribute("center", "139.7,35.7");
57
62
  * earth.setAttribute("time", "2026-06-21T03:00Z");
58
63
  * earth.setAttribute("texture-base", "/textures/");
64
+ * earth.setAttribute("tiles", "/tiles/");
59
65
  * document.body.append(earth);
60
66
  * ```
61
67
  */
62
68
  export class ChikyuEarthRealistic extends HTMLElement {
63
- static observedAttributes = ["center", "time", "clouds", "lights", "light", "live-seconds"];
69
+ static observedAttributes = ["center", "time", "clouds", "lights", "light", "live-seconds", "tiles"];
64
70
  #model = newModel();
65
71
  #mode = "now";
66
72
  #view;
@@ -73,6 +79,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
73
79
  #overlay;
74
80
  #pose = null;
75
81
  #listeners = new Set();
82
+ #hands;
83
+ #reach = null;
76
84
  #onContext = (state) => {
77
85
  if (state === "unavailable")
78
86
  this.#fail("WebGL is not available");
@@ -114,9 +122,19 @@ export class ChikyuEarthRealistic extends HTMLElement {
114
122
  assets: taken.renderer.assets,
115
123
  textureBase: () => this.#textureBase(),
116
124
  cap: () => this.#textureCap(),
125
+ tiles: () => this.tiles ?? undefined,
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
+ },
117
133
  drift: 1.5,
118
134
  invalidate: () => this.#gate?.soon(),
119
135
  onPose: (pose) => {
136
+ if (this.#hands)
137
+ this.#hands.controller.grabRadius = discRadius(pose.width, pose.height, 1);
120
138
  this.#pose = { ...pose, transform: "" };
121
139
  for (const listener of this.#listeners)
122
140
  listener(this.#pose);
@@ -140,12 +158,18 @@ export class ChikyuEarthRealistic extends HTMLElement {
140
158
  });
141
159
  this.addEventListener("pointerdown", this.#take);
142
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) });
143
162
  this.#startTick();
144
163
  this.#locate();
145
164
  }
146
165
  disconnectedCallback() {
147
166
  this.removeEventListener("pointerdown", this.#take);
148
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;
149
173
  clearInterval(this.#tick);
150
174
  this.#tick = undefined;
151
175
  this.#gate?.cancel();
@@ -167,6 +191,25 @@ export class ChikyuEarthRealistic extends HTMLElement {
167
191
  this.light = readLight(value);
168
192
  else if (name === "live-seconds")
169
193
  this.#startTick();
194
+ else if (name === "tiles")
195
+ this.#gate?.soon();
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
+ }
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. */
202
+ get tiles() {
203
+ const given = this.getAttribute("tiles");
204
+ if (!given)
205
+ return null;
206
+ return given.endsWith("/") ? given : `${given}/`;
207
+ }
208
+ set tiles(value) {
209
+ if (value === null || value === "")
210
+ this.removeAttribute("tiles");
211
+ else
212
+ this.setAttribute("tiles", value);
170
213
  }
171
214
  /** A box laid over the Earth for markers (see `@johnmorrisdotca/chikyu-earth/markers`): where it is, the pose of the last draw, and a way to hear the next. */
172
215
  get overlay() {
@@ -224,12 +267,13 @@ export class ChikyuEarthRealistic extends HTMLElement {
224
267
  this.#model.lights = value;
225
268
  this.#gate?.soon();
226
269
  }
227
- /** What the element is doing, for a page or a test: its state, the texture widths held, the draws made. */
270
+ /** What the element is doing, for a page or a test: its state, the texture widths held, the map tiles held, the draws made. */
228
271
  get stats() {
229
272
  const stats = this.#taken?.renderer.stats;
230
273
  return {
231
274
  state: this.#state,
232
275
  tiers: { ...this.#tiers },
276
+ tiles: this.#model.tiles?.stats ?? { ready: false, level: null, held: 0, shown: 0, loading: 0, failed: 0, requested: 0 },
233
277
  draws: stats?.draws ?? 0,
234
278
  contexts: stats?.contexts ?? 0,
235
279
  canvas: stats?.canvas ?? { width: 0, height: 0, pixels: 0 },
@@ -3,3 +3,5 @@ export { chooseTier, textureBytes, textureCap, MAX_TEXTURE, TIERS, TEXELS_PER_RA
3
3
  export { createGate, frameCap, type Gate } from "./gate.ts";
4
4
  export { lookAt, discRadius, ATMOSPHERE_OUTER, type LightMode } from "./earth.ts";
5
5
  export type { ThreeParts } from "./earth.ts";
6
+ export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView, type TileCamera, type TileId, type TileLayer, type VisibleTile } from "./tiles.ts";
7
+ export { TILE_KEEP_MS, TILE_LIMIT } from "./tile-set.ts";
@@ -4,3 +4,5 @@ export { subsolarPoint, unitVector, julianDay } from "./sun.js";
4
4
  export { chooseTier, textureBytes, textureCap, MAX_TEXTURE, TIERS, TEXELS_PER_RADIUS_PIXEL } from "./tiers.js";
5
5
  export { createGate, frameCap } from "./gate.js";
6
6
  export { lookAt, discRadius, ATMOSPHERE_OUTER } from "./earth.js";
7
+ export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView } from "./tiles.js";
8
+ export { TILE_KEEP_MS, TILE_LIMIT } from "./tile-set.js";
@@ -1,5 +1,12 @@
1
1
  export declare const SURFACE_VERT = "\nvarying vec2 vUv;\nvarying vec3 vNormal;\nvarying vec3 vWorld;\nvoid main() {\n vUv = uv;\n vNormal = normalize(mat3(modelMatrix) * position);\n vWorld = (modelMatrix * vec4(position, 1.0)).xyz;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}";
2
- export declare const SURFACE_FRAG = "\nuniform sampler2D dayMap;\nuniform sampler2D nightMap;\nuniform sampler2D waterMap;\nuniform vec3 sunDir;\nuniform float lights;\nuniform float boost;\nuniform float ortho;\nvarying vec2 vUv;\nvarying vec3 vNormal;\nvarying vec3 vWorld;\nvoid main() {\n vec3 n = normalize(vNormal);\n vec3 toEye = ortho > 0.5 ? vec3(0.0, 0.0, 1.0) : normalize(cameraPosition - vWorld);\n float ndl = dot(n, sunDir);\n float day = smoothstep(-0.10, 0.22, ndl);\n vec3 albedo = texture2D(dayMap, vUv).rgb;\n float water = texture2D(waterMap, vUv).r;\n\n vec3 lit = albedo * (0.07 + 1.0 * pow(max(ndl, 0.0), 0.5));\n float dusk = smoothstep(-0.14, 0.0, ndl) * (1.0 - smoothstep(0.0, 0.30, ndl));\n lit += vec3(0.55, 0.28, 0.14) * dusk * 0.30 * (0.35 + 0.65 * albedo.g);\n\n vec3 h = normalize(sunDir + toEye);\n float glint = pow(max(dot(n, h), 0.0), 220.0) * water * day;\n lit += vec3(1.0, 0.93, 0.80) * glint * 0.7;\n\n vec3 night = texture2D(nightMap, vUv).rgb;\n night = night * night * vec3(1.6, 1.5, 1.3) * lights + night * 0.25;\n vec3 col = mix(night, lit, day);\n col += pow(albedo, vec3(0.75)) * boost * 0.65 * (1.0 - day);\n\n float rim = pow(1.0 - clamp(dot(n, toEye), 0.0, 1.0), 3.0);\n float sunSide = 0.12 + 0.88 * smoothstep(-0.25, 0.5, ndl);\n col += vec3(0.20, 0.45, 1.0) * rim * sunSide * 0.55;\n gl_FragColor = vec4(col, 1.0);\n}";
2
+ export declare const SURFACE_FRAG: string;
3
+ /** The same surface for a map tile: the tile's own program. */
4
+ export declare const TILE_FRAG: string;
5
+ /**
6
+ * A map tile's corners: one 0 to 1 grid for every tile, put on the sphere here from the tile's longitude and latitude range (`rect`: west, north, east, south, in radians) at `radius`.
7
+ * `vUvG` is where the point is on the whole-Earth pictures.
8
+ */
9
+ export declare const TILE_VERT = "\nuniform vec4 rect;\nuniform float radius;\nvarying vec2 vUv;\nvarying vec2 vUvG;\nvarying vec3 vNormal;\nvarying vec3 vWorld;\nvoid main() {\n vUv = uv;\n float lon = mix(rect.x, rect.z, uv.x);\n float lat = mix(rect.y, rect.w, uv.y);\n vec3 unit = vec3(cos(lat) * sin(lon), sin(lat), cos(lat) * cos(lon));\n vUvG = vec2((lon + 3.14159265358979) / 6.28318530717959, 0.5 - lat / 3.14159265358979);\n vNormal = normalize(mat3(modelMatrix) * unit);\n vec4 world = modelMatrix * vec4(unit * radius, 1.0);\n vWorld = world.xyz;\n gl_Position = projectionMatrix * viewMatrix * world;\n}";
3
10
  export declare const CLOUD_FRAG = "\nuniform sampler2D cloudMap;\nuniform vec3 sunDir;\nuniform float shift;\nuniform float opacity;\nvarying vec2 vUv;\nvarying vec3 vNormal;\nvoid main() {\n vec3 n = normalize(vNormal);\n float ndl = dot(n, sunDir);\n float c = texture2D(cloudMap, vec2(vUv.x + shift, vUv.y)).r;\n float a = smoothstep(0.28, 0.88, c) * opacity;\n float day = smoothstep(-0.10, 0.25, ndl);\n vec3 col = mix(vec3(0.015, 0.02, 0.04), vec3(1.0), day * (0.18 + 0.82 * pow(max(ndl, 0.0), 0.45)));\n col += vec3(0.55, 0.28, 0.14) * smoothstep(-0.14, 0.0, ndl) * (1.0 - smoothstep(0.0, 0.25, ndl)) * 0.35;\n gl_FragColor = vec4(col, a);\n}";
4
11
  export declare const ATMOSPHERE_VERT = "\nvarying vec3 vPosView;\nvarying vec3 vNormalView;\nvoid main() {\n vec4 view = modelViewMatrix * vec4(position, 1.0);\n vPosView = view.xyz;\n vNormalView = normalize(normalMatrix * position);\n gl_Position = projectionMatrix * view;\n}";
5
12
  export declare const ATMOSPHERE_FRAG = "\nuniform vec3 sunView;\nuniform float outer;\nuniform float ortho;\nvarying vec3 vPosView;\nvarying vec3 vNormalView;\nvoid main() {\n vec3 n = normalize(vNormalView);\n vec3 v = ortho > 0.5 ? vec3(0.0, 0.0, 1.0) : normalize(-vPosView);\n float nz = clamp(dot(n, v), -1.0, 1.0);\n float rho = outer * sqrt(max(0.0, 1.0 - nz * nz));\n float t = clamp((rho - 1.0) / (outer - 1.0), 0.0, 1.0);\n vec2 dir = normalize(n.xy + vec2(1e-5, 0.0));\n float side = smoothstep(-0.40, 0.55, dot(vec3(dir, 0.0), sunView));\n float glow = pow(1.0 - t, 3.0) * (0.10 + 0.90 * side);\n vec3 col = mix(vec3(0.10, 0.22, 0.60), vec3(0.42, 0.68, 1.0), side);\n gl_FragColor = vec4(col, glow * 0.9);\n}";