@johnmorrisdotca/chikyu-earth 0.60.2 → 0.62.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.
@@ -17,6 +17,7 @@ import { setThreeLoader } from "../realistic/shared.ts";
17
17
  import type { LightMode } from "../realistic/earth.ts";
18
18
  import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/types.ts";
19
19
  import type { SatelliteHistory } from "../satellites/history.ts";
20
+ import { type FlyPhase } from "./fly.ts";
20
21
  import { type PlanetName } from "./ephemeris.ts";
21
22
  import { type SatelliteScreen, type SatelliteStyle } from "./satellite-layer.ts";
22
23
  import { type SatelliteOthers } from "./satellite-focus.ts";
@@ -162,6 +163,60 @@ export interface ObserveOptions {
162
163
  /** Glide to the view (true when left out); false, or a reader who asked for reduced motion, jumps. */
163
164
  smooth?: boolean;
164
165
  }
166
+ /**
167
+ * The options of `flyTo`.
168
+ *
169
+ * @example
170
+ * ```ts no-run
171
+ * import type { FlyOptions } from "@johnmorrisdotca/chikyu-earth/space/element";
172
+ *
173
+ * const options: FlyOptions = { height: 30, phase: "both" };
174
+ * console.log(options.height);
175
+ * ```
176
+ */
177
+ export interface FlyOptions {
178
+ /** The height to come down to, in kilometres above the ground (`FLY_HEIGHT_KM`, 30, when left out; never under `FLY_MIN_KM`, 15). `across` keeps the height it has. */
179
+ height?: number;
180
+ /** `across`, `down` or `both` (the default): see `FlyPhase`. */
181
+ phase?: FlyPhase;
182
+ /** Fly (true when left out); false, a reader who asked for reduced motion, or a picture that is not live yet, jumps there. */
183
+ smooth?: boolean;
184
+ /** Ends the move where it is, as a hand on the view does. */
185
+ signal?: AbortSignal;
186
+ }
187
+ /**
188
+ * How a fly-to ended, as `flyTo` gives it and `chikyu-fly-end` sends it: `arrived`, `redirected` (a new `flyTo` or `goToPlace` took it over, carrying its speed on), or `stopped` (a hand on the view, the
189
+ * signal, a ride, or the element leaving the page); the place, the phase, the camera's height then, and what held the descent up (`held`: `no-finer` where no finer picture lies under the place,
190
+ * `zoom-max` at a `zoom-max` the page set, else `null`).
191
+ *
192
+ * @example
193
+ * ```ts no-run
194
+ * import type { FlyEnd } from "@johnmorrisdotca/chikyu-earth/space/element";
195
+ *
196
+ * const say = (end: FlyEnd): string => `${end.reason} at ${Math.round(end.heightKm)} km`;
197
+ * console.log(typeof say);
198
+ * ```
199
+ */
200
+ export interface FlyEnd {
201
+ reason: "arrived" | "redirected" | "stopped";
202
+ lon: number;
203
+ lat: number;
204
+ phase: FlyPhase;
205
+ heightKm: number;
206
+ held: FlyHeld;
207
+ }
208
+ /**
209
+ * What held a descent above the height asked for: `no-finer` (no finer picture under the place: `FLY_FLOOR_KM`), `zoom-max` (the page's own `zoom-max`), or `null`.
210
+ *
211
+ * @example
212
+ * ```ts no-run
213
+ * import type { FlyHeld } from "@johnmorrisdotca/chikyu-earth/space/element";
214
+ *
215
+ * const held: FlyHeld = "no-finer";
216
+ * console.log(held);
217
+ * ```
218
+ */
219
+ export type FlyHeld = "no-finer" | "zoom-max" | null;
165
220
  /**
166
221
  * What the camera is riding along with now: the body or satellite, how (`from`, `follow` or `above`), where it looks, the facing it looks round from (`null` when none was chosen), and the distance kept for a satellite.
167
222
  *
@@ -335,7 +390,8 @@ export declare class ChikyuSpace extends HTMLElement {
335
390
  * is a ring on the ground, all of them one draw call, and places that crowd are gathered into one ring with their count. They turn with the Earth, are hidden on its far side, are dimmer on its night side
336
391
  * and keep their size in pixels at any zoom. Names never overlap one another or the bodies' names; one with no room is left out. The element stores nothing and sends nothing: the page hands the places
337
392
  * over and keeps them where it likes. Setting the property writes the attribute; at most `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight
338
- * and for a reader who asked for less motion.
393
+ * and for a reader who asked for less motion. A place may also have a `layer` (shown or hidden with `place-layers`), a `size` (`small`), a `look` of its own (over `places-look`) and a `namePriority` (`low` lays
394
+ * its name after the cities' names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`.
339
395
  */
340
396
  get places(): Place[];
341
397
  set places(value: readonly Place[]);
@@ -374,7 +430,8 @@ export declare class ChikyuSpace extends HTMLElement {
374
430
  /**
375
431
  * Turn the view 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 stays.
376
432
  * The place is named by its `id`, or by its label in any case. The camera must be looking at the Earth: while it rides along or looks at another body nothing moves. The tilt is held to 90 degrees either
377
- * way, so a place more than 90 degrees of latitude from `center` comes as near the middle as that allows.
433
+ * way, so a place more than 90 degrees of latitude from `center` comes as near the middle as that allows. A new `goToPlace` or `flyTo` while it turns does not stop it: the turn keeps its speed and
434
+ * the way it is going and curves to the new place. A hand on the view ends it where it is.
378
435
  *
379
436
  * @param text - The place's id or label.
380
437
  * @param options - `smooth` (true by default).
@@ -383,6 +440,23 @@ export declare class ChikyuSpace extends HTMLElement {
383
440
  goToPlace(text: string, options?: {
384
441
  smooth?: boolean;
385
442
  }): Promise<Place | undefined>;
443
+ /**
444
+ * Fly the camera to a place: across, the Earth turns under the camera at the height it has until the place is below (along a great circle, eased), then down, a descent to `height` kilometres over
445
+ * it (30 by default). `phase` asks for one part alone, so a page can take a reader there one press at a time. A new `flyTo` or `goToPlace` while one is moving does not stop it: the camera keeps its
446
+ * speed and the way it is going and curves smoothly into the new move, and a descent cut short slows to rest without turning back before the new move goes across. A hand on the view (a drag, a pinch,
447
+ * the wheel, a key) or `signal` ends it where it is; a reader who asked for reduced motion, `smooth: false` or a picture that is not live yet goes there at once. The controls' own turn (Auto-turn) is
448
+ * paused, so the place stays below.
449
+ *
450
+ * The descent comes all the way down only where finer pictures lie under the place (`tiles-finer`, over land from 60 degrees south to 80 degrees north); elsewhere it stops at `FLY_FLOOR_KM` (400 km), and
451
+ * at a `zoom-max` the page set, and says so in `held` and `stats.fly`. Once a fly-to has come below about 320 km the zoom reaches as low as it came. The camera must be looking at the Earth: while it
452
+ * rides along or looks at another body nothing moves. `chikyu-fly-start` is sent when it starts, with `{ lon, lat, phase, heightKm, held }`, and `chikyu-fly-end` when it ends, with what it resolves to.
453
+ *
454
+ * @param lat - Degrees north.
455
+ * @param lon - Degrees east.
456
+ * @param options - `height`, `phase`, `smooth` and `signal` (`FlyOptions`).
457
+ * @returns How it ended, once it has; `undefined` when it cannot fly (a latitude or longitude that is not a number, or the camera not looking at the Earth).
458
+ */
459
+ flyTo(lat: number, lon: number, options?: FlyOptions): Promise<FlyEnd | undefined>;
386
460
  /**
387
461
  * Whether places that crowd are gathered into one ring with their count (the attribute `place-groups`): on by default, `off` leaves every place its own ring. Setting the property writes the attribute.
388
462
  *
@@ -399,6 +473,39 @@ export declare class ChikyuSpace extends HTMLElement {
399
473
  */
400
474
  get placeGroups(): boolean;
401
475
  set placeGroups(value: boolean);
476
+ /**
477
+ * Which layers of places are shown (the attribute `place-layers`, a JSON object of a layer's name to true or false): a place whose `layer` is named `false` is left out, and so is its name; any other place, and any layer not
478
+ * named, is shown. The page hands over every place once and switches the layers, instead of building a list for each switch. Setting the property writes the attribute; an empty object takes it away.
479
+ * `stats.places.hidden` counts the places left out.
480
+ *
481
+ * @example
482
+ * ```ts no-run
483
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
484
+ *
485
+ * const space = document.querySelector("chikyu-space") as ChikyuSpace;
486
+ * space.placeLayers = { harbours: false };
487
+ * space.getAttribute("place-layers"); // '{"harbours":false}'
488
+ * space.setPlaceLayer("harbours", true);
489
+ * space.placeLayers; // { harbours: true }
490
+ * ```
491
+ */
492
+ get placeLayers(): Record<string, boolean>;
493
+ set placeLayers(value: Readonly<Record<string, boolean>>);
494
+ /**
495
+ * Show or hide one layer of places, leaving the others as they are: the same as setting `placeLayers` with that layer changed.
496
+ *
497
+ * @param name - The layer's name, as in a place's `layer`.
498
+ * @param shown - Whether its places are shown.
499
+ *
500
+ * @example
501
+ * ```ts no-run
502
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
503
+ *
504
+ * const space = document.querySelector("chikyu-space") as ChikyuSpace;
505
+ * space.setPlaceLayer("airports", false);
506
+ * ```
507
+ */
508
+ setPlaceLayer(name: string, shown: boolean): void;
402
509
  /** How the places are drawn (the attribute `places-look`): `beam` (a light rising out of the ground with a ring at its foot, the default), `pin` (a thin stick with a round head) or `ring` (only the ring on the ground). */
403
510
  get placesLook(): PlaceLook;
404
511
  set placesLook(value: PlaceLook);
@@ -1029,6 +1136,8 @@ export declare class ChikyuSpace extends HTMLElement {
1029
1136
  mix: number;
1030
1137
  fading: boolean;
1031
1138
  };
1139
+ /** The share of the clouds shown at the last draw, 1 to 0: they give way to the ground as the cloud picture's texels grow past a few device pixels (`cloud-fade`). In the space view it is the share at the nearest ground (the point the map tiles' level is chosen for); the far ground and the horizon keep more, as each fragment is faded by its own distance. */
1140
+ cloudFade: number;
1032
1141
  /** The page's paths: asked for, drawn (with the chosen satellite's own), left out over the cap of 16, unmatched, whether the chosen satellite's own orbit is drawn, draw calls they took at the last draw (0 or 1), the path under the mouse and the `chikyu-path-click` events sent. */
1033
1142
  paths: PathStats;
1034
1143
  ride: {
@@ -1130,6 +1239,7 @@ export declare class ChikyuSpace extends HTMLElement {
1130
1239
  */
1131
1240
  places: {
1132
1241
  places: number;
1242
+ hidden: number;
1133
1243
  shown: number;
1134
1244
  labels: number;
1135
1245
  renders: number;
@@ -1175,6 +1285,18 @@ export declare class ChikyuSpace extends HTMLElement {
1175
1285
  countryNames: CountryNamesStats;
1176
1286
  /** The names of oceans, seas and continents: whether `sea-names` is on, the Earth's radius on the screen, the names shown at the last draw, and how many times the layer was laid out. */
1177
1287
  seaNames: SeaNamesStats;
1288
+ /**
1289
+ * The fly-to (`flyTo`, and `goToPlace`'s turn): whether one is moving and in which part, the camera's height above the ground in kilometres while it looks at the Earth (`null` otherwise), what held
1290
+ * the last descent up (`held`, as in `FlyEnd`), and how many moves have started and how many were taken over by a new one.
1291
+ */
1292
+ fly: {
1293
+ flying: boolean;
1294
+ phase: "across" | "down" | null;
1295
+ heightKm: number | null;
1296
+ held: FlyHeld;
1297
+ moves: number;
1298
+ redirects: number;
1299
+ };
1178
1300
  };
1179
1301
  }
1180
1302
  declare global {
@@ -1,13 +1,14 @@
1
1
  import { carryControls, wrapYaw } from "@johnmorrisdotca/kazoku-ui/view-controls";
2
2
  import { adoptStyles } from "../adopt.js";
3
3
  import { airFor, readAirThickness } from "../realistic/air.js";
4
+ import { readCloudFade } from "../realistic/cloud-fade.js";
4
5
  import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "../realistic/body-label.js";
5
6
  import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
6
- import { cleanPlaces, readPlaceGroups, readPlaces } from "../markers/places.js";
7
+ import { cleanPlaces, readPlaceGroups, readPlaceLayers, readPlaces } from "../markers/places.js";
7
8
  import { readHereCity } from "../markers/here-city.js";
8
9
  import { createHereCity } from "../markers/here-city-host.js";
9
- import { createPlaceLayer, PLACE_STYLE, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
10
- import { aimAt, findPlace, glideView } from "../markers/go-to-place.js";
10
+ import { createPlaceLayer, PLACE_STYLE, placeClick, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
11
+ import { aimAt, findPlace, PLACE_GLIDE_MS } from "../markers/go-to-place.js";
11
12
  import { subsolarPoint } from "../realistic/sun.js";
12
13
  import { SHORT_NAMES } from "../satellites/names.js";
13
14
  import { CITY_NAMES_ATTRIBUTES, CITY_NAMES_STYLE, createCityHost } from "../cities/host.js";
@@ -31,6 +32,7 @@ import { readMeteorStrength } from "../meteors/strength.js";
31
32
  import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
32
33
  import { MAX_TEXTURE } from "../realistic/tiers.js";
33
34
  import { trailOrbits } from "./trail.js";
35
+ import { descentFloorKm, FLY_HEIGHT_KM, FLY_MIN_KM, flyAim, flyAt, flyDistance, flyLonLat, flyStateAt, flyStill, planFly } from "./fly.js";
34
36
  import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt } from "./ephemeris.js";
35
37
  import { MAX_ORBIT_GROUP, readStreakMax } from "./satellite-layer.js";
36
38
  import { applySatelliteFocus, satelliteEmphasis, satelliteGroupRows, shellRadiusOf, zoomForPerspectiveShell } from "./satellite-focus.js";
@@ -109,6 +111,8 @@ const TIME_EVENT_MS = 250;
109
111
  * Riding at a body looking at the Earth, the zoom only narrows the camera's field a little either way: 0.5 to 6.
110
112
  */
111
113
  const LIMITS = { tiltMax: 90, zoomMin: 0.000001, zoomMax: 2.5 };
114
+ /** What the controls say a reader's own hand did: any of these ends a fly-to where it is. */
115
+ const HANDS = new Set(["drag", "pinch", "wheel", "key", "zoom", "pan", "front", "fit"]);
112
116
  /** A number from an attribute, held between `min` and `max`; `null` when it is absent or not a number. */
113
117
  function readFrame(value, min, max) {
114
118
  if (value === null || value.trim() === "")
@@ -196,7 +200,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
196
200
  * ```
197
201
  */
198
202
  export class ChikyuSpace extends HTMLElement {
199
- static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...BEAM_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "bodies-credit", "satellite-tint", "satellite-streak-max", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "ride-viewpoint", "ride-outside-km", "ride-model-size", "ride-drag", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far", "follow", "follow-ease", "dim-occluded", "ride-model-share", "ride-model-seat", "ride-zoom", "ride-up", "compass", "smooth-fps"];
203
+ static observedAttributes = ["cloud-drift", "cloud-fade", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...BEAM_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "place-layers", "here-city", "route", "bodies-credit", "satellite-tint", "satellite-streak-max", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "ride-viewpoint", "ride-outside-km", "ride-model-size", "ride-drag", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far", "follow", "follow-ease", "dim-occluded", "ride-model-share", "ride-model-seat", "ride-zoom", "ride-up", "compass", "smooth-fps"];
200
204
  #model = newSpaceModel();
201
205
  /** The finer imagery (NASA's tile service), one source while the attributes stay the same. Off unless `tiles-finer="gibs"`. */
202
206
  #finerHold = createFinerHolder(() => new Date(this.#model.time), () => this.#gate?.request());
@@ -270,8 +274,15 @@ export class ChikyuSpace extends HTMLElement {
270
274
  /** Whether the page has been told that places in sight were left undrawn. */
271
275
  #placesLost = { told: false };
272
276
  #placeList = [];
273
- /** Counts the turns to a place, so a new one stops the one before. */
274
- #placeGlide = 0;
277
+ /** Counts the moves asked for (`flyTo`, `goToPlace`), so one still finding its floor gives way to a later one. */
278
+ #flyAsks = 0;
279
+ /** The move running (`flyTo`, `goToPlace`): its plan and how to end it. */
280
+ #flight = null;
281
+ #flyStats = { moves: 0, redirects: 0, held: null };
282
+ /** A frame of the move is asked for and not yet run. */
283
+ #flyAsked = false;
284
+ /** The zoom limit under the attributes: the controls' own, raised once a fly-to has come lower. */
285
+ #flyZoomMax = LIMITS.zoomMax;
275
286
  #nameBoxes = new Map();
276
287
  /** A font that arrives after the names were measured: the boxes are read again on the next layout. The satellites' marks are not touched, or the page would be told again about each one already in view. */
277
288
  #onFonts = () => {
@@ -294,6 +305,7 @@ export class ChikyuSpace extends HTMLElement {
294
305
  this.#model.light = readLight(this.getAttribute("light"));
295
306
  this.#model.camera = readCamera(this.getAttribute("camera"));
296
307
  this.#model.cloudDrift = Number.isFinite(Number(this.getAttribute("cloud-drift") ?? "0")) ? Number(this.getAttribute("cloud-drift") ?? "0") : 0;
308
+ this.#model.cloudFade = readCloudFade(this.getAttribute("cloud-fade"));
297
309
  this.#model.earth = { size: readNumber(this.getAttribute("earth-size"), DEFAULT_EARTH_SIZE, 0.02, 50), x: readNumber(this.getAttribute("earth-x"), 0.5, -2, 3), y: readNumber(this.getAttribute("earth-y"), 0.5, -2, 3) };
298
310
  this.#model.stepMs = Math.max(1000, Math.abs(this.#speed) * 1000);
299
311
  this.#model.speed = this.#speed;
@@ -327,6 +339,7 @@ export class ChikyuSpace extends HTMLElement {
327
339
  this.#placeLayer.set(this.#here.named(this.#placeList));
328
340
  this.#placeLayer.look = readPlaceLook(this.getAttribute("places-look"));
329
341
  this.#placeLayer.grouping = readPlaceGroups(this.getAttribute("place-groups"));
342
+ this.#placeLayer.layers = readPlaceLayers(this.getAttribute("place-layers"));
330
343
  this.#dimOccluded = this.getAttribute("dim-occluded") !== "off";
331
344
  this.#placeLayer.dimOccluded = this.#dimOccluded;
332
345
  this.#cities = createCityHost({
@@ -460,7 +473,16 @@ export class ChikyuSpace extends HTMLElement {
460
473
  this.addEventListener("keydown", this.#faceKey);
461
474
  if (!this.hasAttribute("tabindex"))
462
475
  this.tabIndex = 0;
463
- this.#hands = carryControls(this, { initial: this.#model.view, limits: LIMITS, onChange: (state, info) => this.setView(state, info.final) });
476
+ this.#hands = carryControls(this, {
477
+ initial: this.#model.view,
478
+ limits: { ...LIMITS, zoomMax: this.#flyZoomMax },
479
+ onChange: (state, info) => {
480
+ // a hand on the view ends a fly-to where it is
481
+ if (HANDS.has(info.reason))
482
+ this.#flight?.finish("stopped");
483
+ this.setView(state, info.final);
484
+ },
485
+ });
464
486
  this.#labelBox.addEventListener("click", this.#labelClick);
465
487
  this.#labelBox.addEventListener("focusin", this.#labelFocus);
466
488
  }
@@ -543,6 +565,10 @@ export class ChikyuSpace extends HTMLElement {
543
565
  this.#model.cloudDrift = Number.isFinite(Number(value ?? "0")) ? Number(value ?? "0") : 0;
544
566
  this.#gate?.request();
545
567
  }
568
+ else if (name === "cloud-fade") {
569
+ this.#model.cloudFade = readCloudFade(value);
570
+ this.#gate?.request();
571
+ }
546
572
  else if (name === "earth-size")
547
573
  this.earthSize = readNumber(value, DEFAULT_EARTH_SIZE, 0.02, 50);
548
574
  else if (name === "earth-x")
@@ -590,6 +616,10 @@ export class ChikyuSpace extends HTMLElement {
590
616
  this.#placeLayer.grouping = readPlaceGroups(value);
591
617
  this.#gate?.request();
592
618
  }
619
+ else if (name === "place-layers" && this.#placeLayer) {
620
+ this.#placeLayer.layers = readPlaceLayers(value);
621
+ this.#gate?.request();
622
+ }
593
623
  else if (name === "route") {
594
624
  if (applyRoute(this.#model.route, readRoute(value)))
595
625
  this.#gate?.request();
@@ -834,7 +864,8 @@ export class ChikyuSpace extends HTMLElement {
834
864
  * is a ring on the ground, all of them one draw call, and places that crowd are gathered into one ring with their count. They turn with the Earth, are hidden on its far side, are dimmer on its night side
835
865
  * and keep their size in pixels at any zoom. Names never overlap one another or the bodies' names; one with no room is left out. The element stores nothing and sends nothing: the page hands the places
836
866
  * over and keeps them where it likes. Setting the property writes the attribute; at most `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight
837
- * and for a reader who asked for less motion.
867
+ * and for a reader who asked for less motion. A place may also have a `layer` (shown or hidden with `place-layers`), a `size` (`small`), a `look` of its own (over `places-look`) and a `namePriority` (`low` lays
868
+ * its name after the cities' names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`.
838
869
  */
839
870
  get places() {
840
871
  return this.#placeList.map((place) => ({ ...place }));
@@ -920,7 +951,8 @@ export class ChikyuSpace extends HTMLElement {
920
951
  /**
921
952
  * Turn the view 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 stays.
922
953
  * The place is named by its `id`, or by its label in any case. The camera must be looking at the Earth: while it rides along or looks at another body nothing moves. The tilt is held to 90 degrees either
923
- * way, so a place more than 90 degrees of latitude from `center` comes as near the middle as that allows.
954
+ * way, so a place more than 90 degrees of latitude from `center` comes as near the middle as that allows. A new `goToPlace` or `flyTo` while it turns does not stop it: the turn keeps its speed and
955
+ * the way it is going and curves to the new place. A hand on the view ends it where it is.
924
956
  *
925
957
  * @param text - The place's id or label.
926
958
  * @param options - `smooth` (true by default).
@@ -928,22 +960,174 @@ export class ChikyuSpace extends HTMLElement {
928
960
  */
929
961
  async goToPlace(text, options = {}) {
930
962
  const place = findPlace(this.#placeList, text);
931
- const base = this.#model.lookBase;
932
- if (!place || !base || this.#model.ride)
963
+ if (!place || !this.#model.lookBase || this.#model.ride)
933
964
  return undefined;
934
- const controls = this.#controls();
935
- const from = { yaw: this.#model.view.yaw, tilt: this.#model.view.tilt };
936
- const to = aimAt(base, place, from);
937
- const glide = (this.#placeGlide += 1);
938
- const set = (yaw, tilt, final) => {
939
- if (controls)
940
- controls.set({ yaw, tilt, zoom: this.#model.view.zoom }, final, "place");
941
- else
942
- this.setView({ yaw, tilt, zoom: this.#model.view.zoom }, final);
943
- };
944
- glideView(set, from, to, options.smooth !== false && !prefersLessMotion() && this.#view?.live === true, () => glide === this.#placeGlide && this.isConnected);
965
+ this.#flyAsks += 1;
966
+ this.#startFlight(place, { phase: "across", heightKm: null, acrossMs: PLACE_GLIDE_MS, smooth: options.smooth !== false, held: null });
945
967
  return { ...place };
946
968
  }
969
+ /**
970
+ * Fly the camera to a place: across, the Earth turns under the camera at the height it has until the place is below (along a great circle, eased), then down, a descent to `height` kilometres over
971
+ * it (30 by default). `phase` asks for one part alone, so a page can take a reader there one press at a time. A new `flyTo` or `goToPlace` while one is moving does not stop it: the camera keeps its
972
+ * speed and the way it is going and curves smoothly into the new move, and a descent cut short slows to rest without turning back before the new move goes across. A hand on the view (a drag, a pinch,
973
+ * the wheel, a key) or `signal` ends it where it is; a reader who asked for reduced motion, `smooth: false` or a picture that is not live yet goes there at once. The controls' own turn (Auto-turn) is
974
+ * paused, so the place stays below.
975
+ *
976
+ * The descent comes all the way down only where finer pictures lie under the place (`tiles-finer`, over land from 60 degrees south to 80 degrees north); elsewhere it stops at `FLY_FLOOR_KM` (400 km), and
977
+ * at a `zoom-max` the page set, and says so in `held` and `stats.fly`. Once a fly-to has come below about 320 km the zoom reaches as low as it came. The camera must be looking at the Earth: while it
978
+ * rides along or looks at another body nothing moves. `chikyu-fly-start` is sent when it starts, with `{ lon, lat, phase, heightKm, held }`, and `chikyu-fly-end` when it ends, with what it resolves to.
979
+ *
980
+ * @param lat - Degrees north.
981
+ * @param lon - Degrees east.
982
+ * @param options - `height`, `phase`, `smooth` and `signal` (`FlyOptions`).
983
+ * @returns How it ended, once it has; `undefined` when it cannot fly (a latitude or longitude that is not a number, or the camera not looking at the Earth).
984
+ */
985
+ async flyTo(lat, lon, options = {}) {
986
+ if (!Number.isFinite(lat) || !Number.isFinite(lon) || Math.abs(lat) > 90)
987
+ return undefined;
988
+ const ask = (this.#flyAsks += 1);
989
+ const phase = options.phase ?? "both";
990
+ let heightKm = phase === "across" ? null : Math.max(FLY_MIN_KM, Number.isFinite(options.height) ? options.height : FLY_HEIGHT_KM);
991
+ let held = null;
992
+ if (heightKm !== null) {
993
+ const finer = this.tilesFiner !== null;
994
+ // only with finer pictures asked for is it worth knowing whether the place is on land: the outlines are loaded then, and once
995
+ const land = finer ? await import("../place/land.js").then(({ landAt }) => landAt(lon, lat)).then((answer) => answer.country !== null || answer.near !== null) : false;
996
+ const floor = descentFloorKm({ finer, land, lat });
997
+ if (floor !== null && floor > heightKm) {
998
+ heightKm = floor;
999
+ held = "no-finer";
1000
+ }
1001
+ }
1002
+ const where = { lon, lat, phase, heightKm: this.#model.lookBase ? this.#heightKm() : 0, held };
1003
+ // a later move was asked for while this one found its floor
1004
+ if (ask !== this.#flyAsks)
1005
+ return { ...where, reason: "redirected" };
1006
+ if (!this.#model.lookBase || this.#model.ride)
1007
+ return undefined;
1008
+ if (options.signal?.aborted)
1009
+ return { ...where, reason: "stopped" };
1010
+ return new Promise((resolve) => {
1011
+ this.#startFlight({ lon, lat }, {
1012
+ phase,
1013
+ heightKm,
1014
+ smooth: options.smooth !== false,
1015
+ held,
1016
+ ...(options.signal ? { signal: options.signal } : {}),
1017
+ pause: true,
1018
+ start: (detail) => this.dispatchEvent(new CustomEvent("chikyu-fly-start", { detail, bubbles: true, composed: true })),
1019
+ done: (end) => {
1020
+ this.dispatchEvent(new CustomEvent("chikyu-fly-end", { detail: end, bubbles: true, composed: true }));
1021
+ resolve(end);
1022
+ },
1023
+ });
1024
+ });
1025
+ }
1026
+ /** The camera's height above the ground in kilometres while it looks at the Earth, from the zoom and the box's fit. */
1027
+ #heightKm(zoom = this.#model.view.zoom) {
1028
+ return (Math.max(this.#model.nearest, this.#model.fit / Math.max(1e-9, zoom)) - 1) * EARTH_RADIUS_KM;
1029
+ }
1030
+ /**
1031
+ * Start a move to `to`: the one running hands its speed and turn on to it and ends `redirected`. A descent first lets the controls' zoom reach its height (under a `zoom-max` the page set, which holds it).
1032
+ */
1033
+ #startFlight(to, options) {
1034
+ const base = this.#model.lookBase;
1035
+ const at = performance.now();
1036
+ const view = this.#model.view;
1037
+ const now = this.#flight ? flyStateAt(this.#flight.plan, at) : flyStill(flyAim(base.lon - view.yaw, Math.max(-90, Math.min(90, base.lat - view.tilt))), this.#heightKm());
1038
+ if (this.#flight) {
1039
+ this.#flyStats.redirects += 1;
1040
+ this.#flight.finish("redirected");
1041
+ }
1042
+ let heightKm = options.heightKm;
1043
+ let held = options.held;
1044
+ if (heightKm !== null) {
1045
+ const zoom = this.#model.fit / flyDistance(heightKm);
1046
+ this.#model.nearest = Math.min(this.#model.nearest, flyDistance(heightKm));
1047
+ if (zoom > this.#flyZoomMax) {
1048
+ this.#flyZoomMax = zoom;
1049
+ this.#hands?.setLimits({ zoomMax: zoom });
1050
+ }
1051
+ const limit = this.#controls()?.limits?.zoomMax ?? zoom;
1052
+ if (zoom > limit * (1 + 1e-9)) {
1053
+ heightKm = (this.#model.fit / limit - 1) * EARTH_RADIUS_KM;
1054
+ held = "zoom-max";
1055
+ }
1056
+ }
1057
+ this.#flyStats.moves += 1;
1058
+ this.#flyStats.held = held;
1059
+ // the view's own turn would carry the place away from below the camera
1060
+ if (options.pause)
1061
+ this.#controls()?.pause?.();
1062
+ const plan = planFly(now, flyAim(to.lon, to.lat), { at, phase: options.phase, ...(heightKm !== null ? { heightKm } : {}), ...(options.acrossMs !== undefined ? { acrossMs: options.acrossMs } : {}) });
1063
+ const lifts = plan.lifts.length > 0;
1064
+ const abort = () => flight.finish("stopped");
1065
+ const flight = {
1066
+ plan,
1067
+ phase: options.phase,
1068
+ finish: (reason) => {
1069
+ if (this.#flight !== flight)
1070
+ return;
1071
+ this.#flight = null;
1072
+ options.signal?.removeEventListener("abort", abort);
1073
+ bar?.removeEventListener("kazoku-viewchange", hand);
1074
+ options.done?.({ reason, lon: to.lon, lat: to.lat, phase: options.phase, heightKm: this.#heightKm(), held });
1075
+ },
1076
+ };
1077
+ // a bar bound to the view has the hands: a change it makes for one ends the move too
1078
+ const bar = this.#bar();
1079
+ const hand = (event) => {
1080
+ if (HANDS.has(event.detail?.reason ?? ""))
1081
+ flight.finish("stopped");
1082
+ };
1083
+ this.#flight = flight;
1084
+ options.signal?.addEventListener("abort", abort, { once: true });
1085
+ bar?.addEventListener("kazoku-viewchange", hand);
1086
+ options.start?.({ lon: to.lon, lat: to.lat, phase: options.phase, heightKm: heightKm ?? this.#heightKm(), held });
1087
+ if (!options.smooth || prefersLessMotion() || this.#view?.live !== true) {
1088
+ this.#flyView(flyAt(plan, plan.end), true, base, lifts);
1089
+ flight.finish("arrived");
1090
+ return;
1091
+ }
1092
+ this.#askFlyFrame();
1093
+ }
1094
+ /** Ask for the next frame of the move running, once: a move that takes over another goes on in the frame already asked for. */
1095
+ #askFlyFrame() {
1096
+ if (this.#flyAsked)
1097
+ return;
1098
+ this.#flyAsked = true;
1099
+ requestAnimationFrame(this.#flyFrame);
1100
+ }
1101
+ /** One frame of the move running: the point it has now handed to the view, until it ends or the camera stops looking at the Earth. */
1102
+ #flyFrame = () => {
1103
+ this.#flyAsked = false;
1104
+ const flight = this.#flight;
1105
+ if (!flight)
1106
+ return;
1107
+ const looking = this.#model.lookBase;
1108
+ if (!looking || this.#model.ride || !this.isConnected) {
1109
+ flight.finish("stopped");
1110
+ return;
1111
+ }
1112
+ const now = performance.now();
1113
+ const last = now >= flight.plan.end;
1114
+ this.#flyView(flyAt(flight.plan, now), last, looking, flight.plan.lifts.length > 0);
1115
+ if (last)
1116
+ flight.finish("arrived");
1117
+ else
1118
+ this.#askFlyFrame();
1119
+ };
1120
+ /** Hand one point of a move to the controls (or the view, with none): the yaw and tilt that put it in the middle, and the zoom of its height when the move changes the height. */
1121
+ #flyView(point, final, base, lifts) {
1122
+ const view = this.#model.view;
1123
+ const turn = aimAt(base, flyLonLat(point.aim), view);
1124
+ const next = { yaw: turn.yaw, tilt: turn.tilt, zoom: lifts ? this.#model.fit / flyDistance(point.heightKm) : view.zoom };
1125
+ const controls = this.#controls();
1126
+ if (controls)
1127
+ controls.set(next, final, "fly");
1128
+ else
1129
+ this.setView(next, final);
1130
+ }
947
1131
  /**
948
1132
  * Whether places that crowd are gathered into one ring with their count (the attribute `place-groups`): on by default, `off` leaves every place its own ring. Setting the property writes the attribute.
949
1133
  *
@@ -967,6 +1151,49 @@ export class ChikyuSpace extends HTMLElement {
967
1151
  else
968
1152
  this.setAttribute("place-groups", "off");
969
1153
  }
1154
+ /**
1155
+ * Which layers of places are shown (the attribute `place-layers`, a JSON object of a layer's name to true or false): a place whose `layer` is named `false` is left out, and so is its name; any other place, and any layer not
1156
+ * named, is shown. The page hands over every place once and switches the layers, instead of building a list for each switch. Setting the property writes the attribute; an empty object takes it away.
1157
+ * `stats.places.hidden` counts the places left out.
1158
+ *
1159
+ * @example
1160
+ * ```ts no-run
1161
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
1162
+ *
1163
+ * const space = document.querySelector("chikyu-space") as ChikyuSpace;
1164
+ * space.placeLayers = { harbours: false };
1165
+ * space.getAttribute("place-layers"); // '{"harbours":false}'
1166
+ * space.setPlaceLayer("harbours", true);
1167
+ * space.placeLayers; // { harbours: true }
1168
+ * ```
1169
+ */
1170
+ get placeLayers() {
1171
+ return { ...(this.#placeLayer?.layers ?? readPlaceLayers(this.getAttribute("place-layers"))) };
1172
+ }
1173
+ set placeLayers(value) {
1174
+ const names = Object.keys(value);
1175
+ if (names.length === 0)
1176
+ this.removeAttribute("place-layers");
1177
+ else
1178
+ this.setAttribute("place-layers", JSON.stringify(value));
1179
+ }
1180
+ /**
1181
+ * Show or hide one layer of places, leaving the others as they are: the same as setting `placeLayers` with that layer changed.
1182
+ *
1183
+ * @param name - The layer's name, as in a place's `layer`.
1184
+ * @param shown - Whether its places are shown.
1185
+ *
1186
+ * @example
1187
+ * ```ts no-run
1188
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
1189
+ *
1190
+ * const space = document.querySelector("chikyu-space") as ChikyuSpace;
1191
+ * space.setPlaceLayer("airports", false);
1192
+ * ```
1193
+ */
1194
+ setPlaceLayer(name, shown) {
1195
+ this.placeLayers = { ...this.placeLayers, [name]: shown };
1196
+ }
970
1197
  /** The picture said whether it can draw the rings of the places that are not markers of their own. Without `Points` the places' layer draws them itself. */
971
1198
  #ringsDrawn(drawn) {
972
1199
  if (!this.#placeLayer || this.#placeLayer.ringsInPicture === drawn)
@@ -1010,6 +1237,7 @@ export class ChikyuSpace extends HTMLElement {
1010
1237
  #relayNames(cities, sky) {
1011
1238
  if (cities)
1012
1239
  this.#cities?.frame(this.#lastNameFrame, this.#boxesBeforeCities());
1240
+ this.#placeLayer?.late(() => [...this.#bodyNameBoxes(), ...(this.#cities?.boxes ?? [])]);
1013
1241
  this.#seaFrame();
1014
1242
  this.#countryFrame();
1015
1243
  if (sky)
@@ -1020,7 +1248,7 @@ export class ChikyuSpace extends HTMLElement {
1020
1248
  #boxesBeforeCities() {
1021
1249
  const out = this.#beforeCities;
1022
1250
  out.length = 0;
1023
- out.push(...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []));
1251
+ out.push(...this.#bodyNameBoxes(), ...(this.#placeLayer?.earlyBoxes ?? []));
1024
1252
  return out;
1025
1253
  }
1026
1254
  /** What the stars' and constellations' names keep off: everything before them, the cities' names last. The list is refilled, not made again. */
@@ -1512,14 +1740,15 @@ export class ChikyuSpace extends HTMLElement {
1512
1740
  * The controls that are driving this view: a `<kazoku-view-controls for="...">` bound to it (its hands are then the only ones and its controller holds the yaw and tilt), else the element's own hands.
1513
1741
  */
1514
1742
  #controls() {
1515
- if (this.hasAttribute("data-kazoku-bar") && this.id) {
1516
- const root = this.getRootNode();
1517
- const bar = root.querySelector?.(`kazoku-view-controls[for="${CSS.escape(this.id)}"]`);
1518
- const held = bar ? Reflect.get(bar, "controller") : undefined;
1519
- if (held)
1520
- return held;
1521
- }
1522
- return this.#hands?.controller;
1743
+ const bar = this.#bar();
1744
+ const held = bar ? Reflect.get(bar, "controller") : undefined;
1745
+ return held ?? this.#hands?.controller;
1746
+ }
1747
+ /** The `<kazoku-view-controls for="...">` bound to this view, when there is one. */
1748
+ #bar() {
1749
+ if (!this.hasAttribute("data-kazoku-bar") || !this.id)
1750
+ return null;
1751
+ return this.getRootNode().querySelector?.(`kazoku-view-controls[for="${CSS.escape(this.id)}"]`) ?? null;
1523
1752
  }
1524
1753
  /** The body the camera looks at: at zoom 1 it fills the view; the yaw and tilt turn the camera round it. */
1525
1754
  get body() {
@@ -2635,6 +2864,7 @@ export class ChikyuSpace extends HTMLElement {
2635
2864
  satellites: this.#satelliteStats(),
2636
2865
  pace: { ...this.#pace },
2637
2866
  lightFade: { mix: this.#model.lightFade.mix, fading: this.#model.lightFade.fading },
2867
+ cloudFade: this.#model.cloudShown,
2638
2868
  paths: this.#pathControls?.stats() ?? emptyPathStats(),
2639
2869
  ride: { track: this.#model.rideTrack ? { ...this.#model.rideTrack } : null, compass: this.#compass?.shown ? { ...this.#compass.shown } : null, riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null || this.#model.rideFrame.moving, facing: this.facing, groundKm: this.#model.rideFrame.groundKm },
2640
2870
  camera: { position: [this.#model.pose.p[0], this.#model.pose.p[1], this.#model.pose.p[2]], quaternion: [this.#model.pose.q[0], this.#model.pose.q[1], this.#model.pose.q[2], this.#model.pose.q[3]], fov: this.#model.pose.fov },
@@ -2644,7 +2874,7 @@ export class ChikyuSpace extends HTMLElement {
2644
2874
  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: [] },
2645
2875
  followModel: this.#model.followModel,
2646
2876
  tiles: this.#model.tiles?.stats ?? { ready: false, level: null, held: 0, shown: 0, loading: 0, failed: 0, requested: 0, heldBytes: 0, refused: 0, used: {}, finer: null, fading: false },
2647
- places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 }) },
2877
+ places: { ...(this.#placeLayer?.stats ?? { places: 0, hidden: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 }) },
2648
2878
  hereCity: this.#here?.stats ?? { on: false, maxKm: 0, loaded: false, pending: false },
2649
2879
  cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
2650
2880
  borders: { ...this.#model.borders.stats, shown: { ...this.#model.borders.stats.shown }, loaded: [...this.#model.borders.stats.loaded] },
@@ -2653,6 +2883,12 @@ export class ChikyuSpace extends HTMLElement {
2653
2883
  route: { ...this.#model.route.stats },
2654
2884
  countryNames: this.#countries?.stats ?? { on: false, max: 0, countries: 0, names: 0, renders: 0, failed: false },
2655
2885
  seaNames: this.#seas?.stats ?? { on: false, radius: 0, names: 0, renders: 0 },
2886
+ fly: {
2887
+ flying: this.#flight !== null,
2888
+ phase: this.#flight ? (this.#flight.phase === "across" || performance.now() < this.#flight.plan.across ? "across" : "down") : null,
2889
+ heightKm: this.#model.lookBase ? this.#heightKm() : null,
2890
+ ...this.#flyStats,
2891
+ },
2656
2892
  };
2657
2893
  }
2658
2894
  #satelliteStats() {
@@ -2822,6 +3058,11 @@ export class ChikyuSpace extends HTMLElement {
2822
3058
  this.dispatchEvent(new CustomEvent("chikyu-satellite-click", { detail: { ...satellite, info: this.satelliteInfo(satellite), ...this.#estimateOf(satellite) }, bubbles: true, composed: true }));
2823
3059
  return;
2824
3060
  }
3061
+ const place = this.#placeLayer?.pick(x, y);
3062
+ if (place) {
3063
+ claimPress(event);
3064
+ this.dispatchEvent(new CustomEvent("chikyu-place-click", { detail: placeClick(place, x, y), bubbles: true, composed: true }));
3065
+ }
2825
3066
  if (!this.#places)
2826
3067
  return;
2827
3068
  let best;