bruce-cesium 7.5.3 → 7.5.5

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.
@@ -12395,8 +12395,15 @@
12395
12395
  createIfMissing: params.createIfMissing !== false
12396
12396
  };
12397
12397
  const doc = this.viewer.container.ownerDocument;
12398
- doc.addEventListener("pointermove", this.CheckLabelHoverBounds, true);
12399
- this.viewer.container.addEventListener("pointerleave", this.CheckLabelHoverBounds);
12398
+ // Only a label following the cursor should go when the cursor leaves the canvas.
12399
+ if (params.position) {
12400
+ doc.addEventListener("pointermove", this.CheckLabelHoverBounds, true);
12401
+ this.viewer.container.addEventListener("pointerleave", this.CheckLabelHoverBounds);
12402
+ }
12403
+ else {
12404
+ doc.removeEventListener("pointermove", this.CheckLabelHoverBounds, true);
12405
+ this.viewer.container.removeEventListener("pointerleave", this.CheckLabelHoverBounds);
12406
+ }
12400
12407
  doc.defaultView.addEventListener("blur", this.ClearLabelHover);
12401
12408
  this.SyncLabelHover();
12402
12409
  this.viewer.scene.requestRender();
@@ -17255,6 +17262,9 @@
17255
17262
  }
17256
17263
  };
17257
17264
  }
17265
+ HasEntityDataOverride(eId) {
17266
+ return this.entityDataOverrides.has(eId);
17267
+ }
17258
17268
  SetEntityDataOverride(eId, entity) {
17259
17269
  if (this.disposed) {
17260
17270
  return;
@@ -17951,6 +17961,24 @@
17951
17961
  }
17952
17962
  return style;
17953
17963
  }
17964
+ /**
17965
+ * Reads the baked attribute declaration from a loaded tileset, keyed by path.
17966
+ * @param cTileset
17967
+ */
17968
+ function getBakedAttributes(cTileset) {
17969
+ var _a, _b;
17970
+ const result = new Map();
17971
+ const declared = (_b = (_a = cTileset === null || cTileset === void 0 ? void 0 : cTileset.extras) === null || _a === void 0 ? void 0 : _a.bruce) === null || _b === void 0 ? void 0 : _b.bakedAttributes;
17972
+ if (!Array.isArray(declared)) {
17973
+ return result;
17974
+ }
17975
+ for (const baked of declared) {
17976
+ if (Array.isArray(baked === null || baked === void 0 ? void 0 : baked.path) && baked.path.length && typeof baked.property == "string") {
17977
+ result.set(JSON.stringify(baked.path), baked);
17978
+ }
17979
+ }
17980
+ return result;
17981
+ }
17954
17982
  function colorToCColor$3(color) {
17955
17983
  return new Cesium.Color(color.red ? color.red / 255 : 0, color.green ? color.green / 255 : 0, color.blue ? color.blue / 255 : 0, color.alpha);
17956
17984
  }
@@ -18021,6 +18049,10 @@
18021
18049
  // When false the Entity data is still gathered and the regos still updated, but no colour is
18022
18050
  // applied. A historic item that did not ask for styling needs the first without the second.
18023
18051
  this.applyStyles = true;
18052
+ // Attribute values the tiles carry per feature, keyed by JSON path. Empty for a tileset without them.
18053
+ this.bakedAttributes = new Map();
18054
+ // Entities changed since the tileset was generated, so their baked values can no longer be trusted.
18055
+ this.bakedStaleIds = new Set();
18024
18056
  this.reRenderState = new EntityReRenderMaintainState();
18025
18057
  // More expensive process.
18026
18058
  // When an Entity is styled, the rego is reviewed and updated if needed.
@@ -18062,6 +18094,7 @@
18062
18094
  this.viewer = viewer;
18063
18095
  this.api = api;
18064
18096
  this.cTileset = cTileset;
18097
+ this.bakedAttributes = getBakedAttributes(cTileset);
18065
18098
  this.register = register;
18066
18099
  this.menuItemId = menuItemId;
18067
18100
  this.historic = Boolean(historic);
@@ -18140,6 +18173,7 @@
18140
18173
  for (const [internalId, entityId] of this.styledByInternalId) {
18141
18174
  if (BModels.RecordChangeFeed.isEntityInternalIdInRangeString(rangeStr, internalId)) {
18142
18175
  this.feedPendingRestyleIds.add(entityId);
18176
+ this.bakedStaleIds.add(entityId);
18143
18177
  }
18144
18178
  }
18145
18179
  if (this.feedPendingRestyleIds.size && !this.feedRestyleThrottleTimer) {
@@ -18460,17 +18494,7 @@
18460
18494
  for (const key of pendingKeys) {
18461
18495
  const relatedIds = this.stylePendingEntityIds.get(key);
18462
18496
  if (relatedIds) {
18463
- if (this.getTilesetFeatureNeedsFullData(key)) {
18464
- this.entityGatherer.Queue(Array.from(relatedIds));
18465
- }
18466
- else {
18467
- relatedIds.forEach(id => {
18468
- const rego = this.getEntityRego(id);
18469
- if (rego) {
18470
- this.styleTilesetFeature(rego);
18471
- }
18472
- });
18473
- }
18497
+ this.styleOrGatherIds(key, relatedIds);
18474
18498
  }
18475
18499
  }
18476
18500
  this.stylePendingEntityIds.clear();
@@ -18485,17 +18509,7 @@
18485
18509
  if (!relatedIds) {
18486
18510
  return;
18487
18511
  }
18488
- if (this.getTilesetFeatureNeedsFullData(entityTypeId)) {
18489
- this.entityGatherer.Queue(Array.from(relatedIds));
18490
- }
18491
- else {
18492
- relatedIds.forEach(id => {
18493
- const rego = this.getEntityRego(id);
18494
- if (rego) {
18495
- this.styleTilesetFeature(rego);
18496
- }
18497
- });
18498
- }
18512
+ this.styleOrGatherIds(entityTypeId, relatedIds);
18499
18513
  this.stylePendingEntityIds.delete(entityTypeId);
18500
18514
  }
18501
18515
  hasMappingRow(entityTypeId) {
@@ -18580,20 +18594,10 @@
18580
18594
  this.loadEntityTypeDefaultStyle(typeId);
18581
18595
  }
18582
18596
  if (this.styleMappingsLoaded.get(typeId) || (this.styleMappingLoaded && !this.hasMappingRow(typeId))) {
18583
- if (this.getTilesetFeatureNeedsFullData(typeId)) {
18584
- needsDataIds.push(rego.entityId);
18585
- }
18586
- else {
18587
- this.styleTilesetFeature(rego);
18588
- }
18597
+ this.styleOrCollect(rego, typeId, needsDataIds);
18589
18598
  }
18590
18599
  else if (!this.styleMappingsLoaded.has(typeId) && this.styleFallbackLoaded) {
18591
- if (this.getTilesetFeatureNeedsFullData(typeId)) {
18592
- needsDataIds.push(rego.entityId);
18593
- }
18594
- else {
18595
- this.styleTilesetFeature(rego);
18596
- }
18600
+ this.styleOrCollect(rego, typeId, needsDataIds);
18597
18601
  }
18598
18602
  else {
18599
18603
  if (!this.stylePendingEntityIds.has(typeId)) {
@@ -18606,6 +18610,96 @@
18606
18610
  this.entityGatherer.Queue(needsDataIds, highPriority);
18607
18611
  }
18608
18612
  }
18613
+ /**
18614
+ * Styles each Entity waiting on a type's style, gathering the records of those that need one.
18615
+ * @param entityTypeId
18616
+ * @param entityIds
18617
+ */
18618
+ styleOrGatherIds(entityTypeId, entityIds) {
18619
+ const gatherIds = [];
18620
+ for (const id of entityIds) {
18621
+ const rego = this.getEntityRego(id);
18622
+ if (rego) {
18623
+ this.styleOrCollect(rego, entityTypeId, gatherIds);
18624
+ }
18625
+ }
18626
+ if (gatherIds.length) {
18627
+ this.entityGatherer.Queue(gatherIds);
18628
+ }
18629
+ }
18630
+ /**
18631
+ * Styles a feature now when its style reads no record, or reads only values its tile carries, and otherwise collects it for gathering.
18632
+ * @param rego
18633
+ * @param entityTypeId
18634
+ * @param gatherIds Receives the Entity ID when its record is needed.
18635
+ */
18636
+ styleOrCollect(rego, entityTypeId, gatherIds) {
18637
+ if (!this.getTilesetFeatureNeedsFullData(entityTypeId)) {
18638
+ this.styleTilesetFeature(rego);
18639
+ return;
18640
+ }
18641
+ const record = this.canStyleFromBaked(rego.entityId, entityTypeId) ? this.readBakedRecord(rego.visual) : null;
18642
+ if (!record) {
18643
+ gatherIds.push(rego.entityId);
18644
+ return;
18645
+ }
18646
+ this.styleTilesetFeatureFullData(rego, record, []);
18647
+ // A later edit has to reach the record path, and the change feed finds Entities by Internal ID.
18648
+ if (rego.internalId != null) {
18649
+ this.styledByInternalId.set(rego.internalId, rego.entityId);
18650
+ }
18651
+ }
18652
+ /**
18653
+ * Returns if the tile's baked values hold everything this Entity's style would read from its record.
18654
+ * @param entityId
18655
+ * @param entityTypeId
18656
+ */
18657
+ canStyleFromBaked(entityId, entityTypeId) {
18658
+ var _a, _b, _c;
18659
+ // Baked values are the base record at generation time, which a scenario, a point in time or merged sources all differ from.
18660
+ if (!this.bakedAttributes.size || this.historic || !!this.scenario || this.expandSources) {
18661
+ return false;
18662
+ }
18663
+ if (this.bakedStaleIds.has(entityId) || ((_a = this.entityGatherer) === null || _a === void 0 ? void 0 : _a.HasEntityDataOverride(entityId))) {
18664
+ return false;
18665
+ }
18666
+ const paths = BModels.Calculator.GetFieldPaths((_c = (_b = this.getTilesetFeatureStyle(entityTypeId)) === null || _b === void 0 ? void 0 : _b.modelStyle) === null || _c === void 0 ? void 0 : _c.fillColor);
18667
+ return paths != null && paths.every(path => this.bakedAttributes.has(JSON.stringify(path)));
18668
+ }
18669
+ /**
18670
+ * Builds a stand-in record from a feature's baked values, holding only the attributes that have one.
18671
+ * Returns null when the feature's tile lacks a declared column, so the record is gathered instead.
18672
+ * @param visual
18673
+ */
18674
+ readBakedRecord(visual) {
18675
+ if (!(visual instanceof Cesium.Cesium3DTileFeature)) {
18676
+ return null;
18677
+ }
18678
+ const record = {};
18679
+ for (const baked of this.bakedAttributes.values()) {
18680
+ if (!visual.hasProperty(baked.property)) {
18681
+ return null;
18682
+ }
18683
+ let value = visual.getProperty(baked.property);
18684
+ if (value == null) {
18685
+ continue;
18686
+ }
18687
+ // Booleans travel as 0/1 because a boolean column has no way to say "no value".
18688
+ if (baked.type == "BOOLEAN") {
18689
+ value = value != 0;
18690
+ }
18691
+ let target = record;
18692
+ for (let i = 0; i < baked.path.length - 1; i++) {
18693
+ const segment = baked.path[i];
18694
+ if (target[segment] == null || typeof target[segment] != "object") {
18695
+ target[segment] = {};
18696
+ }
18697
+ target = target[segment];
18698
+ }
18699
+ target[baked.path[baked.path.length - 1]] = value;
18700
+ }
18701
+ return record;
18702
+ }
18609
18703
  styleTilesetFeature(rego) {
18610
18704
  this.styleTilesetFeatureFullData(rego, null, []);
18611
18705
  }
@@ -51083,7 +51177,7 @@ void main() {
51083
51177
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
51084
51178
  })(exports.StyleUtils || (exports.StyleUtils = {}));
51085
51179
 
51086
- const VERSION = "7.5.3";
51180
+ const VERSION = "7.5.5";
51087
51181
  /**
51088
51182
  * Updates the environment instance used by bruce-cesium to one specified.
51089
51183
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.