@johnmorrisdotca/chikyu-earth 0.35.0 → 0.37.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 +21 -0
- package/NOTICE.md +27 -1
- package/README.md +20 -2
- package/dist/borders/layer.d.ts +75 -0
- package/dist/borders/layer.js +136 -0
- package/dist/borders/lines.d.ts +138 -0
- package/dist/borders/lines.js +227 -0
- package/dist/catalogue/index.d.ts +1 -0
- package/dist/catalogue/index.js +3 -2
- package/dist/catalogue/pack.js +3 -0
- package/dist/cities/host.d.ts +9 -0
- package/dist/cities/host.js +51 -9
- package/dist/country-names/geometry.d.ts +264 -0
- package/dist/country-names/geometry.js +372 -0
- package/dist/country-names/host.d.ts +82 -0
- package/dist/country-names/host.js +212 -0
- package/dist/grid/layer.d.ts +45 -0
- package/dist/grid/layer.js +66 -0
- package/dist/grid/lines.d.ts +85 -0
- package/dist/grid/lines.js +113 -0
- package/dist/markers/go-to-place.d.ts +27 -0
- package/dist/markers/go-to-place.js +35 -0
- package/dist/markers/index.d.ts +2 -1
- package/dist/markers/index.js +2 -1
- package/dist/markers/layer.d.ts +7 -0
- package/dist/markers/layer.js +7 -0
- package/dist/markers/place-layer.d.ts +58 -7
- package/dist/markers/place-layer.js +326 -64
- package/dist/markers/place-sprites.d.ts +33 -0
- package/dist/markers/place-sprites.js +161 -0
- package/dist/markers/places.d.ts +91 -6
- package/dist/markers/places.js +135 -6
- package/dist/realistic/earth.d.ts +11 -0
- package/dist/realistic/earth.js +55 -1
- package/dist/realistic/element.d.ts +75 -6
- package/dist/realistic/element.js +221 -33
- package/dist/realistic/immersive.d.ts +7 -0
- package/dist/realistic/immersive.js +17 -0
- package/dist/realistic/index.d.ts +6 -0
- package/dist/realistic/index.js +3 -0
- package/dist/realistic/textures.d.ts +5 -0
- package/dist/satellites/index.d.ts +1 -0
- package/dist/satellites/index.js +1 -0
- package/dist/satellites/limits.d.ts +1 -1
- package/dist/satellites/limits.js +1 -1
- package/dist/satellites/owners.d.ts +26 -0
- package/dist/satellites/owners.js +164 -0
- package/dist/satellites/source.js +3 -0
- package/dist/satellites/track.d.ts +5 -0
- package/dist/satellites/track.js +128 -0
- package/dist/satellites/types.d.ts +19 -1
- package/dist/space/element.d.ts +111 -12
- package/dist/space/element.js +360 -26
- package/dist/space/index.d.ts +2 -2
- package/dist/space/index.js +1 -1
- package/dist/space/ride.d.ts +42 -0
- package/dist/space/ride.js +45 -3
- package/dist/space/satellite-layer.d.ts +8 -2
- package/dist/space/satellite-layer.js +138 -19
- package/dist/space/scene.d.ts +56 -6
- package/dist/space/scene.js +97 -15
- package/package.json +3 -3
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
// The places' markers in an element: a small box for each place, moved by CSS transforms when the picture is drawn, and a name for each that has room. The pulse of a `here` place is a CSS
|
|
2
|
-
// animation, so the picture is never drawn again for it; it stops while the element is out of sight, and a reader who asked for less motion gets none. Names are measured as the page draws them.
|
|
3
1
|
import { placeLabels } from "./labels.js";
|
|
4
|
-
import { layoutPlaces, PLACE_LOOKS } from "./places.js";
|
|
2
|
+
import { groupCell, groupPlaces, layoutPlaces, PLACE_LOOKS } from "./places.js";
|
|
5
3
|
/** A `places-look` attribute: one of `PLACE_LOOKS`, else `beam`. */
|
|
6
4
|
export const readPlaceLook = (value) => PLACE_LOOKS.includes(value ?? "") ? value : "beam";
|
|
7
5
|
/** The places' look, for the element's own style sheet. Colours: `--chikyu-place-here` and `--chikyu-place-favourite` on the element or the page. */
|
|
@@ -27,12 +25,44 @@ export const PLACE_STYLE = "#places{position:absolute;inset:0;overflow:hidden;po
|
|
|
27
25
|
"#places[data-look=ring] .pl-stick,#places[data-look=ring] .pl-head{display:none}" +
|
|
28
26
|
".pl-name{position:absolute;left:0;top:0;box-sizing:border-box;padding:1px 6px;font:600 11px/16px system-ui,-apple-system,'Segoe UI',sans-serif;letter-spacing:.04em;white-space:nowrap;color:#eefcff;background:rgba(4,10,20,.72);border:1px solid color-mix(in srgb,var(--c) 60%,transparent);border-radius:3px;will-change:transform;--c:var(--chikyu-place-favourite,#ffd27a)}" +
|
|
29
27
|
".pl-name[data-kind=here]{--c:var(--chikyu-place-here,#7df9ff);color:#fff}" +
|
|
28
|
+
".pl-name[data-kind=group]{padding:0 5px;font-size:10px;line-height:14px;border-radius:7px;background:rgba(4,10,20,.6)}" +
|
|
29
|
+
".pl-name[data-night]{opacity:.82}" +
|
|
30
30
|
".pl-name[data-kind=satellite]{--c:#cfeaff;color:#cfeaff;font-weight:500;background:rgba(4,10,20,.5);border-color:transparent}" +
|
|
31
31
|
".pl-sat{position:absolute;left:-8px;top:-8px;width:16px;height:16px;box-sizing:border-box;border:1.2px solid #cfeaff;border-radius:50%;opacity:.85;will-change:transform}" +
|
|
32
32
|
".pl-sat[hidden]{display:none}" +
|
|
33
|
+
".pl-dot{position:absolute;left:0;top:0;box-sizing:border-box;border:1.5px solid var(--c);border-radius:50%;opacity:.9;will-change:transform}" +
|
|
34
|
+
".pl-dot[hidden]{display:none}" +
|
|
33
35
|
".pl-name.pl-measure{visibility:hidden}";
|
|
34
36
|
/** The ring round a named satellite, in CSS pixels. */
|
|
35
37
|
const SATELLITE_RING = 8;
|
|
38
|
+
/**
|
|
39
|
+
* The most places in sight drawn as markers of their own (a beam, a pin or a ring standing out of the ground, and a name): `here` first, then the rest in the order given. Every other place is a ring on the ground, all of them one draw call.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { PLACE_MARKS } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
44
|
+
*
|
|
45
|
+
* console.log(PLACE_MARKS); // 32
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export const PLACE_MARKS = 32;
|
|
49
|
+
/**
|
|
50
|
+
* The most rings the layer draws itself, as small circles in the page, when the picture cannot draw them (the three.js parts handed over lack `Points`). Places in sight beyond it are counted in `stats.omitted`, not dropped quietly.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { PLACE_DOTS } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
55
|
+
*
|
|
56
|
+
* console.log(PLACE_DOTS); // 600
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export const PLACE_DOTS = 600;
|
|
60
|
+
/** The most names a group's count gets. */
|
|
61
|
+
const GROUP_NAMES = 24;
|
|
62
|
+
const EDGE = 0.02;
|
|
63
|
+
const MARGIN = 60;
|
|
64
|
+
const RING = { here: 9, favourite: 6 };
|
|
65
|
+
const FALLBACK = { here: "#7df9ff", favourite: "#ffd27a" };
|
|
36
66
|
/**
|
|
37
67
|
* Make the places' layer in a box of an element's shadow root (the box is `#places`, styled by {@link PLACE_STYLE}).
|
|
38
68
|
*
|
|
@@ -48,32 +78,67 @@ export function createPlaceLayer(box) {
|
|
|
48
78
|
const marks = [];
|
|
49
79
|
const names = [];
|
|
50
80
|
const sizes = new Map();
|
|
51
|
-
const stats = { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0 };
|
|
81
|
+
const stats = { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, omitted: 0 };
|
|
82
|
+
let grouping = true;
|
|
83
|
+
let ringsInPicture = true;
|
|
84
|
+
// the small circles that stand in for the picture's rings when it cannot draw them: the element, and what it was last written with
|
|
85
|
+
const dots = [];
|
|
86
|
+
let boxes = [];
|
|
52
87
|
const rings = [];
|
|
53
|
-
|
|
54
|
-
|
|
88
|
+
const measures = [];
|
|
89
|
+
// the groups of the places for the cell they were made with, and the rings' data the picture reads
|
|
90
|
+
let groups = [];
|
|
91
|
+
let groupedFor = null;
|
|
92
|
+
let groupedCell = -1;
|
|
93
|
+
let sprites = null;
|
|
94
|
+
const point = { x: 0, y: 0, upX: 0, upY: 0, facing: 0 };
|
|
95
|
+
const colorOk = (value) => !!value && (typeof CSS === "undefined" || typeof CSS.supports !== "function" || CSS.supports("color", value));
|
|
96
|
+
const keyOf = (place) => {
|
|
55
97
|
if (!place.label)
|
|
56
98
|
return null;
|
|
57
|
-
const kind = place.kind === "here" || place.kind === "satellite" ? place.kind : "favourite";
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
99
|
+
const kind = place.kind === "here" || place.kind === "satellite" || place.kind === "group" ? place.kind : "favourite";
|
|
100
|
+
return `${kind}\n${place.label}`;
|
|
101
|
+
};
|
|
102
|
+
// the names not measured yet are written all at once and read all at once: one layout for the lot
|
|
103
|
+
const measureAll = (list) => {
|
|
104
|
+
const todo = [];
|
|
105
|
+
for (const place of list) {
|
|
106
|
+
const key = keyOf(place);
|
|
107
|
+
if (key && !sizes.has(key) && !todo.includes(key))
|
|
108
|
+
todo.push(key);
|
|
109
|
+
}
|
|
110
|
+
if (todo.length === 0)
|
|
111
|
+
return;
|
|
112
|
+
if (sizes.size + todo.length > 600)
|
|
113
|
+
sizes.clear();
|
|
114
|
+
for (const [i, key] of todo.entries()) {
|
|
115
|
+
let span = measures[i];
|
|
116
|
+
if (!span) {
|
|
117
|
+
span = doc.createElement("span");
|
|
118
|
+
span.className = "pl-name pl-measure";
|
|
119
|
+
box.append(span);
|
|
120
|
+
measures[i] = span;
|
|
65
121
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
122
|
+
const cut = key.indexOf("\n");
|
|
123
|
+
span.hidden = false;
|
|
124
|
+
span.dataset["kind"] = key.slice(0, cut);
|
|
125
|
+
span.textContent = key.slice(cut + 1);
|
|
126
|
+
}
|
|
127
|
+
for (const [i, key] of todo.entries()) {
|
|
128
|
+
const rect = measures[i].getBoundingClientRect();
|
|
129
|
+
if (rect.width > 0)
|
|
130
|
+
sizes.set(key, { width: Math.ceil(rect.width), height: Math.ceil(rect.height) });
|
|
75
131
|
}
|
|
76
|
-
|
|
132
|
+
for (const span of measures)
|
|
133
|
+
span.hidden = true;
|
|
134
|
+
};
|
|
135
|
+
const size = (place) => {
|
|
136
|
+
const key = keyOf(place);
|
|
137
|
+
if (!key)
|
|
138
|
+
return null;
|
|
139
|
+
if (!sizes.has(key))
|
|
140
|
+
measureAll([place]);
|
|
141
|
+
return sizes.get(key) ?? null;
|
|
77
142
|
};
|
|
78
143
|
// a font that arrives later draws the names wider or narrower: measure them again
|
|
79
144
|
const fonts = doc.fonts;
|
|
@@ -93,7 +158,7 @@ export function createPlaceLayer(box) {
|
|
|
93
158
|
head.className = "pl-head";
|
|
94
159
|
root.append(disc, stick, head);
|
|
95
160
|
box.append(root);
|
|
96
|
-
mark = { root, disc, stick, head, kind: "", ring: 0 };
|
|
161
|
+
mark = { root, disc, stick, head, kind: "", ring: 0, color: "" };
|
|
97
162
|
marks[i] = mark;
|
|
98
163
|
}
|
|
99
164
|
return mark;
|
|
@@ -113,13 +178,106 @@ export function createPlaceLayer(box) {
|
|
|
113
178
|
if (!list[i].hidden)
|
|
114
179
|
list[i].hidden = true;
|
|
115
180
|
};
|
|
181
|
+
const showName = (name, text, kind, left, top, color, night) => {
|
|
182
|
+
if (name.textContent !== text)
|
|
183
|
+
name.textContent = text;
|
|
184
|
+
if (name.dataset["kind"] !== kind)
|
|
185
|
+
name.dataset["kind"] = kind;
|
|
186
|
+
if (colorOk(color))
|
|
187
|
+
name.style.setProperty("--c", color);
|
|
188
|
+
else if (name.style.getPropertyValue("--c"))
|
|
189
|
+
name.style.removeProperty("--c");
|
|
190
|
+
name.toggleAttribute("data-night", night);
|
|
191
|
+
if (name.hidden)
|
|
192
|
+
name.hidden = false;
|
|
193
|
+
name.style.transform = `translate(${Math.round(left)}px,${Math.round(top)}px)`;
|
|
194
|
+
};
|
|
195
|
+
// a small circle standing in for a ring the picture cannot draw: `fill` is how much of it is solid (a group of several)
|
|
196
|
+
const showDot = (i, x, y, r, fill, color) => {
|
|
197
|
+
let dot = dots[i];
|
|
198
|
+
if (!dot) {
|
|
199
|
+
const root = doc.createElement("i");
|
|
200
|
+
root.className = "pl-dot";
|
|
201
|
+
box.append(root);
|
|
202
|
+
dot = { root, r: -1, color: "", fill: -1 };
|
|
203
|
+
dots[i] = dot;
|
|
204
|
+
}
|
|
205
|
+
if (dot.r !== r) {
|
|
206
|
+
dot.r = r;
|
|
207
|
+
dot.root.style.width = `${2 * r}px`;
|
|
208
|
+
dot.root.style.height = `${2 * r}px`;
|
|
209
|
+
dot.root.style.marginLeft = `${-r}px`;
|
|
210
|
+
dot.root.style.marginTop = `${-r}px`;
|
|
211
|
+
}
|
|
212
|
+
if (dot.color !== color) {
|
|
213
|
+
dot.color = color;
|
|
214
|
+
dot.root.style.setProperty("--c", color);
|
|
215
|
+
}
|
|
216
|
+
if (dot.fill !== fill) {
|
|
217
|
+
dot.fill = fill;
|
|
218
|
+
dot.root.style.background = fill > 0 ? `color-mix(in srgb, ${color} ${Math.round(fill * 100)}%, transparent)` : "none";
|
|
219
|
+
}
|
|
220
|
+
if (dot.root.hidden)
|
|
221
|
+
dot.root.hidden = false;
|
|
222
|
+
dot.root.style.transform = `translate(${x.toFixed(1)}px,${y.toFixed(1)}px)`;
|
|
223
|
+
};
|
|
224
|
+
/** Gather the places again for a new list or a new cell, and write the rings' places and colours. */
|
|
225
|
+
const regroup = (cell) => {
|
|
226
|
+
groupedFor = places;
|
|
227
|
+
groupedCell = cell;
|
|
228
|
+
groups = groupPlaces(places, cell);
|
|
229
|
+
if (groups.length === 0) {
|
|
230
|
+
sprites = null;
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const style = typeof getComputedStyle === "function" ? getComputedStyle(box) : null;
|
|
234
|
+
const kindColor = { here: style?.getPropertyValue("--chikyu-place-here").trim() || FALLBACK.here, favourite: style?.getPropertyValue("--chikyu-place-favourite").trim() || FALLBACK.favourite };
|
|
235
|
+
const points = sprites && sprites.points.length >= groups.length * 3 ? sprites.points : new Float32Array(groups.length * 3);
|
|
236
|
+
const shapes = sprites && sprites.shapes.length >= groups.length * 2 ? sprites.shapes : new Float32Array(groups.length * 2);
|
|
237
|
+
const colors = [];
|
|
238
|
+
for (const [g, group] of groups.entries()) {
|
|
239
|
+
const lon = (group.lon * Math.PI) / 180;
|
|
240
|
+
const lat = (group.lat * Math.PI) / 180;
|
|
241
|
+
points[g * 3] = Math.cos(lat) * Math.sin(lon);
|
|
242
|
+
points[g * 3 + 1] = Math.sin(lat);
|
|
243
|
+
points[g * 3 + 2] = Math.cos(lat) * Math.cos(lon);
|
|
244
|
+
const first = places[group.members[0]];
|
|
245
|
+
const own = colorOk(first.color) && group.members.every((m) => places[m].color === first.color) ? first.color : undefined;
|
|
246
|
+
colors.push(own ?? kindColor[first.kind === "here" && group.members.length === 1 ? "here" : "favourite"]);
|
|
247
|
+
}
|
|
248
|
+
sprites = { version: (sprites?.version ?? 0) + 1, count: groups.length, points, colors, shapesVersion: (sprites?.shapesVersion ?? 0) + 1, shapes };
|
|
249
|
+
};
|
|
116
250
|
// the pulse stops while the element is out of sight
|
|
117
251
|
const watcher = typeof IntersectionObserver === "function" ? new IntersectionObserver((entries) => box.classList.toggle("pl-still", !entries.some((entry) => entry.isIntersecting))) : null;
|
|
118
252
|
watcher?.observe(box);
|
|
253
|
+
const clear = () => {
|
|
254
|
+
hideFrom(marks.map((m) => m.root), 0);
|
|
255
|
+
hideFrom(names, 0);
|
|
256
|
+
hideFrom(rings, 0);
|
|
257
|
+
if (dots.length > 0)
|
|
258
|
+
hideFrom(dots.map((d) => d.root), 0);
|
|
259
|
+
stats.omitted = 0;
|
|
260
|
+
stats.shown = 0;
|
|
261
|
+
stats.labels = 0;
|
|
262
|
+
stats.rings = 0;
|
|
263
|
+
stats.satelliteNames = 0;
|
|
264
|
+
stats.marks = 0;
|
|
265
|
+
stats.groups = 0;
|
|
266
|
+
stats.sprites = 0;
|
|
267
|
+
if (sprites && sprites.shapes.some((v) => v !== 0)) {
|
|
268
|
+
sprites.shapes.fill(0);
|
|
269
|
+
sprites.shapesVersion += 1;
|
|
270
|
+
}
|
|
271
|
+
};
|
|
119
272
|
return {
|
|
120
273
|
set(next) {
|
|
121
274
|
places = next;
|
|
122
275
|
stats.places = next.length;
|
|
276
|
+
if (next.length === 0) {
|
|
277
|
+
groups = [];
|
|
278
|
+
groupedFor = next;
|
|
279
|
+
sprites = null;
|
|
280
|
+
}
|
|
123
281
|
},
|
|
124
282
|
get look() {
|
|
125
283
|
return look;
|
|
@@ -128,26 +286,58 @@ export function createPlaceLayer(box) {
|
|
|
128
286
|
look = value;
|
|
129
287
|
box.dataset["look"] = value;
|
|
130
288
|
},
|
|
131
|
-
|
|
289
|
+
get grouping() {
|
|
290
|
+
return grouping;
|
|
291
|
+
},
|
|
292
|
+
set grouping(value) {
|
|
293
|
+
if (value === grouping)
|
|
294
|
+
return;
|
|
295
|
+
grouping = value;
|
|
296
|
+
groupedFor = null;
|
|
297
|
+
},
|
|
298
|
+
get ringsInPicture() {
|
|
299
|
+
return ringsInPicture;
|
|
300
|
+
},
|
|
301
|
+
set ringsInPicture(value) {
|
|
302
|
+
ringsInPicture = value;
|
|
303
|
+
},
|
|
304
|
+
get sprites() {
|
|
305
|
+
return sprites;
|
|
306
|
+
},
|
|
307
|
+
frame(view, taken = [], satellites = [], sun = null) {
|
|
132
308
|
if (!view || (places.length === 0 && satellites.length === 0)) {
|
|
133
|
-
|
|
134
|
-
hideFrom(names, 0);
|
|
135
|
-
hideFrom(rings, 0);
|
|
136
|
-
stats.shown = 0;
|
|
137
|
-
stats.labels = 0;
|
|
138
|
-
stats.rings = 0;
|
|
139
|
-
stats.satelliteNames = 0;
|
|
309
|
+
clear();
|
|
140
310
|
if (places.length > 0)
|
|
141
311
|
stats.renders += 1;
|
|
312
|
+
boxes = [];
|
|
142
313
|
return;
|
|
143
314
|
}
|
|
144
315
|
stats.renders += 1;
|
|
145
|
-
const
|
|
316
|
+
const cell = grouping ? groupCell(view.radius ?? 0) : 0;
|
|
317
|
+
if (groupedFor !== places || groupedCell !== cell)
|
|
318
|
+
regroup(cell);
|
|
319
|
+
// which groups are in sight, and the places that get markers of their own: `here` first, then in the order given
|
|
320
|
+
const inSight = [];
|
|
321
|
+
let shown = 0;
|
|
322
|
+
for (const [g, group] of groups.entries()) {
|
|
323
|
+
if (!view.at(group.lon, group.lat, point) || point.facing <= EDGE)
|
|
324
|
+
continue;
|
|
325
|
+
if (point.x < -MARGIN || point.y < -MARGIN || point.x > view.width + MARGIN || point.y > view.height + MARGIN)
|
|
326
|
+
continue;
|
|
327
|
+
inSight.push(g);
|
|
328
|
+
shown += group.members.length;
|
|
329
|
+
}
|
|
330
|
+
const singles = inSight.filter((g) => groups[g].members.length === 1);
|
|
331
|
+
const chosen = [...singles.filter((g) => places[groups[g].members[0]].kind === "here"), ...singles.filter((g) => places[groups[g].members[0]].kind !== "here")].slice(0, PLACE_MARKS);
|
|
332
|
+
const own = chosen.map((g) => places[groups[g].members[0]]);
|
|
333
|
+
measureAll(own);
|
|
334
|
+
const layout = layoutPlaces(own, view, look, { size: (place) => size(place), taken, sun });
|
|
146
335
|
// favourites first, so a `here` marker is drawn over them
|
|
147
|
-
const order = [...layout.shapes].sort((a, b) => (
|
|
336
|
+
const order = [...layout.shapes].sort((a, b) => (own[a.index].kind === "here" ? 1 : 0) - (own[b.index].kind === "here" ? 1 : 0));
|
|
148
337
|
for (const [i, shape] of order.entries()) {
|
|
338
|
+
const place = own[shape.index];
|
|
149
339
|
const mark = markAt(i);
|
|
150
|
-
const kind =
|
|
340
|
+
const kind = place.kind === "here" ? "here" : "favourite";
|
|
151
341
|
if (mark.kind !== kind) {
|
|
152
342
|
mark.kind = kind;
|
|
153
343
|
mark.root.dataset["kind"] = kind;
|
|
@@ -156,34 +346,99 @@ export function createPlaceLayer(box) {
|
|
|
156
346
|
mark.ring = shape.ring;
|
|
157
347
|
mark.root.style.setProperty("--r", `${shape.ring}px`);
|
|
158
348
|
}
|
|
349
|
+
const color = colorOk(place.color) ? place.color : "";
|
|
350
|
+
if (mark.color !== color) {
|
|
351
|
+
mark.color = color;
|
|
352
|
+
if (color)
|
|
353
|
+
mark.root.style.setProperty("--c", color);
|
|
354
|
+
else
|
|
355
|
+
mark.root.style.removeProperty("--c");
|
|
356
|
+
}
|
|
159
357
|
if (mark.root.hidden)
|
|
160
358
|
mark.root.hidden = false;
|
|
359
|
+
const opacity = shape.opacity * (1 - 0.5 * shape.night);
|
|
161
360
|
mark.root.style.transform = `translate(${shape.x.toFixed(1)}px,${shape.y.toFixed(1)}px)`;
|
|
162
|
-
mark.root.style.opacity =
|
|
361
|
+
mark.root.style.opacity = opacity >= 1 ? "" : opacity.toFixed(2);
|
|
163
362
|
mark.disc.style.transform = `rotate(${shape.ringAngle.toFixed(1)}deg) scale(1,${shape.squash.toFixed(3)})`;
|
|
164
363
|
mark.stick.style.transform = `rotate(${shape.angle.toFixed(1)}deg) scaleY(${(shape.length / 100).toFixed(3)})`;
|
|
165
364
|
mark.head.style.transform = `translate(${(shape.tipX - shape.x).toFixed(1)}px,${(shape.tipY - shape.y).toFixed(1)}px)`;
|
|
166
365
|
}
|
|
167
366
|
hideFrom(marks.map((m) => m.root), order.length);
|
|
367
|
+
const nightOf = new Map(layout.shapes.map((shape) => [shape.index, shape.night]));
|
|
168
368
|
for (const [i, spot] of layout.labels.entries()) {
|
|
169
|
-
const place =
|
|
170
|
-
|
|
171
|
-
const kind = place.kind === "here" ? "here" : "favourite";
|
|
172
|
-
if (name.textContent !== place.label)
|
|
173
|
-
name.textContent = place.label ?? "";
|
|
174
|
-
if (name.dataset["kind"] !== kind)
|
|
175
|
-
name.dataset["kind"] = kind;
|
|
176
|
-
if (name.hidden)
|
|
177
|
-
name.hidden = false;
|
|
178
|
-
name.style.transform = `translate(${Math.round(spot.left)}px,${Math.round(spot.top)}px)`;
|
|
369
|
+
const place = own[spot.index];
|
|
370
|
+
showName(nameAt(i), place.label ?? "", place.kind === "here" ? "here" : "favourite", spot.left, spot.top, place.color, (nightOf.get(spot.index) ?? 0) > 0.5);
|
|
179
371
|
}
|
|
180
|
-
|
|
181
|
-
const
|
|
372
|
+
let used = layout.labels.length;
|
|
373
|
+
const busy = [...taken];
|
|
182
374
|
for (const spot of layout.labels) {
|
|
183
|
-
const found = size(
|
|
375
|
+
const found = size(own[spot.index]);
|
|
184
376
|
if (found)
|
|
185
|
-
|
|
377
|
+
busy.push({ left: spot.left, top: spot.top, ...found });
|
|
186
378
|
}
|
|
379
|
+
// the rings in the one draw call: every place in sight that has no marker of its own, and every group, larger as it holds more
|
|
380
|
+
let drawnSprites = 0;
|
|
381
|
+
let drawnGroups = 0;
|
|
382
|
+
let drawnDots = 0;
|
|
383
|
+
let omitted = 0;
|
|
384
|
+
if (sprites) {
|
|
385
|
+
const shapes = sprites.shapes;
|
|
386
|
+
const before = shapes.slice(0, groups.length * 2);
|
|
387
|
+
shapes.fill(0, 0, groups.length * 2);
|
|
388
|
+
const marked = new Set(layout.shapes.map((shape) => chosen[shape.index]));
|
|
389
|
+
const counts = [];
|
|
390
|
+
const owners = [];
|
|
391
|
+
for (const g of inSight) {
|
|
392
|
+
if (marked.has(g))
|
|
393
|
+
continue;
|
|
394
|
+
const group = groups[g];
|
|
395
|
+
const n = group.members.length;
|
|
396
|
+
const first = places[group.members[0]];
|
|
397
|
+
const ring = n > 1 ? Math.min(14, 6 + 2.2 * Math.log2(n)) : RING[first.kind === "here" ? "here" : "favourite"];
|
|
398
|
+
shapes[g * 2] = ring;
|
|
399
|
+
shapes[g * 2 + 1] = n > 1 ? 0.3 : 0;
|
|
400
|
+
if (!ringsInPicture || n > 1)
|
|
401
|
+
view.at(group.lon, group.lat, point);
|
|
402
|
+
if (ringsInPicture)
|
|
403
|
+
drawnSprites += 1;
|
|
404
|
+
else if (drawnDots < PLACE_DOTS) {
|
|
405
|
+
showDot(drawnDots, point.x, point.y, ring, n > 1 ? 0.3 : 0, sprites.colors[g]);
|
|
406
|
+
drawnDots += 1;
|
|
407
|
+
drawnSprites += 1;
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
omitted += n;
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
if (n > 1) {
|
|
414
|
+
drawnGroups += 1;
|
|
415
|
+
if (counts.length < GROUP_NAMES * 2) {
|
|
416
|
+
const found = size({ label: String(n), kind: "group" });
|
|
417
|
+
if (found) {
|
|
418
|
+
counts.push({ x: point.x, y: point.y, r: ring, w: found.width, h: found.height, priority: n });
|
|
419
|
+
owners.push(g);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (shapes.some((v, i) => v !== before[i]))
|
|
425
|
+
sprites.shapesVersion += 1;
|
|
426
|
+
const placed = placeLabels(counts, view.width, view.height, GROUP_NAMES, 64, busy);
|
|
427
|
+
for (const spot of placed) {
|
|
428
|
+
const group = groups[owners[spot.item]];
|
|
429
|
+
const count = String(group.members.length);
|
|
430
|
+
const first = places[group.members[0]];
|
|
431
|
+
showName(nameAt(used), count, "group", spot.left, spot.top, group.members.every((m) => places[m].color === first.color) ? first.color : undefined, false);
|
|
432
|
+
const found = size({ label: count, kind: "group" });
|
|
433
|
+
if (found)
|
|
434
|
+
busy.push({ left: spot.left, top: spot.top, ...found });
|
|
435
|
+
used += 1;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
if (dots.length > 0)
|
|
439
|
+
hideFrom(dots.map((d) => d.root), drawnDots);
|
|
440
|
+
stats.omitted = omitted;
|
|
441
|
+
// the ringed satellites: a ring round each that can be seen, and its name where it is free of the places' names and the boxes taken
|
|
187
442
|
const seen = satellites.filter((mark) => mark.visible);
|
|
188
443
|
for (const [i, mark] of seen.entries()) {
|
|
189
444
|
let ring = rings[i];
|
|
@@ -200,6 +455,7 @@ export function createPlaceLayer(box) {
|
|
|
200
455
|
hideFrom(rings, seen.length);
|
|
201
456
|
const items = [];
|
|
202
457
|
const owners = [];
|
|
458
|
+
measureAll(seen.filter((mark) => mark.label).map((mark) => ({ label: mark.label, kind: "satellite" })));
|
|
203
459
|
for (const [i, mark] of seen.entries()) {
|
|
204
460
|
const found = mark.label ? size({ label: mark.label, kind: "satellite" }) : null;
|
|
205
461
|
if (!found)
|
|
@@ -207,32 +463,38 @@ export function createPlaceLayer(box) {
|
|
|
207
463
|
items.push({ x: mark.x, y: mark.y, r: SATELLITE_RING + 2, w: found.width, h: found.height, priority: -i });
|
|
208
464
|
owners.push(mark);
|
|
209
465
|
}
|
|
210
|
-
const placed = placeLabels(items, view.width, view.height, 24, 64,
|
|
211
|
-
for (const
|
|
466
|
+
const placed = placeLabels(items, view.width, view.height, 24, 64, busy);
|
|
467
|
+
for (const spot of placed) {
|
|
212
468
|
const mark = owners[spot.item];
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
name.textContent = mark.label;
|
|
216
|
-
if (name.dataset["kind"] !== "satellite")
|
|
217
|
-
name.dataset["kind"] = "satellite";
|
|
218
|
-
if (name.hidden)
|
|
219
|
-
name.hidden = false;
|
|
220
|
-
name.style.transform = `translate(${Math.round(spot.left)}px,${Math.round(spot.top)}px)`;
|
|
469
|
+
showName(nameAt(used), mark.label, "satellite", spot.left, spot.top, undefined, false);
|
|
470
|
+
used += 1;
|
|
221
471
|
}
|
|
222
|
-
hideFrom(names,
|
|
223
|
-
|
|
472
|
+
hideFrom(names, used);
|
|
473
|
+
boxes = busy.slice(taken.length);
|
|
474
|
+
for (const spot of placed)
|
|
475
|
+
boxes.push({ left: spot.left, top: spot.top, width: items[spot.item].w, height: items[spot.item].h });
|
|
476
|
+
for (const shape of layout.shapes)
|
|
477
|
+
boxes.push({ left: shape.tipX - 5, top: shape.tipY - 5, width: 10, height: 10 });
|
|
478
|
+
stats.shown = shown;
|
|
479
|
+
stats.marks = order.length;
|
|
224
480
|
stats.labels = layout.labels.length;
|
|
481
|
+
stats.groups = drawnGroups;
|
|
482
|
+
stats.sprites = drawnSprites;
|
|
225
483
|
stats.rings = seen.length;
|
|
226
484
|
stats.satelliteNames = placed.length;
|
|
227
485
|
},
|
|
228
486
|
stats,
|
|
487
|
+
get boxes() {
|
|
488
|
+
return boxes;
|
|
489
|
+
},
|
|
229
490
|
dispose() {
|
|
230
491
|
watcher?.disconnect();
|
|
231
492
|
fonts?.removeEventListener?.("loadingdone", refit);
|
|
232
493
|
box.replaceChildren();
|
|
233
494
|
marks.length = 0;
|
|
234
495
|
names.length = 0;
|
|
235
|
-
|
|
496
|
+
measures.length = 0;
|
|
497
|
+
sprites = null;
|
|
236
498
|
},
|
|
237
499
|
};
|
|
238
500
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type * as THREE from "three";
|
|
2
|
+
import type { ThreeParts } from "../realistic/textures.ts";
|
|
3
|
+
/** What the places' layer hands the picture at each draw (see `PlaceLayer.sprites`). */
|
|
4
|
+
export interface PlaceSpriteData {
|
|
5
|
+
/** Changes when the groups change: their places and colours are read again. */
|
|
6
|
+
version: number;
|
|
7
|
+
count: number;
|
|
8
|
+
/** Each group's place on the Earth as a unit vector in the Earth's own axes (x, y, z). */
|
|
9
|
+
points: Float32Array;
|
|
10
|
+
/** Each group's colour, as CSS has it. */
|
|
11
|
+
colors: readonly string[];
|
|
12
|
+
/** Changes when `shapes` changes. */
|
|
13
|
+
shapesVersion: number;
|
|
14
|
+
/** For each group, its ring's radius in CSS pixels (0: not drawn here) and how much of the ring is filled (0 to 1, for a group of several places). */
|
|
15
|
+
shapes: Float32Array;
|
|
16
|
+
}
|
|
17
|
+
/** The rings in one picture: hand them the places' data at each draw. */
|
|
18
|
+
export interface PlaceSprites {
|
|
19
|
+
/** Bring the buffers up to date. `ratio` is device pixels to a CSS pixel, `width` and `height` the picture's size in CSS pixels, and `lit` true when the whole Earth is lit (no night to dim). */
|
|
20
|
+
sync(data: PlaceSpriteData | null, ratio: number, width: number, height: number, lit: boolean): void;
|
|
21
|
+
dispose(): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Make the rings for one picture, as a child of the Earth (so they turn with it). Without three.js's `Points` (a subset of three.js that leaves it out) there are none: `null`.
|
|
25
|
+
*
|
|
26
|
+
* @param three - The page's three.js.
|
|
27
|
+
* @param parent - The Earth, or the group that turns it (radius 1).
|
|
28
|
+
* @param sun - The direction to the Sun in the scene's axes, the uniform the Earth's own surface uses.
|
|
29
|
+
* @returns The rings, or null.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createPlaceSprites(three: ThreeParts, parent: THREE.Object3D, sun: {
|
|
32
|
+
value: THREE.Vector3;
|
|
33
|
+
}): PlaceSprites | null;
|