@johnmorrisdotca/chikyu-earth 0.66.0 → 0.68.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.
@@ -6,6 +6,8 @@ import { adoptStyles } from "../adopt.js";
6
6
  import { footprintAngle, BEAM_ELEVATION } from "../beam/geometry.js";
7
7
  import { orbitShape } from "../catalogue/orbit.js";
8
8
  import { COUNTRIES } from "../countries.js";
9
+ import { creditLine } from "../data-door.js";
10
+ import { ownCredit } from "../door/own.js";
9
11
  import { groundTrack } from "../passes/passes.js";
10
12
  import { subsolarPoint, greenwichSidereal } from "../realistic/sun.js";
11
13
  import { SATELLITE_GROUPS } from "../satellites/catalogue.js";
@@ -17,6 +19,9 @@ import { GROUP_COLOURS, PLANE_COLOURS, SPARE_COLOUR, TRACK_SHADOW, TRACK_SUNLIT
17
19
  import { clusterPlanes, groupFacts } from "./facts.js";
18
20
  import { FLATTENED, MAX_ZOOM, clampView, pixelsPerDegree, projectFlat, wrapLongitude, zoomAbout } from "./geometry.js";
19
21
  import { trackStateOfScene } from "./track-state.js";
22
+ import { airportLine, placeAirports } from "./airports.js";
23
+ import { pointText, placeOver } from "./marks.js";
24
+ import { PhotoPictures, paintPhoto, readLook } from "./photo.js";
20
25
  import { say } from "./words.js";
21
26
  const RAD = Math.PI / 180;
22
27
  /** The most satellites whose footprints are drawn at once when none is chosen. */
@@ -70,11 +75,14 @@ const CSS = `
70
75
  .chips>*{flex:none}
71
76
  @container (min-width:600px){.chips{flex-wrap:wrap;overflow:visible}}
72
77
  .gap{flex:1 1 0}
73
- 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}
78
+ .pair{display:inline-flex;gap:0}
79
+ .pair button:first-child{border-radius:var(--chikyu-flat-button-radius,999px) 0 0 var(--chikyu-flat-button-radius,999px)}
80
+ .pair button:last-child{border-radius:0 var(--chikyu-flat-button-radius,999px) var(--chikyu-flat-button-radius,999px) 0;margin-left:-1px}
81
+ button{font:inherit;color:inherit;background:transparent;border:var(--chikyu-flat-button-border,1px solid color-mix(in srgb,currentColor 35%,transparent));border-radius:var(--chikyu-flat-button-radius,999px);padding:var(--chikyu-flat-button-padding,3px 12px);min-height:var(--chikyu-flat-button-min-height,32px);cursor:pointer;display:inline-flex;align-items:center;gap:6px}
74
82
  button[aria-pressed="true"]{background:color-mix(in srgb,currentColor 14%,transparent);border-color:currentColor}
75
83
  button:disabled{opacity:.45;cursor:default}
76
84
  button:focus-visible{outline:3px solid #6cd0ff;outline-offset:2px}
77
- @media (pointer:coarse){button{min-height:44px;padding:6px 14px}}
85
+ @media (pointer:coarse){button{min-height:var(--chikyu-flat-button-min-height,44px);padding:var(--chikyu-flat-button-padding,6px 14px)}}
78
86
  .chip .swatch{width:10px;height:10px;border-radius:50%;background:var(--c,#9aa5b1);flex:none}
79
87
  .chip .n{opacity:.7;font-variant-numeric:tabular-nums;font-size:.85em}
80
88
  .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)}
@@ -86,11 +94,40 @@ canvas{position:absolute;inset:0;width:100%;height:100%;display:block}
86
94
  .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}
87
95
  .ring.hov{width:14px;height:14px;margin:-7px 0 0 -7px;border-width:1px}
88
96
  .ring[hidden],.tip[hidden]{display:none}
89
- .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)}
90
- .key{position:absolute;left:8px;bottom:8px;display:flex;flex-wrap:wrap;gap:4px 12px;margin:0;padding:3px 8px;border-radius:6px;background:rgba(8,14,28,.82);color:#fff;font-size:.8em;line-height:1.3;pointer-events:none;max-width:calc(100% - 16px)}
97
+ .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:var(--chikyu-flat-tip-font-size,.85em);line-height:1.3;white-space:nowrap;border:1px solid rgba(255,255,255,.3)}
98
+ .key{position:absolute;left:8px;bottom:8px;display:flex;flex-wrap:wrap;gap:4px 12px;margin:0;padding:3px 8px;border-radius:6px;background:rgba(8,14,28,.82);color:#fff;font-size:var(--chikyu-flat-key-font-size,.8em);line-height:1.3;pointer-events:none;max-width:calc(100% - 16px)}
91
99
  .key[hidden]{display:none}
92
100
  .key span{display:inline-flex;align-items:center;gap:6px}
93
101
  .key i{display:inline-block;width:18px;height:0;border-top:3px solid var(--k,#fff);border-radius:2px;box-shadow:0 0 0 1px rgba(0,0,0,.55)}
102
+ button.mark{position:absolute;left:0;top:0;width:26px;height:26px;min-height:0;margin:-13px 0 0 -13px;padding:0;border:0;border-radius:50%;background:transparent;pointer-events:none}
103
+ button.mark[hidden]{display:none}
104
+ button.mark:focus-visible{outline:3px solid #6cd0ff;outline-offset:0}
105
+ .legend{font-size:var(--chikyu-flat-key-font-size,.85em);line-height:1.3;padding-left:var(--chikyu-flat-key-inset,0)}
106
+ .legend[hidden],.legend ul[hidden]{display:none}
107
+ .legend button{min-height:var(--chikyu-flat-button-min-height,28px);padding:var(--chikyu-flat-button-padding,1px 10px);font-size:inherit}
108
+ @media (pointer:coarse){.legend button{min-height:var(--chikyu-flat-button-min-height,40px)}}
109
+ .legend ul{list-style:none;margin:6px 0 0;padding:0;display:flex;flex-wrap:wrap;gap:6px 16px}
110
+ .legend li{display:inline-flex;align-items:center;gap:6px}
111
+ .g{display:inline-flex;align-items:center;justify-content:center;gap:2px;flex:none;width:30px;height:20px;border-radius:4px;background:var(--chikyu-flat-sea,#0b1830)}
112
+ .g i{display:block;width:7px;height:7px;border-radius:50%;background:var(--c,#9aa5b1)}
113
+ .g.sun::before{content:"";width:10px;height:10px;border-radius:50%;background:#ffd54f;box-shadow:0 0 0 1px rgba(0,0,0,.55)}
114
+ .g.home::before{content:"";width:8px;height:8px;background:#fff;box-shadow:0 0 0 2px #0b1830;transform:rotate(45deg)}
115
+ .g.sat i{width:6px;height:6px}
116
+ .g.airport::before{content:"";width:8px;height:8px;box-sizing:border-box;border-radius:50%;background:#fff;box-shadow:0 0 0 1.5px #040812}
117
+ .g.faint::before{content:"";width:7px;height:7px;border-radius:50%;background:#9aa5b1;opacity:.45}
118
+ .g.chosen::before{content:"";width:12px;height:12px;box-sizing:border-box;border:2px solid #fff;border-radius:50%;box-shadow:0 0 0 1px #000}
119
+ .g.footprint::before{content:"";width:16px;height:16px;box-sizing:border-box;border:1px solid rgba(255,255,255,.8);border-radius:50%;background:rgba(255,255,255,.12)}
120
+ .g.line i{width:20px;height:0;border-radius:2px;background:none;border-top:3px solid var(--c)}
121
+ .g.nasa::before{content:"NASA";font-size:.6em;letter-spacing:.04em;color:#fff}
122
+ .g.day{background:linear-gradient(90deg,#4a73a8,#8fb4e6)}
123
+ .g.night{background:linear-gradient(90deg,#1b2f4d,#030812)}
124
+ .g.night-photo{background:radial-gradient(circle at 70% 55%,#ffd98a 0 1px,transparent 2px),radial-gradient(circle at 40% 40%,#ffe9b8 0 1px,transparent 2px),linear-gradient(90deg,#41648f,#02060f)}
125
+ button.credit{position:absolute;right:8px;bottom:8px;display:block;margin:0;padding:2px 8px;min-height:0;border:0;border-radius:6px;background:rgba(8,14,28,.72);color:#fff;font-size:.7em;line-height:1.3;max-width:calc(100% - 16px);text-align:right;cursor:pointer}
126
+ button.credit .full,button.credit[data-open] .short{display:none}
127
+ button.credit[data-open] .full{display:inline}
128
+ @container (min-width:600px){button.credit{cursor:default}button.credit .short{display:none}button.credit .full{display:inline}}
129
+ @media (pointer:coarse){button.credit{min-height:28px;padding:4px 10px}}
130
+ .credit[hidden]{display:none}
94
131
  .msg{position:absolute;inset:0;display:grid;place-items:center;margin:0;padding:12px;text-align:center;color:#cfe0f5;pointer-events:none}
95
132
  .msg:empty{display:none}
96
133
  .sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
@@ -102,11 +139,13 @@ canvas{position:absolute;inset:0;width:100%;height:100%;display:block}
102
139
  * 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),
103
140
  * `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, which is amber in sunlight and blue in the Earth's shadow, a cylinder, with a key: `--chikyu-flat-track-sun` and `--chikyu-flat-track-shadow` change the colours; the footprint is of the chosen satellite, or of every one shown when there are 80 or fewer),
104
141
  * `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` (`steady` keeps each satellite's usual orbit beyond 30 days from its elements), `shade` (`off` for no night),
105
- * `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).
142
+ * `dot-size` (pixels), `controls` (`none`, or any of `centre zoom footprint track chips key look`: the built-in buttons, filter chips, key and Map / Photo pair shown; all but `look` by default) and `lang` (`en` or `ja`; the page's language by default).
143
+ * `look` is `map` (the drawn map, the default) or `photo` (NASA's picture of the Earth, with the night side's city lights; `borders="off"` leaves out the country lines, `texture-base` and `max-texture` are as on the realistic Earth; the pictures are fetched only while it is on, and `lookState` says how it stands).
144
+ * The key under the map names every mark the map draws (`keyOpen` folds it open or shut: open on a wide map, shut on a phone until asked), and the yellow dot (the Sun overhead) and the white diamond (My place) name themselves, with where, when pointed at, pressed or reached with the Tab key.
106
145
  *
107
146
  * 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 }`),
108
- * `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).
109
- * 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`.
147
+ * `chikyu-flat-planes` (the planes were worked out: `{ planes }`), `chikyu-flat-view` (the reader panned or zoomed: `{ center, zoom }`), `chikyu-flat-look` (the look or how it stands changed: `{ look, state }`), `chikyu-flat-mark` (the Sun's dot or the home diamond was pressed: `{ mark, name, text, lon, lat, place, via }`) and `chikyu-timechange` (`{ time, running }`, at most four a second while time runs).
148
+ * Style it with the shadow parts `button` (every button and chip), `tip`, `key` and `msg` (`chikyu-flat::part(button) { … }`) and the custom properties `--chikyu-flat-button-radius`, `--chikyu-flat-button-padding`, `--chikyu-flat-button-min-height`, `--chikyu-flat-button-border`, `--chikyu-flat-tip-font-size`, `--chikyu-flat-key-font-size`, `--chikyu-flat-key-inset` (room kept at the left of the key, for a card lying over the map's left side), `--chikyu-flat-sea`, `--chikyu-flat-land`, `--chikyu-flat-line`, `--chikyu-flat-night`, `--chikyu-flat-day`, `--chikyu-flat-terminator`, `--chikyu-flat-aspect`, `--chikyu-flat-aspect-narrow` and `--chikyu-flat-radius`.
110
149
  *
111
150
  * @example
112
151
  * ```ts no-run
@@ -124,7 +163,7 @@ canvas{position:absolute;inset:0;width:100%;height:100%;display:block}
124
163
  * ```
125
164
  */
126
165
  export class ChikyuFlat extends HTMLElement {
127
- 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"];
166
+ 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", "look", "borders", "texture-base", "max-texture", "airports"];
128
167
  #groups = new Map();
129
168
  #index = new Map();
130
169
  #shown = null;
@@ -159,6 +198,28 @@ export class ChikyuFlat extends HTMLElement {
159
198
  #viewSent = "";
160
199
  #announced = -Infinity;
161
200
  #mapKey = "";
201
+ #look = "map";
202
+ /** The colour of the line of sunrise and sunset as the last draw of the map read it, for the key. */
203
+ #terminatorColour = "#ffc46e";
204
+ #photo = null;
205
+ #photoFailed = false;
206
+ #lookSent = "";
207
+ #markAt = { sun: null, home: null };
208
+ #markHover = null;
209
+ #markShown = null;
210
+ #markNames = new Map();
211
+ #markButtons = { sun: undefined, home: undefined };
212
+ #legend;
213
+ #legendKey = "";
214
+ #legendOpen = null;
215
+ #faint = false;
216
+ /** The airports are asked for (`airports`), the rows once they are loaded (a chunk fetched only then), the ones drawn at the last draw of the map, and the one pointed at or pressed. */
217
+ #airports = false;
218
+ #airportRows = null;
219
+ #airportAt = [];
220
+ #airportHover = null;
221
+ #airportShown = null;
222
+ #credit;
162
223
  #trackKey = "";
163
224
  #trackLines = null;
164
225
  #key;
@@ -349,6 +410,19 @@ export class ChikyuFlat extends HTMLElement {
349
410
  get language() {
350
411
  return (this.getAttribute("lang") ?? this.ownerDocument.documentElement.lang ?? "en").toLowerCase().startsWith("ja") ? "ja" : "en";
351
412
  }
413
+ /** The look of the map: `map`, the drawn map of countries (the default), or `photo`, NASA's picture of the Earth with the night side's city lights. The `look` attribute; the pictures are fetched only while the look is `photo`. */
414
+ get look() {
415
+ return this.#look;
416
+ }
417
+ set look(value) {
418
+ this.setAttribute("look", readLook(value));
419
+ }
420
+ /** How the look stands: `map` (the drawn map is chosen), `loading` (the photo is chosen and its picture is on its way, the drawn map shows meanwhile), `photo` (the photo is shown) or `failed` (the picture could not be fetched, the drawn map shows). `chikyu-flat-look` tells the page when it changes. */
421
+ get lookState() {
422
+ if (this.#look === "map")
423
+ return "map";
424
+ return this.#photoFailed ? "failed" : this.#photo?.day ? "photo" : "loading";
425
+ }
352
426
  /** 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. */
353
427
  get stats() {
354
428
  const canvases = [this.#mapCanvas, this.#dotCanvas].filter((c) => c !== undefined).map((c) => ({ width: c.width, height: c.height }));
@@ -402,6 +476,9 @@ export class ChikyuFlat extends HTMLElement {
402
476
  this.#sizer = undefined;
403
477
  this.#watcher = undefined;
404
478
  document.removeEventListener("visibilitychange", this.#onVisibility);
479
+ // the pictures are let go with the element, and fetched again if it comes back
480
+ this.#photo?.dispose();
481
+ this.#photo = null;
405
482
  }
406
483
  attributeChangedCallback(name) {
407
484
  if (!this.#connected)
@@ -409,6 +486,10 @@ export class ChikyuFlat extends HTMLElement {
409
486
  this.#read(name);
410
487
  if (name === "selected" || name === "footprint-elevation")
411
488
  this.#trackKey = "";
489
+ if (name === "lang") {
490
+ this.#showCredit();
491
+ this.#placeMarkButtons();
492
+ }
412
493
  if (name === "lang" || name === "controls" || name === "group" || name === "colour-by" || name === "color-by" || name === "home-lon" || name === "home-lat" || name === "plane")
413
494
  this.#buildBar();
414
495
  this.#sync();
@@ -457,6 +538,8 @@ export class ChikyuFlat extends HTMLElement {
457
538
  this.#plane = (value ?? "").trim().toUpperCase();
458
539
  else if (name === "footprint")
459
540
  this.#footprint = flag(value);
541
+ else if (name === "airports")
542
+ this.#setAirports(flag(value));
460
543
  else if (name === "track")
461
544
  this.#track = flag(value);
462
545
  else if (name === "selected") {
@@ -474,8 +557,89 @@ export class ChikyuFlat extends HTMLElement {
474
557
  g.sats.estimateFar = estimateFarOf(value);
475
558
  else if (name === "elements-src")
476
559
  this.#load();
477
- else if (name === "shade" || name === "dot-size")
560
+ else if (name === "look")
561
+ this.#setLook(readLook(value));
562
+ else if (name === "texture-base" && this.#photo) {
563
+ this.#photo.dispose();
564
+ this.#photo = this.#makePhoto();
478
565
  this.#mapKey = "";
566
+ }
567
+ else if (name === "shade" || name === "dot-size" || name === "borders" || name === "max-texture")
568
+ this.#mapKey = "";
569
+ }
570
+ /** Where the pictures are served from: the `texture-base` attribute, else the package's own `textures/` folder beside this file, as for the realistic Earth. */
571
+ #textureBase() {
572
+ const base = this.getAttribute("texture-base") ?? new URL("../textures/", import.meta.url).href;
573
+ return base.endsWith("/") ? base : `${base}/`;
574
+ }
575
+ /** The widest picture to hold: the `max-texture` attribute, 4096 at most, and 2048 on a device that reports 2 GB of memory or less. */
576
+ #textureCap() {
577
+ const given = Number(this.getAttribute("max-texture"));
578
+ const memory = navigator.deviceMemory;
579
+ const cap = Number.isFinite(given) && given > 0 ? Math.min(given, 4096) : 4096;
580
+ return memory !== undefined && memory <= 2 ? Math.min(cap, 2048) : cap;
581
+ }
582
+ #makePhoto() {
583
+ const again = () => {
584
+ this.#mapKey = "";
585
+ this.#request();
586
+ this.#announceLook();
587
+ };
588
+ return new PhotoPictures({
589
+ base: () => this.#textureBase(),
590
+ cap: () => this.#textureCap(),
591
+ changed: again,
592
+ failed: () => {
593
+ this.#photoFailed = true;
594
+ again();
595
+ },
596
+ });
597
+ }
598
+ #setLook(look) {
599
+ if (look === this.#look && (look === "map" || this.#photo))
600
+ return;
601
+ this.#look = look;
602
+ this.#photoFailed = false;
603
+ this.#photo?.dispose();
604
+ this.#photo = look === "photo" ? this.#makePhoto() : null;
605
+ this.#mapKey = "";
606
+ this.#showCredit();
607
+ this.#announceLook();
608
+ }
609
+ /** `chikyu-flat-look`, when the look or how it stands changes. */
610
+ #announceLook() {
611
+ const state = this.lookState;
612
+ const key = `${this.#look}/${state}`;
613
+ this.#showCredit();
614
+ if (key === this.#lookSent)
615
+ return;
616
+ const first = this.#lookSent === "";
617
+ this.#lookSent = key;
618
+ if (!first)
619
+ this.dispatchEvent(new CustomEvent("chikyu-flat-look", { detail: { look: this.#look, state }, bubbles: true, composed: true }));
620
+ }
621
+ /** NASA's credit, at the map's bottom edge while the photo is shown: the whole line on a wide map, "Earth: NASA" on a narrow one with the whole line a tap away (and in the key). */
622
+ #showCredit() {
623
+ const credit = this.#credit;
624
+ if (!credit)
625
+ return;
626
+ const on = this.#look === "photo" && this.#photo?.day != null;
627
+ credit.hidden = !on;
628
+ if (!on)
629
+ return;
630
+ const lang = this.language;
631
+ const line = this.#creditText();
632
+ const [short, full] = credit.children;
633
+ if (full.textContent !== line)
634
+ full.textContent = line;
635
+ short.textContent = say(lang, "creditShort");
636
+ credit.setAttribute("aria-label", line);
637
+ credit.title = line;
638
+ credit.lang = lang;
639
+ }
640
+ /** The whole credit line of the pictures, in the page's language. */
641
+ #creditText() {
642
+ return creditLine([ownCredit("chikyu-pictures", 1)], this.language);
479
643
  }
480
644
  #readClock() {
481
645
  this.#advance(performance.now());
@@ -617,6 +781,7 @@ export class ChikyuFlat extends HTMLElement {
617
781
  return;
618
782
  this.#dpr = dpr;
619
783
  this.#view = clampView({ ...this.#view, width, height });
784
+ this.#syncLegend();
620
785
  for (const canvas of [this.#mapCanvas, this.#dotCanvas]) {
621
786
  if (!canvas)
622
787
  continue;
@@ -628,7 +793,7 @@ export class ChikyuFlat extends HTMLElement {
628
793
  #colours() {
629
794
  const style = getComputedStyle(this);
630
795
  const pick = (name, fallback) => style.getPropertyValue(name).trim() || fallback;
631
- 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)" };
796
+ 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(1,4,14,0.2)"), day: pick("--chikyu-flat-day", "rgba(170,205,255,0.1)"), terminator: pick("--chikyu-flat-terminator", "#ffc46e"), grid: "rgba(150,180,220,0.13)" };
632
797
  }
633
798
  #projection() {
634
799
  const v = this.#view;
@@ -647,12 +812,18 @@ export class ChikyuFlat extends HTMLElement {
647
812
  const sun = subsolarPoint(ms);
648
813
  const shade = this.getAttribute("shade") !== "off";
649
814
  const home = this.#home();
650
- // the map is drawn again only when the view, the home or the sun's place (about a quarter of a degree) changed
815
+ const pictures = this.#look === "photo" ? this.#photo : null;
816
+ pictures?.want(360 * pixelsPerDegree(v) * this.#dpr);
817
+ const photo = pictures?.day ? pictures : null;
818
+ // the map is drawn again only when the view, the home or the sun's place (about a quarter of a degree, half a degree over a photo, which costs more) changed
651
819
  const c = this.#colours();
652
- 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("|");
820
+ this.#terminatorColour = c.terminator;
821
+ const per = photo ? 2 : 4;
822
+ 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 * per) : "x", shade ? Math.round(sun.lat * per) : "x", home ? `${home.lon},${home.lat}` : "", c.sea, c.land, c.line, c.night, c.day, c.terminator, photo ? `${photo.day.width}/${photo.night?.width ?? 0}/${this.getAttribute("borders") === "off" ? "x" : "b"}` : "m"].join("|");
653
823
  if (key === this.#mapKey)
654
824
  return;
655
825
  this.#mapKey = key;
826
+ this.#markAt = { sun: null, home: null };
656
827
  this.#counts.mapDraws += 1;
657
828
  const ctx = canvas.getContext("2d", { willReadFrequently: true });
658
829
  if (!ctx)
@@ -662,47 +833,93 @@ export class ChikyuFlat extends HTMLElement {
662
833
  ctx.fillRect(0, 0, v.width, v.height);
663
834
  const projection = this.#projection();
664
835
  const path = geoPath(projection, ctx);
665
- ctx.beginPath();
666
- path(geoGraticule10());
667
- ctx.strokeStyle = c.grid;
668
- ctx.lineWidth = 1;
669
- ctx.stroke();
670
- ctx.beginPath();
671
- path(COUNTRIES);
672
- ctx.fillStyle = c.land;
673
- ctx.fill();
674
- ctx.strokeStyle = c.line;
675
- ctx.lineWidth = 0.6;
676
- ctx.stroke();
836
+ if (photo) {
837
+ // NASA's picture on the map, the borders thin and pale on it, then the night (the darkening and the city lights) over both
838
+ paintPhoto(ctx, v, photo, shade ? sun : null, this.getAttribute("borders") === "off" ? null : () => {
839
+ ctx.beginPath();
840
+ path(COUNTRIES);
841
+ ctx.strokeStyle = "rgba(255,255,255,0.32)";
842
+ ctx.lineWidth = 0.6;
843
+ ctx.stroke();
844
+ });
845
+ }
846
+ else {
847
+ ctx.beginPath();
848
+ path(geoGraticule10());
849
+ ctx.strokeStyle = c.grid;
850
+ ctx.lineWidth = 1;
851
+ ctx.stroke();
852
+ ctx.beginPath();
853
+ path(COUNTRIES);
854
+ ctx.fillStyle = c.land;
855
+ ctx.fill();
856
+ ctx.strokeStyle = c.line;
857
+ ctx.lineWidth = 0.6;
858
+ ctx.stroke();
859
+ }
677
860
  if (shade) {
678
- // the night side: four bands from the sunset line towards midnight, each a little darker
679
- const anti = [wrapLongitude(sun.lon + 180), -sun.lat];
680
- ctx.fillStyle = c.night;
681
- for (const radius of [90, 96, 102, 108]) {
861
+ if (!photo) {
862
+ // the day side a little lighter, and the night side from the sunset line towards midnight in four bands, each darker
682
863
  ctx.beginPath();
683
- path(geoCircle().center(anti).radius(radius).precision(2)());
864
+ path(geoCircle().center([sun.lon, sun.lat]).radius(90).precision(2)());
865
+ ctx.fillStyle = c.day;
684
866
  ctx.fill();
867
+ const anti = [wrapLongitude(sun.lon + 180), -sun.lat];
868
+ ctx.fillStyle = c.night;
869
+ for (const radius of [90, 96, 102, 108]) {
870
+ ctx.beginPath();
871
+ path(geoCircle().center(anti).radius(radius).precision(2)());
872
+ ctx.fill();
873
+ }
685
874
  }
875
+ // the sunrise and sunset line: 90 degrees from the point under the Sun, drawn as a line (not as the edge of a shape, which would be closed along the map's sides)
876
+ ctx.beginPath();
877
+ path({ type: "LineString", coordinates: geoCircle().center([sun.lon, sun.lat]).radius(90).precision(2)().coordinates[0] });
878
+ ctx.lineJoin = "round";
879
+ ctx.lineWidth = 3.4;
880
+ ctx.strokeStyle = "rgba(0,0,0,.4)";
881
+ ctx.stroke();
882
+ ctx.lineWidth = 1.4;
883
+ ctx.strokeStyle = c.terminator;
884
+ ctx.globalAlpha = photo ? 0.75 : 0.95;
885
+ ctx.stroke();
886
+ ctx.globalAlpha = 1;
887
+ ctx.fillStyle = c.night;
686
888
  const at = projectFlat(v, sun.lon, sun.lat);
889
+ const spot = { xs: [], y: at.y, lon: sun.lon, lat: sun.lat };
687
890
  for (const x of [at.x, at.x - 360 * pixelsPerDegree(v), at.x + 360 * pixelsPerDegree(v)]) {
688
891
  if (x < -8 || x > v.width + 8)
689
892
  continue;
893
+ spot.xs.push(x);
690
894
  ctx.beginPath();
691
895
  ctx.arc(x, at.y, 5, 0, Math.PI * 2);
692
896
  ctx.fillStyle = "#ffd54f";
693
897
  ctx.fill();
694
- ctx.lineWidth = 1;
695
- ctx.strokeStyle = "rgba(0,0,0,.5)";
898
+ // over a photo the dot has a dark edge and a pale ring round it, so it reads on cloud, desert and sea
899
+ ctx.lineWidth = photo ? 2 : 1;
900
+ ctx.strokeStyle = photo ? "rgba(0,0,0,.75)" : "rgba(0,0,0,.5)";
696
901
  ctx.stroke();
902
+ if (photo) {
903
+ ctx.beginPath();
904
+ ctx.arc(x, at.y, 6.8, 0, Math.PI * 2);
905
+ ctx.lineWidth = 1;
906
+ ctx.strokeStyle = "rgba(255,255,255,.85)";
907
+ ctx.stroke();
908
+ }
697
909
  ctx.fillStyle = c.night;
698
910
  }
911
+ if (spot.xs.length > 0)
912
+ this.#markAt.sun = spot;
699
913
  }
914
+ this.#drawAirports(ctx, v);
700
915
  if (home) {
701
916
  const at = projectFlat(v, home.lon, home.lat);
702
917
  const wrap = 360 * pixelsPerDegree(v);
918
+ const spot = { xs: [], y: at.y, lon: home.lon, lat: home.lat };
703
919
  for (const x of [at.x, at.x - wrap, at.x + wrap]) {
704
920
  if (x < -10 || x > v.width + 10)
705
921
  continue;
922
+ spot.xs.push(x);
706
923
  ctx.save();
707
924
  ctx.translate(x, at.y);
708
925
  ctx.rotate(Math.PI / 4);
@@ -713,7 +930,88 @@ export class ChikyuFlat extends HTMLElement {
713
930
  ctx.fillRect(-4.5, -4.5, 9, 9);
714
931
  ctx.restore();
715
932
  }
933
+ if (spot.xs.length > 0)
934
+ this.#markAt.home = spot;
935
+ }
936
+ this.#placeMarkButtons();
937
+ this.#syncLegend();
938
+ }
939
+ /** Ask for the airports, or put them away. The rows are in a chunk of their own, fetched the first time they are asked for. */
940
+ #setAirports(on) {
941
+ if (on === this.#airports)
942
+ return;
943
+ this.#airports = on;
944
+ this.#airportAt = [];
945
+ this.#airportHover = this.#airportShown = null;
946
+ this.#mapKey = "";
947
+ if (on && this.#airportRows === null) {
948
+ void import("./airports-data.js").then((data) => {
949
+ this.#airportRows = data.AIRPORT_ROWS.map(([lon, lat, iata, name, country, tier]) => ({ lon, lat, iata, name, country, tier }));
950
+ this.#mapKey = "";
951
+ this.#request();
952
+ }, () => {
953
+ this.#airportRows = [];
954
+ });
955
+ }
956
+ }
957
+ /** The airports on the map's own picture: a small white mark with a dark edge, and from zoom 4 the IATA code beside it. The greater airports first, so a world in sight shows the greater ones. */
958
+ #drawAirports(ctx, v) {
959
+ this.#airportAt = [];
960
+ if (!this.#airports || !this.#airportRows)
961
+ return;
962
+ const placed = placeAirports(v, this.#airportRows);
963
+ this.#airportAt = placed;
964
+ const codes = v.zoom >= 4;
965
+ const dark = this.#look === "photo" && this.#photo?.day != null;
966
+ ctx.save();
967
+ ctx.lineJoin = "round";
968
+ ctx.font = "600 10px system-ui, sans-serif";
969
+ ctx.textBaseline = "middle";
970
+ for (const one of placed) {
971
+ ctx.beginPath();
972
+ ctx.arc(one.x, one.y, one.airport.tier === 1 ? 3 : 2.4, 0, Math.PI * 2);
973
+ ctx.fillStyle = "#ffffff";
974
+ ctx.fill();
975
+ ctx.lineWidth = 1.4;
976
+ ctx.strokeStyle = dark ? "rgba(0,0,0,.85)" : "rgba(4,8,18,.9)";
977
+ ctx.stroke();
978
+ if (codes) {
979
+ ctx.lineWidth = 3;
980
+ ctx.strokeStyle = "rgba(4,8,18,.8)";
981
+ ctx.strokeText(one.airport.iata, one.x + 6, one.y);
982
+ ctx.fillStyle = "#ffffff";
983
+ ctx.fillText(one.airport.iata, one.x + 6, one.y);
984
+ }
985
+ }
986
+ ctx.restore();
987
+ }
988
+ /** The airport drawn nearest to a point, within `reach` pixels. */
989
+ #airportNear(x, y, reach) {
990
+ let best = null;
991
+ let gap = reach * reach;
992
+ for (const one of this.#airportAt) {
993
+ const d = (one.x - x) ** 2 + (one.y - y) ** 2;
994
+ if (d <= gap) {
995
+ gap = d;
996
+ best = one;
997
+ }
716
998
  }
999
+ return best;
1000
+ }
1001
+ /** The name of an airport: its name, code and country, in the page's language. */
1002
+ #airportText(one) {
1003
+ const country = COUNTRIES.features.find((feature) => feature.properties.alpha2 === one.airport.country)?.properties;
1004
+ return airportLine(one.airport, this.language === "ja" ? (country?.ja ?? country?.name ?? null) : (country?.name ?? null), this.language);
1005
+ }
1006
+ /** A press on an airport: its name stays beside it (a finger cannot hover), is read aloud, and the page is told with `chikyu-flat-airport`. */
1007
+ #pressAirport(one) {
1008
+ this.#airportShown = one;
1009
+ this.#placeMarks();
1010
+ const text = this.#airportText(one);
1011
+ if (this.#live)
1012
+ this.#live.textContent = text;
1013
+ const a = one.airport;
1014
+ this.dispatchEvent(new CustomEvent("chikyu-flat-airport", { detail: { iata: a.iata, name: a.name, country: a.country, lon: a.lon, lat: a.lat, tier: a.tier, text, via: "tap" }, bubbles: true, composed: true }));
717
1015
  }
718
1016
  #home() {
719
1017
  const lon = finite(this.getAttribute("home-lon"), Number.NaN);
@@ -870,27 +1168,38 @@ export class ChikyuFlat extends HTMLElement {
870
1168
  }
871
1169
  ctx.globalAlpha = 1;
872
1170
  }
1171
+ // over a photo each dot has a dark rim, so it reads on white cloud and on pale desert alike
1172
+ const rim = this.#look === "photo" && this.#photo?.day != null;
873
1173
  for (const [key, list] of buckets) {
874
1174
  if (list.length === 0)
875
1175
  continue;
876
1176
  const faint = key.endsWith("~");
877
- ctx.fillStyle = faint ? key.slice(0, -1) : key;
878
- ctx.globalAlpha = faint ? 0.45 : 1;
879
- if (radius <= 1.7) {
880
- const side = radius * 2;
881
- for (let j = 0; j < list.length; j += 2)
882
- ctx.fillRect(list[j] - radius, list[j + 1] - radius, side, side);
883
- }
884
- else {
885
- ctx.beginPath();
886
- for (let j = 0; j < list.length; j += 2) {
887
- ctx.moveTo(list[j] + radius, list[j + 1]);
888
- ctx.arc(list[j], list[j + 1], radius, 0, Math.PI * 2);
1177
+ for (const pass of rim ? [true, false] : [false]) {
1178
+ const grown = pass ? radius + 1 : radius;
1179
+ ctx.fillStyle = pass ? "rgba(4,8,18,0.7)" : faint ? key.slice(0, -1) : key;
1180
+ ctx.globalAlpha = faint ? 0.45 : 1;
1181
+ if (grown <= 1.7) {
1182
+ const side = grown * 2;
1183
+ for (let j = 0; j < list.length; j += 2)
1184
+ ctx.fillRect(list[j] - grown, list[j + 1] - grown, side, side);
1185
+ }
1186
+ else {
1187
+ ctx.beginPath();
1188
+ for (let j = 0; j < list.length; j += 2) {
1189
+ ctx.moveTo(list[j] + grown, list[j + 1]);
1190
+ ctx.arc(list[j], list[j + 1], grown, 0, Math.PI * 2);
1191
+ }
1192
+ ctx.fill();
889
1193
  }
890
- ctx.fill();
891
1194
  }
892
1195
  }
893
1196
  ctx.globalAlpha = 1;
1197
+ // the key names the faint dots (old orbit data) only while there are some
1198
+ const faint = [...buckets].some(([colour, list]) => list.length > 0 && colour.endsWith("~"));
1199
+ if (faint !== this.#faint) {
1200
+ this.#faint = faint;
1201
+ this.#syncLegend();
1202
+ }
894
1203
  this.#counts.draws += 1;
895
1204
  this.#counts.dots = dots;
896
1205
  this.#placeMarks();
@@ -926,7 +1235,13 @@ export class ChikyuFlat extends HTMLElement {
926
1235
  path(geoCircle().center([g.lon[i], g.lat[i]]).radius(angle).precision(3)());
927
1236
  ctx.fillStyle = "rgba(255,255,255,0.07)";
928
1237
  ctx.fill();
929
- ctx.strokeStyle = "rgba(255,255,255,0.45)";
1238
+ const onPhoto = this.#look === "photo" && this.#photo?.day != null;
1239
+ if (onPhoto) {
1240
+ ctx.strokeStyle = "rgba(4,8,18,0.55)";
1241
+ ctx.lineWidth = 3;
1242
+ ctx.stroke();
1243
+ }
1244
+ ctx.strokeStyle = onPhoto ? "rgba(255,255,255,0.8)" : "rgba(255,255,255,0.45)";
930
1245
  ctx.lineWidth = 1;
931
1246
  ctx.stroke();
932
1247
  };
@@ -979,10 +1294,11 @@ export class ChikyuFlat extends HTMLElement {
979
1294
  return { sun: style.getPropertyValue("--chikyu-flat-track-sun").trim() || TRACK_SUNLIT, shadow: style.getPropertyValue("--chikyu-flat-track-shadow").trim() || TRACK_SHADOW };
980
1295
  }
981
1296
  /** The key to the track's two colours, shown while the track is. It changes only when the track appears or goes, or the language does. */
982
- #showKey(on) {
1297
+ #showKey(wanted) {
983
1298
  const key = this.#key;
984
1299
  if (!key)
985
1300
  return;
1301
+ const on = wanted && !(this.#wants().has("key") && this.#legendIsOpen());
986
1302
  if (key.hidden === !on && (!on || key.lang === this.language))
987
1303
  return;
988
1304
  key.hidden = !on;
@@ -1051,19 +1367,178 @@ export class ChikyuFlat extends HTMLElement {
1051
1367
  const tip = this.#tip;
1052
1368
  if (!tip)
1053
1369
  return;
1370
+ // a satellite pointed at is named first, then a mark pointed at, then a mark pressed or reached by the keyboard, then the satellite chosen
1371
+ const named = this.#hover ? null : (this.#markHover ?? this.#markShown);
1372
+ const spot = named ? this.#markAt[named] : null;
1054
1373
  const ref = this.#hover ?? picked;
1055
- const where = this.#hover ? (over ?? at) : at;
1056
- if (!ref || !where || ref.g.on[ref.i] !== 1) {
1374
+ const airport = this.#hover || named ? null : (this.#airportHover ?? this.#airportShown);
1375
+ const where = airport ? { x: airport.x, y: airport.y } : spot && named ? { x: spot.xs[0], y: spot.y } : this.#hover ? (over ?? at) : at;
1376
+ if (!where || (!airport && !spot && (!ref || ref.g.on[ref.i] !== 1))) {
1057
1377
  tip.hidden = true;
1058
1378
  return;
1059
1379
  }
1060
1380
  tip.hidden = false;
1061
- tip.textContent = this.#describe(ref);
1381
+ tip.textContent = airport ? this.#airportText(airport) : spot && named ? this.#markText(named) : this.#describe(ref);
1062
1382
  const wide = tip.offsetWidth;
1063
1383
  const left = where.x + 14 + wide > this.#view.width ? Math.max(0, where.x - 14 - wide) : where.x + 14;
1064
1384
  const top = Math.max(0, Math.min(this.#view.height - tip.offsetHeight, where.y - 10));
1065
1385
  tip.style.transform = `translate(${left.toFixed(1)}px,${top.toFixed(1)}px)`;
1066
1386
  }
1387
+ // --- the marks that name themselves ------------------------------------------------------------------------------------------------------------
1388
+ /** What a mark says about itself, in the page's language: what it is, what it is over, and where. Worked out once for each place (to a degree). */
1389
+ #markText(mark) {
1390
+ const spot = this.#markAt[mark];
1391
+ if (!spot)
1392
+ return "";
1393
+ const lang = this.language;
1394
+ const id = `${mark}|${lang}|${Math.round(spot.lon)}|${Math.round(spot.lat)}`;
1395
+ let text = this.#markNames.get(id);
1396
+ if (text === undefined) {
1397
+ const what = say(lang, mark === "sun" ? "sunMark" : "homeMark");
1398
+ const point = pointText(spot.lon, spot.lat, lang);
1399
+ const place = placeOver(spot.lon, spot.lat, lang);
1400
+ text = place ? say(lang, mark === "sun" ? "sunOver" : "homeOver", { what, place, point }) : say(lang, mark === "sun" ? "sunAt" : "homeAt", { what, point });
1401
+ if (this.#markNames.size > 40)
1402
+ this.#markNames.clear();
1403
+ this.#markNames.set(id, text);
1404
+ }
1405
+ return text;
1406
+ }
1407
+ /** Of a satellite and a mark both within reach of a point, the one nearer it: a mark pointed at straight is not lost to a satellite that happens to be close. Returns the mark to use, or null when the satellite is to be. */
1408
+ #markOver(hit, x, y, reach) {
1409
+ const mark = this.#markHit(x, y, reach);
1410
+ if (!mark || !hit)
1411
+ return mark;
1412
+ const spot = this.#markAt[mark];
1413
+ const away = Math.min(...spot.xs.map((at) => Math.hypot(at - x, spot.y - y)));
1414
+ return away < Math.hypot(hit.g.sx[hit.i] - x, hit.g.sy[hit.i] - y) ? mark : null;
1415
+ }
1416
+ /** The mark painted within `reach` pixels of a point, or null. */
1417
+ #markHit(x, y, reach) {
1418
+ for (const mark of ["sun", "home"]) {
1419
+ const spot = this.#markAt[mark];
1420
+ if (spot && Math.abs(spot.y - y) <= reach && spot.xs.some((at) => Math.hypot(at - x, spot.y - y) <= reach))
1421
+ return mark;
1422
+ }
1423
+ return null;
1424
+ }
1425
+ /** A press on a mark, with a finger, a mouse or the keyboard: its name stays beside it (a finger has no pointer to hover), it is read aloud, and the page is told with `chikyu-flat-mark`. */
1426
+ #pressMark(mark, via) {
1427
+ const spot = this.#markAt[mark];
1428
+ if (!spot)
1429
+ return;
1430
+ this.#markShown = mark;
1431
+ this.#placeMarks();
1432
+ const lang = this.language;
1433
+ const text = this.#markText(mark);
1434
+ if (this.#live)
1435
+ this.#live.textContent = text;
1436
+ this.dispatchEvent(new CustomEvent("chikyu-flat-mark", { detail: { mark, name: say(lang, mark === "sun" ? "sunMark" : "homeMark"), text, lon: spot.lon, lat: spot.lat, place: placeOver(spot.lon, spot.lat, lang), via }, bubbles: true, composed: true }));
1437
+ }
1438
+ /** The keyboard's way to the marks: a button over each, with its name, that takes no pointer. Moved when the map is drawn. */
1439
+ #placeMarkButtons() {
1440
+ const lang = this.language;
1441
+ for (const mark of ["sun", "home"]) {
1442
+ const button = this.#markButtons[mark];
1443
+ const spot = this.#markAt[mark];
1444
+ if (!button)
1445
+ continue;
1446
+ button.hidden = !spot;
1447
+ if (!spot) {
1448
+ if (this.#markShown === mark)
1449
+ this.#markShown = null;
1450
+ continue;
1451
+ }
1452
+ button.style.transform = `translate(${spot.xs[0].toFixed(1)}px,${spot.y.toFixed(1)}px)`;
1453
+ button.setAttribute("aria-label", this.#markText(mark));
1454
+ button.lang = lang;
1455
+ }
1456
+ }
1457
+ /** The key under the map: every mark the map draws now, each with the picture of it and its name. Made again only when what is drawn, the words or the fold change. */
1458
+ #syncLegend() {
1459
+ const box = this.#legend;
1460
+ if (!box)
1461
+ return;
1462
+ const lang = this.language;
1463
+ const wants = this.#wants().has("key");
1464
+ box.hidden = !wants;
1465
+ if (!wants)
1466
+ return;
1467
+ const open = this.#legendIsOpen();
1468
+ const shade = this.getAttribute("shade") !== "off";
1469
+ const photo = this.#look === "photo" && this.#photo?.day != null;
1470
+ const shown = this.#shownGroups();
1471
+ const byPlane = this.#byPlane(shown);
1472
+ const chosen = this.#selected !== null;
1473
+ const entries = [];
1474
+ if (shade)
1475
+ entries.push({ glyph: "sun", text: say(lang, "keySun") });
1476
+ if (this.#home())
1477
+ entries.push({ glyph: "home", text: say(lang, "keyHome") });
1478
+ if (this.#airports)
1479
+ entries.push({ glyph: "airport", text: say(lang, "keyAirport") });
1480
+ if (shown.length > 0)
1481
+ entries.push({ glyph: "sat", text: say(lang, byPlane ? "keySatPlane" : "keySatGroup"), colours: byPlane ? PLANE_COLOURS.slice(0, 3) : shown.slice(0, 3).map((g) => g.colour) });
1482
+ if (this.#faint)
1483
+ entries.push({ glyph: "faint", text: say(lang, "keyFaint") });
1484
+ if (chosen)
1485
+ entries.push({ glyph: "chosen", text: say(lang, "keyRing") });
1486
+ if (this.#footprint)
1487
+ entries.push({ glyph: "footprint", text: say(lang, "keyFootprint") });
1488
+ if (this.#track && chosen) {
1489
+ const colours = this.#trackColours();
1490
+ entries.push({ glyph: "line", text: say(lang, "trackSunlit"), colours: [colours.sun] }, { glyph: "line", text: say(lang, "trackShadow"), colours: [colours.shadow] });
1491
+ }
1492
+ if (shade)
1493
+ entries.push({ glyph: "day", text: say(lang, "keyDay") }, { glyph: photo ? "night-photo" : "night", text: say(lang, photo ? "keyNightPhoto" : "keyNight") }, { glyph: "line", text: say(lang, "keyTerminator"), colours: [this.#terminatorColour] });
1494
+ if (photo)
1495
+ entries.push({ glyph: "nasa", text: this.#creditText() });
1496
+ const key = JSON.stringify([lang, open, entries]);
1497
+ if (key === this.#legendKey)
1498
+ return;
1499
+ this.#legendKey = key;
1500
+ const d = box.ownerDocument;
1501
+ const toggle = d.createElement("button");
1502
+ toggle.type = "button";
1503
+ toggle.setAttribute("part", "button");
1504
+ toggle.dataset["act"] = "key";
1505
+ toggle.setAttribute("aria-expanded", String(open));
1506
+ toggle.setAttribute("aria-controls", "legend-list");
1507
+ toggle.setAttribute("aria-label", say(lang, open ? "keyHide" : "keyShow"));
1508
+ toggle.textContent = `${say(lang, "key")} ${open ? "▾" : "▸"}`;
1509
+ const list = d.createElement("ul");
1510
+ list.id = "legend-list";
1511
+ list.setAttribute("aria-label", say(lang, "keyMarks"));
1512
+ list.hidden = !open;
1513
+ for (const entry of entries) {
1514
+ const item = d.createElement("li");
1515
+ const glyph = d.createElement("span");
1516
+ glyph.className = `g ${entry.glyph}`;
1517
+ glyph.setAttribute("aria-hidden", "true");
1518
+ for (const colour of entry.colours ?? []) {
1519
+ const dot = d.createElement("i");
1520
+ dot.style.setProperty("--c", colour);
1521
+ glyph.append(dot);
1522
+ }
1523
+ item.append(glyph, entry.text);
1524
+ list.append(item);
1525
+ }
1526
+ box.replaceChildren(toggle, list);
1527
+ box.lang = lang;
1528
+ }
1529
+ /** Whether the key's list is open: what the reader chose, else open on a wide map and shut on a narrow one. */
1530
+ #legendIsOpen() {
1531
+ return this.#legendOpen ?? this.#view.width >= 600;
1532
+ }
1533
+ /** The key folded open or shut. A property so a page can set it; the reader's button does the same. */
1534
+ get keyOpen() {
1535
+ return this.#legendIsOpen();
1536
+ }
1537
+ set keyOpen(value) {
1538
+ this.#legendOpen = Boolean(value);
1539
+ this.#syncLegend();
1540
+ this.#request();
1541
+ }
1067
1542
  #nameOf(ref) {
1068
1543
  const set = ref.g.sats.sets[ref.i];
1069
1544
  return SHORT_NAMES[set.NORAD_CAT_ID]?.[this.language] ?? set.OBJECT_NAME;
@@ -1103,18 +1578,53 @@ export class ChikyuFlat extends HTMLElement {
1103
1578
  const hovRing = Object.assign(d.createElement("div"), { className: "ring hov", hidden: true });
1104
1579
  const tip = Object.assign(d.createElement("div"), { className: "tip", hidden: true });
1105
1580
  tip.setAttribute("aria-hidden", "true");
1581
+ tip.setAttribute("part", "tip");
1106
1582
  const msg = Object.assign(d.createElement("p"), { className: "msg" });
1107
1583
  msg.setAttribute("role", "status");
1584
+ msg.setAttribute("part", "msg");
1108
1585
  const key = Object.assign(d.createElement("p"), { className: "key", hidden: true });
1109
1586
  key.setAttribute("role", "group");
1587
+ key.setAttribute("part", "key");
1588
+ const credit = Object.assign(d.createElement("button"), { className: "credit", type: "button", hidden: true });
1589
+ credit.setAttribute("part", "button credit");
1590
+ credit.append(d.createElement("span"), d.createElement("span"));
1591
+ credit.children[0].className = "short";
1592
+ credit.children[1].className = "full";
1593
+ credit.setAttribute("aria-expanded", "false");
1594
+ credit.addEventListener("click", () => credit.setAttribute("aria-expanded", String(credit.toggleAttribute("data-open"))));
1595
+ const legend = Object.assign(d.createElement("div"), { className: "legend", hidden: true });
1596
+ legend.setAttribute("role", "group");
1597
+ legend.setAttribute("part", "key");
1598
+ legend.addEventListener("click", this.#onLegend);
1599
+ const marks = ["sun", "home"].map((mark) => {
1600
+ const button = Object.assign(d.createElement("button"), { className: "mark", type: "button", hidden: true });
1601
+ button.dataset["mark"] = mark;
1602
+ button.addEventListener("focus", () => {
1603
+ this.#markShown = mark;
1604
+ this.#placeMarks();
1605
+ if (this.#live)
1606
+ this.#live.textContent = this.#markText(mark);
1607
+ });
1608
+ button.addEventListener("blur", () => {
1609
+ if (this.#markShown !== mark)
1610
+ return;
1611
+ this.#markShown = null;
1612
+ this.#placeMarks();
1613
+ });
1614
+ button.addEventListener("click", () => this.#pressMark(mark, "key"));
1615
+ this.#markButtons[mark] = button;
1616
+ return button;
1617
+ });
1110
1618
  const live = Object.assign(d.createElement("p"), { className: "sr", id: "live" });
1111
1619
  live.setAttribute("role", "status");
1112
1620
  live.setAttribute("aria-live", "polite");
1113
1621
  const help = Object.assign(d.createElement("p"), { className: "sr", id: "help" });
1114
1622
  dots.setAttribute("aria-describedby", "help live");
1115
- stage.append(map, dots, selRing, hovRing, tip, key, msg);
1623
+ stage.append(map, dots, selRing, hovRing, tip, ...marks, key, credit, msg);
1116
1624
  this.#key = key;
1117
- root.append(bar, stage, live, help);
1625
+ this.#credit = credit;
1626
+ root.append(bar, stage, legend, live, help);
1627
+ this.#legend = legend;
1118
1628
  this.#bar = bar;
1119
1629
  this.#stage = stage;
1120
1630
  this.#mapCanvas = map;
@@ -1143,7 +1653,7 @@ export class ChikyuFlat extends HTMLElement {
1143
1653
  const raw = (this.getAttribute("controls") ?? "").trim().toLowerCase();
1144
1654
  if (raw === "none" || raw === "off")
1145
1655
  return new Set();
1146
- const all = ["centre", "zoom", "footprint", "track", "chips"];
1656
+ const all = ["centre", "zoom", "footprint", "track", "chips", "key"];
1147
1657
  if (raw === "" || raw === "all")
1148
1658
  return new Set(all);
1149
1659
  return new Set(raw.split(/[\s,]+/).map((one) => (one === "center" ? "centre" : one)));
@@ -1160,7 +1670,7 @@ export class ChikyuFlat extends HTMLElement {
1160
1670
  this.shadowRoot.querySelector("#help").textContent = say(lang, "help");
1161
1671
  bar.setAttribute("role", "toolbar");
1162
1672
  bar.setAttribute("aria-label", say(lang, "controls"));
1163
- const button = (act, label, extra = "") => `<button type="button" data-act="${act}"${extra}>${escape(label)}</button>`;
1673
+ const button = (act, label, extra = "") => `<button type="button" part="button" data-act="${act}"${extra}>${escape(label)}</button>`;
1164
1674
  const rows = [];
1165
1675
  const first = [];
1166
1676
  if (wants.has("centre")) {
@@ -1168,6 +1678,11 @@ export class ChikyuFlat extends HTMLElement {
1168
1678
  if (Number.isFinite(finite(this.getAttribute("home-lon"), Number.NaN)))
1169
1679
  first.push(button("home", say(lang, "myPlace"), ` aria-label="${escape(say(lang, "centreHome"))}" aria-pressed="false"`));
1170
1680
  }
1681
+ if (wants.has("airports"))
1682
+ first.push(button("airports", say(lang, "airports"), ` aria-pressed="false"`));
1683
+ // the look's own pair of buttons, beside the centre buttons and not at the far end of the row (a page's own buttons often sit there): not among the defaults, so a page that has not asked for it sees no new button
1684
+ if (wants.has("look"))
1685
+ first.push(`<span class="pair" role="group" aria-label="${escape(say(lang, "lookGroup"))}">${button("look-map", say(lang, "lookMap"), ` aria-pressed="false"`)}${button("look-photo", say(lang, "lookPhoto"), ` aria-pressed="false"`)}</span>`);
1171
1686
  if (wants.has("zoom"))
1172
1687
  first.push(`<span class="gap"></span>`, button("zoomout", "−", ` aria-label="${escape(say(lang, "zoomOut"))}"`), button("zoomin", "+", ` aria-label="${escape(say(lang, "zoomIn"))}"`));
1173
1688
  else
@@ -1185,13 +1700,13 @@ export class ChikyuFlat extends HTMLElement {
1185
1700
  const g = one[0];
1186
1701
  const chips = [button("plane", say(lang, "all"), ` class="chip" data-plane="" aria-pressed="false"`)];
1187
1702
  for (const plane of g.clusters.planes)
1188
- 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>`);
1703
+ chips.push(`<button type="button" part="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>`);
1189
1704
  rows.push(`<div class="row chips" role="group" aria-label="${escape(say(lang, "planesFilter"))}">${chips.join("")}</div>`);
1190
1705
  }
1191
1706
  else if (groups === "groups") {
1192
- const chips = [`<button type="button" class="chip" data-act="group" data-group="*" aria-pressed="false">${escape(say(lang, "all"))}</button>`];
1707
+ const chips = [`<button type="button" part="button" class="chip" data-act="group" data-group="*" aria-pressed="false">${escape(say(lang, "all"))}</button>`];
1193
1708
  for (const g of this.#groups.values())
1194
- 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>`);
1709
+ chips.push(`<button type="button" part="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>`);
1195
1710
  rows.push(`<div class="row chips" role="group" aria-label="${escape(say(lang, "groupsFilter"))}">${chips.join("")}</div>`);
1196
1711
  }
1197
1712
  }
@@ -1227,6 +1742,9 @@ export class ChikyuFlat extends HTMLElement {
1227
1742
  set('[data-act="home"]', Number.isFinite(home.lon) && Math.abs(wrapLongitude(this.#view.centerLon - home.lon)) < 0.5);
1228
1743
  set('[data-act="footprint"]', this.#footprint);
1229
1744
  set('[data-act="track"]', this.#track);
1745
+ set('[data-act="airports"]', this.#airports);
1746
+ set('[data-act="look-map"]', this.#look === "map");
1747
+ set('[data-act="look-photo"]', this.#look === "photo");
1230
1748
  const shown = this.#shownGroups();
1231
1749
  bar.querySelectorAll('[data-act="group"]').forEach((chip) => {
1232
1750
  const id = chip.dataset["group"];
@@ -1237,6 +1755,7 @@ export class ChikyuFlat extends HTMLElement {
1237
1755
  bar.querySelector('[data-act="zoomout"]')?.toggleAttribute("disabled", this.#view.zoom <= 1);
1238
1756
  if (this.#dotCanvas)
1239
1757
  this.#dotCanvas.toggleAttribute("data-zoomed", this.#view.zoom > 1);
1758
+ this.#syncLegend();
1240
1759
  }
1241
1760
  #afterFilter() {
1242
1761
  this.#buildBar();
@@ -1244,6 +1763,12 @@ export class ChikyuFlat extends HTMLElement {
1244
1763
  this.#schedule();
1245
1764
  this.dispatchEvent(new CustomEvent("chikyu-flat-filter", { detail: { groups: this.visibleGroups, plane: this.#plane }, bubbles: true, composed: true }));
1246
1765
  }
1766
+ #onLegend = (event) => {
1767
+ if (!event.target?.closest("button[data-act=key]"))
1768
+ return;
1769
+ this.keyOpen = !this.#legendIsOpen();
1770
+ this.#legend?.querySelector("button[data-act=key]")?.focus();
1771
+ };
1247
1772
  #onBar = (event) => {
1248
1773
  const target = event.target?.closest("button[data-act]");
1249
1774
  if (!target || target.hasAttribute("disabled"))
@@ -1266,6 +1791,13 @@ export class ChikyuFlat extends HTMLElement {
1266
1791
  this.#sync();
1267
1792
  this.#request();
1268
1793
  }
1794
+ else if (act === "look-map" || act === "look-photo") {
1795
+ // the attribute is the look: the page that set the controls sees the change as it sees any other
1796
+ this.setAttribute("look", act === "look-photo" ? "photo" : "map");
1797
+ }
1798
+ else if (act === "airports") {
1799
+ this.toggleAttribute("airports");
1800
+ }
1269
1801
  else if (act === "track") {
1270
1802
  this.#track = !this.#track;
1271
1803
  this.#trackKey = "";
@@ -1448,9 +1980,27 @@ export class ChikyuFlat extends HTMLElement {
1448
1980
  this.#dotCanvas.style.cursor = "";
1449
1981
  if (drag && !drag.moved) {
1450
1982
  // a tap: a finger needs more room than a mouse
1451
- const hit = this.#hit(at.x, at.y, event.pointerType === "touch" ? 22 : 9);
1983
+ const near = this.#hit(at.x, at.y, event.pointerType === "touch" ? 22 : 9);
1452
1984
  if (event.pointerType !== "mouse")
1453
1985
  this.#hover = null;
1986
+ const mark = this.#markOver(near, at.x, at.y, event.pointerType === "touch" ? 22 : 11);
1987
+ const hit = mark ? null : near;
1988
+ if (mark) {
1989
+ this.#pressMark(mark, "tap");
1990
+ return;
1991
+ }
1992
+ const airport = hit ? null : this.#airportNear(at.x, at.y, event.pointerType === "touch" ? 20 : 9);
1993
+ if (airport) {
1994
+ this.#markShown = null;
1995
+ this.#pressAirport(airport);
1996
+ return;
1997
+ }
1998
+ // a tap anywhere else puts a pressed mark's or airport's name away
1999
+ this.#markShown = null;
2000
+ this.#markHover = null;
2001
+ this.#airportShown = null;
2002
+ this.#airportHover = null;
2003
+ this.#placeMarks();
1454
2004
  this.#choose(hit, "tap");
1455
2005
  }
1456
2006
  }
@@ -1465,16 +2015,27 @@ export class ChikyuFlat extends HTMLElement {
1465
2015
  }
1466
2016
  };
1467
2017
  #onLeave = (event) => {
1468
- if (event.pointerType !== "mouse" || this.#hover === null)
2018
+ if (event.pointerType !== "mouse" || (this.#hover === null && this.#markHover === null && this.#airportHover === null))
1469
2019
  return;
1470
2020
  this.#hover = null;
2021
+ this.#markHover = null;
2022
+ this.#airportHover = null;
2023
+ if (this.#dotCanvas)
2024
+ this.#dotCanvas.style.cursor = "";
1471
2025
  this.#placeMarks();
1472
2026
  };
1473
2027
  #hoverAt(x, y) {
1474
- const hit = this.#hit(x, y, 8);
1475
- if (sameRef(hit, this.#hover))
2028
+ const near = this.#hit(x, y, 8);
2029
+ const mark = this.#markOver(near, x, y, 11);
2030
+ const hit = mark ? null : near;
2031
+ const airport = hit || mark ? null : this.#airportNear(x, y, 8);
2032
+ if (this.#dotCanvas)
2033
+ this.#dotCanvas.style.cursor = mark || airport ? "pointer" : "";
2034
+ if (sameRef(hit, this.#hover) && mark === this.#markHover && airport?.airport === this.#airportHover?.airport)
1476
2035
  return;
1477
2036
  this.#hover = hit;
2037
+ this.#markHover = mark;
2038
+ this.#airportHover = airport;
1478
2039
  this.#placeMarks();
1479
2040
  if (hit)
1480
2041
  this.#pick(hit, "hover");
@@ -1500,6 +2061,11 @@ export class ChikyuFlat extends HTMLElement {
1500
2061
  return;
1501
2062
  }
1502
2063
  if (key === "Escape") {
2064
+ if (this.#markShown || this.#airportShown) {
2065
+ this.#markShown = null;
2066
+ this.#airportShown = null;
2067
+ this.#placeMarks();
2068
+ }
1503
2069
  if (this.#cursor || this.#selected) {
1504
2070
  this.#cursor = null;
1505
2071
  this.#choose(null, "key");