@johnmorrisdotca/chikyu-earth 0.38.0 → 0.40.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 +13 -0
- package/README.md +2 -1
- package/dist/cities/geometry.d.ts +7 -0
- package/dist/cities/geometry.js +1 -1
- package/dist/cities/host.d.ts +10 -2
- package/dist/cities/host.js +4 -2
- package/dist/markers/layer.d.ts +16 -1
- package/dist/markers/layer.js +3 -2
- package/dist/markers/place-layer.js +3 -0
- package/dist/paint/buffer.d.ts +6 -1
- package/dist/paint/buffer.js +151 -68
- package/dist/paint/texture.d.ts +16 -6
- package/dist/paint/texture.js +46 -27
- package/dist/realistic/earth.d.ts +1 -1
- package/dist/realistic/earth.js +5 -4
- package/dist/realistic/element-base.d.ts +437 -0
- package/dist/realistic/element-base.js +1249 -0
- package/dist/realistic/element.d.ts +2 -431
- package/dist/realistic/element.js +3 -1203
- package/dist/realistic/index.d.ts +1 -1
- package/dist/realistic/no-cultures.d.ts +1 -0
- package/dist/realistic/no-cultures.js +2 -0
- package/dist/realistic/tiles.d.ts +24 -0
- package/dist/realistic/tiles.js +30 -12
- package/dist/sky/culture-source.d.ts +15 -0
- package/dist/sky/culture-source.js +15 -0
- package/dist/sky/cultures.d.ts +1 -0
- package/dist/sky/cultures.js +8 -0
- package/dist/sky/host.d.ts +12 -0
- package/dist/sky/host.js +174 -22
- package/dist/space/element-base.d.ts +624 -0
- package/dist/space/element-base.js +1656 -0
- package/dist/space/element.d.ts +2 -612
- package/dist/space/element.js +3 -1597
- package/dist/space/no-cultures.d.ts +1 -0
- package/dist/space/no-cultures.js +2 -0
- package/dist/space/scene.d.ts +8 -1
- package/dist/space/scene.js +73 -34
- package/package.json +23 -3
|
@@ -1,1203 +1,3 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
|
|
5
|
-
import { adoptStyles } from "../adopt.js";
|
|
6
|
-
import { airFor, readAirThickness } from "./air.js";
|
|
7
|
-
import { IMMERSIVE_STYLE, immersiveWheel } from "./immersive.js";
|
|
8
|
-
import { NOTES_STYLE, setAirNote } from "./air-note.js";
|
|
9
|
-
import { cameraCentre, createEarthItem, discRadius, lookAt, newModel } from "./earth.js";
|
|
10
|
-
import { createPaintState, paintedGround } from "../paint/buffer.js";
|
|
11
|
-
import { MAX_ORBIT_GROUP } from "../space/satellite-layer.js";
|
|
12
|
-
import { readMeteorStrength } from "../meteors/strength.js";
|
|
13
|
-
import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
|
|
14
|
-
import { createDoorHost } from "../door/host.js";
|
|
15
|
-
import { folderSource } from "../door/map.js";
|
|
16
|
-
import { ownCredit } from "../door/own.js";
|
|
17
|
-
import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "./body-label.js";
|
|
18
|
-
import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
|
|
19
|
-
import { cleanPlaces, orthoView, readPlaceGroups, readPlaces } from "../markers/places.js";
|
|
20
|
-
import { createPlaceLayer, PLACE_STYLE, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
|
|
21
|
-
import { aimAt, findPlace, glideView } from "../markers/go-to-place.js";
|
|
22
|
-
import { subsolarPoint } from "./sun.js";
|
|
23
|
-
import { CITY_NAMES_ATTRIBUTES, CITY_NAMES_STYLE, createCityHost } from "../cities/host.js";
|
|
24
|
-
import { project } from "../markers/project.js";
|
|
25
|
-
import { BORDER_ATTRIBUTES, readBorders } from "../borders/lines.js";
|
|
26
|
-
import { GRID_ATTRIBUTES, readGrid } from "../grid/lines.js";
|
|
27
|
-
import { COUNTRY_NAMES_ATTRIBUTES } from "../country-names/geometry.js";
|
|
28
|
-
import { COUNTRY_NAMES_STYLE, createCountryHost } from "../country-names/host.js";
|
|
29
|
-
import { createGate, frameCap } from "./gate.js";
|
|
30
|
-
import { setSharedRenderer, setThreeLoader, takeRenderer } from "./shared.js";
|
|
31
|
-
export { setSharedRenderer, setThreeLoader };
|
|
32
|
-
import { MAX_TEXTURE, TIERS } from "./tiers.js";
|
|
33
|
-
const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative;isolation:isolate}" + IMMERSIVE_STYLE + "#stage,#overlay{position:absolute;inset:0}#overlay{pointer-events:none}" + PLACE_STYLE + SKY_STYLE + COUNTRY_NAMES_STYLE + CITY_NAMES_STYLE + METEOR_NOTE_STYLE + NOTES_STYLE;
|
|
34
|
-
const RAD = Math.PI / 180;
|
|
35
|
-
/** The Sun and the clouds are re-placed this often at real time: 15 degrees an hour is 0.25 degree a minute. */
|
|
36
|
-
const LIVE_TICK_MS = 60_000;
|
|
37
|
-
const MIN_TICK_MS = 1000;
|
|
38
|
-
/** The least time between two `chikyu-timechange` events while time runs: a few a second at most, however fast the picture is drawn. */
|
|
39
|
-
const TIME_EVENT_MS = 250;
|
|
40
|
-
/** How fast the Sun goes round the Earth, degrees a second of real time (the light, the night side and the clouds' drift all follow it). */
|
|
41
|
-
const SUN_RATE = 360 / 86_400;
|
|
42
|
-
/** Tilt to the poles; zoom from a tenth of Fit, which leaves the whole Earth small in the view, to 5 times: the package's own pictures are sharp to about 5 times. */
|
|
43
|
-
const LIMITS = { tiltMax: 90, zoomMin: 0.1, zoomMax: 5 };
|
|
44
|
-
/** With the finer tiles the detail runs 4 times further: the finest level is 4 times wider than the widest picture. */
|
|
45
|
-
const TILES_ZOOM_MAX = "20";
|
|
46
|
-
const readCentre = (value) => {
|
|
47
|
-
if (!value)
|
|
48
|
-
return null;
|
|
49
|
-
const [lon, lat] = value.split(",").map((part) => Number(part.trim()));
|
|
50
|
-
if (!Number.isFinite(lon) || !Number.isFinite(lat) || Math.abs(lon) > 180 || Math.abs(lat) > 90)
|
|
51
|
-
return null;
|
|
52
|
-
return { lon: lon, lat: lat };
|
|
53
|
-
};
|
|
54
|
-
/** A `camera` attribute: `ground` or `sun`, else the camera held in the stars (the default: the Earth turns beneath it). */
|
|
55
|
-
const readCamera = (value) => (value === "ground" || value === "sun" ? value : "space");
|
|
56
|
-
/** A `cloud-drift` attribute: degrees an hour the clouds are made to move eastward against the ground (0, the default: where the picture has them). */
|
|
57
|
-
const readDrift = (value) => (value !== null && Number.isFinite(Number(value)) ? Number(value) : 0);
|
|
58
|
-
/** The quickest a satellite goes round, degrees a second (a low orbit: 88 minutes). */
|
|
59
|
-
const SATELLITE_RATE = 360 / (88 * 60);
|
|
60
|
-
const SATELLITE_COLORS = ["#ffd54f", "#7fd4ff", "#ff8fa3", "#9ef0a8"];
|
|
61
|
-
/** A `light` attribute: `lit` or `boost`, else the true sun. */
|
|
62
|
-
const readLight = (value) => (value === "lit" || value === "boost" ? value : "sun");
|
|
63
|
-
const readRatio = (value) => {
|
|
64
|
-
const ratio = Number(value);
|
|
65
|
-
return value !== null && Number.isFinite(ratio) && ratio > 0 ? Math.min(ratio, 2) : undefined;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* A `speed` attribute: how many seconds pass for each real second.
|
|
69
|
-
*
|
|
70
|
-
* @param value - The attribute's text, or `null` when it is not there.
|
|
71
|
-
* @returns The speed, or `null` when the value is empty or not a number (the clock then follows `time`: real time for "now", held for a date).
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts no-run
|
|
75
|
-
* import { readSpeed } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
76
|
-
*
|
|
77
|
-
* console.log(readSpeed("86400"), readSpeed("-3600"), readSpeed(null));
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
export const readSpeed = (value) => {
|
|
81
|
-
if (value === null || value.trim() === "")
|
|
82
|
-
return null;
|
|
83
|
-
const speed = Number(value);
|
|
84
|
-
return Number.isFinite(speed) ? speed : null;
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* A `time` attribute: "now" (or none) follows the clock, else an ISO date such as 2026-06-21T12:00:00Z.
|
|
88
|
-
*
|
|
89
|
-
* @param value - The attribute's text, or `null` when it is not there.
|
|
90
|
-
* @returns The moment in milliseconds since the Unix epoch, or `"now"` when the value is empty, `"now"` or not a date.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```ts no-run
|
|
94
|
-
* import { readTime } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
95
|
-
*
|
|
96
|
-
* console.log(readTime("2026-06-21T12:00:00Z"), readTime(null), readTime("tomorrow"));
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
export const readTime = (value) => {
|
|
100
|
-
if (value === null || value === "" || value === "now")
|
|
101
|
-
return "now";
|
|
102
|
-
const ms = Date.parse(value);
|
|
103
|
-
return Number.isFinite(ms) ? ms : "now";
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
* The `<chikyu-earth-realistic>` custom element: the Earth from space, drawn with three.js through kazoku-ui's shared renderer (one WebGL context for the page). It takes `center` (`"lon,lat"`), `time` (`now` or an ISO date; the real Sun at that moment), `clouds="off"`, `lights="off"`, `live-seconds`, `texture-base` (where the pictures are served from), `tiles` (where a set of finer map tiles is served from, see the Earth tiles guide: only the tiles in view are loaded, over the package's own pictures, which stay as the far view and the fallback; without it, or when a tile cannot be fetched, the Earth is drawn as before) and `max-ratio` (the most device pixels to a CSS pixel the canvas is drawn at, 2 at most, and `0.5` draws at half the size and scales it up: for a background; read when the element connects, and it is the shared renderer's cap for the whole page), and a shared view controller's camera through `setView`. It draws only when something changes, at most 30 times a second, and nothing while it is out of sight or the tab is hidden.
|
|
107
|
-
*
|
|
108
|
-
* It has a clock, like `<chikyu-space>`'s: `speed` is how many seconds pass for each real second (`1` is real time, `0` holds, `3600` is an hour a second, `86400` a day a second, a negative number runs backwards), and the clock runs from `time`, the moment shown.
|
|
109
|
-
* The Sun's light, the night side and the clouds follow it. Without a `speed`, nothing about a page from before changes: `time="now"` (or no `time`) follows the real clock, the Sun and the clouds put right every `live-seconds` (a minute by default, a second at the least),
|
|
110
|
-
* and a date holds still. A `speed` runs the clock from the moment shown at that rate (from now, when `time` is "now"); `speed="0"` holds it. At real time it steps every `live-seconds`; faster, it draws as often as the Sun's turn moves a pixel, once a second at least and 30 a second at most
|
|
111
|
-
* (a reader who prefers reduced motion gets one step a second), and nothing at all while it is held, out of sight or in a hidden tab.
|
|
112
|
-
*
|
|
113
|
-
* While time runs it sends `chikyu-timechange` with `detail: { time, running: true }` (the moment shown in milliseconds since 1970), at most four times a second however fast the picture is drawn and not from a hidden tab, and once with `running: false` when the clock holds
|
|
114
|
-
* (a date is set, or `speed` is 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.
|
|
115
|
-
*
|
|
116
|
-
* `meteors` (the attribute, with or without a value other than `off`; the property is a boolean) draws meteors as they look from space: short streaks 80 to 120 km up,
|
|
117
|
-
* only where it is dark or twilight, more of them where an active shower's radiant stands high and on the side that faces the Earth's way. Each streak's place and
|
|
118
|
-
* moment are drawn at random (and said so in a line under the picture, which `meteors-label="off"` takes away for a page that says it itself); how many there are,
|
|
119
|
-
* where they fall, their height and the showers' dates are real (`@johnmorrisdotca/chikyu-earth/meteors`). They run while the clock runs, at any speed, and not
|
|
120
|
-
* at all while it is held, out of sight, in a hidden tab, or for a reader who prefers reduced motion until the page sets a `speed` (a Play). `chikyu-meteors`
|
|
121
|
-
* is sent when the strongest active shower changes, with `detail: { shower, zhr }` (`shower` is `null` when none is active).
|
|
122
|
-
* `meteors-strength` (0 to 1, the property `meteorsStrength`; 1 when the page says nothing) makes them subtler: fewer streaks and fainter ones, none at 0, and nothing that is real changes.
|
|
123
|
-
*
|
|
124
|
-
* `borders` draws the borders on the land as thin lines that turn with the Earth: `countries` (chizu's, at any size), `regions` (provinces, states and the like, from the page's `borderData.regions`,
|
|
125
|
-
* once the Earth is large enough to tell them apart), or both with a bare attribute. The shapes are loaded only when a set is switched on; `chikyu-borders-unavailable` is sent when they cannot be.
|
|
126
|
-
*
|
|
127
|
-
* `grid` draws the meridians and parallels on the Earth (every 30 degrees while it is small on the screen, every 15 once it is large), with the equator, the tropics, the polar circles and the prime
|
|
128
|
-
* meridian picked out, light on the day side and dim on the night side. `country-names` names the countries at the middle of the part of each in view, in the page's language, never over another
|
|
129
|
-
* name, as many as fit (40 at most, or the number given); the outlines are loaded only when it is set, and `chikyu-country-names-unavailable` is sent when they cannot be.
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```ts no-run
|
|
133
|
-
* import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
134
|
-
*
|
|
135
|
-
* const earth = document.createElement("chikyu-earth-realistic") as ChikyuEarthRealistic;
|
|
136
|
-
* earth.setAttribute("center", "139.7,35.7");
|
|
137
|
-
* earth.setAttribute("time", "2026-06-21T03:00Z");
|
|
138
|
-
* earth.setAttribute("texture-base", "/textures/");
|
|
139
|
-
* earth.setAttribute("tiles", "/tiles/");
|
|
140
|
-
* earth.setAttribute("speed", "86400");
|
|
141
|
-
* earth.placeGroups = false; // place-groups="off": every place keeps its own ring
|
|
142
|
-
* earth.paint = { id: "25544", length: "1d", swath: "track" };
|
|
143
|
-
* earth.clearPaint();
|
|
144
|
-
* earth.addEventListener("chikyu-timechange", (event) => {
|
|
145
|
-
* const { time, running } = (event as CustomEvent<{ time: number; running: boolean }>).detail;
|
|
146
|
-
* console.log(new Date(time).toISOString(), running ? "running" : "held");
|
|
147
|
-
* });
|
|
148
|
-
* document.body.append(earth);
|
|
149
|
-
* ```
|
|
150
|
-
*/
|
|
151
|
-
export class ChikyuEarthRealistic extends HTMLElement {
|
|
152
|
-
static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "satellite-tint"];
|
|
153
|
-
#model = newModel();
|
|
154
|
-
#paint = createPaintState();
|
|
155
|
-
#mode = "now";
|
|
156
|
-
#view;
|
|
157
|
-
#gate;
|
|
158
|
-
#tick;
|
|
159
|
-
/** The clock's speed when `speed` is given (attribute or property); `null` follows `time`: real time for "now", held for a date. */
|
|
160
|
-
#speed = null;
|
|
161
|
-
/** The page's own clock, in milliseconds, at the last step. */
|
|
162
|
-
#last = 0;
|
|
163
|
-
#announced = -Infinity;
|
|
164
|
-
/** The clock is running (a `running: false` is owed when it holds). */
|
|
165
|
-
#running = false;
|
|
166
|
-
#state = "loading";
|
|
167
|
-
#tiers = { day: TIERS.day[0], night: TIERS.night[0], clouds: TIERS.clouds[0], water: TIERS.water[0] };
|
|
168
|
-
#taken;
|
|
169
|
-
/** The data door: the outside sources of map this Earth draws from, and whose data is on the screen. */
|
|
170
|
-
#door = createDoorHost(this, {
|
|
171
|
-
own: () => this.#ownCredits(),
|
|
172
|
-
used: () => new Map(Object.entries(this.#model.tiles?.stats.used ?? {})),
|
|
173
|
-
}, { kinds: ["tiles"] }, () => this.#gate?.soon());
|
|
174
|
-
#stage;
|
|
175
|
-
#overlay;
|
|
176
|
-
#pose = null;
|
|
177
|
-
/** The names of cities on the Earth (`city-names`), and the look of the names. */
|
|
178
|
-
#cities;
|
|
179
|
-
#citiesStyle = {};
|
|
180
|
-
/** The names of the countries on the Earth (`country-names`), and the look of the names. */
|
|
181
|
-
#countries;
|
|
182
|
-
#countriesStyle = {};
|
|
183
|
-
#listeners = new Set();
|
|
184
|
-
#placeLayer;
|
|
185
|
-
/** Whether the page has been told that places in sight were left undrawn. */
|
|
186
|
-
#placesLost = { told: false };
|
|
187
|
-
#placeList = [];
|
|
188
|
-
/** Counts the turns to a place, so a new one stops the one before. */
|
|
189
|
-
#placeGlide = 0;
|
|
190
|
-
#hands;
|
|
191
|
-
#reach = null;
|
|
192
|
-
/** The page has set a `speed` since the element came into the page: for a reader who prefers reduced motion, that is the Play that lets meteors start. */
|
|
193
|
-
#played = false;
|
|
194
|
-
#note;
|
|
195
|
-
/** The names of the stars and the constellation lines (`star-names`, `constellation-lines`), and the look of the names. */
|
|
196
|
-
#sky;
|
|
197
|
-
#skyStyle = {};
|
|
198
|
-
#keepClear = [];
|
|
199
|
-
#airNote;
|
|
200
|
-
#onContext = (state) => {
|
|
201
|
-
if (state === "unavailable")
|
|
202
|
-
this.#fail("WebGL is not available");
|
|
203
|
-
};
|
|
204
|
-
// The canvas's own events reach the stage in the capture phase (they do not bubble); the shared renderer handles them and this follows.
|
|
205
|
-
#lost = () => this.#set("lost");
|
|
206
|
-
#restored = () => this.#set("live");
|
|
207
|
-
connectedCallback() {
|
|
208
|
-
this.#model.centre = readCentre(this.getAttribute("center")) ?? this.#model.centre;
|
|
209
|
-
this.#mode = readTime(this.getAttribute("time"));
|
|
210
|
-
this.#model.time = this.#mode === "now" ? Date.now() : this.#mode;
|
|
211
|
-
this.#speed = readSpeed(this.getAttribute("speed"));
|
|
212
|
-
this.#last = performance.now();
|
|
213
|
-
this.#model.clouds = this.getAttribute("clouds") !== "off";
|
|
214
|
-
this.#model.lights = this.getAttribute("lights") !== "off";
|
|
215
|
-
this.#model.light = readLight(this.getAttribute("light"));
|
|
216
|
-
this.#model.camera = readCamera(this.getAttribute("camera"));
|
|
217
|
-
this.#model.cloudDrift = readDrift(this.getAttribute("cloud-drift"));
|
|
218
|
-
this.#model.airThickness = readAirThickness(this.getAttribute("air-thickness"));
|
|
219
|
-
this.#applyBodyLabel();
|
|
220
|
-
this.#door.book.ownOnly(this.getAttribute("data") === "own");
|
|
221
|
-
this.#model.speed = this.speed;
|
|
222
|
-
if (!this.hasAttribute("role"))
|
|
223
|
-
this.setAttribute("role", "img");
|
|
224
|
-
if (!this.hasAttribute("aria-label"))
|
|
225
|
-
this.setAttribute("aria-label", "The Earth from space, with its sunlit and dark sides");
|
|
226
|
-
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
227
|
-
root.innerHTML = `<div id="stage"></div><div id="places"></div><div id="overlay"></div><div id="notes"><p id="air-note" hidden></p><p id="meteor-note" hidden></p></div>`;
|
|
228
|
-
adoptStyles(root, STYLE, this.nonce);
|
|
229
|
-
this.#stage = root.getElementById("stage");
|
|
230
|
-
this.#overlay = root.getElementById("overlay");
|
|
231
|
-
this.#note = root.getElementById("meteor-note");
|
|
232
|
-
this.#airNote = root.getElementById("air-note");
|
|
233
|
-
this.#sky = createSkyHost({
|
|
234
|
-
root,
|
|
235
|
-
attribute: (name) => this.getAttribute(name),
|
|
236
|
-
language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
|
|
237
|
-
onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-sky-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
238
|
-
loadFont: loadMichroma,
|
|
239
|
-
});
|
|
240
|
-
this.#sky.setStyle(this.#skyStyle);
|
|
241
|
-
this.#sky.setKeepClear(this.#keepClear);
|
|
242
|
-
this.#placeLayer = createPlaceLayer(root.getElementById("places"));
|
|
243
|
-
this.#placeList = readPlaces(this.getAttribute("places"));
|
|
244
|
-
this.#placeLayer.set(this.#placeList);
|
|
245
|
-
this.#placeLayer.look = readPlaceLook(this.getAttribute("places-look"));
|
|
246
|
-
this.#placeLayer.grouping = readPlaceGroups(this.getAttribute("place-groups"));
|
|
247
|
-
this.#cities = createCityHost({
|
|
248
|
-
root,
|
|
249
|
-
attribute: (name) => this.getAttribute(name),
|
|
250
|
-
language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
|
|
251
|
-
onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-city-names-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
252
|
-
onLayout: () => this.#countryFrame(),
|
|
253
|
-
});
|
|
254
|
-
this.#cities.setStyle(this.#citiesStyle);
|
|
255
|
-
Object.assign(this.#model.borders, readBorders(this.getAttribute("borders")));
|
|
256
|
-
this.#model.borders.onError = (error) => this.dispatchEvent(new CustomEvent("chikyu-borders-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } }));
|
|
257
|
-
this.#model.grid.on = readGrid(this.getAttribute("grid"));
|
|
258
|
-
this.#model.grid.onError = (error) => this.dispatchEvent(new CustomEvent("chikyu-grid-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } }));
|
|
259
|
-
this.#countries = createCountryHost({
|
|
260
|
-
root,
|
|
261
|
-
attribute: (name) => this.getAttribute(name),
|
|
262
|
-
language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
|
|
263
|
-
onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-country-names-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
264
|
-
});
|
|
265
|
-
this.#countries.setStyle(this.#countriesStyle);
|
|
266
|
-
this.#played = false;
|
|
267
|
-
this.#model.meteors.on = this.#meteorsAsked();
|
|
268
|
-
this.#model.meteors.strength = readMeteorStrength(this.getAttribute("meteors-strength"));
|
|
269
|
-
this.#model.meteors.running = () => this.speed !== 0 && document.visibilityState !== "hidden" && (this.#played || !prefersLessMotion());
|
|
270
|
-
this.#model.meteors.onShower = (shower, zhr) => this.dispatchEvent(new CustomEvent("chikyu-meteors", { detail: { shower, zhr } }));
|
|
271
|
-
this.#meteorNote();
|
|
272
|
-
setAirNote(this.#airNote, this, this.#model.airThickness);
|
|
273
|
-
this.#stage.addEventListener("webglcontextlost", this.#lost, true);
|
|
274
|
-
this.#stage.addEventListener("webglcontextrestored", this.#restored, true);
|
|
275
|
-
const nav = navigator;
|
|
276
|
-
const cap = frameCap(30, { deviceMemory: nav.deviceMemory, hardwareConcurrency: nav.hardwareConcurrency });
|
|
277
|
-
this.#gate = createGate(1000 / cap, () => this.#view?.invalidate());
|
|
278
|
-
nav.getBattery?.().then((battery) => {
|
|
279
|
-
if (!battery.charging && battery.level <= 0.2)
|
|
280
|
-
this.#gate?.setMinMs(1000 / Math.min(cap, 15));
|
|
281
|
-
}, () => undefined);
|
|
282
|
-
const maxRatio = readRatio(this.getAttribute("max-ratio"));
|
|
283
|
-
if (maxRatio)
|
|
284
|
-
this.#model.ratio = () => Math.min(globalThis.devicePixelRatio || 1, 2, maxRatio);
|
|
285
|
-
const taken = takeRenderer(this.#onContext, maxRatio);
|
|
286
|
-
this.#taken = taken;
|
|
287
|
-
const item = createEarthItem(this.#model, {
|
|
288
|
-
assets: taken.renderer.assets,
|
|
289
|
-
textureBase: () => this.#textureBase(),
|
|
290
|
-
cap: () => this.#textureCap(),
|
|
291
|
-
sources: () => this.#tileSources(),
|
|
292
|
-
onTiles: (layers) => {
|
|
293
|
-
if (!this.hasAttribute("zoom-max") || this.getAttribute("zoom-max") === this.#reach) {
|
|
294
|
-
this.#reach = TILES_ZOOM_MAX;
|
|
295
|
-
// not written again when it is already there: the view controls take a written attribute as a new limit and bring the view back to fit, which a change of source must not do to a reader's zoom
|
|
296
|
-
if (this.getAttribute("zoom-max") !== TILES_ZOOM_MAX)
|
|
297
|
-
this.setAttribute("zoom-max", TILES_ZOOM_MAX);
|
|
298
|
-
}
|
|
299
|
-
this.dispatchEvent(new CustomEvent("chikyu-tiles", { detail: { layers } }));
|
|
300
|
-
},
|
|
301
|
-
air: () => airFor(this.getAttribute("air")),
|
|
302
|
-
invalidate: () => this.#gate?.soon(),
|
|
303
|
-
onDraw: () => this.#gate?.drawn(),
|
|
304
|
-
onTiled: () => this.#door.announce(),
|
|
305
|
-
onSky: (sky) => this.#sky?.frame(sky),
|
|
306
|
-
onLabelError: (error) => this.dispatchEvent(new CustomEvent("chikyu-body-label-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
307
|
-
placeSprites: () => this.#placeLayer?.sprites ?? null,
|
|
308
|
-
onPose: (pose) => {
|
|
309
|
-
if (this.#hands)
|
|
310
|
-
this.#hands.controller.grabRadius = discRadius(pose.width, pose.height, 1);
|
|
311
|
-
this.#pose = { ...pose, transform: "" };
|
|
312
|
-
this.#posing = true;
|
|
313
|
-
try {
|
|
314
|
-
for (const listener of this.#listeners)
|
|
315
|
-
listener(this.#pose);
|
|
316
|
-
}
|
|
317
|
-
finally {
|
|
318
|
-
this.#posing = false;
|
|
319
|
-
}
|
|
320
|
-
if (this.#placeLayer && (this.#placeList.length > 0 || this.#placeLayer.stats.shown > 0)) {
|
|
321
|
-
this.#placeLayer.frame(orthoView(pose), [], [], this.#model.light === "lit" ? null : subsolarPoint(this.#model.time));
|
|
322
|
-
this.#notePlacesLost();
|
|
323
|
-
}
|
|
324
|
-
this.#cityFrame();
|
|
325
|
-
},
|
|
326
|
-
onPlaceRings: (drawn) => this.#ringsDrawn(drawn),
|
|
327
|
-
onSatellitesError: (error) => this.dispatchEvent(new CustomEvent("chikyu-satellites-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
328
|
-
paint: {
|
|
329
|
-
data: this.#paint.data,
|
|
330
|
-
width: this.#paint.width,
|
|
331
|
-
height: this.#paint.height,
|
|
332
|
-
step: (ms) => this.#paint.step(ms, (at) => paintedGround(this.#model.satellites.groups, this.#paint.id, at)),
|
|
333
|
-
span: () => this.#paint.spanMinutes,
|
|
334
|
-
on: () => this.#paint.on,
|
|
335
|
-
},
|
|
336
|
-
onError: (error) => this.#fail(error instanceof Error ? error.message : String(error)),
|
|
337
|
-
onTier: (layer, width) => {
|
|
338
|
-
if (layer in this.#tiers)
|
|
339
|
-
this.#tiers[layer] = width;
|
|
340
|
-
this.dispatchEvent(new CustomEvent("chikyu-tier", { detail: { layer, width } }));
|
|
341
|
-
},
|
|
342
|
-
});
|
|
343
|
-
this.#view = taken.renderer.view(this.#stage, item, { still: null });
|
|
344
|
-
this.#set("loading");
|
|
345
|
-
void this.#view.focus().then((live) => {
|
|
346
|
-
if (live) {
|
|
347
|
-
this.#set("live");
|
|
348
|
-
this.dispatchEvent(new CustomEvent("chikyu-ready"));
|
|
349
|
-
}
|
|
350
|
-
else if (this.#state === "loading")
|
|
351
|
-
this.#set(this.#view?.live === false && taken.renderer.focused !== undefined ? "idle" : "unavailable");
|
|
352
|
-
});
|
|
353
|
-
this.addEventListener("pointerdown", this.#take);
|
|
354
|
-
this.addEventListener("pointerdown", this.#down);
|
|
355
|
-
this.addEventListener("focusin", this.#take);
|
|
356
|
-
// before the shared hands (which hear it after this): a plain wheel in an immersive view zooms
|
|
357
|
-
this.addEventListener("wheel", this.#wheel, { capture: true, passive: false });
|
|
358
|
-
this.#hands = carryControls(this, { initial: this.#model.view, limits: LIMITS, onChange: (state, info) => this.setView(state, info.final) });
|
|
359
|
-
this.#startTick();
|
|
360
|
-
document.addEventListener("visibilitychange", this.#onVisible);
|
|
361
|
-
}
|
|
362
|
-
disconnectedCallback() {
|
|
363
|
-
this.removeEventListener("pointerdown", this.#take);
|
|
364
|
-
this.removeEventListener("pointerdown", this.#down);
|
|
365
|
-
this.removeEventListener("wheel", this.#wheel, { capture: true });
|
|
366
|
-
window.removeEventListener("pointerup", this.#up, true);
|
|
367
|
-
this.removeEventListener("focusin", this.#take);
|
|
368
|
-
this.#hands?.unbind();
|
|
369
|
-
this.#hands = undefined;
|
|
370
|
-
if (this.#reach !== null && this.getAttribute("zoom-max") === this.#reach)
|
|
371
|
-
this.removeAttribute("zoom-max");
|
|
372
|
-
this.#reach = null;
|
|
373
|
-
clearTimeout(this.#tick);
|
|
374
|
-
this.#tick = undefined;
|
|
375
|
-
this.#running = false;
|
|
376
|
-
document.removeEventListener("visibilitychange", this.#onVisible);
|
|
377
|
-
this.#gate?.cancel();
|
|
378
|
-
this.#view?.dispose();
|
|
379
|
-
this.#view = undefined;
|
|
380
|
-
this.#taken?.release();
|
|
381
|
-
this.#taken = undefined;
|
|
382
|
-
this.#sky?.dispose();
|
|
383
|
-
this.#sky = undefined;
|
|
384
|
-
this.#placeLayer?.dispose();
|
|
385
|
-
this.#placeLayer = undefined;
|
|
386
|
-
this.#cities?.dispose();
|
|
387
|
-
this.#cities = undefined;
|
|
388
|
-
this.#countries?.dispose();
|
|
389
|
-
this.#countries = undefined;
|
|
390
|
-
}
|
|
391
|
-
attributeChangedCallback(name, _old, value) {
|
|
392
|
-
if (name === "center")
|
|
393
|
-
this.centre = readCentre(value) ?? { lon: 0, lat: 0 };
|
|
394
|
-
else if (name === "time")
|
|
395
|
-
this.time = readTime(value);
|
|
396
|
-
else if (name === "speed")
|
|
397
|
-
this.#setSpeed(readSpeed(value));
|
|
398
|
-
else if (name === "clouds")
|
|
399
|
-
this.clouds = value !== "off";
|
|
400
|
-
else if (name === "lights")
|
|
401
|
-
this.lights = value !== "off";
|
|
402
|
-
else if (name === "light")
|
|
403
|
-
this.light = readLight(value);
|
|
404
|
-
else if (name === "live-seconds")
|
|
405
|
-
this.#startTick();
|
|
406
|
-
else if (name === "tiles")
|
|
407
|
-
this.#gate?.soon();
|
|
408
|
-
else if (name === "data")
|
|
409
|
-
this.#door.book.ownOnly(value === "own");
|
|
410
|
-
else if (name === "camera")
|
|
411
|
-
this.camera = readCamera(value);
|
|
412
|
-
else if (name === "cloud-drift") {
|
|
413
|
-
this.#model.cloudDrift = readDrift(value);
|
|
414
|
-
this.#gate?.soon();
|
|
415
|
-
}
|
|
416
|
-
else if (name === "meteors")
|
|
417
|
-
this.meteors = this.#meteorsAsked();
|
|
418
|
-
else if (name === "meteors-strength") {
|
|
419
|
-
this.#model.meteors.strength = readMeteorStrength(value);
|
|
420
|
-
this.#gate?.soon();
|
|
421
|
-
}
|
|
422
|
-
else if (name === "air-thickness") {
|
|
423
|
-
this.#model.airThickness = readAirThickness(value);
|
|
424
|
-
this.#gate?.soon();
|
|
425
|
-
}
|
|
426
|
-
else if (name === "meteors-label" || name === "lang") {
|
|
427
|
-
this.#meteorNote();
|
|
428
|
-
if (name === "lang") {
|
|
429
|
-
this.#applyBodyLabel();
|
|
430
|
-
this.#sky?.refresh();
|
|
431
|
-
this.#cities?.refresh();
|
|
432
|
-
this.#countries?.refresh();
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
else if (BODY_LABEL_ATTRIBUTES.includes(name))
|
|
436
|
-
this.#applyBodyLabel();
|
|
437
|
-
else if (SKY_ATTRIBUTES.includes(name))
|
|
438
|
-
this.#sky?.refresh();
|
|
439
|
-
else if (name === "places") {
|
|
440
|
-
this.#placeList = readPlaces(value);
|
|
441
|
-
this.#placeLayer?.set(this.#placeList);
|
|
442
|
-
this.#gate?.soon();
|
|
443
|
-
}
|
|
444
|
-
else if (name === "places-look" && this.#placeLayer) {
|
|
445
|
-
this.#placeLayer.look = readPlaceLook(value);
|
|
446
|
-
this.#gate?.soon();
|
|
447
|
-
}
|
|
448
|
-
else if (name === "place-groups" && this.#placeLayer) {
|
|
449
|
-
this.#placeLayer.grouping = readPlaceGroups(value);
|
|
450
|
-
this.#gate?.soon();
|
|
451
|
-
}
|
|
452
|
-
else if (CITY_NAMES_ATTRIBUTES.includes(name))
|
|
453
|
-
this.#cities?.refresh();
|
|
454
|
-
else if (name === "borders") {
|
|
455
|
-
Object.assign(this.#model.borders, readBorders(value));
|
|
456
|
-
this.#gate?.soon();
|
|
457
|
-
}
|
|
458
|
-
else if (name === "grid") {
|
|
459
|
-
this.#model.grid.on = readGrid(value);
|
|
460
|
-
this.#gate?.soon();
|
|
461
|
-
}
|
|
462
|
-
else if (COUNTRY_NAMES_ATTRIBUTES.includes(name))
|
|
463
|
-
this.#countries?.refresh();
|
|
464
|
-
else if (name === "satellite-tint") {
|
|
465
|
-
this.#model.satellites.orbitTint = value === "orbit";
|
|
466
|
-
this.#gate?.soon();
|
|
467
|
-
}
|
|
468
|
-
if (name === "air-thickness" || name === "air-label" || name === "lang")
|
|
469
|
-
setAirNote(this.#airNote, this, this.#model.airThickness);
|
|
470
|
-
}
|
|
471
|
-
#meteorsAsked() {
|
|
472
|
-
return this.hasAttribute("meteors") && this.getAttribute("meteors") !== "off";
|
|
473
|
-
}
|
|
474
|
-
/** The line under the picture that says the streaks are an illustration, in the language of the element or the page. */
|
|
475
|
-
#meteorNote() {
|
|
476
|
-
setMeteorNote(this.#note, this, this.#model.meteors.on);
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* How many times its real thickness the air is drawn, from 1 (the true thickness) to 5 (the attribute `air-thickness`; 3 when the page says nothing). The shell, and the heights over which the air thins, are that many times larger, and the
|
|
480
|
-
* air's own light is the same, so a ring that is a hair's breadth at whole-Earth zoom can be seen. While it is above 1 the element says so in a line under the picture (`air-label="off"` takes the line away, for a page that says it itself).
|
|
481
|
-
*/
|
|
482
|
-
get airThickness() {
|
|
483
|
-
return this.#model.airThickness;
|
|
484
|
-
}
|
|
485
|
-
set airThickness(value) {
|
|
486
|
-
this.setAttribute("air-thickness", String(value));
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* Meteors seen from space, on or off (the attribute `meteors`): see the class's description. Off by default, and nothing of theirs is made until they are first switched on.
|
|
490
|
-
*/
|
|
491
|
-
get meteors() {
|
|
492
|
-
return this.#model.meteors.on;
|
|
493
|
-
}
|
|
494
|
-
set meteors(value) {
|
|
495
|
-
if (value !== this.#meteorsAsked()) {
|
|
496
|
-
if (value)
|
|
497
|
-
this.setAttribute("meteors", "");
|
|
498
|
-
else
|
|
499
|
-
this.removeAttribute("meteors");
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
this.#model.meteors.on = value;
|
|
503
|
-
this.#meteorNote();
|
|
504
|
-
this.#gate?.soon();
|
|
505
|
-
}
|
|
506
|
-
/**
|
|
507
|
-
* How strongly the meteors are drawn, from 0 to 1 (the attribute `meteors-strength`; 1, the full look, when the page says nothing): it scales how bright each streak is and how many are drawn, so 0.3 is
|
|
508
|
-
* fewer and fainter and 0 draws none. It changes nothing that is real: the rates, the showers and `chikyu-meteors` are the same at every strength, and the line under the picture still says the streaks are an illustration.
|
|
509
|
-
* A number outside the range is brought to its nearest end; setting the property writes the attribute.
|
|
510
|
-
*/
|
|
511
|
-
get meteorsStrength() {
|
|
512
|
-
return this.#model.meteors.strength;
|
|
513
|
-
}
|
|
514
|
-
set meteorsStrength(value) {
|
|
515
|
-
this.setAttribute("meteors-strength", String(value));
|
|
516
|
-
}
|
|
517
|
-
/**
|
|
518
|
-
* The name written on the Earth, as the family's body label: `EARTH` (`地球` on a Japanese page) laid on the globe so it turns with it, the surface showing through the letters. Off (`null`) unless the page sets it. The plain attributes are the family's:
|
|
519
|
-
* `body-label` (`painted`, `etched`, `outline` or `burned`; absent, no label), `body-label-strength` (0 to 1, 0.5), `body-label-repeat` (`once`, `both` or `around`), `body-label-latitude` (degrees), `body-label-facing` (present: always facing the reader),
|
|
520
|
-
* `body-label-font` (a CSS font family the page has loaded; Michroma, fetched once, when left out) and `body-label-fallback-font` (for letters the font has none of, such as Japanese). The property is the same options as an object, or `null`; setting it writes the attributes.
|
|
521
|
-
* Nothing of it is fetched or made until it is first set, it is not drawn while the Earth is under 24 pixels in radius, and nothing is drawn at rest. A three.js handed over with `setThreeLoader` must include `CanvasTexture`, `SphereGeometry`, `MeshLambertMaterial`, `SRGBColorSpace`, `NormalBlending`
|
|
522
|
-
* and `AdditiveBlending`; without them `chikyu-body-label-unavailable` is sent and the name is not drawn.
|
|
523
|
-
*/
|
|
524
|
-
get bodyLabel() {
|
|
525
|
-
return readBodyLabel((name) => this.getAttribute(name));
|
|
526
|
-
}
|
|
527
|
-
set bodyLabel(value) {
|
|
528
|
-
for (const name of BODY_LABEL_ATTRIBUTES)
|
|
529
|
-
this.removeAttribute(name);
|
|
530
|
-
if (value === null)
|
|
531
|
-
return;
|
|
532
|
-
this.setAttribute("body-label", value.look ?? "painted");
|
|
533
|
-
if (value.strength !== undefined)
|
|
534
|
-
this.setAttribute("body-label-strength", String(value.strength));
|
|
535
|
-
if (value.repeat !== undefined)
|
|
536
|
-
this.setAttribute("body-label-repeat", value.repeat);
|
|
537
|
-
if (value.latitude !== undefined)
|
|
538
|
-
this.setAttribute("body-label-latitude", String(value.latitude));
|
|
539
|
-
if (value.facing)
|
|
540
|
-
this.setAttribute("body-label-facing", "");
|
|
541
|
-
if (value.font)
|
|
542
|
-
this.setAttribute("body-label-font", value.font);
|
|
543
|
-
if (value.fallbackFont)
|
|
544
|
-
this.setAttribute("body-label-fallback-font", value.fallbackFont);
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* The names of the brightest stars and the constellations as faint lines, laid over the sky the page draws (hoshi-stars' `sky-labels`, an optional peer loaded only when one of these is set). The plain attributes are hoshi's: `star-names` (a count of the brightest stars in view and not covered by the
|
|
548
|
-
* Earth, the Moon or the Sun; bare is 10), `star-names-magnitude` (only stars at least that bright) and `constellation-lines` (the 88 figures as lines at this strength, 0 to 1; bare is 0.16): none of them, and nothing is loaded. The figure under the pointer or touched is at full strength and shows its name. Names are in the
|
|
549
|
-
* page's language and never overlap. Nothing is redrawn at rest. `chikyu-sky-unavailable` is sent when hoshi-stars is not there. The property is the look of the names, a partial `SkyLabelStyle` (font, size, case, ring, leader and the rest).
|
|
550
|
-
*/
|
|
551
|
-
get skyStyle() {
|
|
552
|
-
return { ...this.#skyStyle };
|
|
553
|
-
}
|
|
554
|
-
set skyStyle(value) {
|
|
555
|
-
this.#skyStyle = { ...value };
|
|
556
|
-
this.#sky?.setStyle(this.#skyStyle);
|
|
557
|
-
}
|
|
558
|
-
/**
|
|
559
|
-
* 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
|
|
560
|
-
* 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.
|
|
561
|
-
* 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`).
|
|
562
|
-
*/
|
|
563
|
-
get constellation() {
|
|
564
|
-
return this.#sky?.picked ?? null;
|
|
565
|
-
}
|
|
566
|
-
set constellation(value) {
|
|
567
|
-
this.#sky?.pick(value);
|
|
568
|
-
}
|
|
569
|
-
/**
|
|
570
|
-
* 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
|
|
571
|
-
* 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
|
|
572
|
-
* 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.
|
|
573
|
-
*/
|
|
574
|
-
get keepClear() {
|
|
575
|
-
return [...this.#keepClear];
|
|
576
|
-
}
|
|
577
|
-
set keepClear(value) {
|
|
578
|
-
this.#keepClear = value ? [...value] : [];
|
|
579
|
-
this.#sky?.setKeepClear(this.#keepClear);
|
|
580
|
-
}
|
|
581
|
-
/**
|
|
582
|
-
* 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`
|
|
583
|
-
* (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
|
|
584
|
-
* 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
|
|
585
|
-
* and keep their size in pixels at any zoom. Names never overlap one another; one with no room is left out. The element stores nothing and sends nothing: the page hands the places over and keeps them where
|
|
586
|
-
* 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 and for a reader who asked
|
|
587
|
-
* for less motion.
|
|
588
|
-
*/
|
|
589
|
-
get places() {
|
|
590
|
-
return this.#placeList.map((place) => ({ ...place }));
|
|
591
|
-
}
|
|
592
|
-
set places(value) {
|
|
593
|
-
const clean = cleanPlaces(value);
|
|
594
|
-
if (clean.length === 0)
|
|
595
|
-
this.removeAttribute("places");
|
|
596
|
-
else
|
|
597
|
-
this.setAttribute("places", JSON.stringify(clean));
|
|
598
|
-
}
|
|
599
|
-
/**
|
|
600
|
-
* Turn the Earth so a place of `places` is in the middle, at a pace a reader can follow (at once with `smooth: false`, for a reader who asked for less motion, or before the picture is live); the zoom
|
|
601
|
-
* and pan stay. The place is named by its `id`, or by its label in any case. The tilt is held to 90 degrees either way, so a place more than 90 degrees of latitude from `center` comes as near the middle
|
|
602
|
-
* as that allows.
|
|
603
|
-
*
|
|
604
|
-
* @param text - The place's id or label.
|
|
605
|
-
* @param options - `smooth` (true by default).
|
|
606
|
-
* @returns The place, once the turn has started; `undefined` when there is no such place.
|
|
607
|
-
*/
|
|
608
|
-
async goToPlace(text, options = {}) {
|
|
609
|
-
const place = findPlace(this.#placeList, text);
|
|
610
|
-
if (!place)
|
|
611
|
-
return undefined;
|
|
612
|
-
const view = this.#model.view;
|
|
613
|
-
const from = { yaw: view.yaw, tilt: view.tilt };
|
|
614
|
-
const to = aimAt(cameraCentre(this.#model), place, from);
|
|
615
|
-
const bar = this.hasAttribute("data-kazoku-bar") && this.id ? this.getRootNode().querySelector?.(`kazoku-view-controls[for="${CSS.escape(this.id)}"]`) : null;
|
|
616
|
-
const controls = (bar ? Reflect.get(bar, "controller") : undefined) ?? this.#hands?.controller;
|
|
617
|
-
const glide = (this.#placeGlide += 1);
|
|
618
|
-
const set = (yaw, tilt, final) => {
|
|
619
|
-
if (controls)
|
|
620
|
-
controls.set({ yaw, tilt }, final, "place");
|
|
621
|
-
else
|
|
622
|
-
this.setView({ ...this.#model.view, yaw, tilt }, final);
|
|
623
|
-
};
|
|
624
|
-
glideView(set, from, to, options.smooth !== false && !prefersLessMotion() && this.#view?.live === true, () => glide === this.#placeGlide && this.isConnected);
|
|
625
|
-
return { ...place };
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* 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.
|
|
629
|
-
*
|
|
630
|
-
* @example
|
|
631
|
-
* ```ts no-run
|
|
632
|
-
* import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
633
|
-
*
|
|
634
|
-
* const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
|
|
635
|
-
* earth.placeGroups = false;
|
|
636
|
-
* earth.getAttribute("place-groups"); // "off"
|
|
637
|
-
* earth.placeGroups = true;
|
|
638
|
-
* earth.hasAttribute("place-groups"); // false
|
|
639
|
-
* ```
|
|
640
|
-
*/
|
|
641
|
-
get placeGroups() {
|
|
642
|
-
return this.#placeLayer?.grouping ?? readPlaceGroups(this.getAttribute("place-groups"));
|
|
643
|
-
}
|
|
644
|
-
set placeGroups(value) {
|
|
645
|
-
if (value)
|
|
646
|
-
this.removeAttribute("place-groups");
|
|
647
|
-
else
|
|
648
|
-
this.setAttribute("place-groups", "off");
|
|
649
|
-
}
|
|
650
|
-
/** 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. */
|
|
651
|
-
#ringsDrawn(drawn) {
|
|
652
|
-
if (!this.#placeLayer || this.#placeLayer.ringsInPicture === drawn)
|
|
653
|
-
return;
|
|
654
|
-
this.#placeLayer.ringsInPicture = drawn;
|
|
655
|
-
this.#gate?.soon();
|
|
656
|
-
}
|
|
657
|
-
/** Tell the page once when places in sight had no room among the fallback circles. Missing `Points` alone leaves them drawn, so it says nothing. */
|
|
658
|
-
#notePlacesLost() {
|
|
659
|
-
const notice = placesLostNotice(this.#placesLost, this.#placeLayer?.stats.omitted ?? 0);
|
|
660
|
-
if (!notice)
|
|
661
|
-
return;
|
|
662
|
-
this.dispatchEvent(new CustomEvent("chikyu-places-unavailable", { detail: notice }));
|
|
663
|
-
}
|
|
664
|
-
/** 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). */
|
|
665
|
-
get placesLook() {
|
|
666
|
-
return this.#placeLayer?.look ?? readPlaceLook(this.getAttribute("places-look"));
|
|
667
|
-
}
|
|
668
|
-
set placesLook(value) {
|
|
669
|
-
this.setAttribute("places-look", value);
|
|
670
|
-
}
|
|
671
|
-
/**
|
|
672
|
-
* 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.
|
|
673
|
-
*/
|
|
674
|
-
get cityNamesStyle() {
|
|
675
|
-
return { ...this.#citiesStyle };
|
|
676
|
-
}
|
|
677
|
-
set cityNamesStyle(value) {
|
|
678
|
-
this.#citiesStyle = { ...value };
|
|
679
|
-
this.#cities?.setStyle(this.#citiesStyle);
|
|
680
|
-
}
|
|
681
|
-
/** Whether the meridians and parallels are drawn (the attribute `grid`). Setting it writes the attribute, or takes it away. */
|
|
682
|
-
get grid() {
|
|
683
|
-
return readGrid(this.getAttribute("grid"));
|
|
684
|
-
}
|
|
685
|
-
set grid(value) {
|
|
686
|
-
if (value)
|
|
687
|
-
this.setAttribute("grid", "");
|
|
688
|
-
else
|
|
689
|
-
this.removeAttribute("grid");
|
|
690
|
-
}
|
|
691
|
-
/**
|
|
692
|
-
* 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
|
|
693
|
-
* language and the data are not set here.
|
|
694
|
-
*/
|
|
695
|
-
get countryNamesStyle() {
|
|
696
|
-
return { ...this.#countriesStyle };
|
|
697
|
-
}
|
|
698
|
-
set countryNamesStyle(value) {
|
|
699
|
-
this.#countriesStyle = { ...value };
|
|
700
|
-
this.#countries?.setStyle(this.#countriesStyle);
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
* Which borders are drawn (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.
|
|
704
|
-
* Setting it writes the attribute: both sets as `borders="countries regions"`, one as its own word, none takes the attribute away.
|
|
705
|
-
*/
|
|
706
|
-
get borders() {
|
|
707
|
-
return readBorders(this.getAttribute("borders"));
|
|
708
|
-
}
|
|
709
|
-
set borders(value) {
|
|
710
|
-
const words = [value.countries ? "countries" : "", value.regions ? "regions" : ""].filter(Boolean);
|
|
711
|
-
if (words.length === 0)
|
|
712
|
-
this.removeAttribute("borders");
|
|
713
|
-
else
|
|
714
|
-
this.setAttribute("borders", words.join(" "));
|
|
715
|
-
}
|
|
716
|
-
/**
|
|
717
|
-
* 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.
|
|
718
|
-
* Set it before `borders` is switched on: shapes already loaded are kept.
|
|
719
|
-
*/
|
|
720
|
-
get borderData() {
|
|
721
|
-
return { ...this.#model.borders.data };
|
|
722
|
-
}
|
|
723
|
-
set borderData(value) {
|
|
724
|
-
this.#model.borders.data = { ...value };
|
|
725
|
-
this.#gate?.soon();
|
|
726
|
-
}
|
|
727
|
-
/** Tells the names of cities, then of countries, where the Earth is in the picture just drawn (the orthographic view the markers share); the countries' names keep clear of the places' and the cities'. */
|
|
728
|
-
#cityFrame() {
|
|
729
|
-
const pose = this.#pose;
|
|
730
|
-
if (!this.#cities || !pose)
|
|
731
|
-
return;
|
|
732
|
-
const frame = {
|
|
733
|
-
width: pose.width,
|
|
734
|
-
height: pose.height,
|
|
735
|
-
radius: pose.radius,
|
|
736
|
-
disc: { x: pose.cx, y: pose.cy, radius: pose.radius },
|
|
737
|
-
project: (lon, lat, out) => {
|
|
738
|
-
const at = project(lon, lat, pose);
|
|
739
|
-
out.x = at.x;
|
|
740
|
-
out.y = at.y;
|
|
741
|
-
return at.z;
|
|
742
|
-
},
|
|
743
|
-
};
|
|
744
|
-
this.#cities.frame(frame);
|
|
745
|
-
this.#nameFrame = frame;
|
|
746
|
-
this.#countryFrame();
|
|
747
|
-
}
|
|
748
|
-
/** The frame the names were last laid out on. */
|
|
749
|
-
#nameFrame = null;
|
|
750
|
-
/** Lays the countries' names out on the last frame, clear of the places' and the cities' names as they are now. */
|
|
751
|
-
#countryFrame() {
|
|
752
|
-
const countries = this.#countries;
|
|
753
|
-
if (!countries || !this.#nameFrame)
|
|
754
|
-
return;
|
|
755
|
-
countries.frame(this.#nameFrame, countries.stats.on ? [...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? []), ...[...this.#claims.values()].flat()] : []);
|
|
756
|
-
}
|
|
757
|
-
/** Puts the name's settings and text right from the attributes (`body-label` and its family, `lang`). */
|
|
758
|
-
#applyBodyLabel() {
|
|
759
|
-
this.#model.bodyLabel.settings = readBodyLabel((name) => this.getAttribute(name));
|
|
760
|
-
this.#model.bodyLabel.text = bodyLabelText((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en");
|
|
761
|
-
this.#gate?.soon();
|
|
762
|
-
}
|
|
763
|
-
/** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
|
|
764
|
-
get controller() {
|
|
765
|
-
return this.#hands?.controller;
|
|
766
|
-
}
|
|
767
|
-
/** The map source of each layer now: the last one a page added for it, else the folder of the `tiles` attribute. */
|
|
768
|
-
#tileSources() {
|
|
769
|
-
const folder = this.tiles === null ? undefined : folderSource(this.tiles);
|
|
770
|
-
const day = this.#door.book.mapSources("day")[0] ?? folder;
|
|
771
|
-
const night = this.#door.book.mapSources("night")[0] ?? folder;
|
|
772
|
-
return { ...(day ? { day } : {}), ...(night ? { night } : {}) };
|
|
773
|
-
}
|
|
774
|
-
/** The package's own credits for the last drawn frame: its pictures while it is drawn, and its finer tiles when a window of them is in view (unless a page added the folder itself, which the door counts). */
|
|
775
|
-
#ownCredits() {
|
|
776
|
-
const used = this.#model.tiles?.stats.used ?? {};
|
|
777
|
-
const own = [ownCredit("chikyu-pictures", this.#state === "live" ? 1 : 0)];
|
|
778
|
-
if (this.#door.book.get("chikyu-tiles") === undefined)
|
|
779
|
-
own.push(ownCredit("chikyu-tiles", used["chikyu-tiles"] ?? 0));
|
|
780
|
-
return own;
|
|
781
|
-
}
|
|
782
|
-
/**
|
|
783
|
-
* The outside sources of map this Earth draws from (the data door): each carries its own licence and credit, and a map source for the `day` or `night` layer takes the place of the folder of tiles for that layer. Assign a list to
|
|
784
|
-
* replace them; a source that is refused (an empty credit, no licence, a clashing id, a kind the Earth does not draw, a layer it does not know) throws a `TypeError` and nothing changes. A property, never an attribute: data is not text.
|
|
785
|
-
*/
|
|
786
|
-
get sources() {
|
|
787
|
-
return this.#door.sources();
|
|
788
|
-
}
|
|
789
|
-
set sources(list) {
|
|
790
|
-
this.#door.setSources(list);
|
|
791
|
-
}
|
|
792
|
-
/** Adds an outside source of map: checked at once (a `TypeError` for one that is refused), and the Earth draws from it. Returns the function that takes it away. */
|
|
793
|
-
addSource(source) {
|
|
794
|
-
return this.#door.book.addSource(source);
|
|
795
|
-
}
|
|
796
|
-
/** Takes a source away by its id: its loads stop, its tiles are freed, its credit goes. Returns whether there was one. */
|
|
797
|
-
removeSource(id) {
|
|
798
|
-
return this.#door.book.removeSource(id);
|
|
799
|
-
}
|
|
800
|
-
/** Switches a source off (`false`) or on again, and keeps it in the Earth: a layers panel's switch. The attribute `data="own"` ignores every outside source at once. */
|
|
801
|
-
enableSource(id, on) {
|
|
802
|
-
this.#door.book.enableSource(id, on);
|
|
803
|
-
}
|
|
804
|
-
/**
|
|
805
|
-
* Whose data is in the last drawn frame: the package's own first (its pictures; its finer tiles while a window of them is in view) and then each outside source that gave a tile, with how many (`used`). `creditLine(credits, "en" | "ja")`
|
|
806
|
-
* from `@johnmorrisdotca/chikyu-earth/door` writes them as a line with the licences. `chikyu-creditschange` fires when this set changes (not at each frame), with `detail: { credits }`.
|
|
807
|
-
*/
|
|
808
|
-
credits() {
|
|
809
|
-
return this.#door.credits();
|
|
810
|
-
}
|
|
811
|
-
/** Where the finer map tiles are served from (a folder with `manifest.json`), or `null` for none; the attribute `tiles`. The Earth loads only the tiles in view, over its own pictures. */
|
|
812
|
-
get tiles() {
|
|
813
|
-
const given = this.getAttribute("tiles");
|
|
814
|
-
if (!given)
|
|
815
|
-
return null;
|
|
816
|
-
return given.endsWith("/") ? given : `${given}/`;
|
|
817
|
-
}
|
|
818
|
-
set tiles(value) {
|
|
819
|
-
if (value === null || value === "")
|
|
820
|
-
this.removeAttribute("tiles");
|
|
821
|
-
else
|
|
822
|
-
this.setAttribute("tiles", value);
|
|
823
|
-
}
|
|
824
|
-
/** A box laid over the Earth for markers (see `@johnmorrisdotca/chikyu-earth/markers`): where it is, the pose of the last draw, and a way to hear the next. */
|
|
825
|
-
get overlay() {
|
|
826
|
-
if (!this.#overlay)
|
|
827
|
-
throw new Error("chikyu-earth-realistic: attach markers once the element is in the page");
|
|
828
|
-
return {
|
|
829
|
-
overlayRoot: this.#overlay,
|
|
830
|
-
pose: this.#pose,
|
|
831
|
-
subscribe: (listener) => {
|
|
832
|
-
this.#listeners.add(listener);
|
|
833
|
-
return () => this.#listeners.delete(listener);
|
|
834
|
-
},
|
|
835
|
-
claim: (owner, boxes) => {
|
|
836
|
-
if (boxes.length === 0)
|
|
837
|
-
this.#claims.delete(owner);
|
|
838
|
-
else
|
|
839
|
-
this.#claims.set(owner, boxes);
|
|
840
|
-
// laid out again only when the overlay changed between draws: at a draw the names are laid out after it anyway
|
|
841
|
-
if (!this.#posing)
|
|
842
|
-
this.#countryFrame();
|
|
843
|
-
},
|
|
844
|
-
};
|
|
845
|
-
}
|
|
846
|
-
/** The boxes overlays on the element (markers) take, by overlay. */
|
|
847
|
-
#claims = new Map();
|
|
848
|
-
/** True while the overlays are told of a draw. */
|
|
849
|
-
#posing = false;
|
|
850
|
-
/** Where the view starts: longitude and latitude; the shared controls' yaw and tilt turn it from there. */
|
|
851
|
-
get centre() {
|
|
852
|
-
return { ...this.#model.centre };
|
|
853
|
-
}
|
|
854
|
-
set centre(value) {
|
|
855
|
-
this.#model.centre = { ...value };
|
|
856
|
-
this.#model.cameraSpin = null;
|
|
857
|
-
this.#gate?.soon();
|
|
858
|
-
}
|
|
859
|
-
/**
|
|
860
|
-
* How the camera is held (the `camera` attribute). `space` (the default): held in the stars, looking at the place `center` names as it is at the
|
|
861
|
-
* moment the camera is set (when the element opens, and again when `time` or `center` is set), so the Earth turns beneath it as the clock runs, with the day and night line where the Sun really is. `ground`: over the place `center` names on the ground, so the Earth keeps still and the clock moves the light across it. `sun`: held on the Sun's side, `center` being the longitude and
|
|
862
|
-
* latitude from the sub-solar point (`0,0` looks straight at the noon place and shows no night), so the day and night line keeps its place on the screen while the Earth turns beneath. A drag turns the view about the same body in any of them.
|
|
863
|
-
*/
|
|
864
|
-
get camera() {
|
|
865
|
-
return this.#model.camera;
|
|
866
|
-
}
|
|
867
|
-
set camera(value) {
|
|
868
|
-
this.#model.camera = value;
|
|
869
|
-
this.#model.cameraSpin = null;
|
|
870
|
-
this.#gate?.soon();
|
|
871
|
-
}
|
|
872
|
-
/** True for the full-screen mode (the `immersive` attribute): the element fills its box in any shape, a plain wheel zooms instead of scrolling the page, and a touch drag turns the view instead of scrolling. */
|
|
873
|
-
get immersive() {
|
|
874
|
-
return this.hasAttribute("immersive");
|
|
875
|
-
}
|
|
876
|
-
set immersive(value) {
|
|
877
|
-
this.toggleAttribute("immersive", value);
|
|
878
|
-
}
|
|
879
|
-
/** The moment shown: milliseconds since the epoch, or "now" while it follows the real clock. The clock runs from it at `speed`, so a number read while time runs is the moment it has reached. */
|
|
880
|
-
get time() {
|
|
881
|
-
return this.#mode === "now" && this.speed === 1 ? "now" : this.#model.time;
|
|
882
|
-
}
|
|
883
|
-
set time(value) {
|
|
884
|
-
this.#mode = value instanceof Date ? value.getTime() : value;
|
|
885
|
-
if (this.#mode === "now")
|
|
886
|
-
this.#model.time = Date.now();
|
|
887
|
-
else
|
|
888
|
-
this.#model.time = this.#mode;
|
|
889
|
-
this.#model.cameraSpin = null;
|
|
890
|
-
this.#model.speed = this.speed;
|
|
891
|
-
this.#last = performance.now();
|
|
892
|
-
this.#startTick();
|
|
893
|
-
this.#gate?.soon();
|
|
894
|
-
}
|
|
895
|
-
/**
|
|
896
|
-
* Seconds of time for each real second: `1` is real time, `0` holds, `3600` is an hour a second, `86400` a day a second, a negative number runs backwards. Without one (the attribute `speed` left out) the clock
|
|
897
|
-
* follows `time`: real time for "now", held for a date. Reading it gives the speed in force. Setting it is setting the attribute (and `null`-like, a value that is not a number, takes it off); it works out the moment shown up to now at the old speed first, so a hold keeps the moment the reader saw last.
|
|
898
|
-
*/
|
|
899
|
-
get speed() {
|
|
900
|
-
return this.#speed ?? (this.#mode === "now" ? 1 : 0);
|
|
901
|
-
}
|
|
902
|
-
set speed(value) {
|
|
903
|
-
if (Number.isFinite(value))
|
|
904
|
-
this.setAttribute("speed", String(value));
|
|
905
|
-
else
|
|
906
|
-
this.removeAttribute("speed");
|
|
907
|
-
}
|
|
908
|
-
#setSpeed(next) {
|
|
909
|
-
if (this.isConnected && this.speed !== 0)
|
|
910
|
-
this.#advance(performance.now());
|
|
911
|
-
if (this.isConnected && this.#view)
|
|
912
|
-
this.#played = true;
|
|
913
|
-
this.#speed = next;
|
|
914
|
-
this.#model.speed = this.speed;
|
|
915
|
-
this.#last = performance.now();
|
|
916
|
-
this.#startTick();
|
|
917
|
-
this.#gate?.soon();
|
|
918
|
-
}
|
|
919
|
-
get clouds() {
|
|
920
|
-
return this.#model.clouds;
|
|
921
|
-
}
|
|
922
|
-
set clouds(value) {
|
|
923
|
-
this.#model.clouds = value;
|
|
924
|
-
this.#gate?.soon();
|
|
925
|
-
}
|
|
926
|
-
/** How the Earth is lit: `sun` (true, the default), `lit` (always lit: the night side is never a black frame) or `boost` (the true terminator with the night side raised). */
|
|
927
|
-
get light() {
|
|
928
|
-
return this.#model.light;
|
|
929
|
-
}
|
|
930
|
-
set light(value) {
|
|
931
|
-
this.#model.light = value;
|
|
932
|
-
this.#gate?.soon();
|
|
933
|
-
}
|
|
934
|
-
get lights() {
|
|
935
|
-
return this.#model.lights;
|
|
936
|
-
}
|
|
937
|
-
set lights(value) {
|
|
938
|
-
this.#model.lights = value;
|
|
939
|
-
this.#gate?.soon();
|
|
940
|
-
}
|
|
941
|
-
/** What the element is doing, for a page or a test: its state, the texture widths held, the map tiles held, the draws made. */
|
|
942
|
-
get stats() {
|
|
943
|
-
const stats = this.#taken?.renderer.stats;
|
|
944
|
-
return {
|
|
945
|
-
state: this.#state,
|
|
946
|
-
tiers: { ...this.#tiers },
|
|
947
|
-
satellites: this.#satelliteStats(),
|
|
948
|
-
tiles: this.#model.tiles?.stats ?? { ready: false, level: null, held: 0, shown: 0, loading: 0, failed: 0, requested: 0, heldBytes: 0, refused: 0, used: {} },
|
|
949
|
-
draws: stats?.draws ?? 0,
|
|
950
|
-
contexts: stats?.contexts ?? 0,
|
|
951
|
-
canvas: stats?.canvas ?? { width: 0, height: 0, pixels: 0 },
|
|
952
|
-
assets: { entries: stats?.assets.entries ?? 0, refs: stats?.assets.refs ?? 0 },
|
|
953
|
-
meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
|
|
954
|
-
bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
|
|
955
|
-
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: [] },
|
|
956
|
-
places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 }) },
|
|
957
|
-
cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
|
|
958
|
-
borders: { ...this.#model.borders.stats, shown: { ...this.#model.borders.stats.shown }, loaded: [...this.#model.borders.stats.loaded] },
|
|
959
|
-
grid: { ...this.#model.grid.stats },
|
|
960
|
-
countryNames: this.#countries?.stats ?? { on: false, max: 0, countries: 0, names: 0, renders: 0, failed: false },
|
|
961
|
-
};
|
|
962
|
-
}
|
|
963
|
-
/**
|
|
964
|
-
* Apply a shared view controller's camera (yaw, tilt, zoom, pan). A change under half a pixel is not drawn, a settled change always is,
|
|
965
|
-
* and draws are at most 30 a second.
|
|
966
|
-
*/
|
|
967
|
-
setView(view, final = true) {
|
|
968
|
-
this.#model.view = { ...view };
|
|
969
|
-
const drawn = this.#model.drawn;
|
|
970
|
-
if (!drawn) {
|
|
971
|
-
this.#gate?.soon();
|
|
972
|
-
return;
|
|
973
|
-
}
|
|
974
|
-
const shifted = view.zoom !== drawn.view.zoom || view.panX !== drawn.view.panX || view.panY !== drawn.view.panY;
|
|
975
|
-
const a = lookAt(drawn.centre, drawn.view);
|
|
976
|
-
const b = lookAt(cameraCentre(this.#model), view);
|
|
977
|
-
const px = (Math.abs(b.lon - a.lon) * Math.cos(((a.lat + b.lat) / 2) * RAD) + Math.abs(b.lat - a.lat)) * RAD * drawn.radius;
|
|
978
|
-
if (shifted || px >= 0.5 || (final && px > 0.01))
|
|
979
|
-
this.#gate?.soon();
|
|
980
|
-
}
|
|
981
|
-
// --- satellites ---------------------------------------------------------------------------------------------------------------------------------
|
|
982
|
-
/**
|
|
983
|
-
* Colour each satellite by its orbit class (low, medium, geostationary, highly elliptical, other). Off by default, so a group keeps the colour it was given. The attribute is `satellite-tint="orbit"`.
|
|
984
|
-
*/
|
|
985
|
-
get satelliteTint() {
|
|
986
|
-
return this.#model.satellites.orbitTint ? "orbit" : "off";
|
|
987
|
-
}
|
|
988
|
-
set satelliteTint(value) {
|
|
989
|
-
if (value === "orbit")
|
|
990
|
-
this.setAttribute("satellite-tint", "orbit");
|
|
991
|
-
else
|
|
992
|
-
this.removeAttribute("satellite-tint");
|
|
993
|
-
}
|
|
994
|
-
/**
|
|
995
|
-
* Show a group of satellites (made by `createSatellites`) under a name, or take the group away with `null`. A group is one draw call however many satellites it holds, so every group of the catalogue can be shown at once. Giving the name of a group
|
|
996
|
-
* that is already shown replaces it. `style`: `color` and `size` (CSS pixels) of the dots, and `orbits` to draw every orbit (only for a group of 40 or fewer, such as the stations). The groups are placed by SGP4 about once a second and interpolated
|
|
997
|
-
* between. Above `MAX_SATELLITE_SPEED` each satellite is a short streak along its orbit instead of being hidden. They are hidden by the Earth when they are behind it, and draw at most 30 times a second and not at all while the clock holds.
|
|
998
|
-
*
|
|
999
|
-
* @param group - The group's name, for `showSatellites`, `selectSatellite` and the events.
|
|
1000
|
-
* @param satellites - The group, or `null` to remove it.
|
|
1001
|
-
* @param style - How to draw it.
|
|
1002
|
-
*/
|
|
1003
|
-
/**
|
|
1004
|
-
* Paint one satellite's path on the Earth. `id` is a NORAD catalogue number or `group:index`. `length` is how long the trail is kept, in simulated time (`1d` when left out, or `1w`, `1m`). `swath` is `track` (the point under the satellite, the default) or `coverage` (where it is at least 10° above the horizon). Setting another satellite clears the trail. `null` clears it.
|
|
1005
|
-
*/
|
|
1006
|
-
get paint() {
|
|
1007
|
-
return this.#paint.on ? { id: this.#paint.id, length: this.#paint.length, swath: this.#paint.swath } : null;
|
|
1008
|
-
}
|
|
1009
|
-
set paint(value) {
|
|
1010
|
-
this.#paint.set(value);
|
|
1011
|
-
this.#gate?.soon();
|
|
1012
|
-
}
|
|
1013
|
-
/** Take the painted trail off the Earth. */
|
|
1014
|
-
clearPaint() {
|
|
1015
|
-
this.#paint.clear();
|
|
1016
|
-
this.#gate?.soon();
|
|
1017
|
-
}
|
|
1018
|
-
/** Texels the trail has painted. 0 after `clearPaint`, and again when the painted satellite changes. */
|
|
1019
|
-
get paintPixels() {
|
|
1020
|
-
return this.#paint.pixels;
|
|
1021
|
-
}
|
|
1022
|
-
setSatellites(group, satellites, style = {}) {
|
|
1023
|
-
const groups = this.#model.satellites.groups;
|
|
1024
|
-
if (satellites === null) {
|
|
1025
|
-
groups.delete(group);
|
|
1026
|
-
if (this.#model.satellites.selected?.group === group)
|
|
1027
|
-
this.#model.satellites.selected = null;
|
|
1028
|
-
}
|
|
1029
|
-
else {
|
|
1030
|
-
const was = groups.get(group);
|
|
1031
|
-
groups.set(group, {
|
|
1032
|
-
satellites,
|
|
1033
|
-
color: style.color ?? was?.color ?? SATELLITE_COLORS[groups.size % SATELLITE_COLORS.length],
|
|
1034
|
-
size: style.size ?? was?.size ?? 3,
|
|
1035
|
-
orbits: (style.orbits ?? was?.orbits ?? false) && satellites.count <= MAX_ORBIT_GROUP,
|
|
1036
|
-
visible: was?.visible ?? true,
|
|
1037
|
-
});
|
|
1038
|
-
}
|
|
1039
|
-
this.#last = performance.now();
|
|
1040
|
-
this.#startTick();
|
|
1041
|
-
this.#gate?.soon();
|
|
1042
|
-
}
|
|
1043
|
-
/** Show or hide a group without losing it. */
|
|
1044
|
-
showSatellites(group, on) {
|
|
1045
|
-
const found = this.#model.satellites.groups.get(group);
|
|
1046
|
-
if (!found || found.visible === on)
|
|
1047
|
-
return;
|
|
1048
|
-
found.visible = on;
|
|
1049
|
-
this.#startTick();
|
|
1050
|
-
this.#gate?.soon();
|
|
1051
|
-
}
|
|
1052
|
-
/** The groups now set, with how many satellites each holds and whether it is shown. */
|
|
1053
|
-
get satelliteGroups() {
|
|
1054
|
-
return [...this.#model.satellites.groups].map(([name, group]) => ({ name, count: group.satellites.count, visible: group.visible }));
|
|
1055
|
-
}
|
|
1056
|
-
/** Mark one satellite: a larger ring round it and its orbit drawn. `null` lets it go. */
|
|
1057
|
-
selectSatellite(ref) {
|
|
1058
|
-
const found = ref ? this.#model.satellites.groups.get(ref.group) : undefined;
|
|
1059
|
-
this.#model.satellites.selected = ref && found && ref.index >= 0 && ref.index < found.satellites.count ? { group: ref.group, index: ref.index } : null;
|
|
1060
|
-
this.#gate?.soon();
|
|
1061
|
-
}
|
|
1062
|
-
/** The satellite marked by `selectSatellite` or by a press on it, if any. */
|
|
1063
|
-
get selectedSatellite() {
|
|
1064
|
-
const chosen = this.#model.satellites.selected;
|
|
1065
|
-
return chosen ? { ...chosen } : null;
|
|
1066
|
-
}
|
|
1067
|
-
/** Facts about one satellite at the moment shown (name, number, element age, height, speed, period, and `ownerCountry` when the owner is one country); undefined if it cannot be placed then. */
|
|
1068
|
-
satelliteInfo(ref) {
|
|
1069
|
-
return this.#model.satellites.groups.get(ref.group)?.satellites.info(ref.index, this.#model.time);
|
|
1070
|
-
}
|
|
1071
|
-
#satelliteStats() {
|
|
1072
|
-
const drawn = this.#model.satellites.drawn;
|
|
1073
|
-
let propagations = 0;
|
|
1074
|
-
let lastBatchMs = 0;
|
|
1075
|
-
let maxBatchMs = 0;
|
|
1076
|
-
for (const group of this.#model.satellites.groups.values()) {
|
|
1077
|
-
propagations += group.satellites.propagations;
|
|
1078
|
-
lastBatchMs = Math.max(lastBatchMs, group.satellites.timing.lastBatchMs);
|
|
1079
|
-
maxBatchMs = Math.max(maxBatchMs, group.satellites.timing.maxBatchMs);
|
|
1080
|
-
}
|
|
1081
|
-
let epochMs = 0;
|
|
1082
|
-
for (const group of this.#model.satellites.groups.values())
|
|
1083
|
-
epochMs = Math.max(epochMs, group.satellites.newestEpochMs);
|
|
1084
|
-
return { groups: this.#model.satellites.groups.size, placed: drawn.placed, segments: drawn.segments, tooFast: drawn.tooFast, dotScale: drawn.dotScale, epochMs, propagations, lastBatchMs, maxBatchMs, updateMs: drawn.updateMs, maxUpdateMs: drawn.maxUpdateMs, averageUpdateMs: drawn.updates ? drawn.totalMs / drawn.updates : 0, updates: drawn.updates };
|
|
1085
|
-
}
|
|
1086
|
-
// A press that does not turn the view (under 6 pixels) on a satellite tells the page, which chooses it with `selectSatellite` if it likes.
|
|
1087
|
-
#downX = 0;
|
|
1088
|
-
#downY = 0;
|
|
1089
|
-
#down = (event) => {
|
|
1090
|
-
if (event.button !== 0 || this.#model.satellites.groups.size === 0)
|
|
1091
|
-
return;
|
|
1092
|
-
this.#downX = event.clientX;
|
|
1093
|
-
this.#downY = event.clientY;
|
|
1094
|
-
window.addEventListener("pointerup", this.#up, { capture: true, once: true });
|
|
1095
|
-
};
|
|
1096
|
-
#up = (event) => {
|
|
1097
|
-
if (Math.hypot(event.clientX - this.#downX, event.clientY - this.#downY) > 6)
|
|
1098
|
-
return;
|
|
1099
|
-
const rect = this.getBoundingClientRect();
|
|
1100
|
-
const satellite = this.#model.pick?.(event.clientX - rect.left, event.clientY - rect.top, 12);
|
|
1101
|
-
if (satellite)
|
|
1102
|
-
this.dispatchEvent(new CustomEvent("chikyu-satellite-click", { detail: { ...satellite, info: this.satelliteInfo(satellite) }, bubbles: true, composed: true }));
|
|
1103
|
-
};
|
|
1104
|
-
#wheel = (event) => immersiveWheel(this, event);
|
|
1105
|
-
/** The view as it is (for a page that wants to read it back). */
|
|
1106
|
-
get view() {
|
|
1107
|
-
return { ...this.#model.view };
|
|
1108
|
-
}
|
|
1109
|
-
/** Bring the moment shown up to `now` (the page's own clock, in milliseconds) at the speed it has run at. */
|
|
1110
|
-
#advance(now) {
|
|
1111
|
-
if (this.speed === 1 && this.#mode === "now")
|
|
1112
|
-
this.#model.time = Date.now();
|
|
1113
|
-
else
|
|
1114
|
-
this.#model.time += (now - this.#last) * this.speed;
|
|
1115
|
-
this.#last = now;
|
|
1116
|
-
}
|
|
1117
|
-
/** The wait before the next step: real time every `live-seconds` (a minute by default); faster time as often as the Sun's turn moves a pixel, 1 to 30 times a second (once a second for a reader who prefers reduced motion). */
|
|
1118
|
-
#wait() {
|
|
1119
|
-
const seconds = Number(this.getAttribute("live-seconds"));
|
|
1120
|
-
const live = Number.isFinite(seconds) && seconds > 0 ? Math.max(MIN_TICK_MS, seconds * 1000) : LIVE_TICK_MS;
|
|
1121
|
-
const speed = Math.abs(this.speed);
|
|
1122
|
-
const satellites = this.#satellitesMoving();
|
|
1123
|
-
// satellites go round in 90 minutes, so with any on show even real time is drawn about once a second
|
|
1124
|
-
if (speed <= 1 && !satellites)
|
|
1125
|
-
return live;
|
|
1126
|
-
if (typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches)
|
|
1127
|
-
return Math.min(live, 1000);
|
|
1128
|
-
const radius = this.#model.drawn?.radius ?? 200;
|
|
1129
|
-
return Math.min(live, 1000 / Math.min(30, Math.max(1, (satellites ? SATELLITE_RATE : SUN_RATE) * RAD * speed * radius)));
|
|
1130
|
-
}
|
|
1131
|
-
/** Is anything on show that moves faster than the Earth turns: a group of satellites, including above the interpolation limit where they are drawn as streaks? */
|
|
1132
|
-
#satellitesMoving() {
|
|
1133
|
-
for (const group of this.#model.satellites.groups.values())
|
|
1134
|
-
if (group.visible && group.satellites.count > 0)
|
|
1135
|
-
return true;
|
|
1136
|
-
return false;
|
|
1137
|
-
}
|
|
1138
|
-
/** Tell the page the moment shown: at most four times a second while time runs (`running`, and not from a hidden tab), and once, at once, when it holds. */
|
|
1139
|
-
#announce(running) {
|
|
1140
|
-
const now = performance.now();
|
|
1141
|
-
if (running && (now - this.#announced < TIME_EVENT_MS || document.visibilityState === "hidden"))
|
|
1142
|
-
return;
|
|
1143
|
-
this.#announced = running ? now : -Infinity;
|
|
1144
|
-
this.dispatchEvent(new CustomEvent("chikyu-timechange", { detail: { time: this.#model.time, running } }));
|
|
1145
|
-
}
|
|
1146
|
-
/** While the clock runs the Sun and the clouds are put right at the pace `#wait` gives, and nothing runs at all while it holds. */
|
|
1147
|
-
#startTick() {
|
|
1148
|
-
clearTimeout(this.#tick);
|
|
1149
|
-
this.#tick = undefined;
|
|
1150
|
-
const go = this.isConnected && this.speed !== 0;
|
|
1151
|
-
// the clock was running and now holds: told once, so a page's date box stops following it
|
|
1152
|
-
if (this.#running && !go) {
|
|
1153
|
-
this.#running = false;
|
|
1154
|
-
this.#announce(false);
|
|
1155
|
-
}
|
|
1156
|
-
if (!go)
|
|
1157
|
-
return;
|
|
1158
|
-
this.#running = true;
|
|
1159
|
-
this.#tick = setTimeout(this.#onTick, this.#wait());
|
|
1160
|
-
}
|
|
1161
|
-
#onTick = () => {
|
|
1162
|
-
this.#advance(performance.now());
|
|
1163
|
-
this.#tick = setTimeout(this.#onTick, this.#wait());
|
|
1164
|
-
this.#gate?.soon();
|
|
1165
|
-
this.#announce(true);
|
|
1166
|
-
};
|
|
1167
|
-
/** Back in a shown tab: the moment is brought up to date, and drawn. */
|
|
1168
|
-
#onVisible = () => {
|
|
1169
|
-
if (document.visibilityState === "hidden" || !this.#running)
|
|
1170
|
-
return;
|
|
1171
|
-
this.#advance(performance.now());
|
|
1172
|
-
this.#gate?.soon();
|
|
1173
|
-
this.#announce(true);
|
|
1174
|
-
};
|
|
1175
|
-
#take = () => {
|
|
1176
|
-
if (this.#view && !this.#view.live)
|
|
1177
|
-
void this.#view.focus();
|
|
1178
|
-
};
|
|
1179
|
-
#textureBase() {
|
|
1180
|
-
const given = this.getAttribute("texture-base");
|
|
1181
|
-
const base = given ?? new URL("../textures/", import.meta.url).href;
|
|
1182
|
-
return base.endsWith("/") ? base : `${base}/`;
|
|
1183
|
-
}
|
|
1184
|
-
#textureCap() {
|
|
1185
|
-
const given = Number(this.getAttribute("max-texture"));
|
|
1186
|
-
const memory = navigator.deviceMemory;
|
|
1187
|
-
const cap = Number.isFinite(given) && given > 0 ? Math.min(given, MAX_TEXTURE) : MAX_TEXTURE;
|
|
1188
|
-
return memory !== undefined && memory <= 2 ? Math.min(cap, 2048) : cap;
|
|
1189
|
-
}
|
|
1190
|
-
#set(state) {
|
|
1191
|
-
if (this.#state === state)
|
|
1192
|
-
return;
|
|
1193
|
-
this.#state = state;
|
|
1194
|
-
this.dataset["state"] = state;
|
|
1195
|
-
}
|
|
1196
|
-
#fail(reason) {
|
|
1197
|
-
this.#set("unavailable");
|
|
1198
|
-
this.dispatchEvent(new CustomEvent("chikyu-unavailable", { detail: { reason } }));
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
if (typeof customElements !== "undefined" && !customElements.get("chikyu-earth-realistic")) {
|
|
1202
|
-
customElements.define("chikyu-earth-realistic", ChikyuEarthRealistic);
|
|
1203
|
-
}
|
|
1
|
+
// `<chikyu-earth-realistic>` with every sky culture a page can ask for (`constellation-culture`). Each is a file of its own, loaded only when it is asked for. For a build without them use `realistic/no-cultures`.
|
|
2
|
+
import "../sky/cultures.js";
|
|
3
|
+
export * from "./element-base.js";
|