@johnmorrisdotca/chikyu-earth 0.35.0 → 0.36.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 +13 -0
- package/NOTICE.md +23 -1
- package/README.md +20 -2
- package/dist/borders/layer.d.ts +75 -0
- package/dist/borders/layer.js +136 -0
- package/dist/borders/lines.d.ts +138 -0
- package/dist/borders/lines.js +227 -0
- package/dist/cities/host.d.ts +9 -0
- package/dist/cities/host.js +14 -2
- package/dist/country-names/geometry.d.ts +264 -0
- package/dist/country-names/geometry.js +372 -0
- package/dist/country-names/host.d.ts +82 -0
- package/dist/country-names/host.js +212 -0
- package/dist/grid/layer.d.ts +45 -0
- package/dist/grid/layer.js +66 -0
- package/dist/grid/lines.d.ts +85 -0
- package/dist/grid/lines.js +113 -0
- package/dist/markers/go-to-place.d.ts +27 -0
- package/dist/markers/go-to-place.js +35 -0
- package/dist/markers/index.d.ts +2 -1
- package/dist/markers/index.js +2 -1
- package/dist/markers/layer.d.ts +7 -0
- package/dist/markers/layer.js +7 -0
- package/dist/markers/place-layer.d.ts +58 -7
- package/dist/markers/place-layer.js +326 -64
- package/dist/markers/place-sprites.d.ts +33 -0
- package/dist/markers/place-sprites.js +161 -0
- package/dist/markers/places.d.ts +91 -6
- package/dist/markers/places.js +135 -6
- package/dist/realistic/earth.d.ts +11 -0
- package/dist/realistic/earth.js +54 -0
- package/dist/realistic/element.d.ts +65 -4
- package/dist/realistic/element.js +198 -26
- package/dist/realistic/immersive.d.ts +7 -0
- package/dist/realistic/immersive.js +17 -0
- package/dist/realistic/index.d.ts +6 -0
- package/dist/realistic/index.js +3 -0
- package/dist/realistic/textures.d.ts +3 -0
- package/dist/space/element.d.ts +81 -7
- package/dist/space/element.js +246 -16
- package/dist/space/index.d.ts +1 -1
- package/dist/space/scene.d.ts +53 -5
- package/dist/space/scene.js +88 -8
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.36.0 - 2026-11-12
|
|
6
|
+
|
|
7
|
+
- **kazoku-ui 0.41.0, a dependency of this package** (`^0.38.1` to `^0.41.0`, for MacBook browser runs in CI's own Playwright image): a page that installs chikyu-earth now gets kazoku-ui 0.41. What it changes for this package's elements: in Safari a trackpad pinch over a view zooms the view and no longer the whole page (kazoku-ui 0.40.2); `<kazoku-view-controls>` writes a pace, direction or axis read from the address back to its attributes (0.40.0, 0.40.1), which matters only to a page that reads them. The elements' own attributes, events and defaults are unchanged.
|
|
8
|
+
- **The planets and the Moon in the space view have their pictures** (MODULES-850). With wakusei-planets' painter (`setBodyPainter`), every planet, Pluto, the Sun and the moons that have a surface picture are drawn from it in the default look too (the view passes `mapped: true` in the painter's context; it was the shaded look until `bodies="painted"`), and the Moon is the painter's, so it is drawn like the planets (the view's own NASA Moon until it arrives, with `bodies="plain"`, and with no painter). Each drawing is told the camera and the view's size (`update({ ..., view })`, `BodyView` is new in `/space`), so a planet or the Moon big on the screen takes wakusei-planets' finer map tiles for the part in view, and the Sun's glow faces the camera. A painter may carry `credit: { en, ja }`, which the view writes under the picture while it draws the bodies (`bodies-credit="off"` takes it away). `stats.bodies` adds `held` (the moons kept, shown or gone from the view for less than four seconds), `moon` and `tiles`; the test of the moons let go at rest reads `held`, since with their pictures the moons share the planets' shaders. The demo uses wakusei-planets 0.36.0 with its tiles and the credit; NOTICE.md lists the pictures' sources, four of them CC BY 4.0. Tests: `e2e/space-full.gl.ts`.
|
|
9
|
+
- **`<chikyu-space>` works full screen** (MODULES-848). `immersive` (new attribute and property, as on `<chikyu-earth-realistic>`): the element fills its box in any shape with the Earth and its glow inside the shorter side, a plain wheel zooms (out past the Moon to the planets, and back), and a drag anywhere, a touch drag too, turns the view round the Earth; without it kazoku-ui's rules stand. The full-screen page takes `look=space`. Browser tests: the element and its canvas are the window to a pixel at 1440 by 900, 390 by 844 and 2400 by 700; the wheel goes out until the Moon is in view and back; a drag from a corner turns; `checkGestures` is green but for the wheel's pan; the freeze test adds the full-screen space view at rest and on a 5K screen.
|
|
10
|
+
- **The grid and country names on the Earth** (MODULES-1150). `<chikyu-earth-realistic>` and `<chikyu-space>` take `grid` (the property `grid`) and draw the meridians and parallels on the Earth: every 30 degrees while its radius on the screen is under 220 CSS pixels (`GRID_FINE_RADIUS`), every 15 above; the equator brightest, the tropics and polar circles bright (the IAU's tilt, `EARTH_TILT`), the prime meridian warm; under the clouds, light by day and dim by night, turning with the Earth. One batch of lines (one draw call; 3,240 segments, a 95 kB buffer, made once). They take `country-names` (a bare attribute for 40 at most, or a number up to 120; `countryNamesStyle` and `--chikyu-country-*` for the look) and name the countries in sight at the middle of the part of each in view, sized by it, in the page's language (chizu's English and Japanese names), never over each other or over the names of cities, places, a page's markers (`OverlayHost.claim`, which `attachMarkers` now calls) and the space view's bodies, inside the Earth's disc (so clear of the star names), never from the far side, more as the Earth grows. chizu's `world-geo` is loaded only when it is set (shared with `borders`); `chikyu-country-names-unavailable` and `chikyu-grid-unavailable` say when either cannot be made. Each element's code grows by 3.7 to 3.9 kB gzipped; nothing is drawn at rest. `stats.grid` and `stats.countryNames` have the counts; the pure parts (`gridLines`, `countrySpots`, `layoutCountryNames` and the rest) are in `@johnmorrisdotca/chikyu-earth/realistic`. The demo has Grid and Country names buttons (`grid=on`, `country-names=on` in the address). New guide: The grid and country names on the Earth (English and Japanese).
|
|
11
|
+
- **Any number of places on the live 3D Earth** (MODULES-863, the drawing parts). `places` on `<chikyu-space>` and `<chikyu-earth-realistic>` now takes up to 5,000 places (`MAX_PLACES`, was 200). The first `PLACE_MARKS` (32) in sight, `here` first and then in the order given, stand up out of the ground with their names as before; every other place is a ring lying on the ground, all of them one draw call (three.js `Points`, made only while a ring is shown, its buffers written again only when the places or their groups change), so a thousand places add one draw call to a frame and nothing at rest. Places closer than about 24 pixels on the screen are gathered into one larger ring with their count, in cells fixed to the ground so the groups turn with the Earth (`groupPlaces`, `groupCell`, `PLACE_GROUP_PX`); the reader's own place is never gathered. A place may have a colour of its own (`color`: a hex colour, `rgb()`/`hsl()` with numbers, or a colour's name). Places on the night side are drawn at half strength and their names a little dimmer, still readable (`layoutPlaces` takes `sun` and each shape says its `night`); nothing is dimmed with `light="lit"`. `goToPlace(idOrLabel, { smooth })` turns the view so a place is in the middle, at a pace a reader can follow, or at once for a reader who asked for less motion; in the space view only while the camera looks at the Earth. `stats.places` adds `marks`, `sprites` and `groups`. A click on the globe or on a place is not part of this release: it waits for a decision (MODULES-1082).
|
|
12
|
+
- **Borders on the Earth** (MODULES-864). `<chikyu-earth-realistic>` and `<chikyu-space>` take `borders` (`countries`, `regions`, or bare for both; the property `borders` as `{ countries, regions }`) and draw the borders on the land as thin lines that turn with the Earth, above the clouds and under the air, by day and by night. Only edges two shapes share are drawn, never a coast. The countries are chizu's `world-geo` (Natural Earth 1:110m, public domain), loaded with a dynamic import only when a set is switched on (166 kB minified, 44.3 kB gzipped; a page with the line globe has it already). The regions (provinces, states) come from the page's own `borderData.regions(code)`, asked only for the countries the view shows once the Earth's radius on the screen is 900 CSS pixels or more (`BORDER_REGIONS_RADIUS`); chizu's own regions are drawn for flat maps and cannot be laid on a sphere yet (MODULES-1142). Each set is one batch of lines (one draw call); the 3,012 country segments are a 72 kB buffer; the element's code grows by 1.9 kB gzipped; nothing is drawn at rest. `chikyu-borders-unavailable` is sent when the shapes cannot be loaded, and the Earth goes on without them; `stats.borders` has the counts. The pure parts (`sharedEdges`, `shapeBoxes`, `codesNear`, `readBorders`) are in `@johnmorrisdotca/chikyu-earth/realistic`. The demo has a Borders button (`borders=on` in the address). New guide: Borders on the Earth (English and Japanese).
|
|
13
|
+
- **Place grouping has an off switch, and no place is lost without `Points`** (MODULES-863). `place-groups="off"` (and `placeGroups = false`) leaves every place its own ring instead of gathering crowds into one ring with a count; gathering stays the default. When the three.js parts handed over lack `Points`, the picture cannot draw the rings of the places that are not markers of their own: they were dropped without a word. The places' layer now draws them itself as small circles in the page (at most `PLACE_DOTS`, 600), the element sends `chikyu-places-unavailable` once, and `stats.places.omitted` counts the places in sight that had no room. `readPlaceGroups` and `PLACE_DOTS` are exported from `/markers`.
|
|
14
|
+
- **Satellite names are kept from one frame to the next** (MODULES-1096). The names drawn beside the satellite rings are cached for each satellite and language: a frame reads the page's language once rather than once for each satellite, and no longer works out an orbit just to read a name that does not change. The cache is dropped when the language changes, when `satelliteNames` is set and when a group is replaced. Nothing a page can see changes.
|
|
15
|
+
- **Two flaky tests are steady** (MODULES-1149, MODULES-1154). The satellite-label test waits for the other view's names before it compares them, and the freeze test reads the frames and the draw calls in one call. Tests only; the budgets are unchanged.
|
|
16
|
+
- **A country-names load that ends after the element let go is ignored** (MODULES-1150). The layer no longer makes its box again, or tells the page of a failure, when the outlines arrive after `dispose`.
|
|
17
|
+
|
|
5
18
|
## 0.35.0 - 2026-11-12
|
|
6
19
|
|
|
7
20
|
- **The figures follow a sky culture** (MODULES-1125). `constellation-culture` is `iau` (the 88, the default), `western`, `japanese` (the 88 by their Japanese names, then the traditional figures such as Subaru, the Pleiades) or `chinese`; the lines, the hovered and picked figure and its name follow it, and the events carry `id`, `kind` and `culture`. The value is exactly what the page sets (a Japanese page keeps the IAU's figures unless it says `japanese`); an unknown value is `iau` with one warning. Each culture's data is a dynamic import of its own, fetched only when asked for. hoshi-stars' `createFigureLines` takes no culture yet, so the lines of a culture are laid out here from `figures(culture)`.
|
package/NOTICE.md
CHANGED
|
@@ -10,6 +10,21 @@ admin-0 countries, which Natural Earth places in the **public domain**
|
|
|
10
10
|
(https://github.com/johnmorrisdotca/chizu, MIT, by John Morris), whose `world-geo` entry
|
|
11
11
|
(`@johnmorrisdotca/chizu/world-geo`) holds them as longitude and latitude; nothing is fetched at runtime.
|
|
12
12
|
|
|
13
|
+
## Borders
|
|
14
|
+
|
|
15
|
+
The borders on the realistic Earth and the space view (`borders`, `src/borders/`) are drawn from the same data: chizu's
|
|
16
|
+
`world-geo`, Natural Earth 5.1.2's admin-0 countries at 1:110m, credited as chizu credits them. chizu's NOTICE.md quotes
|
|
17
|
+
Natural Earth's terms of use (https://www.naturalearthdata.com/about/terms-of-use/, read by chizu on 2026-10-01): the data
|
|
18
|
+
"are in the public domain" and "Crediting the authors is unnecessary"; it is done here anyway: Natural Earth, made by
|
|
19
|
+
volunteers and supported by the North American Cartographic Information Society. Only the edges two countries share are
|
|
20
|
+
drawn; the code that finds them is this package's own and MIT. Natural Earth draws borders as they are held on the ground
|
|
21
|
+
(de facto), and so do these lines. The regions (provinces, states) are the page's own data, handed over through
|
|
22
|
+
`borderData.regions`, with the page's own licence; this package ships none (2026-11-11).
|
|
23
|
+
|
|
24
|
+
## The grid and the country names on the 3D Earth
|
|
25
|
+
|
|
26
|
+
The grid (`grid`, `src/grid/`) is drawn from numbers alone: meridians and parallels every 15 degrees, the tropics and polar circles at the Earth's tilt of 23.4393 degrees (the IAU's obliquity of the ecliptic at J2000, as under "The printable sheets"). The country names on the realistic Earth and the space view (`country-names`, `src/country-names/`) are chizu's `world-geo` names (see "Country names and codes" below), loaded only when asked for; where each name goes is worked out by this package's own code (MIT) from the same Natural Earth outlines (see "Borders"), and no label positions are taken from any other map (2026-11-12).
|
|
27
|
+
|
|
13
28
|
## Country names and codes
|
|
14
29
|
|
|
15
30
|
Each outline's English name, Japanese name and country code come from **chizu**'s `world-geo`, whose names are
|
|
@@ -55,7 +70,14 @@ item to: NASA's Scientific Visualization Studio" (Visualizer Ernie Wright, USRA;
|
|
|
55
70
|
## The planets' places
|
|
56
71
|
|
|
57
72
|
`<chikyu-space>` computes positions with **astronomy-engine** (https://github.com/cosinekitty/astronomy, MIT, copyright Don Cross), the page's own optional peer dependency: this package does not
|
|
58
|
-
bundle or ship it. In this package the planets are drawn as plain colours, from no picture
|
|
73
|
+
bundle or ship it. In this package the planets are drawn as plain colours, from no picture: a page that wants their pictures hands the view a painter (`setBodyPainter`), and the painter's pictures are the page's, with their own credit, which the view writes under the picture when the painter carries one (`credit`).
|
|
74
|
+
|
|
75
|
+
The demo site's space views paint the Sun, the planets, Pluto, their moons and the Moon with the pictures of **wakusei-planets** (https://github.com/johnmorrisdotca/wakusei-planets, MIT, by John Morris), a separate optional package. Its 512 and 1024 pixel pictures are copied from its npm package and served beside the demo (`planets/`); its finer map tiles are read from its own site (https://johnmorrisdotca.github.io/wakusei-planets/tiles/) when a planet or the Moon is big on the screen. None of them is in this package. Their sources and licences, as wakusei-planets' NOTICE.md gives them (read 2026-11-11, version 0.36.0):
|
|
76
|
+
|
|
77
|
+
- Mars, Pluto, the Moon, the moons of Jupiter and Saturn, Triton, Charon, the Earth and Saturn's rings, and the finer tiles: maps by NASA, the USGS, JPL and the missions' teams, public domain (NASA asks to be acknowledged as the source).
|
|
78
|
+
- Venus, Saturn's bands, Neptune and the Sun: **Solar System Scope** (https://www.solarsystemscope.com/textures/), whose page says (read 2026-11-11): "Distributed under Attribution 4.0 International license: You may use, adapt, and share these textures for any purpose, even commercially." Mercury: "Mercury Realistic 8K" by **Shady Tex** (https://sketchfab.com/3d-models/mercury-realistic-8k-215f364627054d25ae03bcd72afda714), the same map as Solar System Scope's. Jupiter, Uranus and Saturn's poles: "Jupiter", "Uranus" and "Saturn" by **Nestaeric** (https://sketchfab.com/Nestaeric). Each Sketchfab page shows the licence "CC Attribution" (read 2026-11-11). All of these are **CC BY 4.0** (https://creativecommons.org/licenses/by/4.0/: "You must give appropriate credit, provide a link to the license, and indicate if changes were made"). wakusei-planets resized and reprojected them; its NOTICE.md says what was done to each.
|
|
79
|
+
|
|
80
|
+
The demo credits them on the screen: the space view writes "Planet and Moon pictures: NASA, USGS and JPL (public domain); Solar System Scope, Shady Tex and Nestaeric (CC BY 4.0), by way of Wakusei Planets." under the picture (in Japanese on a Japanese page), the full-screen page writes it under its title, and the demo's credit links lead here.
|
|
59
81
|
|
|
60
82
|
## Satellites
|
|
61
83
|
|
package/README.md
CHANGED
|
@@ -232,9 +232,25 @@ console.log(bodyLabelText("en"), bodyLabelText("ja"), BODY_LABEL_ATTRIBUTES.leng
|
|
|
232
232
|
<chikyu-earth-realistic city-names="24"></chikyu-earth-realistic>
|
|
233
233
|
```
|
|
234
234
|
|
|
235
|
+
## Borders
|
|
236
|
+
|
|
237
|
+
`borders` on `<chikyu-earth-realistic>` and `<chikyu-space>` draws the borders between countries on the land, as thin lines that turn with the Earth, by day and by night, from chizu's `world-geo` (Natural Earth 1:110m, public domain), loaded only when it is set (44 kB gzipped). `borders="regions"` adds a page's own provinces and states (`borderData.regions`) once the Earth is large enough to tell them apart. Each set is one batch of lines; nothing is drawn at rest: [guide](docs/guides/borders.md).
|
|
238
|
+
|
|
239
|
+
```html
|
|
240
|
+
<chikyu-earth-realistic borders="countries"></chikyu-earth-realistic>
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## The grid and country names
|
|
244
|
+
|
|
245
|
+
`grid` on `<chikyu-earth-realistic>` and `<chikyu-space>` draws the meridians and parallels on the Earth (every 30 degrees while it is small on the screen, every 15 once it is large), with the equator, the tropics, the polar circles and the prime meridian picked out, light by day and dim by night. `country-names` names the countries in sight at the middle of the part of each you can see, in the page's language (chizu's English and Japanese names), never over another name and never on the far side. Both are off unless set; the grid is one batch of lines and nothing is drawn at rest: [guide](docs/guides/grid-and-country-names.md).
|
|
246
|
+
|
|
247
|
+
```html
|
|
248
|
+
<chikyu-earth-realistic grid country-names></chikyu-earth-realistic>
|
|
249
|
+
```
|
|
250
|
+
|
|
235
251
|
## You are here, and places on the Earth
|
|
236
252
|
|
|
237
|
-
`places` on `<chikyu-space>` and `<chikyu-earth-realistic>` marks places on the Earth, each a beam, a pin or a ring (`places-look`) standing out of the ground, turning with the Earth
|
|
253
|
+
`places` on `<chikyu-space>` and `<chikyu-earth-realistic>` marks places on the Earth, each a beam, a pin or a ring (`places-look`) standing out of the ground, turning with the Earth, hidden on its far side and dimmer at night: `kind: "here"` for the reader's own place (brighter, with a quiet pulse) and favourites, quieter, each with an optional `color`. Up to 5,000: the first 32 in sight stand up with their names, the rest are rings in one draw call, crowds are gathered with their count, and `goToPlace(id)` turns the view to one. Names never overlap; nothing is drawn at rest. The package never asks for the reader's place and stores or sends nothing: the page asks on a press and rounds the place with `nearby` first: [guide](docs/guides/places.md).
|
|
238
254
|
|
|
239
255
|
```html
|
|
240
256
|
<chikyu-space places='[{"id":"me","lon":-79.4,"lat":43.7,"label":"You are here","kind":"here"}]'></chikyu-space>
|
|
@@ -557,6 +573,8 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
|
|
|
557
573
|
| [The date follows the clock, and Play](docs/guides/time-and-play.md) | The `chikyu-timechange` event, a `speed` for the space view and the realistic Earth, Play, Pause and Back |
|
|
558
574
|
| [Names on the stars and faint constellation lines](docs/guides/sky-names.md) | The brightest stars named and the constellations as faint lines over the sky, in hoshi-stars' attribute names |
|
|
559
575
|
| [City names on the Earth](docs/guides/city-names.md) | Cities named from kuni's list, more as the Earth grows on the screen, in the page's language |
|
|
576
|
+
| [Borders on the Earth](docs/guides/borders.md) | The borders between countries, and a page's own regions once the Earth is large enough |
|
|
577
|
+
| [The grid and country names on the Earth](docs/guides/grid-and-country-names.md) | Meridians and parallels with the special lines picked out, and the countries in sight named in the page's language |
|
|
560
578
|
| [A name on the Earth](docs/guides/body-label.md) | The Earth's name written on the globe, in the family's plain attribute names |
|
|
561
579
|
| [You are here, and places on the Earth](docs/guides/places.md) | The reader's place and favourite places as markers standing out of the Earth, asked for only on a press, kept on the device |
|
|
562
580
|
| [Meteors seen from space](docs/guides/meteors.md) | Streaks over the night side, the shower table, what is real and what is illustration |
|
|
@@ -590,7 +608,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
|
|
|
590
608
|
|
|
591
609
|
## How to cite
|
|
592
610
|
|
|
593
|
-
> Morris, J. (2026). *Chikyu Earth* (version 0.
|
|
611
|
+
> Morris, J. (2026). *Chikyu Earth* (version 0.36.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
|
|
594
612
|
|
|
595
613
|
GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA. Cite the version you used (`npm ls @johnmorrisdotca/chikyu-earth`), and credit the sources behind the numbers and pictures: [NOTICE.md](NOTICE.md) says who made each one and under what terms.
|
|
596
614
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type * as THREE from "three";
|
|
2
|
+
import type { ThreeParts } from "../realistic/textures.ts";
|
|
3
|
+
import { type BorderShapes } from "./lines.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Where the borders' shapes come from. `countries` gives the countries (chizu's `world-geo`, Natural Earth 1:110m, when left out); `regions` gives one country's regions by its code, or `null`
|
|
6
|
+
* for a country with none, and draws no regions when left out. Each is a set of shapes in longitude and latitude.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts no-run
|
|
10
|
+
* import type { BorderData } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
11
|
+
*
|
|
12
|
+
* const data: BorderData = { regions: async (code) => (code === "JP" ? (await fetch("/regions/jp.json")).json() : null) };
|
|
13
|
+
* console.log(typeof data.regions);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export interface BorderData {
|
|
17
|
+
countries?: () => Promise<BorderShapes>;
|
|
18
|
+
regions?: (code: string) => Promise<BorderShapes | null>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* What the borders have done: how many segments each set has, whether each was drawn at the last draw, the countries whose regions have arrived, how many times a set's lines were made, and whether
|
|
22
|
+
* a set could not be loaded.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts no-run
|
|
26
|
+
* import type { BorderStats } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
27
|
+
*
|
|
28
|
+
* const empty: BorderStats = { countries: 0, regions: 0, shown: { countries: false, regions: false }, loaded: [], builds: 0, failed: false };
|
|
29
|
+
* console.log(empty);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export interface BorderStats {
|
|
33
|
+
countries: number;
|
|
34
|
+
regions: number;
|
|
35
|
+
shown: {
|
|
36
|
+
countries: boolean;
|
|
37
|
+
regions: boolean;
|
|
38
|
+
};
|
|
39
|
+
loaded: string[];
|
|
40
|
+
builds: number;
|
|
41
|
+
failed: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** What the element and the scene share: the sets switched on, where the shapes come from, and what the layer did. */
|
|
44
|
+
export interface BorderState {
|
|
45
|
+
countries: boolean;
|
|
46
|
+
regions: boolean;
|
|
47
|
+
data: BorderData;
|
|
48
|
+
onError?: (error: unknown) => void;
|
|
49
|
+
stats: BorderStats;
|
|
50
|
+
}
|
|
51
|
+
export declare const newBorderState: () => BorderState;
|
|
52
|
+
/** Places the view shows, how far round the sphere the view reaches from each (degrees), and the Earth's radius on the screen (CSS pixels). */
|
|
53
|
+
export interface BorderView {
|
|
54
|
+
points: readonly {
|
|
55
|
+
lon: number;
|
|
56
|
+
lat: number;
|
|
57
|
+
}[];
|
|
58
|
+
angle: number;
|
|
59
|
+
radius: number;
|
|
60
|
+
}
|
|
61
|
+
export interface BorderLayer {
|
|
62
|
+
sync(view: BorderView): void;
|
|
63
|
+
dispose(): void;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Makes the layer under `parent` (the group that turns with the Earth). It loads what the sets switched on need, the first time `sync` asks.
|
|
67
|
+
*
|
|
68
|
+
* @param three - The page's three.js; it must have `LineSegments`.
|
|
69
|
+
* @param parent - The Earth's own group.
|
|
70
|
+
* @param state - The model's borders.
|
|
71
|
+
* @param invalidate - Asks for a draw (when shapes arrive).
|
|
72
|
+
* @param order - The render order: after the clouds, before the air.
|
|
73
|
+
* @returns The layer.
|
|
74
|
+
*/
|
|
75
|
+
export declare function createBorderLayer(three: ThreeParts, parent: THREE.Object3D, state: BorderState, invalidate: () => void, order: number): BorderLayer;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { BORDER_REGIONS_RADIUS, codesNear, shapeBoxes, sharedEdges } from "./lines.js";
|
|
2
|
+
/** The lines sit this far above the ground (in Earth radii): over the map tiles and the sphere's flat facets, and under the clouds. */
|
|
3
|
+
const BORDER_RADIUS = 1.0015;
|
|
4
|
+
const COUNTRY_LOOK = { color: "#ffd75e", opacity: 0.85 };
|
|
5
|
+
const REGION_LOOK = { color: "#ffd75e", opacity: 0.6 };
|
|
6
|
+
export const newBorderState = () => ({ countries: false, regions: false, data: {}, stats: { countries: 0, regions: 0, shown: { countries: false, regions: false }, loaded: [], builds: 0, failed: false } });
|
|
7
|
+
const worldGeo = async () => (await import("@johnmorrisdotca/chizu/world-geo")).default;
|
|
8
|
+
/**
|
|
9
|
+
* Makes the layer under `parent` (the group that turns with the Earth). It loads what the sets switched on need, the first time `sync` asks.
|
|
10
|
+
*
|
|
11
|
+
* @param three - The page's three.js; it must have `LineSegments`.
|
|
12
|
+
* @param parent - The Earth's own group.
|
|
13
|
+
* @param state - The model's borders.
|
|
14
|
+
* @param invalidate - Asks for a draw (when shapes arrive).
|
|
15
|
+
* @param order - The render order: after the clouds, before the air.
|
|
16
|
+
* @returns The layer.
|
|
17
|
+
*/
|
|
18
|
+
export function createBorderLayer(three, parent, state, invalidate, order) {
|
|
19
|
+
const Lines = three.LineSegments;
|
|
20
|
+
if (!Lines)
|
|
21
|
+
throw new Error("the three.js handed over has no LineSegments, which the borders need");
|
|
22
|
+
let disposed = false;
|
|
23
|
+
let asked = false;
|
|
24
|
+
let boxes = null;
|
|
25
|
+
const regionAsked = new Set();
|
|
26
|
+
const regionLines = new Map();
|
|
27
|
+
const stats = state.stats;
|
|
28
|
+
const make = (look) => {
|
|
29
|
+
const geometry = new three.BufferGeometry();
|
|
30
|
+
const material = new three.LineBasicMaterial({ color: look.color, transparent: true, opacity: look.opacity, depthWrite: false });
|
|
31
|
+
const lines = new Lines(geometry, material);
|
|
32
|
+
lines.scale.setScalar(BORDER_RADIUS);
|
|
33
|
+
lines.renderOrder = order;
|
|
34
|
+
lines.visible = false;
|
|
35
|
+
parent.add(lines);
|
|
36
|
+
return lines;
|
|
37
|
+
};
|
|
38
|
+
const countries = make(COUNTRY_LOOK);
|
|
39
|
+
const regions = make(REGION_LOOK);
|
|
40
|
+
const fill = (lines, positions) => {
|
|
41
|
+
lines.geometry.dispose();
|
|
42
|
+
const geometry = new three.BufferGeometry();
|
|
43
|
+
geometry.setAttribute("position", new three.BufferAttribute(positions, 3));
|
|
44
|
+
lines.geometry = geometry;
|
|
45
|
+
stats.builds += 1;
|
|
46
|
+
};
|
|
47
|
+
const fail = (error) => {
|
|
48
|
+
if (disposed)
|
|
49
|
+
return;
|
|
50
|
+
stats.failed = true;
|
|
51
|
+
state.onError?.(error);
|
|
52
|
+
};
|
|
53
|
+
const loadCountries = () => {
|
|
54
|
+
if (asked)
|
|
55
|
+
return;
|
|
56
|
+
asked = true;
|
|
57
|
+
let loading;
|
|
58
|
+
try {
|
|
59
|
+
loading = (state.data.countries ?? worldGeo)();
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
fail(error);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
loading.then((shapes) => {
|
|
66
|
+
if (disposed)
|
|
67
|
+
return;
|
|
68
|
+
const positions = sharedEdges(shapes);
|
|
69
|
+
fill(countries, positions);
|
|
70
|
+
stats.countries = positions.length / 6;
|
|
71
|
+
boxes = shapeBoxes(shapes);
|
|
72
|
+
invalidate();
|
|
73
|
+
}, fail);
|
|
74
|
+
};
|
|
75
|
+
const loadRegions = (codes) => {
|
|
76
|
+
const loader = state.data.regions;
|
|
77
|
+
if (!loader)
|
|
78
|
+
return;
|
|
79
|
+
for (const code of codes) {
|
|
80
|
+
if (regionAsked.has(code))
|
|
81
|
+
continue;
|
|
82
|
+
regionAsked.add(code);
|
|
83
|
+
let loading;
|
|
84
|
+
try {
|
|
85
|
+
loading = loader(code);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
fail(error);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
loading.then((shapes) => {
|
|
92
|
+
if (disposed || !shapes)
|
|
93
|
+
return;
|
|
94
|
+
regionLines.set(code, sharedEdges(shapes));
|
|
95
|
+
// one batch for every country's regions that has arrived
|
|
96
|
+
let total = 0;
|
|
97
|
+
for (const one of regionLines.values())
|
|
98
|
+
total += one.length;
|
|
99
|
+
const all = new Float32Array(total);
|
|
100
|
+
let at = 0;
|
|
101
|
+
for (const one of regionLines.values()) {
|
|
102
|
+
all.set(one, at);
|
|
103
|
+
at += one.length;
|
|
104
|
+
}
|
|
105
|
+
fill(regions, all);
|
|
106
|
+
stats.regions = total / 6;
|
|
107
|
+
stats.loaded = [...regionLines.keys()];
|
|
108
|
+
invalidate();
|
|
109
|
+
}, fail);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
return {
|
|
113
|
+
sync(view) {
|
|
114
|
+
if (state.countries || state.regions)
|
|
115
|
+
loadCountries();
|
|
116
|
+
const close = view.radius >= BORDER_REGIONS_RADIUS;
|
|
117
|
+
if (state.regions && close && boxes) {
|
|
118
|
+
const near = boxes;
|
|
119
|
+
loadRegions([...new Set(view.points.flatMap((point) => codesNear(near, point.lon, point.lat, view.angle)))]);
|
|
120
|
+
}
|
|
121
|
+
countries.visible = state.countries && stats.countries > 0;
|
|
122
|
+
regions.visible = state.regions && close && stats.regions > 0;
|
|
123
|
+
stats.shown = { countries: countries.visible, regions: regions.visible };
|
|
124
|
+
},
|
|
125
|
+
dispose() {
|
|
126
|
+
disposed = true;
|
|
127
|
+
for (const lines of [countries, regions]) {
|
|
128
|
+
parent.remove(lines);
|
|
129
|
+
lines.geometry.dispose();
|
|
130
|
+
lines.material.dispose();
|
|
131
|
+
}
|
|
132
|
+
regionLines.clear();
|
|
133
|
+
stats.shown = { countries: false, regions: false };
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One shape a border set is made of: a GeoJSON feature in longitude and latitude (degrees), a `Polygon` or `MultiPolygon`, with an optional `code` in its properties (a country's code, which says
|
|
3
|
+
* which regions to ask for). Any other geometry is passed over.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import type { BorderFeature } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
8
|
+
*
|
|
9
|
+
* const square: BorderFeature = { properties: { code: "A" }, geometry: { type: "Polygon", coordinates: [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]] } };
|
|
10
|
+
* console.log(square.properties?.code);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export interface BorderFeature {
|
|
14
|
+
properties?: {
|
|
15
|
+
code?: string | null;
|
|
16
|
+
} | null;
|
|
17
|
+
geometry: {
|
|
18
|
+
type: string;
|
|
19
|
+
coordinates: unknown;
|
|
20
|
+
} | null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A set of shapes whose shared edges are the borders: a GeoJSON `FeatureCollection` in longitude and latitude, such as chizu's `world-geo` (the countries) or a country's regions.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import type { BorderShapes } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
28
|
+
*
|
|
29
|
+
* const none: BorderShapes = { features: [] };
|
|
30
|
+
* console.log(none.features.length);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export interface BorderShapes {
|
|
34
|
+
features: readonly BorderFeature[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Which border sets an element draws, from its `borders` attribute.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import type { BorderSets } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
42
|
+
*
|
|
43
|
+
* const both: BorderSets = { countries: true, regions: true };
|
|
44
|
+
* console.log(both);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export interface BorderSets {
|
|
48
|
+
countries: boolean;
|
|
49
|
+
regions: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The Earth's radius on the screen, in CSS pixels, from which the regions (provinces, states, prefectures) are drawn: about 7 km to a pixel, where a region of a few hundred kilometres is tens of pixels across.
|
|
53
|
+
* The countries are drawn at any size.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { BORDER_REGIONS_RADIUS } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
58
|
+
*
|
|
59
|
+
* console.log(BORDER_REGIONS_RADIUS);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare const BORDER_REGIONS_RADIUS = 900;
|
|
63
|
+
/**
|
|
64
|
+
* The attributes the borders read: `borders`.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { BORDER_ATTRIBUTES } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
69
|
+
*
|
|
70
|
+
* console.log(BORDER_ATTRIBUTES.join(" "));
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare const BORDER_ATTRIBUTES: readonly ["borders"];
|
|
74
|
+
/**
|
|
75
|
+
* A `borders` attribute: absent draws none; a bare attribute draws both sets; otherwise the words in it, `countries` and `regions`, each switch one set on.
|
|
76
|
+
*
|
|
77
|
+
* @param value - The attribute's text, or `null` when it is not there.
|
|
78
|
+
* @returns Which sets are drawn.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* import { readBorders } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
83
|
+
*
|
|
84
|
+
* console.log(readBorders(null), readBorders(""), readBorders("countries"));
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare function readBorders(value: string | null): BorderSets;
|
|
88
|
+
/**
|
|
89
|
+
* The borders of a set of shapes as line segments on the unit sphere: each edge that two different shapes share, drawn once; an edge only one shape has (a coast) is left out.
|
|
90
|
+
* An edge longer than `maxStep` degrees is cut into pieces along the great circle, so the line keeps to the ground.
|
|
91
|
+
*
|
|
92
|
+
* @param shapes - The shapes, in longitude and latitude.
|
|
93
|
+
* @param maxStep - The longest piece in degrees (1 when left out).
|
|
94
|
+
* @returns The segments' ends, x, y, z for each, two points to a segment: ready for a `LineSegments` geometry.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { sharedEdges } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
99
|
+
*
|
|
100
|
+
* const west = { geometry: { type: "Polygon", coordinates: [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]] } };
|
|
101
|
+
* const east = { geometry: { type: "Polygon", coordinates: [[[1, 0], [2, 0], [2, 1], [1, 1], [1, 0]]] } };
|
|
102
|
+
* console.log(sharedEdges({ features: [west, east] }).length / 6);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function sharedEdges(shapes: BorderShapes, maxStep?: number): Float32Array;
|
|
106
|
+
/**
|
|
107
|
+
* Each coded shape's box in longitude and latitude: `[west, south, east, north]`, with `west` greater than `east` for a shape across the 180th meridian (the shorter way round).
|
|
108
|
+
*
|
|
109
|
+
* @param shapes - The shapes; one with no code is left out.
|
|
110
|
+
* @returns The box of each code.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* import { shapeBoxes } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
115
|
+
*
|
|
116
|
+
* const fiji = { properties: { code: "FJ" }, geometry: { type: "Polygon", coordinates: [[[177, -18], [-179, -18], [-179, -16], [177, -16], [177, -18]]] } };
|
|
117
|
+
* console.log(shapeBoxes({ features: [fiji] }).get("FJ"));
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare function shapeBoxes(shapes: BorderShapes): Map<string, [number, number, number, number]>;
|
|
121
|
+
/**
|
|
122
|
+
* The codes whose boxes come within `angle` degrees of a place: the countries whose regions a view may show.
|
|
123
|
+
*
|
|
124
|
+
* @param boxes - The boxes from `shapeBoxes`.
|
|
125
|
+
* @param lon - The place's longitude, degrees.
|
|
126
|
+
* @param lat - The place's latitude, degrees.
|
|
127
|
+
* @param angle - How far round the sphere the view reaches from the place, degrees (90 for the whole near side).
|
|
128
|
+
* @returns The codes, in the boxes' order.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* import { codesNear } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
133
|
+
*
|
|
134
|
+
* const boxes = new Map<string, [number, number, number, number]>([["JP", [122, 24, 154, 46]], ["BR", [-74, -34, -34, 5]]]);
|
|
135
|
+
* console.log(codesNear(boxes, 139.7, 35.7, 10));
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export declare function codesNear(boxes: ReadonlyMap<string, readonly [number, number, number, number]>, lon: number, lat: number, angle: number): string[];
|