@johnmorrisdotca/chikyu-earth 0.33.2 → 0.34.1
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 +14 -0
- package/README.md +23 -5
- package/dist/cities/geometry.d.ts +233 -0
- package/dist/cities/geometry.js +174 -0
- package/dist/cities/host.d.ts +73 -0
- package/dist/cities/host.js +240 -0
- package/dist/element.d.ts +1 -1
- package/dist/element.js +3 -14
- package/dist/markers/index.d.ts +1 -0
- package/dist/markers/index.js +1 -0
- package/dist/markers/labels.d.ts +7 -1
- package/dist/markers/labels.js +12 -1
- package/dist/markers/place-layer.d.ts +43 -0
- package/dist/markers/place-layer.js +238 -0
- package/dist/markers/places.d.ts +279 -0
- package/dist/markers/places.js +213 -0
- package/dist/passes/element.js +2 -5
- package/dist/realistic/body-label.js +19 -11
- package/dist/realistic/earth.js +1 -1
- package/dist/realistic/element.d.ts +35 -0
- package/dist/realistic/element.js +94 -11
- package/dist/realistic/index.d.ts +2 -0
- package/dist/realistic/index.js +2 -0
- package/dist/satellites/index.d.ts +1 -0
- package/dist/satellites/index.js +1 -0
- package/dist/satellites/names.d.ts +14 -0
- package/dist/satellites/names.js +16 -0
- package/dist/sky/cover.d.ts +48 -0
- package/dist/sky/cover.js +100 -0
- package/dist/sky/host.js +48 -18
- package/dist/space/element.d.ts +103 -1
- package/dist/space/element.js +219 -3
- package/dist/space/index.d.ts +3 -1
- package/dist/space/index.js +1 -0
- package/dist/space/satellite-layer.d.ts +26 -0
- package/dist/space/satellite-layer.js +37 -1
- package/dist/space/satellite-model.d.ts +72 -0
- package/dist/space/satellite-model.js +82 -0
- package/dist/space/scene.d.ts +44 -1
- package/dist/space/scene.js +154 -2
- package/package.json +7 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.34.1 - 2026-11-11
|
|
6
|
+
|
|
7
|
+
- **The sky is behind the Earth: constellation lines no longer cross it** (MODULES-1103). The lines were drawn over the Earth's disc (in a ride, across the whole globe). Each line is now cut exactly at the Earth's edge, the air's rim included, in the picture's own camera, in the space view and in a ride at any height, on the day side and the night side. A star whose point, ring or name box touches the Earth, the Moon or the Sun has its name and ring left out (a name only partly on the Earth was shown before), and the figure under the pointer is not lit over the Earth.
|
|
8
|
+
- **The element is its own stacking context** (MODULES-1104). `<chikyu-earth>`, `<chikyu-earth-realistic>` and `<chikyu-space>` are each their own stacking context (`isolation: isolate`), so nothing inside the element (the sky's labels, its lines, its markers) takes part in the page's own stacking: it paints as one piece, where the element sits in the page.
|
|
9
|
+
|
|
10
|
+
## 0.34.0 - 2026-11-11
|
|
11
|
+
|
|
12
|
+
- **You are here, and places on the Earth** (MODULES-927). `<chikyu-space>` and `<chikyu-earth-realistic>` take `places`, a list of `{ id, lon, lat, label, kind }` (attribute as JSON, or property), and draw each as a marker standing out of the ground: it turns with the Earth, is hidden on the far side, fades at the edge and keeps its size in pixels at any zoom. `kind: "here"` is the reader's place (taller, brighter, a quiet pulse at its foot); a `favourite` is quieter. `places-look` is `beam` (the default), `pin` or `ring`; colours come from `--chikyu-place-here` and `--chikyu-place-favourite`. Names sit at the top of the markers, `here` first, measured in the page's font and never over one another or the bodies' names. Nothing is drawn again at rest: the places are laid out with the picture, and the pulse is a CSS animation, stopped out of sight and for a reader who asked for less motion. `stats.places` says how many are drawn and named. The package never asks for the reader's place and stores or sends nothing; `nearby` (in `/markers`, with `readPlaces`, `cleanPlaces`, `orthoView` and `layoutPlaces`) rounds a place to about 10 km before a page draws or keeps it. `placeLabels` takes boxes already used by another layer. The demo has "Show where I am" (asked only on the press, rounded, never put in the address) and the three looks. New guide: "You are here, and places on the Earth".
|
|
13
|
+
- **Favourite places** (MODULES-942, as John decided on 2026-11-11: the package renders the list it is handed; the page owns the picker and keeps the list). Any place without `kind: "here"` is a favourite, drawn quieter than the reader's own place. The demo offers six example cities as favourites and keeps the ones chosen in its address (`fav=Tokyo,Cairo`); the reader's own place is never put there. The places guide says how a page builds and keeps the list.
|
|
14
|
+
- **No location is asked for on load** (MODULES-1071). `<chikyu-earth>` and `<chikyu-earth-realistic>` asked the browser for the reader's location when they opened with no `center`, before the reader had done anything. They no longer ask at all: without `center` they open on 0,0. A page that wants to centre on the reader asks on a press of its own (the demo's "Centre on me") and sets `center`. See the upgrade guide. The embed page's `center=me`, which the embedding page chooses, now asks from the page itself, once, and gives the answer to the look that is shown (on the realistic and space looks it used to apply the answer to the hidden line globe only).
|
|
15
|
+
- **City names on the Earth** (MODULES-937). `<chikyu-earth-realistic>` and `<chikyu-space>` take `city-names` (bare is 24 names at once, a number is that many, 1 to 80; absent, none) and name cities from kuni's `cities` (an optional peer, `>=1.6.1`, loaded only when it is set, one tier at a time): the capitals from an Earth 60 pixels in radius, the other cities of a million from 170, those of 100,000 from 420, the most populous first with a bonus for capitals. A name goes right of its dot, then left, above, below, never over another and never off the picture; a city that is not facing the viewer, or is within about 7 degrees of the limb, is left out. The names are English, or Japanese on a Japanese page where kuni has the name (`name.jaShort` first when kuni gives it, so Tokyo is written as the city and not as the prefecture). The property `cityNamesStyle` has the font, size, weight, colour, outline and the dot's colour and size. Only the layer is drawn again, and nothing at rest; `chikyu-city-names-unavailable` is sent when kuni is not there and `stats.cityNames` has the counts. The pure parts (`layoutCities`, `cityTiersFor`, `cityRank`, `cityNameText`, `nameWidth`, `readCityNames`) are in `@johnmorrisdotca/chikyu-earth/realistic`. The demo has a City names button (`city-names` in the address). New guide: City names on the Earth (English and Japanese).
|
|
16
|
+
- **Ring and name the satellites of a group.** `labelSatellites(group)` rings every member of a small group (the stations) and writes its name beside it in the page's language (`SHORT_NAMES` in `/satellites`: the ISS, Tiangong and Hubble; `satelliteNames` for a page's own), at most 80. The names are laid out after the places' names and never over them, a body's name or one another. `placeSatellite(ref)` says where a satellite is on the screen and whether it can be seen, and `chikyu-satellite-visibility` is sent when a ringed one comes into view or goes out. Nothing is drawn at rest.
|
|
17
|
+
- **Follow a large satellite as a 3D model** (MODULES-861). `setSatellitePainter({ has, make })` hands `<chikyu-space>` the page's own models (the package ships none): a satellite followed with `ride(ref, { view: "follow" })` that the painter has a model for is drawn as that model, held in the middle of the picture at a size that reads (`MODEL_RADIUS_SHARE` of the view's height), pointed the way it flies (`satelliteAxes`, `modelMatrix`) and lit by the Sun, with the Earth turning and sliding beneath; one with no model stays a dot. `largeSatellites()` lists the satellites of the groups set that have a model, and `followNext(step)` hops between them. `stats.followModel` says where the model's middle is drawn. The demo follows the ISS, Tiangong and Hubble as made-up models of boxes and cylinders (`demo/station-models.ts`), not pictures of the real ones.
|
|
18
|
+
|
|
5
19
|
## 0.33.2 - 2026-11-11
|
|
6
20
|
|
|
7
21
|
- **kazoku-ui 0.38.1** (KAZOKU-UI-133). The view controls keep a pace of 1 in the address when the page starts at another, so the line globe's 1× (the Earth's real rate) survives a reload; the test of it is switched on (it was `fixme`).
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
<h1 align="center">Chikyu Earth <sub>地球</sub></h1>
|
|
4
4
|
|
|
5
|
-
<p align="center"><strong>A line-drawn globe that turns at the Earth's own rate,
|
|
5
|
+
<p align="center"><strong>A line-drawn globe that turns at the Earth's own rate, centred on the place you give it.</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
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>
|
|
@@ -41,7 +41,7 @@ Chikyu Earth works on a phone or a tablet as well as on a computer, in the brows
|
|
|
41
41
|
## Features
|
|
42
42
|
|
|
43
43
|
- A line-drawn globe as one SVG: country outlines on an orthographic disc, in two looks (`line`, `thick`), with an optional graticule.
|
|
44
|
-
- It opens centred
|
|
44
|
+
- It opens centred where you say, or on 0,0 when you say nothing; it never asks the browser where the reader is. Auto-turn runs at the Earth's own rate: one sidereal day a turn, and the family's speed buttons (0.5×, 1×, 2×) are multiples of it.
|
|
45
45
|
- The Earth from space (`/realistic`): day and night by the real Sun, city lights, sun glint, clouds and the atmosphere, drawn with three.js through one shared WebGL context.
|
|
46
46
|
- 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.
|
|
47
47
|
- When you can see the ISS (`/passes`): the next passes of the ISS, Tiangong and Hubble over any place, with direction, height, brightness and whether the satellite is lit while the sky is dark, a sky dome that draws each, and `<chikyu-passes>`.
|
|
@@ -77,7 +77,7 @@ One script tag from [jsDelivr](https://www.jsdelivr.com/package/npm/@johnmorrisd
|
|
|
77
77
|
</html>
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
The globe appears centred where you say; with no `center` it
|
|
80
|
+
The globe appears centred where you say; with no `center` it opens on 0,0, the Greenwich meridian on the equator. The globe never asks the browser where the reader is: a page that wants the reader's place asks for it itself, on a press, and sets `center`. `look` is `line` or `thick`. It also zooms and turns: drag, pinch, Ctrl and the wheel, the arrow keys (`controls="none"` takes that off).
|
|
81
81
|
|
|
82
82
|
### With the shared controls
|
|
83
83
|
|
|
@@ -224,6 +224,22 @@ console.log(bodyLabelText("en"), bodyLabelText("ja"), BODY_LABEL_ATTRIBUTES.leng
|
|
|
224
224
|
<chikyu-space star-names="12" constellation-lines="0.16"></chikyu-space>
|
|
225
225
|
```
|
|
226
226
|
|
|
227
|
+
## City names
|
|
228
|
+
|
|
229
|
+
`city-names` on `<chikyu-earth-realistic>` and `<chikyu-space>` names cities on the Earth from kuni's list: the capitals first, then the cities of a million and the large ones as the Earth grows on the screen, the most populous first, in the page's language (Japanese where kuni has the name), never overlapping and none on the far side. kuni is an optional peer loaded only when it is set, a tier at a time; the look is the property `cityNamesStyle`; nothing is drawn at rest: [guide](docs/guides/city-names.md).
|
|
230
|
+
|
|
231
|
+
```html
|
|
232
|
+
<chikyu-earth-realistic city-names="24"></chikyu-earth-realistic>
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## You are here, and places on the Earth
|
|
236
|
+
|
|
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 and hidden on its far side: `kind: "here"` for the reader's own place (brighter, with a quiet pulse) and favourites, quieter. 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
|
+
|
|
239
|
+
```html
|
|
240
|
+
<chikyu-space places='[{"id":"me","lon":-79.4,"lat":43.7,"label":"You are here","kind":"here"}]'></chikyu-space>
|
|
241
|
+
```
|
|
242
|
+
|
|
227
243
|
## Outside data: the data door
|
|
228
244
|
|
|
229
245
|
The package draws; you bring the data. `@johnmorrisdotca/chikyu-earth/door` takes a finer map of the Earth, or a list of satellites' orbit data, as a **source**: a small object that carries its own licence and credit, so the screen can always say whose data it shows. With no source nothing changes: the Earth is drawn from the package's own pictures and tiles (`OWN_SOURCES`, written from `NOTICE.md`, never non-commercial or share-alike). A source of yours may be either, and the credit line prints that beside the licence.
|
|
@@ -411,7 +427,7 @@ The rotation is the pair d3-geo's `rotate` takes: `[-longitude, -latitude]` cent
|
|
|
411
427
|
| Attribute | What it does | Default |
|
|
412
428
|
| --- | --- | --- |
|
|
413
429
|
| `size` | Width and height of the square SVG, in pixels. | `320` |
|
|
414
|
-
| `center` | `"longitude,latitude"` to centre on.
|
|
430
|
+
| `center` | `"longitude,latitude"` to centre on. The element never asks the browser where the reader is: a page that wants that asks on a press and sets `center`. | `0,0` |
|
|
415
431
|
| `look` | `line` or `thick`. (`style` is the older name for it: a framework reads `style` as CSS, so use `look` there.) | `line` |
|
|
416
432
|
| `graticule` | Draw a light graticule under the countries. | off |
|
|
417
433
|
| `controls` | `none` takes off the drag, pinch, wheel and keys the element carries. | on |
|
|
@@ -540,7 +556,9 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
|
|
|
540
556
|
| [Ride along](docs/guides/ride-along.md) | A camera on a moving body |
|
|
541
557
|
| [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 |
|
|
542
558
|
| [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
|
+
| [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 |
|
|
543
560
|
| [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
|
+
| [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 |
|
|
544
562
|
| [Meteors seen from space](docs/guides/meteors.md) | Streaks over the night side, the shower table, what is real and what is illustration |
|
|
545
563
|
| [Outside data, the data door](docs/guides/data-door.md) | Hand the package your own maps of the Earth or orbit data with their licence and credit, switch them off, and show whose data is on the screen |
|
|
546
564
|
| [Zoom, pan and turn](docs/guides/zoom-and-pan.md) | The hands every view carries, each zoom range and why |
|
|
@@ -572,7 +590,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
|
|
|
572
590
|
|
|
573
591
|
## How to cite
|
|
574
592
|
|
|
575
|
-
> Morris, J. (2026). *Chikyu Earth* (version 0.
|
|
593
|
+
> Morris, J. (2026). *Chikyu Earth* (version 0.34.1) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
|
|
576
594
|
|
|
577
595
|
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.
|
|
578
596
|
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The kuni tiers a view needs, in the order they are loaded: the capitals, the other cities of a million, and the others of 100,000.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import type { CityNameTier } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
7
|
+
*
|
|
8
|
+
* const tier: CityNameTier = "1m";
|
|
9
|
+
* console.log(tier);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export type CityNameTier = "capitals" | "1m" | "100k";
|
|
13
|
+
/**
|
|
14
|
+
* What the layer needs of a city: kuni's own record has more, and any list with these fields will do.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import type { NamedCity } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
19
|
+
*
|
|
20
|
+
* const osaka: NamedCity = { id: "Q35765", name: { en: "Osaka", ja: "大阪市" }, lat: 34.69, lon: 135.5, population: 2_700_000, capital: null };
|
|
21
|
+
* console.log(osaka.name.en);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export interface NamedCity {
|
|
25
|
+
id: string;
|
|
26
|
+
name: {
|
|
27
|
+
en: string;
|
|
28
|
+
ja?: string;
|
|
29
|
+
jaShort?: string;
|
|
30
|
+
};
|
|
31
|
+
lat: number;
|
|
32
|
+
lon: number;
|
|
33
|
+
population: number | null;
|
|
34
|
+
capital: "national" | "alternate" | "subdivision" | null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Where the Earth is on the screen at one draw: the box, the Earth's radius in pixels, and a way to find a place on it.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import type { CityFrame } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
42
|
+
*
|
|
43
|
+
* const frame: CityFrame = { width: 400, height: 400, radius: 150, project: (lon, lat, out) => { out.x = 200 + lon; out.y = 200 - lat; return 1; } };
|
|
44
|
+
* console.log(frame.radius);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export interface CityFrame {
|
|
48
|
+
width: number;
|
|
49
|
+
height: number;
|
|
50
|
+
/** The Earth's radius on the screen, in CSS pixels. */
|
|
51
|
+
radius: number;
|
|
52
|
+
/** Writes where a place falls in the box and answers how squarely it faces the viewer: the cosine of the angle between the ground's upward and the line to the viewer, above 0 in sight, 1 at the middle of the disc. */
|
|
53
|
+
project(lon: number, lat: number, out: {
|
|
54
|
+
x: number;
|
|
55
|
+
y: number;
|
|
56
|
+
}): number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* What the names are laid out with: the most names, the text size in pixels and the dot's radius, and how squarely a city must face the viewer (0.12 by default).
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import type { CityLayoutOptions } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
64
|
+
*
|
|
65
|
+
* const options: CityLayoutOptions = { max: 24, size: 12, dot: 3 };
|
|
66
|
+
* console.log(options.max);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export interface CityLayoutOptions {
|
|
70
|
+
max: number;
|
|
71
|
+
size: number;
|
|
72
|
+
dot: number;
|
|
73
|
+
/** Cities that face the viewer less squarely than this are left out, so none crowds the limb (0.12). */
|
|
74
|
+
facing?: number;
|
|
75
|
+
/**
|
|
76
|
+
* The width of a name as the browser draws it, in the font the name is drawn in (a canvas's `measureText`): the estimate from the length is a floor, and the larger of the two is used. A machine whose font has wider letters than the estimate takes
|
|
77
|
+
* (a fallback font for Japanese, say) would otherwise lay names over one another. Left out, the estimate alone is used, as in Node.
|
|
78
|
+
*/
|
|
79
|
+
measure?: (text: string) => number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A city to name: where its dot is, the text to write and where the text's box goes (its top left corner and size).
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* import type { CityName } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
87
|
+
*
|
|
88
|
+
* const place = (one: CityName): string => `${one.text} at ${one.left}, ${one.top}`;
|
|
89
|
+
* console.log(typeof place);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export interface CityName {
|
|
93
|
+
city: NamedCity;
|
|
94
|
+
text: string;
|
|
95
|
+
x: number;
|
|
96
|
+
y: number;
|
|
97
|
+
left: number;
|
|
98
|
+
top: number;
|
|
99
|
+
width: number;
|
|
100
|
+
height: number;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The Earth's radius on the screen, in pixels, from which each tier is shown: the capitals 60, the cities of a million 170, those of 100,000 420.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { TIER_RADIUS } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
108
|
+
*
|
|
109
|
+
* console.log(TIER_RADIUS.capitals, TIER_RADIUS["1m"], TIER_RADIUS["100k"]);
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare const TIER_RADIUS: Readonly<Record<CityNameTier, number>>;
|
|
113
|
+
/**
|
|
114
|
+
* The tiers of cities a view of this size shows: none while the Earth is small, the capitals, then the cities of a million, then those of 100,000 as it grows.
|
|
115
|
+
*
|
|
116
|
+
* @param radius - The Earth's radius on the screen, in CSS pixels.
|
|
117
|
+
* @returns The tiers, smallest first.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { cityTiersFor } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
122
|
+
*
|
|
123
|
+
* console.log(cityTiersFor(30), cityTiersFor(200), cityTiersFor(900));
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function cityTiersFor(radius: number): CityNameTier[];
|
|
127
|
+
/**
|
|
128
|
+
* How much a city counts when names crowd: its people, and a bonus for the capital of a country (2 million), another seat of government (1 million) and the capital of a subdivision (100,000).
|
|
129
|
+
*
|
|
130
|
+
* @param city - The city.
|
|
131
|
+
* @returns The rank; higher is named first.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* import { cityRank } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
136
|
+
*
|
|
137
|
+
* console.log(cityRank({ population: 5_700, capital: "national" }), cityRank({ population: 5_700, capital: null }));
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare function cityRank(city: Pick<NamedCity, "population" | "capital">): number;
|
|
141
|
+
/**
|
|
142
|
+
* The name to write for a city: Japanese on a page in Japanese where kuni has it (the short form, 東京 for 東京都, when kuni gives one), else English.
|
|
143
|
+
*
|
|
144
|
+
* @param city - The city.
|
|
145
|
+
* @param lang - The page's language, `en` or `ja`.
|
|
146
|
+
* @returns The name.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* import { cityNameText } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
151
|
+
*
|
|
152
|
+
* const osaka = { name: { en: "Osaka", ja: "大阪市" } };
|
|
153
|
+
* console.log(cityNameText(osaka, "en"), cityNameText(osaka, "ja"), cityNameText({ name: { en: "Paris" } }, "ja"));
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export declare function cityNameText(city: {
|
|
157
|
+
name: {
|
|
158
|
+
en: string;
|
|
159
|
+
ja?: string;
|
|
160
|
+
jaShort?: string;
|
|
161
|
+
};
|
|
162
|
+
}, lang: "en" | "ja"): string;
|
|
163
|
+
/**
|
|
164
|
+
* About how wide a name is, in pixels, without reading any layout: a Japanese character is as wide as the text is tall, any other about 0.58 of it.
|
|
165
|
+
*
|
|
166
|
+
* @param text - The name.
|
|
167
|
+
* @param size - The text size in pixels.
|
|
168
|
+
* @returns The width, in pixels.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* import { nameWidth } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
173
|
+
*
|
|
174
|
+
* console.log(nameWidth("Tokyo", 12), nameWidth("東京", 12));
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
export declare function nameWidth(text: string, size: number): number;
|
|
178
|
+
/**
|
|
179
|
+
* Lays the names out for one draw: the cities in sight, the most important first, each named beside its dot (right, then left, above, below) where no earlier name is in the way; a city with no room is left out.
|
|
180
|
+
*
|
|
181
|
+
* @param cities - The cities of the tiers shown, the highest rank first (see {@link cityRank}).
|
|
182
|
+
* @param frame - Where the Earth is on the screen.
|
|
183
|
+
* @param lang - The page's language, `en` or `ja`.
|
|
184
|
+
* @param options - The most names, the text size and the dot's radius.
|
|
185
|
+
* @returns The names to show, the most important first.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* import { layoutCities } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
190
|
+
*
|
|
191
|
+
* const frame = { width: 300, height: 300, radius: 120, project: (lon: number, lat: number, out: { x: number; y: number }) => { out.x = 150 + (lon - 133) * 6; out.y = 150 - (lat - 36) * 6; return 1; } };
|
|
192
|
+
* const tokyo = { id: "Q1490", name: { en: "Tokyo", ja: "東京都" }, lat: 35.7, lon: 139.7, population: 37_000_000, capital: "national" as const };
|
|
193
|
+
* const seoul = { id: "Q8684", name: { en: "Seoul" }, lat: 37.6, lon: 127, population: 10_000_000, capital: "national" as const };
|
|
194
|
+
* console.log(layoutCities([tokyo, seoul], frame, "en", { max: 10, size: 12, dot: 3 }).map((one) => one.text));
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
export declare function layoutCities(cities: readonly NamedCity[], frame: CityFrame, lang: "en" | "ja", options: CityLayoutOptions): CityName[];
|
|
198
|
+
/**
|
|
199
|
+
* The most names `city-names` may ask for at once.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* import { CITY_NAMES_MAX } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
204
|
+
*
|
|
205
|
+
* console.log(CITY_NAMES_MAX);
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export declare const CITY_NAMES_MAX = 80;
|
|
209
|
+
/**
|
|
210
|
+
* How many names a bare `city-names` asks for.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```ts
|
|
214
|
+
* import { CITY_NAMES_DEFAULT } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
215
|
+
*
|
|
216
|
+
* console.log(CITY_NAMES_DEFAULT);
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
export declare const CITY_NAMES_DEFAULT = 24;
|
|
220
|
+
/**
|
|
221
|
+
* Reads the `city-names` attribute: absent is off, bare is 24 names, a number is that many names (1 to 80).
|
|
222
|
+
*
|
|
223
|
+
* @param value - The attribute's value, or `null` when it is absent.
|
|
224
|
+
* @returns How many names at most, or `null` for none.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* import { readCityNames } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
229
|
+
*
|
|
230
|
+
* console.log(readCityNames(null), readCityNames(""), readCityNames("12"), readCityNames("500"), readCityNames("many"));
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
export declare function readCityNames(value: string | null): number | null;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// Which cities are named on the Earth, and where: tiers by how large the Earth is on the screen, the most populous first, each name beside its dot where nothing is in the way. Pure.
|
|
2
|
+
import { placeLabels } from "../markers/labels.js";
|
|
3
|
+
/**
|
|
4
|
+
* The Earth's radius on the screen, in pixels, from which each tier is shown: the capitals 60, the cities of a million 170, those of 100,000 420.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { TIER_RADIUS } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
9
|
+
*
|
|
10
|
+
* console.log(TIER_RADIUS.capitals, TIER_RADIUS["1m"], TIER_RADIUS["100k"]);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export const TIER_RADIUS = { capitals: 60, "1m": 170, "100k": 420 };
|
|
14
|
+
/** The most cities looked at at one draw: the most populous in sight; the rest cannot have room for a name. */
|
|
15
|
+
const CANDIDATES = 400;
|
|
16
|
+
/**
|
|
17
|
+
* The tiers of cities a view of this size shows: none while the Earth is small, the capitals, then the cities of a million, then those of 100,000 as it grows.
|
|
18
|
+
*
|
|
19
|
+
* @param radius - The Earth's radius on the screen, in CSS pixels.
|
|
20
|
+
* @returns The tiers, smallest first.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { cityTiersFor } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
25
|
+
*
|
|
26
|
+
* console.log(cityTiersFor(30), cityTiersFor(200), cityTiersFor(900));
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function cityTiersFor(radius) {
|
|
30
|
+
const tiers = [];
|
|
31
|
+
for (const tier of ["capitals", "1m", "100k"])
|
|
32
|
+
if (radius >= TIER_RADIUS[tier])
|
|
33
|
+
tiers.push(tier);
|
|
34
|
+
return tiers;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* How much a city counts when names crowd: its people, and a bonus for the capital of a country (2 million), another seat of government (1 million) and the capital of a subdivision (100,000).
|
|
38
|
+
*
|
|
39
|
+
* @param city - The city.
|
|
40
|
+
* @returns The rank; higher is named first.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { cityRank } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
45
|
+
*
|
|
46
|
+
* console.log(cityRank({ population: 5_700, capital: "national" }), cityRank({ population: 5_700, capital: null }));
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function cityRank(city) {
|
|
50
|
+
const bonus = city.capital === "national" ? 2_000_000 : city.capital === "alternate" ? 1_000_000 : city.capital === "subdivision" ? 100_000 : 0;
|
|
51
|
+
return (city.population ?? 0) + bonus;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The name to write for a city: Japanese on a page in Japanese where kuni has it (the short form, 東京 for 東京都, when kuni gives one), else English.
|
|
55
|
+
*
|
|
56
|
+
* @param city - The city.
|
|
57
|
+
* @param lang - The page's language, `en` or `ja`.
|
|
58
|
+
* @returns The name.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { cityNameText } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
63
|
+
*
|
|
64
|
+
* const osaka = { name: { en: "Osaka", ja: "大阪市" } };
|
|
65
|
+
* console.log(cityNameText(osaka, "en"), cityNameText(osaka, "ja"), cityNameText({ name: { en: "Paris" } }, "ja"));
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function cityNameText(city, lang) {
|
|
69
|
+
return (lang === "ja" ? (city.name.jaShort ?? city.name.ja) : undefined) ?? city.name.en;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* About how wide a name is, in pixels, without reading any layout: a Japanese character is as wide as the text is tall, any other about 0.58 of it.
|
|
73
|
+
*
|
|
74
|
+
* @param text - The name.
|
|
75
|
+
* @param size - The text size in pixels.
|
|
76
|
+
* @returns The width, in pixels.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* import { nameWidth } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
81
|
+
*
|
|
82
|
+
* console.log(nameWidth("Tokyo", 12), nameWidth("東京", 12));
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export function nameWidth(text, size) {
|
|
86
|
+
let width = 0;
|
|
87
|
+
for (const char of text)
|
|
88
|
+
width += (char.codePointAt(0) ?? 0) >= 0x2e80 ? size : size * 0.58;
|
|
89
|
+
return Math.ceil(width) + 4;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Lays the names out for one draw: the cities in sight, the most important first, each named beside its dot (right, then left, above, below) where no earlier name is in the way; a city with no room is left out.
|
|
93
|
+
*
|
|
94
|
+
* @param cities - The cities of the tiers shown, the highest rank first (see {@link cityRank}).
|
|
95
|
+
* @param frame - Where the Earth is on the screen.
|
|
96
|
+
* @param lang - The page's language, `en` or `ja`.
|
|
97
|
+
* @param options - The most names, the text size and the dot's radius.
|
|
98
|
+
* @returns The names to show, the most important first.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* import { layoutCities } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
103
|
+
*
|
|
104
|
+
* const frame = { width: 300, height: 300, radius: 120, project: (lon: number, lat: number, out: { x: number; y: number }) => { out.x = 150 + (lon - 133) * 6; out.y = 150 - (lat - 36) * 6; return 1; } };
|
|
105
|
+
* const tokyo = { id: "Q1490", name: { en: "Tokyo", ja: "東京都" }, lat: 35.7, lon: 139.7, population: 37_000_000, capital: "national" as const };
|
|
106
|
+
* const seoul = { id: "Q8684", name: { en: "Seoul" }, lat: 37.6, lon: 127, population: 10_000_000, capital: "national" as const };
|
|
107
|
+
* console.log(layoutCities([tokyo, seoul], frame, "en", { max: 10, size: 12, dot: 3 }).map((one) => one.text));
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export function layoutCities(cities, frame, lang, options) {
|
|
111
|
+
const facing = options.facing ?? 0.12;
|
|
112
|
+
const out = { x: 0, y: 0 };
|
|
113
|
+
const margin = options.dot + 2;
|
|
114
|
+
const seen = [];
|
|
115
|
+
for (const city of cities) {
|
|
116
|
+
if (seen.length >= CANDIDATES)
|
|
117
|
+
break;
|
|
118
|
+
if (frame.project(city.lon, city.lat, out) < facing)
|
|
119
|
+
continue;
|
|
120
|
+
if (out.x < margin || out.y < margin || out.x > frame.width - margin || out.y > frame.height - margin)
|
|
121
|
+
continue;
|
|
122
|
+
seen.push({ city, x: out.x, y: out.y });
|
|
123
|
+
}
|
|
124
|
+
const height = Math.ceil(options.size * 1.35);
|
|
125
|
+
const texts = seen.map((one) => cityNameText(one.city, lang));
|
|
126
|
+
const items = seen.map((one, index) => ({ x: one.x, y: one.y, r: options.dot, w: Math.max(nameWidth(texts[index], options.size), options.measure ? Math.ceil(options.measure(texts[index])) + 4 : 0), h: height, priority: seen.length - index }));
|
|
127
|
+
return placeLabels(items, frame.width, frame.height, options.max).map((place) => {
|
|
128
|
+
const one = seen[place.item];
|
|
129
|
+
return { city: one.city, text: texts[place.item], x: one.x, y: one.y, left: place.left, top: place.top, width: items[place.item].w, height };
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The most names `city-names` may ask for at once.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* import { CITY_NAMES_MAX } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
138
|
+
*
|
|
139
|
+
* console.log(CITY_NAMES_MAX);
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export const CITY_NAMES_MAX = 80;
|
|
143
|
+
/**
|
|
144
|
+
* How many names a bare `city-names` asks for.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* import { CITY_NAMES_DEFAULT } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
149
|
+
*
|
|
150
|
+
* console.log(CITY_NAMES_DEFAULT);
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export const CITY_NAMES_DEFAULT = 24;
|
|
154
|
+
/**
|
|
155
|
+
* Reads the `city-names` attribute: absent is off, bare is 24 names, a number is that many names (1 to 80).
|
|
156
|
+
*
|
|
157
|
+
* @param value - The attribute's value, or `null` when it is absent.
|
|
158
|
+
* @returns How many names at most, or `null` for none.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* import { readCityNames } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
163
|
+
*
|
|
164
|
+
* console.log(readCityNames(null), readCityNames(""), readCityNames("12"), readCityNames("500"), readCityNames("many"));
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export function readCityNames(value) {
|
|
168
|
+
if (value === null)
|
|
169
|
+
return null;
|
|
170
|
+
const count = Number(value.trim());
|
|
171
|
+
if (value.trim() === "" || !Number.isFinite(count))
|
|
172
|
+
return CITY_NAMES_DEFAULT;
|
|
173
|
+
return Math.min(CITY_NAMES_MAX, Math.max(1, Math.round(count)));
|
|
174
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type CityFrame, type CityNameTier, type NamedCity } from "./geometry.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The look of the city names, all optional: the text's font, size (pixels), weight and colour, the outline round it, and the dot's colour and radius (pixels).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import type { CityNamesStyle } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
8
|
+
*
|
|
9
|
+
* const look: CityNamesStyle = { font: "Georgia, serif", size: 13, colour: "#ffe9b0", halo: "#201400", dot: "#ffd166", dotSize: 3 };
|
|
10
|
+
* console.log(Object.keys(look).join(" "));
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export interface CityNamesStyle {
|
|
14
|
+
font?: string;
|
|
15
|
+
size?: number;
|
|
16
|
+
weight?: number | string;
|
|
17
|
+
colour?: string;
|
|
18
|
+
halo?: string;
|
|
19
|
+
haloWidth?: number;
|
|
20
|
+
dot?: string;
|
|
21
|
+
dotSize?: number;
|
|
22
|
+
}
|
|
23
|
+
/** The styles of the layer, for an element to add to its own (`#cn-canvas`, `#cn-names` and the names in its shadow root). */
|
|
24
|
+
export declare const CITY_NAMES_STYLE: string;
|
|
25
|
+
/** What an element tells the layer about the page. */
|
|
26
|
+
export interface CityHostOptions {
|
|
27
|
+
/** Reads one of the element's attributes. */
|
|
28
|
+
attribute(name: string): string | null;
|
|
29
|
+
/** The page's language, `en` or `ja`. */
|
|
30
|
+
language(): "en" | "ja";
|
|
31
|
+
/** The shadow root the layer is made in. */
|
|
32
|
+
root: ShadowRoot;
|
|
33
|
+
/** Told when a tier of cities could not be loaded (kuni is not installed, or the file did not arrive). */
|
|
34
|
+
onError(error: unknown): void;
|
|
35
|
+
/** Loads kuni's cities; the page's own copy when it has one (the property is for tests and for pages that bundle their own). */
|
|
36
|
+
load?(tier: CityNameTier): Promise<readonly NamedCity[]>;
|
|
37
|
+
}
|
|
38
|
+
export interface CityHost {
|
|
39
|
+
/** Tells where the Earth is in the picture just drawn, or `null` when there is no Earth to name. */
|
|
40
|
+
frame(frame: CityFrame | null): void;
|
|
41
|
+
/** Reads the attribute and the language again after either changed. */
|
|
42
|
+
refresh(): void;
|
|
43
|
+
/** The look of the names (the property `cityNamesStyle`). */
|
|
44
|
+
setStyle(style: CityNamesStyle): void;
|
|
45
|
+
readonly stats: {
|
|
46
|
+
on: boolean;
|
|
47
|
+
max: number;
|
|
48
|
+
radius: number;
|
|
49
|
+
tiers: CityNameTier[];
|
|
50
|
+
cities: number;
|
|
51
|
+
names: number;
|
|
52
|
+
renders: number;
|
|
53
|
+
};
|
|
54
|
+
dispose(): void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The attributes the city names read: `city-names`.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { CITY_NAMES_ATTRIBUTES } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
62
|
+
*
|
|
63
|
+
* console.log(CITY_NAMES_ATTRIBUTES.join(" "));
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare const CITY_NAMES_ATTRIBUTES: readonly ["city-names"];
|
|
67
|
+
/**
|
|
68
|
+
* Makes the layer of one element, inside its shadow root. Nothing of kuni is loaded, and nothing is added to the root, until `city-names` is there and the Earth is big enough for a name.
|
|
69
|
+
*
|
|
70
|
+
* @param options - The attribute reader, the language and the shadow root.
|
|
71
|
+
* @returns The host.
|
|
72
|
+
*/
|
|
73
|
+
export declare function createCityHost(options: CityHostOptions): CityHost;
|