@johnmorrisdotca/chikyu-earth 0.54.0 → 0.56.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 -1
- package/NOTICE.md +5 -1
- package/README.md +1 -1
- package/dist/door/gibs.d.ts +55 -6
- package/dist/door/gibs.js +177 -51
- package/dist/photos/index.d.ts +232 -0
- package/dist/photos/index.js +261 -0
- package/dist/realistic/element-base.d.ts +21 -0
- package/dist/realistic/element-base.js +57 -14
- package/dist/realistic/gate.d.ts +5 -0
- package/dist/realistic/gate.js +5 -2
- package/dist/realistic/index.d.ts +1 -0
- package/dist/realistic/index.js +1 -0
- package/dist/realistic/pace.d.ts +98 -0
- package/dist/realistic/pace.js +112 -0
- package/dist/satellites/track.js +25 -0
- package/dist/satellites/types.d.ts +5 -0
- package/dist/space/element-base.d.ts +21 -0
- package/dist/space/element-base.js +58 -8
- package/package.json +6 -1
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The smallest side of a box, in kilometres: a `sizeKm` below it is held at it.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { PHOTO_MIN_KM } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
7
|
+
*
|
|
8
|
+
* console.log(PHOTO_MIN_KM);
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare const PHOTO_MIN_KM = 1;
|
|
12
|
+
/**
|
|
13
|
+
* The largest side of a box, in kilometres: a `sizeKm` above it is held at it.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { PHOTO_MAX_KM } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
18
|
+
*
|
|
19
|
+
* console.log(PHOTO_MAX_KM);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const PHOTO_MAX_KM = 4000;
|
|
23
|
+
/**
|
|
24
|
+
* The width in pixels a picture has when a page does not say.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { PHOTO_DEFAULT_PX } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
29
|
+
*
|
|
30
|
+
* console.log(PHOTO_DEFAULT_PX);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare const PHOTO_DEFAULT_PX = 512;
|
|
34
|
+
/**
|
|
35
|
+
* The most pixels a picture may have across (and up): a larger `widthPx` is held at it.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { PHOTO_MAX_PX } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
40
|
+
*
|
|
41
|
+
* console.log(PHOTO_MAX_PX);
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const PHOTO_MAX_PX = 2048;
|
|
45
|
+
/**
|
|
46
|
+
* How many days, counting the first, `photoFallbacks` goes back by default.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { PHOTO_FALLBACK_DAYS } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
51
|
+
*
|
|
52
|
+
* console.log(PHOTO_FALLBACK_DAYS);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const PHOTO_FALLBACK_DAYS = 3;
|
|
56
|
+
/**
|
|
57
|
+
* What to ask for: a point, the side of the box in kilometres, and the day.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import type { PhotoOptions } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
62
|
+
*
|
|
63
|
+
* const tokyo: PhotoOptions = { lat: 35.68, lon: 139.77, sizeKm: 200, date: "2026-11-10" };
|
|
64
|
+
* console.log(tokyo.sizeKm);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export interface PhotoOptions {
|
|
68
|
+
/** Degrees north (-90 to 90; a value outside is held at the pole). */
|
|
69
|
+
lat: number;
|
|
70
|
+
/** Degrees east (any number; it is wrapped into -180 to 180). */
|
|
71
|
+
lon: number;
|
|
72
|
+
/** The side of the box on the ground, in kilometres (held between `PHOTO_MIN_KM` and `PHOTO_MAX_KM`). */
|
|
73
|
+
sizeKm: number;
|
|
74
|
+
/** The UTC day as `yyyy-mm-dd`, or a Date or milliseconds since the epoch (its UTC day). */
|
|
75
|
+
date: string | number | Date;
|
|
76
|
+
/** The picture's width and height in pixels (a square). 512 when left out, and never more than `PHOTO_MAX_PX`. */
|
|
77
|
+
widthPx?: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A box in degrees. `west` may be below -180 or `east` above 180 when the box crosses the date line (`wraps`).
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* import type { PhotoBox } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
85
|
+
*
|
|
86
|
+
* const box: PhotoBox = { south: 34, north: 36, west: 138, east: 141, wraps: false };
|
|
87
|
+
* console.log(box.east - box.west);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export interface PhotoBox {
|
|
91
|
+
south: number;
|
|
92
|
+
north: number;
|
|
93
|
+
west: number;
|
|
94
|
+
east: number;
|
|
95
|
+
wraps: boolean;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* One request for a picture: its box (inside -180 to 180), its address, and where it goes in the whole picture. A box that crosses the date line is two of these, side by side.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* import type { PhotoPiece } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
103
|
+
*
|
|
104
|
+
* const place = (piece: PhotoPiece): string => `${piece.offsetPx},${piece.widthPx}`;
|
|
105
|
+
* console.log(typeof place);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export interface PhotoPiece {
|
|
109
|
+
url: string;
|
|
110
|
+
south: number;
|
|
111
|
+
north: number;
|
|
112
|
+
west: number;
|
|
113
|
+
east: number;
|
|
114
|
+
/** Pixels from the left of the whole picture. */
|
|
115
|
+
offsetPx: number;
|
|
116
|
+
widthPx: number;
|
|
117
|
+
heightPx: number;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* One day to try: the day, the layer that has it, the one address of `photoUrl`, and the pieces of the exact box.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* import type { PhotoShot } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
125
|
+
*
|
|
126
|
+
* const label = (shot: PhotoShot): string => `${shot.date} ${shot.layer}`;
|
|
127
|
+
* console.log(typeof label);
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export interface PhotoShot {
|
|
131
|
+
date: string;
|
|
132
|
+
layer: string;
|
|
133
|
+
url: string;
|
|
134
|
+
pieces: PhotoPiece[];
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The box a picture of `sizeKm` around a point covers, in degrees. The height is `sizeKm` of latitude; the width is as many degrees of longitude as make `sizeKm` at the box's middle latitude, so the picture is square on the ground.
|
|
138
|
+
* At a pole the box is moved down so it stays on the Earth (the point is then at its edge) and its width in longitude grows to about 115 degrees. Across the date line `west` is below -180 or `east` above 180 and `wraps` is true.
|
|
139
|
+
*
|
|
140
|
+
* @param options - The point and the size; the date and the width are not read.
|
|
141
|
+
* @returns The box.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* import { photoBox } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
146
|
+
*
|
|
147
|
+
* const fiji = photoBox({ lat: -17.7, lon: 179.9, sizeKm: 200, date: "2026-11-10" });
|
|
148
|
+
* console.log(fiji.wraps, fiji.east > 180);
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare function photoBox(options: PhotoOptions): PhotoBox;
|
|
152
|
+
/**
|
|
153
|
+
* The id of the layer `photoUrl` uses for a day: the first of NOAA-20 VIIRS, Suomi NPP VIIRS and MODIS Terra (all true colour) whose days include it, or null before 2000-02-24.
|
|
154
|
+
*
|
|
155
|
+
* @param day - The UTC day, `yyyy-mm-dd`.
|
|
156
|
+
* @returns The layer id, or null.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* import { photoLayer } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
161
|
+
*
|
|
162
|
+
* console.log(photoLayer("2026-11-10"), photoLayer("2010-06-01"), photoLayer("1999-01-01"));
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export declare function photoLayer(day: string): string | null;
|
|
166
|
+
/**
|
|
167
|
+
* The address of a NASA GIBS snapshot (a WMS GetMap request, EPSG:4326, JPEG) of the box around a point on a day, from the best true-colour layer that has the day (`photoLayer`: NOAA-20 VIIRS from 2018, then Suomi NPP VIIRS and MODIS Terra back to 2000-02-24). About 250 m a pixel, clouds left in.
|
|
168
|
+
* The picture is one request, so a box that would cross the date line or run off a pole is moved to stay inside the world: the point is then not in the middle. `photoPieces` gives the exact box in two requests.
|
|
169
|
+
*
|
|
170
|
+
* @param options - The point, the size of the box and the day.
|
|
171
|
+
* @returns The address, or null when no layer has a picture for the day (before 2000-02-24).
|
|
172
|
+
* @throws RangeError when a number is not finite or the date is not a day.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* import { photoUrl } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
177
|
+
*
|
|
178
|
+
* const url = photoUrl({ lat: 35.68, lon: 139.77, sizeKm: 200, date: "2026-11-10", widthPx: 512 });
|
|
179
|
+
* console.log(url?.includes("TIME=2026-11-10"));
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export declare function photoUrl(options: PhotoOptions): string | null;
|
|
183
|
+
/**
|
|
184
|
+
* The exact box of a point as one or two requests, left to right: two when it crosses the date line, so a page can lay them side by side and the point stays in the middle.
|
|
185
|
+
*
|
|
186
|
+
* @param options - The point, the size of the box and the day.
|
|
187
|
+
* @returns The pieces, or an empty list when no layer has a picture for the day.
|
|
188
|
+
* @throws RangeError when a number is not finite or the date is not a day.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* import { photoPieces } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
193
|
+
*
|
|
194
|
+
* const pieces = photoPieces({ lat: -17.7, lon: 179.9, sizeKm: 200, date: "2026-11-10" });
|
|
195
|
+
* console.log(pieces.length, pieces.map((piece) => piece.widthPx));
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export declare function photoPieces(options: PhotoOptions): PhotoPiece[];
|
|
199
|
+
/**
|
|
200
|
+
* The days to try, newest first: the day asked for, then each day before it, up to `days` of them, skipping a day no layer has. NASA has no picture for a day whose satellite passes it has not yet processed (and answers with a black one, not an error), so a page tries the next of these when one is blank.
|
|
201
|
+
*
|
|
202
|
+
* @param options - The point, the size of the box and the first day.
|
|
203
|
+
* @param days - How many days to count back, the first included (3 by default).
|
|
204
|
+
* @returns The shots, each with its day, layer, one address and pieces.
|
|
205
|
+
* @throws RangeError when a number is not finite or the date is not a day.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* import { photoFallbacks } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
210
|
+
*
|
|
211
|
+
* const shots = photoFallbacks({ lat: 35.68, lon: 139.77, sizeKm: 200, date: "2026-11-10" }, 3);
|
|
212
|
+
* console.log(shots.map((shot) => shot.date));
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
export declare function photoFallbacks(options: PhotoOptions, days?: number): PhotoShot[];
|
|
216
|
+
/**
|
|
217
|
+
* The credit line to show with a picture, in English or Japanese. `full` gives NASA's own acknowledgement sentence for GIBS (the Japanese is this package's translation: NASA publishes none) instead of the short line.
|
|
218
|
+
* The short line names NASA as the source, as NASA asks, and says it is not an endorsement.
|
|
219
|
+
*
|
|
220
|
+
* @param lang - `en` or `ja`.
|
|
221
|
+
* @param full - True for the whole acknowledgement sentence.
|
|
222
|
+
* @returns The line.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* import { photoCredit } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
227
|
+
*
|
|
228
|
+
* console.log(photoCredit("en"));
|
|
229
|
+
* console.log(photoCredit("ja", true).length > photoCredit("ja").length);
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
export declare function photoCredit(lang: "en" | "ja", full?: boolean): string;
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
// Real satellite pictures of the ground under a point: the address of a NASA GIBS (Worldview) snapshot of a box around it, the days to try when a day is missing, and the credit NASA asks for.
|
|
2
|
+
// Pure: nothing here fetches. The reader's browser asks NASA for the picture (no key, and the service answers any page). A page that never imports this does not pay for it.
|
|
3
|
+
import { GIBS_CREDIT, GIBS_LAYERS, gibsHasDay, previousUtcDay, utcDay } from "../door/gibs.js";
|
|
4
|
+
/** The WMS address of NASA's imagery, in the plain latitude and longitude (EPSG:4326) grid. */
|
|
5
|
+
const WMS = "https://gibs.earthdata.nasa.gov/wms/epsg4326/best/wms.cgi";
|
|
6
|
+
/** Kilometres in a degree of latitude (the mean sphere, 6,371 km). */
|
|
7
|
+
const KM_PER_DEGREE = 111.195;
|
|
8
|
+
/**
|
|
9
|
+
* The smallest side of a box, in kilometres: a `sizeKm` below it is held at it.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { PHOTO_MIN_KM } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
14
|
+
*
|
|
15
|
+
* console.log(PHOTO_MIN_KM);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export const PHOTO_MIN_KM = 1;
|
|
19
|
+
/**
|
|
20
|
+
* The largest side of a box, in kilometres: a `sizeKm` above it is held at it.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { PHOTO_MAX_KM } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
25
|
+
*
|
|
26
|
+
* console.log(PHOTO_MAX_KM);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const PHOTO_MAX_KM = 4000;
|
|
30
|
+
/**
|
|
31
|
+
* The width in pixels a picture has when a page does not say.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { PHOTO_DEFAULT_PX } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
36
|
+
*
|
|
37
|
+
* console.log(PHOTO_DEFAULT_PX);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export const PHOTO_DEFAULT_PX = 512;
|
|
41
|
+
/**
|
|
42
|
+
* The most pixels a picture may have across (and up): a larger `widthPx` is held at it.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { PHOTO_MAX_PX } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
47
|
+
*
|
|
48
|
+
* console.log(PHOTO_MAX_PX);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export const PHOTO_MAX_PX = 2048;
|
|
52
|
+
/**
|
|
53
|
+
* How many days, counting the first, `photoFallbacks` goes back by default.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { PHOTO_FALLBACK_DAYS } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
58
|
+
*
|
|
59
|
+
* console.log(PHOTO_FALLBACK_DAYS);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export const PHOTO_FALLBACK_DAYS = 3;
|
|
63
|
+
/**
|
|
64
|
+
* The daily true-colour layers, best first, about 250 m a pixel with the clouds left in: NOAA-20 VIIRS (from 2018-01-05), Suomi NPP VIIRS (2015-11-24 to 2026-11-02, then it ends) and MODIS Terra (from 2000-02-24).
|
|
65
|
+
* The first with a day is used, so a day one of them skipped is taken from the next. Their days are the one table in `door/gibs.ts` (`GIBS_LAYERS`, read on `GIBS_DAYS_READ`), which the finer map tiles use too.
|
|
66
|
+
*/
|
|
67
|
+
const LAYERS = ["VIIRS_NOAA20_CorrectedReflectance_TrueColor", "VIIRS_SNPP_CorrectedReflectance_TrueColor", "MODIS_Terra_CorrectedReflectance_TrueColor"].map((id) => GIBS_LAYERS[id]);
|
|
68
|
+
const clamp = (value, low, high) => Math.min(high, Math.max(low, value));
|
|
69
|
+
const trim = (value) => String(Number(value.toFixed(5)));
|
|
70
|
+
/** The UTC day of a date option, or a RangeError when it is not one. */
|
|
71
|
+
function dayOf(date) {
|
|
72
|
+
if (typeof date === "string") {
|
|
73
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(date);
|
|
74
|
+
const check = match ? new Date(Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]))) : null;
|
|
75
|
+
if (!match || !check || utcDay(check.getTime()) !== date)
|
|
76
|
+
throw new RangeError(`date must be yyyy-mm-dd, a Date or milliseconds: ${date}`);
|
|
77
|
+
return date;
|
|
78
|
+
}
|
|
79
|
+
const ms = date instanceof Date ? date.getTime() : date;
|
|
80
|
+
if (!Number.isFinite(ms))
|
|
81
|
+
throw new RangeError("date must be yyyy-mm-dd, a Date or milliseconds");
|
|
82
|
+
return utcDay(ms);
|
|
83
|
+
}
|
|
84
|
+
function readOptions(options) {
|
|
85
|
+
const { lat, lon, sizeKm, widthPx } = options;
|
|
86
|
+
if (!Number.isFinite(lat) || !Number.isFinite(lon) || !Number.isFinite(sizeKm))
|
|
87
|
+
throw new RangeError("lat, lon and sizeKm must be finite numbers");
|
|
88
|
+
const width = widthPx === undefined ? PHOTO_DEFAULT_PX : widthPx;
|
|
89
|
+
if (!Number.isFinite(width))
|
|
90
|
+
throw new RangeError("widthPx must be a finite number");
|
|
91
|
+
return {
|
|
92
|
+
lat: clamp(lat, -90, 90),
|
|
93
|
+
lon: ((((lon + 180) % 360) + 360) % 360) - 180,
|
|
94
|
+
sizeKm: clamp(sizeKm, PHOTO_MIN_KM, PHOTO_MAX_KM),
|
|
95
|
+
day: dayOf(options.date),
|
|
96
|
+
widthPx: clamp(Math.round(width), 1, PHOTO_MAX_PX),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The box a picture of `sizeKm` around a point covers, in degrees. The height is `sizeKm` of latitude; the width is as many degrees of longitude as make `sizeKm` at the box's middle latitude, so the picture is square on the ground.
|
|
101
|
+
* At a pole the box is moved down so it stays on the Earth (the point is then at its edge) and its width in longitude grows to about 115 degrees. Across the date line `west` is below -180 or `east` above 180 and `wraps` is true.
|
|
102
|
+
*
|
|
103
|
+
* @param options - The point and the size; the date and the width are not read.
|
|
104
|
+
* @returns The box.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* import { photoBox } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
109
|
+
*
|
|
110
|
+
* const fiji = photoBox({ lat: -17.7, lon: 179.9, sizeKm: 200, date: "2026-11-10" });
|
|
111
|
+
* console.log(fiji.wraps, fiji.east > 180);
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export function photoBox(options) {
|
|
115
|
+
const { lat, lon, sizeKm } = readOptions(options);
|
|
116
|
+
const height = sizeKm / KM_PER_DEGREE;
|
|
117
|
+
const south = clamp(lat - height / 2, -90, 90 - height);
|
|
118
|
+
const north = south + height;
|
|
119
|
+
const cosine = Math.cos((((south + north) / 2) * Math.PI) / 180);
|
|
120
|
+
const span = Math.min(360, height / Math.max(cosine, 1e-9));
|
|
121
|
+
const west = lon - span / 2;
|
|
122
|
+
const east = lon + span / 2;
|
|
123
|
+
return { south, north, west, east, wraps: west < -180 || east > 180 };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The id of the layer `photoUrl` uses for a day: the first of NOAA-20 VIIRS, Suomi NPP VIIRS and MODIS Terra (all true colour) whose days include it, or null before 2000-02-24.
|
|
127
|
+
*
|
|
128
|
+
* @param day - The UTC day, `yyyy-mm-dd`.
|
|
129
|
+
* @returns The layer id, or null.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* import { photoLayer } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
134
|
+
*
|
|
135
|
+
* console.log(photoLayer("2026-11-10"), photoLayer("2010-06-01"), photoLayer("1999-01-01"));
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export function photoLayer(day) {
|
|
139
|
+
return LAYERS.find((layer) => gibsHasDay(layer, day))?.id ?? null;
|
|
140
|
+
}
|
|
141
|
+
function requestFor(layer, west, south, east, north, widthPx, heightPx, day) {
|
|
142
|
+
return `${WMS}?SERVICE=WMS&REQUEST=GetMap&VERSION=1.1.1&LAYERS=${layer}&STYLES=&FORMAT=image%2Fjpeg&SRS=EPSG%3A4326&BBOX=${trim(west)},${trim(south)},${trim(east)},${trim(north)}&WIDTH=${widthPx}&HEIGHT=${heightPx}&TIME=${day}`;
|
|
143
|
+
}
|
|
144
|
+
function piecesFor(box, layer, day, widthPx) {
|
|
145
|
+
const piece = (west, east, offsetPx, width) => ({
|
|
146
|
+
url: requestFor(layer, west, box.south, east, box.north, width, widthPx, day),
|
|
147
|
+
south: box.south,
|
|
148
|
+
north: box.north,
|
|
149
|
+
west,
|
|
150
|
+
east,
|
|
151
|
+
offsetPx,
|
|
152
|
+
widthPx: width,
|
|
153
|
+
heightPx: widthPx,
|
|
154
|
+
});
|
|
155
|
+
if (!box.wraps)
|
|
156
|
+
return [piece(box.west, box.east, 0, widthPx)];
|
|
157
|
+
const span = box.east - box.west;
|
|
158
|
+
const crossesEast = box.east > 180;
|
|
159
|
+
const firstSpan = crossesEast ? 180 - box.west : -180 - box.west;
|
|
160
|
+
const left = clamp(Math.round((widthPx * firstSpan) / span), 1, widthPx - 1);
|
|
161
|
+
if (crossesEast)
|
|
162
|
+
return [piece(box.west, 180, 0, left), piece(-180, box.east - 360, left, widthPx - left)];
|
|
163
|
+
return [piece(box.west + 360, 180, 0, left), piece(-180, box.east, left, widthPx - left)];
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The address of a NASA GIBS snapshot (a WMS GetMap request, EPSG:4326, JPEG) of the box around a point on a day, from the best true-colour layer that has the day (`photoLayer`: NOAA-20 VIIRS from 2018, then Suomi NPP VIIRS and MODIS Terra back to 2000-02-24). About 250 m a pixel, clouds left in.
|
|
167
|
+
* The picture is one request, so a box that would cross the date line or run off a pole is moved to stay inside the world: the point is then not in the middle. `photoPieces` gives the exact box in two requests.
|
|
168
|
+
*
|
|
169
|
+
* @param options - The point, the size of the box and the day.
|
|
170
|
+
* @returns The address, or null when no layer has a picture for the day (before 2000-02-24).
|
|
171
|
+
* @throws RangeError when a number is not finite or the date is not a day.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* import { photoUrl } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
176
|
+
*
|
|
177
|
+
* const url = photoUrl({ lat: 35.68, lon: 139.77, sizeKm: 200, date: "2026-11-10", widthPx: 512 });
|
|
178
|
+
* console.log(url?.includes("TIME=2026-11-10"));
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export function photoUrl(options) {
|
|
182
|
+
const { widthPx, day } = readOptions(options);
|
|
183
|
+
const layer = photoLayer(day);
|
|
184
|
+
if (layer === null)
|
|
185
|
+
return null;
|
|
186
|
+
const box = photoBox(options);
|
|
187
|
+
const shift = box.west < -180 ? -180 - box.west : box.east > 180 ? 180 - box.east : 0;
|
|
188
|
+
return requestFor(layer, box.west + shift, box.south, box.east + shift, box.north, widthPx, widthPx, day);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The exact box of a point as one or two requests, left to right: two when it crosses the date line, so a page can lay them side by side and the point stays in the middle.
|
|
192
|
+
*
|
|
193
|
+
* @param options - The point, the size of the box and the day.
|
|
194
|
+
* @returns The pieces, or an empty list when no layer has a picture for the day.
|
|
195
|
+
* @throws RangeError when a number is not finite or the date is not a day.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* import { photoPieces } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
200
|
+
*
|
|
201
|
+
* const pieces = photoPieces({ lat: -17.7, lon: 179.9, sizeKm: 200, date: "2026-11-10" });
|
|
202
|
+
* console.log(pieces.length, pieces.map((piece) => piece.widthPx));
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
export function photoPieces(options) {
|
|
206
|
+
const { widthPx, day } = readOptions(options);
|
|
207
|
+
const layer = photoLayer(day);
|
|
208
|
+
return layer === null ? [] : piecesFor(photoBox(options), layer, day, widthPx);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* The days to try, newest first: the day asked for, then each day before it, up to `days` of them, skipping a day no layer has. NASA has no picture for a day whose satellite passes it has not yet processed (and answers with a black one, not an error), so a page tries the next of these when one is blank.
|
|
212
|
+
*
|
|
213
|
+
* @param options - The point, the size of the box and the first day.
|
|
214
|
+
* @param days - How many days to count back, the first included (3 by default).
|
|
215
|
+
* @returns The shots, each with its day, layer, one address and pieces.
|
|
216
|
+
* @throws RangeError when a number is not finite or the date is not a day.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* import { photoFallbacks } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
221
|
+
*
|
|
222
|
+
* const shots = photoFallbacks({ lat: 35.68, lon: 139.77, sizeKm: 200, date: "2026-11-10" }, 3);
|
|
223
|
+
* console.log(shots.map((shot) => shot.date));
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
export function photoFallbacks(options, days = PHOTO_FALLBACK_DAYS) {
|
|
227
|
+
const { widthPx, day } = readOptions(options);
|
|
228
|
+
const shots = [];
|
|
229
|
+
let at = day;
|
|
230
|
+
const count = clamp(Math.floor(Number.isFinite(days) ? days : PHOTO_FALLBACK_DAYS), 1, 30);
|
|
231
|
+
for (let i = 0; i < count; i += 1) {
|
|
232
|
+
const layer = photoLayer(at);
|
|
233
|
+
if (layer !== null) {
|
|
234
|
+
const dated = { ...options, date: at, widthPx };
|
|
235
|
+
shots.push({ date: at, layer, url: photoUrl(dated), pieces: piecesFor(photoBox(dated), layer, at, widthPx) });
|
|
236
|
+
}
|
|
237
|
+
at = previousUtcDay(Date.parse(`${at}T12:00:00Z`));
|
|
238
|
+
}
|
|
239
|
+
return shots;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* The credit line to show with a picture, in English or Japanese. `full` gives NASA's own acknowledgement sentence for GIBS (the Japanese is this package's translation: NASA publishes none) instead of the short line.
|
|
243
|
+
* The short line names NASA as the source, as NASA asks, and says it is not an endorsement.
|
|
244
|
+
*
|
|
245
|
+
* @param lang - `en` or `ja`.
|
|
246
|
+
* @param full - True for the whole acknowledgement sentence.
|
|
247
|
+
* @returns The line.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* import { photoCredit } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
252
|
+
*
|
|
253
|
+
* console.log(photoCredit("en"));
|
|
254
|
+
* console.log(photoCredit("ja", true).length > photoCredit("ja").length);
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
export function photoCredit(lang, full = false) {
|
|
258
|
+
if (full)
|
|
259
|
+
return GIBS_CREDIT[lang];
|
|
260
|
+
return lang === "ja" ? "画像:NASA GIBS/Worldview(NASA)。NASAが承認したものではありません。" : "Imagery: NASA GIBS / Worldview (NASA). Not endorsed by NASA.";
|
|
261
|
+
}
|
|
@@ -377,6 +377,13 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
377
377
|
tiers: Record<EarthLayer, number>;
|
|
378
378
|
tiles: TileStats;
|
|
379
379
|
satellites: SatelliteStats;
|
|
380
|
+
/** How often the running clock draws, as last worked out: the quickest thing's speed on the screen (CSS pixels a second of real time), the frames a second that asks for, the most allowed (`smooth-fps`, halved on a small device or a low battery) and the wait before the next step in milliseconds. */
|
|
381
|
+
pace: {
|
|
382
|
+
pixelsPerSecond: number;
|
|
383
|
+
perSecond: number;
|
|
384
|
+
cap: number;
|
|
385
|
+
waitMs: number;
|
|
386
|
+
};
|
|
380
387
|
/** The cross-fade when `light` changes to or from `lit` (300 ms, a cut under reduced motion): `mix` is 0 for the true light and 1 for `lit`, and `fading` is true while it moves and another frame is wanted. */
|
|
381
388
|
lightFade: {
|
|
382
389
|
mix: number;
|
|
@@ -486,6 +493,20 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
486
493
|
*/
|
|
487
494
|
get satelliteTint(): "off" | "orbit";
|
|
488
495
|
set satelliteTint(value: "off" | "orbit");
|
|
496
|
+
/**
|
|
497
|
+
* The most steps a second drawn for a clock at real time, or up to 60 times it (the attribute `smooth-fps`; 15 when the page says nothing; 1 to 30). The picture is drawn each time the quickest thing in it (the Sun's turn at this zoom, a satellite dot)
|
|
498
|
+
* has moved half a pixel, at least once a second while satellites are on show, and at most this many. Half as many on a small device or a battery at 20% or lower; one a second for a reader who asked for reduced motion.
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* ```ts
|
|
502
|
+
* import "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
503
|
+
*
|
|
504
|
+
* const earth = document.querySelector("chikyu-earth-realistic")!;
|
|
505
|
+
* earth.smoothFps = 24;
|
|
506
|
+
* ```
|
|
507
|
+
*/
|
|
508
|
+
get smoothFps(): number;
|
|
509
|
+
set smoothFps(value: number);
|
|
489
510
|
/**
|
|
490
511
|
* The longest a satellite's streak may be on the screen, in CSS pixels (the attribute `satellite-streak-max`; 8 when the page says nothing; `0` or `off` for no cap). Above 60 times real time each satellite is drawn as a streak along its orbit
|
|
491
512
|
* for the stretch one frame spans, and at a fast clock that stretch is long: at an hour a second a low satellite would cross a tenth of the Earth in one frame. The cap is a length on the screen, so a low and a high satellite are drawn equally long, and the streak keeps the look it has at 10 minutes a second at any speed. It is the smaller of this number of pixels and 0.025 of the Earth's drawn radius (about 160 km of orbit, what a low satellite covers in a frame at 10 minutes a second), so as the Earth is drawn smaller the streak shrinks in proportion, to a dot, instead of staying as long on a small Earth as on a large one. The marks also lose weight on a small Earth: below a drawn radius of 150 pixels the streaks are fainter and the dark rim of the dots fades, gone at 40 pixels, and a crowd of satellites on a small Earth is drawn fainter in proportion so thousands of them do not wash it. Pointing along the orbit and ending at the satellite, it is the same length at any frame rate. Off restores the whole stretch.
|
|
@@ -38,7 +38,8 @@ import { COUNTRY_NAMES_ATTRIBUTES } from "../country-names/geometry.js";
|
|
|
38
38
|
import { COUNTRY_NAMES_STYLE, createCountryHost } from "../country-names/host.js";
|
|
39
39
|
import { SEA_NAMES_ATTRIBUTES, readSeaNames } from "../sea-names/geometry.js";
|
|
40
40
|
import { SEA_NAMES_STYLE, createSeaHost } from "../sea-names/host.js";
|
|
41
|
-
import { createGate, frameCap } from "./gate.js";
|
|
41
|
+
import { createGate, frameCap, smallDevice } from "./gate.js";
|
|
42
|
+
import { framesPerSecond, readSmoothFps, smoothCap, SMOOTH_UP_TO, waitFor, watchLowBattery } from "./pace.js";
|
|
42
43
|
import { setSharedRenderer, setThreeLoader, takeRenderer } from "./shared.js";
|
|
43
44
|
export { setSharedRenderer, setThreeLoader };
|
|
44
45
|
import { MAX_TEXTURE, TIERS } from "./tiers.js";
|
|
@@ -165,12 +166,16 @@ export const readTime = (value) => {
|
|
|
165
166
|
* ```
|
|
166
167
|
*/
|
|
167
168
|
export class ChikyuEarthRealistic extends HTMLElement {
|
|
168
|
-
static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "satellite-tint", "satellite-streak-max", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far"];
|
|
169
|
+
static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "smooth-fps", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "satellite-tint", "satellite-streak-max", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far"];
|
|
169
170
|
#model = newModel();
|
|
170
171
|
#paint = createPaintState();
|
|
171
172
|
#mode = "now";
|
|
172
173
|
#view;
|
|
173
174
|
#gate;
|
|
175
|
+
/** Whether the battery is low (at 20% or less and not charging): the smooth frame rate is halved. */
|
|
176
|
+
#lowBattery = false;
|
|
177
|
+
/** What `#wait` last worked out, for `stats`. */
|
|
178
|
+
#pace = { pixelsPerSecond: 0, perSecond: 0, cap: 0, waitMs: 0 };
|
|
174
179
|
#tick;
|
|
175
180
|
/** The clock's speed when `speed` is given (attribute or property); `null` follows `time`: real time for "now", held for a date. */
|
|
176
181
|
#speed = null;
|
|
@@ -310,10 +315,12 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
310
315
|
const nav = navigator;
|
|
311
316
|
const cap = frameCap(30, { deviceMemory: nav.deviceMemory, hardwareConcurrency: nav.hardwareConcurrency });
|
|
312
317
|
this.#gate = createGate(1000 / cap, () => this.#view?.invalidate());
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
318
|
+
this.#lowBattery = false;
|
|
319
|
+
watchLowBattery(nav, () => {
|
|
320
|
+
this.#lowBattery = true;
|
|
321
|
+
this.#gate?.setMinMs(1000 / Math.min(cap, 15));
|
|
322
|
+
this.#startTick();
|
|
323
|
+
});
|
|
317
324
|
const maxRatio = readRatio(this.getAttribute("max-ratio"));
|
|
318
325
|
if (maxRatio)
|
|
319
326
|
this.#model.ratio = () => Math.min(globalThis.devicePixelRatio || 1, 2, maxRatio);
|
|
@@ -473,7 +480,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
473
480
|
this.lights = value !== "off";
|
|
474
481
|
else if (name === "light")
|
|
475
482
|
this.light = readLight(value);
|
|
476
|
-
else if (name === "live-seconds")
|
|
483
|
+
else if (name === "live-seconds" || name === "smooth-fps")
|
|
477
484
|
this.#startTick();
|
|
478
485
|
else if (name === "tiles" || name === "tiles-finer" || name === "tiles-finer-layer" || name === "tiles-finer-date" || name === "tiles-finer-timeout")
|
|
479
486
|
this.#gate?.soon();
|
|
@@ -1219,6 +1226,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1219
1226
|
state: this.#state,
|
|
1220
1227
|
tiers: { ...this.#tiers },
|
|
1221
1228
|
satellites: this.#satelliteStats(),
|
|
1229
|
+
pace: { ...this.#pace },
|
|
1222
1230
|
lightFade: { mix: this.#model.lightFade.mix, fading: this.#model.lightFade.fading },
|
|
1223
1231
|
paths: this.#pathControls?.stats() ?? emptyPathStats(),
|
|
1224
1232
|
tiles: this.#model.tiles?.stats ?? { ready: false, level: null, held: 0, shown: 0, loading: 0, failed: 0, requested: 0, heldBytes: 0, refused: 0, used: {}, finer: null, fading: false },
|
|
@@ -1270,6 +1278,27 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1270
1278
|
else
|
|
1271
1279
|
this.removeAttribute("satellite-tint");
|
|
1272
1280
|
}
|
|
1281
|
+
/**
|
|
1282
|
+
* The most steps a second drawn for a clock at real time, or up to 60 times it (the attribute `smooth-fps`; 15 when the page says nothing; 1 to 30). The picture is drawn each time the quickest thing in it (the Sun's turn at this zoom, a satellite dot)
|
|
1283
|
+
* has moved half a pixel, at least once a second while satellites are on show, and at most this many. Half as many on a small device or a battery at 20% or lower; one a second for a reader who asked for reduced motion.
|
|
1284
|
+
*
|
|
1285
|
+
* @example
|
|
1286
|
+
* ```ts
|
|
1287
|
+
* import "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
1288
|
+
*
|
|
1289
|
+
* const earth = document.querySelector("chikyu-earth-realistic")!;
|
|
1290
|
+
* earth.smoothFps = 24;
|
|
1291
|
+
* ```
|
|
1292
|
+
*/
|
|
1293
|
+
get smoothFps() {
|
|
1294
|
+
return readSmoothFps(this.getAttribute("smooth-fps"));
|
|
1295
|
+
}
|
|
1296
|
+
set smoothFps(value) {
|
|
1297
|
+
if (Number.isFinite(value) && value > 0)
|
|
1298
|
+
this.setAttribute("smooth-fps", String(value));
|
|
1299
|
+
else
|
|
1300
|
+
this.removeAttribute("smooth-fps");
|
|
1301
|
+
}
|
|
1273
1302
|
/**
|
|
1274
1303
|
* The longest a satellite's streak may be on the screen, in CSS pixels (the attribute `satellite-streak-max`; 8 when the page says nothing; `0` or `off` for no cap). Above 60 times real time each satellite is drawn as a streak along its orbit
|
|
1275
1304
|
* for the stretch one frame spans, and at a fast clock that stretch is long: at an hour a second a low satellite would cross a tenth of the Earth in one frame. The cap is a length on the screen, so a low and a high satellite are drawn equally long, and the streak keeps the look it has at 10 minutes a second at any speed. It is the smaller of this number of pixels and 0.025 of the Earth's drawn radius (about 160 km of orbit, what a low satellite covers in a frame at 10 minutes a second), so as the Earth is drawn smaller the streak shrinks in proportion, to a dot, instead of staying as long on a small Earth as on a large one. The marks also lose weight on a small Earth: below a drawn radius of 150 pixels the streaks are fainter and the dark rim of the dots fades, gone at 40 pixels, and a crowd of satellites on a small Earth is drawn fainter in proportion so thousands of them do not wash it. Pointing along the orbit and ending at the satellite, it is the same length at any frame rate. Off restores the whole stretch.
|
|
@@ -1678,19 +1707,33 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1678
1707
|
this.#model.time += (now - this.#last) * this.speed;
|
|
1679
1708
|
this.#last = now;
|
|
1680
1709
|
}
|
|
1681
|
-
/** The
|
|
1710
|
+
/** The quickest a satellite on show goes, in Earth radii for each second of game time: the quickest the groups report between their two SGP4 moments, or, before they have any (and above the interpolation limit, where they do not), a low orbit's. */
|
|
1711
|
+
#satelliteRate() {
|
|
1712
|
+
let most = 0;
|
|
1713
|
+
for (const [name, group] of this.#model.satellites.groups)
|
|
1714
|
+
if (satelliteEmphasis(name, group.visible, this.#model.satellites.focus).drawn)
|
|
1715
|
+
most = Math.max(most, group.satellites.fastest);
|
|
1716
|
+
return most > 0 && Math.abs(this.speed) <= SMOOTH_UP_TO ? most : SATELLITE_RATE * RAD;
|
|
1717
|
+
}
|
|
1718
|
+
/**
|
|
1719
|
+
* The wait before the next step: a step each time the quickest thing in the picture has moved half a pixel (the Sun's turn at this zoom, or a satellite dot: the quickest of the groups on show, from the places they hold for the interpolation),
|
|
1720
|
+
* at most `smooth-fps` a second (15), half as many on a small device or a low battery, and at least once a second while satellites are on show. With only the Earth turning, real time waits up to `live-seconds` (a minute by default).
|
|
1721
|
+
* A reader who asked for reduced motion gets one a second at most. Faster than 60 times real time it is a step for each pixel, up to 30 a second.
|
|
1722
|
+
*/
|
|
1682
1723
|
#wait() {
|
|
1683
1724
|
const seconds = Number(this.getAttribute("live-seconds"));
|
|
1684
1725
|
const live = Number.isFinite(seconds) && seconds > 0 ? Math.max(MIN_TICK_MS, seconds * 1000) : LIVE_TICK_MS;
|
|
1685
1726
|
const speed = Math.abs(this.speed);
|
|
1686
1727
|
const satellites = this.#satellitesMoving();
|
|
1687
|
-
// satellites go round in 90 minutes, so with any on show even real time is drawn about once a second
|
|
1688
|
-
if (speed <= 1 && !satellites)
|
|
1689
|
-
return live;
|
|
1690
|
-
if (typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches)
|
|
1691
|
-
return Math.min(live, 1000);
|
|
1692
1728
|
const radius = this.#model.drawn?.radius ?? 200;
|
|
1693
|
-
|
|
1729
|
+
const pixelsPerSecond = Math.max(SUN_RATE * RAD * speed * radius, satellites ? this.#satelliteRate() * speed * radius : 0);
|
|
1730
|
+
const nav = navigator;
|
|
1731
|
+
const cap = smoothCap(this.smoothFps, this.#lowBattery || smallDevice({ deviceMemory: nav.deviceMemory, hardwareConcurrency: nav.hardwareConcurrency }));
|
|
1732
|
+
const perSecond = framesPerSecond({ pixelsPerSecond, speed: this.speed, cap, reduced: prefersLessMotion(), always: satellites });
|
|
1733
|
+
// a hidden tab is not drawn: it is looked at once a second, as the browser would have it anyway
|
|
1734
|
+
const wait = Math.max(waitFor(perSecond, live), document.visibilityState === "hidden" ? 1000 : 0);
|
|
1735
|
+
this.#pace = { pixelsPerSecond, perSecond, cap, waitMs: wait };
|
|
1736
|
+
return wait;
|
|
1694
1737
|
}
|
|
1695
1738
|
/** Is anything on show that moves faster than the Earth turns: a group of satellites, including above the interpolation limit where they are drawn as streaks? */
|
|
1696
1739
|
#satellitesMoving() {
|