@johnmorrisdotca/chikyu-earth 0.61.0 → 0.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +2 -2
- package/dist/realistic/cloud-fade.d.ts +22 -0
- package/dist/realistic/cloud-fade.js +44 -0
- package/dist/realistic/earth.d.ts +3 -0
- package/dist/realistic/earth.js +6 -1
- package/dist/realistic/element-base.d.ts +2 -0
- package/dist/realistic/element-base.js +8 -1
- package/dist/realistic/shaders.d.ts +1 -1
- package/dist/realistic/shaders.js +10 -0
- package/dist/space/element-base.d.ts +88 -1
- package/dist/space/element-base.js +213 -27
- package/dist/space/fly.d.ts +292 -0
- package/dist/space/fly.js +293 -0
- package/dist/space/index.d.ts +1 -0
- package/dist/space/index.js +1 -0
- package/dist/space/scene.d.ts +5 -0
- package/dist/space/scene.js +12 -3
- package/package.json +1 -1
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { carryControls, wrapYaw } from "@johnmorrisdotca/kazoku-ui/view-controls";
|
|
2
2
|
import { adoptStyles } from "../adopt.js";
|
|
3
3
|
import { airFor, readAirThickness } from "../realistic/air.js";
|
|
4
|
+
import { readCloudFade } from "../realistic/cloud-fade.js";
|
|
4
5
|
import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "../realistic/body-label.js";
|
|
5
6
|
import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
|
|
6
7
|
import { cleanPlaces, readPlaceGroups, readPlaceLayers, readPlaces } from "../markers/places.js";
|
|
7
8
|
import { readHereCity } from "../markers/here-city.js";
|
|
8
9
|
import { createHereCity } from "../markers/here-city-host.js";
|
|
9
10
|
import { createPlaceLayer, PLACE_STYLE, placeClick, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
|
|
10
|
-
import { aimAt, findPlace,
|
|
11
|
+
import { aimAt, findPlace, PLACE_GLIDE_MS } from "../markers/go-to-place.js";
|
|
11
12
|
import { subsolarPoint } from "../realistic/sun.js";
|
|
12
13
|
import { SHORT_NAMES } from "../satellites/names.js";
|
|
13
14
|
import { CITY_NAMES_ATTRIBUTES, CITY_NAMES_STYLE, createCityHost } from "../cities/host.js";
|
|
@@ -31,6 +32,7 @@ import { readMeteorStrength } from "../meteors/strength.js";
|
|
|
31
32
|
import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
|
|
32
33
|
import { MAX_TEXTURE } from "../realistic/tiers.js";
|
|
33
34
|
import { trailOrbits } from "./trail.js";
|
|
35
|
+
import { descentFloorKm, FLY_HEIGHT_KM, FLY_MIN_KM, flyAim, flyAt, flyDistance, flyLonLat, flyStateAt, flyStill, planFly } from "./fly.js";
|
|
34
36
|
import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt } from "./ephemeris.js";
|
|
35
37
|
import { MAX_ORBIT_GROUP, readStreakMax } from "./satellite-layer.js";
|
|
36
38
|
import { applySatelliteFocus, satelliteEmphasis, satelliteGroupRows, shellRadiusOf, zoomForPerspectiveShell } from "./satellite-focus.js";
|
|
@@ -109,6 +111,8 @@ const TIME_EVENT_MS = 250;
|
|
|
109
111
|
* Riding at a body looking at the Earth, the zoom only narrows the camera's field a little either way: 0.5 to 6.
|
|
110
112
|
*/
|
|
111
113
|
const LIMITS = { tiltMax: 90, zoomMin: 0.000001, zoomMax: 2.5 };
|
|
114
|
+
/** What the controls say a reader's own hand did: any of these ends a fly-to where it is. */
|
|
115
|
+
const HANDS = new Set(["drag", "pinch", "wheel", "key", "zoom", "pan", "front", "fit"]);
|
|
112
116
|
/** A number from an attribute, held between `min` and `max`; `null` when it is absent or not a number. */
|
|
113
117
|
function readFrame(value, min, max) {
|
|
114
118
|
if (value === null || value.trim() === "")
|
|
@@ -196,7 +200,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
|
|
|
196
200
|
* ```
|
|
197
201
|
*/
|
|
198
202
|
export class ChikyuSpace extends HTMLElement {
|
|
199
|
-
static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...BEAM_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "place-layers", "here-city", "route", "bodies-credit", "satellite-tint", "satellite-streak-max", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "ride-viewpoint", "ride-outside-km", "ride-model-size", "ride-drag", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far", "follow", "follow-ease", "dim-occluded", "ride-model-share", "ride-model-seat", "ride-zoom", "ride-up", "compass", "smooth-fps"];
|
|
203
|
+
static observedAttributes = ["cloud-drift", "cloud-fade", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...BEAM_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "place-layers", "here-city", "route", "bodies-credit", "satellite-tint", "satellite-streak-max", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "ride-viewpoint", "ride-outside-km", "ride-model-size", "ride-drag", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far", "follow", "follow-ease", "dim-occluded", "ride-model-share", "ride-model-seat", "ride-zoom", "ride-up", "compass", "smooth-fps"];
|
|
200
204
|
#model = newSpaceModel();
|
|
201
205
|
/** The finer imagery (NASA's tile service), one source while the attributes stay the same. Off unless `tiles-finer="gibs"`. */
|
|
202
206
|
#finerHold = createFinerHolder(() => new Date(this.#model.time), () => this.#gate?.request());
|
|
@@ -270,8 +274,15 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
270
274
|
/** Whether the page has been told that places in sight were left undrawn. */
|
|
271
275
|
#placesLost = { told: false };
|
|
272
276
|
#placeList = [];
|
|
273
|
-
/** Counts the
|
|
274
|
-
#
|
|
277
|
+
/** Counts the moves asked for (`flyTo`, `goToPlace`), so one still finding its floor gives way to a later one. */
|
|
278
|
+
#flyAsks = 0;
|
|
279
|
+
/** The move running (`flyTo`, `goToPlace`): its plan and how to end it. */
|
|
280
|
+
#flight = null;
|
|
281
|
+
#flyStats = { moves: 0, redirects: 0, held: null };
|
|
282
|
+
/** A frame of the move is asked for and not yet run. */
|
|
283
|
+
#flyAsked = false;
|
|
284
|
+
/** The zoom limit under the attributes: the controls' own, raised once a fly-to has come lower. */
|
|
285
|
+
#flyZoomMax = LIMITS.zoomMax;
|
|
275
286
|
#nameBoxes = new Map();
|
|
276
287
|
/** A font that arrives after the names were measured: the boxes are read again on the next layout. The satellites' marks are not touched, or the page would be told again about each one already in view. */
|
|
277
288
|
#onFonts = () => {
|
|
@@ -294,6 +305,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
294
305
|
this.#model.light = readLight(this.getAttribute("light"));
|
|
295
306
|
this.#model.camera = readCamera(this.getAttribute("camera"));
|
|
296
307
|
this.#model.cloudDrift = Number.isFinite(Number(this.getAttribute("cloud-drift") ?? "0")) ? Number(this.getAttribute("cloud-drift") ?? "0") : 0;
|
|
308
|
+
this.#model.cloudFade = readCloudFade(this.getAttribute("cloud-fade"));
|
|
297
309
|
this.#model.earth = { size: readNumber(this.getAttribute("earth-size"), DEFAULT_EARTH_SIZE, 0.02, 50), x: readNumber(this.getAttribute("earth-x"), 0.5, -2, 3), y: readNumber(this.getAttribute("earth-y"), 0.5, -2, 3) };
|
|
298
310
|
this.#model.stepMs = Math.max(1000, Math.abs(this.#speed) * 1000);
|
|
299
311
|
this.#model.speed = this.#speed;
|
|
@@ -461,7 +473,16 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
461
473
|
this.addEventListener("keydown", this.#faceKey);
|
|
462
474
|
if (!this.hasAttribute("tabindex"))
|
|
463
475
|
this.tabIndex = 0;
|
|
464
|
-
this.#hands = carryControls(this, {
|
|
476
|
+
this.#hands = carryControls(this, {
|
|
477
|
+
initial: this.#model.view,
|
|
478
|
+
limits: { ...LIMITS, zoomMax: this.#flyZoomMax },
|
|
479
|
+
onChange: (state, info) => {
|
|
480
|
+
// a hand on the view ends a fly-to where it is
|
|
481
|
+
if (HANDS.has(info.reason))
|
|
482
|
+
this.#flight?.finish("stopped");
|
|
483
|
+
this.setView(state, info.final);
|
|
484
|
+
},
|
|
485
|
+
});
|
|
465
486
|
this.#labelBox.addEventListener("click", this.#labelClick);
|
|
466
487
|
this.#labelBox.addEventListener("focusin", this.#labelFocus);
|
|
467
488
|
}
|
|
@@ -544,6 +565,10 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
544
565
|
this.#model.cloudDrift = Number.isFinite(Number(value ?? "0")) ? Number(value ?? "0") : 0;
|
|
545
566
|
this.#gate?.request();
|
|
546
567
|
}
|
|
568
|
+
else if (name === "cloud-fade") {
|
|
569
|
+
this.#model.cloudFade = readCloudFade(value);
|
|
570
|
+
this.#gate?.request();
|
|
571
|
+
}
|
|
547
572
|
else if (name === "earth-size")
|
|
548
573
|
this.earthSize = readNumber(value, DEFAULT_EARTH_SIZE, 0.02, 50);
|
|
549
574
|
else if (name === "earth-x")
|
|
@@ -926,7 +951,8 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
926
951
|
/**
|
|
927
952
|
* Turn the view so a place of `places` is in the middle, at a pace a reader can follow (at once with `smooth: false`, for a reader who asked for less motion, or before the picture is live); the zoom stays.
|
|
928
953
|
* The place is named by its `id`, or by its label in any case. The camera must be looking at the Earth: while it rides along or looks at another body nothing moves. The tilt is held to 90 degrees either
|
|
929
|
-
* way, so a place more than 90 degrees of latitude from `center` comes as near the middle as that allows.
|
|
954
|
+
* way, so a place more than 90 degrees of latitude from `center` comes as near the middle as that allows. A new `goToPlace` or `flyTo` while it turns does not stop it: the turn keeps its speed and
|
|
955
|
+
* the way it is going and curves to the new place. A hand on the view ends it where it is.
|
|
930
956
|
*
|
|
931
957
|
* @param text - The place's id or label.
|
|
932
958
|
* @param options - `smooth` (true by default).
|
|
@@ -934,22 +960,174 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
934
960
|
*/
|
|
935
961
|
async goToPlace(text, options = {}) {
|
|
936
962
|
const place = findPlace(this.#placeList, text);
|
|
937
|
-
|
|
938
|
-
if (!place || !base || this.#model.ride)
|
|
963
|
+
if (!place || !this.#model.lookBase || this.#model.ride)
|
|
939
964
|
return undefined;
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
const to = aimAt(base, place, from);
|
|
943
|
-
const glide = (this.#placeGlide += 1);
|
|
944
|
-
const set = (yaw, tilt, final) => {
|
|
945
|
-
if (controls)
|
|
946
|
-
controls.set({ yaw, tilt, zoom: this.#model.view.zoom }, final, "place");
|
|
947
|
-
else
|
|
948
|
-
this.setView({ yaw, tilt, zoom: this.#model.view.zoom }, final);
|
|
949
|
-
};
|
|
950
|
-
glideView(set, from, to, options.smooth !== false && !prefersLessMotion() && this.#view?.live === true, () => glide === this.#placeGlide && this.isConnected);
|
|
965
|
+
this.#flyAsks += 1;
|
|
966
|
+
this.#startFlight(place, { phase: "across", heightKm: null, acrossMs: PLACE_GLIDE_MS, smooth: options.smooth !== false, held: null });
|
|
951
967
|
return { ...place };
|
|
952
968
|
}
|
|
969
|
+
/**
|
|
970
|
+
* Fly the camera to a place: across, the Earth turns under the camera at the height it has until the place is below (along a great circle, eased), then down, a descent to `height` kilometres over
|
|
971
|
+
* it (30 by default). `phase` asks for one part alone, so a page can take a reader there one press at a time. A new `flyTo` or `goToPlace` while one is moving does not stop it: the camera keeps its
|
|
972
|
+
* speed and the way it is going and curves smoothly into the new move, and a descent cut short slows to rest without turning back before the new move goes across. A hand on the view (a drag, a pinch,
|
|
973
|
+
* the wheel, a key) or `signal` ends it where it is; a reader who asked for reduced motion, `smooth: false` or a picture that is not live yet goes there at once. The controls' own turn (Auto-turn) is
|
|
974
|
+
* paused, so the place stays below.
|
|
975
|
+
*
|
|
976
|
+
* The descent comes all the way down only where finer pictures lie under the place (`tiles-finer`, over land from 60 degrees south to 80 degrees north); elsewhere it stops at `FLY_FLOOR_KM` (400 km), and
|
|
977
|
+
* at a `zoom-max` the page set, and says so in `held` and `stats.fly`. Once a fly-to has come below about 320 km the zoom reaches as low as it came. The camera must be looking at the Earth: while it
|
|
978
|
+
* rides along or looks at another body nothing moves. `chikyu-fly-start` is sent when it starts, with `{ lon, lat, phase, heightKm, held }`, and `chikyu-fly-end` when it ends, with what it resolves to.
|
|
979
|
+
*
|
|
980
|
+
* @param lat - Degrees north.
|
|
981
|
+
* @param lon - Degrees east.
|
|
982
|
+
* @param options - `height`, `phase`, `smooth` and `signal` (`FlyOptions`).
|
|
983
|
+
* @returns How it ended, once it has; `undefined` when it cannot fly (a latitude or longitude that is not a number, or the camera not looking at the Earth).
|
|
984
|
+
*/
|
|
985
|
+
async flyTo(lat, lon, options = {}) {
|
|
986
|
+
if (!Number.isFinite(lat) || !Number.isFinite(lon) || Math.abs(lat) > 90)
|
|
987
|
+
return undefined;
|
|
988
|
+
const ask = (this.#flyAsks += 1);
|
|
989
|
+
const phase = options.phase ?? "both";
|
|
990
|
+
let heightKm = phase === "across" ? null : Math.max(FLY_MIN_KM, Number.isFinite(options.height) ? options.height : FLY_HEIGHT_KM);
|
|
991
|
+
let held = null;
|
|
992
|
+
if (heightKm !== null) {
|
|
993
|
+
const finer = this.tilesFiner !== null;
|
|
994
|
+
// only with finer pictures asked for is it worth knowing whether the place is on land: the outlines are loaded then, and once
|
|
995
|
+
const land = finer ? await import("../place/land.js").then(({ landAt }) => landAt(lon, lat)).then((answer) => answer.country !== null || answer.near !== null) : false;
|
|
996
|
+
const floor = descentFloorKm({ finer, land, lat });
|
|
997
|
+
if (floor !== null && floor > heightKm) {
|
|
998
|
+
heightKm = floor;
|
|
999
|
+
held = "no-finer";
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
const where = { lon, lat, phase, heightKm: this.#model.lookBase ? this.#heightKm() : 0, held };
|
|
1003
|
+
// a later move was asked for while this one found its floor
|
|
1004
|
+
if (ask !== this.#flyAsks)
|
|
1005
|
+
return { ...where, reason: "redirected" };
|
|
1006
|
+
if (!this.#model.lookBase || this.#model.ride)
|
|
1007
|
+
return undefined;
|
|
1008
|
+
if (options.signal?.aborted)
|
|
1009
|
+
return { ...where, reason: "stopped" };
|
|
1010
|
+
return new Promise((resolve) => {
|
|
1011
|
+
this.#startFlight({ lon, lat }, {
|
|
1012
|
+
phase,
|
|
1013
|
+
heightKm,
|
|
1014
|
+
smooth: options.smooth !== false,
|
|
1015
|
+
held,
|
|
1016
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
1017
|
+
pause: true,
|
|
1018
|
+
start: (detail) => this.dispatchEvent(new CustomEvent("chikyu-fly-start", { detail, bubbles: true, composed: true })),
|
|
1019
|
+
done: (end) => {
|
|
1020
|
+
this.dispatchEvent(new CustomEvent("chikyu-fly-end", { detail: end, bubbles: true, composed: true }));
|
|
1021
|
+
resolve(end);
|
|
1022
|
+
},
|
|
1023
|
+
});
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
/** The camera's height above the ground in kilometres while it looks at the Earth, from the zoom and the box's fit. */
|
|
1027
|
+
#heightKm(zoom = this.#model.view.zoom) {
|
|
1028
|
+
return (Math.max(this.#model.nearest, this.#model.fit / Math.max(1e-9, zoom)) - 1) * EARTH_RADIUS_KM;
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1031
|
+
* Start a move to `to`: the one running hands its speed and turn on to it and ends `redirected`. A descent first lets the controls' zoom reach its height (under a `zoom-max` the page set, which holds it).
|
|
1032
|
+
*/
|
|
1033
|
+
#startFlight(to, options) {
|
|
1034
|
+
const base = this.#model.lookBase;
|
|
1035
|
+
const at = performance.now();
|
|
1036
|
+
const view = this.#model.view;
|
|
1037
|
+
const now = this.#flight ? flyStateAt(this.#flight.plan, at) : flyStill(flyAim(base.lon - view.yaw, Math.max(-90, Math.min(90, base.lat - view.tilt))), this.#heightKm());
|
|
1038
|
+
if (this.#flight) {
|
|
1039
|
+
this.#flyStats.redirects += 1;
|
|
1040
|
+
this.#flight.finish("redirected");
|
|
1041
|
+
}
|
|
1042
|
+
let heightKm = options.heightKm;
|
|
1043
|
+
let held = options.held;
|
|
1044
|
+
if (heightKm !== null) {
|
|
1045
|
+
const zoom = this.#model.fit / flyDistance(heightKm);
|
|
1046
|
+
this.#model.nearest = Math.min(this.#model.nearest, flyDistance(heightKm));
|
|
1047
|
+
if (zoom > this.#flyZoomMax) {
|
|
1048
|
+
this.#flyZoomMax = zoom;
|
|
1049
|
+
this.#hands?.setLimits({ zoomMax: zoom });
|
|
1050
|
+
}
|
|
1051
|
+
const limit = this.#controls()?.limits?.zoomMax ?? zoom;
|
|
1052
|
+
if (zoom > limit * (1 + 1e-9)) {
|
|
1053
|
+
heightKm = (this.#model.fit / limit - 1) * EARTH_RADIUS_KM;
|
|
1054
|
+
held = "zoom-max";
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
this.#flyStats.moves += 1;
|
|
1058
|
+
this.#flyStats.held = held;
|
|
1059
|
+
// the view's own turn would carry the place away from below the camera
|
|
1060
|
+
if (options.pause)
|
|
1061
|
+
this.#controls()?.pause?.();
|
|
1062
|
+
const plan = planFly(now, flyAim(to.lon, to.lat), { at, phase: options.phase, ...(heightKm !== null ? { heightKm } : {}), ...(options.acrossMs !== undefined ? { acrossMs: options.acrossMs } : {}) });
|
|
1063
|
+
const lifts = plan.lifts.length > 0;
|
|
1064
|
+
const abort = () => flight.finish("stopped");
|
|
1065
|
+
const flight = {
|
|
1066
|
+
plan,
|
|
1067
|
+
phase: options.phase,
|
|
1068
|
+
finish: (reason) => {
|
|
1069
|
+
if (this.#flight !== flight)
|
|
1070
|
+
return;
|
|
1071
|
+
this.#flight = null;
|
|
1072
|
+
options.signal?.removeEventListener("abort", abort);
|
|
1073
|
+
bar?.removeEventListener("kazoku-viewchange", hand);
|
|
1074
|
+
options.done?.({ reason, lon: to.lon, lat: to.lat, phase: options.phase, heightKm: this.#heightKm(), held });
|
|
1075
|
+
},
|
|
1076
|
+
};
|
|
1077
|
+
// a bar bound to the view has the hands: a change it makes for one ends the move too
|
|
1078
|
+
const bar = this.#bar();
|
|
1079
|
+
const hand = (event) => {
|
|
1080
|
+
if (HANDS.has(event.detail?.reason ?? ""))
|
|
1081
|
+
flight.finish("stopped");
|
|
1082
|
+
};
|
|
1083
|
+
this.#flight = flight;
|
|
1084
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
1085
|
+
bar?.addEventListener("kazoku-viewchange", hand);
|
|
1086
|
+
options.start?.({ lon: to.lon, lat: to.lat, phase: options.phase, heightKm: heightKm ?? this.#heightKm(), held });
|
|
1087
|
+
if (!options.smooth || prefersLessMotion() || this.#view?.live !== true) {
|
|
1088
|
+
this.#flyView(flyAt(plan, plan.end), true, base, lifts);
|
|
1089
|
+
flight.finish("arrived");
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
this.#askFlyFrame();
|
|
1093
|
+
}
|
|
1094
|
+
/** Ask for the next frame of the move running, once: a move that takes over another goes on in the frame already asked for. */
|
|
1095
|
+
#askFlyFrame() {
|
|
1096
|
+
if (this.#flyAsked)
|
|
1097
|
+
return;
|
|
1098
|
+
this.#flyAsked = true;
|
|
1099
|
+
requestAnimationFrame(this.#flyFrame);
|
|
1100
|
+
}
|
|
1101
|
+
/** One frame of the move running: the point it has now handed to the view, until it ends or the camera stops looking at the Earth. */
|
|
1102
|
+
#flyFrame = () => {
|
|
1103
|
+
this.#flyAsked = false;
|
|
1104
|
+
const flight = this.#flight;
|
|
1105
|
+
if (!flight)
|
|
1106
|
+
return;
|
|
1107
|
+
const looking = this.#model.lookBase;
|
|
1108
|
+
if (!looking || this.#model.ride || !this.isConnected) {
|
|
1109
|
+
flight.finish("stopped");
|
|
1110
|
+
return;
|
|
1111
|
+
}
|
|
1112
|
+
const now = performance.now();
|
|
1113
|
+
const last = now >= flight.plan.end;
|
|
1114
|
+
this.#flyView(flyAt(flight.plan, now), last, looking, flight.plan.lifts.length > 0);
|
|
1115
|
+
if (last)
|
|
1116
|
+
flight.finish("arrived");
|
|
1117
|
+
else
|
|
1118
|
+
this.#askFlyFrame();
|
|
1119
|
+
};
|
|
1120
|
+
/** Hand one point of a move to the controls (or the view, with none): the yaw and tilt that put it in the middle, and the zoom of its height when the move changes the height. */
|
|
1121
|
+
#flyView(point, final, base, lifts) {
|
|
1122
|
+
const view = this.#model.view;
|
|
1123
|
+
const turn = aimAt(base, flyLonLat(point.aim), view);
|
|
1124
|
+
const next = { yaw: turn.yaw, tilt: turn.tilt, zoom: lifts ? this.#model.fit / flyDistance(point.heightKm) : view.zoom };
|
|
1125
|
+
const controls = this.#controls();
|
|
1126
|
+
if (controls)
|
|
1127
|
+
controls.set(next, final, "fly");
|
|
1128
|
+
else
|
|
1129
|
+
this.setView(next, final);
|
|
1130
|
+
}
|
|
953
1131
|
/**
|
|
954
1132
|
* Whether places that crowd are gathered into one ring with their count (the attribute `place-groups`): on by default, `off` leaves every place its own ring. Setting the property writes the attribute.
|
|
955
1133
|
*
|
|
@@ -1562,14 +1740,15 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1562
1740
|
* The controls that are driving this view: a `<kazoku-view-controls for="...">` bound to it (its hands are then the only ones and its controller holds the yaw and tilt), else the element's own hands.
|
|
1563
1741
|
*/
|
|
1564
1742
|
#controls() {
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1743
|
+
const bar = this.#bar();
|
|
1744
|
+
const held = bar ? Reflect.get(bar, "controller") : undefined;
|
|
1745
|
+
return held ?? this.#hands?.controller;
|
|
1746
|
+
}
|
|
1747
|
+
/** The `<kazoku-view-controls for="...">` bound to this view, when there is one. */
|
|
1748
|
+
#bar() {
|
|
1749
|
+
if (!this.hasAttribute("data-kazoku-bar") || !this.id)
|
|
1750
|
+
return null;
|
|
1751
|
+
return this.getRootNode().querySelector?.(`kazoku-view-controls[for="${CSS.escape(this.id)}"]`) ?? null;
|
|
1573
1752
|
}
|
|
1574
1753
|
/** The body the camera looks at: at zoom 1 it fills the view; the yaw and tilt turn the camera round it. */
|
|
1575
1754
|
get body() {
|
|
@@ -2685,6 +2864,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
2685
2864
|
satellites: this.#satelliteStats(),
|
|
2686
2865
|
pace: { ...this.#pace },
|
|
2687
2866
|
lightFade: { mix: this.#model.lightFade.mix, fading: this.#model.lightFade.fading },
|
|
2867
|
+
cloudFade: this.#model.cloudShown,
|
|
2688
2868
|
paths: this.#pathControls?.stats() ?? emptyPathStats(),
|
|
2689
2869
|
ride: { track: this.#model.rideTrack ? { ...this.#model.rideTrack } : null, compass: this.#compass?.shown ? { ...this.#compass.shown } : null, riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null || this.#model.rideFrame.moving, facing: this.facing, groundKm: this.#model.rideFrame.groundKm },
|
|
2690
2870
|
camera: { position: [this.#model.pose.p[0], this.#model.pose.p[1], this.#model.pose.p[2]], quaternion: [this.#model.pose.q[0], this.#model.pose.q[1], this.#model.pose.q[2], this.#model.pose.q[3]], fov: this.#model.pose.fov },
|
|
@@ -2703,6 +2883,12 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
2703
2883
|
route: { ...this.#model.route.stats },
|
|
2704
2884
|
countryNames: this.#countries?.stats ?? { on: false, max: 0, countries: 0, names: 0, renders: 0, failed: false },
|
|
2705
2885
|
seaNames: this.#seas?.stats ?? { on: false, radius: 0, names: 0, renders: 0 },
|
|
2886
|
+
fly: {
|
|
2887
|
+
flying: this.#flight !== null,
|
|
2888
|
+
phase: this.#flight ? (this.#flight.phase === "across" || performance.now() < this.#flight.plan.across ? "across" : "down") : null,
|
|
2889
|
+
heightKm: this.#model.lookBase ? this.#heightKm() : null,
|
|
2890
|
+
...this.#flyStats,
|
|
2891
|
+
},
|
|
2706
2892
|
};
|
|
2707
2893
|
}
|
|
2708
2894
|
#satelliteStats() {
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { type Vec3 } from "./ephemeris.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The height a descent stops at when the page names none, in kilometres: the whole of a city in view, still sharp with the finer 30 m pictures of the land.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { FLY_HEIGHT_KM } from "@johnmorrisdotca/chikyu-earth/space";
|
|
8
|
+
*
|
|
9
|
+
* console.log(FLY_HEIGHT_KM); // 30
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const FLY_HEIGHT_KM = 30;
|
|
13
|
+
/**
|
|
14
|
+
* The lowest height a descent goes to, in kilometres: the camera stays above the clouds' shell.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { FLY_MIN_KM } from "@johnmorrisdotca/chikyu-earth/space";
|
|
19
|
+
*
|
|
20
|
+
* console.log(FLY_MIN_KM); // 15
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const FLY_MIN_KM = 15;
|
|
24
|
+
/**
|
|
25
|
+
* The height a descent stops at where no finer picture lies under it (the sea, Antarctica, the far north, or no `tiles-finer`), in kilometres: as low as the package's own pictures stay sharp.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { FLY_FLOOR_KM } from "@johnmorrisdotca/chikyu-earth/space";
|
|
30
|
+
*
|
|
31
|
+
* console.log(FLY_FLOOR_KM); // 400
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare const FLY_FLOOR_KM = 400;
|
|
35
|
+
/**
|
|
36
|
+
* The parts of a fly-to: `across` turns the Earth under the camera at the height it has until the place is below, `down` comes down to the height over the place, `both` (the default) one after the other.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import type { FlyPhase } from "@johnmorrisdotca/chikyu-earth/space";
|
|
41
|
+
*
|
|
42
|
+
* const phases: FlyPhase[] = ["across", "down", "both"];
|
|
43
|
+
* console.log(phases.length);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export type FlyPhase = "across" | "down" | "both";
|
|
47
|
+
/**
|
|
48
|
+
* Where a move has the camera at one moment, and how it is going: `aim` is the point under it (a unit vector in the Earth's axes: x toward longitude 90, y north, z toward longitude 0), `v` and `a` its speed and
|
|
49
|
+
* acceleration a millisecond, `height` the natural log of the height in kilometres, `hv` and `ha` its speed and acceleration.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import type { FlyState } from "@johnmorrisdotca/chikyu-earth/space";
|
|
54
|
+
*
|
|
55
|
+
* const still: FlyState = { aim: [0, 0, 1], v: [0, 0, 0], a: [0, 0, 0], height: Math.log(1000), hv: 0, ha: 0 };
|
|
56
|
+
* console.log(Math.exp(still.height));
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export interface FlyState {
|
|
60
|
+
aim: Vec3;
|
|
61
|
+
v: Vec3;
|
|
62
|
+
a: Vec3;
|
|
63
|
+
height: number;
|
|
64
|
+
hv: number;
|
|
65
|
+
ha: number;
|
|
66
|
+
}
|
|
67
|
+
/** The turn of a move: from `from` with the speed `v` and acceleration `a` it had, to `to`, over `ms` from `start`; `axis` and `angle` are the great circle between them. */
|
|
68
|
+
interface Turn {
|
|
69
|
+
start: number;
|
|
70
|
+
ms: number;
|
|
71
|
+
from: Vec3;
|
|
72
|
+
to: Vec3;
|
|
73
|
+
axis: Vec3;
|
|
74
|
+
angle: number;
|
|
75
|
+
v: Vec3;
|
|
76
|
+
a: Vec3;
|
|
77
|
+
}
|
|
78
|
+
/** One part of a move's height, in the log of kilometres: from `from` with the speed and acceleration it had to `to`, over `ms` from `start`. */
|
|
79
|
+
interface Lift {
|
|
80
|
+
start: number;
|
|
81
|
+
ms: number;
|
|
82
|
+
from: number;
|
|
83
|
+
to: number;
|
|
84
|
+
v: number;
|
|
85
|
+
a: number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A move worked out by `planFly`: its turn, the parts of its height one after the other, the height it starts at (the log of kilometres), when the turn is over (`across`) and when the whole move is
|
|
89
|
+
* (`end`), on the clock it was planned with.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { planFly, type FlyPlan } from "@johnmorrisdotca/chikyu-earth/space";
|
|
94
|
+
*
|
|
95
|
+
* const plan: FlyPlan = planFly({ aim: [0, 0, 1], v: [0, 0, 0], a: [0, 0, 0], height: Math.log(1000), hv: 0, ha: 0 }, [1, 0, 0], { at: 0, phase: "across" });
|
|
96
|
+
* console.log(plan.end > plan.turn.start);
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export interface FlyPlan {
|
|
100
|
+
readonly turn: Readonly<Turn>;
|
|
101
|
+
readonly lifts: readonly Readonly<Lift>[];
|
|
102
|
+
readonly height: number;
|
|
103
|
+
readonly across: number;
|
|
104
|
+
readonly end: number;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Where a move has the camera at one moment: `aim`, the unit vector of the point under it, and `heightKm`.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* import type { FlyPoint } from "@johnmorrisdotca/chikyu-earth/space";
|
|
112
|
+
*
|
|
113
|
+
* const over: FlyPoint = { aim: [0, 0, 1], heightKm: 30 };
|
|
114
|
+
* console.log(over.heightKm);
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export interface FlyPoint {
|
|
118
|
+
aim: Vec3;
|
|
119
|
+
heightKm: number;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The unit vector of a longitude and latitude in degrees, in the Earth's axes (x toward longitude 90, y north, z toward longitude 0).
|
|
123
|
+
*
|
|
124
|
+
* @param lon - Degrees east.
|
|
125
|
+
* @param lat - Degrees north.
|
|
126
|
+
* @returns The unit vector.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* import { flyAim } from "@johnmorrisdotca/chikyu-earth/space";
|
|
131
|
+
*
|
|
132
|
+
* console.log(flyAim(0, 90).map((n) => Math.round(n))); // [0, 1, 0]
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare function flyAim(lon: number, lat: number): Vec3;
|
|
136
|
+
/**
|
|
137
|
+
* The longitude and latitude in degrees of a unit vector in the Earth's axes, the inverse of `flyAim`.
|
|
138
|
+
*
|
|
139
|
+
* @param aim - The unit vector.
|
|
140
|
+
* @returns `{ lon, lat }`.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* import { flyAim, flyLonLat } from "@johnmorrisdotca/chikyu-earth/space";
|
|
145
|
+
*
|
|
146
|
+
* console.log(flyLonLat(flyAim(139.69, 35.69)));
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export declare function flyLonLat(aim: Vec3): {
|
|
150
|
+
lon: number;
|
|
151
|
+
lat: number;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* How long the turn across takes, in milliseconds: 900 for a short way, up to 2,400 for the far side of the Earth.
|
|
155
|
+
*
|
|
156
|
+
* @param angle - The angle between the two points, in radians.
|
|
157
|
+
* @returns Milliseconds.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* import { flyAcrossMs } from "@johnmorrisdotca/chikyu-earth/space";
|
|
162
|
+
*
|
|
163
|
+
* console.log(flyAcrossMs(0), flyAcrossMs(Math.PI)); // 900 2400
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export declare const flyAcrossMs: (angle: number) => number;
|
|
167
|
+
/**
|
|
168
|
+
* How long a descent takes, in milliseconds: 1,200 and half a second more for each time the height is divided by e, at most 5 seconds.
|
|
169
|
+
*
|
|
170
|
+
* @param fromKm - The height it starts from.
|
|
171
|
+
* @param toKm - The height it ends at.
|
|
172
|
+
* @returns Milliseconds.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* import { flyDownMs } from "@johnmorrisdotca/chikyu-earth/space";
|
|
177
|
+
*
|
|
178
|
+
* console.log(Math.round(flyDownMs(20_000, 30)));
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export declare const flyDownMs: (fromKm: number, toKm: number) => number;
|
|
182
|
+
/**
|
|
183
|
+
* Where a move has the camera at a moment of its clock. Before it starts it is where it began; after it ends, where it ended.
|
|
184
|
+
*
|
|
185
|
+
* @param plan - What `planFly` returned.
|
|
186
|
+
* @param t - The moment, in milliseconds of the clock the plan was made with.
|
|
187
|
+
* @returns The point under the camera and its height.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* import { flyAt, flyAim, flyLonLat, planFly } from "@johnmorrisdotca/chikyu-earth/space";
|
|
192
|
+
*
|
|
193
|
+
* const plan = planFly({ aim: flyAim(0, 0), v: [0, 0, 0], a: [0, 0, 0], height: Math.log(20_000), hv: 0, ha: 0 }, flyAim(139.69, 35.69), { at: 0, phase: "both", heightKm: 30 });
|
|
194
|
+
* const end = flyAt(plan, plan.end);
|
|
195
|
+
* console.log(flyLonLat(end.aim), Math.round(end.heightKm)); // Tokyo, 30
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export declare function flyAt(plan: FlyPlan, t: number): FlyPoint;
|
|
199
|
+
/**
|
|
200
|
+
* Where a move has the camera at a moment and how it is going there: what a new move starts from, so that it carries on with the same speed and turn.
|
|
201
|
+
*
|
|
202
|
+
* @param plan - What `planFly` returned.
|
|
203
|
+
* @param t - The moment, in milliseconds of the plan's clock.
|
|
204
|
+
* @returns The state, with its speeds and accelerations a millisecond.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* import { flyAim, flyStateAt, planFly } from "@johnmorrisdotca/chikyu-earth/space";
|
|
209
|
+
*
|
|
210
|
+
* const plan = planFly({ aim: flyAim(0, 0), v: [0, 0, 0], a: [0, 0, 0], height: Math.log(1000), hv: 0, ha: 0 }, flyAim(90, 0), { at: 0, phase: "across" });
|
|
211
|
+
* const halfway = flyStateAt(plan, plan.end / 2);
|
|
212
|
+
* console.log(Math.hypot(...halfway.v) > 0);
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
export declare function flyStateAt(plan: FlyPlan, t: number): FlyState;
|
|
216
|
+
/**
|
|
217
|
+
* The state of a camera that is not moving: over `aim` at `heightKm`.
|
|
218
|
+
*
|
|
219
|
+
* @param aim - The unit vector of the point under the camera.
|
|
220
|
+
* @param heightKm - Its height in kilometres.
|
|
221
|
+
* @returns The state, with no speed.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* import { flyAim, flyStill } from "@johnmorrisdotca/chikyu-earth/space";
|
|
226
|
+
*
|
|
227
|
+
* console.log(flyStill(flyAim(0, 0), 1000).hv); // 0
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
export declare const flyStill: (aim: Vec3, heightKm: number) => FlyState;
|
|
231
|
+
/**
|
|
232
|
+
* Plan a move from where the camera is and how it is going (`now`) to the point `to`. The turn starts with the camera's own speed and turn and curves to the place along a great circle, slowing to rest over
|
|
233
|
+
* it; the height does the same on a log scale. A height still moving when the move is planned (a descent that a new move cuts short) slows to rest first, without turning back. `across` keeps the height,
|
|
234
|
+
* `down` comes to `heightKm` at once (the turn, if any, beside it), `both` comes down once the turn is over.
|
|
235
|
+
*
|
|
236
|
+
* @param now - Where the camera is and how it is going: `flyStateAt` of the move running, else `flyStill`.
|
|
237
|
+
* @param to - The unit vector of the place.
|
|
238
|
+
* @param options - `at`, the moment on the move's clock; `phase` (`both` by default); `heightKm`, the height to come down to (`FLY_HEIGHT_KM` by default); `acrossMs`, the time of the turn (`flyAcrossMs` of its angle by default).
|
|
239
|
+
* @returns The plan, for `flyAt` and `flyStateAt`.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* import { flyAim, flyStateAt, planFly } from "@johnmorrisdotca/chikyu-earth/space";
|
|
244
|
+
*
|
|
245
|
+
* const start = { aim: flyAim(0, 0), v: [0, 0, 0] as [number, number, number], a: [0, 0, 0] as [number, number, number], height: Math.log(20_000), hv: 0, ha: 0 };
|
|
246
|
+
* const toTokyo = planFly(start, flyAim(139.69, 35.69), { at: 0 });
|
|
247
|
+
* // half way, the reader asks for London: the new move starts with the speed the first one has
|
|
248
|
+
* const toLondon = planFly(flyStateAt(toTokyo, 800), flyAim(-0.13, 51.51), { at: 800 });
|
|
249
|
+
* console.log(toLondon.end > 800);
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
export declare function planFly(now: FlyState, to: Vec3, options: {
|
|
253
|
+
at: number;
|
|
254
|
+
phase?: FlyPhase;
|
|
255
|
+
heightKm?: number;
|
|
256
|
+
acrossMs?: number;
|
|
257
|
+
}): FlyPlan;
|
|
258
|
+
/**
|
|
259
|
+
* The height a descent over a place is held at, in kilometres, or `null` when nothing holds it: a descent comes all the way down only where the finer pictures lie (`tiles-finer` on, over land, from 60
|
|
260
|
+
* degrees south to 80 degrees north, as the survey of the layer found), and stops at `FLY_FLOOR_KM` elsewhere, as low as the package's own pictures stay sharp.
|
|
261
|
+
*
|
|
262
|
+
* @param place - `finer`, whether finer pictures are asked for; `land`, whether the place is on land or near its coast; `lat`, its latitude.
|
|
263
|
+
* @returns The height to hold at, or `null`.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```ts
|
|
267
|
+
* import { descentFloorKm } from "@johnmorrisdotca/chikyu-earth/space";
|
|
268
|
+
*
|
|
269
|
+
* console.log(descentFloorKm({ finer: true, land: true, lat: 35.69 })); // null: down to the height asked for
|
|
270
|
+
* console.log(descentFloorKm({ finer: true, land: false, lat: 30 })); // 400: the sea
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
export declare function descentFloorKm(place: {
|
|
274
|
+
finer: boolean;
|
|
275
|
+
land: boolean;
|
|
276
|
+
lat: number;
|
|
277
|
+
}): number | null;
|
|
278
|
+
/**
|
|
279
|
+
* The camera's distance from the Earth's centre, in Earth radii, for a height above the ground in kilometres.
|
|
280
|
+
*
|
|
281
|
+
* @param heightKm - The height.
|
|
282
|
+
* @returns The distance.
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```ts
|
|
286
|
+
* import { flyDistance } from "@johnmorrisdotca/chikyu-earth/space";
|
|
287
|
+
*
|
|
288
|
+
* console.log(flyDistance(6371)); // 2
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
export declare const flyDistance: (heightKm: number) => number;
|
|
292
|
+
export {};
|