@johnmorrisdotca/chikyu-earth 0.53.0 → 0.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/NOTICE.md +4 -0
- package/README.md +2 -2
- package/dist/flat/colours.d.ts +22 -0
- package/dist/flat/colours.js +22 -0
- package/dist/flat/element.d.ts +18 -1
- package/dist/flat/element.js +111 -22
- package/dist/flat/index.d.ts +2 -1
- package/dist/flat/index.js +2 -1
- package/dist/flat/track-state.d.ts +174 -0
- package/dist/flat/track-state.js +223 -0
- package/dist/flat/words.js +10 -0
- package/dist/passes/index.d.ts +2 -1
- package/dist/passes/index.js +1 -1
- package/dist/passes/passes.d.ts +34 -0
- package/dist/passes/passes.js +43 -2
- package/dist/photos/index.d.ts +232 -0
- package/dist/photos/index.js +284 -0
- package/dist/realistic/element-base.d.ts +6 -0
- package/dist/realistic/element-base.js +15 -2
- package/dist/space/compass.d.ts +36 -0
- package/dist/space/compass.js +72 -0
- package/dist/space/element-base.d.ts +48 -1
- package/dist/space/element-base.js +95 -6
- package/dist/space/index.d.ts +2 -1
- package/dist/space/index.js +1 -0
- package/dist/space/north-up.d.ts +86 -0
- package/dist/space/north-up.js +104 -0
- package/dist/space/path-controls.d.ts +1 -1
- package/dist/space/path-controls.js +13 -2
- package/dist/space/path-ribbons.d.ts +4 -0
- package/dist/space/path-ribbons.js +8 -4
- package/dist/space/satellite-layer.d.ts +5 -0
- package/dist/space/satellite-layer.js +16 -4
- package/dist/space/scene.d.ts +23 -0
- package/dist/space/scene.js +18 -1
- package/package.json +6 -1
|
@@ -0,0 +1,284 @@
|
|
|
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, 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. Read from NASA's capabilities document on 2026-11-17.
|
|
66
|
+
*/
|
|
67
|
+
const LAYERS = [
|
|
68
|
+
{
|
|
69
|
+
id: "VIIRS_NOAA20_CorrectedReflectance_TrueColor",
|
|
70
|
+
running: true,
|
|
71
|
+
days: [["2018-01-05", "2018-02-21"], ["2018-02-24", "2018-03-12"], ["2018-03-14", "2019-12-31"], ["2020-01-02", "2022-01-12"], ["2022-01-14", "2026-11-16"]],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: "VIIRS_SNPP_CorrectedReflectance_TrueColor",
|
|
75
|
+
running: false,
|
|
76
|
+
days: [["2015-11-24", "2022-07-27"], ["2022-08-10", "2024-05-31"], ["2024-06-04", "2024-07-11"], ["2024-07-16", "2024-07-24"], ["2024-07-29", "2024-11-03"], ["2024-11-06", "2026-04-28"], ["2026-04-30", "2026-07-10"], ["2026-07-16", "2026-11-02"]],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: "MODIS_Terra_CorrectedReflectance_TrueColor",
|
|
80
|
+
running: true,
|
|
81
|
+
days: [["2000-02-24", "2000-04-25"], ["2000-04-28", "2000-08-06"], ["2000-08-18", "2001-06-15"], ["2001-07-03", "2002-03-19"], ["2002-03-28", "2003-12-16"], ["2003-12-24", "2008-12-20"], ["2008-12-23", "2016-02-18"], ["2016-02-27", "2022-10-10"], ["2022-10-23", "2026-11-17"]],
|
|
82
|
+
},
|
|
83
|
+
];
|
|
84
|
+
/** Whether the layer lists the day, or is still running and the day is after its last. */
|
|
85
|
+
const hasDay = (layer, day) => {
|
|
86
|
+
const last = layer.days[layer.days.length - 1][1];
|
|
87
|
+
if (day > last)
|
|
88
|
+
return layer.running;
|
|
89
|
+
return layer.days.some(([start, end]) => day >= start && day <= end);
|
|
90
|
+
};
|
|
91
|
+
const clamp = (value, low, high) => Math.min(high, Math.max(low, value));
|
|
92
|
+
const trim = (value) => String(Number(value.toFixed(5)));
|
|
93
|
+
/** The UTC day of a date option, or a RangeError when it is not one. */
|
|
94
|
+
function dayOf(date) {
|
|
95
|
+
if (typeof date === "string") {
|
|
96
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(date);
|
|
97
|
+
const check = match ? new Date(Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]))) : null;
|
|
98
|
+
if (!match || !check || utcDay(check.getTime()) !== date)
|
|
99
|
+
throw new RangeError(`date must be yyyy-mm-dd, a Date or milliseconds: ${date}`);
|
|
100
|
+
return date;
|
|
101
|
+
}
|
|
102
|
+
const ms = date instanceof Date ? date.getTime() : date;
|
|
103
|
+
if (!Number.isFinite(ms))
|
|
104
|
+
throw new RangeError("date must be yyyy-mm-dd, a Date or milliseconds");
|
|
105
|
+
return utcDay(ms);
|
|
106
|
+
}
|
|
107
|
+
function readOptions(options) {
|
|
108
|
+
const { lat, lon, sizeKm, widthPx } = options;
|
|
109
|
+
if (!Number.isFinite(lat) || !Number.isFinite(lon) || !Number.isFinite(sizeKm))
|
|
110
|
+
throw new RangeError("lat, lon and sizeKm must be finite numbers");
|
|
111
|
+
const width = widthPx === undefined ? PHOTO_DEFAULT_PX : widthPx;
|
|
112
|
+
if (!Number.isFinite(width))
|
|
113
|
+
throw new RangeError("widthPx must be a finite number");
|
|
114
|
+
return {
|
|
115
|
+
lat: clamp(lat, -90, 90),
|
|
116
|
+
lon: ((((lon + 180) % 360) + 360) % 360) - 180,
|
|
117
|
+
sizeKm: clamp(sizeKm, PHOTO_MIN_KM, PHOTO_MAX_KM),
|
|
118
|
+
day: dayOf(options.date),
|
|
119
|
+
widthPx: clamp(Math.round(width), 1, PHOTO_MAX_PX),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 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.
|
|
124
|
+
* 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.
|
|
125
|
+
*
|
|
126
|
+
* @param options - The point and the size; the date and the width are not read.
|
|
127
|
+
* @returns The box.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* import { photoBox } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
132
|
+
*
|
|
133
|
+
* const fiji = photoBox({ lat: -17.7, lon: 179.9, sizeKm: 200, date: "2026-11-10" });
|
|
134
|
+
* console.log(fiji.wraps, fiji.east > 180);
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export function photoBox(options) {
|
|
138
|
+
const { lat, lon, sizeKm } = readOptions(options);
|
|
139
|
+
const height = sizeKm / KM_PER_DEGREE;
|
|
140
|
+
const south = clamp(lat - height / 2, -90, 90 - height);
|
|
141
|
+
const north = south + height;
|
|
142
|
+
const cosine = Math.cos((((south + north) / 2) * Math.PI) / 180);
|
|
143
|
+
const span = Math.min(360, height / Math.max(cosine, 1e-9));
|
|
144
|
+
const west = lon - span / 2;
|
|
145
|
+
const east = lon + span / 2;
|
|
146
|
+
return { south, north, west, east, wraps: west < -180 || east > 180 };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 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.
|
|
150
|
+
*
|
|
151
|
+
* @param day - The UTC day, `yyyy-mm-dd`.
|
|
152
|
+
* @returns The layer id, or null.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* import { photoLayer } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
157
|
+
*
|
|
158
|
+
* console.log(photoLayer("2026-11-10"), photoLayer("2010-06-01"), photoLayer("1999-01-01"));
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export function photoLayer(day) {
|
|
162
|
+
return LAYERS.find((layer) => hasDay(layer, day))?.id ?? null;
|
|
163
|
+
}
|
|
164
|
+
function requestFor(layer, west, south, east, north, widthPx, heightPx, day) {
|
|
165
|
+
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}`;
|
|
166
|
+
}
|
|
167
|
+
function piecesFor(box, layer, day, widthPx) {
|
|
168
|
+
const piece = (west, east, offsetPx, width) => ({
|
|
169
|
+
url: requestFor(layer, west, box.south, east, box.north, width, widthPx, day),
|
|
170
|
+
south: box.south,
|
|
171
|
+
north: box.north,
|
|
172
|
+
west,
|
|
173
|
+
east,
|
|
174
|
+
offsetPx,
|
|
175
|
+
widthPx: width,
|
|
176
|
+
heightPx: widthPx,
|
|
177
|
+
});
|
|
178
|
+
if (!box.wraps)
|
|
179
|
+
return [piece(box.west, box.east, 0, widthPx)];
|
|
180
|
+
const span = box.east - box.west;
|
|
181
|
+
const crossesEast = box.east > 180;
|
|
182
|
+
const firstSpan = crossesEast ? 180 - box.west : -180 - box.west;
|
|
183
|
+
const left = clamp(Math.round((widthPx * firstSpan) / span), 1, widthPx - 1);
|
|
184
|
+
if (crossesEast)
|
|
185
|
+
return [piece(box.west, 180, 0, left), piece(-180, box.east - 360, left, widthPx - left)];
|
|
186
|
+
return [piece(box.west + 360, 180, 0, left), piece(-180, box.east, left, widthPx - left)];
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* 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.
|
|
190
|
+
* 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.
|
|
191
|
+
*
|
|
192
|
+
* @param options - The point, the size of the box and the day.
|
|
193
|
+
* @returns The address, or null when no layer has a picture for the day (before 2000-02-24).
|
|
194
|
+
* @throws RangeError when a number is not finite or the date is not a day.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* import { photoUrl } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
199
|
+
*
|
|
200
|
+
* const url = photoUrl({ lat: 35.68, lon: 139.77, sizeKm: 200, date: "2026-11-10", widthPx: 512 });
|
|
201
|
+
* console.log(url?.includes("TIME=2026-11-10"));
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
export function photoUrl(options) {
|
|
205
|
+
const { widthPx, day } = readOptions(options);
|
|
206
|
+
const layer = photoLayer(day);
|
|
207
|
+
if (layer === null)
|
|
208
|
+
return null;
|
|
209
|
+
const box = photoBox(options);
|
|
210
|
+
const shift = box.west < -180 ? -180 - box.west : box.east > 180 ? 180 - box.east : 0;
|
|
211
|
+
return requestFor(layer, box.west + shift, box.south, box.east + shift, box.north, widthPx, widthPx, day);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* 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.
|
|
215
|
+
*
|
|
216
|
+
* @param options - The point, the size of the box and the day.
|
|
217
|
+
* @returns The pieces, or an empty list when no layer has a picture for the day.
|
|
218
|
+
* @throws RangeError when a number is not finite or the date is not a day.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* import { photoPieces } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
223
|
+
*
|
|
224
|
+
* const pieces = photoPieces({ lat: -17.7, lon: 179.9, sizeKm: 200, date: "2026-11-10" });
|
|
225
|
+
* console.log(pieces.length, pieces.map((piece) => piece.widthPx));
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export function photoPieces(options) {
|
|
229
|
+
const { widthPx, day } = readOptions(options);
|
|
230
|
+
const layer = photoLayer(day);
|
|
231
|
+
return layer === null ? [] : piecesFor(photoBox(options), layer, day, widthPx);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* 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.
|
|
235
|
+
*
|
|
236
|
+
* @param options - The point, the size of the box and the first day.
|
|
237
|
+
* @param days - How many days to count back, the first included (3 by default).
|
|
238
|
+
* @returns The shots, each with its day, layer, one address and pieces.
|
|
239
|
+
* @throws RangeError when a number is not finite or the date is not a day.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* import { photoFallbacks } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
244
|
+
*
|
|
245
|
+
* const shots = photoFallbacks({ lat: 35.68, lon: 139.77, sizeKm: 200, date: "2026-11-10" }, 3);
|
|
246
|
+
* console.log(shots.map((shot) => shot.date));
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
export function photoFallbacks(options, days = PHOTO_FALLBACK_DAYS) {
|
|
250
|
+
const { widthPx, day } = readOptions(options);
|
|
251
|
+
const shots = [];
|
|
252
|
+
let at = day;
|
|
253
|
+
const count = clamp(Math.floor(Number.isFinite(days) ? days : PHOTO_FALLBACK_DAYS), 1, 30);
|
|
254
|
+
for (let i = 0; i < count; i += 1) {
|
|
255
|
+
const layer = photoLayer(at);
|
|
256
|
+
if (layer !== null) {
|
|
257
|
+
const dated = { ...options, date: at, widthPx };
|
|
258
|
+
shots.push({ date: at, layer, url: photoUrl(dated), pieces: piecesFor(photoBox(dated), layer, at, widthPx) });
|
|
259
|
+
}
|
|
260
|
+
at = previousUtcDay(Date.parse(`${at}T12:00:00Z`));
|
|
261
|
+
}
|
|
262
|
+
return shots;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* 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.
|
|
266
|
+
* The short line names NASA as the source, as NASA asks, and says it is not an endorsement.
|
|
267
|
+
*
|
|
268
|
+
* @param lang - `en` or `ja`.
|
|
269
|
+
* @param full - True for the whole acknowledgement sentence.
|
|
270
|
+
* @returns The line.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* import { photoCredit } from "@johnmorrisdotca/chikyu-earth/photos";
|
|
275
|
+
*
|
|
276
|
+
* console.log(photoCredit("en"));
|
|
277
|
+
* console.log(photoCredit("ja", true).length > photoCredit("ja").length);
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
export function photoCredit(lang, full = false) {
|
|
281
|
+
if (full)
|
|
282
|
+
return GIBS_CREDIT[lang];
|
|
283
|
+
return lang === "ja" ? "画像:NASA GIBS/Worldview(NASA)。NASAが承認したものではありません。" : "Imagery: NASA GIBS / Worldview (NASA). Not endorsed by NASA.";
|
|
284
|
+
}
|
|
@@ -636,6 +636,12 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
636
636
|
*/
|
|
637
637
|
get selectedPath(): boolean;
|
|
638
638
|
set selectedPath(value: boolean);
|
|
639
|
+
/**
|
|
640
|
+
* Colour the chosen satellite's own orbit by the light on it (the attribute `path-light`; on unless `off`): amber where the satellite is in sunlight and blue where it is in the Earth's shadow (a cylinder of the Earth's radius along the line from the Sun; `--chikyu-path-sun` and `--chikyu-path-shadow` change the two colours, read when the attribute, `selected-path` or the element changes). The width, opacity and dash are still those of the `selected` look.
|
|
641
|
+
* Off, the whole orbit is the `selected` look's one colour, as the orbit always was. The page's other paths (`setPaths`) are not coloured by light. The light is worked out for the moment the orbit was last laid out (it is again every half hour of the clock), and the Sun is taken as fixed over the one revolution the path is.
|
|
642
|
+
*/
|
|
643
|
+
get pathLight(): boolean;
|
|
644
|
+
set pathLight(value: boolean);
|
|
639
645
|
/**
|
|
640
646
|
* How near, in CSS pixels, the pointer has to be to a path for the pick and hover events to report it (the attribute `path-hit`; 8 when left out, 0 to 40; `0` or `off` turns the test off). A touch is given twice that, and at least 16.
|
|
641
647
|
* The test covers the page's paths and the chosen satellite's own orbit, not the part of an orbit the Earth hides, and a satellite's dot under the pointer comes first. In a ride from a satellite the test is off unless the attribute is set.
|
|
@@ -165,7 +165,7 @@ export const readTime = (value) => {
|
|
|
165
165
|
* ```
|
|
166
166
|
*/
|
|
167
167
|
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-hit", "path-priority", "estimate-far"];
|
|
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
169
|
#model = newModel();
|
|
170
170
|
#paint = createPaintState();
|
|
171
171
|
#mode = "now";
|
|
@@ -556,7 +556,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
556
556
|
}
|
|
557
557
|
else if (name === "hover-path" || name === "names-on-hover")
|
|
558
558
|
this.#hover?.sync();
|
|
559
|
-
else if (name === "selected-path")
|
|
559
|
+
else if (name === "selected-path" || name === "path-light")
|
|
560
560
|
this.#pathControls?.sync();
|
|
561
561
|
else if (name === "estimate-far")
|
|
562
562
|
this.#applyEstimate();
|
|
@@ -1562,6 +1562,19 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1562
1562
|
else
|
|
1563
1563
|
this.setAttribute("selected-path", "off");
|
|
1564
1564
|
}
|
|
1565
|
+
/**
|
|
1566
|
+
* Colour the chosen satellite's own orbit by the light on it (the attribute `path-light`; on unless `off`): amber where the satellite is in sunlight and blue where it is in the Earth's shadow (a cylinder of the Earth's radius along the line from the Sun; `--chikyu-path-sun` and `--chikyu-path-shadow` change the two colours, read when the attribute, `selected-path` or the element changes). The width, opacity and dash are still those of the `selected` look.
|
|
1567
|
+
* Off, the whole orbit is the `selected` look's one colour, as the orbit always was. The page's other paths (`setPaths`) are not coloured by light. The light is worked out for the moment the orbit was last laid out (it is again every half hour of the clock), and the Sun is taken as fixed over the one revolution the path is.
|
|
1568
|
+
*/
|
|
1569
|
+
get pathLight() {
|
|
1570
|
+
return !/^(off|false|no|0)$/i.test((this.getAttribute("path-light") ?? "").trim());
|
|
1571
|
+
}
|
|
1572
|
+
set pathLight(value) {
|
|
1573
|
+
if (value)
|
|
1574
|
+
this.removeAttribute("path-light");
|
|
1575
|
+
else
|
|
1576
|
+
this.setAttribute("path-light", "off");
|
|
1577
|
+
}
|
|
1565
1578
|
/**
|
|
1566
1579
|
* How near, in CSS pixels, the pointer has to be to a path for the pick and hover events to report it (the attribute `path-hit`; 8 when left out, 0 to 40; `0` or `off` turns the test off). A touch is given twice that, and at least 16.
|
|
1567
1580
|
* The test covers the page's paths and the chosen satellite's own orbit, not the part of an orbit the Earth hides, and a satellite's dot under the pointer comes first. In a ride from a satellite the test is off unless the attribute is set.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type CompassPoint } from "../flat/track-state.ts";
|
|
2
|
+
import type { RideTrack } from "./scene.ts";
|
|
3
|
+
/** The two languages' words of the compass. `{point}` is the point of the compass and `{deg}` the bearing in whole degrees. */
|
|
4
|
+
export declare const COMPASS_WORDS: {
|
|
5
|
+
readonly en: {
|
|
6
|
+
readonly north: "N";
|
|
7
|
+
readonly heading: "Heading {point} {deg}°";
|
|
8
|
+
readonly label: "Compass: north is shown by the arrow. Heading {point}, {deg} degrees.";
|
|
9
|
+
readonly points: Record<CompassPoint, string>;
|
|
10
|
+
};
|
|
11
|
+
readonly ja: {
|
|
12
|
+
readonly north: "北";
|
|
13
|
+
readonly heading: "進行方向 {point} {deg}°";
|
|
14
|
+
readonly label: "方位磁針:矢印が北を指します。進行方向は{point}、{deg}度。";
|
|
15
|
+
readonly points: Record<CompassPoint, string>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/** The styles of the compass (`#compass`) in an element's shadow root. The dial is white lines on a dark disc, the way-it-goes dot yellow, so it reads on the sea, the land, the night and the day alike; `--chikyu-compass-colour` and `--chikyu-compass-travel` change them. */
|
|
19
|
+
export declare const COMPASS_STYLE = "#compass{position:absolute;left:8px;top:8px;display:flex;flex-direction:column;align-items:center;gap:2px;pointer-events:none;color:var(--chikyu-compass-colour,#fff);font:11px/1.2 system-ui,-apple-system,sans-serif}#compass[hidden]{display:none}#compass svg{width:64px;height:64px;display:block;overflow:visible}#compass .disc{fill:#0b0e14b3;stroke:currentColor;stroke-opacity:.55;stroke-width:1}#compass .north{fill:currentColor}#compass .south{fill:currentColor;fill-opacity:.35}#compass .travel{fill:var(--chikyu-compass-travel,#ffd166);stroke:#0b0e14;stroke-width:1}#compass text{fill:currentColor;font:600 11px system-ui,-apple-system,sans-serif;text-anchor:middle;dominant-baseline:central;paint-order:stroke;stroke:#0b0e14;stroke-width:2.5px}#compass .words{background:#0b0e14b3;padding:1px 6px;border-radius:4px;white-space:nowrap}#compass .words[hidden]{display:none}";
|
|
20
|
+
/** The compass's markup: put it in the shadow root and hand it to `createCompass`. */
|
|
21
|
+
export declare const COMPASS_HTML = "<div id=\"compass\" role=\"img\" hidden><svg viewBox=\"-36 -36 72 72\" aria-hidden=\"true\"><circle class=\"disc\" r=\"25\"></circle><g class=\"arrow\"><path class=\"north\" d=\"M0 -21 L5 -3 L0 -7 L-5 -3 Z\"></path><path class=\"south\" d=\"M0 21 L4 4 L0 7 L-4 4 Z\"></path></g><text class=\"n\" x=\"0\" y=\"-31\">N</text><circle class=\"travel\" r=\"3.4\" cx=\"0\" cy=\"-25\"></circle></svg><span class=\"words\"></span></div>";
|
|
22
|
+
export type CompassMode = "full" | "north" | "off";
|
|
23
|
+
/** Read the attribute `compass`: `off` takes the compass away, `north` shows the arrow without the words, anything else (or nothing) shows both. */
|
|
24
|
+
export declare function readCompass(value: string | null): CompassMode;
|
|
25
|
+
export interface Compass {
|
|
26
|
+
/** Show what the last draw found (or hide the compass for `null`). Changes the page only when something it shows moved by half a degree (the words: a whole degree), the language or the mode changed, so a view at rest does nothing. */
|
|
27
|
+
update(track: RideTrack | null, lang: "en" | "ja", mode: CompassMode): void;
|
|
28
|
+
/** What the compass shows now, for a test: the angle of the arrow, the angle of the dot and the words; `null` when it is hidden. */
|
|
29
|
+
readonly shown: {
|
|
30
|
+
northDeg: number;
|
|
31
|
+
travelDeg: number | null;
|
|
32
|
+
text: string;
|
|
33
|
+
} | null;
|
|
34
|
+
}
|
|
35
|
+
/** Take the markup the element put in its shadow root and make the compass of it. */
|
|
36
|
+
export declare function createCompass(root: ShadowRoot): Compass;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// The compass mark on a ride's picture: a small dial in the element's shadow root with an arrow that points to north, a dot on its rim for the way the satellite is going, and the heading in words ("Heading SE 128°"). It is a few DOM nodes, not the graphics card's,
|
|
2
|
+
// and it is changed only by the draw that moves it, and only when what it shows has changed by half a degree: a picture at rest touches nothing.
|
|
3
|
+
import { compassPoint } from "../flat/track-state.js";
|
|
4
|
+
/** The two languages' words of the compass. `{point}` is the point of the compass and `{deg}` the bearing in whole degrees. */
|
|
5
|
+
export const COMPASS_WORDS = {
|
|
6
|
+
en: { north: "N", heading: "Heading {point} {deg}°", label: "Compass: north is shown by the arrow. Heading {point}, {deg} degrees.", points: { N: "N", NE: "NE", E: "E", SE: "SE", S: "S", SW: "SW", W: "W", NW: "NW" } },
|
|
7
|
+
ja: { north: "北", heading: "進行方向 {point} {deg}°", label: "方位磁針:矢印が北を指します。進行方向は{point}、{deg}度。", points: { N: "北", NE: "北東", E: "東", SE: "南東", S: "南", SW: "南西", W: "西", NW: "北西" } },
|
|
8
|
+
};
|
|
9
|
+
/** The styles of the compass (`#compass`) in an element's shadow root. The dial is white lines on a dark disc, the way-it-goes dot yellow, so it reads on the sea, the land, the night and the day alike; `--chikyu-compass-colour` and `--chikyu-compass-travel` change them. */
|
|
10
|
+
export const COMPASS_STYLE = "#compass{position:absolute;left:8px;top:8px;display:flex;flex-direction:column;align-items:center;gap:2px;pointer-events:none;color:var(--chikyu-compass-colour,#fff);font:11px/1.2 system-ui,-apple-system,sans-serif}#compass[hidden]{display:none}#compass svg{width:64px;height:64px;display:block;overflow:visible}#compass .disc{fill:#0b0e14b3;stroke:currentColor;stroke-opacity:.55;stroke-width:1}#compass .north{fill:currentColor}#compass .south{fill:currentColor;fill-opacity:.35}#compass .travel{fill:var(--chikyu-compass-travel,#ffd166);stroke:#0b0e14;stroke-width:1}#compass text{fill:currentColor;font:600 11px system-ui,-apple-system,sans-serif;text-anchor:middle;dominant-baseline:central;paint-order:stroke;stroke:#0b0e14;stroke-width:2.5px}#compass .words{background:#0b0e14b3;padding:1px 6px;border-radius:4px;white-space:nowrap}#compass .words[hidden]{display:none}";
|
|
11
|
+
/** The compass's markup: put it in the shadow root and hand it to `createCompass`. */
|
|
12
|
+
export const COMPASS_HTML = '<div id="compass" role="img" hidden><svg viewBox="-36 -36 72 72" aria-hidden="true"><circle class="disc" r="25"></circle><g class="arrow"><path class="north" d="M0 -21 L5 -3 L0 -7 L-5 -3 Z"></path><path class="south" d="M0 21 L4 4 L0 7 L-4 4 Z"></path></g><text class="n" x="0" y="-31">N</text><circle class="travel" r="3.4" cx="0" cy="-25"></circle></svg><span class="words"></span></div>';
|
|
13
|
+
/** Read the attribute `compass`: `off` takes the compass away, `north` shows the arrow without the words, anything else (or nothing) shows both. */
|
|
14
|
+
export function readCompass(value) {
|
|
15
|
+
const text = (value ?? "").trim().toLowerCase();
|
|
16
|
+
return text === "off" || text === "false" || text === "no" || text === "none" ? "off" : text === "north" ? "north" : "full";
|
|
17
|
+
}
|
|
18
|
+
/** Take the markup the element put in its shadow root and make the compass of it. */
|
|
19
|
+
export function createCompass(root) {
|
|
20
|
+
const box = root.getElementById("compass");
|
|
21
|
+
const arrow = box.querySelector(".arrow");
|
|
22
|
+
const letter = box.querySelector("text.n");
|
|
23
|
+
const dot = box.querySelector(".travel");
|
|
24
|
+
const words = box.querySelector(".words");
|
|
25
|
+
let key = "";
|
|
26
|
+
let shown = null;
|
|
27
|
+
return {
|
|
28
|
+
update(track, lang, mode) {
|
|
29
|
+
if (!track || mode === "off" || track.northDeg === null) {
|
|
30
|
+
if (!box.hidden)
|
|
31
|
+
box.hidden = true;
|
|
32
|
+
key = "";
|
|
33
|
+
shown = null;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const north = Math.round(track.northDeg * 2) / 2;
|
|
37
|
+
const travel = track.travelDeg === null ? null : Math.round(track.travelDeg * 2) / 2;
|
|
38
|
+
const bearing = Math.round(track.bearingDeg) % 360;
|
|
39
|
+
const next = `${north}|${travel}|${bearing}|${lang}|${mode}`;
|
|
40
|
+
if (next === key && !box.hidden)
|
|
41
|
+
return;
|
|
42
|
+
key = next;
|
|
43
|
+
const set = COMPASS_WORDS[lang];
|
|
44
|
+
const text = set.heading.replace("{point}", set.points[compassPoint(bearing)]).replace("{deg}", String(bearing));
|
|
45
|
+
arrow.setAttribute("transform", `rotate(${north})`);
|
|
46
|
+
// the letter stays upright, at the arrow's tip
|
|
47
|
+
const a = north * (Math.PI / 180);
|
|
48
|
+
letter.setAttribute("x", (31 * Math.sin(a)).toFixed(2));
|
|
49
|
+
letter.setAttribute("y", (-31 * Math.cos(a)).toFixed(2));
|
|
50
|
+
if (letter.textContent !== set.north)
|
|
51
|
+
letter.textContent = set.north;
|
|
52
|
+
if (travel === null)
|
|
53
|
+
dot.setAttribute("visibility", "hidden");
|
|
54
|
+
else {
|
|
55
|
+
dot.removeAttribute("visibility");
|
|
56
|
+
const t = travel * (Math.PI / 180);
|
|
57
|
+
dot.setAttribute("cx", (25 * Math.sin(t)).toFixed(2));
|
|
58
|
+
dot.setAttribute("cy", (-25 * Math.cos(t)).toFixed(2));
|
|
59
|
+
}
|
|
60
|
+
words.textContent = text;
|
|
61
|
+
words.hidden = mode === "north";
|
|
62
|
+
box.setAttribute("aria-label", set.label.replace("{point}", set.points[compassPoint(bearing)]).replace("{deg}", String(bearing)));
|
|
63
|
+
box.lang = lang;
|
|
64
|
+
if (box.hidden)
|
|
65
|
+
box.hidden = false;
|
|
66
|
+
shown = { northDeg: north, travelDeg: travel, text };
|
|
67
|
+
},
|
|
68
|
+
get shown() {
|
|
69
|
+
return shown;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -21,9 +21,10 @@ import { type SatelliteScreen, type SatelliteStyle } from "./satellite-layer.ts"
|
|
|
21
21
|
import { type SatelliteOthers } from "./satellite-focus.ts";
|
|
22
22
|
import { type PathStats } from "./path-controls.ts";
|
|
23
23
|
import { type PathHit, type PathRequest, type PathStyle } from "./paths.ts";
|
|
24
|
+
import type { RideUp } from "./north-up.ts";
|
|
24
25
|
import { type RideDrag, type RideFace, type RideLook, type RideModelSize, type RideViewpoint } from "./ride.ts";
|
|
25
26
|
import { type ScaleMode } from "./scale.ts";
|
|
26
|
-
import { BODY_NAMES, type CameraMode, type BodyName, type BodyPainter, type RideTarget, type SatellitePainter } from "./scene.ts";
|
|
27
|
+
import { BODY_NAMES, type CameraMode, type BodyName, type BodyPainter, type RideTarget, type RideTrack, type SatellitePainter } from "./scene.ts";
|
|
27
28
|
import { type PaintSpec } from "../paint/buffer.ts";
|
|
28
29
|
export { BODY_NAMES, type BodyName, type CameraMode, type RideTarget };
|
|
29
30
|
/**
|
|
@@ -127,6 +128,8 @@ export interface RideOptions {
|
|
|
127
128
|
modelSize?: RideModelSize;
|
|
128
129
|
/** What a drag does in an outside ride from the satellite (`view: "from"`): `head` (the default, or the element's `ride-drag`) turns the view where the camera is, like turning your head, so the camera keeps its place behind and above the satellite and the scene turns round it; `orbit` takes the camera round the satellite as it looks about, so the satellite stays in the same place in the picture and is seen from every side, as a ride did up to 0.51. */
|
|
129
130
|
drag?: RideDrag;
|
|
131
|
+
/** Which way is up in the view above a satellite (`view: "above"`): `travel` (the default, or the element's `ride-up`) puts the way the satellite is going at the top of the picture, `north` puts north there, so the satellite is seen to go the way it really goes over the ground. Within 3 degrees of a pole it is `travel` (mixed in smoothly out to 6). A drag turns the picture from there. */
|
|
132
|
+
up?: RideUp;
|
|
130
133
|
distanceKm?: number;
|
|
131
134
|
smooth?: boolean;
|
|
132
135
|
}
|
|
@@ -153,6 +156,8 @@ export interface Riding {
|
|
|
153
156
|
modelSize: RideModelSize;
|
|
154
157
|
/** `head` or `orbit` (see `RideOptions`). */
|
|
155
158
|
drag: RideDrag;
|
|
159
|
+
/** `travel` or `north` (see `RideOptions`). */
|
|
160
|
+
up: RideUp;
|
|
156
161
|
}
|
|
157
162
|
type SatelliteStats = {
|
|
158
163
|
groups: number;
|
|
@@ -606,6 +611,36 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
606
611
|
*/
|
|
607
612
|
get rideDrag(): RideDrag;
|
|
608
613
|
set rideDrag(value: RideDrag);
|
|
614
|
+
/**
|
|
615
|
+
* Which way is up in the picture of a ride above a satellite (the attribute `ride-up`): `travel` (the default) keeps the way the satellite is going at the top, so the picture turns as the heading does; `north` keeps north at the top, so the satellite is seen to go south-east, or whichever way
|
|
616
|
+
* it really goes over the ground. Within 3 degrees of a pole north-up gives way to travel-up (mixed in smoothly out to 6 degrees), because there north's direction swings round faster than a picture can follow. A drag turns the picture from the up it has, so with `north` a drag turns it away from north, and the compass shows where north has gone.
|
|
617
|
+
* It is the default for the next `ride` and, set while riding, turns the picture to the new up in one eased glide (a jump for a reader who asked for reduced motion), keeping the ride and the clock. The other views (`from`, `follow`) keep the way it is going at the top. See `RideOptions.up`.
|
|
618
|
+
*
|
|
619
|
+
* @example
|
|
620
|
+
* ```ts
|
|
621
|
+
* import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
622
|
+
*
|
|
623
|
+
* const space = document.createElement("chikyu-space") as ChikyuSpace;
|
|
624
|
+
* space.rideUp = "north";
|
|
625
|
+
* console.log(space.rideUp);
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
get rideUp(): RideUp;
|
|
629
|
+
set rideUp(value: RideUp);
|
|
630
|
+
/**
|
|
631
|
+
* Where the ridden satellite is over the ground and how it is going, as of the last draw: `lat`, `lon`, `heightKm`, `bearingDeg` (the way its ground track runs, degrees clockwise from north, with the Earth's turn taken out), `ascending` (going north), `sunlit` (the Sun lights it; the Earth's shadow is a cylinder),
|
|
632
|
+
* and where north is in the picture: `northDeg` (degrees clockwise from the top; 0 means north is at the top) and `travelDeg` (the way it goes, in the picture). `null` when no satellite is ridden or followed. A page that prints "heading SE 128°" reads `bearingDeg` and needs no maths of its own;
|
|
633
|
+
* `chikyu-ride-track` is sent with the same object when the whole degree of the heading, `ascending` or `sunlit` changes, never on a timer. It is worked out by the draws the picture makes, so it is as new as the last draw.
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* ```ts
|
|
637
|
+
* import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
638
|
+
*
|
|
639
|
+
* const space = document.createElement("chikyu-space") as ChikyuSpace;
|
|
640
|
+
* console.log(space.rideTrack);
|
|
641
|
+
* ```
|
|
642
|
+
*/
|
|
643
|
+
get rideTrack(): RideTrack | null;
|
|
609
644
|
/**
|
|
610
645
|
* The radius of the ridden satellite's model as a share of the picture's height, 0.02 to 1.2 (the attribute `ride-model-share`), or `null` for the ride's own: 0.22 along the way it goes, 0.17 above the satellite (its size at the lowest height; `ride-model-size="distance"` still shrinks it as the ride rises).
|
|
611
646
|
* Set while riding it glides in 0.4 s (at once for a reader who asked for less motion). `stats.followModel.share` is the share in use.
|
|
@@ -799,6 +834,12 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
799
834
|
*/
|
|
800
835
|
get selectedPath(): boolean;
|
|
801
836
|
set selectedPath(value: boolean);
|
|
837
|
+
/**
|
|
838
|
+
* Colour the chosen satellite's own orbit by the light on it (the attribute `path-light`; on unless `off`): amber where the satellite is in sunlight and blue where it is in the Earth's shadow (a cylinder of the Earth's radius along the line from the Sun; `--chikyu-path-sun` and `--chikyu-path-shadow` change the two colours, read when the attribute, `selected-path` or the element changes). The width, opacity and dash are still those of the `selected` look.
|
|
839
|
+
* Off, the whole orbit is the `selected` look's one colour, as the orbit always was. The page's other paths (`setPaths`) are not coloured by light. The light is worked out for the moment the orbit was last laid out (it is again every half hour of the clock), and the Sun is taken as fixed over the one revolution the path is.
|
|
840
|
+
*/
|
|
841
|
+
get pathLight(): boolean;
|
|
842
|
+
set pathLight(value: boolean);
|
|
802
843
|
/**
|
|
803
844
|
* How near, in CSS pixels, the pointer has to be to a path for the pick and hover events to report it (the attribute `path-hit`; 8 when left out, 0 to 40; `0` or `off` turns the test off). A touch is given twice that, and at least 16.
|
|
804
845
|
* The test covers the page's paths and the chosen satellite's own orbit, not the part of an orbit the Earth hides, and a satellite's dot under the pointer comes first. In a ride from a satellite the test is off unless the attribute is set.
|
|
@@ -894,6 +935,12 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
894
935
|
/** The page's paths: asked for, drawn (with the chosen satellite's own), left out over the cap of 16, unmatched, whether the chosen satellite's own orbit is drawn, draw calls they took at the last draw (0 or 1), the path under the mouse and the `chikyu-path-click` events sent. */
|
|
895
936
|
paths: PathStats;
|
|
896
937
|
ride: {
|
|
938
|
+
track: RideTrack | null;
|
|
939
|
+
compass: {
|
|
940
|
+
northDeg: number;
|
|
941
|
+
travelDeg: number | null;
|
|
942
|
+
text: string;
|
|
943
|
+
} | null;
|
|
897
944
|
riding: boolean;
|
|
898
945
|
lost: boolean;
|
|
899
946
|
gliding: boolean;
|