@johnmorrisdotca/chikyu-earth 0.33.2 → 0.34.1

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +23 -5
  3. package/dist/cities/geometry.d.ts +233 -0
  4. package/dist/cities/geometry.js +174 -0
  5. package/dist/cities/host.d.ts +73 -0
  6. package/dist/cities/host.js +240 -0
  7. package/dist/element.d.ts +1 -1
  8. package/dist/element.js +3 -14
  9. package/dist/markers/index.d.ts +1 -0
  10. package/dist/markers/index.js +1 -0
  11. package/dist/markers/labels.d.ts +7 -1
  12. package/dist/markers/labels.js +12 -1
  13. package/dist/markers/place-layer.d.ts +43 -0
  14. package/dist/markers/place-layer.js +238 -0
  15. package/dist/markers/places.d.ts +279 -0
  16. package/dist/markers/places.js +213 -0
  17. package/dist/passes/element.js +2 -5
  18. package/dist/realistic/body-label.js +19 -11
  19. package/dist/realistic/earth.js +1 -1
  20. package/dist/realistic/element.d.ts +35 -0
  21. package/dist/realistic/element.js +94 -11
  22. package/dist/realistic/index.d.ts +2 -0
  23. package/dist/realistic/index.js +2 -0
  24. package/dist/satellites/index.d.ts +1 -0
  25. package/dist/satellites/index.js +1 -0
  26. package/dist/satellites/names.d.ts +14 -0
  27. package/dist/satellites/names.js +16 -0
  28. package/dist/sky/cover.d.ts +48 -0
  29. package/dist/sky/cover.js +100 -0
  30. package/dist/sky/host.js +48 -18
  31. package/dist/space/element.d.ts +103 -1
  32. package/dist/space/element.js +219 -3
  33. package/dist/space/index.d.ts +3 -1
  34. package/dist/space/index.js +1 -0
  35. package/dist/space/satellite-layer.d.ts +26 -0
  36. package/dist/space/satellite-layer.js +37 -1
  37. package/dist/space/satellite-model.d.ts +72 -0
  38. package/dist/space/satellite-model.js +82 -0
  39. package/dist/space/scene.d.ts +44 -1
  40. package/dist/space/scene.js +154 -2
  41. package/package.json +7 -3
@@ -0,0 +1,279 @@
1
+ import type { GeoPoint } from "../types.ts";
2
+ import { type Pose } from "./project.ts";
3
+ /**
4
+ * What a place is to the reader: `here` (where they are, drawn bright, with a quiet pulse) or `favourite` (a place they keep, drawn quieter).
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import type { PlaceKind } from "@johnmorrisdotca/chikyu-earth/markers";
9
+ *
10
+ * const kind: PlaceKind = "here";
11
+ * console.log(kind);
12
+ * ```
13
+ */
14
+ export type PlaceKind = "here" | "favourite";
15
+ /**
16
+ * One place for the `places` attribute or property of `<chikyu-space>` and `<chikyu-earth-realistic>`. The package keeps none and stores none: the page hands them over.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import type { Place } from "@johnmorrisdotca/chikyu-earth/markers";
21
+ *
22
+ * const places: Place[] = [
23
+ * { id: "me", lon: -79.4, lat: 43.7, label: "You are here", kind: "here" },
24
+ * { id: "tokyo", lon: 139.69, lat: 35.69, label: "Tokyo", kind: "favourite" },
25
+ * ];
26
+ * console.log(places.length);
27
+ * ```
28
+ */
29
+ export interface Place {
30
+ /** Your own unique name for it. */
31
+ id: string;
32
+ /** Degrees east and north. */
33
+ lon: number;
34
+ lat: number;
35
+ /** Shown at the top of the marker when there is room. */
36
+ label?: string;
37
+ /** `here` or `favourite` (the default). */
38
+ kind?: PlaceKind;
39
+ }
40
+ /**
41
+ * How a place is drawn: `beam` (a light rising out of the ground with a ring at its foot), `pin` (a thin stick with a round head) or `ring` (only the ring on the ground).
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import { PLACE_LOOKS, type PlaceLook } from "@johnmorrisdotca/chikyu-earth/markers";
46
+ *
47
+ * const look: PlaceLook = "pin";
48
+ * console.log(PLACE_LOOKS.includes(look));
49
+ * ```
50
+ */
51
+ export type PlaceLook = "beam" | "pin" | "ring";
52
+ /**
53
+ * Every look a place can have, the default first.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { PLACE_LOOKS } from "@johnmorrisdotca/chikyu-earth/markers";
58
+ *
59
+ * console.log(PLACE_LOOKS.join(", "));
60
+ * ```
61
+ */
62
+ export declare const PLACE_LOOKS: readonly PlaceLook[];
63
+ /**
64
+ * The most places one element draws; the rest of a longer list are left out.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * import { MAX_PLACES } from "@johnmorrisdotca/chikyu-earth/markers";
69
+ *
70
+ * console.log(MAX_PLACES);
71
+ * ```
72
+ */
73
+ export declare const MAX_PLACES = 200;
74
+ /**
75
+ * A point of the Earth's surface as one picture shows it: where it falls (CSS pixels in the box), which way is straight up from the ground there on the screen (`upX`, `upY`: a direction whose
76
+ * length is how much of an upright stick the reader sees, 0 looking straight down on it and 1 seeing it side on) and `facing`, the cosine between the ground's upright and the way to the camera
77
+ * (above 0 the point faces the reader, at or below it is on the far side).
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * import type { SurfacePoint } from "@johnmorrisdotca/chikyu-earth/markers";
82
+ *
83
+ * const middle: SurfacePoint = { x: 210, y: 210, upX: 0, upY: 0, facing: 1 };
84
+ * console.log(middle.facing);
85
+ * ```
86
+ */
87
+ export interface SurfacePoint {
88
+ x: number;
89
+ y: number;
90
+ upX: number;
91
+ upY: number;
92
+ facing: number;
93
+ }
94
+ /**
95
+ * A picture of the Earth for places to be laid on: its box, and a way to find a point of the surface in it (false when the point is behind the camera).
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * import { orthoView, type PlaceView } from "@johnmorrisdotca/chikyu-earth/markers";
100
+ *
101
+ * const view: PlaceView = orthoView({ lon: 0, lat: 0, radius: 200, cx: 210, cy: 210, width: 420, height: 420 });
102
+ * console.log(view.width);
103
+ * ```
104
+ */
105
+ export interface PlaceView {
106
+ width: number;
107
+ height: number;
108
+ at(lon: number, lat: number, out: SurfacePoint): boolean;
109
+ }
110
+ /**
111
+ * Where one place's marker is drawn: the foot on the ground, the top of the stick, the stick's turn and length, the ring's turn, how flat it is and its radius, and how strongly it shows (it fades at the Earth's edge).
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * import { layoutPlaces, orthoView, type PlaceShape } from "@johnmorrisdotca/chikyu-earth/markers";
116
+ *
117
+ * const shape: PlaceShape | undefined = layoutPlaces([{ id: "a", lon: 0, lat: 0 }], orthoView({ lon: 0, lat: 0, radius: 200, cx: 210, cy: 210, width: 420, height: 420 }), "beam").shapes[0];
118
+ * console.log(shape?.length);
119
+ * ```
120
+ */
121
+ export interface PlaceShape {
122
+ /** Index into the places given. */
123
+ index: number;
124
+ x: number;
125
+ y: number;
126
+ tipX: number;
127
+ tipY: number;
128
+ /** The stick's direction, degrees clockwise from straight up on the screen. */
129
+ angle: number;
130
+ /** The stick's length in CSS pixels (0 for the `ring` look). */
131
+ length: number;
132
+ /** The direction of the ring's short axis, degrees clockwise from straight up. */
133
+ ringAngle: number;
134
+ /** The ring's short axis over its long one: 1 seen from straight above, near 0 at the Earth's edge. */
135
+ squash: number;
136
+ /** The ring's radius in CSS pixels. */
137
+ ring: number;
138
+ opacity: number;
139
+ }
140
+ /**
141
+ * Where one place's name goes: which place it is and the top-left corner of its box.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * import type { PlaceLabelSpot } from "@johnmorrisdotca/chikyu-earth/markers";
146
+ *
147
+ * const spot: PlaceLabelSpot = { index: 0, left: 120, top: 80 };
148
+ * console.log(spot.left);
149
+ * ```
150
+ */
151
+ export interface PlaceLabelSpot {
152
+ index: number;
153
+ left: number;
154
+ top: number;
155
+ }
156
+ /**
157
+ * The markers and names of a set of places in one picture.
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * import { layoutPlaces, orthoView, type PlaceLayout } from "@johnmorrisdotca/chikyu-earth/markers";
162
+ *
163
+ * const layout: PlaceLayout = layoutPlaces([], orthoView({ lon: 0, lat: 0, radius: 200, cx: 210, cy: 210, width: 420, height: 420 }), "beam");
164
+ * console.log(layout.shapes.length, layout.labels.length);
165
+ * ```
166
+ */
167
+ export interface PlaceLayout {
168
+ shapes: PlaceShape[];
169
+ labels: PlaceLabelSpot[];
170
+ }
171
+ /**
172
+ * What {@link layoutPlaces} may be told: the size of each name as the page draws it (a place with no size gets no name), boxes another layer already uses, and the most names.
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * import type { PlaceLayoutOptions } from "@johnmorrisdotca/chikyu-earth/markers";
177
+ *
178
+ * const options: PlaceLayoutOptions = { size: () => ({ width: 60, height: 18 }), maxLabels: 8 };
179
+ * console.log(options.maxLabels);
180
+ * ```
181
+ */
182
+ export interface PlaceLayoutOptions {
183
+ size?: (place: Place, index: number) => {
184
+ width: number;
185
+ height: number;
186
+ } | null;
187
+ taken?: readonly {
188
+ left: number;
189
+ top: number;
190
+ width: number;
191
+ height: number;
192
+ }[];
193
+ maxLabels?: number;
194
+ }
195
+ /**
196
+ * The places of a list a page handed over, made safe to draw: each needs a longitude from -180 to 180 and a latitude from -90 to 90; one without an `id` is given its place in the list, a
197
+ * label is cut to 80 letters, a kind that is not `here` is `favourite`. Anything else is left out, and at most {@link MAX_PLACES} are kept.
198
+ *
199
+ * @param list - What the page gave: an array of places, or anything.
200
+ * @returns The places to draw.
201
+ *
202
+ * @example
203
+ * ```ts
204
+ * import { cleanPlaces } from "@johnmorrisdotca/chikyu-earth/markers";
205
+ *
206
+ * console.log(cleanPlaces([{ lon: 2.35, lat: 48.86, label: "Paris" }, { lon: 500, lat: 0 }]));
207
+ * ```
208
+ */
209
+ export declare function cleanPlaces(list: unknown): Place[];
210
+ /**
211
+ * Read the `places` attribute: a JSON array of places (see {@link cleanPlaces}). Anything that is not JSON is no places.
212
+ *
213
+ * @param value - The attribute's text, or null.
214
+ * @returns The places to draw.
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * import { readPlaces } from "@johnmorrisdotca/chikyu-earth/markers";
219
+ *
220
+ * console.log(readPlaces('[{"id":"me","lon":-79.4,"lat":43.7,"kind":"here"}]'));
221
+ * ```
222
+ */
223
+ export declare function readPlaces(value: string | null | undefined): Place[];
224
+ /**
225
+ * A place made less exact: put on a grid about `km` kilometres across, so a reader's own place can be drawn without saying their street. Use it on what the browser's location gives before
226
+ * it is drawn or kept.
227
+ *
228
+ * @param point - Longitude and latitude in degrees.
229
+ * @param km - The grid's size in kilometres (10).
230
+ * @returns The point on the grid, to four decimals.
231
+ *
232
+ * @example
233
+ * ```ts
234
+ * import { nearby } from "@johnmorrisdotca/chikyu-earth/markers";
235
+ *
236
+ * console.log(nearby({ lon: -79.38321, lat: 43.65348 }));
237
+ * ```
238
+ */
239
+ export declare function nearby(point: GeoPoint, km?: number): GeoPoint;
240
+ /**
241
+ * A view for places from a picture drawn straight on, as `<chikyu-earth-realistic>` and the line globe are: the point of the Earth in the middle, the disc's radius and centre and the box's size.
242
+ *
243
+ * @param pose - The view and the box.
244
+ * @returns A view {@link layoutPlaces} can lay places on.
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * import { orthoView } from "@johnmorrisdotca/chikyu-earth/markers";
249
+ *
250
+ * const out = { x: 0, y: 0, upX: 0, upY: 0, facing: 0 };
251
+ * orthoView({ lon: 0, lat: 0, radius: 200, cx: 210, cy: 210, width: 420, height: 420 }).at(90, 0, out);
252
+ * console.log(Math.round(out.x), out.facing < 0.01);
253
+ * ```
254
+ */
255
+ export declare function orthoView(pose: Pose & {
256
+ width: number;
257
+ height: number;
258
+ }): PlaceView;
259
+ /**
260
+ * Where each place's marker and name go in one picture. A place on the far side of the Earth, or off the picture, is left out; one near the Earth's edge fades. The stick stands up from the ground as the picture
261
+ * sees it, leaning towards the top of the screen where the reader looks straight down on it, so it never shrinks to a dot; the ring at its foot is flattened as the ground is. A `here` place is taller and wider
262
+ * than a favourite. Names go at the top of the stick, `here` first and then in the order given, never over one another or over a box in `taken`; a name with no free place is left out.
263
+ *
264
+ * @param places - The places, as {@link cleanPlaces} makes them.
265
+ * @param view - The picture.
266
+ * @param look - `beam`, `pin` or `ring`.
267
+ * @param options - The size of each name, boxes already used and the most names (16).
268
+ * @returns The markers to draw and where the names go.
269
+ *
270
+ * @example
271
+ * ```ts
272
+ * import { layoutPlaces, orthoView } from "@johnmorrisdotca/chikyu-earth/markers";
273
+ *
274
+ * const view = orthoView({ lon: 139.69, lat: 35.69, radius: 200, cx: 210, cy: 210, width: 420, height: 420 });
275
+ * const layout = layoutPlaces([{ id: "tokyo", lon: 139.69, lat: 35.69, label: "Tokyo", kind: "here" }], view, "beam", { size: () => ({ width: 48, height: 18 }) });
276
+ * console.log(layout.shapes[0]?.length, layout.labels.length);
277
+ * ```
278
+ */
279
+ export declare function layoutPlaces(places: readonly Place[], view: PlaceView, look: PlaceLook, options?: PlaceLayoutOptions): PlaceLayout;
@@ -0,0 +1,213 @@
1
+ import { placeLabels } from "./labels.js";
2
+ import { project } from "./project.js";
3
+ /**
4
+ * Every look a place can have, the default first.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { PLACE_LOOKS } from "@johnmorrisdotca/chikyu-earth/markers";
9
+ *
10
+ * console.log(PLACE_LOOKS.join(", "));
11
+ * ```
12
+ */
13
+ export const PLACE_LOOKS = ["beam", "pin", "ring"];
14
+ /**
15
+ * The most places one element draws; the rest of a longer list are left out.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { MAX_PLACES } from "@johnmorrisdotca/chikyu-earth/markers";
20
+ *
21
+ * console.log(MAX_PLACES);
22
+ * ```
23
+ */
24
+ export const MAX_PLACES = 200;
25
+ const RAD = Math.PI / 180;
26
+ /** A place this close to the Earth's edge (the cosine of its angle from the reader) is left out; up to FADE beyond it, it fades in. */
27
+ const EDGE = 0.02;
28
+ const FADE = 0.12;
29
+ const MARGIN = 60;
30
+ const SIZES = { here: { length: 46, ring: 9 }, favourite: { length: 28, ring: 6 } };
31
+ const isObject = (value) => typeof value === "object" && value !== null;
32
+ /**
33
+ * The places of a list a page handed over, made safe to draw: each needs a longitude from -180 to 180 and a latitude from -90 to 90; one without an `id` is given its place in the list, a
34
+ * label is cut to 80 letters, a kind that is not `here` is `favourite`. Anything else is left out, and at most {@link MAX_PLACES} are kept.
35
+ *
36
+ * @param list - What the page gave: an array of places, or anything.
37
+ * @returns The places to draw.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import { cleanPlaces } from "@johnmorrisdotca/chikyu-earth/markers";
42
+ *
43
+ * console.log(cleanPlaces([{ lon: 2.35, lat: 48.86, label: "Paris" }, { lon: 500, lat: 0 }]));
44
+ * ```
45
+ */
46
+ export function cleanPlaces(list) {
47
+ if (!Array.isArray(list))
48
+ return [];
49
+ const out = [];
50
+ for (const [i, item] of list.entries()) {
51
+ if (out.length >= MAX_PLACES)
52
+ break;
53
+ if (!isObject(item))
54
+ continue;
55
+ const lon = Number(item["lon"]);
56
+ const lat = Number(item["lat"]);
57
+ if (!Number.isFinite(lon) || !Number.isFinite(lat) || Math.abs(lon) > 180 || Math.abs(lat) > 90)
58
+ continue;
59
+ const place = { id: typeof item["id"] === "string" && item["id"] ? item["id"] : String(i), lon, lat, kind: item["kind"] === "here" ? "here" : "favourite" };
60
+ if (typeof item["label"] === "string" && item["label"].trim())
61
+ place.label = item["label"].trim().slice(0, 80);
62
+ out.push(place);
63
+ }
64
+ return out;
65
+ }
66
+ /**
67
+ * Read the `places` attribute: a JSON array of places (see {@link cleanPlaces}). Anything that is not JSON is no places.
68
+ *
69
+ * @param value - The attribute's text, or null.
70
+ * @returns The places to draw.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * import { readPlaces } from "@johnmorrisdotca/chikyu-earth/markers";
75
+ *
76
+ * console.log(readPlaces('[{"id":"me","lon":-79.4,"lat":43.7,"kind":"here"}]'));
77
+ * ```
78
+ */
79
+ export function readPlaces(value) {
80
+ if (!value)
81
+ return [];
82
+ try {
83
+ return cleanPlaces(JSON.parse(value));
84
+ }
85
+ catch {
86
+ return [];
87
+ }
88
+ }
89
+ /**
90
+ * A place made less exact: put on a grid about `km` kilometres across, so a reader's own place can be drawn without saying their street. Use it on what the browser's location gives before
91
+ * it is drawn or kept.
92
+ *
93
+ * @param point - Longitude and latitude in degrees.
94
+ * @param km - The grid's size in kilometres (10).
95
+ * @returns The point on the grid, to four decimals.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * import { nearby } from "@johnmorrisdotca/chikyu-earth/markers";
100
+ *
101
+ * console.log(nearby({ lon: -79.38321, lat: 43.65348 }));
102
+ * ```
103
+ */
104
+ export function nearby(point, km = 10) {
105
+ const step = Math.max(km, 0.01) / 111.32;
106
+ const lat = Math.max(-90, Math.min(90, Math.round(point.lat / step) * step));
107
+ const lonStep = Math.min(360, step / Math.max(Math.cos(lat * RAD), 0.01));
108
+ let lon = Math.round(point.lon / lonStep) * lonStep;
109
+ if (lon > 180)
110
+ lon -= 360;
111
+ if (lon < -180)
112
+ lon += 360;
113
+ const four = (n) => Math.round(n * 10_000) / 10_000 || 0;
114
+ return { lon: four(lon), lat: four(lat) };
115
+ }
116
+ /**
117
+ * A view for places from a picture drawn straight on, as `<chikyu-earth-realistic>` and the line globe are: the point of the Earth in the middle, the disc's radius and centre and the box's size.
118
+ *
119
+ * @param pose - The view and the box.
120
+ * @returns A view {@link layoutPlaces} can lay places on.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * import { orthoView } from "@johnmorrisdotca/chikyu-earth/markers";
125
+ *
126
+ * const out = { x: 0, y: 0, upX: 0, upY: 0, facing: 0 };
127
+ * orthoView({ lon: 0, lat: 0, radius: 200, cx: 210, cy: 210, width: 420, height: 420 }).at(90, 0, out);
128
+ * console.log(Math.round(out.x), out.facing < 0.01);
129
+ * ```
130
+ */
131
+ export function orthoView(pose) {
132
+ return {
133
+ width: pose.width,
134
+ height: pose.height,
135
+ at(lon, lat, out) {
136
+ const p = project(lon, lat, pose);
137
+ out.x = p.x;
138
+ out.y = p.y;
139
+ out.upX = (p.x - pose.cx) / pose.radius;
140
+ out.upY = (p.y - pose.cy) / pose.radius;
141
+ out.facing = p.z;
142
+ return true;
143
+ },
144
+ };
145
+ }
146
+ /**
147
+ * Where each place's marker and name go in one picture. A place on the far side of the Earth, or off the picture, is left out; one near the Earth's edge fades. The stick stands up from the ground as the picture
148
+ * sees it, leaning towards the top of the screen where the reader looks straight down on it, so it never shrinks to a dot; the ring at its foot is flattened as the ground is. A `here` place is taller and wider
149
+ * than a favourite. Names go at the top of the stick, `here` first and then in the order given, never over one another or over a box in `taken`; a name with no free place is left out.
150
+ *
151
+ * @param places - The places, as {@link cleanPlaces} makes them.
152
+ * @param view - The picture.
153
+ * @param look - `beam`, `pin` or `ring`.
154
+ * @param options - The size of each name, boxes already used and the most names (16).
155
+ * @returns The markers to draw and where the names go.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * import { layoutPlaces, orthoView } from "@johnmorrisdotca/chikyu-earth/markers";
160
+ *
161
+ * const view = orthoView({ lon: 139.69, lat: 35.69, radius: 200, cx: 210, cy: 210, width: 420, height: 420 });
162
+ * const layout = layoutPlaces([{ id: "tokyo", lon: 139.69, lat: 35.69, label: "Tokyo", kind: "here" }], view, "beam", { size: () => ({ width: 48, height: 18 }) });
163
+ * console.log(layout.shapes[0]?.length, layout.labels.length);
164
+ * ```
165
+ */
166
+ export function layoutPlaces(places, view, look, options = {}) {
167
+ const point = { x: 0, y: 0, upX: 0, upY: 0, facing: 0 };
168
+ const shapes = [];
169
+ const items = [];
170
+ const named = [];
171
+ for (const [index, place] of places.entries()) {
172
+ if (!view.at(place.lon, place.lat, point) || point.facing <= EDGE)
173
+ continue;
174
+ if (point.x < -MARGIN || point.y < -MARGIN || point.x > view.width + MARGIN || point.y > view.height + MARGIN)
175
+ continue;
176
+ const size = SIZES[place.kind === "here" ? "here" : "favourite"];
177
+ const side = Math.min(1, Math.hypot(point.upX, point.upY));
178
+ // straight up from the ground as seen, bent towards the top of the screen as the reader comes to look straight down on it
179
+ let dx = point.upX;
180
+ let dy = point.upY - (1 - side);
181
+ const norm = Math.hypot(dx, dy);
182
+ if (norm < 1e-6) {
183
+ dx = 0;
184
+ dy = -1;
185
+ }
186
+ else {
187
+ dx /= norm;
188
+ dy /= norm;
189
+ }
190
+ const length = look === "ring" ? 0 : size.length * (0.55 + 0.45 * side);
191
+ const shape = {
192
+ index,
193
+ x: point.x,
194
+ y: point.y,
195
+ tipX: point.x + dx * length,
196
+ tipY: point.y + dy * length,
197
+ angle: Math.atan2(dx, -dy) / RAD,
198
+ length,
199
+ ringAngle: side > 1e-4 ? Math.atan2(point.upX, -point.upY) / RAD : 0,
200
+ squash: Math.max(0.08, Math.min(1, point.facing)),
201
+ ring: size.ring,
202
+ opacity: Math.min(1, (point.facing - EDGE) / FADE),
203
+ };
204
+ shapes.push(shape);
205
+ const box = place.label ? options.size?.(place, index) : null;
206
+ if (box) {
207
+ items.push({ x: shape.tipX, y: shape.tipY, r: look === "ring" ? size.ring : 3, w: box.width, h: box.height, priority: place.kind === "here" ? 1 : 0 });
208
+ named.push(index);
209
+ }
210
+ }
211
+ const placed = placeLabels(items, view.width, view.height, options.maxLabels ?? 16, 64, options.taken ?? []);
212
+ return { shapes, labels: placed.map((p) => ({ index: named[p.item], left: p.left, top: p.top })) };
213
+ }
@@ -3,6 +3,7 @@
3
3
  import { adoptStyles } from "../adopt.js";
4
4
  import { fetchElements } from "../satellites/source.js";
5
5
  import { creditLine } from "../data-door.js";
6
+ import { SHORT_NAMES } from "../satellites/names.js";
6
7
  import { createDoorHost } from "../door/host.js";
7
8
  import { mergeElementSets } from "../door/elements.js";
8
9
  import { DEFAULT_DIM_AFTER_DAYS } from "../satellites/limits.js";
@@ -117,11 +118,7 @@ const WORDS = {
117
118
  },
118
119
  };
119
120
  /** The short names of the satellites this element knows, in each language; any other satellite is shown under the name in its elements. */
120
- const SHORT = {
121
- 25544: { en: "ISS", ja: "ISS" },
122
- 48274: { en: "Tiangong", ja: "天宮" },
123
- 20580: { en: "Hubble", ja: "ハッブル" },
124
- };
121
+ const SHORT = SHORT_NAMES;
125
122
  const CSS = `
126
123
  :host{display:block;color:inherit;font:inherit;container-type:inline-size}
127
124
  *{box-sizing:border-box}
@@ -94,7 +94,14 @@ export async function loadMichroma() {
94
94
  export function setBodyLabelFontUrl(url) {
95
95
  fontUrl = url;
96
96
  }
97
- const signatureOf = (state) => (state.settings ? JSON.stringify([state.text, state.settings]) : "");
97
+ const same = (made, state) => {
98
+ const s = state.settings;
99
+ return made !== null && s !== null && made.text === state.text && made.look === s.look && made.strength === s.strength && made.repeat === s.repeat && made.latitude === s.latitude && made.facing === s.facing && made.font === s.font && made.fallbackFont === s.fallbackFont;
100
+ };
101
+ const copyOf = (state) => {
102
+ const s = state.settings;
103
+ return { text: state.text, look: s.look, strength: s.strength, repeat: s.repeat, latitude: s.latitude, facing: s.facing, font: s.font, fallbackFont: s.fallbackFont };
104
+ };
98
105
  /**
99
106
  * Makes the layer that keeps the Earth's name on its globe, inside `parent` (the group or mesh that turns with the Earth, a radius of 1). The family's body label is loaded only when the settings first ask for it, and its font (Michroma, 64 kB) only
100
107
  * when the page has named no font of its own. All three.js parts the label needs must be in `three` (the full three.js has them); without them `onError` is told once and nothing is drawn.
@@ -109,7 +116,7 @@ export function createBodyLabelLayer(three, parent, state, deps) {
109
116
  let label = null;
110
117
  let loading = false;
111
118
  let failed = false;
112
- let signature = "";
119
+ let made = null;
113
120
  let gone = false;
114
121
  const options = () => {
115
122
  const s = state.settings;
@@ -121,7 +128,7 @@ export function createBodyLabelLayer(three, parent, state, deps) {
121
128
  parent.remove(label.object);
122
129
  label.dispose();
123
130
  label = null;
124
- signature = "";
131
+ made = null;
125
132
  state.drawn = { made: false, showing: false };
126
133
  };
127
134
  const make = () => {
@@ -138,13 +145,13 @@ export function createBodyLabelLayer(three, parent, state, deps) {
138
145
  loading = false;
139
146
  return;
140
147
  }
141
- const made = module.createBodyLabel(three, options());
142
- parent.add(made.object);
143
- label = made;
148
+ const created = module.createBodyLabel(three, options());
149
+ parent.add(created.object);
150
+ label = created;
144
151
  state.drawn.made = true;
145
- signature = signatureOf(state);
152
+ made = copyOf(state);
146
153
  loading = false;
147
- void made.ready.then(() => {
154
+ void created.ready.then(() => {
148
155
  if (!gone)
149
156
  deps.invalidate();
150
157
  });
@@ -161,7 +168,9 @@ export function createBodyLabelLayer(three, parent, state, deps) {
161
168
  if (gone)
162
169
  return;
163
170
  if (!state.settings) {
171
+ // switched off: the label goes, and a load that failed may be tried again when it is switched on
164
172
  remove();
173
+ failed = false;
165
174
  return;
166
175
  }
167
176
  if (!label) {
@@ -169,9 +178,8 @@ export function createBodyLabelLayer(three, parent, state, deps) {
169
178
  make();
170
179
  return;
171
180
  }
172
- const now = signatureOf(state);
173
- if (now !== signature) {
174
- signature = now;
181
+ if (!same(made, state)) {
182
+ made = copyOf(state);
175
183
  label.set(options());
176
184
  deps.invalidate();
177
185
  }
@@ -244,7 +244,7 @@ export function createEarthItem(model, deps) {
244
244
  deps.onSky({
245
245
  width: size.width,
246
246
  height: size.height,
247
- discs: [{ x: cx, y: cy, radius }],
247
+ discs: [{ x: cx, y: cy, radius: radius * airTop(model.airThickness) }],
248
248
  project(rightAscension, declination, out) {
249
249
  const r = rightAscension * RAD;
250
250
  const d = declination * RAD;
@@ -6,6 +6,8 @@ import { type SatelliteStyle } from "../space/satellite-layer.ts";
6
6
  import type { Credit, DataSource } from "../data-door.ts";
7
7
  import { type BodyLabelSettings } from "./body-label.ts";
8
8
  import type { SkyLabelStyle } from "../sky/style.ts";
9
+ import { type Place, type PlaceLook } from "../markers/places.ts";
10
+ import { type CityNamesStyle } from "../cities/host.ts";
9
11
  import { setSharedRenderer, setThreeLoader } from "./shared.ts";
10
12
  export { setSharedRenderer, setThreeLoader };
11
13
  export type { CameraMode };
@@ -141,6 +143,22 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
141
143
  */
142
144
  get skyStyle(): Partial<SkyLabelStyle>;
143
145
  set skyStyle(value: Partial<SkyLabelStyle>);
146
+ /**
147
+ * Places marked on the Earth (the attribute `places`, a JSON array): each `{ id, lon, lat, label, kind }`, `kind` being `here` (where the reader is: drawn bright and taller, with a quiet pulse) or `favourite`
148
+ * (the default: quieter). Each stands up out of the ground, turns with the Earth, is hidden on its far side and keeps its size in pixels at any zoom. Names go at the top, `here` first, and never overlap
149
+ * one another; one with no room is left out. The element stores nothing and sends nothing: the page hands the places over and keeps them where it likes. Setting the property writes the attribute; at most
150
+ * `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight and for a reader who asked for less motion.
151
+ */
152
+ get places(): Place[];
153
+ set places(value: readonly Place[]);
154
+ /** How the places are drawn (the attribute `places-look`): `beam` (a light rising out of the ground with a ring at its foot, the default), `pin` (a thin stick with a round head) or `ring` (only the ring on the ground). */
155
+ get placesLook(): PlaceLook;
156
+ set placesLook(value: PlaceLook);
157
+ /**
158
+ * The look of the names of cities (`city-names`): font, size, weight, colour, the outline round the text, and the dot's colour and size. Any of them may be left out; the Earth's size, the language and the data are not set here.
159
+ */
160
+ get cityNamesStyle(): CityNamesStyle;
161
+ set cityNamesStyle(value: CityNamesStyle);
144
162
  /** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
145
163
  get controller(): ViewController | undefined;
146
164
  /**
@@ -243,6 +261,23 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
243
261
  y: number;
244
262
  }[];
245
263
  };
264
+ /** The places: how many were handed over, how many are drawn and named at the last draw, and how many times they were laid out. */
265
+ places: {
266
+ places: number;
267
+ shown: number;
268
+ labels: number;
269
+ renders: number;
270
+ };
271
+ /** The names of cities: whether `city-names` is set and the most it asks for, the Earth's radius on the screen, the tiers of kuni's cities that have arrived and how many cities, the names shown at the last draw and how many times the layer was drawn. */
272
+ cityNames: {
273
+ on: boolean;
274
+ max: number;
275
+ radius: number;
276
+ tiers: string[];
277
+ cities: number;
278
+ names: number;
279
+ renders: number;
280
+ };
246
281
  };
247
282
  /**
248
283
  * Apply a shared view controller's camera (yaw, tilt, zoom, pan). A change under half a pixel is not drawn, a settled change always is,