@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.
@@ -0,0 +1,93 @@
1
+ import { type FlatView } from "./geometry.ts";
2
+ import type { FlatLang } from "./words.ts";
3
+ /**
4
+ * An airport as the flat map holds it: where it is, its IATA code, its name (OurAirports', in English), its country's ISO code and its tier (1 a large airport, 2 a medium one).
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import type { Airport } from "@johnmorrisdotca/chikyu-earth/flat";
9
+ *
10
+ * const narita: Airport = { lon: 140.39, lat: 35.77, iata: "NRT", name: "Narita International Airport", country: "JP", tier: 1 };
11
+ * console.log(narita.iata);
12
+ * ```
13
+ */
14
+ export interface Airport {
15
+ lon: number;
16
+ lat: number;
17
+ iata: string;
18
+ name: string;
19
+ country: string;
20
+ tier: 1 | 2;
21
+ }
22
+ /**
23
+ * The zoom from which the medium airports are drawn as well as the large ones.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import { MEDIUM_FROM_ZOOM } from "@johnmorrisdotca/chikyu-earth/flat";
28
+ *
29
+ * console.log(MEDIUM_FROM_ZOOM);
30
+ * ```
31
+ */
32
+ export declare const MEDIUM_FROM_ZOOM = 3;
33
+ /**
34
+ * The zoom from which an airport's code is written beside it.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { CODES_FROM_ZOOM } from "@johnmorrisdotca/chikyu-earth/flat";
39
+ *
40
+ * console.log(CODES_FROM_ZOOM);
41
+ * ```
42
+ */
43
+ export declare const CODES_FROM_ZOOM = 4;
44
+ /**
45
+ * An airport placed on the map: where it falls in the box, in CSS pixels from its top left, and the airport.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import type { PlacedAirport } from "@johnmorrisdotca/chikyu-earth/flat";
50
+ *
51
+ * const at = (one: PlacedAirport): string => `${one.airport.iata} at ${one.x}, ${one.y}`;
52
+ * console.log(typeof at);
53
+ * ```
54
+ */
55
+ export interface PlacedAirport {
56
+ x: number;
57
+ y: number;
58
+ airport: Airport;
59
+ }
60
+ /**
61
+ * The airports to draw for a view: the large ones, and the medium ones from zoom 3, greater first, with no two in one small cell of the box (so the whole world shows its greater airports and a closer map more of them). A world wider than the box shows an airport at the other turn of it too.
62
+ *
63
+ * @param view - The view.
64
+ * @param airports - Every airport, the greater first within a tier (`AIRPORT_ROWS` as `Airport`s).
65
+ * @returns The airports placed in the box.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * import { placeAirports } from "@johnmorrisdotca/chikyu-earth/flat";
70
+ *
71
+ * const view = { width: 720, height: 360, centerLon: 0, centerLat: 0, zoom: 1 };
72
+ * const airports = [{ lon: 139.78, lat: 35.55, iata: "HND", name: "Tokyo Haneda Airport", country: "JP", tier: 1 as const }];
73
+ * console.log(placeAirports(view, airports).map((one) => one.airport.iata));
74
+ * ```
75
+ */
76
+ export declare function placeAirports(view: FlatView, airports: readonly Airport[]): PlacedAirport[];
77
+ /**
78
+ * What to call an airport: its name, its IATA code and its country, in the page's language (the airport's name is OurAirports', in English; the country's is the package's own, in English or Japanese).
79
+ *
80
+ * @param airport - The airport.
81
+ * @param countryName - The name of its country in the language, or null.
82
+ * @param lang - `en` or `ja`.
83
+ * @returns The line, such as `Narita International Airport (NRT), Japan`.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * import { airportLine } from "@johnmorrisdotca/chikyu-earth/flat";
88
+ *
89
+ * const narita = { lon: 140.39, lat: 35.77, iata: "NRT", name: "Narita International Airport", country: "JP", tier: 1 as const };
90
+ * console.log(airportLine(narita, "Japan", "en"), airportLine(narita, "日本", "ja"));
91
+ * ```
92
+ */
93
+ export declare function airportLine(airport: Airport, countryName: string | null, lang: FlatLang): string;
@@ -0,0 +1,86 @@
1
+ // The airports on the flat map: which of them to draw at a view (the greater ones when the whole world is in sight, more as the map is zoomed in, never two in one small cell) and what to call one.
2
+ // Pure: no DOM and no dependency. The rows themselves (`airports-data.ts`, from OurAirports) are loaded only when a map asks for the airports.
3
+ import { pixelsPerDegree, projectFlat } from "./geometry.js";
4
+ /**
5
+ * The zoom from which the medium airports are drawn as well as the large ones.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { MEDIUM_FROM_ZOOM } from "@johnmorrisdotca/chikyu-earth/flat";
10
+ *
11
+ * console.log(MEDIUM_FROM_ZOOM);
12
+ * ```
13
+ */
14
+ export const MEDIUM_FROM_ZOOM = 3;
15
+ /**
16
+ * The zoom from which an airport's code is written beside it.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { CODES_FROM_ZOOM } from "@johnmorrisdotca/chikyu-earth/flat";
21
+ *
22
+ * console.log(CODES_FROM_ZOOM);
23
+ * ```
24
+ */
25
+ export const CODES_FROM_ZOOM = 4;
26
+ /**
27
+ * The airports to draw for a view: the large ones, and the medium ones from zoom 3, greater first, with no two in one small cell of the box (so the whole world shows its greater airports and a closer map more of them). A world wider than the box shows an airport at the other turn of it too.
28
+ *
29
+ * @param view - The view.
30
+ * @param airports - Every airport, the greater first within a tier (`AIRPORT_ROWS` as `Airport`s).
31
+ * @returns The airports placed in the box.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { placeAirports } from "@johnmorrisdotca/chikyu-earth/flat";
36
+ *
37
+ * const view = { width: 720, height: 360, centerLon: 0, centerLat: 0, zoom: 1 };
38
+ * const airports = [{ lon: 139.78, lat: 35.55, iata: "HND", name: "Tokyo Haneda Airport", country: "JP", tier: 1 as const }];
39
+ * console.log(placeAirports(view, airports).map((one) => one.airport.iata));
40
+ * ```
41
+ */
42
+ export function placeAirports(view, airports) {
43
+ const out = [];
44
+ const codes = view.zoom >= CODES_FROM_ZOOM;
45
+ const cell = codes ? 46 : 16;
46
+ const taken = new Set();
47
+ const turn = 360 * pixelsPerDegree(view);
48
+ const pad = 6;
49
+ for (const airport of airports) {
50
+ if (airport.tier === 2 && view.zoom < MEDIUM_FROM_ZOOM)
51
+ break;
52
+ const at = projectFlat(view, airport.lon, airport.lat);
53
+ if (at.y < -pad || at.y > view.height + pad)
54
+ continue;
55
+ for (const x of [at.x - turn, at.x, at.x + turn]) {
56
+ if (x < -pad || x > view.width + pad)
57
+ continue;
58
+ const key = Math.floor(x / cell) * 4096 + Math.floor(at.y / cell);
59
+ if (taken.has(key))
60
+ continue;
61
+ taken.add(key);
62
+ out.push({ x, y: at.y, airport });
63
+ }
64
+ }
65
+ return out;
66
+ }
67
+ /**
68
+ * What to call an airport: its name, its IATA code and its country, in the page's language (the airport's name is OurAirports', in English; the country's is the package's own, in English or Japanese).
69
+ *
70
+ * @param airport - The airport.
71
+ * @param countryName - The name of its country in the language, or null.
72
+ * @param lang - `en` or `ja`.
73
+ * @returns The line, such as `Narita International Airport (NRT), Japan`.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * import { airportLine } from "@johnmorrisdotca/chikyu-earth/flat";
78
+ *
79
+ * const narita = { lon: 140.39, lat: 35.77, iata: "NRT", name: "Narita International Airport", country: "JP", tier: 1 as const };
80
+ * console.log(airportLine(narita, "Japan", "en"), airportLine(narita, "日本", "ja"));
81
+ * ```
82
+ */
83
+ export function airportLine(airport, countryName, lang) {
84
+ const country = countryName ?? airport.country;
85
+ return lang === "ja" ? `${airport.name}(${airport.iata})、${country}` : `${airport.name} (${airport.iata}), ${country}`;
86
+ }
@@ -1,6 +1,7 @@
1
1
  import type { ElementSet } from "../satellites/types.ts";
2
2
  import { type GroupFacts, type Plane } from "./facts.ts";
3
3
  import { type GroundTrackState } from "./track-state.ts";
4
+ import { type FlatLook } from "./photo.ts";
4
5
  import { type FlatLang } from "./words.ts";
5
6
  /**
6
7
  * One satellite of a group, as a page is told of it: what `chikyu-flat-pick` carries.
@@ -70,11 +71,13 @@ export interface GroupStyle {
70
71
  * 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),
71
72
  * `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),
72
73
  * `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),
73
- * `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).
74
+ * `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).
75
+ * `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).
76
+ * 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.
74
77
  *
75
78
  * 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 }`),
76
- * `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).
77
- * 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`.
79
+ * `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).
80
+ * 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`.
78
81
  *
79
82
  * @example
80
83
  * ```ts no-run
@@ -141,6 +144,11 @@ export declare class ChikyuFlat extends HTMLElement {
141
144
  set paused(value: boolean);
142
145
  /** The language of the words: the `lang` attribute, else the page's. */
143
146
  get language(): FlatLang;
147
+ /** 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`. */
148
+ get look(): FlatLook;
149
+ set look(value: FlatLook);
150
+ /** 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. */
151
+ get lookState(): "map" | "loading" | "photo" | "failed";
144
152
  /** 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. */
145
153
  get stats(): {
146
154
  draws: number;
@@ -168,6 +176,9 @@ export declare class ChikyuFlat extends HTMLElement {
168
176
  connectedCallback(): void;
169
177
  disconnectedCallback(): void;
170
178
  attributeChangedCallback(name: string): void;
179
+ /** The key folded open or shut. A property so a page can set it; the reader's button does the same. */
180
+ get keyOpen(): boolean;
181
+ set keyOpen(value: boolean);
171
182
  /**
172
183
  * Where a loaded satellite is over the ground at the moment shown, which way its ground track runs and whether the Sun lights it: `{ lat, lon, heightKm, bearingDeg, ascending, sunlit }` (see `GroundTrackState`), placed exactly by SGP4. Null when the number names no loaded satellite
173
184
  * or it cannot be placed at that moment. It is the same state that `chikyu-flat-pick` carries (`sunlit`, `bearingDeg`, `ascending`).