@johnmorrisdotca/chikyu-earth 0.46.6 → 0.47.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
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.47.0 - 2026-11-13
4
+
5
+ - **The demo's Find box keeps a Japanese query.** A name in kana or kanji used to be dropped before the catalogue was asked, so `ハッブル` found nothing. It now asks the catalogue, and a satellite the package knows by a short name is listed by that name (Hubble, not only HST).
6
+ - **A satellite hidden by the Earth** (MODULES-1243). `placeSatellite` adds `occluded`: true when the line from the camera meets the Earth before the satellite, false in front, false at the limb, and false when the satellite is only behind the camera (`behind` is unchanged). The package's own satellite names, stations included, are drawn at 45 percent opacity with no ring while occluded, and restored as the satellite comes out. `dim-occluded="off"` (the property `dimOccluded`, on by default) leaves those names out. `earthHides` is the same test, for a page that places its own names.
7
+ - **A share of the Earth's turn on the space view** (MODULES-1223). `follow` on `<chikyu-space>` is a number from 0 to 1. 0, the default, holds the stars, which is what `camera="space"` already does, so a page that sets nothing changes nothing. 1 turns with the Earth. A number between takes that share. Changing it keeps the longitude under the middle of the view. `follow-ease` is how many seconds the change takes (0.4 when left out, 0 for none, and at once when the reader asks for reduced motion). It follows a fast, reversed or paused clock, and nothing is drawn while the clock is stopped and `follow` is not changing. A step of the clock longer than half a turn now keeps the Earth's real turn (a day is a full turn), so a fast clock moves the ground at the Earth's own rate. `centreLongitude` reads the longitude under the middle, and `shownTime` is the moment of the draw it belongs to.
8
+ - **The place under a point** (MODULES-1265). `placeOf(lon, lat)` in `@johnmorrisdotca/chikyu-earth/place` returns the country, a country the point is only near, the sea or ocean, the continent and the nearest city. The countries are the line globe's outlines, Natural Earth at 1:110m, indexed on a 15° grid. A point inside an outline is `country`. A point outside every outline and within 50 km (`PLACE_COAST_KM`) is `near`, because that coarse coast is the wrong place to claim a country. The sea is the nearest named sea, gulf, bay or ocean within its reach (`SEA_REACH_KM`); nothing is named when none reaches. The continent follows the country's group, named as on the sea-names list. Australia the country is that continent. A point at least 2,500 km closer to another continent's point (eastern Russia, French Guiana) uses the nearer one. Pacific island countries the outlines group as Oceania are `oceania`, which is not one of those seven. The nearest city is the caller's lists, the same three tiers as `here-city`, and towns under 100,000 only when `towns` is passed. `alongTrack` reports each change of country, nearby country or sea along a ground track, at the sample that entered it. A call is about 0.14 ms once the grid is built.
9
+ - **A faint orbit while the pointer rests on a satellite** (MODULES-1234). On `<chikyu-space>` and `<chikyu-earth-realistic>`, resting on a satellite shows its name and draws its orbit at about a third of the brightness of a chosen satellite's orbit (`hover-path`, on when `names-on-hover` is on; `hover-path="off"` turns the orbit off, `names-on-hover="off"` turns the name off). The colour and the opacity are `--chikyu-hover-path` and `--chikyu-hover-path-opacity`. The path is worked out once from the elements already loaded. It fades out when the pointer leaves (at once when the reader asks for reduced motion). A chosen orbit is unchanged. A touch does not rest, so nothing new is drawn, and nothing is drawn while the pointer is still and no satellite is under it.
10
+ - **Frame the ridden satellite, zoom inside a ride, and a viewpoint switch that fades** (MODULES-1316). `ride-model-share` (property `rideModelShare`, option `modelShare`, 0.02 to 1.2: the model's radius as a share of the picture's height; 0.22 along the way it goes, up from 0.17, 0.17 above, 0.10 looking down) and `ride-model-seat` (`rideModelSeat`, `modelSeat`, 0.5 to 1.4: where its middle sits from the top; 0.86 along the way it goes, down from 0.90) frame the model, so with the defaults the body and a good part of a wing are in view in Ride along, and a page can go to a close framing (1 and 1). `ride-zoom` (`rideZoom`, 0.5 to 40; the field of view is 60 degrees over it, the least `rideFov` now allows is 1.5) zooms in a ride, and `stats.ride.groundKm` (`{ across, tall }`, kilometres of ground below the satellite) says how much ground the picture spans. All are settable while riding, glide in 0.4 s (a jump under reduced motion), cost one draw for the change and nothing at rest. Switching `ride-viewpoint` between `outside` and `inside` now fades the model over 0.4 s as the camera closes on it (and back), and `stats.followModel` reports `share`, `seat` and `weight`.
11
+
3
12
  ## 0.46.6 - 2026-11-13
4
13
 
5
14
  - **A beam from the chosen satellite to the ground below it** (MODULES-1309). `beam` on `<chikyu-space>` (off unless set; the property `beam`) draws a soft, additive cone of light from the satellite marked with `selectSatellite`, or the one ridden, down to its footprint on the ground: a lit ring and a faint fill, the circle from which the satellite is above `beam-elevation` degrees (25), worked from its height (`footprintAngle`, `footprintKm`), cut off by the limb, in Ride along and Ride above as well. `beam-cells` (up to 91) adds spot cells in a hexagonal pack, each with a thin shaft of light (an illustration, not any operator's plan), `beam-cell-size`, `beam-color` and `beam-strength` set the look; `stats.beam` says the footprint's radius in kilometres. It is part of the draw that moves the satellite: nothing at rest, nothing rebuilt on a clock step, no shimmer. Guide: `docs/guides/beam.md` (and its Japanese twin), and a "Satellite beam" button in the demo.
package/README.md CHANGED
@@ -359,7 +359,7 @@ Passes are only as good as the orbit data are new: each pass says how old its el
359
359
  <p align="center"><img alt="Riding along with the ISS, tipped towards the horizon: the Earth's curve and atmosphere, and the orbits of the other stations in the sky" src="docs/images/space-ride-horizon.png" width="420"></p>
360
360
 
361
361
  `space.ride({ group: "stations", index: 0 }, { look: "horizon" })` puts the camera on the ISS (or a Starlink satellite, the Moon, a planet) at its real place for the moment shown and looks at the Earth, which goes by beneath
362
- as the body moves along its orbit; switch to another body and the camera glides there. Straight down or toward the horizon, from the body or following it at a distance, time faster or slower. A ridden satellite is in the picture by default (the camera a little behind and above it, a small drawing of it where the page has no model, not to scale); `ride-viewpoint="inside"` (property `rideViewpoint`, option `viewpoint`) puts the camera at the satellite instead. Seen from above, the model shrinks as the ride rises and hands over to the ordinary mark by 2,000 km; `ride-model-size="fixed"` (property `rideModelSize`, option `modelSize`) keeps one size at every height. It animates continuously, so it keeps to the
362
+ as the body moves along its orbit; switch to another body and the camera glides there. Straight down or toward the horizon, from the body or following it at a distance, time faster or slower. A ridden satellite is in the picture by default (the camera a little behind and above it, a small drawing of it where the page has no model, not to scale); `ride-viewpoint="inside"` (property `rideViewpoint`, option `viewpoint`) puts the camera at the satellite instead. Seen from above, the model shrinks as the ride rises and hands over to the ordinary mark by 2,000 km; `ride-model-size="fixed"` (property `rideModelSize`, option `modelSize`) keeps one size at every height. `ride-model-share`, `ride-model-seat` and `ride-zoom` frame and zoom the ridden satellite (properties `rideModelShare`, `rideModelSeat`, `rideZoom`). It animates continuously, so it keeps to the
363
363
  same budget: at most 30 frames a second (one a second for reduced motion), nothing drawn while paused, out of sight or hidden. [Ride along guide](docs/guides/ride-along.md), [docs/ride-along.md](docs/ride-along.md).
364
364
 
365
365
  ## Printable sheets
@@ -399,7 +399,7 @@ rotate or drag controls.
399
399
  | --- | --- | --- |
400
400
  | `<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 |
401
401
  | `<chikyu-earth-realistic>` | 0.1 to 5 times; 40 with `tiles` found (20 for a set that stops at level 4) | the package's pictures are 4096 pixels across at most; the finest tile level is up to 8 times that |
402
- | `<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 |
402
+ | `<chikyu-space>` | a millionth to 2.5 times; 0.5 to 40 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 |
403
403
 
404
404
  [Zoom, pan and turn](docs/guides/zoom-and-pan.md) says more. For buttons, a slider, Auto-turn and the address, add the
405
405
  bar for the element (give it an `id` and a `tabindex`); it takes the hands over and the page applies its events:
@@ -612,7 +612,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
612
612
 
613
613
  ## How to cite
614
614
 
615
- > Morris, J. (2026). *Chikyu Earth* (version 0.46.6) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
615
+ > Morris, J. (2026). *Chikyu Earth* (version 0.47.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
616
616
 
617
617
  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.
618
618
 
@@ -7,7 +7,7 @@ import { type BeamOptions } from "./geometry.ts";
7
7
  *
8
8
  * @example
9
9
  * ```ts no-run
10
- * import type { BeamStats } from "@johnmorrisdotca/chikyu-earth/space/element";
10
+ * import type { BeamStats } from "@johnmorrisdotca/chikyu-earth/space";
11
11
  *
12
12
  * const none: BeamStats = { shown: false, heightKm: 0, radiusKm: 0, angleDegrees: 0, elevation: 25, cells: 0, cellRadiusKm: 0, builds: 0, failed: false };
13
13
  * console.log(none);
@@ -12,6 +12,8 @@ export interface SatelliteMark {
12
12
  x: number;
13
13
  y: number;
14
14
  visible: boolean;
15
+ /** The Earth hides it. The name is dimmed and the ring is left off, unless dimming is off. */
16
+ occluded?: boolean;
15
17
  }
16
18
  /**
17
19
  * The most places in sight drawn as markers of their own (a beam, a pin or a ring standing out of the ground, and a name): `here` first, then the rest in the order given. Every other place is a ring on the ground, all of them one draw call.
@@ -73,6 +75,8 @@ export interface PlaceLayer {
73
75
  * fading at the Earth's edge and dimmer at night, and `stats.omitted` counts the places in sight it had no room for. `stats.sprites` counts only the rings the picture draws; `stats.dots` counts the circles.
74
76
  */
75
77
  ringsInPicture: boolean;
78
+ /** Dim a name the Earth hides, and leave its ring off. On by default. Off leaves that name out. */
79
+ dimOccluded: boolean;
76
80
  readonly stats: {
77
81
  places: number;
78
82
  shown: number;
@@ -28,6 +28,7 @@ export const PLACE_STYLE = "#places{position:absolute;inset:0;overflow:hidden;po
28
28
  ".pl-name[data-kind=group]{padding:0 5px;font-size:10px;line-height:14px;border-radius:7px;background:rgba(4,10,20,.6)}" +
29
29
  ".pl-name[data-night]{opacity:.82}" +
30
30
  ".pl-name[data-kind=satellite]{--c:#cfeaff;color:#cfeaff;font-weight:500;background:rgba(4,10,20,.5);border-color:transparent}" +
31
+ ".pl-name[data-occluded]{opacity:.45}" +
31
32
  ".pl-sat{position:absolute;left:-8px;top:-8px;width:16px;height:16px;box-sizing:border-box;border:1.2px solid #cfeaff;border-radius:50%;opacity:.85;will-change:transform}" +
32
33
  ".pl-sat[hidden]{display:none}" +
33
34
  ".pl-dot{position:absolute;left:0;top:0;box-sizing:border-box;border:1.5px solid var(--c);border-radius:50%;opacity:.9}" +
@@ -93,6 +94,7 @@ export function createPlaceLayer(box) {
93
94
  const stats = { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 };
94
95
  let grouping = true;
95
96
  let ringsInPicture = true;
97
+ let dimOccluded = true;
96
98
  // the small circles that stand in for the picture's rings when it cannot draw them: the element, and what it was last written with
97
99
  const dots = [];
98
100
  // where each group fell on the screen the last time the picture could not draw the rings: x, y, facing. Grown when the groups grow, never one array a frame.
@@ -194,7 +196,7 @@ export function createPlaceLayer(box) {
194
196
  if (!list[i].hidden)
195
197
  list[i].hidden = true;
196
198
  };
197
- const showName = (name, text, kind, left, top, color, night) => {
199
+ const showName = (name, text, kind, left, top, color, night, occluded = false) => {
198
200
  if (name.textContent !== text)
199
201
  name.textContent = text;
200
202
  if (name.dataset["kind"] !== kind)
@@ -204,6 +206,11 @@ export function createPlaceLayer(box) {
204
206
  else if (name.style.getPropertyValue("--c"))
205
207
  name.style.removeProperty("--c");
206
208
  name.toggleAttribute("data-night", night);
209
+ name.toggleAttribute("data-occluded", occluded);
210
+ if (occluded)
211
+ name.style.opacity = "0.45";
212
+ else if (name.style.opacity === "0.45")
213
+ name.style.opacity = "";
207
214
  if (name.hidden)
208
215
  name.hidden = false;
209
216
  name.style.transform = `translate(${Math.round(left)}px,${Math.round(top)}px)`;
@@ -346,6 +353,12 @@ export function createPlaceLayer(box) {
346
353
  set ringsInPicture(value) {
347
354
  ringsInPicture = value;
348
355
  },
356
+ get dimOccluded() {
357
+ return dimOccluded;
358
+ },
359
+ set dimOccluded(value) {
360
+ dimOccluded = value;
361
+ },
349
362
  get sprites() {
350
363
  return sprites;
351
364
  },
@@ -507,8 +520,9 @@ export function createPlaceLayer(box) {
507
520
  }
508
521
  hideDots(drawnDots);
509
522
  stats.omitted = omitted;
510
- // the ringed satellites: a ring round each that can be seen, and its name where it is free of the places' names and the boxes taken
523
+ // a ring round each satellite that can be seen. A name the Earth hides is dimmed and has no ring, unless that dimming is off, in which case the name is left out.
511
524
  const seen = satellites.filter((mark) => mark.visible);
525
+ const labelled = dimOccluded ? satellites.filter((mark) => mark.visible || mark.occluded) : seen;
512
526
  for (const [i, mark] of seen.entries()) {
513
527
  let ring = rings[i];
514
528
  if (!ring) {
@@ -524,18 +538,18 @@ export function createPlaceLayer(box) {
524
538
  hideFrom(rings, seen.length);
525
539
  const items = [];
526
540
  const owners = [];
527
- measureAll(seen.filter((mark) => mark.label).map((mark) => ({ label: mark.label, kind: "satellite" })));
528
- for (const [i, mark] of seen.entries()) {
541
+ measureAll(labelled.filter((mark) => mark.label).map((mark) => ({ label: mark.label, kind: "satellite" })));
542
+ for (const [i, mark] of labelled.entries()) {
529
543
  const found = mark.label ? size({ label: mark.label, kind: "satellite" }) : null;
530
544
  if (!found)
531
545
  continue;
532
- items.push({ x: mark.x, y: mark.y, r: SATELLITE_RING + 2, w: found.width, h: found.height, priority: -i });
546
+ items.push({ x: mark.x, y: mark.y, r: mark.occluded ? 2 : SATELLITE_RING + 2, w: found.width, h: found.height, priority: -i });
533
547
  owners.push(mark);
534
548
  }
535
549
  const placed = placeLabels(items, view.width, view.height, 24, 64, busy);
536
550
  for (const spot of placed) {
537
551
  const mark = owners[spot.item];
538
- showName(nameAt(used), mark.label, "satellite", spot.left, spot.top, undefined, false);
552
+ showName(nameAt(used), mark.label, "satellite", spot.left, spot.top, undefined, false, mark.occluded === true);
539
553
  used += 1;
540
554
  }
541
555
  hideFrom(names, used);
@@ -0,0 +1,230 @@
1
+ import { type HereTown } from "../markers/here-city.ts";
2
+ import { PLACE_COAST_KM } from "./land.ts";
3
+ import { SEA_REACH_KM } from "./water.ts";
4
+ export { PLACE_COAST_KM, SEA_REACH_KM };
5
+ /**
6
+ * A named place: an id, and the English and Japanese names.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import type { PlaceName } from "@johnmorrisdotca/chikyu-earth/place";
11
+ *
12
+ * const pacific: PlaceName = { id: "pacific-ocean", name: "Pacific Ocean", nameJa: "太平洋" };
13
+ * console.log(pacific.name);
14
+ * ```
15
+ */
16
+ export interface PlaceName {
17
+ id: string;
18
+ name: string;
19
+ nameJa: string;
20
+ }
21
+ /**
22
+ * A country from the outlines. `code` is the ISO 3166-1 alpha-2 code, or null where the outline has none.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import type { PlaceCountry } from "@johnmorrisdotca/chikyu-earth/place";
27
+ *
28
+ * const japan: PlaceCountry = { code: "JP", name: "Japan", nameJa: "日本" };
29
+ * console.log(japan.code);
30
+ * ```
31
+ */
32
+ export interface PlaceCountry {
33
+ code: string | null;
34
+ name: string;
35
+ nameJa: string;
36
+ }
37
+ /**
38
+ * The nearest country when the point is outside every outline and within {@link PLACE_COAST_KM} of one.
39
+ * The 1:110m line is not trusted that close to a coast, so this is not reported as `country`.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * import type { PlaceNear } from "@johnmorrisdotca/chikyu-earth/place";
44
+ *
45
+ * const off: PlaceNear = { code: "JP", name: "Japan", nameJa: "日本", distanceKm: 12 };
46
+ * console.log(off.distanceKm);
47
+ * ```
48
+ */
49
+ export interface PlaceNear extends PlaceCountry {
50
+ distanceKm: number;
51
+ }
52
+ /**
53
+ * The nearest city, from the lists the caller passed. `nameJa` is the short Japanese name, then the Japanese name, and the English name when neither is known.
54
+ * `bearingDeg` is degrees clockwise from north, from the point to the city, or 0 when the city has no coordinates.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import type { PlaceCity } from "@johnmorrisdotca/chikyu-earth/place";
59
+ *
60
+ * const paris: PlaceCity = { name: "Paris", nameJa: "パリ", countryCode: "FR", distanceKm: 1, bearingDeg: 20 };
61
+ * console.log(paris.name);
62
+ * ```
63
+ */
64
+ export interface PlaceCity {
65
+ name: string;
66
+ nameJa: string;
67
+ countryCode: string | null;
68
+ distanceKm: number;
69
+ bearingDeg: number;
70
+ }
71
+ /**
72
+ * What {@link placeOf} returns. `country` is set only when the point is inside an outline. `near` is set only when it is not, and a country lies within {@link PLACE_COAST_KM}.
73
+ * `sea` is set when `country` is not, and a named water is within its reach. `continent` follows the country or the nearby country, and is null over open water.
74
+ * Oceania is not one of the seven continents in the sea-names list: an island country chizu groups there has `id` `oceania` and chizu's own names. Australia the country uses the Australia continent.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * import type { PlaceOf } from "@johnmorrisdotca/chikyu-earth/place";
79
+ *
80
+ * const empty: PlaceOf = { country: null, near: null, sea: null, continent: null, nearestCity: null };
81
+ * console.log(empty.country);
82
+ * ```
83
+ */
84
+ export interface PlaceOf {
85
+ country: PlaceCountry | null;
86
+ near: PlaceNear | null;
87
+ sea: PlaceName | null;
88
+ continent: PlaceName | null;
89
+ nearestCity: PlaceCity | null;
90
+ }
91
+ /**
92
+ * The city lists for {@link placeOf}. The three tiers here-city loads (capitals, a million, 100,000) match this.
93
+ * `towns` is read only when the caller passes it, and only for the one or two countries those tiers name, the same rule as here-city.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * import type { PlaceCities } from "@johnmorrisdotca/chikyu-earth/place";
98
+ *
99
+ * const cities: PlaceCities = { nearest: () => null };
100
+ * console.log(cities.nearest({ lat: 0, lon: 0 }));
101
+ * ```
102
+ */
103
+ export interface PlaceCities {
104
+ nearest(point: {
105
+ lat: number;
106
+ lon: number;
107
+ }, options?: {
108
+ maxKm?: number;
109
+ }): {
110
+ city: {
111
+ id: string;
112
+ name: {
113
+ en: string;
114
+ ja?: string;
115
+ jaShort?: string;
116
+ };
117
+ country?: string;
118
+ lat?: number;
119
+ lon?: number;
120
+ };
121
+ km: number;
122
+ } | null;
123
+ within?(point: {
124
+ lat: number;
125
+ lon: number;
126
+ }, maxKm: number): readonly {
127
+ city: {
128
+ country?: string;
129
+ };
130
+ km: number;
131
+ }[];
132
+ }
133
+ /**
134
+ * Options for {@link placeOf} and {@link alongTrack}. Without `cities`, `nearestCity` is null. `maxKm` defaults to 100 and is at most 20,000.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * import type { PlaceOptions } from "@johnmorrisdotca/chikyu-earth/place";
139
+ *
140
+ * const options: PlaceOptions = { maxKm: 40 };
141
+ * console.log(options.maxKm);
142
+ * ```
143
+ */
144
+ export interface PlaceOptions {
145
+ cities?: PlaceCities;
146
+ towns?: (countryCode: string) => readonly HereTown[];
147
+ maxKm?: number;
148
+ }
149
+ /**
150
+ * The place a ground track is in at one sample: a country, a country it is only near, or a sea or ocean.
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * import type { TrackPlace } from "@johnmorrisdotca/chikyu-earth/place";
155
+ *
156
+ * const france: TrackPlace = { kind: "country", id: "FR", name: "France", nameJa: "フランス" };
157
+ * console.log(france.kind);
158
+ * ```
159
+ */
160
+ export interface TrackPlace {
161
+ kind: "country" | "near" | "sea";
162
+ id: string;
163
+ name: string;
164
+ nameJa: string;
165
+ }
166
+ /**
167
+ * One change along a ground track. `t` is the sample's own time, the first sample where the new place is seen, not a time guessed between samples.
168
+ * The first sample is included, with `leaving` null. `near` is the approaching country.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * import type { TrackChange } from "@johnmorrisdotca/chikyu-earth/place";
173
+ *
174
+ * const change: TrackChange = { t: 0, entering: null, leaving: null };
175
+ * console.log(change.t);
176
+ * ```
177
+ */
178
+ export interface TrackChange {
179
+ t: number;
180
+ entering: TrackPlace | null;
181
+ leaving: TrackPlace | null;
182
+ }
183
+ /**
184
+ * The country, sea or ocean, continent and nearest city at one point.
185
+ * Countries are the line globe's outlines, Natural Earth at 1:110m. A point inside an outline is `country`.
186
+ * A point outside every outline and within {@link PLACE_COAST_KM} (50 km) of one is `near` instead: the coarse coast is not reported as a country.
187
+ * The sea is the nearest named sea, gulf, bay or ocean within its reach ({@link SEA_REACH_KM}); a smaller water's point is nearer, so it wins over the ocean. It is null while `country` is set, and null when no water is within reach.
188
+ * The continent is the country's group in the outlines, named as in the sea-names list. Australia the country uses that continent, not the Oceania group. A point whose continent point is at least 2,500 km nearer than its country's group (eastern Russia, French Guiana) uses the nearer one. The city lists are the caller's: without `cities`, `nearestCity` is null.
189
+ * Towns under 100,000 are read only when `towns` is passed. The outlines are indexed on a 15° grid so a call is cheap enough to make about once a second.
190
+ *
191
+ * @param lon - Degrees east. A value outside -180 to 180 is wrapped.
192
+ * @param lat - Degrees north, -90 to 90.
193
+ * @param options - City lists and the kilometre limit. Omit them to skip the city.
194
+ * @returns The place. Every field is null when `lat` is not a latitude.
195
+ *
196
+ * @example
197
+ * ```ts
198
+ * import { placeOf } from "@johnmorrisdotca/chikyu-earth/place";
199
+ *
200
+ * console.log(placeOf(2.35, 48.86).country?.code);
201
+ * console.log(placeOf(-150, 0).sea?.id);
202
+ * console.log(placeOf(0, 90).country);
203
+ * ```
204
+ */
205
+ export declare function placeOf(lon: number, lat: number, options?: PlaceOptions): PlaceOf;
206
+ /**
207
+ * The ordered changes of place along a ground track. Each point is `{ lon, lat, t }`.
208
+ * A change is reported at the sample that entered the new place. `near` is how a page says the track is approaching a country; the next sample inside it is the country itself.
209
+ *
210
+ * @param points - The track, in order. A point with no latitude is skipped.
211
+ * @param options - The same city lists as {@link placeOf}. They do not change the country or the sea.
212
+ * @returns One row for the first sample, then one row each time the country, the nearby country or the sea changes.
213
+ *
214
+ * @example
215
+ * ```ts
216
+ * import { alongTrack } from "@johnmorrisdotca/chikyu-earth/place";
217
+ *
218
+ * const rows = alongTrack([
219
+ * { lon: -40, lat: 40, t: 0 },
220
+ * { lon: -3.7, lat: 40.4, t: 1 },
221
+ * { lon: 2.35, lat: 48.86, t: 2 },
222
+ * ]);
223
+ * console.log(rows.map((row) => row.entering?.id).join(" "));
224
+ * ```
225
+ */
226
+ export declare function alongTrack(points: readonly {
227
+ lon: number;
228
+ lat: number;
229
+ t: number;
230
+ }[], options?: PlaceOptions): TrackChange[];
@@ -0,0 +1,183 @@
1
+ // Where a point is on the Earth: the country, the sea or ocean, the continent, and the nearest city.
2
+ // Pure. A page that never imports this does not pay for it. The country shapes are Natural Earth 1:110m (chizu's world-geo).
3
+ // The seas and continents are the sea-names list. Cities are whoever the caller passes, the same lists here-city uses.
4
+ import { SEA_FEATURES } from "../sea-names/features.js";
5
+ import { HERE_CITY_KM, HERE_CITY_MAX_KM, chooseHereCity, hereCountries } from "../markers/here-city.js";
6
+ import { landAt, PLACE_COAST_KM } from "./land.js";
7
+ import { SEA_REACH_KM, waterAt } from "./water.js";
8
+ export { PLACE_COAST_KM, SEA_REACH_KM };
9
+ const RAD = Math.PI / 180;
10
+ const CONTINENT_ID = {
11
+ Africa: "africa",
12
+ Antarctica: "antarctica",
13
+ Asia: "asia",
14
+ Europe: "europe",
15
+ "North America": "north-america",
16
+ "South America": "south-america",
17
+ };
18
+ const empty = () => ({ country: null, near: null, sea: null, continent: null, nearestCity: null });
19
+ const clean = (lon, lat) => {
20
+ if (!Number.isFinite(lon) || !Number.isFinite(lat) || lat < -90 || lat > 90)
21
+ return null;
22
+ let x = ((lon + 180) % 360 + 360) % 360 - 180;
23
+ if (x === -180 && lon > 0)
24
+ x = 180;
25
+ return { lon: x, lat };
26
+ };
27
+ const countryOf = (hit) => ({ code: hit.code, name: hit.name, nameJa: hit.nameJa });
28
+ const kmTo = (lon, lat, feature) => {
29
+ const φ1 = lat * RAD;
30
+ const φ2 = feature.lat * RAD;
31
+ const Δφ = (feature.lat - lat) * RAD;
32
+ const Δλ = (feature.lon - lon) * RAD;
33
+ const h = Math.sin(Δφ / 2) ** 2 + Math.cos(φ1) * Math.cos(φ2) * Math.sin(Δλ / 2) ** 2;
34
+ return 2 * 6371.0088 * Math.asin(Math.min(1, Math.sqrt(h)));
35
+ };
36
+ /** A country chizu puts in one continent can still reach into another (eastern Russia, French Guiana). Use the nearer continent point when it is this much closer. */
37
+ const CONTINENT_SHIFT_KM = 2500;
38
+ const named = (feature) => ({ id: feature.id, name: feature.name.en, nameJa: feature.name.ja });
39
+ const continentOf = (hit, lon, lat) => {
40
+ const continents = SEA_FEATURES.filter((one) => one.kind === "continent");
41
+ if (hit.code === "AU") {
42
+ const australia = continents.find((one) => one.id === "australia");
43
+ return australia ? named(australia) : null;
44
+ }
45
+ if (hit.group === "Oceania")
46
+ return { id: "oceania", name: "Oceania", nameJa: hit.groupJa || "オセアニア" };
47
+ let nearest = continents[0];
48
+ let nearestKm = nearest ? kmTo(lon, lat, nearest) : Number.POSITIVE_INFINITY;
49
+ for (const feature of continents.slice(1)) {
50
+ const km = kmTo(lon, lat, feature);
51
+ if (km < nearestKm) {
52
+ nearest = feature;
53
+ nearestKm = km;
54
+ }
55
+ }
56
+ const grouped = continents.find((one) => one.id === CONTINENT_ID[hit.group]);
57
+ if (!grouped)
58
+ return nearest ? named(nearest) : null;
59
+ const feature = kmTo(lon, lat, grouped) - nearestKm >= CONTINENT_SHIFT_KM && nearest ? nearest : grouped;
60
+ return named(feature);
61
+ };
62
+ const bearingDeg = (fromLon, fromLat, toLon, toLat) => {
63
+ const φ1 = fromLat * RAD;
64
+ const φ2 = toLat * RAD;
65
+ const Δλ = (toLon - fromLon) * RAD;
66
+ const y = Math.sin(Δλ) * Math.cos(φ2);
67
+ const x = Math.cos(φ1) * Math.sin(φ2) - Math.sin(φ1) * Math.cos(φ2) * Math.cos(Δλ);
68
+ return (Math.atan2(y, x) * (180 / Math.PI) + 360) % 360;
69
+ };
70
+ const cityOf = (lon, lat, options) => {
71
+ const cities = options?.cities;
72
+ if (!cities)
73
+ return null;
74
+ const maxKm = Math.min(HERE_CITY_MAX_KM, options?.maxKm ?? HERE_CITY_KM);
75
+ if (!(maxKm > 0))
76
+ return null;
77
+ const point = { lat, lon };
78
+ const coarse = cities.nearest(point, { maxKm });
79
+ const townsOf = options?.towns;
80
+ const towns = townsOf ? hereCountries(point, cities, maxKm).flatMap((code) => townsOf(code) ?? []) : [];
81
+ const chosen = chooseHereCity(point, coarse, towns, maxKm);
82
+ if (!chosen)
83
+ return null;
84
+ const town = towns.find((one) => one.id === chosen.id);
85
+ const at = town ?? (coarse && coarse.city.id === chosen.id ? coarse.city : undefined);
86
+ const countryCode = (town?.country ?? coarse?.city.country ?? "").trim().toUpperCase() || null;
87
+ const nameJa = chosen.name.jaShort || chosen.name.ja || chosen.name.en;
88
+ const cityLat = at?.lat;
89
+ const cityLon = at?.lon;
90
+ const bearing = cityLat !== undefined && cityLon !== undefined && Number.isFinite(cityLat) && Number.isFinite(cityLon) ? bearingDeg(lon, lat, cityLon, cityLat) : 0;
91
+ return { name: chosen.name.en, nameJa, countryCode, distanceKm: chosen.km, bearingDeg: bearing };
92
+ };
93
+ const headline = (place) => {
94
+ if (place.country)
95
+ return { kind: "country", id: place.country.code ?? place.country.name, name: place.country.name, nameJa: place.country.nameJa };
96
+ if (place.near)
97
+ return { kind: "near", id: place.near.code ?? place.near.name, name: place.near.name, nameJa: place.near.nameJa };
98
+ if (place.sea)
99
+ return { kind: "sea", id: place.sea.id, name: place.sea.name, nameJa: place.sea.nameJa };
100
+ return null;
101
+ };
102
+ const same = (a, b) => a?.kind === b?.kind && a?.id === b?.id;
103
+ /**
104
+ * The country, sea or ocean, continent and nearest city at one point.
105
+ * Countries are the line globe's outlines, Natural Earth at 1:110m. A point inside an outline is `country`.
106
+ * A point outside every outline and within {@link PLACE_COAST_KM} (50 km) of one is `near` instead: the coarse coast is not reported as a country.
107
+ * The sea is the nearest named sea, gulf, bay or ocean within its reach ({@link SEA_REACH_KM}); a smaller water's point is nearer, so it wins over the ocean. It is null while `country` is set, and null when no water is within reach.
108
+ * The continent is the country's group in the outlines, named as in the sea-names list. Australia the country uses that continent, not the Oceania group. A point whose continent point is at least 2,500 km nearer than its country's group (eastern Russia, French Guiana) uses the nearer one. The city lists are the caller's: without `cities`, `nearestCity` is null.
109
+ * Towns under 100,000 are read only when `towns` is passed. The outlines are indexed on a 15° grid so a call is cheap enough to make about once a second.
110
+ *
111
+ * @param lon - Degrees east. A value outside -180 to 180 is wrapped.
112
+ * @param lat - Degrees north, -90 to 90.
113
+ * @param options - City lists and the kilometre limit. Omit them to skip the city.
114
+ * @returns The place. Every field is null when `lat` is not a latitude.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import { placeOf } from "@johnmorrisdotca/chikyu-earth/place";
119
+ *
120
+ * console.log(placeOf(2.35, 48.86).country?.code);
121
+ * console.log(placeOf(-150, 0).sea?.id);
122
+ * console.log(placeOf(0, 90).country);
123
+ * ```
124
+ */
125
+ export function placeOf(lon, lat, options) {
126
+ const at = clean(lon, lat);
127
+ if (!at)
128
+ return empty();
129
+ const land = landAt(at.lon, at.lat);
130
+ const held = land.country ?? land.near;
131
+ const water = land.country ? null : waterAt(at.lon, at.lat);
132
+ return {
133
+ country: land.country ? countryOf(land.country) : null,
134
+ near: land.near ? { ...countryOf(land.near), distanceKm: land.near.distanceKm } : null,
135
+ sea: water ? { id: water.id, name: water.name.en, nameJa: water.name.ja } : null,
136
+ continent: held ? continentOf(held, at.lon, at.lat) : null,
137
+ nearestCity: cityOf(at.lon, at.lat, options),
138
+ };
139
+ }
140
+ /**
141
+ * The ordered changes of place along a ground track. Each point is `{ lon, lat, t }`.
142
+ * A change is reported at the sample that entered the new place. `near` is how a page says the track is approaching a country; the next sample inside it is the country itself.
143
+ *
144
+ * @param points - The track, in order. A point with no latitude is skipped.
145
+ * @param options - The same city lists as {@link placeOf}. They do not change the country or the sea.
146
+ * @returns One row for the first sample, then one row each time the country, the nearby country or the sea changes.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * import { alongTrack } from "@johnmorrisdotca/chikyu-earth/place";
151
+ *
152
+ * const rows = alongTrack([
153
+ * { lon: -40, lat: 40, t: 0 },
154
+ * { lon: -3.7, lat: 40.4, t: 1 },
155
+ * { lon: 2.35, lat: 48.86, t: 2 },
156
+ * ]);
157
+ * console.log(rows.map((row) => row.entering?.id).join(" "));
158
+ * ```
159
+ */
160
+ export function alongTrack(points, options) {
161
+ const out = [];
162
+ let previous = null;
163
+ let started = false;
164
+ for (const point of points) {
165
+ if (!Number.isFinite(point.t))
166
+ continue;
167
+ const place = placeOf(point.lon, point.lat, options);
168
+ if (!Number.isFinite(point.lon) || !Number.isFinite(point.lat) || point.lat < -90 || point.lat > 90)
169
+ continue;
170
+ const next = headline(place);
171
+ if (!started) {
172
+ out.push({ t: point.t, entering: next, leaving: null });
173
+ previous = next;
174
+ started = true;
175
+ continue;
176
+ }
177
+ if (same(previous, next))
178
+ continue;
179
+ out.push({ t: point.t, entering: next, leaving: previous });
180
+ previous = next;
181
+ }
182
+ return out;
183
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * How close to a 1:110m outline, in kilometres, still counts as that country nearby.
3
+ * The outlines can sit tens of kilometres off a real coast, so a point this close is not reported as inside.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { PLACE_COAST_KM } from "@johnmorrisdotca/chikyu-earth/place";
8
+ *
9
+ * console.log(PLACE_COAST_KM);
10
+ * ```
11
+ */
12
+ export declare const PLACE_COAST_KM = 50;
13
+ /** A country the outlines know, with the continent group chizu gives it. */
14
+ export interface LandHit {
15
+ code: string | null;
16
+ name: string;
17
+ nameJa: string;
18
+ group: string;
19
+ groupJa: string;
20
+ }
21
+ export interface LandAnswer {
22
+ /** Inside one outline, and not merely within {@link PLACE_COAST_KM} of its edge while sitting outside it. */
23
+ country: LandHit | null;
24
+ /** Outside every outline, and within {@link PLACE_COAST_KM} of the nearest one. */
25
+ near: (LandHit & {
26
+ distanceKm: number;
27
+ }) | null;
28
+ }
29
+ /** The country at a longitude and latitude, or the nearest one when the point is just off a coarse outline. The shapes are Natural Earth 1:110m. */
30
+ export declare function landAt(lon: number, lat: number): LandAnswer;