@johnmorrisdotca/chikyu-earth 0.39.0 → 0.40.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 CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.40.0 - 2026-11-12
6
+
7
+ - **Names of different layers never overlap** (MODULES-1072). On `<chikyu-space>` and `<chikyu-earth-realistic>` each layer placed its names alone: city names ignored the places, the markers' labels ignored the places' names, and star names ignored every layer's names and rings, so a name could sit over another layer's. The layers now lay out in a fixed order, each keeping clear of the boxes of those before it: the places' names, rings and marks with the ringed satellites, then the markers' labels, then the cities' names, then the stars' and constellations' names (the countries' names, which already kept clear of the others, come after the cities'). A star whose name box or ring touches an earlier box is left out and the next star is named. The order is the draw's: the realistic Earth's places are laid out before its markers and the sky after the cities, as the space view's sky is after its cities. `OverlayHost` has an optional `taken()` (the places' boxes, which `attachMarkers` reads), `CityLayoutOptions` has `taken`, and a satellite's ring is among the boxes the places take. Boxes are handed over when names are laid out, which is when the view changes; nothing is laid out or drawn at rest. Tests: `test/label-overlap.test.ts` and `e2e/label-overlap.gl.ts`.
8
+ - **A glide is counted on the page, not polled** (MODULES-1190). `e2e/ride-above.gl.ts` watched for the camera's glide into the above view by polling `stats.ride.gliding`, and a short glide could be missed (seen in CI on 2026-11-12). The page now counts each glide at every animation frame and the test reads the count; it fails when a view change never glides. A test change only; the package is unchanged.
9
+
5
10
  ## 0.39.0 - 2026-11-12
6
11
 
7
12
  - **The painted trail follows the orbit at any clock, and costs nothing until it is used** (MODULES-1188). A month laid down at once, or a fast clock, took samples too far apart and drew chords across the map: samples are now at most a third of a trip apart. A clock run backwards laid down nothing for the older end, so the trail shrank: it now fills it in. A coverage swath over the date line was cut at the edge of the map: it now wraps. Switching to a satellite that paints nothing left the old picture on the globe: the cleared picture is sent. The trail's two megabytes and its picture on the graphics card were made in every view, painting or not: they are made when the first satellite is painted, and `clearPaint()` gives them back.
package/README.md CHANGED
@@ -609,7 +609,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
609
609
 
610
610
  ## How to cite
611
611
 
612
- > Morris, J. (2026). *Chikyu Earth* (version 0.39.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
612
+ > Morris, J. (2026). *Chikyu Earth* (version 0.40.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
613
613
 
614
614
  GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA. Cite the version you used (`npm ls @johnmorrisdotca/chikyu-earth`), and credit the sources behind the numbers and pictures: [NOTICE.md](NOTICE.md) says who made each one and under what terms.
615
615
 
@@ -77,6 +77,13 @@ export interface CityLayoutOptions {
77
77
  * (a fallback font for Japanese, say) would otherwise lay names over one another. Left out, the estimate alone is used, as in Node.
78
78
  */
79
79
  measure?: (text: string) => number;
80
+ /** Boxes another layer's names, rings and marks already take (left, top, width and height from the picture's top left): no name is put over one. */
81
+ taken?: readonly {
82
+ left: number;
83
+ top: number;
84
+ width: number;
85
+ height: number;
86
+ }[];
80
87
  }
81
88
  /**
82
89
  * A city to name: where its dot is, the text to write and where the text's box goes (its top left corner and size).
@@ -124,7 +124,7 @@ export function layoutCities(cities, frame, lang, options) {
124
124
  const height = Math.ceil(options.size * 1.35);
125
125
  const texts = seen.map((one) => cityNameText(one.city, lang));
126
126
  const items = seen.map((one, index) => ({ x: one.x, y: one.y, r: options.dot, w: Math.max(nameWidth(texts[index], options.size), options.measure ? Math.ceil(options.measure(texts[index])) + 4 : 0), h: height, priority: seen.length - index }));
127
- return placeLabels(items, frame.width, frame.height, options.max).map((place) => {
127
+ return placeLabels(items, frame.width, frame.height, options.max, 64, options.taken).map((place) => {
128
128
  const one = seen[place.item];
129
129
  return { city: one.city, text: texts[place.item], x: one.x, y: one.y, left: place.left, top: place.top, width: items[place.item].w, height };
130
130
  });
@@ -38,8 +38,16 @@ export interface CityHostOptions {
38
38
  onLayout?(): void;
39
39
  }
40
40
  export interface CityHost {
41
- /** Tells where the Earth is in the picture just drawn, or `null` when there is no Earth to name. */
42
- frame(frame: CityFrame | null): void;
41
+ /**
42
+ * Tells where the Earth is in the picture just drawn, or `null` when there is no Earth to name. `taken` is the boxes the layers placed before this one (the places', the markers', the bodies' names) take: no name goes over one.
43
+ * The list is read again whenever the names are laid out between draws, so the element refills the same array.
44
+ */
45
+ frame(frame: CityFrame | null, taken?: readonly {
46
+ left: number;
47
+ top: number;
48
+ width: number;
49
+ height: number;
50
+ }[]): void;
43
51
  /** Reads the attribute and the language again after either changed. */
44
52
  refresh(): void;
45
53
  /** The look of the names (the property `cityNamesStyle`). */
@@ -35,6 +35,7 @@ export function createCityHost(options) {
35
35
  let version = 0;
36
36
  let cache;
37
37
  let last = null;
38
+ let lastTaken;
38
39
  let shown = [];
39
40
  let renders = 0;
40
41
  let style = {};
@@ -154,7 +155,7 @@ export function createCityHost(options) {
154
155
  const size = style.size ?? DEFAULTS.size;
155
156
  const dot = style.dotSize ?? DEFAULTS.dot;
156
157
  usedLang = options.language();
157
- shown = layoutCities(citiesFor(tiers), frame, usedLang, { max, size, dot, measure: measurer(size) });
158
+ shown = layoutCities(citiesFor(tiers), frame, usedLang, { max, size, dot, measure: measurer(size), ...(lastTaken ? { taken: lastTaken } : {}) });
158
159
  place(frame, dot);
159
160
  }
160
161
  function place(frame, dot) {
@@ -223,10 +224,11 @@ export function createCityHost(options) {
223
224
  };
224
225
  doc.fonts?.addEventListener?.("loadingdone", onFonts);
225
226
  return {
226
- frame(next) {
227
+ frame(next, taken) {
227
228
  if (gone)
228
229
  return;
229
230
  last = next;
231
+ lastTaken = taken;
230
232
  if (max === null)
231
233
  return;
232
234
  if (!next) {
@@ -33,13 +33,28 @@ export interface OverlayHost {
33
33
  readonly overlayRoot: HTMLElement;
34
34
  readonly pose: OverlayPose | null;
35
35
  subscribe(listener: (pose: OverlayPose) => void): () => void;
36
- /** Tells the element the boxes an overlay's marks and labels take now (an empty list when it is taken away), so the element's own names keep clear of them. */
36
+ /**
37
+ * Tells the element the boxes an overlay's marks and labels take now (an empty list when it is taken away), so the element's own names keep clear of them. `names` is the part of `boxes` that is the labels' (the marks' own boxes are the rest): the cities' names, which are
38
+ * set at a mark's own place, keep clear of the labels and not of the marks.
39
+ */
37
40
  claim?(owner: object, boxes: readonly {
38
41
  left: number;
39
42
  top: number;
40
43
  width: number;
41
44
  height: number;
45
+ }[], names?: readonly {
46
+ left: number;
47
+ top: number;
48
+ width: number;
49
+ height: number;
42
50
  }[]): void;
51
+ /** The boxes the element's own places take now (names, rings, marks): the markers' labels are put clear of them, as the places come first. */
52
+ taken?(): readonly {
53
+ left: number;
54
+ top: number;
55
+ width: number;
56
+ height: number;
57
+ }[];
43
58
  }
44
59
  /**
45
60
  * What {@link attachMarkers} may be asked: the most labels, how close markers gather, and the default colour.
@@ -232,7 +232,7 @@ export function attachMarkers(element, options = {}) {
232
232
  hitMembers.push(g.members);
233
233
  }
234
234
  }
235
- const placed = placeLabels(items, pose.width, pose.height, maxLabels);
235
+ const placed = placeLabels(items, pose.width, pose.height, maxLabels, 64, host.taken?.());
236
236
  for (let k = 0; k < placed.length; k += 1) {
237
237
  const p = placed[k];
238
238
  const m = data.items[labelled[p.item]];
@@ -264,9 +264,10 @@ export function attachMarkers(element, options = {}) {
264
264
  const boxes = [];
265
265
  for (const p of placed)
266
266
  boxes.push({ left: p.left, top: p.top, width: items[p.item].w, height: items[p.item].h });
267
+ const names = boxes.slice();
267
268
  for (let k = 0; k < hitX.length; k += 1)
268
269
  boxes.push({ left: hitX[k] - hitR[k], top: hitY[k] - hitR[k], width: hitR[k] * 2, height: hitR[k] * 2 });
269
- host.claim?.(api, boxes);
270
+ host.claim?.(api, boxes, names);
270
271
  stats.markers = visible.length - groups.reduce((sum, g) => sum + (g.members.length > 1 ? g.members.length : 0), 0);
271
272
  stats.clusters = clusters;
272
273
  stats.labels = placed.length;
@@ -544,6 +544,9 @@ export function createPlaceLayer(box) {
544
544
  boxes.push({ left: spot.left, top: spot.top, width: items[spot.item].w, height: items[spot.item].h });
545
545
  for (const shape of layout.shapes)
546
546
  boxes.push({ left: shape.tipX - 5, top: shape.tipY - 5, width: 10, height: 10 });
547
+ // the ring round each satellite that can be seen: other layers' names keep off it as they keep off its name
548
+ for (const mark of seen)
549
+ boxes.push({ left: mark.x - SATELLITE_RING, top: mark.y - SATELLITE_RING, width: SATELLITE_RING * 2, height: SATELLITE_RING * 2 });
547
550
  stats.shown = shown;
548
551
  stats.marks = order.length;
549
552
  stats.labels = layout.labels.length;
@@ -247,6 +247,8 @@ export function createEarthItem(model, deps) {
247
247
  if (model.bodyLabel.settings && !nameOn)
248
248
  nameOn = createBodyLabelLayer(three, turned, model.bodyLabel, { invalidate: deps.invalidate, ...(deps.onLabelError ? { onError: deps.onLabelError } : {}) });
249
249
  nameOn?.sync(camera, radius);
250
+ deps.onPose?.({ lon: look.lon, lat: look.lat, radius, cx: size.width / 2 + view.panX, cy: size.height / 2 + view.panY, width: size.width, height: size.height });
251
+ // the sky after the places, the markers and the city names, so its names keep clear of what they take as it is laid out
250
252
  if (deps.onSky) {
251
253
  // the sky as the picture's own axes see it: a direction in space, turned as the satellites are into the picture's axes, falls where its sideways and upward parts say, in front when it points towards the viewer
252
254
  spun.updateWorldMatrix(true, false);
@@ -268,7 +270,6 @@ export function createEarthItem(model, deps) {
268
270
  },
269
271
  });
270
272
  }
271
- deps.onPose?.({ lon: look.lon, lat: look.lat, radius, cx: size.width / 2 + view.panX, cy: size.height / 2 + view.panY, width: size.width, height: size.height });
272
273
  // the borders: made the first time a set is switched on, above the clouds and under the air
273
274
  if ((model.borders.countries || model.borders.regions) && !borders && !model.borders.stats.failed) {
274
275
  try {
@@ -241,6 +241,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
241
241
  language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
242
242
  onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-sky-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
243
243
  loadFont: loadMichroma,
244
+ taken: () => this.#boxesBeforeSky(),
244
245
  });
245
246
  this.#sky.setStyle(this.#skyStyle);
246
247
  this.#sky.setKeepClear(this.#keepClear);
@@ -254,7 +255,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
254
255
  attribute: (name) => this.getAttribute(name),
255
256
  language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
256
257
  onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-city-names-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
257
- onLayout: () => this.#countryFrame(),
258
+ onLayout: () => this.#relayNames(false, true),
258
259
  });
259
260
  this.#cities.setStyle(this.#citiesStyle);
260
261
  Object.assign(this.#model.borders, readBorders(this.getAttribute("borders")));
@@ -313,6 +314,11 @@ export class ChikyuEarthRealistic extends HTMLElement {
313
314
  onPose: (pose) => {
314
315
  if (this.#hands)
315
316
  this.#hands.controller.grabRadius = discRadius(pose.width, pose.height, 1);
317
+ // the places first, then the markers (they keep off what the places take), then the cities', countries', stars' and constellations' names
318
+ if (this.#placeLayer && (this.#placeList.length > 0 || this.#placeLayer.stats.shown > 0)) {
319
+ this.#placeLayer.frame(orthoView(pose), [], [], this.#model.light === "lit" ? null : subsolarPoint(this.#model.time));
320
+ this.#notePlacesLost();
321
+ }
316
322
  this.#pose = { ...pose, transform: "" };
317
323
  this.#posing = true;
318
324
  try {
@@ -322,10 +328,6 @@ export class ChikyuEarthRealistic extends HTMLElement {
322
328
  finally {
323
329
  this.#posing = false;
324
330
  }
325
- if (this.#placeLayer && (this.#placeList.length > 0 || this.#placeLayer.stats.shown > 0)) {
326
- this.#placeLayer.frame(orthoView(pose), [], [], this.#model.light === "lit" ? null : subsolarPoint(this.#model.time));
327
- this.#notePlacesLost();
328
- }
329
331
  this.#cityFrame();
330
332
  },
331
333
  onPlaceRings: (drawn) => this.#ringsDrawn(drawn),
@@ -747,9 +749,40 @@ export class ChikyuEarthRealistic extends HTMLElement {
747
749
  return at.z;
748
750
  },
749
751
  };
750
- this.#cities.frame(frame);
751
752
  this.#nameFrame = frame;
753
+ this.#relayNames(true, false);
754
+ }
755
+ /**
756
+ * Lays the names that come after the places and the markers out on the last frame, in the order of the layers: the cities' names clear of the places' names, rings and marks and of the markers' labels; the countries' names clear of those and the cities'; the stars' and constellations'
757
+ * names clear of all of them. `cities` says whether the cities are laid out again (a new frame), or only what follows them (the cities told that they changed); `sky` says whether the stars' names are laid out again, which a draw does itself after the names.
758
+ */
759
+ #relayNames(cities, sky) {
760
+ if (cities && this.#nameFrame)
761
+ this.#cities?.frame(this.#nameFrame, this.#boxesBeforeCities());
752
762
  this.#countryFrame();
763
+ if (sky)
764
+ this.#sky?.relayout();
765
+ }
766
+ /** What the cities' names keep off: what the places layer takes (names, rings, marks) and the markers' labels (a city is named beside its own dot, which a marker may sit on, so the marks are not kept clear of). The list is refilled, not made again. */
767
+ #beforeCities = [];
768
+ #boxesBeforeCities() {
769
+ const out = this.#beforeCities;
770
+ out.length = 0;
771
+ out.push(...(this.#placeLayer?.boxes ?? []));
772
+ for (const boxes of this.#claimedNames.values())
773
+ out.push(...boxes);
774
+ return out;
775
+ }
776
+ /** What the stars' and constellations' names keep off: everything before them, the cities' names last. The list is refilled, not made again. */
777
+ #beforeSky = [];
778
+ #boxesBeforeSky() {
779
+ const out = this.#beforeSky;
780
+ out.length = 0;
781
+ out.push(...(this.#placeLayer?.boxes ?? []));
782
+ for (const boxes of this.#claims.values())
783
+ out.push(...boxes);
784
+ out.push(...(this.#cities?.boxes ?? []));
785
+ return out;
753
786
  }
754
787
  /** The frame the names were last laid out on. */
755
788
  #nameFrame = null;
@@ -838,19 +871,26 @@ export class ChikyuEarthRealistic extends HTMLElement {
838
871
  this.#listeners.add(listener);
839
872
  return () => this.#listeners.delete(listener);
840
873
  },
841
- claim: (owner, boxes) => {
842
- if (boxes.length === 0)
874
+ taken: () => this.#placeLayer?.boxes ?? [],
875
+ claim: (owner, boxes, names) => {
876
+ if (boxes.length === 0) {
843
877
  this.#claims.delete(owner);
844
- else
878
+ this.#claimedNames.delete(owner);
879
+ }
880
+ else {
845
881
  this.#claims.set(owner, boxes);
882
+ this.#claimedNames.set(owner, names ?? boxes);
883
+ }
846
884
  // laid out again only when the overlay changed between draws: at a draw the names are laid out after it anyway
847
885
  if (!this.#posing)
848
- this.#countryFrame();
886
+ this.#relayNames(true, true);
849
887
  },
850
888
  };
851
889
  }
852
890
  /** The boxes overlays on the element (markers) take, by overlay. */
853
891
  #claims = new Map();
892
+ /** The part of each overlay's boxes that is its labels'. */
893
+ #claimedNames = new Map();
854
894
  /** True while the overlays are told of a draw. */
855
895
  #posing = false;
856
896
  /** Where the view starts: longitude and latitude; the shared controls' yaw and tilt turn it from there. */
@@ -11,6 +11,8 @@ export interface SkyHost {
11
11
  refresh(): void;
12
12
  /** The places where the sky's names must not go (the property `keepClear`): rectangles in the element's pixels, or elements of the page. `null` for none. */
13
13
  setKeepClear(areas: readonly SkyKeepClear[] | null): void;
14
+ /** Lays the names out once more on the last frame, where a layer placed before this one has moved between draws (a marker list changed, city names arrived). Nothing happens when there is no frame or no name is asked for. */
15
+ relayout(): void;
14
16
  /** The look of the names, as a partial hoshi-stars `LabelStyle` (the property `skyStyle`). */
15
17
  setStyle(style: Partial<SkyLabelStyle>): void;
16
18
  /** Picks a constellation by its IAU abbreviation (`Ori`), or lets it go (`null`): the property `constellation`. Sends no event. */
@@ -52,6 +54,16 @@ export interface SkyHostOptions {
52
54
  importer?: () => Promise<typeof import("@johnmorrisdotca/hoshi-stars/sky-labels")>;
53
55
  /** Brings hoshi-stars' `constellations` in, for the names of the figures: a dynamic import by default. */
54
56
  constellations?: () => Promise<typeof import("@johnmorrisdotca/hoshi-stars/constellations")>;
57
+ /**
58
+ * The boxes the layers placed before the sky take in the picture just drawn (the places' names and marks, the markers' labels, the bodies' and the cities' names), as left, top, width and height from the picture's top left. No star name, ring or figure name goes over one.
59
+ * Read when the names are laid out; the element refills the same list, so nothing is made at a draw.
60
+ */
61
+ taken?: () => readonly {
62
+ left: number;
63
+ top: number;
64
+ width: number;
65
+ height: number;
66
+ }[];
55
67
  /** Brings a sky culture of hoshi-stars in (`western`, `japanese` or `chinese`): a dynamic import of the culture by default, a page's own (or a test's) where it has one. */
56
68
  cultures?: (id: string) => Promise<Culture>;
57
69
  }
package/dist/sky/host.js CHANGED
@@ -86,7 +86,10 @@ export function createSkyHost(options) {
86
86
  let covered;
87
87
  /** The places the page asked to keep clear, and as boxes from the picture's top left: measured when something has changed (a resize, a new list), never at each frame. */
88
88
  let keepList = [];
89
+ const pageKeep = [];
90
+ /** What the names keep off: the page's places (`pageKeep`) and the boxes the layers placed before the sky take (the pool `ext`, refilled at each layout). */
89
91
  const keep = [];
92
+ const ext = [];
90
93
  let keepStale = true;
91
94
  let keepWatch;
92
95
  let keepEvents = false;
@@ -104,7 +107,7 @@ export function createSkyHost(options) {
104
107
  queuedFrame = true;
105
108
  const run = () => {
106
109
  queuedFrame = false;
107
- if (module && last && (keep.length > 0 || options.attribute("constellation-names") !== null || shownAbbr !== null))
110
+ if (module && last && (pageKeep.length > 0 || options.attribute("constellation-names") !== null || shownAbbr !== null))
108
111
  compute();
109
112
  };
110
113
  if (typeof globalThis.requestAnimationFrame === "function")
@@ -131,7 +134,7 @@ export function createSkyHost(options) {
131
134
  const measureKeep = (rewatch) => {
132
135
  keepStale = false;
133
136
  const items = keepItems();
134
- keep.length = 0;
137
+ pageKeep.length = 0;
135
138
  if (items.length === 0) {
136
139
  keepWatch?.disconnect();
137
140
  return;
@@ -139,7 +142,7 @@ export function createSkyHost(options) {
139
142
  const host = root.host;
140
143
  const own = host.getBoundingClientRect();
141
144
  for (const item of items)
142
- keep.push(keepBox(item, own));
145
+ pageKeep.push(keepBox(item, own));
143
146
  if (!rewatch)
144
147
  return;
145
148
  // a box that grows or shrinks is read again and the layer laid out again; the observer is set again only when the list has changed
@@ -165,9 +168,27 @@ export function createSkyHost(options) {
165
168
  function markStale() {
166
169
  keepStale = true;
167
170
  // scrolled or resized while something is kept clear: the names are laid out again at the next frame, once however many events
168
- if (keep.length > 0)
171
+ if (pageKeep.length > 0)
169
172
  later();
170
173
  }
174
+ /** Joins the page's places and the boxes of the layers placed before: the objects are reused, nothing is made at a layout. */
175
+ function mergeKeep() {
176
+ keep.length = 0;
177
+ for (const one of pageKeep)
178
+ keep.push(one);
179
+ const others = options.taken?.();
180
+ if (!others)
181
+ return;
182
+ for (let i = 0; i < others.length; i += 1) {
183
+ const o = others[i];
184
+ const one = (ext[i] ??= { l: 0, t: 0, r: 0, b: 0 });
185
+ one.l = o.left;
186
+ one.t = o.top;
187
+ one.r = o.left + o.width;
188
+ one.b = o.top + o.height;
189
+ keep.push(one);
190
+ }
191
+ }
171
192
  let keepRewatch = true;
172
193
  const attach = () => {
173
194
  if (attached)
@@ -980,6 +1001,7 @@ export function createSkyHost(options) {
980
1001
  measureKeep(keepRewatch);
981
1002
  keepRewatch = false;
982
1003
  }
1004
+ mergeKeep();
983
1005
  takenStale = true;
984
1006
  hulls.length = 0;
985
1007
  if (names)
@@ -1059,6 +1081,10 @@ export function createSkyHost(options) {
1059
1081
  configure();
1060
1082
  compute();
1061
1083
  },
1084
+ relayout() {
1085
+ if (module && wanted() && last)
1086
+ compute();
1087
+ },
1062
1088
  setKeepClear(areas) {
1063
1089
  keepList = areas ? [...areas] : [];
1064
1090
  keepRewatch = true;
@@ -245,6 +245,7 @@ export class ChikyuSpace extends HTMLElement {
245
245
  language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
246
246
  onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-sky-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
247
247
  loadFont: loadMichroma,
248
+ taken: () => this.#boxesBeforeSky(),
248
249
  });
249
250
  this.#sky.setStyle(this.#skyStyle);
250
251
  this.#sky.setKeepClear(this.#keepClear);
@@ -258,7 +259,7 @@ export class ChikyuSpace extends HTMLElement {
258
259
  attribute: (name) => this.getAttribute(name),
259
260
  language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
260
261
  onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-city-names-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
261
- onLayout: () => this.#countryFrame(),
262
+ onLayout: () => this.#relayNames(false, true),
262
263
  });
263
264
  this.#cities.setStyle(this.#citiesStyle);
264
265
  Object.assign(this.#model.borders, readBorders(this.getAttribute("borders")));
@@ -705,9 +706,37 @@ export class ChikyuSpace extends HTMLElement {
705
706
  }
706
707
  /** Tells the names of cities, then of countries, where the Earth is in the picture just drawn; the countries' names keep clear of the bodies', the places' and the cities'. */
707
708
  #nameFrame(frame) {
708
- this.#cities?.frame(frame);
709
709
  this.#lastNameFrame = frame;
710
+ this.#relayNames(true, false);
711
+ }
712
+ /**
713
+ * Lays the names that come after the places out on the last frame, in the order of the layers: the cities' names clear of the bodies' names and the places' names, rings and marks; the countries' names clear of those and the cities'; the stars' and constellations' names
714
+ * clear of all of them. `cities` says whether the cities are laid out again (a new frame), or only what follows them (the cities told that they changed); `sky` says whether the stars' names are laid out again, which a draw does itself after the names.
715
+ */
716
+ #relayNames(cities, sky) {
717
+ if (cities)
718
+ this.#cities?.frame(this.#lastNameFrame, this.#boxesBeforeCities());
710
719
  this.#countryFrame();
720
+ if (sky)
721
+ this.#sky?.relayout();
722
+ }
723
+ /** What the cities' names keep off: the bodies' names and what the places layer takes (names, rings, marks). The list is refilled, not made again. */
724
+ #beforeCities = [];
725
+ #boxesBeforeCities() {
726
+ const out = this.#beforeCities;
727
+ out.length = 0;
728
+ out.push(...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []));
729
+ return out;
730
+ }
731
+ /** What the stars' and constellations' names keep off: everything before them, the cities' names last. The list is refilled, not made again. */
732
+ #beforeSky = [];
733
+ #boxesBeforeSky() {
734
+ const out = this.#beforeSky;
735
+ out.length = 0;
736
+ if (!this.#lastNameFrame)
737
+ return out;
738
+ out.push(...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? []));
739
+ return out;
711
740
  }
712
741
  /** The frame the names were last laid out on. */
713
742
  #lastNameFrame = null;
@@ -832,6 +832,38 @@ export function createSpaceItem(model, deps) {
832
832
  if (model.bodyLabel.settings && !nameOn)
833
833
  nameOn = createBodyLabelLayer(three, earth, model.bodyLabel, { invalidate: () => deps.invalidate(), ...(deps.onLabelError ? { onError: deps.onLabelError } : {}) });
834
834
  nameOn?.sync(camera, rideFrom ? 0 : Math.min(px.Earth, 1e5));
835
+ if (deps.onCities) {
836
+ if (hidden === "Earth")
837
+ deps.onCities(null);
838
+ else {
839
+ // a place on the ground, turned with the Earth (the Earth is at the middle, one unit in radius): in sight when the viewer is above its horizon, found through the camera
840
+ const ground = new three.Vector3();
841
+ const eye = camera.position;
842
+ const turned = earth.quaternion;
843
+ ground.set(0, 0, 0).project(camera);
844
+ const disc = { x: ((ground.x + 1) / 2) * size.width, y: ((1 - ground.y) / 2) * size.height, radius: Math.min(px.Earth, 1e5) };
845
+ deps.onCities({
846
+ width: size.width,
847
+ height: size.height,
848
+ radius: Math.min(px.Earth, 1e5),
849
+ ...(ground.z > -1 && ground.z < 1 ? { disc } : {}),
850
+ project(lon, lat, out) {
851
+ const phi = lat * RAD;
852
+ const lambda = lon * RAD;
853
+ ground.set(Math.cos(phi) * Math.sin(lambda), Math.sin(phi), Math.cos(phi) * Math.cos(lambda)).applyQuaternion(turned);
854
+ const dx = eye.x - ground.x;
855
+ const dy = eye.y - ground.y;
856
+ const dz = eye.z - ground.z;
857
+ const facing = (ground.x * dx + ground.y * dy + ground.z * dz) / (Math.hypot(dx, dy, dz) || 1);
858
+ ground.project(camera);
859
+ out.x = ((ground.x + 1) / 2) * size.width;
860
+ out.y = ((1 - ground.y) / 2) * size.height;
861
+ return ground.z > 1 || ground.z < -1 ? -1 : facing;
862
+ },
863
+ });
864
+ }
865
+ }
866
+ // the sky after the places and the city names, so its names keep clear of what they take as it is laid out
835
867
  if (deps.onSky) {
836
868
  const sky = new three.Vector3();
837
869
  // stars are directions: a point far along the direction from the camera, in the scene's axes (x to the vernal equinox, y north, z completing the hand), seen through the camera
@@ -869,37 +901,6 @@ export function createSpaceItem(model, deps) {
869
901
  },
870
902
  });
871
903
  }
872
- if (deps.onCities) {
873
- if (hidden === "Earth")
874
- deps.onCities(null);
875
- else {
876
- // a place on the ground, turned with the Earth (the Earth is at the middle, one unit in radius): in sight when the viewer is above its horizon, found through the camera
877
- const ground = new three.Vector3();
878
- const eye = camera.position;
879
- const turned = earth.quaternion;
880
- ground.set(0, 0, 0).project(camera);
881
- const disc = { x: ((ground.x + 1) / 2) * size.width, y: ((1 - ground.y) / 2) * size.height, radius: Math.min(px.Earth, 1e5) };
882
- deps.onCities({
883
- width: size.width,
884
- height: size.height,
885
- radius: Math.min(px.Earth, 1e5),
886
- ...(ground.z > -1 && ground.z < 1 ? { disc } : {}),
887
- project(lon, lat, out) {
888
- const phi = lat * RAD;
889
- const lambda = lon * RAD;
890
- ground.set(Math.cos(phi) * Math.sin(lambda), Math.sin(phi), Math.cos(phi) * Math.cos(lambda)).applyQuaternion(turned);
891
- const dx = eye.x - ground.x;
892
- const dy = eye.y - ground.y;
893
- const dz = eye.z - ground.z;
894
- const facing = (ground.x * dx + ground.y * dy + ground.z * dz) / (Math.hypot(dx, dy, dz) || 1);
895
- ground.project(camera);
896
- out.x = ((ground.x + 1) / 2) * size.width;
897
- out.y = ((1 - ground.y) / 2) * size.height;
898
- return ground.z > 1 || ground.z < -1 ? -1 : facing;
899
- },
900
- });
901
- }
902
- }
903
904
  if (layer && deps.onSelected) {
904
905
  const at = model.satellites.selected ? layer.place(camera, size) : null;
905
906
  if (at || selectedShown)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/chikyu-earth",
3
- "version": "0.39.0",
3
+ "version": "0.40.0",
4
4
  "description": "Chikyu Earth 地球 — A line-drawn globe for the web: country outlines that turn at the Earth's own rate, centred on the place you give it, with an optional realistic Earth from space (three.js), the Sun, Moon and planets, satellites on their orbits, and markers for any place. A web component and an SVG string.",
5
5
  "keywords": [
6
6
  "earth",