@johnmorrisdotca/chikyu-earth 0.34.1 → 0.36.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/NOTICE.md +23 -1
  3. package/README.md +20 -2
  4. package/dist/borders/layer.d.ts +75 -0
  5. package/dist/borders/layer.js +136 -0
  6. package/dist/borders/lines.d.ts +138 -0
  7. package/dist/borders/lines.js +227 -0
  8. package/dist/cities/host.d.ts +9 -0
  9. package/dist/cities/host.js +14 -2
  10. package/dist/country-names/geometry.d.ts +264 -0
  11. package/dist/country-names/geometry.js +372 -0
  12. package/dist/country-names/host.d.ts +82 -0
  13. package/dist/country-names/host.js +212 -0
  14. package/dist/grid/layer.d.ts +45 -0
  15. package/dist/grid/layer.js +66 -0
  16. package/dist/grid/lines.d.ts +85 -0
  17. package/dist/grid/lines.js +113 -0
  18. package/dist/markers/go-to-place.d.ts +27 -0
  19. package/dist/markers/go-to-place.js +35 -0
  20. package/dist/markers/index.d.ts +2 -1
  21. package/dist/markers/index.js +2 -1
  22. package/dist/markers/layer.d.ts +7 -0
  23. package/dist/markers/layer.js +7 -0
  24. package/dist/markers/place-layer.d.ts +58 -7
  25. package/dist/markers/place-layer.js +326 -64
  26. package/dist/markers/place-sprites.d.ts +33 -0
  27. package/dist/markers/place-sprites.js +161 -0
  28. package/dist/markers/places.d.ts +91 -6
  29. package/dist/markers/places.js +135 -6
  30. package/dist/realistic/earth.d.ts +11 -0
  31. package/dist/realistic/earth.js +54 -0
  32. package/dist/realistic/element.d.ts +84 -4
  33. package/dist/realistic/element.js +224 -27
  34. package/dist/realistic/immersive.d.ts +7 -0
  35. package/dist/realistic/immersive.js +17 -0
  36. package/dist/realistic/index.d.ts +7 -0
  37. package/dist/realistic/index.js +3 -0
  38. package/dist/realistic/textures.d.ts +3 -0
  39. package/dist/sky/culture-lines.d.ts +56 -0
  40. package/dist/sky/culture-lines.js +82 -0
  41. package/dist/sky/figure-pick.d.ts +75 -0
  42. package/dist/sky/figure-pick.js +200 -0
  43. package/dist/sky/host.d.ts +17 -1
  44. package/dist/sky/host.js +615 -71
  45. package/dist/sky/keep-clear.d.ts +63 -0
  46. package/dist/sky/keep-clear.js +55 -0
  47. package/dist/space/element.d.ts +105 -10
  48. package/dist/space/element.js +275 -18
  49. package/dist/space/index.d.ts +2 -2
  50. package/dist/space/index.js +1 -1
  51. package/dist/space/satellite-model.d.ts +22 -0
  52. package/dist/space/satellite-model.js +38 -0
  53. package/dist/space/scene.d.ts +56 -7
  54. package/dist/space/scene.js +124 -23
  55. package/package.json +3 -3
@@ -3,13 +3,20 @@ import { adoptStyles } from "../adopt.js";
3
3
  import { airFor, readAirThickness } from "../realistic/air.js";
4
4
  import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "../realistic/body-label.js";
5
5
  import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
6
- import { cleanPlaces, readPlaces } from "../markers/places.js";
6
+ import { cleanPlaces, readPlaceGroups, readPlaces } from "../markers/places.js";
7
7
  import { createPlaceLayer, PLACE_STYLE, readPlaceLook } from "../markers/place-layer.js";
8
+ import { aimAt, findPlace, glideView } from "../markers/go-to-place.js";
9
+ import { subsolarPoint } from "../realistic/sun.js";
8
10
  import { SHORT_NAMES } from "../satellites/names.js";
9
11
  import { CITY_NAMES_ATTRIBUTES, CITY_NAMES_STYLE, createCityHost } from "../cities/host.js";
12
+ import { BORDER_ATTRIBUTES, readBorders } from "../borders/lines.js";
13
+ import { GRID_ATTRIBUTES, readGrid } from "../grid/lines.js";
14
+ import { COUNTRY_NAMES_ATTRIBUTES } from "../country-names/geometry.js";
15
+ import { COUNTRY_NAMES_STYLE, createCountryHost } from "../country-names/host.js";
10
16
  import { createGate, frameCap } from "../realistic/gate.js";
11
17
  import { setThreeLoader, takeRenderer } from "../realistic/shared.js";
12
18
  import { NOTES_STYLE, setAirNote } from "../realistic/air-note.js";
19
+ import { IMMERSIVE_STYLE, immersiveWheel } from "../realistic/immersive.js";
13
20
  import { readMeteorStrength } from "../meteors/strength.js";
14
21
  import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
15
22
  import { MAX_TEXTURE } from "../realistic/tiers.js";
@@ -98,17 +105,25 @@ const readTime = (value) => {
98
105
  const ms = Date.parse(value);
99
106
  return Number.isFinite(ms) ? ms : "now";
100
107
  };
101
- const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden;isolation:isolate}#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}${PLACE_STYLE}${SKY_STYLE}${CITY_NAMES_STYLE}${METEOR_NOTE_STYLE}${NOTES_STYLE}`;
108
+ 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}${PLACE_STYLE}${SKY_STYLE}${COUNTRY_NAMES_STYLE}${CITY_NAMES_STYLE}${METEOR_NOTE_STYLE}${NOTES_STYLE}`;
102
109
  /**
103
110
  * 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.
104
111
  *
105
- * It carries kazoku-ui's controls itself: a drag turns the view, two fingers pinch, Ctrl and the wheel zoom (a plain wheel at Fit scrolls the page) and the arrow keys, + and - work once it is focused. The zoom runs from a millionth of Fit (the whole solar system) to 2.5 times, and from 0.5 to 6 times while riding from a body. `controls="none"` turns the hands off; `zoom-min` and `zoom-max` change the range. A `<kazoku-view-controls for="...">` on the element takes the hands over, and the page applies its events with `setView`.
112
+ * It carries kazoku-ui's controls itself: a drag turns the view, two fingers pinch, Ctrl and the wheel zoom (a plain wheel at Fit scrolls the page) and the arrow keys, + and - work once it is focused. The zoom runs from a millionth of Fit (the whole solar system) to 2.5 times, and from 0.5 to 6 times while riding from a body. `controls="none"` turns the hands off; `zoom-min` and `zoom-max` change the range. A `<kazoku-view-controls for="...">` on the element takes the hands over, and the page applies its events with `setView`. `immersive` is the full-screen mode: any shape of box, a plain wheel zooms and a drag anywhere turns.
113
+ *
114
+ * With a body painter that carries a `credit` (`setBodyPainter`), the credit of its pictures is written under the picture while it draws the bodies; `bodies-credit="off"` takes the line away.
106
115
  *
107
116
  * While time runs (`speed` is not 0) it sends `chikyu-timechange` with `detail: { time, running: true }`, `time` being the moment shown in milliseconds since 1970, at most four times a second however fast the picture is
108
117
  * drawn (and, with the clock at real time, as often as it steps: once a minute, or once a second with satellites or a ride on show), only while the tab is shown, and once with `running: false` when the clock holds
109
118
  * (`speed` set to 0): a page writes the date into its date box from it. It is not sent for a `time` the page sets itself. `chikyu-time` is the older event of every step the clock takes (up to thirty a second):
110
119
  * it is kept for pages that use it, but a page that shows the date wants `chikyu-timechange`.
111
120
  *
121
+ * `borders` draws the borders on the Earth's land as thin lines that turn with it, as on `<chikyu-earth-realistic>`: `countries`, `regions` (from the page's `borderData.regions`, once the Earth is
122
+ * large enough), or both with a bare attribute; `chikyu-borders-unavailable` is sent when the shapes cannot be loaded.
123
+ *
124
+ * `grid` draws the meridians and parallels on the Earth, and `country-names` names its countries, as on `<chikyu-earth-realistic>`: the names keep clear of the bodies', the places' and the
125
+ * cities' names and stay on the Earth's disc; `chikyu-country-names-unavailable` is sent when the outlines cannot be loaded.
126
+ *
112
127
  * @example
113
128
  * ```ts no-run
114
129
  * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
@@ -124,7 +139,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
124
139
  * ```
125
140
  */
126
141
  export class ChikyuSpace extends HTMLElement {
127
- 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, "air-thickness", "air-label", "lang", "places", "places-look"];
142
+ 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, ...COUNTRY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "bodies-credit"];
128
143
  #model = newSpaceModel();
129
144
  #mode = "now";
130
145
  #speed = 1;
@@ -135,13 +150,22 @@ export class ChikyuSpace extends HTMLElement {
135
150
  /** The names of the stars and the constellation lines (`star-names`, `constellation-lines`), and the look of the names. */
136
151
  #sky;
137
152
  #skyStyle = {};
153
+ #keepClear = [];
138
154
  /** The names of cities on the Earth (`city-names`), and the look of the names. */
139
155
  #cities;
140
156
  #citiesStyle = {};
157
+ /** The names of the countries on the Earth (`country-names`), and the look of the names. */
158
+ #countries;
159
+ #countriesStyle = {};
141
160
  #satNames = {};
161
+ /** A ringed satellite's name, by `group:index`, for `#satLabelLang`. The name does not depend on the moment, so a frame reads it and does not propagate the orbit again. */
162
+ #satLabelCache = new Map();
163
+ /** `en` or `ja` once that language has been read for the cached names; empty until the first read. */
164
+ #satLabelLang = "";
142
165
  /** The ringed satellites of the last draw (`labelSatellites`), laid out with the places. */
143
166
  #marks = [];
144
167
  #airNote;
168
+ #bodiesNote;
145
169
  #gate;
146
170
  #taken;
147
171
  #stage;
@@ -162,6 +186,8 @@ export class ChikyuSpace extends HTMLElement {
162
186
  #ridden = {};
163
187
  #placeLayer;
164
188
  #placeList = [];
189
+ /** Counts the turns to a place, so a new one stops the one before. */
190
+ #placeGlide = 0;
165
191
  #nameBoxes = new Map();
166
192
  /** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
167
193
  get controller() {
@@ -187,12 +213,13 @@ export class ChikyuSpace extends HTMLElement {
187
213
  if (!this.hasAttribute("aria-label"))
188
214
  this.setAttribute("aria-label", "The Earth, the Moon, the Sun and the planets in their places for the date shown");
189
215
  const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
190
- 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></div>`;
216
+ 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></div>`;
191
217
  adoptStyles(root, STYLE, this.nonce);
192
218
  this.#stage = root.getElementById("stage");
193
219
  this.#labelBox = root.getElementById("labels");
194
220
  this.#note = root.getElementById("meteor-note");
195
221
  this.#airNote = root.getElementById("air-note");
222
+ this.#bodiesNote = root.getElementById("bodies-note");
196
223
  this.#sky = createSkyHost({
197
224
  root,
198
225
  attribute: (name) => this.getAttribute(name),
@@ -201,20 +228,35 @@ export class ChikyuSpace extends HTMLElement {
201
228
  loadFont: loadMichroma,
202
229
  });
203
230
  this.#sky.setStyle(this.#skyStyle);
231
+ this.#sky.setKeepClear(this.#keepClear);
204
232
  this.#placeLayer = createPlaceLayer(root.getElementById("places"));
205
233
  this.#placeList = readPlaces(this.getAttribute("places"));
206
234
  this.#placeLayer.set(this.#placeList);
207
235
  this.#placeLayer.look = readPlaceLook(this.getAttribute("places-look"));
236
+ this.#placeLayer.grouping = readPlaceGroups(this.getAttribute("place-groups"));
208
237
  this.#cities = createCityHost({
209
238
  root,
210
239
  attribute: (name) => this.getAttribute(name),
211
240
  language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
212
241
  onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-city-names-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
242
+ onLayout: () => this.#countryFrame(),
213
243
  });
214
244
  this.#cities.setStyle(this.#citiesStyle);
245
+ Object.assign(this.#model.borders, readBorders(this.getAttribute("borders")));
246
+ this.#model.borders.onError = (error) => this.dispatchEvent(new CustomEvent("chikyu-borders-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } }));
247
+ this.#model.grid.on = readGrid(this.getAttribute("grid"));
248
+ this.#model.grid.onError = (error) => this.dispatchEvent(new CustomEvent("chikyu-grid-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } }));
249
+ this.#countries = createCountryHost({
250
+ root,
251
+ attribute: (name) => this.getAttribute(name),
252
+ language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
253
+ onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-country-names-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
254
+ });
255
+ this.#countries.setStyle(this.#countriesStyle);
215
256
  this.#model.airThickness = readAirThickness(this.getAttribute("air-thickness"));
216
257
  this.#applyBodyLabel();
217
258
  setAirNote(this.#airNote, this, this.#model.airThickness);
259
+ this.#showBodiesCredit();
218
260
  this.#played = false;
219
261
  this.#model.meteors.on = this.#meteorsAsked();
220
262
  this.#model.meteors.strength = readMeteorStrength(this.getAttribute("meteors-strength"));
@@ -244,12 +286,14 @@ export class ChikyuSpace extends HTMLElement {
244
286
  onLabels: (places) => this.#placeLabels(places),
245
287
  onSky: (sky) => this.#sky?.frame(sky),
246
288
  onPlaces: (view) => this.#drawPlaces(view),
247
- onCities: (frame) => this.#cities?.frame(frame),
289
+ placeSprites: () => this.#placeLayer?.sprites ?? null,
290
+ onCities: (frame) => this.#nameFrame(frame),
248
291
  onLabelError: (error) => this.dispatchEvent(new CustomEvent("chikyu-body-label-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
249
292
  onSatelliteMarks: (marks) => this.#showMarks(marks),
250
293
  onSelected: (place) => this.#placeChosen(place),
251
294
  onMoving: () => this.#gate?.request(),
252
295
  onRideLost: () => this.#rideLost(),
296
+ onPlaceRings: (drawn) => this.#ringsDrawn(drawn),
253
297
  onSatellitesError: (error) => this.dispatchEvent(new CustomEvent("chikyu-satellites-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
254
298
  ...(painter ? { painter } : {}),
255
299
  satellitePainter: () => satellitePainter,
@@ -268,6 +312,8 @@ export class ChikyuSpace extends HTMLElement {
268
312
  this.#last = performance.now();
269
313
  this.#schedule();
270
314
  this.addEventListener("pointerdown", this.#down);
315
+ // before the shared hands (which hear it after this): a plain wheel in an immersive view zooms
316
+ this.addEventListener("wheel", this.#wheel, { capture: true, passive: false });
271
317
  this.#hands = carryControls(this, { initial: this.#model.view, limits: LIMITS, onChange: (state, info) => this.setView(state, info.final) });
272
318
  this.#labelBox.addEventListener("click", this.#labelClick);
273
319
  this.#labelBox.addEventListener("focusin", this.#labelFocus);
@@ -277,6 +323,7 @@ export class ChikyuSpace extends HTMLElement {
277
323
  this.#hands = undefined;
278
324
  this.#zoomRange(false);
279
325
  this.removeEventListener("pointerdown", this.#down);
326
+ this.removeEventListener("wheel", this.#wheel, { capture: true });
280
327
  window.removeEventListener("pointerup", this.#up, true);
281
328
  clearTimeout(this.#timer);
282
329
  this.#timer = undefined;
@@ -290,6 +337,8 @@ export class ChikyuSpace extends HTMLElement {
290
337
  this.#placeLayer?.dispose();
291
338
  this.#placeLayer = undefined;
292
339
  this.#cities?.dispose();
340
+ this.#countries?.dispose();
341
+ this.#countries = undefined;
293
342
  this.#cities = undefined;
294
343
  }
295
344
  attributeChangedCallback(name, _old, value) {
@@ -337,6 +386,7 @@ export class ChikyuSpace extends HTMLElement {
337
386
  this.#applyBodyLabel();
338
387
  this.#sky?.refresh();
339
388
  this.#cities?.refresh();
389
+ this.#countries?.refresh();
340
390
  }
341
391
  }
342
392
  else if (BODY_LABEL_ATTRIBUTES.includes(name))
@@ -352,10 +402,48 @@ export class ChikyuSpace extends HTMLElement {
352
402
  this.#placeLayer.look = readPlaceLook(value);
353
403
  this.#gate?.request();
354
404
  }
405
+ else if (name === "place-groups" && this.#placeLayer) {
406
+ this.#placeLayer.grouping = readPlaceGroups(value);
407
+ this.#gate?.request();
408
+ }
355
409
  else if (CITY_NAMES_ATTRIBUTES.includes(name))
356
410
  this.#cities?.refresh();
411
+ else if (name === "borders") {
412
+ Object.assign(this.#model.borders, readBorders(value));
413
+ this.#gate?.request();
414
+ }
415
+ else if (name === "grid") {
416
+ this.#model.grid.on = readGrid(value);
417
+ this.#gate?.request();
418
+ }
419
+ else if (COUNTRY_NAMES_ATTRIBUTES.includes(name))
420
+ this.#countries?.refresh();
357
421
  if (name === "air-thickness" || name === "air-label" || name === "lang")
358
422
  setAirNote(this.#airNote, this, this.#model.airThickness);
423
+ if (name === "bodies-credit" || name === "lang")
424
+ this.#showBodiesCredit();
425
+ }
426
+ #wheel = (event) => immersiveWheel(this, event);
427
+ /** The body painter's credit under the picture, in the element's or the page's language: shown while the painter draws the bodies (not `plain`), unless `bodies-credit` is `off`. */
428
+ #showBodiesCredit() {
429
+ const note = this.#bodiesNote;
430
+ if (!note)
431
+ return;
432
+ const lang = (this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en";
433
+ const credit = painter?.credit?.[lang] ?? "";
434
+ note.textContent = credit;
435
+ note.lang = lang;
436
+ note.hidden = credit === "" || this.bodies === "plain" || this.getAttribute("bodies-credit") === "off";
437
+ }
438
+ /**
439
+ * True for the full-screen mode (the `immersive` attribute): the element fills its box in any shape (the Earth fits the shorter side with its glow inside it, `earth-size`), a plain wheel zooms instead of scrolling
440
+ * the page, a drag anywhere on it turns the view, and a touch drag turns it instead of scrolling. A notch of the wheel is about 1.2 times; out far enough the Moon, the Sun and the planets come into view.
441
+ */
442
+ get immersive() {
443
+ return this.hasAttribute("immersive");
444
+ }
445
+ set immersive(value) {
446
+ this.toggleAttribute("immersive", value);
359
447
  }
360
448
  #meteorsAsked() {
361
449
  return this.hasAttribute("meteors") && this.getAttribute("meteors") !== "off";
@@ -434,10 +522,35 @@ export class ChikyuSpace extends HTMLElement {
434
522
  this.#sky?.setStyle(this.#skyStyle);
435
523
  }
436
524
  /**
437
- * Places marked on the Earth (the attribute `places`, a JSON array): each `{ id, lon, lat, label, kind }`, `kind` being `here` (where the reader is: drawn bright and taller, with a quiet pulse) or `favourite`
438
- * (the default: quieter). Each stands up out of the ground, turns with the Earth, is hidden on its far side and keeps its size in pixels at any zoom. Names go at the top, `here` first, and never overlap
439
- * 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 over and keeps them where it likes. Setting the property writes
440
- * 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 and for a reader who asked for less motion.
525
+ * The constellation that is picked, by its IAU abbreviation (`Ori`), or `null`. A reader picks one by a click or a tap on its lines or inside its figure (and with the key `C`, or `Shift`+`C` for the previous, while the element has the focus); a click on empty sky, or `Escape`, lets it go. The picked figure's lines are lit and its name is
526
+ * shown at the middle of the part of it in view, until another is picked or it is let go. A page sets the property to pick one itself, which sends no event. `chikyu-constellation-pick` is sent at each pick of the reader's, with `detail` `{ abbreviation, id, name, english, japanese, kind, culture }` (`culture` is `iau` unless `constellation-culture` names another), and `null` when it is let go; `chikyu-constellation-hover` is sent the same way as a mouse rests on a figure and leaves it.
527
+ * Needs `constellation-lines` set. `constellation-culture` (`iau` by default, `western`, `japanese` or `chinese`; each is fetched only when asked for, and the value is exactly what the page sets) makes the figures, the pick and the names those of that sky culture. The attribute `constellation-names` (off by default) writes the name of every figure in view at the middle of the part of it that is on the picture, quieter than the star names and clear of them, of the Earth, the Moon, the Sun, the places and satellites named, and of the places kept clear (`keepClear`).
528
+ */
529
+ get constellation() {
530
+ return this.#sky?.picked ?? null;
531
+ }
532
+ set constellation(value) {
533
+ this.#sky?.pick(value);
534
+ }
535
+ /**
536
+ * Places on the picture where the sky's names must not go: a page's own text laid over the element, say. Each is a rectangle in the element's own CSS pixels from its top left (`{ x, y, width, height }`), or an element of the page whose box is read. A star name whose box touches
537
+ * one is left out, and so is a star whose point is in one (the next star is named instead); the picked constellation's name is moved clear of it. The lines are still drawn. The boxes are read when the list changes, when the page or an element is resized or scrolled, and not at each frame: a
538
+ * page that moves its text without resizing it sets the property again. The attribute `keep-clear` takes a CSS selector for the same (`keep-clear=".hero h1, .hero .lead"`). Nothing is redrawn at rest.
539
+ */
540
+ get keepClear() {
541
+ return [...this.#keepClear];
542
+ }
543
+ set keepClear(value) {
544
+ this.#keepClear = value ? [...value] : [];
545
+ this.#sky?.setKeepClear(this.#keepClear);
546
+ }
547
+ /**
548
+ * Places marked on the Earth (the attribute `places`, a JSON array): each `{ id, lon, lat, label, kind, color }`, `kind` being `here` (where the reader is: drawn bright and taller, with a quiet pulse) or `favourite`
549
+ * (the default: quieter), and `color` an optional CSS colour of its own. The first `PLACE_MARKS` in sight (`here` first, then in the order given) stand up out of the ground with their names; every other place
550
+ * 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
551
+ * 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
552
+ * 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
553
+ * and for a reader who asked for less motion.
441
554
  */
442
555
  get places() {
443
556
  return this.#placeList.map((place) => ({ ...place }));
@@ -449,6 +562,54 @@ export class ChikyuSpace extends HTMLElement {
449
562
  else
450
563
  this.setAttribute("places", JSON.stringify(clean));
451
564
  }
565
+ /**
566
+ * 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.
567
+ * 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
568
+ * way, so a place more than 90 degrees of latitude from `center` comes as near the middle as that allows.
569
+ *
570
+ * @param text - The place's id or label.
571
+ * @param options - `smooth` (true by default).
572
+ * @returns The place, once the turn has started; `undefined` when there is no such place or the camera is not looking at the Earth.
573
+ */
574
+ async goToPlace(text, options = {}) {
575
+ const place = findPlace(this.#placeList, text);
576
+ const base = this.#model.lookBase;
577
+ if (!place || !base || this.#model.ride)
578
+ return undefined;
579
+ const controls = this.#controls();
580
+ const from = { yaw: this.#model.view.yaw, tilt: this.#model.view.tilt };
581
+ const to = aimAt(base, place, from);
582
+ const glide = (this.#placeGlide += 1);
583
+ const set = (yaw, tilt, final) => {
584
+ if (controls)
585
+ controls.set({ yaw, tilt, zoom: this.#model.view.zoom }, final, "place");
586
+ else
587
+ this.setView({ yaw, tilt, zoom: this.#model.view.zoom }, final);
588
+ };
589
+ glideView(set, from, to, options.smooth !== false && !prefersLessMotion() && this.#view?.live === true, () => glide === this.#placeGlide && this.isConnected);
590
+ return { ...place };
591
+ }
592
+ /**
593
+ * 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.
594
+ */
595
+ get placeGroups() {
596
+ return this.#placeLayer?.grouping ?? readPlaceGroups(this.getAttribute("place-groups"));
597
+ }
598
+ set placeGroups(value) {
599
+ if (value)
600
+ this.removeAttribute("place-groups");
601
+ else
602
+ this.setAttribute("place-groups", "off");
603
+ }
604
+ /** 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 and the page is told once, so no place is lost without a word. */
605
+ #ringsDrawn(drawn) {
606
+ if (!this.#placeLayer || this.#placeLayer.ringsInPicture === drawn)
607
+ return;
608
+ this.#placeLayer.ringsInPicture = drawn;
609
+ if (!drawn)
610
+ this.dispatchEvent(new CustomEvent("chikyu-places-unavailable", { detail: { reason: "the three.js parts handed over lack Points: the places' rings are drawn as small circles in the page, at most 600, and stats.places.omitted counts the rest" } }));
611
+ this.#gate?.request();
612
+ }
452
613
  /** 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). */
453
614
  get placesLook() {
454
615
  return this.#placeLayer?.look ?? readPlaceLook(this.getAttribute("places-look"));
@@ -461,6 +622,26 @@ export class ChikyuSpace extends HTMLElement {
461
622
  const layer = this.#placeLayer;
462
623
  if (!layer || (this.#placeList.length === 0 && this.#marks.length === 0 && layer.stats.shown === 0 && layer.stats.rings === 0))
463
624
  return;
625
+ layer.frame(view, this.#bodyNameBoxes(), this.#marks, this.#model.light === "lit" ? null : subsolarPoint(this.#model.time));
626
+ }
627
+ /** Tells the names of cities, then of countries, where the Earth is in the picture just drawn; the countries' names keep clear of the bodies', the places' and the cities'. */
628
+ #nameFrame(frame) {
629
+ this.#cities?.frame(frame);
630
+ this.#lastNameFrame = frame;
631
+ this.#countryFrame();
632
+ }
633
+ /** The frame the names were last laid out on. */
634
+ #lastNameFrame = null;
635
+ /** Lays the countries' names out on the last frame, clear of the bodies', the places' and the cities' names as they are now. */
636
+ #countryFrame() {
637
+ const countries = this.#countries;
638
+ if (!countries)
639
+ return;
640
+ const frame = this.#lastNameFrame;
641
+ countries.frame(frame, countries.stats.on && frame ? [...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? [])] : []);
642
+ }
643
+ /** The boxes the bodies' names take beside them in the picture just drawn. */
644
+ #bodyNameBoxes() {
464
645
  const taken = [];
465
646
  if (this.#model.labels && this.#places) {
466
647
  for (const name of BODY_NAMES) {
@@ -479,7 +660,7 @@ export class ChikyuSpace extends HTMLElement {
479
660
  taken.push({ left: at.x + Math.max(4, Math.min(at.r, 40)), top: at.y - 8, ...box });
480
661
  }
481
662
  }
482
- layer.frame(view, taken, this.#marks);
663
+ return taken;
483
664
  }
484
665
  /**
485
666
  * The look of the names of cities (`city-names`): font, size, weight, colour, the outline round the text, and the dot's colour and size. Any of them may be left out; the Earth's size, the language and the data are not set here.
@@ -491,6 +672,52 @@ export class ChikyuSpace extends HTMLElement {
491
672
  this.#citiesStyle = { ...value };
492
673
  this.#cities?.setStyle(this.#citiesStyle);
493
674
  }
675
+ /** Whether the meridians and parallels are drawn on the Earth (the attribute `grid`). Setting it writes the attribute, or takes it away. */
676
+ get grid() {
677
+ return readGrid(this.getAttribute("grid"));
678
+ }
679
+ set grid(value) {
680
+ if (value)
681
+ this.setAttribute("grid", "");
682
+ else
683
+ this.removeAttribute("grid");
684
+ }
685
+ /**
686
+ * The look of the names of countries (`country-names`): font, weight, colour, the outline round the text, and the smallest and largest text size. Any of them may be left out; the Earth's size, the
687
+ * language and the data are not set here.
688
+ */
689
+ get countryNamesStyle() {
690
+ return { ...this.#countriesStyle };
691
+ }
692
+ set countryNamesStyle(value) {
693
+ this.#countriesStyle = { ...value };
694
+ this.#countries?.setStyle(this.#countriesStyle);
695
+ }
696
+ /**
697
+ * Which borders are drawn on the Earth (the attribute `borders`): the countries' at any size, and the regions' (provinces, states, prefectures) once the Earth is large enough on the screen to tell them apart.
698
+ * Setting it writes the attribute: both sets as `borders="countries regions"`, one as its own word, none takes the attribute away.
699
+ */
700
+ get borders() {
701
+ return readBorders(this.getAttribute("borders"));
702
+ }
703
+ set borders(value) {
704
+ const words = [value.countries ? "countries" : "", value.regions ? "regions" : ""].filter(Boolean);
705
+ if (words.length === 0)
706
+ this.removeAttribute("borders");
707
+ else
708
+ this.setAttribute("borders", words.join(" "));
709
+ }
710
+ /**
711
+ * Where the borders' shapes come from (see `BorderData`): `countries` in place of chizu's `world-geo`, and `regions`, a country's regions by its code, which draws the regions; without it none are drawn.
712
+ * Set it before `borders` is switched on: shapes already loaded are kept.
713
+ */
714
+ get borderData() {
715
+ return { ...this.#model.borders.data };
716
+ }
717
+ set borderData(value) {
718
+ this.#model.borders.data = { ...value };
719
+ this.#gate?.request();
720
+ }
494
721
  /** Puts the name's settings and text right from the attributes (`body-label` and its family, `lang`). */
495
722
  #applyBodyLabel() {
496
723
  this.#model.bodyLabel.settings = readBodyLabel((name) => this.getAttribute(name));
@@ -610,6 +837,7 @@ export class ChikyuSpace extends HTMLElement {
610
837
  }
611
838
  set bodies(value) {
612
839
  this.#model.bodies = value;
840
+ this.#showBodiesCredit();
613
841
  this.#gate?.request();
614
842
  }
615
843
  /** How the Earth is lit: `sun` (true, the default), `lit` (always lit, as if by daylight from the camera's side, so a ride on the night side is never a black frame) or `boost` (the true terminator, with the night side raised). The Sun, the Moon and the planets keep their true places. */
@@ -714,7 +942,9 @@ export class ChikyuSpace extends HTMLElement {
714
942
  this.#focusBeforeRide = model.focus;
715
943
  // the heading starts from the yaw the controls already hold (an address that carries `yaw` is read before the ride begins), so a ride opened from the address looks where the one that was dragged there looked
716
944
  model.rideTurn = rideTurnDegrees(model.view.yaw, model.view.zoom);
717
- const view = typeof target === "string" && target === "Earth" ? "follow" : (options.view ?? "from");
945
+ const asked = options.view ?? "from";
946
+ // above a body is meant for a satellite: a body is followed
947
+ const view = typeof target === "string" && (target === "Earth" || asked === "above") ? "follow" : asked;
718
948
  model.ride = { target: typeof target === "string" ? target : { group: target.group, index: target.index }, view, look: options.look ?? "down", distanceKm: Math.max(100, options.distanceKm ?? 3000) };
719
949
  if (typeof target === "string" && view === "follow")
720
950
  model.focus = target;
@@ -754,6 +984,7 @@ export class ChikyuSpace extends HTMLElement {
754
984
  const out = [];
755
985
  if (!satellitePainter)
756
986
  return out;
987
+ this.#prepareSatLabelLang();
757
988
  for (const [group, state] of this.#model.satellites.groups) {
758
989
  state.satellites.sets.forEach((set, index) => {
759
990
  if (satellitePainter.has(set.NORAD_CAT_ID))
@@ -816,6 +1047,8 @@ export class ChikyuSpace extends HTMLElement {
816
1047
  visible: was?.visible ?? true,
817
1048
  });
818
1049
  }
1050
+ // a group's index may now be a different satellite, so a cached name for that ref is no longer its name
1051
+ this.#satLabelCache.clear();
819
1052
  this.#last = performance.now();
820
1053
  this.#schedule();
821
1054
  this.#gate?.request();
@@ -873,6 +1106,7 @@ export class ChikyuSpace extends HTMLElement {
873
1106
  }
874
1107
  set satelliteNames(value) {
875
1108
  this.#satNames = { ...value };
1109
+ this.#satLabelCache.clear();
876
1110
  this.#gate?.request();
877
1111
  }
878
1112
  /**
@@ -882,17 +1116,37 @@ export class ChikyuSpace extends HTMLElement {
882
1116
  placeSatellite(ref) {
883
1117
  return this.#model.placeSatellite?.(ref) ?? null;
884
1118
  }
885
- /** The name beside a ringed satellite: the page's own (`satelliteNames`), else the short one in the page's language, else the name in its elements. */
1119
+ /** The page's language for a satellite name: Japanese when the nearest `lang` starts with `ja`, otherwise English. Read once per pass, not once per satellite. */
1120
+ #readSatLabelLang() {
1121
+ return (this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en";
1122
+ }
1123
+ /** Remember the page's language and drop cached names when it changes. One `closest("[lang]")` for the pass. */
1124
+ #prepareSatLabelLang() {
1125
+ const lang = this.#readSatLabelLang();
1126
+ if (lang !== this.#satLabelLang) {
1127
+ this.#satLabelCache.clear();
1128
+ this.#satLabelLang = lang;
1129
+ }
1130
+ }
1131
+ /** The name beside a ringed satellite: the page's own (`satelliteNames`), else the short one in the page's language, else the name in its elements. Cached per ref and language: the name is constant, and reading it does not propagate the orbit again. */
886
1132
  #satelliteName(ref) {
1133
+ const key = `${ref.group}:${ref.index}`;
1134
+ const cached = this.#satLabelCache.get(key);
1135
+ if (cached !== undefined)
1136
+ return cached;
887
1137
  const info = this.satelliteInfo(ref);
888
1138
  if (!info)
889
1139
  return "";
890
- const lang = (this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en";
891
- return this.#satNames[info.noradId] ?? SHORT_NAMES[info.noradId]?.[lang] ?? info.name;
1140
+ const lang = this.#satLabelLang === "ja" ? "ja" : "en";
1141
+ const name = this.#satNames[info.noradId] ?? SHORT_NAMES[info.noradId]?.[lang] ?? info.name;
1142
+ this.#satLabelCache.set(key, name);
1143
+ return name;
892
1144
  }
893
1145
  #markSeen = new Map();
894
1146
  /** Hands the places layer the ringed satellites of this draw, and tells the page when one comes into view or goes out of it. */
895
1147
  #showMarks(marks) {
1148
+ if (marks.length > 0)
1149
+ this.#prepareSatLabelLang();
896
1150
  this.#marks = marks.map((m) => ({ id: `${m.ref.group}:${m.ref.index}`, label: this.#satelliteName(m.ref), x: m.x, y: m.y, visible: m.visible }));
897
1151
  const now = new Map();
898
1152
  for (const m of marks) {
@@ -975,13 +1229,16 @@ export class ChikyuSpace extends HTMLElement {
975
1229
  satellites: this.#satelliteStats(),
976
1230
  ride: { riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null },
977
1231
  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 },
978
- bodies: { look: this.#model.bodies || painter?.looks?.[0] || "plain", painted: this.#model.painted.bodies, moons: this.#model.painted.moons },
1232
+ 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 },
979
1233
  meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
980
1234
  bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
981
- sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, renders: 0, lang: "", stars: [] },
1235
+ 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: [] },
982
1236
  followModel: this.#model.followModel,
983
- places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0 }) },
1237
+ places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, omitted: 0 }) },
984
1238
  cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
1239
+ borders: { ...this.#model.borders.stats, shown: { ...this.#model.borders.stats.shown }, loaded: [...this.#model.borders.stats.loaded] },
1240
+ grid: { ...this.#model.grid.stats },
1241
+ countryNames: this.#countries?.stats ?? { on: false, max: 0, countries: 0, names: 0, renders: 0, failed: false },
985
1242
  };
986
1243
  }
987
1244
  #satelliteStats() {
@@ -1,6 +1,6 @@
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 PaintContext, type SatellitePainter } from "./scene.ts";
3
+ export { fitDistance, plainPainter, type BodyDrawing, type BodyMoon, type BodyPainter, type BodyView, type PaintContext, type SatellitePainter } from "./scene.ts";
4
4
  export { RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideInput, type RideLook, type RidePose } from "./ride.ts";
5
5
  export type { SatelliteScreen } from "./satellite-layer.ts";
6
- export { MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
6
+ export { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
@@ -4,4 +4,4 @@ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitP
4
4
  export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition } from "./scale.js";
5
5
  export { fitDistance, plainPainter } from "./scene.js";
6
6
  export { RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
7
- export { MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
7
+ export { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
@@ -31,6 +31,28 @@ export declare function satelliteAxes(position: Vec3, velocity: Vec3): {
31
31
  y: Vec3;
32
32
  z: Vec3;
33
33
  } | null;
34
+ /**
35
+ * The camera of the view above a satellite: where it stands from the satellite (a unit vector, to be multiplied by the height) and the way its picture's top points. With no turn and no tip the camera is straight above the satellite, looking straight down at it, the way the satellite is going at the top of
36
+ * the picture. `yaw` turns the picture about the satellite (the top points the other way round the satellite); `tilt` tips the camera back (positive) or ahead of the satellite (negative), so it looks down at it from behind or in front.
37
+ *
38
+ * @param position - The satellite's place from the Earth's centre.
39
+ * @param velocity - Its velocity.
40
+ * @param yaw - The turn of the picture about the satellite, in radians.
41
+ * @param tilt - How far the camera is tipped back from straight above, in radians.
42
+ * @returns The unit offset of the camera from the satellite, and the unit vector at the top of its picture.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * import { aboveAxes } from "@johnmorrisdotca/chikyu-earth/space";
47
+ *
48
+ * const view = aboveAxes([1.07, 0, 0], [0, 0, 1], 0, 0);
49
+ * console.log(view.offset, view.up);
50
+ * ```
51
+ */
52
+ export declare function aboveAxes(position: Vec3, velocity: Vec3, yaw: number, tilt: number): {
53
+ offset: Vec3;
54
+ up: Vec3;
55
+ };
34
56
  /**
35
57
  * The 4 by 4 matrix, row by row (what three.js's `Matrix4.set` takes), that puts a model of radius 1 at a place, turned to the satellite's axes and scaled: its columns are the axes times the scale, then the place.
36
58
  *
@@ -40,6 +40,44 @@ export function satelliteAxes(position, velocity) {
40
40
  const y = [z[1] * x[2] - z[2] * x[1], z[2] * x[0] - z[0] * x[2], z[0] * x[1] - z[1] * x[0]];
41
41
  return { x, y, z };
42
42
  }
43
+ /**
44
+ * The camera of the view above a satellite: where it stands from the satellite (a unit vector, to be multiplied by the height) and the way its picture's top points. With no turn and no tip the camera is straight above the satellite, looking straight down at it, the way the satellite is going at the top of
45
+ * the picture. `yaw` turns the picture about the satellite (the top points the other way round the satellite); `tilt` tips the camera back (positive) or ahead of the satellite (negative), so it looks down at it from behind or in front.
46
+ *
47
+ * @param position - The satellite's place from the Earth's centre.
48
+ * @param velocity - Its velocity.
49
+ * @param yaw - The turn of the picture about the satellite, in radians.
50
+ * @param tilt - How far the camera is tipped back from straight above, in radians.
51
+ * @returns The unit offset of the camera from the satellite, and the unit vector at the top of its picture.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { aboveAxes } from "@johnmorrisdotca/chikyu-earth/space";
56
+ *
57
+ * const view = aboveAxes([1.07, 0, 0], [0, 0, 1], 0, 0);
58
+ * console.log(view.offset, view.up);
59
+ * ```
60
+ */
61
+ export function aboveAxes(position, velocity, yaw, tilt) {
62
+ let axes = satelliteAxes(position, velocity);
63
+ if (!axes) {
64
+ // no way it is going (or no place): any level direction will do
65
+ const length = Math.hypot(position[0], position[1], position[2]);
66
+ const z = length > 0 ? [position[0] / length, position[1] / length, position[2] / length] : [1, 0, 0];
67
+ const from = Math.abs(z[1]) < 0.9 ? [0, 1, 0] : [1, 0, 0];
68
+ const cross = [from[1] * z[2] - from[2] * z[1], from[2] * z[0] - from[0] * z[2], from[0] * z[1] - from[1] * z[0]];
69
+ const size = Math.hypot(cross[0], cross[1], cross[2]) || 1;
70
+ const x = [cross[0] / size, cross[1] / size, cross[2] / size];
71
+ axes = { x, y: [z[1] * x[2] - z[2] * x[1], z[2] * x[0] - z[0] * x[2], z[0] * x[1] - z[1] * x[0]], z };
72
+ }
73
+ const { x, y, z } = axes;
74
+ const cy = Math.cos(yaw);
75
+ const sy = Math.sin(yaw);
76
+ const top = [cy * x[0] + sy * y[0], cy * x[1] + sy * y[1], cy * x[2] + sy * y[2]];
77
+ const ct = Math.cos(tilt);
78
+ const st = Math.sin(tilt);
79
+ return { offset: [ct * z[0] - st * top[0], ct * z[1] - st * top[1], ct * z[2] - st * top[2]], up: top };
80
+ }
43
81
  /**
44
82
  * The 4 by 4 matrix, row by row (what three.js's `Matrix4.set` takes), that puts a model of radius 1 at a place, turned to the satellite's axes and scaled: its columns are the axes times the scale, then the place.
45
83
  *