@johnmorrisdotca/chikyu-earth 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/NOTICE.md +23 -1
- package/README.md +20 -2
- package/dist/borders/layer.d.ts +75 -0
- package/dist/borders/layer.js +136 -0
- package/dist/borders/lines.d.ts +138 -0
- package/dist/borders/lines.js +227 -0
- package/dist/cities/host.d.ts +9 -0
- package/dist/cities/host.js +14 -2
- package/dist/country-names/geometry.d.ts +264 -0
- package/dist/country-names/geometry.js +372 -0
- package/dist/country-names/host.d.ts +82 -0
- package/dist/country-names/host.js +212 -0
- package/dist/grid/layer.d.ts +45 -0
- package/dist/grid/layer.js +66 -0
- package/dist/grid/lines.d.ts +85 -0
- package/dist/grid/lines.js +113 -0
- package/dist/markers/go-to-place.d.ts +27 -0
- package/dist/markers/go-to-place.js +35 -0
- package/dist/markers/index.d.ts +2 -1
- package/dist/markers/index.js +2 -1
- package/dist/markers/layer.d.ts +7 -0
- package/dist/markers/layer.js +7 -0
- package/dist/markers/place-layer.d.ts +58 -7
- package/dist/markers/place-layer.js +326 -64
- package/dist/markers/place-sprites.d.ts +33 -0
- package/dist/markers/place-sprites.js +161 -0
- package/dist/markers/places.d.ts +91 -6
- package/dist/markers/places.js +135 -6
- package/dist/realistic/earth.d.ts +11 -0
- package/dist/realistic/earth.js +54 -0
- package/dist/realistic/element.d.ts +65 -4
- package/dist/realistic/element.js +198 -26
- package/dist/realistic/immersive.d.ts +7 -0
- package/dist/realistic/immersive.js +17 -0
- package/dist/realistic/index.d.ts +6 -0
- package/dist/realistic/index.js +3 -0
- package/dist/realistic/textures.d.ts +3 -0
- package/dist/space/element.d.ts +81 -7
- package/dist/space/element.js +246 -16
- package/dist/space/index.d.ts +1 -1
- package/dist/space/scene.d.ts +53 -5
- package/dist/space/scene.js +88 -8
- package/package.json +3 -3
package/dist/space/element.js
CHANGED
|
@@ -3,13 +3,20 @@ import { adoptStyles } from "../adopt.js";
|
|
|
3
3
|
import { airFor, readAirThickness } from "../realistic/air.js";
|
|
4
4
|
import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "../realistic/body-label.js";
|
|
5
5
|
import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
|
|
6
|
-
import { cleanPlaces, readPlaces } from "../markers/places.js";
|
|
6
|
+
import { cleanPlaces, readPlaceGroups, readPlaces } from "../markers/places.js";
|
|
7
7
|
import { createPlaceLayer, PLACE_STYLE, readPlaceLook } from "../markers/place-layer.js";
|
|
8
|
+
import { aimAt, findPlace, glideView } from "../markers/go-to-place.js";
|
|
9
|
+
import { subsolarPoint } from "../realistic/sun.js";
|
|
8
10
|
import { SHORT_NAMES } from "../satellites/names.js";
|
|
9
11
|
import { CITY_NAMES_ATTRIBUTES, CITY_NAMES_STYLE, createCityHost } from "../cities/host.js";
|
|
12
|
+
import { BORDER_ATTRIBUTES, readBorders } from "../borders/lines.js";
|
|
13
|
+
import { GRID_ATTRIBUTES, readGrid } from "../grid/lines.js";
|
|
14
|
+
import { COUNTRY_NAMES_ATTRIBUTES } from "../country-names/geometry.js";
|
|
15
|
+
import { COUNTRY_NAMES_STYLE, createCountryHost } from "../country-names/host.js";
|
|
10
16
|
import { createGate, frameCap } from "../realistic/gate.js";
|
|
11
17
|
import { setThreeLoader, takeRenderer } from "../realistic/shared.js";
|
|
12
18
|
import { NOTES_STYLE, setAirNote } from "../realistic/air-note.js";
|
|
19
|
+
import { IMMERSIVE_STYLE, immersiveWheel } from "../realistic/immersive.js";
|
|
13
20
|
import { readMeteorStrength } from "../meteors/strength.js";
|
|
14
21
|
import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
|
|
15
22
|
import { MAX_TEXTURE } from "../realistic/tiers.js";
|
|
@@ -98,17 +105,25 @@ const readTime = (value) => {
|
|
|
98
105
|
const ms = Date.parse(value);
|
|
99
106
|
return Number.isFinite(ms) ? ms : "now";
|
|
100
107
|
};
|
|
101
|
-
const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden;isolation:isolate}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-sat{position:absolute;left:0;top:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-sat[hidden]{display:none}${PLACE_STYLE}${SKY_STYLE}${CITY_NAMES_STYLE}${METEOR_NOTE_STYLE}${NOTES_STYLE}`;
|
|
108
|
+
const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden;isolation:isolate}${IMMERSIVE_STYLE}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-sat{position:absolute;left:0;top:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-sat[hidden]{display:none}${PLACE_STYLE}${SKY_STYLE}${COUNTRY_NAMES_STYLE}${CITY_NAMES_STYLE}${METEOR_NOTE_STYLE}${NOTES_STYLE}`;
|
|
102
109
|
/**
|
|
103
110
|
* The `<chikyu-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`, `time` (`now` or an ISO date), `speed` (1 is real time, 0 holds, 86400 is a day a second, negative runs backwards), `scale` (`compressed` or `true`), `labels` and `orbits` (`off` hides them); positions are computed in the browser by astronomy-engine, an optional peer dependency. It draws only when something changes, and nothing while it is out of sight.
|
|
104
111
|
*
|
|
105
|
-
* It carries kazoku-ui's controls itself: a drag turns the view, two fingers pinch, Ctrl and the wheel zoom (a plain wheel at Fit scrolls the page) and the arrow keys, + and - work once it is focused. The zoom runs from a millionth of Fit (the whole solar system) to 2.5 times, and from 0.5 to 6 times while riding from a body. `controls="none"` turns the hands off; `zoom-min` and `zoom-max` change the range. A `<kazoku-view-controls for="...">` on the element takes the hands over, and the page applies its events with `setView`.
|
|
112
|
+
* It carries kazoku-ui's controls itself: a drag turns the view, two fingers pinch, Ctrl and the wheel zoom (a plain wheel at Fit scrolls the page) and the arrow keys, + and - work once it is focused. The zoom runs from a millionth of Fit (the whole solar system) to 2.5 times, and from 0.5 to 6 times while riding from a body. `controls="none"` turns the hands off; `zoom-min` and `zoom-max` change the range. A `<kazoku-view-controls for="...">` on the element takes the hands over, and the page applies its events with `setView`. `immersive` is the full-screen mode: any shape of box, a plain wheel zooms and a drag anywhere turns.
|
|
113
|
+
*
|
|
114
|
+
* With a body painter that carries a `credit` (`setBodyPainter`), the credit of its pictures is written under the picture while it draws the bodies; `bodies-credit="off"` takes the line away.
|
|
106
115
|
*
|
|
107
116
|
* While time runs (`speed` is not 0) it sends `chikyu-timechange` with `detail: { time, running: true }`, `time` being the moment shown in milliseconds since 1970, at most four times a second however fast the picture is
|
|
108
117
|
* drawn (and, with the clock at real time, as often as it steps: once a minute, or once a second with satellites or a ride on show), only while the tab is shown, and once with `running: false` when the clock holds
|
|
109
118
|
* (`speed` set to 0): a page writes the date into its date box from it. It is not sent for a `time` the page sets itself. `chikyu-time` is the older event of every step the clock takes (up to thirty a second):
|
|
110
119
|
* it is kept for pages that use it, but a page that shows the date wants `chikyu-timechange`.
|
|
111
120
|
*
|
|
121
|
+
* `borders` draws the borders on the Earth's land as thin lines that turn with it, as on `<chikyu-earth-realistic>`: `countries`, `regions` (from the page's `borderData.regions`, once the Earth is
|
|
122
|
+
* large enough), or both with a bare attribute; `chikyu-borders-unavailable` is sent when the shapes cannot be loaded.
|
|
123
|
+
*
|
|
124
|
+
* `grid` draws the meridians and parallels on the Earth, and `country-names` names its countries, as on `<chikyu-earth-realistic>`: the names keep clear of the bodies', the places' and the
|
|
125
|
+
* cities' names and stay on the Earth's disc; `chikyu-country-names-unavailable` is sent when the outlines cannot be loaded.
|
|
126
|
+
*
|
|
112
127
|
* @example
|
|
113
128
|
* ```ts no-run
|
|
114
129
|
* import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
@@ -124,7 +139,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
|
|
|
124
139
|
* ```
|
|
125
140
|
*/
|
|
126
141
|
export class ChikyuSpace extends HTMLElement {
|
|
127
|
-
static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look"];
|
|
142
|
+
static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "bodies-credit"];
|
|
128
143
|
#model = newSpaceModel();
|
|
129
144
|
#mode = "now";
|
|
130
145
|
#speed = 1;
|
|
@@ -139,10 +154,18 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
139
154
|
/** The names of cities on the Earth (`city-names`), and the look of the names. */
|
|
140
155
|
#cities;
|
|
141
156
|
#citiesStyle = {};
|
|
157
|
+
/** The names of the countries on the Earth (`country-names`), and the look of the names. */
|
|
158
|
+
#countries;
|
|
159
|
+
#countriesStyle = {};
|
|
142
160
|
#satNames = {};
|
|
161
|
+
/** A ringed satellite's name, by `group:index`, for `#satLabelLang`. The name does not depend on the moment, so a frame reads it and does not propagate the orbit again. */
|
|
162
|
+
#satLabelCache = new Map();
|
|
163
|
+
/** `en` or `ja` once that language has been read for the cached names; empty until the first read. */
|
|
164
|
+
#satLabelLang = "";
|
|
143
165
|
/** The ringed satellites of the last draw (`labelSatellites`), laid out with the places. */
|
|
144
166
|
#marks = [];
|
|
145
167
|
#airNote;
|
|
168
|
+
#bodiesNote;
|
|
146
169
|
#gate;
|
|
147
170
|
#taken;
|
|
148
171
|
#stage;
|
|
@@ -163,6 +186,8 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
163
186
|
#ridden = {};
|
|
164
187
|
#placeLayer;
|
|
165
188
|
#placeList = [];
|
|
189
|
+
/** Counts the turns to a place, so a new one stops the one before. */
|
|
190
|
+
#placeGlide = 0;
|
|
166
191
|
#nameBoxes = new Map();
|
|
167
192
|
/** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
|
|
168
193
|
get controller() {
|
|
@@ -188,12 +213,13 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
188
213
|
if (!this.hasAttribute("aria-label"))
|
|
189
214
|
this.setAttribute("aria-label", "The Earth, the Moon, the Sun and the planets in their places for the date shown");
|
|
190
215
|
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
191
|
-
root.innerHTML = `<div id="stage"></div><div id="places"></div><div id="labels" aria-hidden="true"></div><div id="notes"><p id="air-note" hidden></p><p id="meteor-note" hidden></p></div>`;
|
|
216
|
+
root.innerHTML = `<div id="stage"></div><div id="places"></div><div id="labels" aria-hidden="true"></div><div id="notes"><p id="air-note" hidden></p><p id="meteor-note" hidden></p><p id="bodies-note" hidden></p></div>`;
|
|
192
217
|
adoptStyles(root, STYLE, this.nonce);
|
|
193
218
|
this.#stage = root.getElementById("stage");
|
|
194
219
|
this.#labelBox = root.getElementById("labels");
|
|
195
220
|
this.#note = root.getElementById("meteor-note");
|
|
196
221
|
this.#airNote = root.getElementById("air-note");
|
|
222
|
+
this.#bodiesNote = root.getElementById("bodies-note");
|
|
197
223
|
this.#sky = createSkyHost({
|
|
198
224
|
root,
|
|
199
225
|
attribute: (name) => this.getAttribute(name),
|
|
@@ -207,16 +233,30 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
207
233
|
this.#placeList = readPlaces(this.getAttribute("places"));
|
|
208
234
|
this.#placeLayer.set(this.#placeList);
|
|
209
235
|
this.#placeLayer.look = readPlaceLook(this.getAttribute("places-look"));
|
|
236
|
+
this.#placeLayer.grouping = readPlaceGroups(this.getAttribute("place-groups"));
|
|
210
237
|
this.#cities = createCityHost({
|
|
211
238
|
root,
|
|
212
239
|
attribute: (name) => this.getAttribute(name),
|
|
213
240
|
language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
|
|
214
241
|
onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-city-names-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
242
|
+
onLayout: () => this.#countryFrame(),
|
|
215
243
|
});
|
|
216
244
|
this.#cities.setStyle(this.#citiesStyle);
|
|
245
|
+
Object.assign(this.#model.borders, readBorders(this.getAttribute("borders")));
|
|
246
|
+
this.#model.borders.onError = (error) => this.dispatchEvent(new CustomEvent("chikyu-borders-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } }));
|
|
247
|
+
this.#model.grid.on = readGrid(this.getAttribute("grid"));
|
|
248
|
+
this.#model.grid.onError = (error) => this.dispatchEvent(new CustomEvent("chikyu-grid-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } }));
|
|
249
|
+
this.#countries = createCountryHost({
|
|
250
|
+
root,
|
|
251
|
+
attribute: (name) => this.getAttribute(name),
|
|
252
|
+
language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
|
|
253
|
+
onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-country-names-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
254
|
+
});
|
|
255
|
+
this.#countries.setStyle(this.#countriesStyle);
|
|
217
256
|
this.#model.airThickness = readAirThickness(this.getAttribute("air-thickness"));
|
|
218
257
|
this.#applyBodyLabel();
|
|
219
258
|
setAirNote(this.#airNote, this, this.#model.airThickness);
|
|
259
|
+
this.#showBodiesCredit();
|
|
220
260
|
this.#played = false;
|
|
221
261
|
this.#model.meteors.on = this.#meteorsAsked();
|
|
222
262
|
this.#model.meteors.strength = readMeteorStrength(this.getAttribute("meteors-strength"));
|
|
@@ -246,12 +286,14 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
246
286
|
onLabels: (places) => this.#placeLabels(places),
|
|
247
287
|
onSky: (sky) => this.#sky?.frame(sky),
|
|
248
288
|
onPlaces: (view) => this.#drawPlaces(view),
|
|
249
|
-
|
|
289
|
+
placeSprites: () => this.#placeLayer?.sprites ?? null,
|
|
290
|
+
onCities: (frame) => this.#nameFrame(frame),
|
|
250
291
|
onLabelError: (error) => this.dispatchEvent(new CustomEvent("chikyu-body-label-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
251
292
|
onSatelliteMarks: (marks) => this.#showMarks(marks),
|
|
252
293
|
onSelected: (place) => this.#placeChosen(place),
|
|
253
294
|
onMoving: () => this.#gate?.request(),
|
|
254
295
|
onRideLost: () => this.#rideLost(),
|
|
296
|
+
onPlaceRings: (drawn) => this.#ringsDrawn(drawn),
|
|
255
297
|
onSatellitesError: (error) => this.dispatchEvent(new CustomEvent("chikyu-satellites-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
256
298
|
...(painter ? { painter } : {}),
|
|
257
299
|
satellitePainter: () => satellitePainter,
|
|
@@ -270,6 +312,8 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
270
312
|
this.#last = performance.now();
|
|
271
313
|
this.#schedule();
|
|
272
314
|
this.addEventListener("pointerdown", this.#down);
|
|
315
|
+
// before the shared hands (which hear it after this): a plain wheel in an immersive view zooms
|
|
316
|
+
this.addEventListener("wheel", this.#wheel, { capture: true, passive: false });
|
|
273
317
|
this.#hands = carryControls(this, { initial: this.#model.view, limits: LIMITS, onChange: (state, info) => this.setView(state, info.final) });
|
|
274
318
|
this.#labelBox.addEventListener("click", this.#labelClick);
|
|
275
319
|
this.#labelBox.addEventListener("focusin", this.#labelFocus);
|
|
@@ -279,6 +323,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
279
323
|
this.#hands = undefined;
|
|
280
324
|
this.#zoomRange(false);
|
|
281
325
|
this.removeEventListener("pointerdown", this.#down);
|
|
326
|
+
this.removeEventListener("wheel", this.#wheel, { capture: true });
|
|
282
327
|
window.removeEventListener("pointerup", this.#up, true);
|
|
283
328
|
clearTimeout(this.#timer);
|
|
284
329
|
this.#timer = undefined;
|
|
@@ -292,6 +337,8 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
292
337
|
this.#placeLayer?.dispose();
|
|
293
338
|
this.#placeLayer = undefined;
|
|
294
339
|
this.#cities?.dispose();
|
|
340
|
+
this.#countries?.dispose();
|
|
341
|
+
this.#countries = undefined;
|
|
295
342
|
this.#cities = undefined;
|
|
296
343
|
}
|
|
297
344
|
attributeChangedCallback(name, _old, value) {
|
|
@@ -339,6 +386,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
339
386
|
this.#applyBodyLabel();
|
|
340
387
|
this.#sky?.refresh();
|
|
341
388
|
this.#cities?.refresh();
|
|
389
|
+
this.#countries?.refresh();
|
|
342
390
|
}
|
|
343
391
|
}
|
|
344
392
|
else if (BODY_LABEL_ATTRIBUTES.includes(name))
|
|
@@ -354,10 +402,48 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
354
402
|
this.#placeLayer.look = readPlaceLook(value);
|
|
355
403
|
this.#gate?.request();
|
|
356
404
|
}
|
|
405
|
+
else if (name === "place-groups" && this.#placeLayer) {
|
|
406
|
+
this.#placeLayer.grouping = readPlaceGroups(value);
|
|
407
|
+
this.#gate?.request();
|
|
408
|
+
}
|
|
357
409
|
else if (CITY_NAMES_ATTRIBUTES.includes(name))
|
|
358
410
|
this.#cities?.refresh();
|
|
411
|
+
else if (name === "borders") {
|
|
412
|
+
Object.assign(this.#model.borders, readBorders(value));
|
|
413
|
+
this.#gate?.request();
|
|
414
|
+
}
|
|
415
|
+
else if (name === "grid") {
|
|
416
|
+
this.#model.grid.on = readGrid(value);
|
|
417
|
+
this.#gate?.request();
|
|
418
|
+
}
|
|
419
|
+
else if (COUNTRY_NAMES_ATTRIBUTES.includes(name))
|
|
420
|
+
this.#countries?.refresh();
|
|
359
421
|
if (name === "air-thickness" || name === "air-label" || name === "lang")
|
|
360
422
|
setAirNote(this.#airNote, this, this.#model.airThickness);
|
|
423
|
+
if (name === "bodies-credit" || name === "lang")
|
|
424
|
+
this.#showBodiesCredit();
|
|
425
|
+
}
|
|
426
|
+
#wheel = (event) => immersiveWheel(this, event);
|
|
427
|
+
/** The body painter's credit under the picture, in the element's or the page's language: shown while the painter draws the bodies (not `plain`), unless `bodies-credit` is `off`. */
|
|
428
|
+
#showBodiesCredit() {
|
|
429
|
+
const note = this.#bodiesNote;
|
|
430
|
+
if (!note)
|
|
431
|
+
return;
|
|
432
|
+
const lang = (this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en";
|
|
433
|
+
const credit = painter?.credit?.[lang] ?? "";
|
|
434
|
+
note.textContent = credit;
|
|
435
|
+
note.lang = lang;
|
|
436
|
+
note.hidden = credit === "" || this.bodies === "plain" || this.getAttribute("bodies-credit") === "off";
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* True for the full-screen mode (the `immersive` attribute): the element fills its box in any shape (the Earth fits the shorter side with its glow inside it, `earth-size`), a plain wheel zooms instead of scrolling
|
|
440
|
+
* the page, a drag anywhere on it turns the view, and a touch drag turns it instead of scrolling. A notch of the wheel is about 1.2 times; out far enough the Moon, the Sun and the planets come into view.
|
|
441
|
+
*/
|
|
442
|
+
get immersive() {
|
|
443
|
+
return this.hasAttribute("immersive");
|
|
444
|
+
}
|
|
445
|
+
set immersive(value) {
|
|
446
|
+
this.toggleAttribute("immersive", value);
|
|
361
447
|
}
|
|
362
448
|
#meteorsAsked() {
|
|
363
449
|
return this.hasAttribute("meteors") && this.getAttribute("meteors") !== "off";
|
|
@@ -459,10 +545,12 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
459
545
|
this.#sky?.setKeepClear(this.#keepClear);
|
|
460
546
|
}
|
|
461
547
|
/**
|
|
462
|
-
* Places marked on the Earth (the attribute `places`, a JSON array): each `{ id, lon, lat, label, kind }`, `kind` being `here` (where the reader is: drawn bright and taller, with a quiet pulse) or `favourite`
|
|
463
|
-
* (the default: quieter)
|
|
464
|
-
*
|
|
465
|
-
*
|
|
548
|
+
* Places marked on the Earth (the attribute `places`, a JSON array): each `{ id, lon, lat, label, kind, color }`, `kind` being `here` (where the reader is: drawn bright and taller, with a quiet pulse) or `favourite`
|
|
549
|
+
* (the default: quieter), and `color` an optional CSS colour of its own. The first `PLACE_MARKS` in sight (`here` first, then in the order given) stand up out of the ground with their names; every other place
|
|
550
|
+
* is a ring on the ground, all of them one draw call, and places that crowd are gathered into one ring with their count. They turn with the Earth, are hidden on its far side, are dimmer on its night side
|
|
551
|
+
* and keep their size in pixels at any zoom. Names never overlap one another or the bodies' names; one with no room is left out. The element stores nothing and sends nothing: the page hands the places
|
|
552
|
+
* over and keeps them where it likes. Setting the property writes the attribute; at most `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight
|
|
553
|
+
* and for a reader who asked for less motion.
|
|
466
554
|
*/
|
|
467
555
|
get places() {
|
|
468
556
|
return this.#placeList.map((place) => ({ ...place }));
|
|
@@ -474,6 +562,54 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
474
562
|
else
|
|
475
563
|
this.setAttribute("places", JSON.stringify(clean));
|
|
476
564
|
}
|
|
565
|
+
/**
|
|
566
|
+
* Turn the view so a place of `places` is in the middle, at a pace a reader can follow (at once with `smooth: false`, for a reader who asked for less motion, or before the picture is live); the zoom stays.
|
|
567
|
+
* The place is named by its `id`, or by its label in any case. The camera must be looking at the Earth: while it rides along or looks at another body nothing moves. The tilt is held to 90 degrees either
|
|
568
|
+
* way, so a place more than 90 degrees of latitude from `center` comes as near the middle as that allows.
|
|
569
|
+
*
|
|
570
|
+
* @param text - The place's id or label.
|
|
571
|
+
* @param options - `smooth` (true by default).
|
|
572
|
+
* @returns The place, once the turn has started; `undefined` when there is no such place or the camera is not looking at the Earth.
|
|
573
|
+
*/
|
|
574
|
+
async goToPlace(text, options = {}) {
|
|
575
|
+
const place = findPlace(this.#placeList, text);
|
|
576
|
+
const base = this.#model.lookBase;
|
|
577
|
+
if (!place || !base || this.#model.ride)
|
|
578
|
+
return undefined;
|
|
579
|
+
const controls = this.#controls();
|
|
580
|
+
const from = { yaw: this.#model.view.yaw, tilt: this.#model.view.tilt };
|
|
581
|
+
const to = aimAt(base, place, from);
|
|
582
|
+
const glide = (this.#placeGlide += 1);
|
|
583
|
+
const set = (yaw, tilt, final) => {
|
|
584
|
+
if (controls)
|
|
585
|
+
controls.set({ yaw, tilt, zoom: this.#model.view.zoom }, final, "place");
|
|
586
|
+
else
|
|
587
|
+
this.setView({ yaw, tilt, zoom: this.#model.view.zoom }, final);
|
|
588
|
+
};
|
|
589
|
+
glideView(set, from, to, options.smooth !== false && !prefersLessMotion() && this.#view?.live === true, () => glide === this.#placeGlide && this.isConnected);
|
|
590
|
+
return { ...place };
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Whether places that crowd are gathered into one ring with their count (the attribute `place-groups`): on by default, `off` leaves every place its own ring. Setting the property writes the attribute.
|
|
594
|
+
*/
|
|
595
|
+
get placeGroups() {
|
|
596
|
+
return this.#placeLayer?.grouping ?? readPlaceGroups(this.getAttribute("place-groups"));
|
|
597
|
+
}
|
|
598
|
+
set placeGroups(value) {
|
|
599
|
+
if (value)
|
|
600
|
+
this.removeAttribute("place-groups");
|
|
601
|
+
else
|
|
602
|
+
this.setAttribute("place-groups", "off");
|
|
603
|
+
}
|
|
604
|
+
/** The picture said whether it can draw the rings of the places that are not markers of their own. Without `Points` the places' layer draws them itself and the page is told once, so no place is lost without a word. */
|
|
605
|
+
#ringsDrawn(drawn) {
|
|
606
|
+
if (!this.#placeLayer || this.#placeLayer.ringsInPicture === drawn)
|
|
607
|
+
return;
|
|
608
|
+
this.#placeLayer.ringsInPicture = drawn;
|
|
609
|
+
if (!drawn)
|
|
610
|
+
this.dispatchEvent(new CustomEvent("chikyu-places-unavailable", { detail: { reason: "the three.js parts handed over lack Points: the places' rings are drawn as small circles in the page, at most 600, and stats.places.omitted counts the rest" } }));
|
|
611
|
+
this.#gate?.request();
|
|
612
|
+
}
|
|
477
613
|
/** How the places are drawn (the attribute `places-look`): `beam` (a light rising out of the ground with a ring at its foot, the default), `pin` (a thin stick with a round head) or `ring` (only the ring on the ground). */
|
|
478
614
|
get placesLook() {
|
|
479
615
|
return this.#placeLayer?.look ?? readPlaceLook(this.getAttribute("places-look"));
|
|
@@ -486,6 +622,26 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
486
622
|
const layer = this.#placeLayer;
|
|
487
623
|
if (!layer || (this.#placeList.length === 0 && this.#marks.length === 0 && layer.stats.shown === 0 && layer.stats.rings === 0))
|
|
488
624
|
return;
|
|
625
|
+
layer.frame(view, this.#bodyNameBoxes(), this.#marks, this.#model.light === "lit" ? null : subsolarPoint(this.#model.time));
|
|
626
|
+
}
|
|
627
|
+
/** Tells the names of cities, then of countries, where the Earth is in the picture just drawn; the countries' names keep clear of the bodies', the places' and the cities'. */
|
|
628
|
+
#nameFrame(frame) {
|
|
629
|
+
this.#cities?.frame(frame);
|
|
630
|
+
this.#lastNameFrame = frame;
|
|
631
|
+
this.#countryFrame();
|
|
632
|
+
}
|
|
633
|
+
/** The frame the names were last laid out on. */
|
|
634
|
+
#lastNameFrame = null;
|
|
635
|
+
/** Lays the countries' names out on the last frame, clear of the bodies', the places' and the cities' names as they are now. */
|
|
636
|
+
#countryFrame() {
|
|
637
|
+
const countries = this.#countries;
|
|
638
|
+
if (!countries)
|
|
639
|
+
return;
|
|
640
|
+
const frame = this.#lastNameFrame;
|
|
641
|
+
countries.frame(frame, countries.stats.on && frame ? [...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? [])] : []);
|
|
642
|
+
}
|
|
643
|
+
/** The boxes the bodies' names take beside them in the picture just drawn. */
|
|
644
|
+
#bodyNameBoxes() {
|
|
489
645
|
const taken = [];
|
|
490
646
|
if (this.#model.labels && this.#places) {
|
|
491
647
|
for (const name of BODY_NAMES) {
|
|
@@ -504,7 +660,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
504
660
|
taken.push({ left: at.x + Math.max(4, Math.min(at.r, 40)), top: at.y - 8, ...box });
|
|
505
661
|
}
|
|
506
662
|
}
|
|
507
|
-
|
|
663
|
+
return taken;
|
|
508
664
|
}
|
|
509
665
|
/**
|
|
510
666
|
* The look of the names of cities (`city-names`): font, size, weight, colour, the outline round the text, and the dot's colour and size. Any of them may be left out; the Earth's size, the language and the data are not set here.
|
|
@@ -516,6 +672,52 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
516
672
|
this.#citiesStyle = { ...value };
|
|
517
673
|
this.#cities?.setStyle(this.#citiesStyle);
|
|
518
674
|
}
|
|
675
|
+
/** Whether the meridians and parallels are drawn on the Earth (the attribute `grid`). Setting it writes the attribute, or takes it away. */
|
|
676
|
+
get grid() {
|
|
677
|
+
return readGrid(this.getAttribute("grid"));
|
|
678
|
+
}
|
|
679
|
+
set grid(value) {
|
|
680
|
+
if (value)
|
|
681
|
+
this.setAttribute("grid", "");
|
|
682
|
+
else
|
|
683
|
+
this.removeAttribute("grid");
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* The look of the names of countries (`country-names`): font, weight, colour, the outline round the text, and the smallest and largest text size. Any of them may be left out; the Earth's size, the
|
|
687
|
+
* language and the data are not set here.
|
|
688
|
+
*/
|
|
689
|
+
get countryNamesStyle() {
|
|
690
|
+
return { ...this.#countriesStyle };
|
|
691
|
+
}
|
|
692
|
+
set countryNamesStyle(value) {
|
|
693
|
+
this.#countriesStyle = { ...value };
|
|
694
|
+
this.#countries?.setStyle(this.#countriesStyle);
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Which borders are drawn on the Earth (the attribute `borders`): the countries' at any size, and the regions' (provinces, states, prefectures) once the Earth is large enough on the screen to tell them apart.
|
|
698
|
+
* Setting it writes the attribute: both sets as `borders="countries regions"`, one as its own word, none takes the attribute away.
|
|
699
|
+
*/
|
|
700
|
+
get borders() {
|
|
701
|
+
return readBorders(this.getAttribute("borders"));
|
|
702
|
+
}
|
|
703
|
+
set borders(value) {
|
|
704
|
+
const words = [value.countries ? "countries" : "", value.regions ? "regions" : ""].filter(Boolean);
|
|
705
|
+
if (words.length === 0)
|
|
706
|
+
this.removeAttribute("borders");
|
|
707
|
+
else
|
|
708
|
+
this.setAttribute("borders", words.join(" "));
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Where the borders' shapes come from (see `BorderData`): `countries` in place of chizu's `world-geo`, and `regions`, a country's regions by its code, which draws the regions; without it none are drawn.
|
|
712
|
+
* Set it before `borders` is switched on: shapes already loaded are kept.
|
|
713
|
+
*/
|
|
714
|
+
get borderData() {
|
|
715
|
+
return { ...this.#model.borders.data };
|
|
716
|
+
}
|
|
717
|
+
set borderData(value) {
|
|
718
|
+
this.#model.borders.data = { ...value };
|
|
719
|
+
this.#gate?.request();
|
|
720
|
+
}
|
|
519
721
|
/** Puts the name's settings and text right from the attributes (`body-label` and its family, `lang`). */
|
|
520
722
|
#applyBodyLabel() {
|
|
521
723
|
this.#model.bodyLabel.settings = readBodyLabel((name) => this.getAttribute(name));
|
|
@@ -635,6 +837,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
635
837
|
}
|
|
636
838
|
set bodies(value) {
|
|
637
839
|
this.#model.bodies = value;
|
|
840
|
+
this.#showBodiesCredit();
|
|
638
841
|
this.#gate?.request();
|
|
639
842
|
}
|
|
640
843
|
/** How the Earth is lit: `sun` (true, the default), `lit` (always lit, as if by daylight from the camera's side, so a ride on the night side is never a black frame) or `boost` (the true terminator, with the night side raised). The Sun, the Moon and the planets keep their true places. */
|
|
@@ -781,6 +984,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
781
984
|
const out = [];
|
|
782
985
|
if (!satellitePainter)
|
|
783
986
|
return out;
|
|
987
|
+
this.#prepareSatLabelLang();
|
|
784
988
|
for (const [group, state] of this.#model.satellites.groups) {
|
|
785
989
|
state.satellites.sets.forEach((set, index) => {
|
|
786
990
|
if (satellitePainter.has(set.NORAD_CAT_ID))
|
|
@@ -843,6 +1047,8 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
843
1047
|
visible: was?.visible ?? true,
|
|
844
1048
|
});
|
|
845
1049
|
}
|
|
1050
|
+
// a group's index may now be a different satellite, so a cached name for that ref is no longer its name
|
|
1051
|
+
this.#satLabelCache.clear();
|
|
846
1052
|
this.#last = performance.now();
|
|
847
1053
|
this.#schedule();
|
|
848
1054
|
this.#gate?.request();
|
|
@@ -900,6 +1106,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
900
1106
|
}
|
|
901
1107
|
set satelliteNames(value) {
|
|
902
1108
|
this.#satNames = { ...value };
|
|
1109
|
+
this.#satLabelCache.clear();
|
|
903
1110
|
this.#gate?.request();
|
|
904
1111
|
}
|
|
905
1112
|
/**
|
|
@@ -909,17 +1116,37 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
909
1116
|
placeSatellite(ref) {
|
|
910
1117
|
return this.#model.placeSatellite?.(ref) ?? null;
|
|
911
1118
|
}
|
|
912
|
-
/** The
|
|
1119
|
+
/** The page's language for a satellite name: Japanese when the nearest `lang` starts with `ja`, otherwise English. Read once per pass, not once per satellite. */
|
|
1120
|
+
#readSatLabelLang() {
|
|
1121
|
+
return (this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en";
|
|
1122
|
+
}
|
|
1123
|
+
/** Remember the page's language and drop cached names when it changes. One `closest("[lang]")` for the pass. */
|
|
1124
|
+
#prepareSatLabelLang() {
|
|
1125
|
+
const lang = this.#readSatLabelLang();
|
|
1126
|
+
if (lang !== this.#satLabelLang) {
|
|
1127
|
+
this.#satLabelCache.clear();
|
|
1128
|
+
this.#satLabelLang = lang;
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
/** The name beside a ringed satellite: the page's own (`satelliteNames`), else the short one in the page's language, else the name in its elements. Cached per ref and language: the name is constant, and reading it does not propagate the orbit again. */
|
|
913
1132
|
#satelliteName(ref) {
|
|
1133
|
+
const key = `${ref.group}:${ref.index}`;
|
|
1134
|
+
const cached = this.#satLabelCache.get(key);
|
|
1135
|
+
if (cached !== undefined)
|
|
1136
|
+
return cached;
|
|
914
1137
|
const info = this.satelliteInfo(ref);
|
|
915
1138
|
if (!info)
|
|
916
1139
|
return "";
|
|
917
|
-
const lang =
|
|
918
|
-
|
|
1140
|
+
const lang = this.#satLabelLang === "ja" ? "ja" : "en";
|
|
1141
|
+
const name = this.#satNames[info.noradId] ?? SHORT_NAMES[info.noradId]?.[lang] ?? info.name;
|
|
1142
|
+
this.#satLabelCache.set(key, name);
|
|
1143
|
+
return name;
|
|
919
1144
|
}
|
|
920
1145
|
#markSeen = new Map();
|
|
921
1146
|
/** Hands the places layer the ringed satellites of this draw, and tells the page when one comes into view or goes out of it. */
|
|
922
1147
|
#showMarks(marks) {
|
|
1148
|
+
if (marks.length > 0)
|
|
1149
|
+
this.#prepareSatLabelLang();
|
|
923
1150
|
this.#marks = marks.map((m) => ({ id: `${m.ref.group}:${m.ref.index}`, label: this.#satelliteName(m.ref), x: m.x, y: m.y, visible: m.visible }));
|
|
924
1151
|
const now = new Map();
|
|
925
1152
|
for (const m of marks) {
|
|
@@ -1002,13 +1229,16 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1002
1229
|
satellites: this.#satelliteStats(),
|
|
1003
1230
|
ride: { riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null },
|
|
1004
1231
|
camera: { position: [this.#model.pose.p[0], this.#model.pose.p[1], this.#model.pose.p[2]], quaternion: [this.#model.pose.q[0], this.#model.pose.q[1], this.#model.pose.q[2], this.#model.pose.q[3]], fov: this.#model.pose.fov },
|
|
1005
|
-
bodies: { look: this.#model.bodies || painter?.looks?.[0] || "plain", painted: this.#model.painted.bodies, moons: this.#model.painted.moons },
|
|
1232
|
+
bodies: { look: this.#model.bodies || painter?.looks?.[0] || "plain", painted: this.#model.painted.bodies, moons: this.#model.painted.moons, held: this.#model.painted.held, moon: this.#model.painted.moon, tiles: this.#model.painted.tiles },
|
|
1006
1233
|
meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
|
|
1007
1234
|
bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
|
|
1008
1235
|
sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, pick: null, hover: null, constellations: 0, culture: "iau", renders: 0, lang: "", stars: [] },
|
|
1009
1236
|
followModel: this.#model.followModel,
|
|
1010
|
-
places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0 }) },
|
|
1237
|
+
places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, omitted: 0 }) },
|
|
1011
1238
|
cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
|
|
1239
|
+
borders: { ...this.#model.borders.stats, shown: { ...this.#model.borders.stats.shown }, loaded: [...this.#model.borders.stats.loaded] },
|
|
1240
|
+
grid: { ...this.#model.grid.stats },
|
|
1241
|
+
countryNames: this.#countries?.stats ?? { on: false, max: 0, countries: 0, names: 0, renders: 0, failed: false },
|
|
1012
1242
|
};
|
|
1013
1243
|
}
|
|
1014
1244
|
#satelliteStats() {
|
package/dist/space/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitPath, PLANETS, type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
|
|
2
2
|
export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
|
|
3
|
-
export { fitDistance, plainPainter, type BodyDrawing, type BodyMoon, type BodyPainter, type PaintContext, type SatellitePainter } from "./scene.ts";
|
|
3
|
+
export { fitDistance, plainPainter, type BodyDrawing, type BodyMoon, type BodyPainter, type BodyView, type PaintContext, type SatellitePainter } from "./scene.ts";
|
|
4
4
|
export { RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideInput, type RideLook, type RidePose } from "./ride.ts";
|
|
5
5
|
export type { SatelliteScreen } from "./satellite-layer.ts";
|
|
6
6
|
export { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -9,10 +9,14 @@ import type { SatelliteRef } from "../satellites/types.ts";
|
|
|
9
9
|
import { type RideLook } from "./ride.ts";
|
|
10
10
|
import type { SkyFrame } from "../sky/frame.ts";
|
|
11
11
|
import type { PlaceView } from "../markers/places.ts";
|
|
12
|
-
import type
|
|
12
|
+
import { type PlaceSpriteData } from "../markers/place-sprites.ts";
|
|
13
|
+
import type { CountryFrame } from "../country-names/geometry.ts";
|
|
14
|
+
import type { GeoPoint } from "../types.ts";
|
|
13
15
|
import { type SatelliteScreen, type SatelliteState } from "./satellite-layer.ts";
|
|
14
16
|
import { type BodyLabelState } from "../realistic/body-label.ts";
|
|
15
17
|
import { type MeteorState } from "../meteors/layer.ts";
|
|
18
|
+
import { type BorderState } from "../borders/layer.ts";
|
|
19
|
+
import { type GridState } from "../grid/layer.ts";
|
|
16
20
|
type Three = ThreeParts;
|
|
17
21
|
/** How much of the view's shorter side the Earth's disc fills at zoom 1 when the page does not say: 0.9, so the atmosphere's glow (8% beyond the disc) is inside the view and never cut. */
|
|
18
22
|
export declare const DEFAULT_EARTH_SIZE = 0.9;
|
|
@@ -145,10 +149,13 @@ export interface SpaceModel {
|
|
|
145
149
|
distance: number;
|
|
146
150
|
radiusPx: number;
|
|
147
151
|
} | null;
|
|
148
|
-
/** What the painter has made now: the Sun and planets with a drawing, and the moons shown (set at each draw). */
|
|
152
|
+
/** What the painter has made now: the Sun and planets with a drawing, the moons shown and the moons held (shown, or gone from the view for less than `MOON_KEEP_MS`), whether the Moon is the painter's, and the bodies with finer map tiles on them (set at each draw). */
|
|
149
153
|
painted: {
|
|
150
154
|
bodies: number;
|
|
151
155
|
moons: number;
|
|
156
|
+
held: number;
|
|
157
|
+
moon: boolean;
|
|
158
|
+
tiles: number;
|
|
152
159
|
};
|
|
153
160
|
/** How many times astronomy-engine has been asked for a frame. */
|
|
154
161
|
lookups: number;
|
|
@@ -160,6 +167,10 @@ export interface SpaceModel {
|
|
|
160
167
|
meteors: MeteorState;
|
|
161
168
|
/** The name written on the Earth (src/realistic/body-label.ts): off unless the element sets it. */
|
|
162
169
|
bodyLabel: BodyLabelState;
|
|
170
|
+
/** The borders of the countries and of their regions, on the Earth (src/borders/layer.ts): off unless the element switches them on. */
|
|
171
|
+
borders: BorderState;
|
|
172
|
+
/** The meridians and parallels on the Earth (src/grid/layer.ts): off unless the element switches them on. */
|
|
173
|
+
grid: GridState;
|
|
163
174
|
/** The body or satellite the camera rides along with, or null. */
|
|
164
175
|
ride: RideState | null;
|
|
165
176
|
/** Set at each draw: the target of the ride could not be placed (a satellite whose elements are too old, or that is gone), so the ordinary camera was used. */
|
|
@@ -180,6 +191,8 @@ export interface SpaceModel {
|
|
|
180
191
|
tilt: number;
|
|
181
192
|
zoom: number;
|
|
182
193
|
} | null;
|
|
194
|
+
/** The point of the ground the view would look at with yaw and tilt 0, as of the last draw (the middle of the view is this less the yaw and tilt), or null while the camera rides or looks at another body. */
|
|
195
|
+
lookBase: GeoPoint | null;
|
|
183
196
|
heightPx: number;
|
|
184
197
|
pose: Pose;
|
|
185
198
|
/** Pixels a second that riding makes things move on the screen at 1x clock speed (0 when not riding): the draw rate follows it. */
|
|
@@ -223,16 +236,40 @@ export interface BodyDrawing {
|
|
|
223
236
|
object: THREE.Object3D;
|
|
224
237
|
/** Told at each draw the unit direction from the body to the Sun, in scene axes (x to the vernal equinox, y north). */
|
|
225
238
|
light?(toSun: Vec3): void;
|
|
226
|
-
/**
|
|
239
|
+
/**
|
|
240
|
+
* Told at each draw, after the object is placed and scaled: the direction to the Sun, the moment shown, how many CSS pixels across its radius the body is (a sharper picture is worth fetching only for a big one), and the
|
|
241
|
+
* camera with the size of the view in CSS pixels (`view`), so a body big in the view can lay finer map tiles over the part of it that is seen, and a glow can face the camera.
|
|
242
|
+
*/
|
|
227
243
|
update?(info: {
|
|
228
244
|
toSun: Vec3;
|
|
229
245
|
ms: number;
|
|
230
246
|
radiusPx: number;
|
|
247
|
+
view?: BodyView;
|
|
231
248
|
}): void;
|
|
249
|
+
/** What the window of finer map tiles on the body is doing (`shown` is the level on it now, or `null`), for a drawing that has one. */
|
|
250
|
+
readonly tiles?: {
|
|
251
|
+
shown: number | null;
|
|
252
|
+
} | undefined;
|
|
232
253
|
/** True to have the scene turn the object to face the camera (a disc or a glow). */
|
|
233
254
|
billboard?: boolean;
|
|
234
255
|
dispose(): void;
|
|
235
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* The camera that draws the bodies and the size of its view in CSS pixels, as the space view tells a drawing at each draw. The camera's matrices are current.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```ts no-run
|
|
262
|
+
* import type { BodyView } from "@johnmorrisdotca/chikyu-earth/space";
|
|
263
|
+
*
|
|
264
|
+
* const across = (view: BodyView): number => view.width;
|
|
265
|
+
* console.log(typeof across);
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
export interface BodyView {
|
|
269
|
+
camera: THREE.Camera;
|
|
270
|
+
width: number;
|
|
271
|
+
height: number;
|
|
272
|
+
}
|
|
236
273
|
/**
|
|
237
274
|
* The seam for drawing a followed satellite as a 3D model: the package ships no model, the page supplies them. `has` says whether there is a model for a satellite (by NORAD number: `25544` is the ISS); `make` makes it as a drawing of radius 1
|
|
238
275
|
* (its middle at the origin, its long axis along +x, its top, the side that faces space, along +z, and its left along +y), at once or later (a promise); the view places it where the satellite is, points it the way it flies, sizes it to read and
|
|
@@ -270,6 +307,8 @@ export interface PaintContext {
|
|
|
270
307
|
ratio: number;
|
|
271
308
|
/** The widest picture, in pixels, the GPU should be given. */
|
|
272
309
|
maxTexture: number;
|
|
310
|
+
/** True to draw every body that has a surface picture from it, in any look but `plain`: the space view asks for this, so a planet or the Moon is never shown shaded where it has a real map. */
|
|
311
|
+
mapped?: boolean;
|
|
273
312
|
}
|
|
274
313
|
/**
|
|
275
314
|
* One moon of a planet at a moment: its name, where it is from the planet's centre and how big it is, both in radii of the planet, in scene axes.
|
|
@@ -306,6 +345,11 @@ export interface BodyPainter {
|
|
|
306
345
|
make(three: ThreeParts, name: string, context?: PaintContext): BodyDrawing | Promise<BodyDrawing>;
|
|
307
346
|
moons?(planet: PlanetName, ms: number): readonly BodyMoon[];
|
|
308
347
|
looks?: readonly string[];
|
|
348
|
+
/** Whose pictures the painter draws, in English and Japanese: the space view writes it under the picture while the painter draws the bodies. */
|
|
349
|
+
credit?: {
|
|
350
|
+
en: string;
|
|
351
|
+
ja: string;
|
|
352
|
+
};
|
|
309
353
|
}
|
|
310
354
|
export interface SpaceDeps {
|
|
311
355
|
assets: AssetCache;
|
|
@@ -322,8 +366,12 @@ export interface SpaceDeps {
|
|
|
322
366
|
onSky?: (frame: SkyFrame) => void;
|
|
323
367
|
/** Where points of the Earth's surface fall on the screen at this draw, for the places drawn on it. Called at each draw. */
|
|
324
368
|
onPlaces?: (view: PlaceView) => void;
|
|
325
|
-
/**
|
|
326
|
-
|
|
369
|
+
/** The rings the places' layer wants drawn in one draw call, read right after `onPlaces`. */
|
|
370
|
+
placeSprites?: () => PlaceSpriteData | null;
|
|
371
|
+
/** Told once, when the rings of the places that are not markers of their own were first wanted: whether the picture can draw them (false when the three.js parts handed over lack `Points`). */
|
|
372
|
+
onPlaceRings?: (drawn: boolean) => void;
|
|
373
|
+
/** Where the Earth is on the screen (its disc) and how to find a place on it, for the names of cities and countries. Called at each draw, with `null` while no Earth is shown. */
|
|
374
|
+
onCities?: (frame: CountryFrame | null) => void;
|
|
327
375
|
/** The name written on the Earth could not be made. */
|
|
328
376
|
onLabelError?: (error: unknown) => void;
|
|
329
377
|
/** Where the chosen satellite is on the screen, or null. Called at each draw while a satellite is chosen (and once when it is let go). */
|