gralobe 1.0.39 → 1.0.41

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/dist/gralobe.js CHANGED
@@ -4186,6 +4186,7 @@ class it {
4186
4186
  countries = [];
4187
4187
  loaded = !1;
4188
4188
  statsMap;
4189
+ featureLabels = [];
4189
4190
  topologyConfig;
4190
4191
  // State for progressive rendering
4191
4192
  currentRenderId = 0;
@@ -4234,7 +4235,7 @@ class it {
4234
4235
  it.cache.set(e, t);
4235
4236
  }
4236
4237
  try {
4237
- this.countries = await it.cache.get(e), this.loaded = !0, this.onProgress?.(1);
4238
+ this.countries = await it.cache.get(e), this.loaded = !0, this.updateFeatureLabels(), this.onProgress?.(1);
4238
4239
  } catch (t) {
4239
4240
  it.cache.delete(e), console.error("Error loading cached topology:", t), this.loaded = !0;
4240
4241
  }
@@ -4265,7 +4266,50 @@ class it {
4265
4266
  setFeatures(e) {
4266
4267
  e.forEach((t) => {
4267
4268
  t.path || (t.path = this.createPath(t));
4268
- }), this.countries = e, this.loaded = !0, this.topologyConfig && (this.topologyConfig.disableNormalization = !0);
4269
+ }), this.countries = e, this.loaded = !0, this.topologyConfig && (this.topologyConfig.disableNormalization = !0), this.updateFeatureLabels();
4270
+ }
4271
+ /**
4272
+ * Update feature labels from current countries
4273
+ */
4274
+ updateFeatureLabels() {
4275
+ this.featureLabels = this.countries.map((e) => {
4276
+ const t = this.computeCentroid(e);
4277
+ return t ? {
4278
+ id: String(e.id || e.properties?.id || ""),
4279
+ name: e.properties?.name || e.properties?.NAME || e.properties?.Name || "",
4280
+ lat: t[1],
4281
+ lon: t[0]
4282
+ } : null;
4283
+ }).filter(
4284
+ (e) => e !== null && e.id !== "" && e.name !== ""
4285
+ );
4286
+ }
4287
+ /**
4288
+ * Get labels for all custom features (with centroids)
4289
+ */
4290
+ getFeatureLabels() {
4291
+ return this.featureLabels;
4292
+ }
4293
+ /**
4294
+ * Compute centroid of a GeoJSON feature (simple average for polygons)
4295
+ */
4296
+ computeCentroid(e) {
4297
+ const t = e.geometry;
4298
+ if (!t) return null;
4299
+ let i = [];
4300
+ if (t.type === "Point")
4301
+ return t.coordinates;
4302
+ if (t.type === "Polygon")
4303
+ i = t.coordinates.flat();
4304
+ else if (t.type === "MultiPolygon")
4305
+ i = t.coordinates.flat(2);
4306
+ else
4307
+ return null;
4308
+ if (i.length === 0) return null;
4309
+ let n = 0, r = 0;
4310
+ for (const s of i)
4311
+ n += s[0], r += s[1];
4312
+ return [n / i.length, r / i.length];
4269
4313
  }
4270
4314
  /**
4271
4315
  * Render a choropleth texture for the given statistic
@@ -6732,7 +6776,9 @@ class wo {
6732
6776
  duration: 1
6733
6777
  }));
6734
6778
  }
6735
- ), this.config.showLegend && (this.legend = new oo(this.container)), await this.createGlobe(), this.createStars(), this.config.effects.atmosphere && this.createAtmosphere(), this.countryLabels = new $a(this.container, Q), this.scene.add(this.countryLabels.getGroup()), this.globe && this.countryLabels.setGlobe(this.globe), this.countryLabels.setCamera(this.camera), this.countryLabels.setStyle(this.config.labels), this.exporter = new ro(this.renderer, this.scene, this.camera), this.legend && this.exporter.setLegendElement(this.legend.getElement()), this.countryLabels && this.exporter.setCountryLabels(this.countryLabels), this.config.showControls && this.createGUI(), this.setupInteraction(), await this.choropleth.waitForLoad(), this.setStatistic(this.config.statistic);
6779
+ ), this.config.showLegend && (this.legend = new oo(this.container)), await this.createGlobe(), this.createStars(), this.config.effects.atmosphere && this.createAtmosphere(), this.countryLabels = new $a(this.container, Q), this.scene.add(this.countryLabels.getGroup()), this.globe && this.countryLabels.setGlobe(this.globe), this.countryLabels.setCamera(this.camera), this.countryLabels.setStyle(this.config.labels), this.exporter = new ro(this.renderer, this.scene, this.camera), this.legend && this.exporter.setLegendElement(this.legend.getElement()), this.countryLabels && this.exporter.setCountryLabels(this.countryLabels), this.config.showControls && this.createGUI(), this.setupInteraction(), await this.choropleth.waitForLoad();
6780
+ const i = this.choropleth.getFeatureLabels();
6781
+ i.length > 0 && this.addCustomLabels(i), this.setStatistic(this.config.statistic);
6736
6782
  } catch (i) {
6737
6783
  console.error("GlobeViz init failed:", i);
6738
6784
  }
@@ -7054,7 +7100,7 @@ class wo {
7054
7100
  }
7055
7101
  }
7056
7102
  if (this.legend && i && this.legend.show(i), this.countryLabels && this.choropleth) {
7057
- const n = this.choropleth.getStatsMap(), r = n ? Array.from(n.keys()) : [];
7103
+ const n = this.choropleth.getStatsMap(), r = n ? Array.from(n.values()).map((s) => s.code) : [];
7058
7104
  this.countryLabels.setDataIds(r);
7059
7105
  }
7060
7106
  } else {
@@ -7129,14 +7175,16 @@ class wo {
7129
7175
  if (!this.choropleth) return;
7130
7176
  const t = await xo.mapPointsToTopology(e);
7131
7177
  this.choropleth.setFeatures(t.features);
7132
- const i = [
7178
+ const i = this.choropleth.getFeatureLabels();
7179
+ i.length > 0 && this.addCustomLabels(i);
7180
+ const n = [
7133
7181
  "#ffffb2",
7134
7182
  "#fd8d3c",
7135
7183
  "#bd0026"
7136
- ], n = Object.values(t.statistics), r = Math.max(...n, 1);
7137
- this.choropleth.renderCustomTexture(t.statistics, i, [
7184
+ ], r = Object.values(t.statistics), s = Math.max(...r, 1);
7185
+ this.choropleth.renderCustomTexture(t.statistics, n, [
7138
7186
  0,
7139
- r
7187
+ s
7140
7188
  ]), this.material && (this.material.uniforms.uCityLights.value = 1, this.config.effects.cityLights = !0), this.countryLabels && (this.countryLabels.getGroup().visible = !1);
7141
7189
  }
7142
7190
  resize(e, t) {