bruce-cesium 7.0.8 → 7.1.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.
@@ -6307,6 +6307,7 @@
6307
6307
  // Attached to a cesium viewer to indicate a re-check should be done.
6308
6308
  // This is to override the cache that avoids re-checking when the camera hasn't moved.
6309
6309
  const SHOULD_RECHECK_KEY = Symbol("SHOULD_RECHECK_KEY");
6310
+ const RECHECK_KICK_KEY = Symbol("RECHECK_KICK_KEY");
6310
6311
  /**
6311
6312
  * We will recheck if the camera has turned or moved enough.
6312
6313
  * @param viewer
@@ -6453,6 +6454,8 @@
6453
6454
  }
6454
6455
  const toRemove = [];
6455
6456
  const toAdd = [];
6457
+ // Entities the register has to re-evaluate, because the culler cannot restore a `show` it did not set.
6458
+ const toRefresh = new Set();
6456
6459
  const isIsolatedAny = register.GetIsIsolatedAny();
6457
6460
  const slice = entityIds.splice(0, CHECK_BATCH);
6458
6461
  for (let i = 0; i < slice.length; i++) {
@@ -6490,17 +6493,23 @@
6490
6493
  }
6491
6494
  const shouldCull = shouldCullEntity(viewer, part);
6492
6495
  if (shouldCull) {
6493
- part[VisualRegisterCuller.VISUAL_CULL_KEY] = true;
6496
+ part[exports.VisualRegisterCuller.VISUAL_CULL_KEY] = true;
6494
6497
  toRemove.push(part);
6495
6498
  }
6496
6499
  else {
6497
- delete part[VisualRegisterCuller.VISUAL_CULL_KEY];
6500
+ delete part[exports.VisualRegisterCuller.VISUAL_CULL_KEY];
6498
6501
  if (rego.overrideShow != false &&
6499
6502
  !IsCEntityInScene(viewer, part) &&
6500
6503
  !state.hidden &&
6501
6504
  (!isIsolatedAny || state.isolated)) {
6502
6505
  toAdd.push(part);
6503
6506
  }
6507
+ else if (part.show === false &&
6508
+ rego.overrideShow != false &&
6509
+ !state.hidden &&
6510
+ (!isIsolatedAny || state.isolated)) {
6511
+ toRefresh.add(entityId);
6512
+ }
6504
6513
  }
6505
6514
  }
6506
6515
  }
@@ -6511,6 +6520,11 @@
6511
6520
  if (toAdd.length > 0) {
6512
6521
  addEntities(viewer, toAdd);
6513
6522
  }
6523
+ if (toRefresh.size > 0) {
6524
+ register.ForceUpdate({
6525
+ entityIds: Array.from(toRefresh)
6526
+ });
6527
+ }
6514
6528
  if (entityIds.length <= 0) {
6515
6529
  clearInterval(checkInterval);
6516
6530
  checkInterval = null;
@@ -6574,7 +6588,6 @@
6574
6588
  });
6575
6589
  });
6576
6590
  }
6577
- var VisualRegisterCuller;
6578
6591
  (function (VisualRegisterCuller) {
6579
6592
  VisualRegisterCuller.VISUAL_CULL_KEY = Symbol("VISUAL_CULL_KEY");
6580
6593
  /**
@@ -6597,6 +6610,7 @@
6597
6610
  runCullChecker(register);
6598
6611
  lastCullCheck = new Date();
6599
6612
  }, 1000);
6613
+ register.Viewer[RECHECK_KICK_KEY] = () => { var _a; return (_a = checkQueue === null || checkQueue === void 0 ? void 0 : checkQueue.Call) === null || _a === void 0 ? void 0 : _a.call(checkQueue); };
6600
6614
  let moveStartRemoval = register.Viewer.camera.moveStart.addEventListener(() => {
6601
6615
  var _a;
6602
6616
  (_a = checkQueue.Call) === null || _a === void 0 ? void 0 : _a.call(checkQueue);
@@ -6639,6 +6653,9 @@
6639
6653
  checkWaiting = false;
6640
6654
  checkQueue === null || checkQueue === void 0 ? void 0 : checkQueue.Dispose();
6641
6655
  checkQueue = null;
6656
+ if (register.Viewer) {
6657
+ delete register.Viewer[RECHECK_KICK_KEY];
6658
+ }
6642
6659
  };
6643
6660
  }
6644
6661
  VisualRegisterCuller.Monitor = Monitor;
@@ -6729,16 +6746,28 @@
6729
6746
  return false;
6730
6747
  }
6731
6748
  if (visual instanceof Cesium.Entity) {
6732
- return visual[VisualRegisterCuller.VISUAL_CULL_KEY] == true;
6749
+ if (visual[VisualRegisterCuller.VISUAL_CULL_KEY] != true) {
6750
+ return false;
6751
+ }
6752
+ // Invalidated, so the decision above was measured from geometry that no longer describes this.
6753
+ return boundingSphereCache.Get(visual.id) != null;
6733
6754
  }
6734
6755
  return false;
6735
6756
  }
6736
6757
  VisualRegisterCuller.IsCulled = IsCulled;
6758
+ /**
6759
+ * Asks for the next cull pass to actually re-measure, and brings that pass forward.
6760
+ */
6737
6761
  function MarkShouldRecheck(viewer) {
6762
+ var _a, _b;
6763
+ if (!viewer || ((_a = viewer.isDestroyed) === null || _a === void 0 ? void 0 : _a.call(viewer))) {
6764
+ return;
6765
+ }
6738
6766
  viewer[SHOULD_RECHECK_KEY] = true;
6767
+ (_b = viewer[RECHECK_KICK_KEY]) === null || _b === void 0 ? void 0 : _b.call(viewer);
6739
6768
  }
6740
6769
  VisualRegisterCuller.MarkShouldRecheck = MarkShouldRecheck;
6741
- })(VisualRegisterCuller || (VisualRegisterCuller = {}));
6770
+ })(exports.VisualRegisterCuller || (exports.VisualRegisterCuller = {}));
6742
6771
 
6743
6772
  function isTilesetFeatureAlive(visual) {
6744
6773
  const cTileset = visual === null || visual === void 0 ? void 0 : visual.tileset;
@@ -6825,7 +6854,7 @@
6825
6854
  }
6826
6855
  // A sub-object can be culled while the siblings are not.
6827
6856
  // We only cull things that give us some benefit. For example clamped to ground graphics are expensive to keep rendered.
6828
- show = show ? !VisualRegisterCuller.IsCulled(viewer, rego, visual) : false;
6857
+ show = show ? !exports.VisualRegisterCuller.IsCulled(viewer, rego, visual) : false;
6829
6858
  if (visual._parentEntity && !ignoreParent) {
6830
6859
  updateCEntityShow(viewer, visual._parentEntity, rego, show, false, depth + 1);
6831
6860
  }
@@ -7178,7 +7207,7 @@
7178
7207
  this.tilesets = new Map();
7179
7208
  this.viewer = params.viewer;
7180
7209
  this.apiGetters = params.apiGetters;
7181
- this.cameraCullerDispose = VisualRegisterCuller.Monitor({
7210
+ this.cameraCullerDispose = exports.VisualRegisterCuller.Monitor({
7182
7211
  register: this
7183
7212
  });
7184
7213
  }
@@ -8190,6 +8219,26 @@
8190
8219
  exports.CesiumEntityStyler.UpdateColorSetting("highlight", color);
8191
8220
  }
8192
8221
  }
8222
+ /**
8223
+ * Whether any rego for this entity is currently held as being edited.
8224
+ */
8225
+ IsEditing(params) {
8226
+ const { entityId, menuItemId } = params;
8227
+ const regos = this.rego[entityId];
8228
+ if (!(regos === null || regos === void 0 ? void 0 : regos.length)) {
8229
+ return false;
8230
+ }
8231
+ for (let i = 0; i < regos.length; i++) {
8232
+ const rego = regos[i];
8233
+ if (menuItemId && rego.menuItemId !== menuItemId) {
8234
+ continue;
8235
+ }
8236
+ if (rego.editing) {
8237
+ return true;
8238
+ }
8239
+ }
8240
+ return false;
8241
+ }
8193
8242
  /**
8194
8243
  * Marks visuals as being actively edited, which exempts them from culling until it is turned back off.
8195
8244
  */
@@ -8210,12 +8259,15 @@
8210
8259
  if (menuItemId && rego.menuItemId !== menuItemId) {
8211
8260
  continue;
8212
8261
  }
8213
- if (Boolean(rego.editing) == Boolean(editing)) {
8262
+ const wasEditing = Boolean(rego.editing);
8263
+ if (wasEditing == Boolean(editing) && editing) {
8214
8264
  continue;
8215
8265
  }
8216
8266
  // Null rather than false, so the rego does not carry a key for every visual ever edited.
8217
8267
  rego.editing = editing ? true : null;
8218
- changed = true;
8268
+ if (wasEditing != Boolean(editing)) {
8269
+ changed = true;
8270
+ }
8219
8271
  if (editing) {
8220
8272
  const parts = exports.EntityUtils.GatherEntity({
8221
8273
  entity: rego.visual
@@ -8225,18 +8277,17 @@
8225
8277
  if (!(part instanceof Cesium.Entity)) {
8226
8278
  continue;
8227
8279
  }
8228
- const removalPending = VisualRegisterCuller.CancelQueuedSceneChange(part);
8229
- const wasCulled = part[VisualRegisterCuller.VISUAL_CULL_KEY] == true || removalPending;
8230
- delete part[VisualRegisterCuller.VISUAL_CULL_KEY];
8280
+ const removalPending = exports.VisualRegisterCuller.CancelQueuedSceneChange(part);
8281
+ const wasCulled = part[exports.VisualRegisterCuller.VISUAL_CULL_KEY] == true || removalPending;
8282
+ delete part[exports.VisualRegisterCuller.VISUAL_CULL_KEY];
8231
8283
  if (wasCulled && !IsCEntityInScene(this.viewer, part)) {
8232
8284
  AddCEntityToScene(this.viewer, part, rego.collection);
8233
8285
  }
8234
8286
  }
8235
8287
  }
8236
8288
  else {
8237
- // The geometry almost certainly moved, so what was measured before is worthless.
8238
- VisualRegisterCuller.InvalidateBounds(rego.visual);
8239
- VisualRegisterCuller.MarkShouldRecheck(this.viewer);
8289
+ exports.VisualRegisterCuller.InvalidateBounds(rego.visual);
8290
+ exports.VisualRegisterCuller.MarkShouldRecheck(this.viewer);
8240
8291
  }
8241
8292
  }
8242
8293
  }
@@ -8710,6 +8761,9 @@
8710
8761
  // Tilesets will often add -> remove -> add because of how tiles load in and out of the scene.
8711
8762
  // To avoid flickering, we'll just replace rather than remove -> add.
8712
8763
  if (!rego.tilesetId && params.removePrior != false) {
8764
+ if (!rego.editing && this.IsEditing({ entityId: rego.entityId, menuItemId: rego.menuItemId })) {
8765
+ rego.editing = true;
8766
+ }
8713
8767
  this.RemoveRegos({
8714
8768
  entityId: rego.entityId,
8715
8769
  menuItemId: rego.menuItemId,
@@ -34664,6 +34718,54 @@
34664
34718
  });
34665
34719
  }
34666
34720
  EntityUtils.GetPosAsync = GetPosAsync;
34721
+ // Graphics that take a heightReference, and so get a cached terrain offset from Cesium.
34722
+ const GROUND_REFERENCED_GRAPHICS = ["ellipse", "polygon", "corridor", "rectangle", "box", "cylinder", "ellipsoid"];
34723
+ const HEIGHT_REFERENCE_KEYS = ["heightReference", "extrudedHeightReference"];
34724
+ /**
34725
+ * Makes a moved graphic sample the ground again at where it now is.
34726
+ *
34727
+ * Reassigning the height references touches an observed property, so the updater discards the stale offset
34728
+ * and builds a new one against the current position.
34729
+ * @returns whether anything was refreshed.
34730
+ */
34731
+ function RefreshGroundClamping(params) {
34732
+ var _a, _b;
34733
+ const { viewer, visual } = params;
34734
+ if (!viewer || ((_a = viewer.isDestroyed) === null || _a === void 0 ? void 0 : _a.call(viewer)) || !(visual instanceof Cesium.Entity)) {
34735
+ return false;
34736
+ }
34737
+ const parts = GatherEntity({ entity: visual });
34738
+ let refreshed = false;
34739
+ for (let i = 0; i < parts.length; i++) {
34740
+ const part = parts[i];
34741
+ if (!(part instanceof Cesium.Entity)) {
34742
+ continue;
34743
+ }
34744
+ for (let j = 0; j < GROUND_REFERENCED_GRAPHICS.length; j++) {
34745
+ const graphic = part[GROUND_REFERENCED_GRAPHICS[j]];
34746
+ if (!graphic) {
34747
+ continue;
34748
+ }
34749
+ for (let k = 0; k < HEIGHT_REFERENCE_KEYS.length; k++) {
34750
+ const key = HEIGHT_REFERENCE_KEYS[k];
34751
+ const current = GetValue$1(viewer, graphic[key]);
34752
+ // Nothing to resample for a graphic that does not follow the ground.
34753
+ if (current == null || current === Cesium.HeightReference.NONE) {
34754
+ continue;
34755
+ }
34756
+ // A new property instance rather than the same value written back, since an equal value would
34757
+ // be dropped as a no-op and the updater would never hear about it.
34758
+ graphic[key] = new Cesium.ConstantProperty(current);
34759
+ refreshed = true;
34760
+ }
34761
+ }
34762
+ }
34763
+ if (refreshed) {
34764
+ (_b = viewer.scene) === null || _b === void 0 ? void 0 : _b.requestRender();
34765
+ }
34766
+ return refreshed;
34767
+ }
34768
+ EntityUtils.RefreshGroundClamping = RefreshGroundClamping;
34667
34769
  /**
34668
34770
  * Returns entity and any associated parent/sibling entities as a flat array.
34669
34771
  * @param entity
@@ -34854,7 +34956,9 @@
34854
34956
  viewer: params.viewer,
34855
34957
  createIfMissing: true
34856
34958
  });
34857
- const location = await EntityUtils.GetLocation({
34959
+ // A tileset-only fly-to has no entities to sample from, so there's nothing to resolve here.
34960
+ // The tileset's own bounding sphere is used further down instead.
34961
+ const location = (entityIds === null || entityIds === void 0 ? void 0 : entityIds.length) ? await EntityUtils.GetLocation({
34858
34962
  samples: entityIds.map((id) => ({
34859
34963
  entityId: id,
34860
34964
  entity: entityLookup.get(id),
@@ -34865,7 +34969,7 @@
34865
34969
  visualRegister: manager.VisualsRegister,
34866
34970
  minimumAlt: params.minimumAlt,
34867
34971
  api: manager.Getters.GetBruceApi()
34868
- });
34972
+ }) : null;
34869
34973
  if (params.isCancelled && params.isCancelled()) {
34870
34974
  return;
34871
34975
  }
@@ -36969,7 +37073,7 @@
36969
37073
  model._radius = radius;
36970
37074
  model._radiusLoaded = true;
36971
37075
  if (params.viewer && params.viewer.scene && !params.viewer.isDestroyed()) {
36972
- VisualRegisterCuller.MarkShouldRecheck(params.viewer);
37076
+ exports.VisualRegisterCuller.MarkShouldRecheck(params.viewer);
36973
37077
  }
36974
37078
  }
36975
37079
  // Rough estimate on when the model is ready in the scene.
@@ -39574,8 +39678,9 @@
39574
39678
  if (bandCheck) {
39575
39679
  cEntity._bandCheck = bandCheck;
39576
39680
  }
39577
- VisualRegisterCuller.InvalidateBounds(cEntity);
39681
+ exports.VisualRegisterCuller.InvalidateBounds(cEntity);
39578
39682
  });
39683
+ exports.VisualRegisterCuller.MarkShouldRecheck(params.viewer);
39579
39684
  return {
39580
39685
  entities: cEntities,
39581
39686
  updated
@@ -40341,7 +40446,7 @@
40341
40446
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
40342
40447
  })(exports.StyleUtils || (exports.StyleUtils = {}));
40343
40448
 
40344
- const VERSION = "7.0.8";
40449
+ const VERSION = "7.1.0";
40345
40450
  /**
40346
40451
  * Updates the environment instance used by bruce-cesium to one specified.
40347
40452
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.