@johnmorrisdotca/chikyu-earth 0.41.0 → 0.43.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,6 +1,20 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.43.0 - 2026-11-13
4
+
5
+ - **One satellite group at a time** (MODULES-1215). `focusSatelliteGroup(name, options)` on `<chikyu-space>` and `<chikyu-earth-realistic>` shows one group that has been set and deals with the others: `others` is `"dim"` (the default; the same dimming an old element set uses, so no new object) or `"hide"`. `frame` (true by default) pulls the camera back with the view's own zoom until the group's orbits fit. The distance is the greatest apogee, from mean motion and eccentricity, and it stops at 8 Earth radii. `null` restores each group's own shown state and the camera. A group that has not been set returns `{ ok: false, reason: "not-set" }` and changes nothing. `focusedSatelliteGroup` is the name or `null`. `satelliteGroups` adds `emphasis` and `placed`, and keeps `count`. `chikyu-satellite-focus` is sent with `{ group, count }` when the choice changes. The demo has a row, "One group". Nothing is drawn at rest.
6
+ - **A ring appears when the satellite comes into the picture** (MODULES-1213). `ringSatellites` keeps the satellites it was asked to ring. One that is outside the picture gets its ring on the first later draw that shows it, and nothing is drawn at rest just to wait. `placeSatellite` adds `edge` (`"top"`, `"right"`, `"bottom"`, `"left"` or `null`) and `behind` (true when the satellite is behind the camera), and no longer answers `null` for a satellite that is merely out of the picture: it returns the place outside the picture, so check `.visible`.
7
+
8
+ ## 0.42.0 - 2026-11-13
9
+
10
+ - **The "you are here" marker can take the nearest city's name** (MODULES-1077). `here-city` on `<chikyu-space>` and `<chikyu-earth-realistic>` (off by default; the property `hereCity` is `false`, `true` or a number of kilometres) names each `kind: "here"` place with the nearest city within 100 km (`HERE_CITY_KM`; a number on the attribute is that limit, at most 20,000). The name follows the page's language. The cities are kuni's capitals, the other cities of a million and the others of 100,000, loaded only when this is on and a `here` place is set; a smaller town keeps the label the page gave. `places` itself is not changed. Nothing is drawn again at rest.
11
+ - **Satellites nearest a place, a point in the sky, or another satellite** (MODULES-652). `nearest`, `within` and `closeApproach` in `@johnmorrisdotca/chikyu-earth/satellites` answer from the group's SGP4 positions (`exact`), once per call and never on a timer. `by: "space"` returns kilometres with a rough uncertainty (1 km at the epoch, and 1 km more for each day the elements have aged). `by: "sky"` returns the angle in degrees. `closeApproach` samples the span and then refines the closest moment to a tenth of a second (the closest sample alone was 172 km off a true 100 km in the test, two satellites 7 km/s apart); its uncertainty is the elements' own, not the sample step. A satellite straight overhead is its height away. `ringSatellites` on `<chikyu-space>` rings the ones a page names. One call places each satellite once: about 0.15 ms for one, so a few thousand is on the order of a second.
12
+ - **Distance and the route between two places** (MODULES-679). `route` on `<chikyu-earth>`, `<chikyu-earth-realistic>` and `<chikyu-space>` (absent by default; the property is the two places or `null`) draws the line between them. `routeInfo` gives the WGS84 geodesic (`kilometres`, Vincenty), the great-circle distance on a sphere of 6371.0088 km, the initial and final bearings, and a flight time at 900 km/h. The line is split at the date line. Nothing is drawn again at rest. There is no flat world map in this package: the line globe is the flat drawing, and `routeRuns` is there for a page that draws its own.
13
+ - **Bodies are made only when they are big enough to see** (MODULES-1192). `<chikyu-space>` made the painter's drawing of the Sun, the Moon and every planet in every view, with their mapped pictures, however small or far from the view. It now asks the painter for a body only when the body is in the view and at least 6 CSS pixels across its radius (`BODY_MAKE_PX`); a smaller one, or one out of the view, is a plain sphere of the right colour (the Moon is the view's own Moon), and a body that has shrunk below 3 pixels or left the view is let go of its pictures after four seconds (`BODY_KEEP_MS`), so one that comes and goes is not made again and again. Measured in the default Earth view (Nov 10, centred on -100,40): the pictures loaded went from 10 (the Sun, the Moon and the eight planets, 150,446 bytes) to 1 (the Moon, 16,974 bytes); `stats.bodies.mapped` says how many drawings are the painter's. wakusei-planets' `credit` therefore narrows by itself: an Earth view with no CC BY body in it shows no CC BY line, Jupiter adds Nestaeric's credit, the Sun adds Solar System Scope's, and no line is written while the painter holds nothing. Nothing is drawn at rest and the GPU objects are flat across moves. Tests: `e2e/space-bodies.gl.ts`, `e2e/space-credit.gl.ts`, `e2e/space-full.gl.ts`.
14
+ - **Reduced motion gathers the pictures that arrive** (MODULES-1195). Since bodies are made only when big enough (MODULES-1192), a body that came into view made its pictures arrive one by one, each asking for a draw: a reader who asked for reduced motion got about 8 draws in half a second, and 1.75 draws a second riding the ISS at 60x against the one step a second the clock makes. The Earth's maps, its finer tiles and a body's pictures now ask for at most one draw a second (the first after a quiet second at once, those that follow when the second ends), and none while the clock steps at least once a second, whose next step shows them; without reduced motion a picture is drawn as soon as it arrives, as before. `e2e/ride.gl.ts` measures from the start of the ride again (the three seconds `dbae5d8` let pass first are gone): 1.25 draws a second, where the code of 0.42.0 reads 1.75.
15
+ - **The realistic Earth's first draw is waited for, not 5 s** (MODULES-1194). `e2e/air-visible.gl.ts` gave the first draw 5 s and timed out on a loaded Mac; it now waits on the element's own draw counter, within the test's own time. Held back by 8 s in the page, the old wait fails at 5 s and the new one passes. A test change only; the package is unchanged.
16
+ - **The view says when its pictures are still to come** (MODULES-1195). `stats.bodies.pending` is how many pictures asked of the painter have not yet arrived, and one more while a gathered draw waits for its second. Five realistic-Earth tests (`drag`, `ride-face`, `sky-names`, `sky-pick`, `space`) read "rest" after a fixed wait, and on the CI image the pictures of a body that had come into view arrived after it (an extra draw at rest, a picture taken with a plain sphere where the other had its map); they now wait until `pending` is 0 and the draw count has held for longer than the gather window.
17
+ - **The soak counts what the same view holds, once it has settled** (MODULES-1192). `e2e/space.soak.ts` wanted the GPU objects at the end equal to those at the start, but bodies are let go four seconds after they leave the view and the opening view comes out at 63, 66, 69 or 72 buffers and 8 or 9 programs depending on the path to it, each steady for five seconds. It now returns to the opening view (orbits and labels as it opened), stops the controls' Auto-turn, waits until the element's own counts of the bodies it holds (`stats.bodies`) and of the programs, buffers and textures have not moved for five seconds, and then asks that no texture or program is more than at the start and the buffers are within one geometry (3 buffers, 4 GPU objects) of it (a body let go without its geometry disposed takes the soak from 60 textures to 87 and from 330 GPU objects to 416). The first form of this wait still failed in CI (17 textures against 9, MODULES-1198): the demo's Auto-turn kept turning the Earth's view while it settled, and Jupiter and its moons came into its background at some yaws, so the count depended on the yaw it was taken at. Not a leak and not a late release: the bodies are made and let go as designed. The first draw is waited for up to 30 s, not 5 s (a run on a loaded Mac timed out there, as in MODULES-1194). The freeze test waits one second more after the picture opens, for the gathered draws of a reader who asked for reduced motion. A test change only.
4
18
 
5
19
  ## 0.41.0 - 2026-11-12
6
20
 
package/README.md CHANGED
@@ -250,7 +250,9 @@ console.log(bodyLabelText("en"), bodyLabelText("ja"), BODY_LABEL_ATTRIBUTES.leng
250
250
 
251
251
  ## You are here, and places on the Earth
252
252
 
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).
253
+ `route` on `<chikyu-earth>`, `<chikyu-earth-realistic>` and `<chikyu-space>` draws the line between two places (`lon,lat,lon,lat`). `routeInfo` gives the accurate distance on the Earth's real shape, the great-circle distance, the bearings and a flight time at 900 km/h. The line is off until it is set, and nothing is drawn at rest: [guide](docs/guides/routes.md).
254
+
255
+ `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. `here-city` (off by default) names a `here` place with the nearest city within 100 km, in the page's language; kuni is loaded only then. 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).
254
256
 
255
257
  ```html
256
258
  <chikyu-space places='[{"id":"me","lon":-79.4,"lat":43.7,"label":"You are here","kind":"here"}]'></chikyu-space>
@@ -309,7 +311,7 @@ console.log(`${book.mapSources("day").length} day maps with the source off`);
309
311
 
310
312
  ## Satellites
311
313
 
312
- The ISS, a space station or thousands of Starlink satellites at the places SGP4 puts them for the date and time shown, on `<chikyu-space>`: a group is one draw call however many it holds, press one to get its name, height and speed, and its orbit is drawn. Chikyu fetches nothing: your page passes in orbital elements (CelesTrak's JSON, within its usage policy), and satellite.js (MIT, an optional peer) does the maths about once a second, with every frame between interpolated. `fetchElements(url)` reads OMM JSON, CSV or TLE from an address you choose, politely (https, not again within two hours, stop on any answer that is not 200). A satellite whose elements are more than 14 days from the time shown is drawn dimmer, and one more than 30 days away is left out. A group is hidden while the clock runs faster than 60 times real time. A small catalogue (`SATELLITE_GROUPS`, `CATALOGUE`, `findInCatalogue`) names fourteen groups (stations, weather, GPS, Galileo, OneWeb and more) and about forty satellites worth following, with no elements in it. The guide has the rules for getting elements and the budget, each line tested: [satellites guide](docs/guides/satellites.md), [docs/satellites.md](docs/satellites.md).
314
+ The ISS, a space station or thousands of Starlink satellites at the places SGP4 puts them for the date and time shown, on `<chikyu-space>`: a group is one draw call however many it holds, press one to get its name, height and speed, and its orbit is drawn. Chikyu fetches nothing: your page passes in orbital elements (CelesTrak's JSON, within its usage policy), and satellite.js (MIT, an optional peer) does the maths about once a second, with every frame between interpolated. `fetchElements(url)` reads OMM JSON, CSV or TLE from an address you choose, politely (https, not again within two hours, stop on any answer that is not 200). A satellite whose elements are more than 14 days from the time shown is drawn dimmer, and one more than 30 days away is left out. A group is hidden while the clock runs faster than 60 times real time. `nearest` and `within` say which satellites are closest to a place, a direction in the sky or another satellite, and `closeApproach` the next time two of them pass; each call places every satellite once and does not run again by itself. `ringSatellites` rings the ones you name. A small catalogue (`SATELLITE_GROUPS`, `CATALOGUE`, `findInCatalogue`) names fourteen groups (stations, weather, GPS, Galileo, OneWeb and more) and about forty satellites worth following, with no elements in it. The guide has the rules for getting elements and the budget, each line tested: [satellites guide](docs/guides/satellites.md), [docs/satellites.md](docs/satellites.md).
313
315
 
314
316
  <p align="center"><img alt="The ISS, ringed, over South Africa on 3 November 2026, with its orbit and the stations' orbits" src="docs/images/space-sat-iss.png" width="420"></p>
315
317
 
@@ -609,7 +611,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
609
611
 
610
612
  ## How to cite
611
613
 
612
- > Morris, J. (2026). *Chikyu Earth* (version 0.41.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
614
+ > Morris, J. (2026). *Chikyu Earth* (version 0.43.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
613
615
 
614
616
  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.
615
617
 
package/dist/element.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type ViewController } from "@johnmorrisdotca/kazoku-ui/view-controls";
2
+ import { type RouteLeg } from "./route.ts";
2
3
  import type { OverlayHost } from "./markers/layer.ts";
3
4
  import type { GeoPoint, GlobeView } from "./types.ts";
4
5
  /**
@@ -22,6 +23,20 @@ export declare class ChikyuEarth extends HTMLElement {
22
23
  get controller(): ViewController | undefined;
23
24
  /** Where the view is centred now: the `center` attribute, else 0,0. The element never asks the browser where the reader is. */
24
25
  get centre(): GeoPoint;
26
+ /**
27
+ * A route between two places (the attribute `route`, `lon,lat,lon,lat`). Null, the default, draws none. The line is the WGS84 geodesic, split at the date line.
28
+ * Setting the property writes the attribute. Nothing is drawn again at rest: the line is part of the picture, which is drawn when the view or the route changes.
29
+ */
30
+ get route(): {
31
+ from: GeoPoint;
32
+ to: GeoPoint;
33
+ } | null;
34
+ set route(value: {
35
+ from: GeoPoint;
36
+ to: GeoPoint;
37
+ } | null);
38
+ /** The distance, bearings and flight-time estimate for `route`, or null when none is set. The flight time assumes 900 km/h. */
39
+ get routeInfo(): RouteLeg | null;
25
40
  /** A box laid over the globe for markers (see `@johnmorrisdotca/chikyu-earth/markers`): where it is, the pose of the last drawing, and a way to hear the next. */
26
41
  get overlay(): OverlayHost;
27
42
  disconnectedCallback(): void;
package/dist/element.js CHANGED
@@ -3,6 +3,7 @@
3
3
  import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
4
4
  import { adoptStyles } from "./adopt.js";
5
5
  import { globe } from "./globe.js";
6
+ import { readRoute, routeLeg, routeText } from "./route.js";
6
7
  import { cleanStyle } from "./styles.js";
7
8
  import { globeBaseScale, HOME_VIEW, lookAt } from "./view.js";
8
9
  const readCentre = (value) => {
@@ -37,7 +38,7 @@ const STYLE = ":host{display:block;position:relative;isolation:isolate}.holder s
37
38
  * ```
38
39
  */
39
40
  export class ChikyuEarth extends HTMLElement {
40
- static observedAttributes = ["center", "look", "style", "size", "graticule"];
41
+ static observedAttributes = ["center", "look", "style", "size", "graticule", "route"];
41
42
  #centre = { lon: 0, lat: 0 };
42
43
  #view = { ...HOME_VIEW };
43
44
  #drawn = { ...HOME_VIEW };
@@ -55,6 +56,24 @@ export class ChikyuEarth extends HTMLElement {
55
56
  get centre() {
56
57
  return { ...this.#centre };
57
58
  }
59
+ /**
60
+ * A route between two places (the attribute `route`, `lon,lat,lon,lat`). Null, the default, draws none. The line is the WGS84 geodesic, split at the date line.
61
+ * Setting the property writes the attribute. Nothing is drawn again at rest: the line is part of the picture, which is drawn when the view or the route changes.
62
+ */
63
+ get route() {
64
+ return readRoute(this.getAttribute("route"));
65
+ }
66
+ set route(value) {
67
+ if (!value)
68
+ this.removeAttribute("route");
69
+ else
70
+ this.setAttribute("route", routeText(value));
71
+ }
72
+ /** The distance, bearings and flight-time estimate for `route`, or null when none is set. The flight time assumes 900 km/h. */
73
+ get routeInfo() {
74
+ const route = this.route;
75
+ return route ? routeLeg(route.from, route.to) : null;
76
+ }
58
77
  /** A box laid over the globe for markers (see `@johnmorrisdotca/chikyu-earth/markers`): where it is, the pose of the last drawing, and a way to hear the next. */
59
78
  get overlay() {
60
79
  this.#ensureShell();
@@ -164,7 +183,7 @@ export class ChikyuEarth extends HTMLElement {
164
183
  this.#liveAt = performance.now();
165
184
  const size = Number(this.getAttribute("size")) || 320;
166
185
  const style = cleanStyle(this.getAttribute("look") ?? this.getAttribute("style"));
167
- const svg = globe({ size, style, centre: this.#centre, view: this.#view, graticule: this.hasAttribute("graticule") });
186
+ const svg = globe({ size, style, centre: this.#centre, view: this.#view, graticule: this.hasAttribute("graticule"), route: readRoute(this.getAttribute("route")) });
168
187
  const root = this.#ensureShell();
169
188
  root.querySelector(".holder").innerHTML = svg;
170
189
  this.#drawn = { ...this.#view };
package/dist/globe.js CHANGED
@@ -2,6 +2,7 @@
2
2
  // arguments always give the same markup, so it works on a server, in a test, or in the element.
3
3
  import { geoGraticule10, geoOrthographic, geoPath } from "d3-geo";
4
4
  import { COUNTRIES } from "./countries.js";
5
+ import { routePoints, routeRuns } from "./route.js";
5
6
  import { cleanStyle, STYLES } from "./styles.js";
6
7
  import { projectionView } from "./view.js";
7
8
  const SPHERE = { type: "Sphere" };
@@ -45,6 +46,12 @@ export function globe(options = {}) {
45
46
  if (d)
46
47
  parts.push(`<path d="${d}" fill="${style.land}" stroke="${style.line}" stroke-width="${style.outline}" stroke-linejoin="round"/>`);
47
48
  }
49
+ if (options.route) {
50
+ const runs = routeRuns(routePoints(options.route.from, options.route.to));
51
+ const d = path({ type: "MultiLineString", coordinates: runs.map((run) => run.map((place) => [place.lon, place.lat])) });
52
+ if (d)
53
+ parts.push(`<path d="${d}" fill="none" stroke="#7df9ff" stroke-width="1.5" stroke-linejoin="round"/>`);
54
+ }
48
55
  parts.push(`<path d="${horizon}" fill="none" stroke="${style.line}" stroke-width="${style.horizon}"/>`);
49
56
  return (`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}" width="${size}" height="${size}" ` +
50
57
  `role="img" aria-label="The Earth, a globe of country outlines" stroke-linecap="round">${parts.join("")}</svg>`);
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { globe } from "./globe.ts";
2
+ export { FLIGHT_SPEED_KM_H, MEAN_RADIUS_KM, WGS84_A_M, WGS84_F, greatCircleKm, readRoute, routeLeg, routePoints, routeRuns, routeText, type RouteLeg } from "./route.ts";
2
3
  export { COUNTRIES } from "./countries.ts";
3
4
  export { cleanStyle, DEFAULT_STYLE, STYLE_NAMES, STYLES, type Style, type StyleName } from "./styles.ts";
4
5
  export { centreRotation, DEGREES_PER_MS, rotationAt, SIDEREAL_DAY_MS, spinAt } from "./rotate.ts";
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { globe } from "./globe.js";
2
+ export { FLIGHT_SPEED_KM_H, MEAN_RADIUS_KM, WGS84_A_M, WGS84_F, greatCircleKm, readRoute, routeLeg, routePoints, routeRuns, routeText } from "./route.js";
2
3
  export { COUNTRIES } from "./countries.js";
3
4
  export { cleanStyle, DEFAULT_STYLE, STYLE_NAMES, STYLES } from "./styles.js";
4
5
  export { centreRotation, DEGREES_PER_MS, rotationAt, SIDEREAL_DAY_MS, spinAt } from "./rotate.js";
@@ -0,0 +1,30 @@
1
+ import { type HereCitySource } from "./here-city.ts";
2
+ import type { Place } from "./places.ts";
3
+ export interface HereCityHost {
4
+ /** `false` leaves every label as the page set it. A number is the kilometre limit. */
5
+ setLimit(limit: false | number): void;
6
+ /** The places to draw. A `here` place whose city is known has that city's name; every other place is the one given. */
7
+ named(places: readonly Place[]): readonly Place[];
8
+ /** The page's language changed: name the places again from the cities already loaded. */
9
+ refresh(): void;
10
+ readonly stats: {
11
+ on: boolean;
12
+ maxKm: number;
13
+ loaded: boolean;
14
+ pending: boolean;
15
+ };
16
+ dispose(): void;
17
+ }
18
+ export interface HereCityOptions {
19
+ language(): "en" | "ja";
20
+ /** Cities have arrived, or the language changed, so the element can lay the names out once. */
21
+ onChange(): void;
22
+ /** kuni could not be loaded. */
23
+ onError?(error: unknown): void;
24
+ /** The city list. The default is kuni's capitals, cities of a million and cities of 100,000, loaded only when a `here` place asks. */
25
+ load?(): Promise<HereCitySource>;
26
+ }
27
+ /**
28
+ * The namer for one element. `load` runs at most once, and only after `setLimit` is a number and `named` is given a `here` place.
29
+ */
30
+ export declare function createHereCity(options: HereCityOptions): HereCityHost;
@@ -0,0 +1,105 @@
1
+ // Loads kuni's cities once, when `here-city` is on and a `here` place is set, and names those places. Nothing is loaded while it is off, and nothing is asked again at rest.
2
+ import { HERE_CITY_TIERS, hereCityLabels } from "./here-city.js";
3
+ const defaultLoad = async () => {
4
+ const { loadCities } = await import("@johnmorrisdotca/kuni/cities");
5
+ return loadCities(...HERE_CITY_TIERS);
6
+ };
7
+ /**
8
+ * The namer for one element. `load` runs at most once, and only after `setLimit` is a number and `named` is given a `here` place.
9
+ */
10
+ export function createHereCity(options) {
11
+ const load = options.load ?? defaultLoad;
12
+ let limit = false;
13
+ let source = null;
14
+ let loading = false;
15
+ let failed = false;
16
+ let gone = false;
17
+ let generation = 0;
18
+ let cache;
19
+ const changed = () => {
20
+ cache = undefined;
21
+ if (source && limit !== false && !gone)
22
+ options.onChange();
23
+ };
24
+ // The family's language chooser tells the document. The name is worked out again once, and the element draws that change.
25
+ const onLanguage = () => queueMicrotask(changed);
26
+ if (typeof document !== "undefined")
27
+ document.addEventListener("kazoku-languagechange", onLanguage);
28
+ const ensure = () => {
29
+ if (loading || source || failed || gone)
30
+ return;
31
+ loading = true;
32
+ const generationNow = generation;
33
+ let pending;
34
+ try {
35
+ pending = Promise.resolve(load());
36
+ }
37
+ catch (error) {
38
+ loading = false;
39
+ failed = true;
40
+ options.onError?.(error);
41
+ return;
42
+ }
43
+ void pending.then((cities) => {
44
+ if (gone || generationNow !== generation)
45
+ return;
46
+ source = cities;
47
+ loading = false;
48
+ if (limit !== false)
49
+ options.onChange();
50
+ }, (error) => {
51
+ if (gone || generationNow !== generation)
52
+ return;
53
+ loading = false;
54
+ failed = true;
55
+ options.onError?.(error);
56
+ });
57
+ };
58
+ return {
59
+ setLimit(next) {
60
+ if (next === limit)
61
+ return;
62
+ limit = next;
63
+ cache = undefined;
64
+ failed = false;
65
+ },
66
+ named(places) {
67
+ if (gone || limit === false || !places.some((place) => place.kind === "here"))
68
+ return places;
69
+ if (!source) {
70
+ ensure();
71
+ return places;
72
+ }
73
+ const lang = options.language();
74
+ if (cache && cache.places === places && cache.lang === lang && cache.limit === limit && cache.source === source)
75
+ return cache.out;
76
+ const hits = new Map(hereCityLabels(places, source, { lang, maxKm: limit }).map((hit) => [hit.index, hit]));
77
+ let changed = false;
78
+ const out = places.map((place, index) => {
79
+ const hit = hits.get(index);
80
+ if (!hit || place.label === hit.label)
81
+ return place;
82
+ changed = true;
83
+ return { ...place, label: hit.label };
84
+ });
85
+ const labelled = changed ? out : places;
86
+ cache = { places, lang, limit, source, out: labelled };
87
+ return labelled;
88
+ },
89
+ refresh() {
90
+ changed();
91
+ },
92
+ get stats() {
93
+ return { on: limit !== false, maxKm: limit === false ? 0 : limit, loaded: source !== null, pending: loading };
94
+ },
95
+ dispose() {
96
+ gone = true;
97
+ generation += 1;
98
+ source = null;
99
+ cache = undefined;
100
+ loading = false;
101
+ if (typeof document !== "undefined")
102
+ document.removeEventListener("kazoku-languagechange", onLanguage);
103
+ },
104
+ };
105
+ }
@@ -0,0 +1,128 @@
1
+ import type { Place } from "./places.ts";
2
+ /**
3
+ * How far, in kilometres, a `here` marker looks for a city when `here-city` is set with no number.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { HERE_CITY_KM } from "@johnmorrisdotca/chikyu-earth/markers";
8
+ *
9
+ * console.log(HERE_CITY_KM); // 100
10
+ * ```
11
+ */
12
+ export declare const HERE_CITY_KM = 100;
13
+ /**
14
+ * The furthest `here-city` will look, in kilometres. A larger number is read as this.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { HERE_CITY_MAX_KM, readHereCity } from "@johnmorrisdotca/chikyu-earth/markers";
19
+ *
20
+ * console.log(readHereCity("999999") === HERE_CITY_MAX_KM);
21
+ * ```
22
+ */
23
+ export declare const HERE_CITY_MAX_KM = 20000;
24
+ /**
25
+ * The kuni tiers a `here` marker's city is chosen from. A city of fewer than 100,000 people is in none of them.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { HERE_CITY_TIERS } from "@johnmorrisdotca/chikyu-earth/markers";
30
+ *
31
+ * console.log(HERE_CITY_TIERS.join(" "));
32
+ * ```
33
+ */
34
+ export declare const HERE_CITY_TIERS: readonly ["capitals", "1m", "100k"];
35
+ /**
36
+ * What `here-city` needs of a city list: `nearest`, as kuni's `CitySet` has it. Any list with that method will do.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import type { HereCitySource } from "@johnmorrisdotca/chikyu-earth/markers";
41
+ *
42
+ * const source: HereCitySource = { nearest: () => null };
43
+ * console.log(source.nearest({ lat: 0, lon: 0 }));
44
+ * ```
45
+ */
46
+ export interface HereCitySource {
47
+ nearest(point: {
48
+ lat: number;
49
+ lon: number;
50
+ }, options?: {
51
+ maxKm?: number;
52
+ }): {
53
+ city: {
54
+ id: string;
55
+ name: {
56
+ en: string;
57
+ ja?: string;
58
+ jaShort?: string;
59
+ };
60
+ };
61
+ km: number;
62
+ } | null;
63
+ }
64
+ /**
65
+ * The city chosen for one `here` place.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * import type { HereCityHit } from "@johnmorrisdotca/chikyu-earth/markers";
70
+ *
71
+ * const hit: HereCityHit = { index: 0, id: "Q90", label: "Paris", km: 2 };
72
+ * console.log(hit.label);
73
+ * ```
74
+ */
75
+ export interface HereCityHit {
76
+ /** Where the place is in the list given. */
77
+ index: number;
78
+ /** The city's id. */
79
+ id: string;
80
+ /** The name to draw, in the page's language. */
81
+ label: string;
82
+ /** The great-circle distance kuni reported, in kilometres. */
83
+ km: number;
84
+ }
85
+ /**
86
+ * Read the `here-city` attribute. Absent, `off`, or anything that is not a positive number of kilometres: off (`false`).
87
+ * Present with no value, or `on`: {@link HERE_CITY_KM}. A positive number: that many kilometres, at most {@link HERE_CITY_MAX_KM}.
88
+ *
89
+ * @param value - The attribute's text, or null when it is not set.
90
+ * @returns `false` when the marker keeps the page's label, or the kilometre limit.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * import { HERE_CITY_KM, readHereCity } from "@johnmorrisdotca/chikyu-earth/markers";
95
+ *
96
+ * console.log(readHereCity(null), readHereCity(""), readHereCity("40"), readHereCity("off"), HERE_CITY_KM);
97
+ * ```
98
+ */
99
+ export declare function readHereCity(value: string | null | undefined): false | number;
100
+ /**
101
+ * The city for each `here` place, nearest first within `maxKm`, named in `lang`. A favourite is left out. A place with no city inside the limit is left out, so the page's own label stays.
102
+ * The lookup is the source's: this adds none.
103
+ *
104
+ * @param places - The places, as the element holds them.
105
+ * @param source - A city list with `nearest` (kuni's `CitySet`).
106
+ * @param options - `lang` (`en` or `ja`) and `maxKm`.
107
+ * @returns One hit for each `here` place that has a city inside the limit, in the list's order.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * import { hereCityLabels } from "@johnmorrisdotca/chikyu-earth/markers";
112
+ *
113
+ * const paris = { id: "Q90", name: { en: "Paris", ja: "パリ" } };
114
+ * const source = {
115
+ * nearest(_point: { lat: number; lon: number }, options?: { maxKm?: number }) {
116
+ * return options?.maxKm !== undefined && options.maxKm < 5 ? null : { city: paris, km: 2 };
117
+ * },
118
+ * };
119
+ * const places = [{ lon: 2.35, lat: 48.86, kind: "here" as const }, { lon: 4.84, lat: 45.76, kind: "favourite" as const }];
120
+ * console.log(hereCityLabels(places, source, { lang: "en", maxKm: 100 })[0]?.label);
121
+ * console.log(hereCityLabels(places, source, { lang: "ja", maxKm: 100 })[0]?.label);
122
+ * console.log(hereCityLabels(places, source, { lang: "en", maxKm: 1 }).length);
123
+ * ```
124
+ */
125
+ export declare function hereCityLabels(places: readonly Pick<Place, "lon" | "lat" | "kind">[], source: HereCitySource, options: {
126
+ lang: "en" | "ja";
127
+ maxKm: number;
128
+ }): HereCityHit[];
@@ -0,0 +1,107 @@
1
+ /**
2
+ * How far, in kilometres, a `here` marker looks for a city when `here-city` is set with no number.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { HERE_CITY_KM } from "@johnmorrisdotca/chikyu-earth/markers";
7
+ *
8
+ * console.log(HERE_CITY_KM); // 100
9
+ * ```
10
+ */
11
+ export const HERE_CITY_KM = 100;
12
+ /**
13
+ * The furthest `here-city` will look, in kilometres. A larger number is read as this.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { HERE_CITY_MAX_KM, readHereCity } from "@johnmorrisdotca/chikyu-earth/markers";
18
+ *
19
+ * console.log(readHereCity("999999") === HERE_CITY_MAX_KM);
20
+ * ```
21
+ */
22
+ export const HERE_CITY_MAX_KM = 20_000;
23
+ /**
24
+ * The kuni tiers a `here` marker's city is chosen from. A city of fewer than 100,000 people is in none of them.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { HERE_CITY_TIERS } from "@johnmorrisdotca/chikyu-earth/markers";
29
+ *
30
+ * console.log(HERE_CITY_TIERS.join(" "));
31
+ * ```
32
+ */
33
+ export const HERE_CITY_TIERS = ["capitals", "1m", "100k"];
34
+ /** The name to write, the same rule as the city names: the short Japanese name, then the Japanese name, else English. */
35
+ const cityText = (name, lang) => {
36
+ const ja = lang === "ja" ? (name.jaShort || name.ja) : undefined;
37
+ return ja || name.en;
38
+ };
39
+ /**
40
+ * Read the `here-city` attribute. Absent, `off`, or anything that is not a positive number of kilometres: off (`false`).
41
+ * Present with no value, or `on`: {@link HERE_CITY_KM}. A positive number: that many kilometres, at most {@link HERE_CITY_MAX_KM}.
42
+ *
43
+ * @param value - The attribute's text, or null when it is not set.
44
+ * @returns `false` when the marker keeps the page's label, or the kilometre limit.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { HERE_CITY_KM, readHereCity } from "@johnmorrisdotca/chikyu-earth/markers";
49
+ *
50
+ * console.log(readHereCity(null), readHereCity(""), readHereCity("40"), readHereCity("off"), HERE_CITY_KM);
51
+ * ```
52
+ */
53
+ export function readHereCity(value) {
54
+ if (value == null)
55
+ return false;
56
+ const text = value.trim().toLowerCase();
57
+ if (text === "" || text === "on")
58
+ return HERE_CITY_KM;
59
+ if (text === "off")
60
+ return false;
61
+ const km = Number(text);
62
+ if (!Number.isFinite(km) || km <= 0)
63
+ return false;
64
+ return Math.min(km, HERE_CITY_MAX_KM);
65
+ }
66
+ /**
67
+ * The city for each `here` place, nearest first within `maxKm`, named in `lang`. A favourite is left out. A place with no city inside the limit is left out, so the page's own label stays.
68
+ * The lookup is the source's: this adds none.
69
+ *
70
+ * @param places - The places, as the element holds them.
71
+ * @param source - A city list with `nearest` (kuni's `CitySet`).
72
+ * @param options - `lang` (`en` or `ja`) and `maxKm`.
73
+ * @returns One hit for each `here` place that has a city inside the limit, in the list's order.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * import { hereCityLabels } from "@johnmorrisdotca/chikyu-earth/markers";
78
+ *
79
+ * const paris = { id: "Q90", name: { en: "Paris", ja: "パリ" } };
80
+ * const source = {
81
+ * nearest(_point: { lat: number; lon: number }, options?: { maxKm?: number }) {
82
+ * return options?.maxKm !== undefined && options.maxKm < 5 ? null : { city: paris, km: 2 };
83
+ * },
84
+ * };
85
+ * const places = [{ lon: 2.35, lat: 48.86, kind: "here" as const }, { lon: 4.84, lat: 45.76, kind: "favourite" as const }];
86
+ * console.log(hereCityLabels(places, source, { lang: "en", maxKm: 100 })[0]?.label);
87
+ * console.log(hereCityLabels(places, source, { lang: "ja", maxKm: 100 })[0]?.label);
88
+ * console.log(hereCityLabels(places, source, { lang: "en", maxKm: 1 }).length);
89
+ * ```
90
+ */
91
+ export function hereCityLabels(places, source, options) {
92
+ if (!(options.maxKm > 0))
93
+ return [];
94
+ const out = [];
95
+ for (const [index, place] of places.entries()) {
96
+ if (place.kind !== "here")
97
+ continue;
98
+ const found = source.nearest({ lat: place.lat, lon: place.lon }, { maxKm: options.maxKm });
99
+ if (!found || !(found.km <= options.maxKm))
100
+ continue;
101
+ const label = cityText(found.city.name, options.lang).trim().slice(0, 80);
102
+ if (!label)
103
+ continue;
104
+ out.push({ index, id: found.city.id, label, km: found.km });
105
+ }
106
+ return out;
107
+ }
@@ -4,4 +4,5 @@ export { clusterPoints, type Cluster } from "./cluster.ts";
4
4
  export { placeLabels, type LabelItem, type Placement } from "./labels.ts";
5
5
  export type { GroupInfo, MarkerEventDetail, MarkerIcon, MarkerInput } from "./types.ts";
6
6
  export { cleanPlaces, groupCell, groupPlaces, layoutPlaces, MAX_PLACES, nearby, orthoView, PLACE_GROUP_PX, PLACE_LOOKS, readPlaceGroups, readPlaces, type Place, type PlaceGroup, type PlaceKind, type PlaceLabelSpot, type PlaceLayout, type PlaceLayoutOptions, type PlaceLook, type PlaceShape, type PlaceView, type SurfacePoint } from "./places.ts";
7
+ export { HERE_CITY_KM, HERE_CITY_MAX_KM, HERE_CITY_TIERS, hereCityLabels, readHereCity, type HereCityHit, type HereCitySource } from "./here-city.ts";
7
8
  export { PLACE_DOTS, PLACE_MARKS } from "./place-layer.ts";
@@ -5,4 +5,5 @@ export { project, projectAll, canvasRatio } from "./project.js";
5
5
  export { clusterPoints } from "./cluster.js";
6
6
  export { placeLabels } from "./labels.js";
7
7
  export { cleanPlaces, groupCell, groupPlaces, layoutPlaces, MAX_PLACES, nearby, orthoView, PLACE_GROUP_PX, PLACE_LOOKS, readPlaceGroups, readPlaces } from "./places.js";
8
+ export { HERE_CITY_KM, HERE_CITY_MAX_KM, HERE_CITY_TIERS, hereCityLabels, readHereCity } from "./here-city.js";
8
9
  export { PLACE_DOTS, PLACE_MARKS } from "./place-layer.js";
@@ -13,6 +13,7 @@ import { type PlaceSpriteData } from "../markers/place-sprites.ts";
13
13
  import { type MeteorState } from "../meteors/layer.ts";
14
14
  import { type BorderState } from "../borders/layer.ts";
15
15
  import { type GridState } from "../grid/layer.ts";
16
+ import { type RouteState } from "../route/layer.ts";
16
17
  export type { ThreeParts };
17
18
  type Three = ThreeParts;
18
19
  /**
@@ -96,6 +97,8 @@ export interface EarthModel {
96
97
  borders: BorderState;
97
98
  /** The meridians and parallels (src/grid/layer.ts): off unless the element switches them on. */
98
99
  grid: GridState;
100
+ /** A route between two places (src/route/layer.ts): off unless the element sets it. */
101
+ route: RouteState;
99
102
  }
100
103
  export interface EarthDeps {
101
104
  assets: AssetCache;
@@ -10,6 +10,7 @@ import { beginPlaceSprites, createPlaceSprites } from "../markers/place-sprites.
10
10
  import { createMeteorLayer, newMeteorState } from "../meteors/layer.js";
11
11
  import { createBorderLayer, newBorderState } from "../borders/layer.js";
12
12
  import { createGridLayer, newGridState } from "../grid/layer.js";
13
+ import { createRouteLayer, newRouteState } from "../route/layer.js";
13
14
  import { pointOnEarth } from "./tiles.js";
14
15
  import { paintMinute } from "../paint/buffer.js";
15
16
  import { createPaintTexture } from "../paint/texture.js";
@@ -48,6 +49,7 @@ export const newModel = () => ({
48
49
  bodyLabel: newBodyLabelState(),
49
50
  borders: newBorderState(),
50
51
  grid: newGridState(),
52
+ route: newRouteState(),
51
53
  });
52
54
  /**
53
55
  * The disc's radius in CSS pixels in a box of `width` x `height` at `zoom`: it fits the glow in the box at 1x.
@@ -199,6 +201,7 @@ export function createEarthItem(model, deps) {
199
201
  let borders = null;
200
202
  const placeRings = { sprites: null, tried: false };
201
203
  let gridLayer = null;
204
+ let routeLayer = null;
202
205
  return {
203
206
  scene,
204
207
  camera,
@@ -309,6 +312,16 @@ export function createEarthItem(model, deps) {
309
312
  }
310
313
  }
311
314
  gridLayer?.sync(radius);
315
+ if ((model.route.ends || routeLayer) && !routeLayer && !model.route.failed) {
316
+ try {
317
+ routeLayer = createRouteLayer(three, turned, model.route);
318
+ }
319
+ catch (error) {
320
+ model.route.failed = true;
321
+ console.warn(error instanceof Error ? error.message : error);
322
+ }
323
+ }
324
+ routeLayer?.sync();
312
325
  if (deps.paint) {
313
326
  const changed = deps.paint.step(model.time);
314
327
  paint.sync(deps.paint.on(), changed);
@@ -337,6 +350,7 @@ export function createEarthItem(model, deps) {
337
350
  borders?.dispose();
338
351
  placeRings.sprites?.dispose();
339
352
  gridLayer?.dispose();
353
+ routeLayer?.dispose();
340
354
  model.tiles = null;
341
355
  tiles.dispose();
342
356
  textures.dispose();