@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.
@@ -4,6 +4,7 @@ import { type CameraMode, type LightMode } from "./earth.ts";
4
4
  import { type PaintSpec } from "../paint/buffer.ts";
5
5
  import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/types.ts";
6
6
  import { type SatelliteStyle } from "../space/satellite-layer.ts";
7
+ import { type SatelliteOthers } from "../space/satellite-focus.ts";
7
8
  import type { Credit, DataSource } from "../data-door.ts";
8
9
  import { type BodyLabelSettings } from "./body-label.ts";
9
10
  import type { SkyKeepClear } from "../sky/keep-clear.ts";
@@ -12,6 +13,7 @@ import { type Place, type PlaceLook } from "../markers/places.ts";
12
13
  import { type CityNamesStyle } from "../cities/host.ts";
13
14
  import { type BorderSets } from "../borders/lines.ts";
14
15
  import type { BorderData, BorderStats } from "../borders/layer.ts";
16
+ import { type RouteLeg } from "../route.ts";
15
17
  import type { GridStats } from "../grid/layer.ts";
16
18
  import { type CountryNamesStats, type CountryNamesStyle } from "../country-names/host.ts";
17
19
  import { setSharedRenderer, setThreeLoader } from "./shared.ts";
@@ -192,6 +194,38 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
192
194
  */
193
195
  get places(): Place[];
194
196
  set places(value: readonly Place[]);
197
+ /**
198
+ * Name each `here` place with the nearest city (the attribute `here-city`). `false` (the default) leaves the page's label and loads nothing.
199
+ * `true` looks within 100 km (`HERE_CITY_KM`). A number is that limit in kilometres, at most 20,000 (`HERE_CITY_MAX_KM`); a city further away is not used, and the page's label stays.
200
+ * The cities are kuni's capitals, the other cities of a million and the others of 100,000, an optional peer loaded only when this is on and a `here` place is set. The name follows the page's language
201
+ * (the short Japanese name, then the Japanese name, else English). `places` is not changed: only the drawn name is. Nothing is drawn again at rest.
202
+ *
203
+ * @example
204
+ * ```ts no-run
205
+ * import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
206
+ *
207
+ * const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
208
+ * earth.hereCity = true;
209
+ * console.log(earth.hereCity); // 100
210
+ * earth.hereCity = false;
211
+ * ```
212
+ */
213
+ get hereCity(): false | number;
214
+ set hereCity(value: false | true | number);
215
+ /**
216
+ * 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, and it turns with the Earth.
217
+ * Setting the property writes the attribute. Nothing is drawn again at rest: the line is drawn with the picture, and only when the route or the view changes.
218
+ */
219
+ get route(): {
220
+ from: GeoPoint;
221
+ to: GeoPoint;
222
+ } | null;
223
+ set route(value: {
224
+ from: GeoPoint;
225
+ to: GeoPoint;
226
+ } | null);
227
+ /** The distance, bearings and flight-time estimate for `route`, or null when none is set. The flight time assumes 900 km/h. */
228
+ get routeInfo(): RouteLeg | null;
195
229
  /**
196
230
  * Turn the Earth so a place of `places` is in the middle, at a pace a reader can follow (at once with `smooth: false`, for a reader who asked for less motion, or before the picture is live); the zoom
197
231
  * and pan stay. The place is named by its `id`, or by its label in any case. The tilt is held to 90 degrees either way, so a place more than 90 degrees of latitude from `center` comes as near the middle
@@ -367,6 +401,13 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
367
401
  dots: number;
368
402
  omitted: number;
369
403
  };
404
+ /** The nearest city on a `here` marker (`here-city`): whether it is on, the kilometre limit (0 when off), whether kuni's cities have arrived, and whether that load is still going. */
405
+ hereCity: {
406
+ on: boolean;
407
+ maxKm: number;
408
+ loaded: boolean;
409
+ pending: boolean;
410
+ };
370
411
  /** The names of cities: whether `city-names` is set and the most it asks for, the Earth's radius on the screen, the tiers of kuni's cities that have arrived and how many cities, the names shown at the last draw and how many times the layer was drawn. */
371
412
  cityNames: {
372
413
  on: boolean;
@@ -381,6 +422,13 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
381
422
  borders: BorderStats;
382
423
  /** The grid: whether it was drawn at the last draw, whether every 15 degrees (else 30), its segments then, how many times its lines were made, and whether it could not be made. */
383
424
  grid: GridStats;
425
+ /** The route between two places: whether one is set, and its geodesic distance, great-circle distance and flight time at 900 km/h. */
426
+ route: {
427
+ on: boolean;
428
+ kilometres: number;
429
+ greatCircleKm: number;
430
+ flightHours: number;
431
+ };
384
432
  /** The names of countries: whether `country-names` is set and the most it asks for, the countries loaded, the names shown at the last draw, how many times they were laid out, and whether the outlines could not be loaded. */
385
433
  countryNames: CountryNamesStats;
386
434
  };
@@ -415,12 +463,36 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
415
463
  setSatellites(group: string, satellites: Satellites | null, style?: Partial<SatelliteStyle>): void;
416
464
  /** Show or hide a group without losing it. */
417
465
  showSatellites(group: string, on: boolean): void;
418
- /** The groups now set, with how many satellites each holds and whether it is shown. */
466
+ /**
467
+ * The groups now set. `count` is how many satellites the group holds, `visible` is the shown state from `showSatellites` (a focus does not change it), `placed` is how many the last draw placed (0 when the group is not drawn) and `emphasis` is how a focus treats it: `focus`, `dim`, `hidden` or `plain` (no focus).
468
+ */
419
469
  get satelliteGroups(): {
420
470
  name: string;
421
471
  count: number;
422
472
  visible: boolean;
473
+ placed: number;
474
+ emphasis: "focus" | "dim" | "hidden" | "plain";
423
475
  }[];
476
+ /** The group `focusSatelliteGroup` is showing on its own, or `null`. */
477
+ get focusedSatelliteGroup(): string | null;
478
+ /**
479
+ * Show one group on its own. The others are drawn dimmer (`others: "dim"`, the default, through the same dimming an old element set uses) or not drawn (`"hide"`). `frame` (true by default) pulls the camera back, by this view's own zoom, until the group's orbits fit: the distance is the greatest apogee of the group, from each satellite's mean motion and eccentricity, and it stops at 8 Earth radii. `null` puts every group back to the shown state it had, and puts the camera back when it was moved. A name that `setSatellites` has not set returns `{ ok: false, reason: "not-set" }` and changes nothing. It does not throw. When the choice changes, `chikyu-satellite-focus` is sent with `{ group, count }`.
480
+ *
481
+ * @param name - The group's name, or `null` to clear the focus.
482
+ * @param options - `others` and `frame`.
483
+ * @returns `{ ok: true, group, count }` when the group is set (`group` is `null` and `count` is 0 when cleared). `{ ok: false, reason: "not-set" }` when it is not.
484
+ */
485
+ focusSatelliteGroup(name: string | null, options?: {
486
+ others?: SatelliteOthers;
487
+ frame?: boolean;
488
+ }): {
489
+ ok: true;
490
+ group: string | null;
491
+ count: number;
492
+ } | {
493
+ ok: false;
494
+ reason: "not-set";
495
+ };
424
496
  /** Mark one satellite: a larger ring round it and its orbit drawn. `null` lets it go. */
425
497
  selectSatellite(ref: SatelliteRef | null): void;
426
498
  /** The satellite marked by `selectSatellite` or by a press on it, if any. */
@@ -9,6 +9,7 @@ import { NOTES_STYLE, setAirNote } from "./air-note.js";
9
9
  import { cameraCentre, createEarthItem, discRadius, lookAt, newModel } from "./earth.js";
10
10
  import { createPaintState, paintedGround, paintedPeriod } from "../paint/buffer.js";
11
11
  import { MAX_ORBIT_GROUP } from "../space/satellite-layer.js";
12
+ import { applySatelliteFocus, satelliteEmphasis, satelliteGroupRows, shellRadiusOf, zoomForOrthographicShell } from "../space/satellite-focus.js";
12
13
  import { readMeteorStrength } from "../meteors/strength.js";
13
14
  import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
14
15
  import { createDoorHost } from "../door/host.js";
@@ -17,6 +18,8 @@ import { ownCredit } from "../door/own.js";
17
18
  import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "./body-label.js";
18
19
  import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
19
20
  import { cleanPlaces, orthoView, readPlaceGroups, readPlaces } from "../markers/places.js";
21
+ import { readHereCity } from "../markers/here-city.js";
22
+ import { createHereCity } from "../markers/here-city-host.js";
20
23
  import { createPlaceLayer, PLACE_STYLE, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
21
24
  import { aimAt, findPlace, glideView } from "../markers/go-to-place.js";
22
25
  import { subsolarPoint } from "./sun.js";
@@ -24,6 +27,8 @@ import { CITY_NAMES_ATTRIBUTES, CITY_NAMES_STYLE, createCityHost } from "../citi
24
27
  import { project } from "../markers/project.js";
25
28
  import { BORDER_ATTRIBUTES, readBorders } from "../borders/lines.js";
26
29
  import { GRID_ATTRIBUTES, readGrid } from "../grid/lines.js";
30
+ import { readRoute, routeLeg, routeText } from "../route.js";
31
+ import { applyRoute } from "../route/layer.js";
27
32
  import { COUNTRY_NAMES_ATTRIBUTES } from "../country-names/geometry.js";
28
33
  import { COUNTRY_NAMES_STYLE, createCountryHost } from "../country-names/host.js";
29
34
  import { createGate, frameCap } from "./gate.js";
@@ -154,7 +159,7 @@ export const readTime = (value) => {
154
159
  * ```
155
160
  */
156
161
  export class ChikyuEarthRealistic extends HTMLElement {
157
- static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "satellite-tint"];
162
+ static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "satellite-tint"];
158
163
  #model = newModel();
159
164
  #paint = createPaintState();
160
165
  #mode = "now";
@@ -187,12 +192,16 @@ export class ChikyuEarthRealistic extends HTMLElement {
187
192
  #countriesStyle = {};
188
193
  #listeners = new Set();
189
194
  #placeLayer;
195
+ /** The nearest city's name on a `here` marker (`here-city`), loaded only when that is on. */
196
+ #here;
190
197
  /** Whether the page has been told that places in sight were left undrawn. */
191
198
  #placesLost = { told: false };
192
199
  #placeList = [];
193
200
  /** Counts the turns to a place, so a new one stops the one before. */
194
201
  #placeGlide = 0;
195
202
  #hands;
203
+ /** The view from before a satellite group was framed, put back when the focus is cleared. */
204
+ #focusView = null;
196
205
  #reach = null;
197
206
  /** The page has set a `speed` since the element came into the page: for a reader who prefers reduced motion, that is the Play that lets meteors start. */
198
207
  #played = false;
@@ -246,8 +255,9 @@ export class ChikyuEarthRealistic extends HTMLElement {
246
255
  this.#sky.setStyle(this.#skyStyle);
247
256
  this.#sky.setKeepClear(this.#keepClear);
248
257
  this.#placeLayer = createPlaceLayer(root.getElementById("places"));
258
+ this.#here = this.#openHereCity();
249
259
  this.#placeList = readPlaces(this.getAttribute("places"));
250
- this.#placeLayer.set(this.#placeList);
260
+ this.#placeLayer.set(this.#here.named(this.#placeList));
251
261
  this.#placeLayer.look = readPlaceLook(this.getAttribute("places-look"));
252
262
  this.#placeLayer.grouping = readPlaceGroups(this.getAttribute("place-groups"));
253
263
  this.#cities = createCityHost({
@@ -388,6 +398,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
388
398
  this.#taken = undefined;
389
399
  this.#sky?.dispose();
390
400
  this.#sky = undefined;
401
+ this.#here?.dispose();
402
+ this.#here = undefined;
391
403
  this.#placeLayer?.dispose();
392
404
  this.#placeLayer = undefined;
393
405
  this.#cities?.dispose();
@@ -437,6 +449,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
437
449
  this.#sky?.refresh();
438
450
  this.#cities?.refresh();
439
451
  this.#countries?.refresh();
452
+ this.#here?.refresh();
440
453
  }
441
454
  }
442
455
  else if (BODY_LABEL_ATTRIBUTES.includes(name))
@@ -445,8 +458,11 @@ export class ChikyuEarthRealistic extends HTMLElement {
445
458
  this.#sky?.refresh();
446
459
  else if (name === "places") {
447
460
  this.#placeList = readPlaces(value);
448
- this.#placeLayer?.set(this.#placeList);
449
- this.#gate?.soon();
461
+ this.#applyPlaces();
462
+ }
463
+ else if (name === "here-city") {
464
+ this.#here?.setLimit(readHereCity(value));
465
+ this.#applyPlaces();
450
466
  }
451
467
  else if (name === "places-look" && this.#placeLayer) {
452
468
  this.#placeLayer.look = readPlaceLook(value);
@@ -456,6 +472,10 @@ export class ChikyuEarthRealistic extends HTMLElement {
456
472
  this.#placeLayer.grouping = readPlaceGroups(value);
457
473
  this.#gate?.soon();
458
474
  }
475
+ else if (name === "route") {
476
+ if (applyRoute(this.#model.route, readRoute(value)))
477
+ this.#gate?.soon();
478
+ }
459
479
  else if (CITY_NAMES_ATTRIBUTES.includes(name))
460
480
  this.#cities?.refresh();
461
481
  else if (name === "borders") {
@@ -604,6 +624,77 @@ export class ChikyuEarthRealistic extends HTMLElement {
604
624
  else
605
625
  this.setAttribute("places", JSON.stringify(clean));
606
626
  }
627
+ /**
628
+ * Name each `here` place with the nearest city (the attribute `here-city`). `false` (the default) leaves the page's label and loads nothing.
629
+ * `true` looks within 100 km (`HERE_CITY_KM`). A number is that limit in kilometres, at most 20,000 (`HERE_CITY_MAX_KM`); a city further away is not used, and the page's label stays.
630
+ * The cities are kuni's capitals, the other cities of a million and the others of 100,000, an optional peer loaded only when this is on and a `here` place is set. The name follows the page's language
631
+ * (the short Japanese name, then the Japanese name, else English). `places` is not changed: only the drawn name is. Nothing is drawn again at rest.
632
+ *
633
+ * @example
634
+ * ```ts no-run
635
+ * import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
636
+ *
637
+ * const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
638
+ * earth.hereCity = true;
639
+ * console.log(earth.hereCity); // 100
640
+ * earth.hereCity = false;
641
+ * ```
642
+ */
643
+ get hereCity() {
644
+ return readHereCity(this.getAttribute("here-city"));
645
+ }
646
+ set hereCity(value) {
647
+ if (value === true)
648
+ this.setAttribute("here-city", "");
649
+ else if (value === false)
650
+ this.removeAttribute("here-city");
651
+ else {
652
+ const km = readHereCity(String(value));
653
+ if (km === false)
654
+ this.removeAttribute("here-city");
655
+ else
656
+ this.setAttribute("here-city", String(km));
657
+ }
658
+ }
659
+ /** The cities for `here-city`, asked for only when the attribute is on. */
660
+ #openHereCity() {
661
+ const host = createHereCity({
662
+ language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
663
+ onChange: () => {
664
+ if (this.isConnected)
665
+ this.#applyPlaces();
666
+ },
667
+ onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-here-city-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
668
+ });
669
+ host.setLimit(readHereCity(this.getAttribute("here-city")));
670
+ return host;
671
+ }
672
+ /** Hand the places to the layer, with a here marker's city name when one is known, and draw once. */
673
+ #applyPlaces() {
674
+ const layer = this.#placeLayer;
675
+ if (!layer)
676
+ return;
677
+ layer.set(this.#here?.named(this.#placeList) ?? this.#placeList);
678
+ this.#gate?.soon();
679
+ }
680
+ /**
681
+ * 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, and it turns with the Earth.
682
+ * Setting the property writes the attribute. Nothing is drawn again at rest: the line is drawn with the picture, and only when the route or the view changes.
683
+ */
684
+ get route() {
685
+ return readRoute(this.getAttribute("route"));
686
+ }
687
+ set route(value) {
688
+ if (!value)
689
+ this.removeAttribute("route");
690
+ else
691
+ this.setAttribute("route", routeText(value));
692
+ }
693
+ /** The distance, bearings and flight-time estimate for `route`, or null when none is set. The flight time assumes 900 km/h. */
694
+ get routeInfo() {
695
+ const route = this.route;
696
+ return route ? routeLeg(route.from, route.to) : null;
697
+ }
607
698
  /**
608
699
  * Turn the Earth so a place of `places` is in the middle, at a pace a reader can follow (at once with `smooth: false`, for a reader who asked for less motion, or before the picture is live); the zoom
609
700
  * and pan stay. The place is named by its `id`, or by its label in any case. The tilt is held to 90 degrees either way, so a place more than 90 degrees of latitude from `center` comes as near the middle
@@ -1000,9 +1091,11 @@ export class ChikyuEarthRealistic extends HTMLElement {
1000
1091
  bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
1001
1092
  sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, pick: null, hover: null, constellations: 0, culture: "iau", renders: 0, lang: "", stars: [] },
1002
1093
  places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 }) },
1094
+ hereCity: this.#here?.stats ?? { on: false, maxKm: 0, loaded: false, pending: false },
1003
1095
  cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
1004
1096
  borders: { ...this.#model.borders.stats, shown: { ...this.#model.borders.stats.shown }, loaded: [...this.#model.borders.stats.loaded] },
1005
1097
  grid: { ...this.#model.grid.stats },
1098
+ route: { ...this.#model.route.stats },
1006
1099
  countryNames: this.#countries?.stats ?? { on: false, max: 0, countries: 0, names: 0, renders: 0, failed: false },
1007
1100
  };
1008
1101
  }
@@ -1071,6 +1164,11 @@ export class ChikyuEarthRealistic extends HTMLElement {
1071
1164
  groups.delete(group);
1072
1165
  if (this.#model.satellites.selected?.group === group)
1073
1166
  this.#model.satellites.selected = null;
1167
+ if (this.#model.satellites.focus?.name === group) {
1168
+ this.#model.satellites.focus = null;
1169
+ this.#restoreFocusView();
1170
+ this.dispatchEvent(new CustomEvent("chikyu-satellite-focus", { detail: { group: null, count: 0 }, bubbles: true, composed: true }));
1171
+ }
1074
1172
  }
1075
1173
  else {
1076
1174
  const was = groups.get(group);
@@ -1095,9 +1193,66 @@ export class ChikyuEarthRealistic extends HTMLElement {
1095
1193
  this.#startTick();
1096
1194
  this.#gate?.soon();
1097
1195
  }
1098
- /** The groups now set, with how many satellites each holds and whether it is shown. */
1196
+ /**
1197
+ * The groups now set. `count` is how many satellites the group holds, `visible` is the shown state from `showSatellites` (a focus does not change it), `placed` is how many the last draw placed (0 when the group is not drawn) and `emphasis` is how a focus treats it: `focus`, `dim`, `hidden` or `plain` (no focus).
1198
+ */
1099
1199
  get satelliteGroups() {
1100
- return [...this.#model.satellites.groups].map(([name, group]) => ({ name, count: group.satellites.count, visible: group.visible }));
1200
+ return satelliteGroupRows(this.#model.satellites);
1201
+ }
1202
+ /** The group `focusSatelliteGroup` is showing on its own, or `null`. */
1203
+ get focusedSatelliteGroup() {
1204
+ return this.#model.satellites.focus?.name ?? null;
1205
+ }
1206
+ /**
1207
+ * Show one group on its own. The others are drawn dimmer (`others: "dim"`, the default, through the same dimming an old element set uses) or not drawn (`"hide"`). `frame` (true by default) pulls the camera back, by this view's own zoom, until the group's orbits fit: the distance is the greatest apogee of the group, from each satellite's mean motion and eccentricity, and it stops at 8 Earth radii. `null` puts every group back to the shown state it had, and puts the camera back when it was moved. A name that `setSatellites` has not set returns `{ ok: false, reason: "not-set" }` and changes nothing. It does not throw. When the choice changes, `chikyu-satellite-focus` is sent with `{ group, count }`.
1208
+ *
1209
+ * @param name - The group's name, or `null` to clear the focus.
1210
+ * @param options - `others` and `frame`.
1211
+ * @returns `{ ok: true, group, count }` when the group is set (`group` is `null` and `count` is 0 when cleared). `{ ok: false, reason: "not-set" }` when it is not.
1212
+ */
1213
+ focusSatelliteGroup(name, options = {}) {
1214
+ const answer = applySatelliteFocus(this.#model.satellites, name, options);
1215
+ if (!answer.ok || answer.group === undefined || answer.count === undefined)
1216
+ return { ok: false, reason: "not-set" };
1217
+ if (answer.group === null)
1218
+ this.#restoreFocusView();
1219
+ else if (options.frame !== false)
1220
+ this.#frameSatelliteShell(answer.group);
1221
+ if (answer.changed)
1222
+ this.dispatchEvent(new CustomEvent("chikyu-satellite-focus", { detail: { group: answer.group, count: answer.count }, bubbles: true, composed: true }));
1223
+ // which groups are drawn decides how often time is drawn, so the next step is worked out again, as for `showSatellites`
1224
+ this.#startTick();
1225
+ this.#gate?.soon();
1226
+ return { ok: true, group: answer.group, count: answer.count };
1227
+ }
1228
+ /** The view's own zoom, far enough that the group's shell fills the picture, with the Earth back in the middle. */
1229
+ #frameSatelliteShell(name) {
1230
+ const group = this.#model.satellites.groups.get(name);
1231
+ if (!group)
1232
+ return;
1233
+ const box = this.getBoundingClientRect();
1234
+ if (box.width < 2 || box.height < 2)
1235
+ return;
1236
+ if (!this.#focusView)
1237
+ this.#focusView = { ...this.#model.view };
1238
+ const zoom = zoomForOrthographicShell(shellRadiusOf(group.satellites.sets), box.width, box.height, LIMITS.zoomMin, LIMITS.zoomMax);
1239
+ this.#applyCamera({ ...this.#model.view, zoom, panX: 0, panY: 0 });
1240
+ }
1241
+ /** Put back the view from before the shell was framed. */
1242
+ #restoreFocusView() {
1243
+ const saved = this.#focusView;
1244
+ this.#focusView = null;
1245
+ if (saved)
1246
+ this.#applyCamera(saved);
1247
+ }
1248
+ /** Hand a camera to the controls that are driving the view, or to the view itself when those are not there yet. */
1249
+ #applyCamera(view) {
1250
+ const bar = this.hasAttribute("data-kazoku-bar") && this.id ? this.getRootNode().querySelector?.(`kazoku-view-controls[for="${CSS.escape(this.id)}"]`) : null;
1251
+ const controls = (bar ? Reflect.get(bar, "controller") : undefined) ?? this.#hands?.controller;
1252
+ if (controls)
1253
+ controls.set(view, true, "satellites");
1254
+ else
1255
+ this.setView(view, true);
1101
1256
  }
1102
1257
  /** Mark one satellite: a larger ring round it and its orbit drawn. `null` lets it go. */
1103
1258
  selectSatellite(ref) {
@@ -1176,8 +1331,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
1176
1331
  }
1177
1332
  /** Is anything on show that moves faster than the Earth turns: a group of satellites, including above the interpolation limit where they are drawn as streaks? */
1178
1333
  #satellitesMoving() {
1179
- for (const group of this.#model.satellites.groups.values())
1180
- if (group.visible && group.satellites.count > 0)
1334
+ for (const [name, group] of this.#model.satellites.groups)
1335
+ if (satelliteEmphasis(name, group.visible, this.#model.satellites.focus).drawn && group.satellites.count > 0)
1181
1336
  return true;
1182
1337
  return false;
1183
1338
  }
@@ -0,0 +1,32 @@
1
+ import type * as THREE from "three";
2
+ import type { ThreeParts } from "../realistic/textures.ts";
3
+ import type { GeoPoint } from "../types.ts";
4
+ export interface RouteStats {
5
+ on: boolean;
6
+ kilometres: number;
7
+ greatCircleKm: number;
8
+ flightHours: number;
9
+ }
10
+ export interface RouteState {
11
+ ends: {
12
+ from: GeoPoint;
13
+ to: GeoPoint;
14
+ } | null;
15
+ version: number;
16
+ failed: boolean;
17
+ stats: RouteStats;
18
+ }
19
+ export declare const newRouteState: () => RouteState;
20
+ /** Put a route on the model. Returns false when it did not change, so the element does not ask for a frame. */
21
+ export declare function applyRoute(state: RouteState, ends: {
22
+ from: GeoPoint;
23
+ to: GeoPoint;
24
+ } | null): boolean;
25
+ export interface RouteLayer {
26
+ sync(): void;
27
+ dispose(): void;
28
+ }
29
+ /**
30
+ * The route under `parent` (the group that turns with the Earth). Needs `LineSegments`, as the grid does.
31
+ */
32
+ export declare function createRouteLayer(three: ThreeParts, parent: THREE.Object3D, state: RouteState): RouteLayer;
@@ -0,0 +1,74 @@
1
+ import { routeLeg, routePoints } from "../route.js";
2
+ /** How far above the ground the line sits, in Earth radii: over the grid and the sphere's facets. */
3
+ const ROUTE_RADIUS = 1.003;
4
+ const ROUTE_COLOUR = 0x7df9ff;
5
+ export const newRouteState = () => ({ ends: null, version: 0, failed: false, stats: { on: false, kilometres: 0, greatCircleKm: 0, flightHours: 0 } });
6
+ const same = (a, b) => a === b || (a !== null && b !== null && a.from.lon === b.from.lon && a.from.lat === b.from.lat && a.to.lon === b.to.lon && a.to.lat === b.to.lat);
7
+ /** Put a route on the model. Returns false when it did not change, so the element does not ask for a frame. */
8
+ export function applyRoute(state, ends) {
9
+ if (same(state.ends, ends))
10
+ return false;
11
+ state.ends = ends;
12
+ state.version += 1;
13
+ const leg = ends ? routeLeg(ends.from, ends.to) : null;
14
+ state.stats = { on: leg !== null, kilometres: leg?.kilometres ?? 0, greatCircleKm: leg?.greatCircleKm ?? 0, flightHours: leg?.flightHours ?? 0 };
15
+ return true;
16
+ }
17
+ const positionsOf = (from, to) => {
18
+ const points = routePoints(from, to, 96);
19
+ if (points.length < 2)
20
+ return null;
21
+ const out = new Float32Array((points.length - 1) * 6);
22
+ const put = (at, place) => {
23
+ const lat = (place.lat * Math.PI) / 180;
24
+ const lon = (place.lon * Math.PI) / 180;
25
+ const c = Math.cos(lat) * ROUTE_RADIUS;
26
+ out[at] = c * Math.sin(lon);
27
+ out[at + 1] = Math.sin(lat) * ROUTE_RADIUS;
28
+ out[at + 2] = c * Math.cos(lon);
29
+ };
30
+ for (let i = 0; i < points.length - 1; i += 1) {
31
+ put(i * 6, points[i]);
32
+ put(i * 6 + 3, points[i + 1]);
33
+ }
34
+ return out;
35
+ };
36
+ /**
37
+ * The route under `parent` (the group that turns with the Earth). Needs `LineSegments`, as the grid does.
38
+ */
39
+ export function createRouteLayer(three, parent, state) {
40
+ const Lines = three.LineSegments;
41
+ if (!Lines)
42
+ throw new Error("the three.js handed over has no LineSegments, which the route needs");
43
+ const geometry = new three.BufferGeometry();
44
+ const material = new three.LineBasicMaterial({ color: ROUTE_COLOUR, transparent: true, opacity: 0.95, depthWrite: false });
45
+ const line = new Lines(geometry, material);
46
+ line.visible = false;
47
+ line.frustumCulled = false;
48
+ line.renderOrder = 2;
49
+ parent.add(line);
50
+ let built = -1;
51
+ return {
52
+ sync() {
53
+ if (built === state.version)
54
+ return;
55
+ built = state.version;
56
+ const ends = state.ends;
57
+ const positions = ends ? positionsOf(ends.from, ends.to) : null;
58
+ if (!positions) {
59
+ line.visible = false;
60
+ return;
61
+ }
62
+ // let the renderer free the buffer of the line it had, so changing the route leaves the GPU objects as they were
63
+ geometry.dispose();
64
+ geometry.setAttribute("position", new three.BufferAttribute(positions, 3));
65
+ geometry.computeBoundingSphere();
66
+ line.visible = true;
67
+ },
68
+ dispose() {
69
+ parent.remove(line);
70
+ geometry.dispose();
71
+ material.dispose();
72
+ },
73
+ };
74
+ }