@johnmorrisdotca/chikyu-earth 0.53.0 → 0.55.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.
@@ -37,6 +37,7 @@ import { bindPaths, emptyPathStats, pointerOf, readPathPriority } from "./path-c
37
37
  import { styleTable } from "./paths.js";
38
38
  import { bindSatelliteHover, hoverPathOn, hoverStyleOf, namesOnHover as namesHoverOn } from "./satellite-hover.js";
39
39
  import { clampFollow, retargetFollow } from "./follow.js";
40
+ import { COMPASS_HTML, COMPASS_STYLE, createCompass, readCompass } from "./compass.js";
40
41
  import { RIDE_FACES, rideTiltLimits, rideTurnDegrees } from "./ride.js";
41
42
  import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
42
43
  import { BODY_NAMES, createSpaceItem, DEFAULT_EARTH_SIZE, newSpaceModel } from "./scene.js";
@@ -132,7 +133,7 @@ const readTime = (value) => {
132
133
  const ms = Date.parse(value);
133
134
  return Number.isFinite(ms) ? ms : "now";
134
135
  };
135
- const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden;isolation:isolate}${IMMERSIVE_STYLE}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-sat{position:absolute;left:0;top:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-sat[hidden]{display:none}.sp-sat[data-hover]{transition:opacity 180ms linear}@media (prefers-reduced-motion: reduce){.sp-sat[data-hover]{transition:none}}${PLACE_STYLE}${SKY_STYLE}${COUNTRY_NAMES_STYLE}${SEA_NAMES_STYLE}${CITY_NAMES_STYLE}${METEOR_NOTE_STYLE}${NOTES_STYLE}`;
136
+ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden;isolation:isolate}${IMMERSIVE_STYLE}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-sat{position:absolute;left:0;top:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-sat[hidden]{display:none}.sp-sat[data-hover]{transition:opacity 180ms linear}@media (prefers-reduced-motion: reduce){.sp-sat[data-hover]{transition:none}}${PLACE_STYLE}${SKY_STYLE}${COUNTRY_NAMES_STYLE}${SEA_NAMES_STYLE}${CITY_NAMES_STYLE}${METEOR_NOTE_STYLE}${NOTES_STYLE}${COMPASS_STYLE}`;
136
137
  /**
137
138
  * The `<chikyu-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`, `time` (`now` or an ISO date), `speed` (1 is real time, 0 holds, 86400 is a day a second, negative runs backwards), `scale` (`compressed` or `true`), `labels` and `orbits` (`off` hides them); positions are computed in the browser by astronomy-engine, an optional peer dependency. It draws only when something changes, and nothing while it is out of sight.
138
139
  *
@@ -177,7 +178,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
177
178
  * ```
178
179
  */
179
180
  export class ChikyuSpace extends HTMLElement {
180
- 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-model-size", "ride-drag", "hover-path", "names-on-hover", "selected-path", "path-hit", "path-priority", "estimate-far", "follow", "follow-ease", "dim-occluded", "ride-model-share", "ride-model-seat", "ride-zoom"];
181
+ 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-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"];
181
182
  #model = newSpaceModel();
182
183
  /** The finer imagery (NASA's tile service), one source while the attributes stay the same. Off unless `tiles-finer="gibs"`. */
183
184
  #finerHold = createFinerHolder(() => new Date(this.#model.time), () => this.#gate?.request());
@@ -208,6 +209,10 @@ export class ChikyuSpace extends HTMLElement {
208
209
  /** The ringed satellites of the last draw (`labelSatellites`), laid out with the places. */
209
210
  #marks = [];
210
211
  #airNote;
212
+ /** The compass on a ride's picture. */
213
+ #compass;
214
+ /** The heading last told to the page (`chikyu-ride-track`): whole degrees, ascending and sunlit, so a heading that has not changed is not told again. */
215
+ #toldTrack = "";
211
216
  #bodiesNote;
212
217
  #gate;
213
218
  #taken;
@@ -273,8 +278,9 @@ export class ChikyuSpace extends HTMLElement {
273
278
  if (!this.hasAttribute("aria-label"))
274
279
  this.setAttribute("aria-label", "The Earth, the Moon, the Sun and the planets in their places for the date shown");
275
280
  const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
276
- root.innerHTML = `<div id="stage"></div><div id="places"></div><div id="labels" aria-hidden="true"></div><div id="notes"><p id="air-note" hidden></p><p id="meteor-note" hidden></p><p id="bodies-note" hidden></p><p id="finer-credit" hidden></p></div>`;
281
+ root.innerHTML = `<div id="stage"></div><div id="places"></div><div id="labels" aria-hidden="true"></div>${COMPASS_HTML}<div id="notes"><p id="air-note" hidden></p><p id="meteor-note" hidden></p><p id="bodies-note" hidden></p><p id="finer-credit" hidden></p></div>`;
277
282
  adoptStyles(root, STYLE, this.nonce);
283
+ this.#compass = createCompass(root);
278
284
  this.#stage = root.getElementById("stage");
279
285
  this.#labelBox = root.getElementById("labels");
280
286
  this.#note = root.getElementById("meteor-note");
@@ -474,6 +480,10 @@ export class ChikyuSpace extends HTMLElement {
474
480
  this.#applyModelSize();
475
481
  else if (name === "ride-drag")
476
482
  this.#applyDrag();
483
+ else if (name === "ride-up")
484
+ this.#applyUp();
485
+ else if (name === "compass")
486
+ this.#showCompass();
477
487
  else if (name === "ride-model-share" || name === "ride-model-seat")
478
488
  this.#applyFrame();
479
489
  else if (name === "ride-zoom")
@@ -580,7 +590,7 @@ export class ChikyuSpace extends HTMLElement {
580
590
  }
581
591
  else if (name === "hover-path" || name === "names-on-hover")
582
592
  this.#hover?.sync();
583
- else if (name === "selected-path")
593
+ else if (name === "selected-path" || name === "path-light")
584
594
  this.#pathControls?.sync();
585
595
  else if (name === "estimate-far")
586
596
  this.#applyEstimate();
@@ -957,6 +967,7 @@ export class ChikyuSpace extends HTMLElement {
957
967
  #nameFrame(frame) {
958
968
  this.#lastNameFrame = frame;
959
969
  this.#tellModel();
970
+ this.#showCompass();
960
971
  this.#relayNames(true, false);
961
972
  }
962
973
  /**
@@ -1525,7 +1536,7 @@ export class ChikyuSpace extends HTMLElement {
1525
1536
  // a body followed (a planet, the Moon, the Earth) is looked at from round it as the view turns: it has no ways to face
1526
1537
  const faceable = !(view === "follow" && typeof target === "string");
1527
1538
  const face = faceable && options.face && RIDE_FACES.includes(options.face) ? options.face : null;
1528
- model.ride = { target: typeof target === "string" ? target : { group: target.group, index: target.index }, view, look: face && view === "from" ? "horizon" : (options.look ?? "down"), face, distanceKm: Math.max(100, options.distanceKm ?? 3000), viewpoint: options.viewpoint === "inside" || options.viewpoint === "outside" ? options.viewpoint : this.rideViewpoint, modelSize: options.modelSize === "fixed" || options.modelSize === "distance" ? options.modelSize : this.rideModelSize, drag: options.drag === "head" || options.drag === "orbit" ? options.drag : this.rideDrag };
1539
+ model.ride = { target: typeof target === "string" ? target : { group: target.group, index: target.index }, view, look: face && view === "from" ? "horizon" : (options.look ?? "down"), face, distanceKm: Math.max(100, options.distanceKm ?? 3000), viewpoint: options.viewpoint === "inside" || options.viewpoint === "outside" ? options.viewpoint : this.rideViewpoint, modelSize: options.modelSize === "fixed" || options.modelSize === "distance" ? options.modelSize : this.rideModelSize, drag: options.drag === "head" || options.drag === "orbit" ? options.drag : this.rideDrag, up: options.up === "north" || options.up === "travel" ? options.up : this.rideUp };
1529
1540
  if (face) {
1530
1541
  model.view = { yaw: 0, tilt: 0, zoom: model.view.zoom };
1531
1542
  model.rideTurn = 0;
@@ -1724,6 +1735,71 @@ export class ChikyuSpace extends HTMLElement {
1724
1735
  this.#gate?.request();
1725
1736
  this.dispatchEvent(new CustomEvent("chikyu-ride", { detail: this.riding }));
1726
1737
  }
1738
+ /**
1739
+ * Which way is up in the picture of a ride above a satellite (the attribute `ride-up`): `travel` (the default) keeps the way the satellite is going at the top, so the picture turns as the heading does; `north` keeps north at the top, so the satellite is seen to go south-east, or whichever way
1740
+ * it really goes over the ground. Within 3 degrees of a pole north-up gives way to travel-up (mixed in smoothly out to 6 degrees), because there north's direction swings round faster than a picture can follow. A drag turns the picture from the up it has, so with `north` a drag turns it away from north, and the compass shows where north has gone.
1741
+ * It is the default for the next `ride` and, set while riding, turns the picture to the new up in one eased glide (a jump for a reader who asked for reduced motion), keeping the ride and the clock. The other views (`from`, `follow`) keep the way it is going at the top. See `RideOptions.up`.
1742
+ *
1743
+ * @example
1744
+ * ```ts
1745
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
1746
+ *
1747
+ * const space = document.createElement("chikyu-space") as ChikyuSpace;
1748
+ * space.rideUp = "north";
1749
+ * console.log(space.rideUp);
1750
+ * ```
1751
+ */
1752
+ get rideUp() {
1753
+ return this.getAttribute("ride-up") === "north" ? "north" : "travel";
1754
+ }
1755
+ set rideUp(value) {
1756
+ this.setAttribute("ride-up", value === "north" ? "north" : "travel");
1757
+ }
1758
+ #applyUp() {
1759
+ const model = this.#model;
1760
+ const ride = model.ride;
1761
+ const next = this.rideUp;
1762
+ if (!ride || ride.up === next)
1763
+ return;
1764
+ const reduced = prefersLessMotion();
1765
+ const pose = model.pose;
1766
+ model.ride = { ...ride, up: next };
1767
+ // only the view above a satellite looks different
1768
+ const moves = ride.view === "above" && typeof ride.target !== "string";
1769
+ model.transition = moves && !reduced && pose.valid ? { start: performance.now(), duration: 800, from: { p: [pose.p[0], pose.p[1], pose.p[2]], q: [pose.q[0], pose.q[1], pose.q[2], pose.q[3]], fov: pose.fov } } : null;
1770
+ this.#last = performance.now();
1771
+ this.#schedule();
1772
+ this.#gate?.request();
1773
+ this.dispatchEvent(new CustomEvent("chikyu-ride", { detail: this.riding }));
1774
+ }
1775
+ /**
1776
+ * Where the ridden satellite is over the ground and how it is going, as of the last draw: `lat`, `lon`, `heightKm`, `bearingDeg` (the way its ground track runs, degrees clockwise from north, with the Earth's turn taken out), `ascending` (going north), `sunlit` (the Sun lights it; the Earth's shadow is a cylinder),
1777
+ * and where north is in the picture: `northDeg` (degrees clockwise from the top; 0 means north is at the top) and `travelDeg` (the way it goes, in the picture). `null` when no satellite is ridden or followed. A page that prints "heading SE 128°" reads `bearingDeg` and needs no maths of its own;
1778
+ * `chikyu-ride-track` is sent with the same object when the whole degree of the heading, `ascending` or `sunlit` changes, never on a timer. It is worked out by the draws the picture makes, so it is as new as the last draw.
1779
+ *
1780
+ * @example
1781
+ * ```ts
1782
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
1783
+ *
1784
+ * const space = document.createElement("chikyu-space") as ChikyuSpace;
1785
+ * console.log(space.rideTrack);
1786
+ * ```
1787
+ */
1788
+ get rideTrack() {
1789
+ return this.#model.rideTrack ? { ...this.#model.rideTrack } : null;
1790
+ }
1791
+ /** Shows the compass for the last draw (the language, the mode of the attribute `compass`), and tells the page when the heading changed by a whole degree, or the satellite went into or out of the Earth's shadow. Called with the draw. */
1792
+ #showCompass() {
1793
+ const track = this.#model.rideTrack;
1794
+ const lang = (this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en";
1795
+ this.#compass?.update(track, lang, readCompass(this.getAttribute("compass")));
1796
+ const key = track ? `${Math.round(track.bearingDeg) % 360}|${track.ascending}|${track.sunlit}` : "";
1797
+ if (key === this.#toldTrack)
1798
+ return;
1799
+ this.#toldTrack = key;
1800
+ if (track)
1801
+ this.dispatchEvent(new CustomEvent("chikyu-ride-track", { detail: { ...track } }));
1802
+ }
1727
1803
  #applyModelSize() {
1728
1804
  const ride = this.#model.ride;
1729
1805
  const next = this.rideModelSize;
@@ -2157,6 +2233,19 @@ export class ChikyuSpace extends HTMLElement {
2157
2233
  else
2158
2234
  this.setAttribute("selected-path", "off");
2159
2235
  }
2236
+ /**
2237
+ * Colour the chosen satellite's own orbit by the light on it (the attribute `path-light`; on unless `off`): amber where the satellite is in sunlight and blue where it is in the Earth's shadow (a cylinder of the Earth's radius along the line from the Sun; `--chikyu-path-sun` and `--chikyu-path-shadow` change the two colours, read when the attribute, `selected-path` or the element changes). The width, opacity and dash are still those of the `selected` look.
2238
+ * Off, the whole orbit is the `selected` look's one colour, as the orbit always was. The page's other paths (`setPaths`) are not coloured by light. The light is worked out for the moment the orbit was last laid out (it is again every half hour of the clock), and the Sun is taken as fixed over the one revolution the path is.
2239
+ */
2240
+ get pathLight() {
2241
+ return !/^(off|false|no|0)$/i.test((this.getAttribute("path-light") ?? "").trim());
2242
+ }
2243
+ set pathLight(value) {
2244
+ if (value)
2245
+ this.removeAttribute("path-light");
2246
+ else
2247
+ this.setAttribute("path-light", "off");
2248
+ }
2160
2249
  /**
2161
2250
  * How near, in CSS pixels, the pointer has to be to a path for the pick and hover events to report it (the attribute `path-hit`; 8 when left out, 0 to 40; `0` or `off` turns the test off). A touch is given twice that, and at least 16.
2162
2251
  * The test covers the page's paths and the chosen satellite's own orbit, not the part of an orbit the Earth hides, and a satellite's dot under the pointer comes first. In a ride from a satellite the test is off unless the attribute is set.
@@ -2366,7 +2455,7 @@ export class ChikyuSpace extends HTMLElement {
2366
2455
  satellites: this.#satelliteStats(),
2367
2456
  lightFade: { mix: this.#model.lightFade.mix, fading: this.#model.lightFade.fading },
2368
2457
  paths: this.#pathControls?.stats() ?? emptyPathStats(),
2369
- ride: { 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 },
2458
+ 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 },
2370
2459
  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 },
2371
2460
  bodies: { look: this.#model.bodies || painter?.looks?.[0] || "plain", painted: this.#model.painted.bodies, moons: this.#model.painted.moons, held: this.#model.painted.held, moon: this.#model.painted.moon, tiles: this.#model.painted.tiles, mapped: this.#model.painted.mapped, pending: this.#model.painted.pending },
2372
2461
  meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
@@ -1,9 +1,10 @@
1
1
  export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitPath, PLANETS, type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
2
2
  export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
3
- export { fitDistance, plainPainter, type BodyDrawing, type BodyMoon, type BodyPainter, type BodyView, type PaintContext, type SatellitePainter } from "./scene.ts";
3
+ export { fitDistance, plainPainter, type BodyDrawing, type RideTrack, type BodyMoon, type BodyPainter, type BodyView, type PaintContext, type SatellitePainter } from "./scene.ts";
4
4
  export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideDrag, type RideFace, type RideInput, type RideLook, type RidePose, type RideModelSize, type RideViewpoint } from "./ride.ts";
5
5
  export { earthHides, type SatelliteScreen } from "./satellite-layer.ts";
6
6
  export { ABOVE_MODEL_KM, ABOVE_MODEL_SHARE, aboveAxes, aboveModelShare, MODEL_FADE_FROM_KM, MODEL_FADE_TO_KM, MODEL_HANDOVER_PX, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
7
+ export { localNorth, NORTH_UP_BLEND_DEG, NORTH_UP_POLE_DEG, northUpYaw, screenAngle, type RideUp } from "./north-up.ts";
7
8
  export { genericSatellite, satelliteKind, type SatelliteKind } from "./generic-satellite.ts";
8
9
  export { BEAM_ATTRIBUTES, BEAM_COLOUR, BEAM_ELEVATION, beamCells, footprintAngle, footprintKm, readBeam, type BeamCells, type BeamOptions } from "../beam/geometry.ts";
9
10
  export type { BeamStats } from "../beam/layer.ts";
@@ -6,6 +6,7 @@ export { fitDistance, plainPainter } from "./scene.js";
6
6
  export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
7
7
  export { earthHides } from "./satellite-layer.js";
8
8
  export { ABOVE_MODEL_KM, ABOVE_MODEL_SHARE, aboveAxes, aboveModelShare, MODEL_FADE_FROM_KM, MODEL_FADE_TO_KM, MODEL_HANDOVER_PX, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
9
+ export { localNorth, NORTH_UP_BLEND_DEG, NORTH_UP_POLE_DEG, northUpYaw, screenAngle } from "./north-up.js";
9
10
  export { genericSatellite, satelliteKind } from "./generic-satellite.js";
10
11
  export { BEAM_ATTRIBUTES, BEAM_COLOUR, BEAM_ELEVATION, beamCells, footprintAngle, footprintKm, readBeam } from "../beam/geometry.js";
11
12
  export { RIDE_PATH_FADE_KM } from "./path-ribbons.js";
@@ -0,0 +1,86 @@
1
+ import type { Vec3 } from "./ephemeris.ts";
2
+ /**
3
+ * Which way is up in the picture of a ride above a satellite: `travel` (the default) puts the way the satellite is going at the top, so the picture turns with its heading; `north` puts north at the top, so the satellite is seen to move in its real direction over the ground (south-east, say).
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import type { RideUp } from "@johnmorrisdotca/chikyu-earth/space";
8
+ *
9
+ * const ups: RideUp[] = ["travel", "north"];
10
+ * console.log(ups.join(" or "));
11
+ * ```
12
+ */
13
+ export type RideUp = "travel" | "north";
14
+ /**
15
+ * How close to a pole, in degrees of arc, a satellite must be for north-up to give way to travel-up: inside this, north's direction on the ground swings round faster than a picture can follow (and at the pole itself it has none), so the way it is going is at the top.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { NORTH_UP_POLE_DEG } from "@johnmorrisdotca/chikyu-earth/space";
20
+ *
21
+ * console.log(NORTH_UP_POLE_DEG);
22
+ * ```
23
+ */
24
+ export declare const NORTH_UP_POLE_DEG = 3;
25
+ /**
26
+ * How many more degrees from a pole north-up takes to come back in: travel-up holds inside {@link NORTH_UP_POLE_DEG}, north-up holds beyond that many degrees more, and between them the two are mixed by a smooth step so the picture turns, never jumps.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { NORTH_UP_BLEND_DEG } from "@johnmorrisdotca/chikyu-earth/space";
31
+ *
32
+ * console.log(NORTH_UP_BLEND_DEG);
33
+ * ```
34
+ */
35
+ export declare const NORTH_UP_BLEND_DEG = 3;
36
+ /**
37
+ * Which way north is at a place, as a unit vector in the scene's axes (y is north): the way along the ground that goes towards the pole. `null` at the poles themselves and at the centre, where it is not defined.
38
+ *
39
+ * @param position - Where the place is, from the Earth's centre, in any unit.
40
+ * @returns A unit vector level with the ground there, or `null`.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { localNorth } from "@johnmorrisdotca/chikyu-earth/space";
45
+ *
46
+ * console.log(localNorth([1.066, 0, 0]));
47
+ * ```
48
+ */
49
+ export declare function localNorth(position: Vec3): Vec3 | null;
50
+ /**
51
+ * The turn that puts north at the top of the picture of the view above a satellite (`aboveAxes` turns the picture by its `yaw`, from the way the satellite is going at the top), and how much of it holds. Add `yaw * weight` to the picture's own turn. The weight is 1 away from the poles,
52
+ * 0 within {@link NORTH_UP_POLE_DEG} degrees of one (the way it is going stays at the top), and a smooth step between, over {@link NORTH_UP_BLEND_DEG} degrees. A satellite that is not moving has no way to turn from, and gives a weight of 0.
53
+ *
54
+ * @param position - Where the satellite is, from the Earth's centre.
55
+ * @param velocity - The way it is going.
56
+ * @returns The yaw in radians (positive turns the top towards the left of the way it goes) and its weight, 0 to 1.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * import { northUpYaw } from "@johnmorrisdotca/chikyu-earth/space";
61
+ *
62
+ * // over the equator going east: north is on the left, a quarter turn
63
+ * const turn = northUpYaw([1.066, 0, 0], [0, 0, -7.66]);
64
+ * console.log((turn.yaw / (Math.PI / 180)).toFixed(0), turn.weight);
65
+ * ```
66
+ */
67
+ export declare function northUpYaw(position: Vec3, velocity: Vec3): {
68
+ yaw: number;
69
+ weight: number;
70
+ };
71
+ /**
72
+ * Where north points in a picture: the angle, clockwise from the top of the picture, of a direction as the camera sees it (the part of it in the picture's plane). 0 means north is at the top, 90 to the right. `null` when the direction points along the camera's line of sight (or away), where it has no direction in the picture.
73
+ *
74
+ * @param quaternion - The camera's turn, `[x, y, z, w]` as three.js has it (the camera looks along its own -z, with +y up and +x to the right).
75
+ * @param direction - The direction in the scene's axes, such as `localNorth`.
76
+ * @returns Degrees clockwise from the top of the picture, 0 up to 360, or `null`.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * import { screenAngle } from "@johnmorrisdotca/chikyu-earth/space";
81
+ *
82
+ * // a camera that is not turned: +y is at the top, +x to the right
83
+ * console.log(screenAngle([0, 0, 0, 1], [0, 1, 0]), screenAngle([0, 0, 0, 1], [1, 0, 0]));
84
+ * ```
85
+ */
86
+ export declare function screenAngle(quaternion: readonly [number, number, number, number], direction: Vec3): number | null;
@@ -0,0 +1,104 @@
1
+ import { satelliteAxes } from "./satellite-model.js";
2
+ const RAD = Math.PI / 180;
3
+ /**
4
+ * How close to a pole, in degrees of arc, a satellite must be for north-up to give way to travel-up: inside this, north's direction on the ground swings round faster than a picture can follow (and at the pole itself it has none), so the way it is going is at the top.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { NORTH_UP_POLE_DEG } from "@johnmorrisdotca/chikyu-earth/space";
9
+ *
10
+ * console.log(NORTH_UP_POLE_DEG);
11
+ * ```
12
+ */
13
+ export const NORTH_UP_POLE_DEG = 3;
14
+ /**
15
+ * How many more degrees from a pole north-up takes to come back in: travel-up holds inside {@link NORTH_UP_POLE_DEG}, north-up holds beyond that many degrees more, and between them the two are mixed by a smooth step so the picture turns, never jumps.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { NORTH_UP_BLEND_DEG } from "@johnmorrisdotca/chikyu-earth/space";
20
+ *
21
+ * console.log(NORTH_UP_BLEND_DEG);
22
+ * ```
23
+ */
24
+ export const NORTH_UP_BLEND_DEG = 3;
25
+ /**
26
+ * Which way north is at a place, as a unit vector in the scene's axes (y is north): the way along the ground that goes towards the pole. `null` at the poles themselves and at the centre, where it is not defined.
27
+ *
28
+ * @param position - Where the place is, from the Earth's centre, in any unit.
29
+ * @returns A unit vector level with the ground there, or `null`.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import { localNorth } from "@johnmorrisdotca/chikyu-earth/space";
34
+ *
35
+ * console.log(localNorth([1.066, 0, 0]));
36
+ * ```
37
+ */
38
+ export function localNorth(position) {
39
+ const length = Math.hypot(position[0], position[1], position[2]);
40
+ if (!(length > 0))
41
+ return null;
42
+ const up = [position[0] / length, position[1] / length, position[2] / length];
43
+ const level = [-up[1] * up[0], 1 - up[1] * up[1], -up[1] * up[2]];
44
+ const size = Math.hypot(level[0], level[1], level[2]);
45
+ return size > 1e-9 ? [level[0] / size, level[1] / size, level[2] / size] : null;
46
+ }
47
+ /**
48
+ * The turn that puts north at the top of the picture of the view above a satellite (`aboveAxes` turns the picture by its `yaw`, from the way the satellite is going at the top), and how much of it holds. Add `yaw * weight` to the picture's own turn. The weight is 1 away from the poles,
49
+ * 0 within {@link NORTH_UP_POLE_DEG} degrees of one (the way it is going stays at the top), and a smooth step between, over {@link NORTH_UP_BLEND_DEG} degrees. A satellite that is not moving has no way to turn from, and gives a weight of 0.
50
+ *
51
+ * @param position - Where the satellite is, from the Earth's centre.
52
+ * @param velocity - The way it is going.
53
+ * @returns The yaw in radians (positive turns the top towards the left of the way it goes) and its weight, 0 to 1.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { northUpYaw } from "@johnmorrisdotca/chikyu-earth/space";
58
+ *
59
+ * // over the equator going east: north is on the left, a quarter turn
60
+ * const turn = northUpYaw([1.066, 0, 0], [0, 0, -7.66]);
61
+ * console.log((turn.yaw / (Math.PI / 180)).toFixed(0), turn.weight);
62
+ * ```
63
+ */
64
+ export function northUpYaw(position, velocity) {
65
+ const axes = satelliteAxes(position, velocity);
66
+ const north = localNorth(position);
67
+ if (!axes || !north)
68
+ return { yaw: 0, weight: 0 };
69
+ const yaw = Math.atan2(north[0] * axes.y[0] + north[1] * axes.y[1] + north[2] * axes.y[2], north[0] * axes.x[0] + north[1] * axes.x[1] + north[2] * axes.x[2]);
70
+ // the angle from the nearer pole: the up vector's component along y is the cosine of the colatitude
71
+ const polar = Math.acos(Math.min(1, Math.abs(axes.z[1]))) / RAD;
72
+ const k = Math.min(1, Math.max(0, (polar - NORTH_UP_POLE_DEG) / NORTH_UP_BLEND_DEG));
73
+ return { yaw, weight: k * k * (3 - 2 * k) };
74
+ }
75
+ /**
76
+ * Where north points in a picture: the angle, clockwise from the top of the picture, of a direction as the camera sees it (the part of it in the picture's plane). 0 means north is at the top, 90 to the right. `null` when the direction points along the camera's line of sight (or away), where it has no direction in the picture.
77
+ *
78
+ * @param quaternion - The camera's turn, `[x, y, z, w]` as three.js has it (the camera looks along its own -z, with +y up and +x to the right).
79
+ * @param direction - The direction in the scene's axes, such as `localNorth`.
80
+ * @returns Degrees clockwise from the top of the picture, 0 up to 360, or `null`.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { screenAngle } from "@johnmorrisdotca/chikyu-earth/space";
85
+ *
86
+ * // a camera that is not turned: +y is at the top, +x to the right
87
+ * console.log(screenAngle([0, 0, 0, 1], [0, 1, 0]), screenAngle([0, 0, 0, 1], [1, 0, 0]));
88
+ * ```
89
+ */
90
+ export function screenAngle(quaternion, direction) {
91
+ // the direction in the camera's own axes: turned by the inverse of the camera's turn
92
+ const [qx, qy, qz, w] = quaternion;
93
+ const px = -qx;
94
+ const py = -qy;
95
+ const pz = -qz;
96
+ const tx = 2 * (py * direction[2] - pz * direction[1]);
97
+ const ty = 2 * (pz * direction[0] - px * direction[2]);
98
+ const tz = 2 * (px * direction[1] - py * direction[0]);
99
+ const x = direction[0] + w * tx + (py * tz - pz * ty);
100
+ const y = direction[1] + w * ty + (pz * tx - px * tz);
101
+ if (Math.hypot(x, y) < 1e-6)
102
+ return null;
103
+ return (((Math.atan2(x, y) / RAD) % 360) + 360) % 360;
104
+ }
@@ -2,7 +2,7 @@ import type { SatelliteRef } from "../satellites/types.ts";
2
2
  import type { SatelliteState } from "./satellite-layer.ts";
3
3
  import { MAX_PATHS, type PathHit, type PathRequest, type PathStyle } from "./paths.ts";
4
4
  /** The attributes the paths add to an element. */
5
- export declare const PATH_ATTRIBUTES: readonly ["selected-path", "path-hit", "path-priority"];
5
+ export declare const PATH_ATTRIBUTES: readonly ["selected-path", "path-light", "path-hit", "path-priority"];
6
6
  /** Which comes first under a pointer: a satellite's `dots` (the default), or `paths` (a path of the page's, unless the dot is of a satellite whose path is listed or that is chosen). Anything else is `dots`. */
7
7
  export type PathPriority = "dots" | "paths";
8
8
  export declare const readPathPriority: (value: string | null) => PathPriority;
@@ -1,6 +1,9 @@
1
+ // What the two satellite elements share for the page's paths: the list and the look table, the attributes `selected-path` and `path-hit`, the test of which path a pointer is on, and the events `chikyu-path-hover` and `chikyu-path-click`.
2
+ // One press means one thing, in this order: a satellite's dot, then a path, then the sky. The element asks {@link PathControls.press} after the dot and before anything else, and what it answers `true` to is not given to the sky.
3
+ import { TRACK_SHADOW, TRACK_SUNLIT } from "../flat/colours.js";
1
4
  import { capPaths, hitRadius, MAX_PATHS, readPathHit, styleTable } from "./paths.js";
2
5
  /** The attributes the paths add to an element. */
3
- export const PATH_ATTRIBUTES = ["selected-path", "path-hit", "path-priority"];
6
+ export const PATH_ATTRIBUTES = ["selected-path", "path-light", "path-hit", "path-priority"];
4
7
  export const readPathPriority = (value) => (value === "paths" ? "paths" : "dots");
5
8
  export const pointerOf = (event) => (event.pointerType === "touch" ? "touch" : event.pointerType === "pen" ? "pen" : "mouse");
6
9
  export function bindPaths(host) {
@@ -90,9 +93,17 @@ export function bindPaths(host) {
90
93
  },
91
94
  sync() {
92
95
  const on = element.getAttribute("selected-path") !== "off";
93
- if (on === state.paths.selectedOn)
96
+ // the chosen orbit in sunlight and in the Earth's shadow: `path-light="off"` keeps it one colour; the colours are the page's `--chikyu-path-sun` and `--chikyu-path-shadow`
97
+ const lightOn = !/^(off|false|no|0)$/i.test((element.getAttribute("path-light") ?? "").trim());
98
+ const style = getComputedStyle(element);
99
+ const sun = style.getPropertyValue("--chikyu-path-sun").trim() || TRACK_SUNLIT;
100
+ const shadow = style.getPropertyValue("--chikyu-path-shadow").trim() || TRACK_SHADOW;
101
+ const light = state.paths.light;
102
+ const lightChanged = lightOn !== light.on || sun !== light.sun || shadow !== light.shadow;
103
+ if (on === state.paths.selectedOn && !lightChanged)
94
104
  return;
95
105
  state.paths.selectedOn = on;
106
+ state.paths.light = { on: lightOn, sun, shadow };
96
107
  state.paths.version += 1;
97
108
  host.request();
98
109
  },
@@ -23,6 +23,10 @@ export interface RibbonPath {
23
23
  style: PathStyle;
24
24
  /** Earth radii from the camera over which the path fades in (nothing at the camera, all of its opacity at this distance); 0 or missing draws it at its look everywhere. */
25
25
  fade?: number;
26
+ /** One flag a point ({@link PATH_POINTS}): 1 where the segment that starts at the point is drawn in `darkInk` instead of the look's colour (the part of an orbit in the Earth's shadow). */
27
+ dark?: Uint8Array;
28
+ /** Any CSS colour: what the flagged segments are drawn in. Needed with `dark`. */
29
+ darkInk?: string;
26
30
  }
27
31
  export interface PathRibbons {
28
32
  /** Write the paths into the buffers, none for an empty list. Costs nothing on the GPU until the next draw, and nothing is drawn while there are no paths. */
@@ -134,13 +134,16 @@ export function createPathRibbons(three, scene) {
134
134
  mesh.visible = false;
135
135
  scene.add(mesh);
136
136
  const colour = new three.Color();
137
+ const shade = new three.Color();
137
138
  let count = 0;
138
139
  return {
139
140
  set(paths) {
140
141
  count = Math.min(PATH_SLOTS, paths.length);
141
142
  for (let p = 0; p < count; p += 1) {
142
- const { positions, style, fade = 0 } = paths[p];
143
+ const { positions, style, fade = 0, dark, darkInk } = paths[p];
143
144
  colour.set(style.color);
145
+ if (dark && darkInk)
146
+ shade.set(darkInk);
144
147
  // the arc length at each point, in Earth radii, for the dashes
145
148
  let along = 0;
146
149
  for (let i = 0; i < PATH_POINTS; i += 1) {
@@ -153,6 +156,7 @@ export function createPathRibbons(three, scene) {
153
156
  const bz = positions[j * 3 + 2];
154
157
  const length = Math.hypot(bx - ax, by - ay, bz - az);
155
158
  const q = p * PATH_POINTS + i;
159
+ const ink0 = dark && darkInk && dark[i] === 1 ? shade : colour;
156
160
  for (let k = 0; k < 4; k += 1) {
157
161
  const v = q * 4 + k;
158
162
  position[v * 3] = ax;
@@ -161,9 +165,9 @@ export function createPathRibbons(three, scene) {
161
165
  other[v * 3] = bx;
162
166
  other[v * 3 + 1] = by;
163
167
  other[v * 3 + 2] = bz;
164
- ink[v * 4] = colour.r;
165
- ink[v * 4 + 1] = colour.g;
166
- ink[v * 4 + 2] = colour.b;
168
+ ink[v * 4] = ink0.r;
169
+ ink[v * 4 + 1] = ink0.g;
170
+ ink[v * 4 + 2] = ink0.b;
167
171
  ink[v * 4 + 3] = style.opacity;
168
172
  look[v * 4] = style.width;
169
173
  look[v * 4 + 1] = style.dash ? style.dash[0] : 0;
@@ -48,6 +48,11 @@ export interface SatelliteState {
48
48
  requests: PathRequest[];
49
49
  overrides: Record<string, Partial<PathStyle> | null>;
50
50
  selectedOn: boolean;
51
+ light: {
52
+ on: boolean;
53
+ sun: string;
54
+ shadow: string;
55
+ };
51
56
  version: number;
52
57
  info: PathInfo[];
53
58
  dropped: number;
@@ -1,6 +1,8 @@
1
1
  import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
2
2
  import { satelliteEmphasis } from "./satellite-focus.js";
3
3
  import { BUILT_IN_PATH_STYLES, capPaths, nearestLoop, resolvePathId, styleOf, styleTable } from "./paths.js";
4
+ import { shadowFlags, sunDirectionScene } from "../flat/track-state.js";
5
+ import { TRACK_SHADOW, TRACK_SUNLIT } from "../flat/colours.js";
4
6
  import { createPathRibbons, RIDE_PATH_FADE_KM } from "./path-ribbons.js";
5
7
  /**
6
8
  * The longest a streak may be along its orbit, in Earth radii: 0.025, about 160 km, which is what a low satellite covers in a frame at 10 minutes a second (150 km). On the screen that is a share of the Earth's drawn radius, so a streak
@@ -56,7 +58,7 @@ export function longestStreak(segments, count, earthPx) {
56
58
  }
57
59
  return longest * earthPx;
58
60
  }
59
- export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, focus: null, modelOver: null, hover: { ref: null, fade: 0, enabled: true, color: "#ffffff", opacity: HOVER_PATH_OPACITY }, paths: { requests: [], overrides: {}, selectedOn: true, version: 0, info: [], dropped: 0, unresolved: 0 }, ridden: null, streakMax: DEFAULT_STREAK_MAX, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, longestStreakPx: 0, streakCapPx: 0, weight: 1, fade: 1, earthPx: 0, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0, selectedRing: false, hoverPath: false, hoverOpacity: 0, selectedOpacity: 0, orbitLines: 0, pathsDrawn: 0, pathDraws: 0, estimated: 0 } });
61
+ export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, focus: null, modelOver: null, hover: { ref: null, fade: 0, enabled: true, color: "#ffffff", opacity: HOVER_PATH_OPACITY }, paths: { requests: [], overrides: {}, selectedOn: true, light: { on: true, sun: TRACK_SUNLIT, shadow: TRACK_SHADOW }, version: 0, info: [], dropped: 0, unresolved: 0 }, ridden: null, streakMax: DEFAULT_STREAK_MAX, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, longestStreakPx: 0, streakCapPx: 0, weight: 1, fade: 1, earthPx: 0, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0, selectedRing: false, hoverPath: false, hoverOpacity: 0, selectedOpacity: 0, orbitLines: 0, pathsDrawn: 0, pathDraws: 0, estimated: 0 } });
60
62
  /** The most orbits a group may draw all at once, one line each. */
61
63
  export const MAX_ORBIT_GROUP = 40;
62
64
  const ORBIT_POINTS = 120;
@@ -410,7 +412,8 @@ export function createSatelliteLayer(three, scene, state, ratio) {
410
412
  wanted.push({ id: norad ?? refKey(ref), ref, name: "selected", style: table["selected"], fade: riding ? RIDE_PATH_FADE_KM / EARTH_KM : 0 });
411
413
  }
412
414
  }
413
- const signature = wanted.map((w) => `${refKey(w.ref)}|${w.name}|${w.style.color}|${w.style.width}|${w.style.opacity}|${w.style.dash ? w.style.dash.join(",") : "-"}|${w.fade}`).join(";");
415
+ const light = pathState.light;
416
+ const signature = `${light.on ? `${light.sun}|${light.shadow}` : "-"};` + wanted.map((w) => `${refKey(w.ref)}|${w.name}|${w.style.color}|${w.style.width}|${w.style.opacity}|${w.style.dash ? w.style.dash.join(",") : "-"}|${w.fade}`).join(";");
414
417
  let dirty = signature !== slotsSignature;
415
418
  const old = new Map(slots.map((slot) => [slot.key, slot]));
416
419
  let empty = 0;
@@ -420,7 +423,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
420
423
  let slot = old.get(key);
421
424
  const set = find(w.ref);
422
425
  if (!slot) {
423
- slot = { key, info: { id: w.id, ref: w.ref, style: w.name }, style: w.style, fade: w.fade, positions: new Float32Array(ORBIT_POINTS * 3), screen: new Float32Array(ORBIT_POINTS * 2), seen: new Uint8Array(ORBIT_POINTS), at: Number.NaN, wall: 0, empty: false };
426
+ slot = { key, info: { id: w.id, ref: w.ref, style: w.name }, style: w.style, fade: w.fade, positions: new Float32Array(ORBIT_POINTS * 3), screen: new Float32Array(ORBIT_POINTS * 2), seen: new Uint8Array(ORBIT_POINTS), at: Number.NaN, wall: 0, dark: new Uint8Array(ORBIT_POINTS), darkFor: "", empty: false };
424
427
  dirty = true;
425
428
  }
426
429
  old.delete(key);
@@ -434,6 +437,15 @@ export function createSatelliteLayer(three, scene, state, ratio) {
434
437
  slot.empty = slot.positions.every((v) => v === 0);
435
438
  dirty = true;
436
439
  }
440
+ // the chosen satellite's own orbit, coloured by where the Earth's shadow lies on it (the Sun is fixed over the one revolution it is)
441
+ const shaded = light.on && w.name === "selected" && !slot.empty;
442
+ const darkFor = shaded ? `${slot.at}|${light.sun}|${light.shadow}` : "";
443
+ if (darkFor !== slot.darkFor) {
444
+ slot.darkFor = darkFor;
445
+ if (shaded)
446
+ shadowFlags(slot.positions, ORBIT_POINTS, sunDirectionScene(slot.at), slot.dark);
447
+ dirty = true;
448
+ }
437
449
  if (slot.empty)
438
450
  empty += 1;
439
451
  next.push(slot);
@@ -441,7 +453,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
441
453
  slots = next;
442
454
  if (dirty) {
443
455
  slotsSignature = signature;
444
- ribbons.set(slots.filter((slot) => !slot.empty).map((slot) => ({ positions: slot.positions, style: slot.style, fade: slot.fade })));
456
+ ribbons.set(slots.filter((slot) => !slot.empty).map((slot) => ({ positions: slot.positions, style: slot.darkFor ? { ...slot.style, color: light.sun } : slot.style, fade: slot.fade, ...(slot.darkFor ? { dark: slot.dark, darkInk: light.shadow } : {}) })));
445
457
  }
446
458
  const own = wanted.filter((w) => w.name === "selected" && pathState.selectedOn);
447
459
  pathState.info = slots.filter((slot) => !slot.empty).map((slot) => ({ ...slot.info }));
@@ -14,6 +14,8 @@ import type { PlaceView } from "../markers/places.ts";
14
14
  import { type PlaceSpriteData } from "../markers/place-sprites.ts";
15
15
  import type { CountryFrame } from "../country-names/geometry.ts";
16
16
  import type { GeoPoint } from "../types.ts";
17
+ import { type RideUp } from "./north-up.ts";
18
+ import { type GroundTrackState } from "../flat/track-state.ts";
17
19
  import type { PathHit } from "./paths.ts";
18
20
  import { type SatelliteScreen, type SatelliteState } from "./satellite-layer.ts";
19
21
  import { type BodyLabelState } from "../realistic/body-label.ts";
@@ -124,6 +126,25 @@ export interface RideState {
124
126
  modelSize: RideModelSize;
125
127
  /** What a drag does in an outside ride from the satellite: `head` turns the view where the camera is, `orbit` takes the camera round the satellite. */
126
128
  drag: RideDrag;
129
+ /** Which way is up in the view above a satellite: the way it is going (`travel`), or north. */
130
+ up: RideUp;
131
+ }
132
+ /**
133
+ * Where the ridden satellite is over the ground and how it is going, and where north is in the picture, as of the last draw.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * import type { RideTrack } from "@johnmorrisdotca/chikyu-earth/space";
138
+ *
139
+ * const say = (track: RideTrack): string => `heading ${track.bearingDeg.toFixed(0)} degrees, north ${track.northDeg === null ? "out of sight" : `${track.northDeg.toFixed(0)} degrees round`}`;
140
+ * console.log(typeof say);
141
+ * ```
142
+ */
143
+ export interface RideTrack extends GroundTrackState {
144
+ /** Where north points in the picture, degrees clockwise from its top (0 north at the top, 90 to the right), or `null` when it points along the line of sight. */
145
+ northDeg: number | null;
146
+ /** The way the satellite goes over the ground in the picture, degrees clockwise from its top: the picture's north angle plus the bearing; or `null` with north. */
147
+ travelDeg: number | null;
127
148
  }
128
149
  /** The camera as the last draw left it, for the next one to start from when the ride changes. */
129
150
  export interface Pose {
@@ -239,6 +260,8 @@ export interface SpaceModel {
239
260
  rideMotion: number;
240
261
  /** The heading of a riding camera in degrees, added up change by change from the controls' wrapped yaw (`rideTurnDegrees`): a drag the whole way round is a turn the whole way round, and a change of zoom swings nothing. */
241
262
  rideTurn: number;
263
+ /** The ridden satellite's ground state and where north is in the picture, as of the last draw, or `null` when no satellite is ridden or followed. */
264
+ rideTrack: RideTrack | null;
242
265
  /** How far the riding camera is from the Earth's centre in Earth radii as of the last draw, or null when none rides: the range of tilt that does something follows it. */
243
266
  rideDistance: number | null;
244
267
  /**