@johnmorrisdotca/chikyu-earth 0.51.1 → 0.53.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 +16 -0
- package/README.md +4 -2
- package/dist/flat/colours.d.ts +33 -0
- package/dist/flat/colours.js +49 -0
- package/dist/flat/define.d.ts +3 -0
- package/dist/flat/define.js +6 -0
- package/dist/flat/element.d.ts +171 -0
- package/dist/flat/element.js +1452 -0
- package/dist/flat/facts.d.ts +172 -0
- package/dist/flat/facts.js +168 -0
- package/dist/flat/geometry.d.ts +160 -0
- package/dist/flat/geometry.js +156 -0
- package/dist/flat/index.d.ts +5 -0
- package/dist/flat/index.js +6 -0
- package/dist/flat/words.d.ts +25 -0
- package/dist/flat/words.js +68 -0
- package/dist/space/element-base.d.ts +21 -1
- package/dist/space/element-base.js +41 -2
- package/dist/space/index.d.ts +1 -1
- package/dist/space/ride.d.ts +21 -3
- package/dist/space/ride.js +12 -6
- package/dist/space/scene.d.ts +3 -1
- package/dist/space/scene.js +3 -1
- package/package.json +13 -1
|
@@ -0,0 +1,1452 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
// <chikyu-flat>: satellites on a flat map of the world. A canvas for the map (land, day and night) and a canvas for the dots, the places worked out in the browser by SGP4 (satellite.js, an optional peer) from the elements the page hands over.
|
|
3
|
+
// Nothing runs on a timer when the clock is held, and nothing is drawn at rest, out of sight or in a hidden tab. This file registers nothing: `@johnmorrisdotca/chikyu-earth/flat/define` does.
|
|
4
|
+
import { geoCircle, geoEquirectangular, geoGraticule10, geoPath } from "d3-geo";
|
|
5
|
+
import { adoptStyles } from "../adopt.js";
|
|
6
|
+
import { footprintAngle, BEAM_ELEVATION } from "../beam/geometry.js";
|
|
7
|
+
import { orbitShape } from "../catalogue/orbit.js";
|
|
8
|
+
import { COUNTRIES } from "../countries.js";
|
|
9
|
+
import { groundTrack } from "../passes/passes.js";
|
|
10
|
+
import { subsolarPoint, greenwichSidereal } from "../realistic/sun.js";
|
|
11
|
+
import { SATELLITE_GROUPS } from "../satellites/catalogue.js";
|
|
12
|
+
import { SHORT_NAMES } from "../satellites/names.js";
|
|
13
|
+
import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
|
|
14
|
+
import { fetchElements } from "../satellites/source.js";
|
|
15
|
+
import { createSatellites } from "../satellites/track.js";
|
|
16
|
+
import { GROUP_COLOURS, PLANE_COLOURS, SPARE_COLOUR } from "./colours.js";
|
|
17
|
+
import { clusterPlanes, groupFacts } from "./facts.js";
|
|
18
|
+
import { FLATTENED, MAX_ZOOM, clampView, pixelsPerDegree, projectFlat, wrapLongitude, zoomAbout } from "./geometry.js";
|
|
19
|
+
import { say } from "./words.js";
|
|
20
|
+
const RAD = Math.PI / 180;
|
|
21
|
+
/** The most satellites whose footprints are drawn at once when none is chosen. */
|
|
22
|
+
const FOOTPRINT_MAX = 80;
|
|
23
|
+
const TIME_EVENT_MS = 250;
|
|
24
|
+
/** How long, in real seconds, a fast clock's streak covers, and the longest it is drawn, in pixels. */
|
|
25
|
+
const STREAK_SECONDS = 0.25;
|
|
26
|
+
const STREAK_PX = 28;
|
|
27
|
+
/** ...and for a crowd (thousands of dots), where long streaks would be a tangle. */
|
|
28
|
+
const STREAK_PX_CROWD = 10;
|
|
29
|
+
/** The furthest a pointer may move between going down and coming up and still be a tap, pixels. */
|
|
30
|
+
const TAP_SLOP = 5;
|
|
31
|
+
const sameRef = (a, b) => a === b || (a !== null && b !== null && a.g === b.g && a.i === b.i);
|
|
32
|
+
const escape = (text) => text.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
|
33
|
+
const flag = (value) => value !== null && !/^(off|false|no|0)$/i.test(value.trim());
|
|
34
|
+
const finite = (value, fallback) => (value === null || value.trim() === "" || !Number.isFinite(Number(value)) ? fallback : Number(value));
|
|
35
|
+
const readTime = (value) => {
|
|
36
|
+
if (value === null || value.trim() === "" || value.trim().toLowerCase() === "now")
|
|
37
|
+
return "now";
|
|
38
|
+
const text = value.trim();
|
|
39
|
+
const ms = Date.parse(/[zZ]|[+-]\d\d:?\d\d$/.test(text) || !/T/.test(text) ? text : `${text}Z`);
|
|
40
|
+
return Number.isFinite(ms) ? ms : "now";
|
|
41
|
+
};
|
|
42
|
+
const prefersLessMotion = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
43
|
+
const hidden = () => typeof document !== "undefined" && document.visibilityState === "hidden";
|
|
44
|
+
const CSS = `
|
|
45
|
+
:host{display:flex;flex-direction:column;gap:8px;color:inherit;font:inherit;container-type:inline-size;min-width:0}
|
|
46
|
+
:host([hidden]){display:none}
|
|
47
|
+
*{box-sizing:border-box}
|
|
48
|
+
.bar{display:grid;gap:6px}
|
|
49
|
+
.bar:empty{display:none}
|
|
50
|
+
.row{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
|
|
51
|
+
.chips{flex-wrap:nowrap;overflow-x:auto;scrollbar-width:thin;padding-bottom:2px}
|
|
52
|
+
.chips>*{flex:none}
|
|
53
|
+
@container (min-width:600px){.chips{flex-wrap:wrap;overflow:visible}}
|
|
54
|
+
.gap{flex:1 1 0}
|
|
55
|
+
button{font:inherit;color:inherit;background:transparent;border:1px solid color-mix(in srgb,currentColor 35%,transparent);border-radius:999px;padding:3px 12px;min-height:32px;cursor:pointer;display:inline-flex;align-items:center;gap:6px}
|
|
56
|
+
button[aria-pressed="true"]{background:color-mix(in srgb,currentColor 14%,transparent);border-color:currentColor}
|
|
57
|
+
button:disabled{opacity:.45;cursor:default}
|
|
58
|
+
button:focus-visible{outline:3px solid #6cd0ff;outline-offset:2px}
|
|
59
|
+
@media (pointer:coarse){button{min-height:44px;padding:6px 14px}}
|
|
60
|
+
.chip .swatch{width:10px;height:10px;border-radius:50%;background:var(--c,#9aa5b1);flex:none}
|
|
61
|
+
.chip .n{opacity:.7;font-variant-numeric:tabular-nums;font-size:.85em}
|
|
62
|
+
.stage{position:relative;flex:1 1 auto;min-height:0;aspect-ratio:var(--chikyu-flat-aspect,2/1);overflow:hidden;border-radius:var(--chikyu-flat-radius,10px);background:var(--chikyu-flat-sea,#0b1830)}
|
|
63
|
+
@container (max-width:599px){.stage{aspect-ratio:var(--chikyu-flat-aspect-narrow,4/3)}}
|
|
64
|
+
canvas{position:absolute;inset:0;width:100%;height:100%;display:block}
|
|
65
|
+
.dots{outline:none;cursor:grab;touch-action:pan-y}
|
|
66
|
+
.dots[data-zoomed]{touch-action:none}
|
|
67
|
+
.dots:focus-visible{outline:3px solid #6cd0ff;outline-offset:-3px}
|
|
68
|
+
.ring{position:absolute;left:0;top:0;width:20px;height:20px;margin:-10px 0 0 -10px;border:2px solid #fff;border-radius:50%;pointer-events:none;box-shadow:0 0 0 1px #000,inset 0 0 0 1px #000}
|
|
69
|
+
.ring.hov{width:14px;height:14px;margin:-7px 0 0 -7px;border-width:1px}
|
|
70
|
+
.ring[hidden],.tip[hidden]{display:none}
|
|
71
|
+
.tip{position:absolute;left:0;top:0;pointer-events:none;background:rgba(8,14,28,.94);color:#fff;padding:4px 8px;border-radius:6px;font-size:.85em;line-height:1.3;white-space:nowrap;border:1px solid rgba(255,255,255,.3)}
|
|
72
|
+
.msg{position:absolute;inset:0;display:grid;place-items:center;margin:0;padding:12px;text-align:center;color:#cfe0f5;pointer-events:none}
|
|
73
|
+
.msg:empty{display:none}
|
|
74
|
+
.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
|
|
75
|
+
`;
|
|
76
|
+
/**
|
|
77
|
+
* The `<chikyu-flat>` custom element: satellites on a flat map of the world, at the places SGP4 puts them for the time shown. Import `@johnmorrisdotca/chikyu-earth/flat/define` to register the tag; it needs `satellite.js` (an optional peer).
|
|
78
|
+
*
|
|
79
|
+
* The page gives it orbital elements: `setGroup(id, sets)` for each group (the ids of `SATELLITE_GROUPS` are known by name and colour), or the `elements` property for one, or `elements-src` (an address, read once, through `fetchElements`' rules). The package fetches nothing of its own.
|
|
80
|
+
* Attributes: `center` (the longitude in the middle, degrees; 0, Greenwich, by default; the map wraps round the date line), `home-lon` and `home-lat` (the reader's place: a marker, and the "My place" button, which appear only when given; the element never asks the browser for a place),
|
|
81
|
+
* `group` (which groups to show: `all`, one id, or several with commas), `off` (groups that are loaded but start off when `group` names none, such as `starlink`: the filter chip turns one on), `colour-by` (`group`, or `plane` to colour by orbital plane), `plane` (a plane letter: show that plane only), `footprint` and `track` (draw the coverage circle and the ground track; the footprint is of the chosen satellite, or of every one shown when there are 80 or fewer),
|
|
82
|
+
* `paused` (hold the clock and keep the speed; nothing is drawn while it is held), `trails` (`off` for no streaks at a fast clock), `footprint-elevation` (degrees above the horizon the circle is drawn for; 25 like the 3D beam), `selected` (a NORAD number: the chosen satellite), `time` (`now` or an ISO date; live when absent), `speed` (1 is real time, 0 holds, 86400 is a day a second, negative runs backwards), `estimate-far`, `shade` (`off` for no night),
|
|
83
|
+
* `dot-size` (pixels), `controls` (`none`, or any of `centre zoom footprint track chips`: the built-in buttons and filter chips shown; all by default) and `lang` (`en` or `ja`; the page's language by default).
|
|
84
|
+
*
|
|
85
|
+
* Events: `chikyu-flat-pick` (a satellite under the pointer, tapped, or reached by the keyboard: a `FlatPick`; `detail.id` is null when a tap lands on nothing and clears the choice), `chikyu-flat-filter` (a chip changed which groups or plane are shown: `{ groups, plane }`),
|
|
86
|
+
* `chikyu-flat-planes` (the planes were worked out: `{ planes }`), `chikyu-flat-view` (the reader panned or zoomed: `{ center, zoom }`) and `chikyu-timechange` (`{ time, running }`, at most four a second while time runs).
|
|
87
|
+
* Style it with the custom properties `--chikyu-flat-sea`, `--chikyu-flat-land`, `--chikyu-flat-line`, `--chikyu-flat-night`, `--chikyu-flat-aspect`, `--chikyu-flat-aspect-narrow` and `--chikyu-flat-radius`.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts no-run
|
|
91
|
+
* import "@johnmorrisdotca/chikyu-earth/flat/define";
|
|
92
|
+
* import type { ChikyuFlat } from "@johnmorrisdotca/chikyu-earth/flat/define";
|
|
93
|
+
* import type { ElementSet } from "@johnmorrisdotca/chikyu-earth/satellites";
|
|
94
|
+
*
|
|
95
|
+
* declare const gpsElements: ElementSet[]; // your page's own element sets
|
|
96
|
+
* const flat = document.createElement("chikyu-flat") as ChikyuFlat;
|
|
97
|
+
* flat.setAttribute("center", "139.7");
|
|
98
|
+
* flat.setAttribute("colour-by", "plane");
|
|
99
|
+
* flat.setGroup("gps", gpsElements);
|
|
100
|
+
* document.body.append(flat);
|
|
101
|
+
* flat.addEventListener("chikyu-flat-pick", (event) => console.log((event as CustomEvent).detail.name));
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export class ChikyuFlat extends HTMLElement {
|
|
105
|
+
static observedAttributes = ["paused", "trails", "off", "center", "home-lon", "home-lat", "group", "colour-by", "color-by", "plane", "footprint", "track", "footprint-elevation", "selected", "time", "speed", "estimate-far", "shade", "dot-size", "controls", "lang", "elements-src"];
|
|
106
|
+
#groups = new Map();
|
|
107
|
+
#index = new Map();
|
|
108
|
+
#shown = null;
|
|
109
|
+
/** Groups that start off when `group` names none: loaded, and one tap on their chip away. */
|
|
110
|
+
#off = new Set();
|
|
111
|
+
#plane = "";
|
|
112
|
+
#selected = null;
|
|
113
|
+
#cursor = null;
|
|
114
|
+
#hover = null;
|
|
115
|
+
#footprint = false;
|
|
116
|
+
#track = false;
|
|
117
|
+
#view = { width: 0, height: 0, centerLon: 0, centerLat: 0, zoom: 1 };
|
|
118
|
+
#dpr = 1;
|
|
119
|
+
#mode = "now";
|
|
120
|
+
#time = 0;
|
|
121
|
+
#speed = 1;
|
|
122
|
+
#last = 0;
|
|
123
|
+
#paused = false;
|
|
124
|
+
/** The moment shown jumped (the page set it, the speed changed, the tab came back): fast placement pins every satellite again before it turns them. */
|
|
125
|
+
#jump = true;
|
|
126
|
+
#lastDraw = 0;
|
|
127
|
+
#totalMs = 0;
|
|
128
|
+
#timer;
|
|
129
|
+
#exact = new Float64Array(6);
|
|
130
|
+
#frame = 0;
|
|
131
|
+
#inView = true;
|
|
132
|
+
#connected = false;
|
|
133
|
+
#problem = "";
|
|
134
|
+
#waiting = false;
|
|
135
|
+
#loaded;
|
|
136
|
+
#fetch = 0;
|
|
137
|
+
#viewSent = "";
|
|
138
|
+
#announced = -Infinity;
|
|
139
|
+
#mapKey = "";
|
|
140
|
+
#trackKey = "";
|
|
141
|
+
#trackLines = null;
|
|
142
|
+
#stage;
|
|
143
|
+
#bar;
|
|
144
|
+
#mapCanvas;
|
|
145
|
+
#dotCanvas;
|
|
146
|
+
#selRing;
|
|
147
|
+
#hovRing;
|
|
148
|
+
#tip;
|
|
149
|
+
#live;
|
|
150
|
+
#msg;
|
|
151
|
+
#sizer;
|
|
152
|
+
#watcher;
|
|
153
|
+
#pointers = new Map();
|
|
154
|
+
#drag = null;
|
|
155
|
+
#counts = { draws: 0, mapDraws: 0, dots: 0, lastMs: 0, maxMs: 0 };
|
|
156
|
+
#buckets = new Map();
|
|
157
|
+
#streaks = new Map();
|
|
158
|
+
// --- the page's data -------------------------------------------------------------------------------------------------------------------------
|
|
159
|
+
/**
|
|
160
|
+
* Hand over a group's orbital elements, or take the group away with `null`. The satellites start SGP4 here (a Starlink-sized group takes a fraction of a second), the facts and orbital planes are worked out, and the next draw shows them.
|
|
161
|
+
* `id` is a name of `SATELLITE_GROUPS` (`gps`, `starlink`: its words and colour are known) or any name of the page's own, with `style` for its colour and words.
|
|
162
|
+
*
|
|
163
|
+
* @param id - The group's name.
|
|
164
|
+
* @param sets - Its element sets, as `createSatellites` takes them; `null` removes the group.
|
|
165
|
+
* @param style - The colour and the English and Japanese names of a group the package does not know.
|
|
166
|
+
*/
|
|
167
|
+
setGroup(id, sets, style = {}) {
|
|
168
|
+
const old = this.#groups.get(id);
|
|
169
|
+
if (old) {
|
|
170
|
+
for (const set of old.sats.sets)
|
|
171
|
+
if (this.#index.get(set.NORAD_CAT_ID)?.g === old)
|
|
172
|
+
this.#index.delete(set.NORAD_CAT_ID);
|
|
173
|
+
if (this.#selected?.g === old)
|
|
174
|
+
this.#selected = null;
|
|
175
|
+
if (this.#cursor?.g === old)
|
|
176
|
+
this.#cursor = null;
|
|
177
|
+
if (this.#hover?.g === old)
|
|
178
|
+
this.#hover = null;
|
|
179
|
+
this.#groups.delete(id);
|
|
180
|
+
}
|
|
181
|
+
if (sets !== null) {
|
|
182
|
+
const sats = createSatellites(sets);
|
|
183
|
+
sats.estimateFar = flag(this.getAttribute("estimate-far"));
|
|
184
|
+
const known = SATELLITE_GROUPS.find((one) => one.id === id);
|
|
185
|
+
const n = sats.count;
|
|
186
|
+
const clusters = clusterPlanes(sats.sets);
|
|
187
|
+
const group = {
|
|
188
|
+
id,
|
|
189
|
+
label: style.label ?? known?.label ?? id,
|
|
190
|
+
labelJa: style.labelJa ?? known?.labelJa ?? style.label ?? id,
|
|
191
|
+
colour: style.colour ?? GROUP_COLOURS[id] ?? PLANE_COLOURS[this.#groups.size % PLANE_COLOURS.length],
|
|
192
|
+
sats,
|
|
193
|
+
n,
|
|
194
|
+
buf: new Float32Array(n * 3),
|
|
195
|
+
lon: new Float32Array(n),
|
|
196
|
+
lat: new Float32Array(n),
|
|
197
|
+
alt: new Float32Array(n),
|
|
198
|
+
sx: new Float32Array(n),
|
|
199
|
+
sy: new Float32Array(n),
|
|
200
|
+
seg: null,
|
|
201
|
+
cursor: 0,
|
|
202
|
+
on: new Uint8Array(n),
|
|
203
|
+
clusters,
|
|
204
|
+
facts: groupFacts(sats.sets),
|
|
205
|
+
};
|
|
206
|
+
this.#groups.set(id, group);
|
|
207
|
+
sats.sets.forEach((set, i) => this.#index.set(set.NORAD_CAT_ID, { g: group, i }));
|
|
208
|
+
this.#waiting = false;
|
|
209
|
+
this.#problem = "";
|
|
210
|
+
this.#syncSpeed();
|
|
211
|
+
}
|
|
212
|
+
const wanted = Number(this.getAttribute("selected"));
|
|
213
|
+
if (this.#selected === null && Number.isFinite(wanted) && this.#index.has(wanted))
|
|
214
|
+
this.#selected = this.#index.get(wanted) ?? null;
|
|
215
|
+
this.#trackKey = "";
|
|
216
|
+
this.#buildBar();
|
|
217
|
+
this.dispatchEvent(new CustomEvent("chikyu-flat-planes", { detail: { planes: this.planes }, bubbles: true, composed: true }));
|
|
218
|
+
this.#request();
|
|
219
|
+
this.#schedule();
|
|
220
|
+
}
|
|
221
|
+
/** The element sets of the group the attributes name (`group`, else `satellites`): a shorthand for one group. Setting it calls `setGroup`. */
|
|
222
|
+
get elements() {
|
|
223
|
+
return this.#groups.get(this.#defaultId())?.sats.sets ?? [];
|
|
224
|
+
}
|
|
225
|
+
set elements(sets) {
|
|
226
|
+
this.setGroup(this.#defaultId(), sets);
|
|
227
|
+
}
|
|
228
|
+
/** The groups loaded, in the order they were given: their name, words, colour and how many satellites started SGP4. */
|
|
229
|
+
get groups() {
|
|
230
|
+
return [...this.#groups.values()].map((g) => ({ id: g.id, label: g.label, labelJa: g.labelJa, colour: g.colour, count: g.n }));
|
|
231
|
+
}
|
|
232
|
+
/** The facts (`groupFacts`) of a loaded group, or undefined. */
|
|
233
|
+
facts(id) {
|
|
234
|
+
return this.#groups.get(id)?.facts;
|
|
235
|
+
}
|
|
236
|
+
/** The orbital planes of every loaded group (by right ascension of the ascending node; see `clusterPlanes`): the letter, how many satellites, the colour the map gives it. A group with no planes to show has none here. */
|
|
237
|
+
get planes() {
|
|
238
|
+
const out = [];
|
|
239
|
+
for (const g of this.#groups.values())
|
|
240
|
+
for (const plane of g.clusters.planes)
|
|
241
|
+
out.push({ ...plane, group: g.id, colour: PLANE_COLOURS[plane.index % PLANE_COLOURS.length] });
|
|
242
|
+
return out;
|
|
243
|
+
}
|
|
244
|
+
/** The groups on show: those the `group` attribute names, or the ones a chip chose; every loaded group when none is chosen. Set to a list of ids, or `null` for all. */
|
|
245
|
+
get visibleGroups() {
|
|
246
|
+
return this.#shownGroups().map((g) => g.id);
|
|
247
|
+
}
|
|
248
|
+
set visibleGroups(ids) {
|
|
249
|
+
this.#shown = ids === null ? null : new Set(ids);
|
|
250
|
+
this.#afterFilter();
|
|
251
|
+
}
|
|
252
|
+
/** The NORAD number of the chosen satellite, or null. Set it to choose one from code (no `chikyu-flat-pick` is sent), `null` to clear. */
|
|
253
|
+
get selected() {
|
|
254
|
+
return this.#selected ? (this.#selected.g.sats.sets[this.#selected.i]?.NORAD_CAT_ID ?? null) : null;
|
|
255
|
+
}
|
|
256
|
+
set selected(id) {
|
|
257
|
+
this.#selected = id === null ? null : (this.#index.get(id) ?? null);
|
|
258
|
+
this.#trackKey = "";
|
|
259
|
+
this.#sync();
|
|
260
|
+
this.#request();
|
|
261
|
+
}
|
|
262
|
+
/** The longitude in the middle, degrees. Set it to centre the map there; a reader's pan changes it, and `chikyu-flat-view` tells the page. */
|
|
263
|
+
get center() {
|
|
264
|
+
return this.#view.centerLon;
|
|
265
|
+
}
|
|
266
|
+
set center(lon) {
|
|
267
|
+
this.#view = clampView({ ...this.#view, centerLon: lon });
|
|
268
|
+
this.#sync();
|
|
269
|
+
this.#request();
|
|
270
|
+
}
|
|
271
|
+
/** The zoom: 1 shows the whole world, up to 8. */
|
|
272
|
+
get zoom() {
|
|
273
|
+
return this.#view.zoom;
|
|
274
|
+
}
|
|
275
|
+
set zoom(value) {
|
|
276
|
+
this.#view = clampView({ ...this.#view, zoom: value });
|
|
277
|
+
this.#sync();
|
|
278
|
+
this.#request();
|
|
279
|
+
}
|
|
280
|
+
/** The moment shown, in milliseconds since the Unix epoch. Set it to a number (or a `Date`) to move the clock, or "now" to go live. */
|
|
281
|
+
get time() {
|
|
282
|
+
this.#advance(performance.now());
|
|
283
|
+
return this.#time;
|
|
284
|
+
}
|
|
285
|
+
set time(value) {
|
|
286
|
+
this.#mode = value === "now" ? "now" : typeof value === "number" ? value : value.getTime();
|
|
287
|
+
this.#time = this.#mode === "now" ? Date.now() : this.#mode;
|
|
288
|
+
this.#last = performance.now();
|
|
289
|
+
// a jump: the dots are placed again at once, from the new moment
|
|
290
|
+
this.#jump = true;
|
|
291
|
+
this.#request();
|
|
292
|
+
this.#schedule();
|
|
293
|
+
}
|
|
294
|
+
/** How fast the clock runs: 1 is real time, 0 holds, 86400 is a day a second, negative runs backwards. */
|
|
295
|
+
get speed() {
|
|
296
|
+
return this.#speed;
|
|
297
|
+
}
|
|
298
|
+
set speed(value) {
|
|
299
|
+
this.#advance(performance.now());
|
|
300
|
+
this.#speed = Number.isFinite(value) ? value : 1;
|
|
301
|
+
this.#jump = true;
|
|
302
|
+
this.#syncSpeed();
|
|
303
|
+
this.#schedule();
|
|
304
|
+
this.#request();
|
|
305
|
+
}
|
|
306
|
+
/** True while the clock is held with its speed kept (the page's Pause): nothing is drawn but what the reader changes. Setting it false carries on from the moment shown at the same speed. */
|
|
307
|
+
get paused() {
|
|
308
|
+
return this.#paused;
|
|
309
|
+
}
|
|
310
|
+
set paused(value) {
|
|
311
|
+
const now = performance.now();
|
|
312
|
+
this.#advance(now);
|
|
313
|
+
if (value === this.#paused)
|
|
314
|
+
return;
|
|
315
|
+
this.#paused = value;
|
|
316
|
+
// held, the moment stays where it is even in real time (it does not jump to the clock's now when carried on)
|
|
317
|
+
if (value && this.#mode === "now")
|
|
318
|
+
this.#mode = this.#time;
|
|
319
|
+
this.#last = now;
|
|
320
|
+
this.#jump = true;
|
|
321
|
+
this.#schedule();
|
|
322
|
+
this.#request();
|
|
323
|
+
this.dispatchEvent(new CustomEvent("chikyu-timechange", { detail: { time: this.#time, running: this.#running(), paused: value }, bubbles: true, composed: true }));
|
|
324
|
+
}
|
|
325
|
+
/** The language of the words: the `lang` attribute, else the page's. */
|
|
326
|
+
get language() {
|
|
327
|
+
return (this.getAttribute("lang") ?? this.ownerDocument.documentElement.lang ?? "en").toLowerCase().startsWith("ja") ? "ja" : "en";
|
|
328
|
+
}
|
|
329
|
+
/** Counters for a test or a page: draws of the dots, draws of the map, the dots drawn at the last draw, the milliseconds the last draw and the slowest took, and the canvases' size in pixels. */
|
|
330
|
+
get stats() {
|
|
331
|
+
const canvases = [this.#mapCanvas, this.#dotCanvas].filter((c) => c !== undefined).map((c) => ({ width: c.width, height: c.height }));
|
|
332
|
+
return { draws: this.#counts.draws, mapDraws: this.#counts.mapDraws, dots: this.#counts.dots, lastDrawMs: this.#counts.lastMs, maxDrawMs: this.#counts.maxMs, running: this.#running(), paused: this.#paused, fast: this.#fast(), averageDrawMs: this.#counts.draws > 0 ? this.#totalMs / this.#counts.draws : 0, canvases };
|
|
333
|
+
}
|
|
334
|
+
/** Where a satellite is on the screen as of the last draw, in CSS pixels from the map's top left, or null when it is not drawn (not loaded, filtered out, off the map or too old). */
|
|
335
|
+
placeOf(id) {
|
|
336
|
+
const ref = this.#index.get(id);
|
|
337
|
+
if (!ref || ref.g.on[ref.i] !== 1)
|
|
338
|
+
return null;
|
|
339
|
+
return { x: ref.g.sx[ref.i], y: ref.g.sy[ref.i], lon: ref.g.lon[ref.i], lat: ref.g.lat[ref.i], altitudeKm: ref.g.alt[ref.i] };
|
|
340
|
+
}
|
|
341
|
+
// --- the element's life ----------------------------------------------------------------------------------------------------------------------
|
|
342
|
+
connectedCallback() {
|
|
343
|
+
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
344
|
+
adoptStyles(root, CSS, this.getAttribute("nonce") ?? "");
|
|
345
|
+
if (!this.#stage)
|
|
346
|
+
this.#build(root);
|
|
347
|
+
this.#connected = true;
|
|
348
|
+
this.#readAll();
|
|
349
|
+
this.#advance(performance.now());
|
|
350
|
+
this.#sizer = new ResizeObserver(() => {
|
|
351
|
+
this.#measure();
|
|
352
|
+
this.#request();
|
|
353
|
+
});
|
|
354
|
+
this.#sizer.observe(this.#stage);
|
|
355
|
+
if (typeof IntersectionObserver === "function") {
|
|
356
|
+
this.#watcher = new IntersectionObserver((entries) => {
|
|
357
|
+
const was = this.#visibleNow();
|
|
358
|
+
this.#inView = entries[entries.length - 1]?.isIntersecting ?? true;
|
|
359
|
+
if (!was && this.#visibleNow())
|
|
360
|
+
this.#wake();
|
|
361
|
+
});
|
|
362
|
+
this.#watcher.observe(this);
|
|
363
|
+
}
|
|
364
|
+
document.addEventListener("visibilitychange", this.#onVisibility);
|
|
365
|
+
this.#measure();
|
|
366
|
+
this.#buildBar();
|
|
367
|
+
this.#request();
|
|
368
|
+
this.#schedule();
|
|
369
|
+
}
|
|
370
|
+
disconnectedCallback() {
|
|
371
|
+
this.#connected = false;
|
|
372
|
+
clearTimeout(this.#timer);
|
|
373
|
+
this.#timer = undefined;
|
|
374
|
+
if (this.#frame)
|
|
375
|
+
cancelAnimationFrame(this.#frame);
|
|
376
|
+
this.#frame = 0;
|
|
377
|
+
this.#sizer?.disconnect();
|
|
378
|
+
this.#watcher?.disconnect();
|
|
379
|
+
this.#sizer = undefined;
|
|
380
|
+
this.#watcher = undefined;
|
|
381
|
+
document.removeEventListener("visibilitychange", this.#onVisibility);
|
|
382
|
+
}
|
|
383
|
+
attributeChangedCallback(name) {
|
|
384
|
+
if (!this.#connected)
|
|
385
|
+
return;
|
|
386
|
+
this.#read(name);
|
|
387
|
+
if (name === "selected" || name === "footprint-elevation")
|
|
388
|
+
this.#trackKey = "";
|
|
389
|
+
if (name === "lang" || name === "controls" || name === "group" || name === "colour-by" || name === "color-by" || name === "home-lon" || name === "home-lat" || name === "plane")
|
|
390
|
+
this.#buildBar();
|
|
391
|
+
this.#sync();
|
|
392
|
+
this.#request();
|
|
393
|
+
this.#schedule();
|
|
394
|
+
}
|
|
395
|
+
#onVisibility = () => {
|
|
396
|
+
if (this.#visibleNow())
|
|
397
|
+
this.#wake();
|
|
398
|
+
else {
|
|
399
|
+
clearTimeout(this.#timer);
|
|
400
|
+
this.#timer = undefined;
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
#visibleNow() {
|
|
404
|
+
return this.#connected && this.#inView && !hidden();
|
|
405
|
+
}
|
|
406
|
+
/** Back in sight: bring the clock up to date, draw once, and start the timer again. */
|
|
407
|
+
#wake() {
|
|
408
|
+
this.#advance(performance.now());
|
|
409
|
+
this.#jump = true;
|
|
410
|
+
this.#request();
|
|
411
|
+
this.#schedule();
|
|
412
|
+
}
|
|
413
|
+
/** Take in every attribute the element has: when it comes into the page. */
|
|
414
|
+
#readAll() {
|
|
415
|
+
for (const name of _a.observedAttributes)
|
|
416
|
+
this.#read(name);
|
|
417
|
+
}
|
|
418
|
+
/** Take in one attribute. A change to one never undoes what the reader did with another (a chosen satellite, the pan). */
|
|
419
|
+
#read(name) {
|
|
420
|
+
const value = this.getAttribute(name);
|
|
421
|
+
if (name === "center") {
|
|
422
|
+
const lon = finite(value, Number.NaN);
|
|
423
|
+
if (Number.isFinite(lon))
|
|
424
|
+
this.#view = clampView({ ...this.#view, centerLon: lon });
|
|
425
|
+
this.#mapKey = "";
|
|
426
|
+
}
|
|
427
|
+
else if (name === "group") {
|
|
428
|
+
const ids = (value ?? "").split(/[\s,]+/).filter((one) => one !== "" && one.toLowerCase() !== "all");
|
|
429
|
+
this.#shown = ids.length === 0 ? null : new Set(ids);
|
|
430
|
+
}
|
|
431
|
+
else if (name === "off")
|
|
432
|
+
this.#off = new Set((value ?? "").split(/[\s,]+/).filter((one) => one !== ""));
|
|
433
|
+
else if (name === "plane")
|
|
434
|
+
this.#plane = (value ?? "").trim().toUpperCase();
|
|
435
|
+
else if (name === "footprint")
|
|
436
|
+
this.#footprint = flag(value);
|
|
437
|
+
else if (name === "track")
|
|
438
|
+
this.#track = flag(value);
|
|
439
|
+
else if (name === "selected") {
|
|
440
|
+
const id = value === null || value.trim() === "" ? null : Number(value);
|
|
441
|
+
this.#selected = id !== null && Number.isFinite(id) ? (this.#index.get(id) ?? null) : null;
|
|
442
|
+
}
|
|
443
|
+
else if (name === "paused") {
|
|
444
|
+
if (flag(value) !== this.#paused)
|
|
445
|
+
this.paused = flag(value);
|
|
446
|
+
}
|
|
447
|
+
else if (name === "time" || name === "speed")
|
|
448
|
+
this.#readClock();
|
|
449
|
+
else if (name === "estimate-far")
|
|
450
|
+
for (const g of this.#groups.values())
|
|
451
|
+
g.sats.estimateFar = flag(value);
|
|
452
|
+
else if (name === "elements-src")
|
|
453
|
+
this.#load();
|
|
454
|
+
else if (name === "shade" || name === "dot-size")
|
|
455
|
+
this.#mapKey = "";
|
|
456
|
+
}
|
|
457
|
+
#readClock() {
|
|
458
|
+
this.#advance(performance.now());
|
|
459
|
+
this.#mode = readTime(this.getAttribute("time"));
|
|
460
|
+
this.#time = this.#mode === "now" ? Date.now() : this.#mode;
|
|
461
|
+
const raw = this.getAttribute("speed");
|
|
462
|
+
const speed = raw === null || raw.trim() === "" ? 1 : Number(raw);
|
|
463
|
+
this.#speed = Number.isFinite(speed) ? speed : 1;
|
|
464
|
+
this.#last = performance.now();
|
|
465
|
+
this.#jump = true;
|
|
466
|
+
this.#syncSpeed();
|
|
467
|
+
}
|
|
468
|
+
/** How far apart the two SGP4 batches are, so a fast clock does not run SGP4 more than once a (game) second. */
|
|
469
|
+
#syncSpeed() {
|
|
470
|
+
const step = Math.max(1000, Math.abs(this.#speed) * 1000);
|
|
471
|
+
for (const g of this.#groups.values())
|
|
472
|
+
g.sats.setStep(step);
|
|
473
|
+
}
|
|
474
|
+
#defaultId() {
|
|
475
|
+
return (this.getAttribute("group") ?? "").split(/[\s,]+/).find((one) => one !== "" && one.toLowerCase() !== "all") ?? "satellites";
|
|
476
|
+
}
|
|
477
|
+
#load() {
|
|
478
|
+
const address = this.getAttribute("elements-src");
|
|
479
|
+
if (!address || address === this.#loaded)
|
|
480
|
+
return;
|
|
481
|
+
this.#loaded = address;
|
|
482
|
+
const turn = (this.#fetch += 1);
|
|
483
|
+
this.#waiting = true;
|
|
484
|
+
this.#showMessage();
|
|
485
|
+
// one polite request when the element comes into the page: fetchElements keeps the answer and leaves a source that failed alone, and nothing here asks again
|
|
486
|
+
void fetchElements(address).then((got) => {
|
|
487
|
+
if (turn === this.#fetch)
|
|
488
|
+
this.elements = got.sets;
|
|
489
|
+
}, (error) => {
|
|
490
|
+
if (turn !== this.#fetch)
|
|
491
|
+
return;
|
|
492
|
+
this.#waiting = false;
|
|
493
|
+
this.#problem = error instanceof Error ? error.message : "no answer";
|
|
494
|
+
this.#showMessage();
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
// --- the clock -------------------------------------------------------------------------------------------------------------------------------
|
|
498
|
+
#advance(now) {
|
|
499
|
+
if (this.#paused || this.#speed === 0) {
|
|
500
|
+
// held: the moment stays
|
|
501
|
+
}
|
|
502
|
+
else if (this.#speed === 1 && this.#mode === "now")
|
|
503
|
+
this.#time = Date.now();
|
|
504
|
+
else
|
|
505
|
+
this.#time += (now - this.#last) * this.#speed;
|
|
506
|
+
this.#last = now;
|
|
507
|
+
}
|
|
508
|
+
/** The clock is running and the element is in sight: it asks for frames. A held clock, a hidden tab and a view out of sight ask for none. */
|
|
509
|
+
#running() {
|
|
510
|
+
return this.#visibleNow() && this.#speed !== 0 && !this.#paused;
|
|
511
|
+
}
|
|
512
|
+
/** Is the clock fast enough that SGP4 cannot be run for every frame (the satellites turn along their orbits and are drawn as streaks)? */
|
|
513
|
+
#fast() {
|
|
514
|
+
return !this.#paused && Math.abs(this.#speed) > MAX_SATELLITE_SPEED;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* How often a running clock draws: as often as a satellite in a low orbit (about 0.07 degree of the map a second) moves half a pixel, up to every frame, and at least once a second; once a second at most for a reader who asked for reduced motion.
|
|
518
|
+
* With nothing to show, the pace of the night's edge (the Earth turns 0.004 degree a second).
|
|
519
|
+
*/
|
|
520
|
+
#rate() {
|
|
521
|
+
const k = pixelsPerDegree(this.#view.width > 0 ? this.#view : { ...this.#view, width: 600, height: 300 });
|
|
522
|
+
const dots = this.#shownGroups().length > 0;
|
|
523
|
+
let perSecond = ((dots ? 0.07 : 0.0042) * Math.abs(this.#speed) * k) / 0.5;
|
|
524
|
+
perSecond = Math.min(60, Math.max(dots ? 1 : 1 / 30, perSecond));
|
|
525
|
+
if (prefersLessMotion())
|
|
526
|
+
perSecond = Math.min(perSecond, 1);
|
|
527
|
+
return perSecond;
|
|
528
|
+
}
|
|
529
|
+
/** After a draw, or when something about the clock changed: ask for the next frame in time, a frame a time at the pace `#rate` gives, by a timer when frames are far apart. Nothing at all when the clock is held or out of sight. */
|
|
530
|
+
#schedule() {
|
|
531
|
+
clearTimeout(this.#timer);
|
|
532
|
+
this.#timer = undefined;
|
|
533
|
+
if (!this.#running())
|
|
534
|
+
return;
|
|
535
|
+
const wait = 1000 / this.#rate() - (performance.now() - this.#lastDraw);
|
|
536
|
+
if (wait > 14) {
|
|
537
|
+
this.#timer = setTimeout(() => {
|
|
538
|
+
this.#timer = undefined;
|
|
539
|
+
this.#request();
|
|
540
|
+
}, wait);
|
|
541
|
+
}
|
|
542
|
+
else
|
|
543
|
+
this.#request();
|
|
544
|
+
}
|
|
545
|
+
/** `chikyu-timechange`: the moment shown, at most four times a second while time runs. */
|
|
546
|
+
#announceTime() {
|
|
547
|
+
const now = performance.now();
|
|
548
|
+
if (!this.#running() || now - this.#announced < TIME_EVENT_MS)
|
|
549
|
+
return;
|
|
550
|
+
this.#announced = now;
|
|
551
|
+
this.dispatchEvent(new CustomEvent("chikyu-timechange", { detail: { time: this.#time, running: true, paused: false }, bubbles: true, composed: true }));
|
|
552
|
+
}
|
|
553
|
+
// --- drawing ---------------------------------------------------------------------------------------------------------------------------------
|
|
554
|
+
/** Ask for one draw at the next frame, however many reasons there are. Nothing is asked for out of sight or in a hidden tab: the draw is made when the element comes back. */
|
|
555
|
+
#request() {
|
|
556
|
+
if (!this.#connected)
|
|
557
|
+
return;
|
|
558
|
+
// out of sight or in a hidden tab nothing is asked for: `#wake` draws once when the element comes back
|
|
559
|
+
if (!this.#visibleNow())
|
|
560
|
+
return;
|
|
561
|
+
if (this.#frame)
|
|
562
|
+
return;
|
|
563
|
+
this.#frame = requestAnimationFrame(() => {
|
|
564
|
+
this.#frame = 0;
|
|
565
|
+
this.#draw();
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
#shownGroups() {
|
|
569
|
+
const out = [];
|
|
570
|
+
for (const g of this.#groups.values())
|
|
571
|
+
if (this.#shown === null ? !this.#off.has(g.id) : this.#shown.has(g.id))
|
|
572
|
+
out.push(g);
|
|
573
|
+
return out;
|
|
574
|
+
}
|
|
575
|
+
/** The plane letter the filter keeps, when exactly one group is on show and it has that plane. */
|
|
576
|
+
#planeIndex(groups) {
|
|
577
|
+
if (this.#plane === "" || groups.length !== 1)
|
|
578
|
+
return -1;
|
|
579
|
+
return groups[0].clusters.planes.find((one) => one.id === this.#plane)?.index ?? -1;
|
|
580
|
+
}
|
|
581
|
+
#byPlane(groups) {
|
|
582
|
+
const by = (this.getAttribute("colour-by") ?? this.getAttribute("color-by") ?? "group").trim().toLowerCase();
|
|
583
|
+
return by === "plane" && groups.some((g) => g.clusters.clustered);
|
|
584
|
+
}
|
|
585
|
+
#measure() {
|
|
586
|
+
const stage = this.#stage;
|
|
587
|
+
if (!stage)
|
|
588
|
+
return;
|
|
589
|
+
const width = stage.clientWidth;
|
|
590
|
+
const height = stage.clientHeight;
|
|
591
|
+
// the canvases stay inside 6 million pixels and 4096 a side, whatever the screen
|
|
592
|
+
const dpr = Math.max(0.5, Math.min(window.devicePixelRatio || 1, 3, width > 0 && height > 0 ? Math.sqrt(6_000_000 / (width * height)) : 3, width > 0 || height > 0 ? 4096 / Math.max(width, height) : 3));
|
|
593
|
+
if (width === this.#view.width && height === this.#view.height && dpr === this.#dpr)
|
|
594
|
+
return;
|
|
595
|
+
this.#dpr = dpr;
|
|
596
|
+
this.#view = clampView({ ...this.#view, width, height });
|
|
597
|
+
for (const canvas of [this.#mapCanvas, this.#dotCanvas]) {
|
|
598
|
+
if (!canvas)
|
|
599
|
+
continue;
|
|
600
|
+
canvas.width = Math.max(1, Math.round(width * dpr));
|
|
601
|
+
canvas.height = Math.max(1, Math.round(height * dpr));
|
|
602
|
+
}
|
|
603
|
+
this.#mapKey = "";
|
|
604
|
+
}
|
|
605
|
+
#colours() {
|
|
606
|
+
const style = getComputedStyle(this);
|
|
607
|
+
const pick = (name, fallback) => style.getPropertyValue(name).trim() || fallback;
|
|
608
|
+
return { sea: pick("--chikyu-flat-sea", "#0b1830"), land: pick("--chikyu-flat-land", "#1d3557"), line: pick("--chikyu-flat-line", "#46628a"), night: pick("--chikyu-flat-night", "rgba(2,6,18,0.16)"), grid: "rgba(150,180,220,0.13)" };
|
|
609
|
+
}
|
|
610
|
+
#projection() {
|
|
611
|
+
const v = this.#view;
|
|
612
|
+
const k = pixelsPerDegree(v);
|
|
613
|
+
return geoEquirectangular()
|
|
614
|
+
.rotate([-v.centerLon, 0])
|
|
615
|
+
.scale(k / RAD)
|
|
616
|
+
.translate([v.width / 2, v.height / 2 + v.centerLat * k])
|
|
617
|
+
.precision(0.4);
|
|
618
|
+
}
|
|
619
|
+
#drawMap(ms) {
|
|
620
|
+
const canvas = this.#mapCanvas;
|
|
621
|
+
const v = this.#view;
|
|
622
|
+
if (!canvas || v.width === 0)
|
|
623
|
+
return;
|
|
624
|
+
const sun = subsolarPoint(ms);
|
|
625
|
+
const shade = this.getAttribute("shade") !== "off";
|
|
626
|
+
const home = this.#home();
|
|
627
|
+
// the map is drawn again only when the view, the home or the sun's place (about a quarter of a degree) changed
|
|
628
|
+
const c = this.#colours();
|
|
629
|
+
const key = [v.width, v.height, this.#dpr, v.centerLon.toFixed(3), v.centerLat.toFixed(3), v.zoom.toFixed(3), shade ? Math.round(sun.lon * 4) : "x", shade ? Math.round(sun.lat * 4) : "x", home ? `${home.lon},${home.lat}` : "", c.sea, c.land, c.line, c.night].join("|");
|
|
630
|
+
if (key === this.#mapKey)
|
|
631
|
+
return;
|
|
632
|
+
this.#mapKey = key;
|
|
633
|
+
this.#counts.mapDraws += 1;
|
|
634
|
+
const ctx = canvas.getContext("2d", { willReadFrequently: true });
|
|
635
|
+
if (!ctx)
|
|
636
|
+
return;
|
|
637
|
+
ctx.setTransform(this.#dpr, 0, 0, this.#dpr, 0, 0);
|
|
638
|
+
ctx.fillStyle = c.sea;
|
|
639
|
+
ctx.fillRect(0, 0, v.width, v.height);
|
|
640
|
+
const projection = this.#projection();
|
|
641
|
+
const path = geoPath(projection, ctx);
|
|
642
|
+
ctx.beginPath();
|
|
643
|
+
path(geoGraticule10());
|
|
644
|
+
ctx.strokeStyle = c.grid;
|
|
645
|
+
ctx.lineWidth = 1;
|
|
646
|
+
ctx.stroke();
|
|
647
|
+
ctx.beginPath();
|
|
648
|
+
path(COUNTRIES);
|
|
649
|
+
ctx.fillStyle = c.land;
|
|
650
|
+
ctx.fill();
|
|
651
|
+
ctx.strokeStyle = c.line;
|
|
652
|
+
ctx.lineWidth = 0.6;
|
|
653
|
+
ctx.stroke();
|
|
654
|
+
if (shade) {
|
|
655
|
+
// the night side: four bands from the sunset line towards midnight, each a little darker
|
|
656
|
+
const anti = [wrapLongitude(sun.lon + 180), -sun.lat];
|
|
657
|
+
ctx.fillStyle = c.night;
|
|
658
|
+
for (const radius of [90, 96, 102, 108]) {
|
|
659
|
+
ctx.beginPath();
|
|
660
|
+
path(geoCircle().center(anti).radius(radius).precision(2)());
|
|
661
|
+
ctx.fill();
|
|
662
|
+
}
|
|
663
|
+
const at = projectFlat(v, sun.lon, sun.lat);
|
|
664
|
+
for (const x of [at.x, at.x - 360 * pixelsPerDegree(v), at.x + 360 * pixelsPerDegree(v)]) {
|
|
665
|
+
if (x < -8 || x > v.width + 8)
|
|
666
|
+
continue;
|
|
667
|
+
ctx.beginPath();
|
|
668
|
+
ctx.arc(x, at.y, 5, 0, Math.PI * 2);
|
|
669
|
+
ctx.fillStyle = "#ffd54f";
|
|
670
|
+
ctx.fill();
|
|
671
|
+
ctx.lineWidth = 1;
|
|
672
|
+
ctx.strokeStyle = "rgba(0,0,0,.5)";
|
|
673
|
+
ctx.stroke();
|
|
674
|
+
ctx.fillStyle = c.night;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
if (home) {
|
|
678
|
+
const at = projectFlat(v, home.lon, home.lat);
|
|
679
|
+
const wrap = 360 * pixelsPerDegree(v);
|
|
680
|
+
for (const x of [at.x, at.x - wrap, at.x + wrap]) {
|
|
681
|
+
if (x < -10 || x > v.width + 10)
|
|
682
|
+
continue;
|
|
683
|
+
ctx.save();
|
|
684
|
+
ctx.translate(x, at.y);
|
|
685
|
+
ctx.rotate(Math.PI / 4);
|
|
686
|
+
ctx.fillStyle = "#ffffff";
|
|
687
|
+
ctx.strokeStyle = "#0b1830";
|
|
688
|
+
ctx.lineWidth = 2;
|
|
689
|
+
ctx.strokeRect(-4.5, -4.5, 9, 9);
|
|
690
|
+
ctx.fillRect(-4.5, -4.5, 9, 9);
|
|
691
|
+
ctx.restore();
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
#home() {
|
|
696
|
+
const lon = finite(this.getAttribute("home-lon"), Number.NaN);
|
|
697
|
+
const lat = finite(this.getAttribute("home-lat"), Number.NaN);
|
|
698
|
+
return Number.isFinite(lon) && Number.isFinite(lat) ? { lon: wrapLongitude(lon), lat } : null;
|
|
699
|
+
}
|
|
700
|
+
#draw() {
|
|
701
|
+
const started = performance.now();
|
|
702
|
+
const canvas = this.#dotCanvas;
|
|
703
|
+
const v = this.#view;
|
|
704
|
+
if (!canvas || v.width === 0 || v.height === 0)
|
|
705
|
+
return;
|
|
706
|
+
this.#advance(started);
|
|
707
|
+
const ms = this.#time;
|
|
708
|
+
const gmst = greenwichSidereal(ms);
|
|
709
|
+
this.#drawMap(ms);
|
|
710
|
+
// a canvas the processor draws, not the graphics card: thousands of small shapes a frame are quicker that way (a machine with no graphics card, or drawing in software, ran 1 frame a second against 60) and the picture is small
|
|
711
|
+
const ctx = canvas.getContext("2d", { willReadFrequently: true });
|
|
712
|
+
if (!ctx)
|
|
713
|
+
return;
|
|
714
|
+
ctx.setTransform(this.#dpr, 0, 0, this.#dpr, 0, 0);
|
|
715
|
+
ctx.clearRect(0, 0, v.width, v.height);
|
|
716
|
+
const groups = this.#shownGroups();
|
|
717
|
+
const k = pixelsPerDegree(v);
|
|
718
|
+
const wrapPx = 360 * k;
|
|
719
|
+
const planeAt = this.#planeIndex(groups);
|
|
720
|
+
const byPlane = this.#byPlane(groups);
|
|
721
|
+
const total = groups.reduce((sum, g) => sum + g.n, 0);
|
|
722
|
+
const size = finite(this.getAttribute("dot-size"), 0);
|
|
723
|
+
const r = size > 0 ? size / 2 : total > 5000 ? 1.1 : total > 1500 ? 1.5 : total > 300 ? 2 : 3;
|
|
724
|
+
const radius = r * Math.min(1.8, 0.85 + v.zoom * 0.15);
|
|
725
|
+
const pad = radius + 1;
|
|
726
|
+
const buckets = this.#buckets;
|
|
727
|
+
for (const list of buckets.values())
|
|
728
|
+
list.length = 0;
|
|
729
|
+
const streaks = this.#streaks;
|
|
730
|
+
for (const list of streaks.values())
|
|
731
|
+
list.length = 0;
|
|
732
|
+
// a clock too fast for SGP4 to run for every frame: the satellites are turned along their orbits from a pinned place (SGP4 itself a slice of the group a frame, the whole group once a second) and drawn as streaks
|
|
733
|
+
const fast = this.#fast();
|
|
734
|
+
const streak = fast && this.getAttribute("trails") !== "off";
|
|
735
|
+
const dtReal = this.#lastDraw === 0 ? 16 : Math.min(1000, Math.max(0, started - this.#lastDraw));
|
|
736
|
+
const chosen = this.#selected;
|
|
737
|
+
const streakPx = total > 3000 ? STREAK_PX_CROWD : STREAK_PX;
|
|
738
|
+
let dots = 0;
|
|
739
|
+
for (const g of groups) {
|
|
740
|
+
if (fast) {
|
|
741
|
+
g.seg ??= new Float32Array(g.n * 6);
|
|
742
|
+
if (this.#jump) {
|
|
743
|
+
g.sats.pin(ms);
|
|
744
|
+
g.cursor = 0;
|
|
745
|
+
}
|
|
746
|
+
else {
|
|
747
|
+
const slice = Math.max(1, Math.ceil(g.n * (dtReal / 1000)));
|
|
748
|
+
g.sats.pin(ms, g.cursor, slice);
|
|
749
|
+
g.cursor = g.cursor + slice >= g.n ? 0 : g.cursor + slice;
|
|
750
|
+
}
|
|
751
|
+
g.sats.arc(ms, this.#speed * 1000 * STREAK_SECONDS, g.buf, g.seg, (streakPx / k) * RAD);
|
|
752
|
+
}
|
|
753
|
+
else
|
|
754
|
+
g.sats.at(ms, g.buf);
|
|
755
|
+
// the chosen satellite is always where SGP4 puts it, to the frame
|
|
756
|
+
if (chosen && chosen.g === g && g.sats.exact(chosen.i, ms, this.#exact)) {
|
|
757
|
+
g.buf[chosen.i * 3] = this.#exact[0];
|
|
758
|
+
g.buf[chosen.i * 3 + 1] = this.#exact[1];
|
|
759
|
+
g.buf[chosen.i * 3 + 2] = this.#exact[2];
|
|
760
|
+
}
|
|
761
|
+
const { buf, lon, lat, alt, sx, sy, on, sats, seg } = g;
|
|
762
|
+
const planeOf = g.clusters.planeOf;
|
|
763
|
+
const dimmed = sats.dimmed;
|
|
764
|
+
for (let i = 0; i < g.n; i += 1) {
|
|
765
|
+
on[i] = 0;
|
|
766
|
+
if (!sats.visible(i))
|
|
767
|
+
continue;
|
|
768
|
+
if (planeAt >= 0 && planeOf[i] !== planeAt)
|
|
769
|
+
continue;
|
|
770
|
+
const x = buf[i * 3];
|
|
771
|
+
const y = buf[i * 3 + 1];
|
|
772
|
+
const z = buf[i * 3 + 2];
|
|
773
|
+
const rr = Math.sqrt(x * x + y * y + z * z);
|
|
774
|
+
const longitude = wrapLongitude((Math.atan2(-z, x) / RAD) - gmst);
|
|
775
|
+
const latitude = (Math.atan(Math.tan(Math.asin(y / rr)) / FLATTENED)) / RAD;
|
|
776
|
+
lon[i] = longitude;
|
|
777
|
+
lat[i] = latitude;
|
|
778
|
+
alt[i] = (rr - 1) * 6371;
|
|
779
|
+
const px = v.width / 2 + wrapLongitude(longitude - v.centerLon) * k;
|
|
780
|
+
const py = v.height / 2 - (latitude - v.centerLat) * k;
|
|
781
|
+
if (py < -pad || py > v.height + pad || px < -pad || px > v.width + pad) {
|
|
782
|
+
// the world is wider than the box when the box is wide, and the dot may be in view at the other copy of the world
|
|
783
|
+
if (px < -pad && px + wrapPx <= v.width + pad && py >= -pad && py <= v.height + pad) {
|
|
784
|
+
sx[i] = px + wrapPx;
|
|
785
|
+
}
|
|
786
|
+
else if (px > v.width + pad && px - wrapPx >= -pad && py >= -pad && py <= v.height + pad) {
|
|
787
|
+
sx[i] = px - wrapPx;
|
|
788
|
+
}
|
|
789
|
+
else
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
else
|
|
793
|
+
sx[i] = px;
|
|
794
|
+
sy[i] = py;
|
|
795
|
+
on[i] = 1;
|
|
796
|
+
dots += 1;
|
|
797
|
+
const colour = byPlane ? (planeOf[i] >= 0 ? PLANE_COLOURS[planeOf[i] % PLANE_COLOURS.length] : SPARE_COLOUR) : g.colour;
|
|
798
|
+
const key = dimmed[i] > 0 ? `${colour}~` : colour;
|
|
799
|
+
let list = buckets.get(key);
|
|
800
|
+
if (!list)
|
|
801
|
+
buckets.set(key, (list = []));
|
|
802
|
+
list.push(sx[i], py);
|
|
803
|
+
// a dot on the map's edge is drawn again at the other side, so it wraps cleanly
|
|
804
|
+
if (sx[i] < pad && sx[i] + wrapPx < v.width + pad)
|
|
805
|
+
list.push(sx[i] + wrapPx, py);
|
|
806
|
+
else if (sx[i] > v.width - pad && sx[i] - wrapPx > -pad)
|
|
807
|
+
list.push(sx[i] - wrapPx, py);
|
|
808
|
+
if (streak && seg) {
|
|
809
|
+
// where it was a moment ago, on the same turn of the map as the dot
|
|
810
|
+
const j = i * 6;
|
|
811
|
+
const bx = seg[j];
|
|
812
|
+
const by = seg[j + 1];
|
|
813
|
+
const bz = seg[j + 2];
|
|
814
|
+
const br = Math.sqrt(bx * bx + by * by + bz * bz);
|
|
815
|
+
if (br > 0) {
|
|
816
|
+
const lon0 = (Math.atan2(-bz, bx) / RAD) - gmst;
|
|
817
|
+
const lat0 = Math.atan(Math.tan(Math.asin(by / br)) / FLATTENED) / RAD;
|
|
818
|
+
const x0 = sx[i] + wrapLongitude(lon0 - longitude) * k;
|
|
819
|
+
const y0 = v.height / 2 - (lat0 - v.centerLat) * k;
|
|
820
|
+
if (Math.abs(x0 - sx[i]) < streakPx * 2 && Math.abs(y0 - py) < streakPx * 2) {
|
|
821
|
+
let trail = streaks.get(colour);
|
|
822
|
+
if (!trail)
|
|
823
|
+
streaks.set(colour, (trail = []));
|
|
824
|
+
trail.push(x0, y0, sx[i], py);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
// the coverage circles and the track, under the dots
|
|
831
|
+
this.#drawOver(ctx, groups, ms);
|
|
832
|
+
if (streak) {
|
|
833
|
+
// a butt cap and a hairline for a crowd: thousands of round, wide strokes cost the rasteriser more than the whole of the rest of the draw
|
|
834
|
+
ctx.lineCap = "butt";
|
|
835
|
+
ctx.lineWidth = total > 3000 ? 1 : Math.max(1, radius * 1.4);
|
|
836
|
+
ctx.globalAlpha = 0.7;
|
|
837
|
+
for (const [colour, list] of streaks) {
|
|
838
|
+
if (list.length === 0)
|
|
839
|
+
continue;
|
|
840
|
+
ctx.strokeStyle = colour;
|
|
841
|
+
ctx.beginPath();
|
|
842
|
+
for (let j = 0; j < list.length; j += 4) {
|
|
843
|
+
ctx.moveTo(list[j], list[j + 1]);
|
|
844
|
+
ctx.lineTo(list[j + 2], list[j + 3]);
|
|
845
|
+
}
|
|
846
|
+
ctx.stroke();
|
|
847
|
+
}
|
|
848
|
+
ctx.globalAlpha = 1;
|
|
849
|
+
}
|
|
850
|
+
for (const [key, list] of buckets) {
|
|
851
|
+
if (list.length === 0)
|
|
852
|
+
continue;
|
|
853
|
+
const faint = key.endsWith("~");
|
|
854
|
+
ctx.fillStyle = faint ? key.slice(0, -1) : key;
|
|
855
|
+
ctx.globalAlpha = faint ? 0.45 : 1;
|
|
856
|
+
if (radius <= 1.7) {
|
|
857
|
+
const side = radius * 2;
|
|
858
|
+
for (let j = 0; j < list.length; j += 2)
|
|
859
|
+
ctx.fillRect(list[j] - radius, list[j + 1] - radius, side, side);
|
|
860
|
+
}
|
|
861
|
+
else {
|
|
862
|
+
ctx.beginPath();
|
|
863
|
+
for (let j = 0; j < list.length; j += 2) {
|
|
864
|
+
ctx.moveTo(list[j] + radius, list[j + 1]);
|
|
865
|
+
ctx.arc(list[j], list[j + 1], radius, 0, Math.PI * 2);
|
|
866
|
+
}
|
|
867
|
+
ctx.fill();
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
ctx.globalAlpha = 1;
|
|
871
|
+
this.#counts.draws += 1;
|
|
872
|
+
this.#counts.dots = dots;
|
|
873
|
+
this.#placeMarks();
|
|
874
|
+
this.#showMessage(dots, groups.length);
|
|
875
|
+
this.#jump = false;
|
|
876
|
+
this.#lastDraw = started;
|
|
877
|
+
const took = performance.now() - started;
|
|
878
|
+
this.#totalMs += took;
|
|
879
|
+
this.#counts.lastMs = took;
|
|
880
|
+
if (took > this.#counts.maxMs)
|
|
881
|
+
this.#counts.maxMs = took;
|
|
882
|
+
this.#announceView();
|
|
883
|
+
this.#announceTime();
|
|
884
|
+
this.#schedule();
|
|
885
|
+
}
|
|
886
|
+
/** The footprints and the ground track, drawn before the dots so the dots lie on them. */
|
|
887
|
+
#drawOver(ctx, groups, ms) {
|
|
888
|
+
const wantFootprint = this.#footprint;
|
|
889
|
+
const wantTrack = this.#track;
|
|
890
|
+
const chosen = this.#selected && this.#selected.g.on[this.#selected.i] === 1 ? this.#selected : null;
|
|
891
|
+
if (!wantFootprint && !(wantTrack && chosen))
|
|
892
|
+
return;
|
|
893
|
+
const path = geoPath(this.#projection(), ctx);
|
|
894
|
+
if (wantFootprint) {
|
|
895
|
+
const elevation = finite(this.getAttribute("footprint-elevation"), BEAM_ELEVATION);
|
|
896
|
+
const one = (g, i) => {
|
|
897
|
+
const angle = footprintAngle(g.alt[i], elevation) / RAD;
|
|
898
|
+
if (!(angle > 0))
|
|
899
|
+
return;
|
|
900
|
+
ctx.beginPath();
|
|
901
|
+
path(geoCircle().center([g.lon[i], g.lat[i]]).radius(angle).precision(3)());
|
|
902
|
+
ctx.fillStyle = "rgba(255,255,255,0.07)";
|
|
903
|
+
ctx.fill();
|
|
904
|
+
ctx.strokeStyle = "rgba(255,255,255,0.45)";
|
|
905
|
+
ctx.lineWidth = 1;
|
|
906
|
+
ctx.stroke();
|
|
907
|
+
};
|
|
908
|
+
if (chosen)
|
|
909
|
+
one(chosen.g, chosen.i);
|
|
910
|
+
else {
|
|
911
|
+
let shown = 0;
|
|
912
|
+
for (const g of groups)
|
|
913
|
+
shown += g.on.reduce((sum, flagged) => sum + flagged, 0);
|
|
914
|
+
if (shown <= FOOTPRINT_MAX)
|
|
915
|
+
for (const g of groups)
|
|
916
|
+
for (let i = 0; i < g.n; i += 1)
|
|
917
|
+
if (g.on[i] === 1)
|
|
918
|
+
one(g, i);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
if (wantTrack && chosen) {
|
|
922
|
+
const lines = this.#trackOf(chosen, ms);
|
|
923
|
+
if (lines) {
|
|
924
|
+
ctx.lineWidth = 1.6;
|
|
925
|
+
ctx.strokeStyle = "rgba(255,255,255,0.35)";
|
|
926
|
+
ctx.setLineDash([4, 4]);
|
|
927
|
+
ctx.beginPath();
|
|
928
|
+
path({ type: "LineString", coordinates: lines.past });
|
|
929
|
+
ctx.stroke();
|
|
930
|
+
ctx.setLineDash([]);
|
|
931
|
+
ctx.strokeStyle = "rgba(255,255,255,0.9)";
|
|
932
|
+
ctx.beginPath();
|
|
933
|
+
path({ type: "LineString", coordinates: lines.future });
|
|
934
|
+
ctx.stroke();
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
/** The ground track of the chosen satellite for one orbit, half behind it and half ahead, worked out again when the clock has moved a fortieth of an orbit. */
|
|
939
|
+
#trackOf(ref, ms) {
|
|
940
|
+
const set = ref.g.sats.sets[ref.i];
|
|
941
|
+
if (!set)
|
|
942
|
+
return null;
|
|
943
|
+
const shape = orbitShape(set.MEAN_MOTION, set.ECCENTRICITY);
|
|
944
|
+
if (!shape)
|
|
945
|
+
return null;
|
|
946
|
+
const period = shape.periodMinutes * 60_000;
|
|
947
|
+
// worked out again when the clock has moved a fortieth of an orbit, and, at a fast clock, once a (real) second: it would flicker if it were drawn for every frame
|
|
948
|
+
const every = Math.max(period / 40, this.#fast() ? Math.abs(this.#speed) * 1000 : 0);
|
|
949
|
+
const key = `${set.NORAD_CAT_ID}:${Math.round(ms / every)}`;
|
|
950
|
+
if (key !== this.#trackKey || !this.#trackLines) {
|
|
951
|
+
this.#trackKey = key;
|
|
952
|
+
const step = Math.max(5, period / 1000 / 160);
|
|
953
|
+
const points = groundTrack(set, ms - period / 2, ms + period / 2, step);
|
|
954
|
+
this.#trackLines = {
|
|
955
|
+
past: points.filter((p) => p.ms <= ms).map((p) => [p.lon, p.lat]),
|
|
956
|
+
future: points.filter((p) => p.ms >= ms).map((p) => [p.lon, p.lat]),
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
return this.#trackLines;
|
|
960
|
+
}
|
|
961
|
+
#announceView() {
|
|
962
|
+
const v = this.#view;
|
|
963
|
+
const key = `${v.centerLon.toFixed(2)},${v.centerLat.toFixed(2)},${v.zoom.toFixed(2)}`;
|
|
964
|
+
if (key === this.#viewSent)
|
|
965
|
+
return;
|
|
966
|
+
const first = this.#viewSent === "";
|
|
967
|
+
this.#viewSent = key;
|
|
968
|
+
if (!first)
|
|
969
|
+
this.dispatchEvent(new CustomEvent("chikyu-flat-view", { detail: { center: v.centerLon, zoom: v.zoom }, bubbles: true, composed: true }));
|
|
970
|
+
}
|
|
971
|
+
/** The rings round the chosen and the hovered satellite, and the name beside the one pointed at: a few DOM nodes moved, so they never ask for a draw of the dots. */
|
|
972
|
+
#placeMarks() {
|
|
973
|
+
const mark = (ring, ref) => {
|
|
974
|
+
if (!ring)
|
|
975
|
+
return null;
|
|
976
|
+
if (!ref || ref.g.on[ref.i] !== 1) {
|
|
977
|
+
ring.hidden = true;
|
|
978
|
+
return null;
|
|
979
|
+
}
|
|
980
|
+
const x = ref.g.sx[ref.i];
|
|
981
|
+
const y = ref.g.sy[ref.i];
|
|
982
|
+
ring.hidden = false;
|
|
983
|
+
ring.style.transform = `translate(${x.toFixed(1)}px,${y.toFixed(1)}px)`;
|
|
984
|
+
return { x, y };
|
|
985
|
+
};
|
|
986
|
+
const picked = this.#cursor ?? this.#selected;
|
|
987
|
+
const at = mark(this.#selRing, picked);
|
|
988
|
+
const over = mark(this.#hovRing, this.#hover && !sameRef(this.#hover, picked) ? this.#hover : null);
|
|
989
|
+
const tip = this.#tip;
|
|
990
|
+
if (!tip)
|
|
991
|
+
return;
|
|
992
|
+
const ref = this.#hover ?? picked;
|
|
993
|
+
const where = this.#hover ? (over ?? at) : at;
|
|
994
|
+
if (!ref || !where || ref.g.on[ref.i] !== 1) {
|
|
995
|
+
tip.hidden = true;
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
998
|
+
tip.hidden = false;
|
|
999
|
+
tip.textContent = this.#describe(ref);
|
|
1000
|
+
const wide = tip.offsetWidth;
|
|
1001
|
+
const left = where.x + 14 + wide > this.#view.width ? Math.max(0, where.x - 14 - wide) : where.x + 14;
|
|
1002
|
+
const top = Math.max(0, Math.min(this.#view.height - tip.offsetHeight, where.y - 10));
|
|
1003
|
+
tip.style.transform = `translate(${left.toFixed(1)}px,${top.toFixed(1)}px)`;
|
|
1004
|
+
}
|
|
1005
|
+
#nameOf(ref) {
|
|
1006
|
+
const set = ref.g.sats.sets[ref.i];
|
|
1007
|
+
return SHORT_NAMES[set.NORAD_CAT_ID]?.[this.language] ?? set.OBJECT_NAME;
|
|
1008
|
+
}
|
|
1009
|
+
#planeOfRef(ref) {
|
|
1010
|
+
const p = ref.g.clusters.planeOf[ref.i] ?? -1;
|
|
1011
|
+
return p >= 0 ? (ref.g.clusters.planes[p]?.id ?? null) : null;
|
|
1012
|
+
}
|
|
1013
|
+
#describe(ref) {
|
|
1014
|
+
const lang = this.language;
|
|
1015
|
+
const plane = this.#planeOfRef(ref);
|
|
1016
|
+
return say(lang, "announce", { name: this.#nameOf(ref), group: lang === "ja" ? ref.g.labelJa : ref.g.label, altitude: Math.round(ref.g.alt[ref.i]).toLocaleString(lang) }) + (plane && ref.g.clusters.clustered && this.#byPlane([ref.g]) ? say(lang, "announcePlane", { id: plane }) : "");
|
|
1017
|
+
}
|
|
1018
|
+
#showMessage(dots = -1, shown = this.#shownGroups().length) {
|
|
1019
|
+
const msg = this.#msg;
|
|
1020
|
+
if (!msg)
|
|
1021
|
+
return;
|
|
1022
|
+
const lang = this.language;
|
|
1023
|
+
if (this.#problem)
|
|
1024
|
+
msg.textContent = say(lang, "unreadable", { why: this.#problem });
|
|
1025
|
+
else if (this.#groups.size === 0)
|
|
1026
|
+
msg.textContent = say(lang, this.#waiting || this.hasAttribute("elements-src") ? "waiting" : "nothing");
|
|
1027
|
+
else
|
|
1028
|
+
msg.textContent = dots === 0 && shown > 0 ? say(lang, "nothing") : "";
|
|
1029
|
+
}
|
|
1030
|
+
// --- the controls ----------------------------------------------------------------------------------------------------------------------------
|
|
1031
|
+
#build(root) {
|
|
1032
|
+
const d = root.ownerDocument;
|
|
1033
|
+
const bar = Object.assign(d.createElement("div"), { className: "bar" });
|
|
1034
|
+
bar.addEventListener("click", this.#onBar);
|
|
1035
|
+
const stage = Object.assign(d.createElement("div"), { className: "stage" });
|
|
1036
|
+
const map = Object.assign(d.createElement("canvas"), { className: "map" });
|
|
1037
|
+
map.setAttribute("aria-hidden", "true");
|
|
1038
|
+
const dots = Object.assign(d.createElement("canvas"), { className: "dots", tabIndex: 0 });
|
|
1039
|
+
dots.setAttribute("role", "application");
|
|
1040
|
+
const selRing = Object.assign(d.createElement("div"), { className: "ring sel", hidden: true });
|
|
1041
|
+
const hovRing = Object.assign(d.createElement("div"), { className: "ring hov", hidden: true });
|
|
1042
|
+
const tip = Object.assign(d.createElement("div"), { className: "tip", hidden: true });
|
|
1043
|
+
tip.setAttribute("aria-hidden", "true");
|
|
1044
|
+
const msg = Object.assign(d.createElement("p"), { className: "msg" });
|
|
1045
|
+
msg.setAttribute("role", "status");
|
|
1046
|
+
const live = Object.assign(d.createElement("p"), { className: "sr", id: "live" });
|
|
1047
|
+
live.setAttribute("role", "status");
|
|
1048
|
+
live.setAttribute("aria-live", "polite");
|
|
1049
|
+
const help = Object.assign(d.createElement("p"), { className: "sr", id: "help" });
|
|
1050
|
+
dots.setAttribute("aria-describedby", "help live");
|
|
1051
|
+
stage.append(map, dots, selRing, hovRing, tip, msg);
|
|
1052
|
+
root.append(bar, stage, live, help);
|
|
1053
|
+
this.#bar = bar;
|
|
1054
|
+
this.#stage = stage;
|
|
1055
|
+
this.#mapCanvas = map;
|
|
1056
|
+
this.#dotCanvas = dots;
|
|
1057
|
+
this.#selRing = selRing;
|
|
1058
|
+
this.#hovRing = hovRing;
|
|
1059
|
+
this.#tip = tip;
|
|
1060
|
+
this.#msg = msg;
|
|
1061
|
+
this.#live = live;
|
|
1062
|
+
dots.addEventListener("pointerdown", this.#onDown);
|
|
1063
|
+
dots.addEventListener("pointermove", this.#onMove);
|
|
1064
|
+
dots.addEventListener("pointerup", this.#onUp);
|
|
1065
|
+
dots.addEventListener("pointercancel", this.#onCancel);
|
|
1066
|
+
dots.addEventListener("pointerleave", this.#onLeave);
|
|
1067
|
+
dots.addEventListener("wheel", this.#onWheel, { passive: false });
|
|
1068
|
+
dots.addEventListener("keydown", this.#onKey);
|
|
1069
|
+
dots.addEventListener("blur", () => {
|
|
1070
|
+
if (this.#cursor) {
|
|
1071
|
+
this.#cursor = null;
|
|
1072
|
+
this.#placeMarks();
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1075
|
+
}
|
|
1076
|
+
/** Which controls the `controls` attribute asks for. */
|
|
1077
|
+
#wants() {
|
|
1078
|
+
const raw = (this.getAttribute("controls") ?? "").trim().toLowerCase();
|
|
1079
|
+
if (raw === "none" || raw === "off")
|
|
1080
|
+
return new Set();
|
|
1081
|
+
const all = ["centre", "zoom", "footprint", "track", "chips"];
|
|
1082
|
+
if (raw === "" || raw === "all")
|
|
1083
|
+
return new Set(all);
|
|
1084
|
+
return new Set(raw.split(/[\s,]+/).map((one) => (one === "center" ? "centre" : one)));
|
|
1085
|
+
}
|
|
1086
|
+
/** The buttons and the filter chips, made again when the words, the groups, the planes or the home change. */
|
|
1087
|
+
#buildBar() {
|
|
1088
|
+
const bar = this.#bar;
|
|
1089
|
+
const dots = this.#dotCanvas;
|
|
1090
|
+
if (!bar || !dots)
|
|
1091
|
+
return;
|
|
1092
|
+
const lang = this.language;
|
|
1093
|
+
const wants = this.#wants();
|
|
1094
|
+
dots.setAttribute("aria-label", say(lang, "map"));
|
|
1095
|
+
this.shadowRoot.querySelector("#help").textContent = say(lang, "help");
|
|
1096
|
+
bar.setAttribute("role", "toolbar");
|
|
1097
|
+
bar.setAttribute("aria-label", say(lang, "controls"));
|
|
1098
|
+
const button = (act, label, extra = "") => `<button type="button" data-act="${act}"${extra}>${escape(label)}</button>`;
|
|
1099
|
+
const rows = [];
|
|
1100
|
+
const first = [];
|
|
1101
|
+
if (wants.has("centre")) {
|
|
1102
|
+
first.push(button("greenwich", say(lang, "greenwich"), ` aria-label="${escape(say(lang, "centreGreenwich"))}" aria-pressed="false"`));
|
|
1103
|
+
if (Number.isFinite(finite(this.getAttribute("home-lon"), Number.NaN)))
|
|
1104
|
+
first.push(button("home", say(lang, "myPlace"), ` aria-label="${escape(say(lang, "centreHome"))}" aria-pressed="false"`));
|
|
1105
|
+
}
|
|
1106
|
+
if (wants.has("zoom"))
|
|
1107
|
+
first.push(`<span class="gap"></span>`, button("zoomout", "−", ` aria-label="${escape(say(lang, "zoomOut"))}"`), button("zoomin", "+", ` aria-label="${escape(say(lang, "zoomIn"))}"`));
|
|
1108
|
+
else
|
|
1109
|
+
first.push(`<span class="gap"></span>`);
|
|
1110
|
+
if (wants.has("footprint"))
|
|
1111
|
+
first.push(button("footprint", say(lang, "footprint"), ` aria-pressed="false"`));
|
|
1112
|
+
if (wants.has("track"))
|
|
1113
|
+
first.push(button("track", say(lang, "groundTrack"), ` aria-pressed="false"`));
|
|
1114
|
+
if (first.length > 1)
|
|
1115
|
+
rows.push(`<div class="row">${first.join("")}</div>`);
|
|
1116
|
+
if (wants.has("chips")) {
|
|
1117
|
+
const groups = this.#shownGroupsForChips();
|
|
1118
|
+
const one = this.#shownGroups();
|
|
1119
|
+
if (groups === "planes" && one.length === 1) {
|
|
1120
|
+
const g = one[0];
|
|
1121
|
+
const chips = [button("plane", say(lang, "all"), ` class="chip" data-plane="" aria-pressed="false"`)];
|
|
1122
|
+
for (const plane of g.clusters.planes)
|
|
1123
|
+
chips.push(`<button type="button" class="chip" data-act="plane" data-plane="${plane.id}" data-i="${plane.index}" aria-pressed="false" aria-label="${escape(say(lang, "planeChip", { id: plane.id, count: plane.count }))}"><span class="swatch"></span>${escape(plane.id)} <span class="n">${plane.count}</span></button>`);
|
|
1124
|
+
rows.push(`<div class="row chips" role="group" aria-label="${escape(say(lang, "planesFilter"))}">${chips.join("")}</div>`);
|
|
1125
|
+
}
|
|
1126
|
+
else if (groups === "groups") {
|
|
1127
|
+
const chips = [`<button type="button" class="chip" data-act="group" data-group="*" aria-pressed="false">${escape(say(lang, "all"))}</button>`];
|
|
1128
|
+
for (const g of this.#groups.values())
|
|
1129
|
+
chips.push(`<button type="button" class="chip" data-act="group" data-group="${escape(g.id)}" aria-pressed="false"><span class="swatch"></span>${escape(lang === "ja" ? g.labelJa : g.label)} <span class="n">${g.n.toLocaleString(lang)}</span></button>`);
|
|
1130
|
+
rows.push(`<div class="row chips" role="group" aria-label="${escape(say(lang, "groupsFilter"))}">${chips.join("")}</div>`);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
bar.innerHTML = rows.join("");
|
|
1134
|
+
// colours go on through the CSS object model: an inline style attribute in the markup would be refused by a strict Content-Security-Policy
|
|
1135
|
+
bar.querySelectorAll("[data-group] .swatch").forEach((swatch) => {
|
|
1136
|
+
const id = swatch.parentElement.dataset["group"];
|
|
1137
|
+
swatch.style.setProperty("--c", this.#groups.get(id)?.colour ?? SPARE_COLOUR);
|
|
1138
|
+
});
|
|
1139
|
+
bar.querySelectorAll("[data-i] .swatch").forEach((swatch) => {
|
|
1140
|
+
const i = Number(swatch.parentElement.dataset["i"]);
|
|
1141
|
+
swatch.style.setProperty("--c", PLANE_COLOURS[i % PLANE_COLOURS.length]);
|
|
1142
|
+
});
|
|
1143
|
+
this.#sync();
|
|
1144
|
+
}
|
|
1145
|
+
/** Which chips to offer: planes when one group with planes is on show and the map is coloured by plane; groups when there are two or more loaded. */
|
|
1146
|
+
#shownGroupsForChips() {
|
|
1147
|
+
const shown = this.#shownGroups();
|
|
1148
|
+
if (this.#byPlane(shown) && shown.length === 1 && shown[0].clusters.clustered)
|
|
1149
|
+
return "planes";
|
|
1150
|
+
if (this.#groups.size >= 2)
|
|
1151
|
+
return "groups";
|
|
1152
|
+
return "none";
|
|
1153
|
+
}
|
|
1154
|
+
/** Bring the pressed states of the buttons and chips up to date without making them again (a reader may be using one). */
|
|
1155
|
+
#sync() {
|
|
1156
|
+
const bar = this.#bar;
|
|
1157
|
+
if (!bar)
|
|
1158
|
+
return;
|
|
1159
|
+
const set = (selector, on) => bar.querySelectorAll(selector).forEach((el) => el.setAttribute("aria-pressed", String(on)));
|
|
1160
|
+
const home = this.#home() ?? { lon: finite(this.getAttribute("home-lon"), Number.NaN), lat: 0 };
|
|
1161
|
+
set('[data-act="greenwich"]', Math.abs(wrapLongitude(this.#view.centerLon)) < 0.5);
|
|
1162
|
+
set('[data-act="home"]', Number.isFinite(home.lon) && Math.abs(wrapLongitude(this.#view.centerLon - home.lon)) < 0.5);
|
|
1163
|
+
set('[data-act="footprint"]', this.#footprint);
|
|
1164
|
+
set('[data-act="track"]', this.#track);
|
|
1165
|
+
const shown = this.#shownGroups();
|
|
1166
|
+
bar.querySelectorAll('[data-act="group"]').forEach((chip) => {
|
|
1167
|
+
const id = chip.dataset["group"];
|
|
1168
|
+
chip.setAttribute("aria-pressed", String(id === "*" ? this.#shown === null : shown.some((g) => g.id === id)));
|
|
1169
|
+
});
|
|
1170
|
+
bar.querySelectorAll('[data-act="plane"]').forEach((chip) => chip.setAttribute("aria-pressed", String((chip.dataset["plane"] ?? "") === this.#plane)));
|
|
1171
|
+
bar.querySelector('[data-act="zoomin"]')?.toggleAttribute("disabled", this.#view.zoom >= MAX_ZOOM);
|
|
1172
|
+
bar.querySelector('[data-act="zoomout"]')?.toggleAttribute("disabled", this.#view.zoom <= 1);
|
|
1173
|
+
if (this.#dotCanvas)
|
|
1174
|
+
this.#dotCanvas.toggleAttribute("data-zoomed", this.#view.zoom > 1);
|
|
1175
|
+
}
|
|
1176
|
+
#afterFilter() {
|
|
1177
|
+
this.#buildBar();
|
|
1178
|
+
this.#request();
|
|
1179
|
+
this.#schedule();
|
|
1180
|
+
this.dispatchEvent(new CustomEvent("chikyu-flat-filter", { detail: { groups: this.visibleGroups, plane: this.#plane }, bubbles: true, composed: true }));
|
|
1181
|
+
}
|
|
1182
|
+
#onBar = (event) => {
|
|
1183
|
+
const target = event.target?.closest("button[data-act]");
|
|
1184
|
+
if (!target || target.hasAttribute("disabled"))
|
|
1185
|
+
return;
|
|
1186
|
+
const act = target.dataset["act"];
|
|
1187
|
+
const v = this.#view;
|
|
1188
|
+
if (act === "greenwich")
|
|
1189
|
+
this.#setView({ ...v, centerLon: 0 });
|
|
1190
|
+
else if (act === "home") {
|
|
1191
|
+
const home = this.#home();
|
|
1192
|
+
const lon = finite(this.getAttribute("home-lon"), 0);
|
|
1193
|
+
this.#setView({ ...v, centerLon: lon, centerLat: v.zoom > 1 && home ? home.lat : v.centerLat });
|
|
1194
|
+
}
|
|
1195
|
+
else if (act === "zoomin")
|
|
1196
|
+
this.#setView(zoomAbout(v, 1.6));
|
|
1197
|
+
else if (act === "zoomout")
|
|
1198
|
+
this.#setView(zoomAbout(v, 1 / 1.6));
|
|
1199
|
+
else if (act === "footprint") {
|
|
1200
|
+
this.#footprint = !this.#footprint;
|
|
1201
|
+
this.#sync();
|
|
1202
|
+
this.#request();
|
|
1203
|
+
}
|
|
1204
|
+
else if (act === "track") {
|
|
1205
|
+
this.#track = !this.#track;
|
|
1206
|
+
this.#trackKey = "";
|
|
1207
|
+
this.#sync();
|
|
1208
|
+
this.#request();
|
|
1209
|
+
}
|
|
1210
|
+
else if (act === "group") {
|
|
1211
|
+
const id = target.dataset["group"];
|
|
1212
|
+
if (id === "*")
|
|
1213
|
+
this.#shown = null;
|
|
1214
|
+
else {
|
|
1215
|
+
const now = new Set(this.#shownGroups().map((g) => g.id));
|
|
1216
|
+
if (now.has(id))
|
|
1217
|
+
now.delete(id);
|
|
1218
|
+
else
|
|
1219
|
+
now.add(id);
|
|
1220
|
+
const usual = [...this.#groups.keys()].filter((one) => !this.#off.has(one));
|
|
1221
|
+
this.#shown = now.size === usual.length && usual.every((one) => now.has(one)) ? null : now;
|
|
1222
|
+
}
|
|
1223
|
+
this.#plane = "";
|
|
1224
|
+
this.#afterFilter();
|
|
1225
|
+
}
|
|
1226
|
+
else if (act === "plane") {
|
|
1227
|
+
this.#plane = target.dataset["plane"] ?? "";
|
|
1228
|
+
this.#afterFilter();
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1231
|
+
#setView(view) {
|
|
1232
|
+
this.#view = clampView(view);
|
|
1233
|
+
this.#mapKey = "";
|
|
1234
|
+
this.#sync();
|
|
1235
|
+
this.#request();
|
|
1236
|
+
}
|
|
1237
|
+
// --- the pointer and the keyboard ------------------------------------------------------------------------------------------------------------
|
|
1238
|
+
#local(event) {
|
|
1239
|
+
const box = this.#dotCanvas.getBoundingClientRect();
|
|
1240
|
+
return { x: event.clientX - box.left, y: event.clientY - box.top };
|
|
1241
|
+
}
|
|
1242
|
+
/** The satellite drawn nearest to a point, within `reach` pixels. */
|
|
1243
|
+
#hit(x, y, reach) {
|
|
1244
|
+
let best = null;
|
|
1245
|
+
let gap = reach * reach;
|
|
1246
|
+
for (const g of this.#shownGroups()) {
|
|
1247
|
+
const { sx, sy, on } = g;
|
|
1248
|
+
for (let i = 0; i < g.n; i += 1) {
|
|
1249
|
+
if (on[i] !== 1)
|
|
1250
|
+
continue;
|
|
1251
|
+
const dx = sx[i] - x;
|
|
1252
|
+
const dy = sy[i] - y;
|
|
1253
|
+
const d = dx * dx + dy * dy;
|
|
1254
|
+
if (d <= gap) {
|
|
1255
|
+
gap = d;
|
|
1256
|
+
best = { g, i };
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
return best;
|
|
1261
|
+
}
|
|
1262
|
+
#pick(ref, via) {
|
|
1263
|
+
const detail = ref
|
|
1264
|
+
? { id: ref.g.sats.sets[ref.i].NORAD_CAT_ID, index: ref.i, group: ref.g.id, name: this.#nameOf(ref), plane: this.#planeOfRef(ref), altitudeKm: ref.g.alt[ref.i], via }
|
|
1265
|
+
: { id: null, index: -1, group: null, name: null, plane: null, altitudeKm: null, via };
|
|
1266
|
+
this.dispatchEvent(new CustomEvent("chikyu-flat-pick", { detail, bubbles: true, composed: true }));
|
|
1267
|
+
}
|
|
1268
|
+
#choose(ref, via) {
|
|
1269
|
+
const same = sameRef(ref, this.#selected);
|
|
1270
|
+
if (ref === null && this.#selected === null)
|
|
1271
|
+
return;
|
|
1272
|
+
if (!same) {
|
|
1273
|
+
this.#selected = ref;
|
|
1274
|
+
this.#trackKey = "";
|
|
1275
|
+
if (this.#footprint || this.#track)
|
|
1276
|
+
this.#request();
|
|
1277
|
+
}
|
|
1278
|
+
this.#sync();
|
|
1279
|
+
this.#placeMarks();
|
|
1280
|
+
if (ref) {
|
|
1281
|
+
this.#announceLive(ref);
|
|
1282
|
+
this.#pick(ref, via);
|
|
1283
|
+
}
|
|
1284
|
+
else if (!same)
|
|
1285
|
+
this.#pick(null, via);
|
|
1286
|
+
}
|
|
1287
|
+
#announceLive(ref) {
|
|
1288
|
+
if (this.#live)
|
|
1289
|
+
this.#live.textContent = this.#describe(ref);
|
|
1290
|
+
}
|
|
1291
|
+
#onDown = (event) => {
|
|
1292
|
+
if (event.pointerType === "mouse" && event.button !== 0)
|
|
1293
|
+
return;
|
|
1294
|
+
const at = this.#local(event);
|
|
1295
|
+
this.#pointers.set(event.pointerId, at);
|
|
1296
|
+
try {
|
|
1297
|
+
this.#dotCanvas.setPointerCapture(event.pointerId);
|
|
1298
|
+
}
|
|
1299
|
+
catch {
|
|
1300
|
+
// a pointer that is already gone
|
|
1301
|
+
}
|
|
1302
|
+
const pinch = this.#pointers.size === 2 ? this.#spread() : 0;
|
|
1303
|
+
this.#drag = { x: at.x, y: at.y, moved: this.#pointers.size === 2, pinch };
|
|
1304
|
+
this.#dotCanvas.style.cursor = "grabbing";
|
|
1305
|
+
};
|
|
1306
|
+
#spread() {
|
|
1307
|
+
const [a, b] = [...this.#pointers.values()];
|
|
1308
|
+
return a && b ? Math.hypot(a.x - b.x, a.y - b.y) : 0;
|
|
1309
|
+
}
|
|
1310
|
+
#onMove = (event) => {
|
|
1311
|
+
const at = this.#local(event);
|
|
1312
|
+
if (!this.#pointers.has(event.pointerId)) {
|
|
1313
|
+
// a pointer going over the map with no button down: the one under it is named
|
|
1314
|
+
if (event.pointerType === "mouse")
|
|
1315
|
+
this.#hoverAt(at.x, at.y);
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
const before = this.#pointers.get(event.pointerId);
|
|
1319
|
+
this.#pointers.set(event.pointerId, at);
|
|
1320
|
+
const drag = this.#drag;
|
|
1321
|
+
if (!drag)
|
|
1322
|
+
return;
|
|
1323
|
+
if (this.#pointers.size >= 2) {
|
|
1324
|
+
const spread = this.#spread();
|
|
1325
|
+
const [a, b] = [...this.#pointers.values()];
|
|
1326
|
+
if (drag.pinch > 0 && spread > 0 && a && b) {
|
|
1327
|
+
const factor = spread / drag.pinch;
|
|
1328
|
+
this.#view = zoomAbout(this.#view, factor, (a.x + b.x) / 2, (a.y + b.y) / 2);
|
|
1329
|
+
drag.pinch = spread;
|
|
1330
|
+
drag.moved = true;
|
|
1331
|
+
this.#mapKey = "";
|
|
1332
|
+
this.#sync();
|
|
1333
|
+
this.#request();
|
|
1334
|
+
}
|
|
1335
|
+
return;
|
|
1336
|
+
}
|
|
1337
|
+
if (!drag.moved && Math.hypot(at.x - drag.x, at.y - drag.y) < TAP_SLOP)
|
|
1338
|
+
return;
|
|
1339
|
+
drag.moved = true;
|
|
1340
|
+
const k = pixelsPerDegree(this.#view);
|
|
1341
|
+
this.#view = clampView({ ...this.#view, centerLon: this.#view.centerLon - (at.x - before.x) / k, centerLat: this.#view.centerLat + (at.y - before.y) / k });
|
|
1342
|
+
this.#hover = null;
|
|
1343
|
+
this.#sync();
|
|
1344
|
+
this.#request();
|
|
1345
|
+
};
|
|
1346
|
+
#onUp = (event) => {
|
|
1347
|
+
const at = this.#local(event);
|
|
1348
|
+
const drag = this.#drag;
|
|
1349
|
+
this.#pointers.delete(event.pointerId);
|
|
1350
|
+
try {
|
|
1351
|
+
this.#dotCanvas.releasePointerCapture(event.pointerId);
|
|
1352
|
+
}
|
|
1353
|
+
catch {
|
|
1354
|
+
// already released
|
|
1355
|
+
}
|
|
1356
|
+
if (this.#pointers.size === 0) {
|
|
1357
|
+
this.#drag = null;
|
|
1358
|
+
this.#dotCanvas.style.cursor = "";
|
|
1359
|
+
if (drag && !drag.moved) {
|
|
1360
|
+
// a tap: a finger needs more room than a mouse
|
|
1361
|
+
const hit = this.#hit(at.x, at.y, event.pointerType === "touch" ? 22 : 9);
|
|
1362
|
+
if (event.pointerType !== "mouse")
|
|
1363
|
+
this.#hover = null;
|
|
1364
|
+
this.#choose(hit, "tap");
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
else if (drag)
|
|
1368
|
+
drag.pinch = this.#spread();
|
|
1369
|
+
};
|
|
1370
|
+
#onCancel = (event) => {
|
|
1371
|
+
this.#pointers.delete(event.pointerId);
|
|
1372
|
+
if (this.#pointers.size === 0) {
|
|
1373
|
+
this.#drag = null;
|
|
1374
|
+
this.#dotCanvas.style.cursor = "";
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
#onLeave = (event) => {
|
|
1378
|
+
if (event.pointerType !== "mouse" || this.#hover === null)
|
|
1379
|
+
return;
|
|
1380
|
+
this.#hover = null;
|
|
1381
|
+
this.#placeMarks();
|
|
1382
|
+
};
|
|
1383
|
+
#hoverAt(x, y) {
|
|
1384
|
+
const hit = this.#hit(x, y, 8);
|
|
1385
|
+
if (sameRef(hit, this.#hover))
|
|
1386
|
+
return;
|
|
1387
|
+
this.#hover = hit;
|
|
1388
|
+
this.#placeMarks();
|
|
1389
|
+
if (hit)
|
|
1390
|
+
this.#pick(hit, "hover");
|
|
1391
|
+
}
|
|
1392
|
+
#onWheel = (event) => {
|
|
1393
|
+
// a plain wheel scrolls the page; Control or Command with the wheel (and a trackpad's pinch, which arrives as one) zooms
|
|
1394
|
+
if (!event.ctrlKey && !event.metaKey)
|
|
1395
|
+
return;
|
|
1396
|
+
event.preventDefault();
|
|
1397
|
+
const at = this.#local(event);
|
|
1398
|
+
this.#setView(zoomAbout(this.#view, Math.exp(-event.deltaY * 0.01), at.x, at.y));
|
|
1399
|
+
};
|
|
1400
|
+
#onKey = (event) => {
|
|
1401
|
+
const key = event.key;
|
|
1402
|
+
if (key === "+" || key === "=") {
|
|
1403
|
+
event.preventDefault();
|
|
1404
|
+
this.#setView(zoomAbout(this.#view, 1.6));
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1407
|
+
if (key === "-" || key === "_") {
|
|
1408
|
+
event.preventDefault();
|
|
1409
|
+
this.#setView(zoomAbout(this.#view, 1 / 1.6));
|
|
1410
|
+
return;
|
|
1411
|
+
}
|
|
1412
|
+
if (key === "Escape") {
|
|
1413
|
+
if (this.#cursor || this.#selected) {
|
|
1414
|
+
this.#cursor = null;
|
|
1415
|
+
this.#choose(null, "key");
|
|
1416
|
+
}
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
if (key === "Enter" || key === " ") {
|
|
1420
|
+
event.preventDefault();
|
|
1421
|
+
const ref = this.#cursor ?? this.#selected;
|
|
1422
|
+
if (ref)
|
|
1423
|
+
this.#choose(ref, "key");
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1426
|
+
const step = key === "ArrowRight" || key === "ArrowDown" ? 1 : key === "ArrowLeft" || key === "ArrowUp" ? -1 : key === "PageDown" ? 10 : key === "PageUp" ? -10 : 0;
|
|
1427
|
+
if (step === 0 && key !== "Home" && key !== "End")
|
|
1428
|
+
return;
|
|
1429
|
+
event.preventDefault();
|
|
1430
|
+
// the satellites on show, from the left of the map to the right
|
|
1431
|
+
const list = [];
|
|
1432
|
+
for (const g of this.#shownGroups())
|
|
1433
|
+
for (let i = 0; i < g.n; i += 1)
|
|
1434
|
+
if (g.on[i] === 1)
|
|
1435
|
+
list.push({ g, i });
|
|
1436
|
+
if (list.length === 0)
|
|
1437
|
+
return;
|
|
1438
|
+
list.sort((a, b) => a.g.sx[a.i] - b.g.sx[b.i] || a.g.sy[a.i] - b.g.sy[b.i]);
|
|
1439
|
+
const current = this.#cursor ?? this.#selected;
|
|
1440
|
+
const at = current ? list.findIndex((one) => one.g === current.g && one.i === current.i) : -1;
|
|
1441
|
+
const next = key === "Home" ? 0 : key === "End" ? list.length - 1 : at < 0 ? (step > 0 ? 0 : list.length - 1) : Math.max(0, Math.min(list.length - 1, at + step));
|
|
1442
|
+
this.#cursor = list[next];
|
|
1443
|
+
this.#placeMarks();
|
|
1444
|
+
this.#announceLive(this.#cursor);
|
|
1445
|
+
this.#pick(this.#cursor, "key");
|
|
1446
|
+
};
|
|
1447
|
+
/** Choose a satellite from code, as a reader's tap would, without sending `chikyu-flat-pick`. A NORAD number the groups do not hold, or `null`, clears the choice. */
|
|
1448
|
+
pick(id) {
|
|
1449
|
+
this.selected = id;
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
_a = ChikyuFlat;
|