bruce-cesium 7.0.7 → 7.0.9

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.
@@ -6010,7 +6010,7 @@
6010
6010
  }
6011
6011
  if (height == null || isNaN(height)) {
6012
6012
  // Terrain tile not loaded yet. Don't record it, so a later pass can sample it properly.
6013
- return coarseCell ? coarseCell.offset : 0;
6013
+ return coarseCell ? coarseCell.offset : NaN;
6014
6014
  }
6015
6015
  // Always fold into the coarse cell as well, so its spread keeps being learned even while the finer grid is
6016
6016
  // answering lookups for this region.
@@ -6033,6 +6033,9 @@
6033
6033
  return pos3d;
6034
6034
  }
6035
6035
  const offset = getTerrainOffset(viewer, pos3d);
6036
+ if (typeof offset == "number" && isNaN(offset)) {
6037
+ return null;
6038
+ }
6036
6039
  if (!offset) {
6037
6040
  return pos3d;
6038
6041
  }
@@ -6282,7 +6285,13 @@
6282
6285
  adjustedSphere.radius += TERRAIN_SKIP_RADIUS_PAD;
6283
6286
  }
6284
6287
  else {
6285
- adjustedSphere.center = adjustPos3d(viewer, boundingSphere.heightRef, adjustedSphere.center);
6288
+ const grounded = adjustPos3d(viewer, boundingSphere.heightRef, adjustedSphere.center);
6289
+ if (!grounded) {
6290
+ // Where this sits depends on ground we have not loaded yet. Guessing means guessing wrong sometimes,
6291
+ // and a wrong cull hides something that is on screen with nothing to bring it back.
6292
+ return false;
6293
+ }
6294
+ adjustedSphere.center = grounded;
6286
6295
  }
6287
6296
  const cullingVolume = camera.frustum.computeCullingVolume(camera.position, camera.direction, camera.up);
6288
6297
  const visibility = cullingVolume.computeVisibility(adjustedSphere);
@@ -6298,6 +6307,7 @@
6298
6307
  // Attached to a cesium viewer to indicate a re-check should be done.
6299
6308
  // This is to override the cache that avoids re-checking when the camera hasn't moved.
6300
6309
  const SHOULD_RECHECK_KEY = Symbol("SHOULD_RECHECK_KEY");
6310
+ const RECHECK_KICK_KEY = Symbol("RECHECK_KICK_KEY");
6301
6311
  /**
6302
6312
  * We will recheck if the camera has turned or moved enough.
6303
6313
  * @param viewer
@@ -6481,11 +6491,11 @@
6481
6491
  }
6482
6492
  const shouldCull = shouldCullEntity(viewer, part);
6483
6493
  if (shouldCull) {
6484
- part[VisualRegisterCuller.VISUAL_CULL_KEY] = true;
6494
+ part[exports.VisualRegisterCuller.VISUAL_CULL_KEY] = true;
6485
6495
  toRemove.push(part);
6486
6496
  }
6487
6497
  else {
6488
- delete part[VisualRegisterCuller.VISUAL_CULL_KEY];
6498
+ delete part[exports.VisualRegisterCuller.VISUAL_CULL_KEY];
6489
6499
  if (rego.overrideShow != false &&
6490
6500
  !IsCEntityInScene(viewer, part) &&
6491
6501
  !state.hidden &&
@@ -6565,7 +6575,6 @@
6565
6575
  });
6566
6576
  });
6567
6577
  }
6568
- var VisualRegisterCuller;
6569
6578
  (function (VisualRegisterCuller) {
6570
6579
  VisualRegisterCuller.VISUAL_CULL_KEY = Symbol("VISUAL_CULL_KEY");
6571
6580
  /**
@@ -6588,6 +6597,7 @@
6588
6597
  runCullChecker(register);
6589
6598
  lastCullCheck = new Date();
6590
6599
  }, 1000);
6600
+ 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); };
6591
6601
  let moveStartRemoval = register.Viewer.camera.moveStart.addEventListener(() => {
6592
6602
  var _a;
6593
6603
  (_a = checkQueue.Call) === null || _a === void 0 ? void 0 : _a.call(checkQueue);
@@ -6630,6 +6640,9 @@
6630
6640
  checkWaiting = false;
6631
6641
  checkQueue === null || checkQueue === void 0 ? void 0 : checkQueue.Dispose();
6632
6642
  checkQueue = null;
6643
+ if (register.Viewer) {
6644
+ delete register.Viewer[RECHECK_KICK_KEY];
6645
+ }
6633
6646
  };
6634
6647
  }
6635
6648
  VisualRegisterCuller.Monitor = Monitor;
@@ -6646,6 +6659,28 @@
6646
6659
  return isCullingIgnored(viewer, rego);
6647
6660
  }
6648
6661
  VisualRegisterCuller.IsCullingIgnored = IsCullingIgnored;
6662
+ /**
6663
+ * Drops any scene add/remove the culler has queued for these graphics.
6664
+ * Emits whether a removal was among them.
6665
+ * @param visuals an entity or an array of them.
6666
+ * @returns whether a queued removal was cancelled, ie. whether this graphic was on its way out.
6667
+ */
6668
+ function CancelQueuedSceneChange(visuals) {
6669
+ const list = Array.isArray(visuals) ? visuals : [visuals];
6670
+ let hadRemoval = false;
6671
+ for (let i = 0; i < list.length; i++) {
6672
+ const visual = list[i];
6673
+ if (!(visual instanceof Cesium.Entity)) {
6674
+ continue;
6675
+ }
6676
+ if (entityRemoveAddState.get(visual.id) === false) {
6677
+ hadRemoval = true;
6678
+ }
6679
+ entityRemoveAddState.delete(visual.id);
6680
+ }
6681
+ return hadRemoval;
6682
+ }
6683
+ VisualRegisterCuller.CancelQueuedSceneChange = CancelQueuedSceneChange;
6649
6684
  /**
6650
6685
  * Discards what the culler knows about an entity's extent, so its next check measures the geometry again.
6651
6686
  * The last cull decision is deliberately kept, see the loop below.
@@ -6677,6 +6712,19 @@
6677
6712
  invalidateBounds(ids);
6678
6713
  }
6679
6714
  VisualRegisterCuller.InvalidateBounds = InvalidateBounds;
6715
+ /**
6716
+ * Measures a graphic against the current view and says whether it is out of frame.
6717
+ */
6718
+ function ShouldCull(viewer, visual) {
6719
+ if (!(visual instanceof Cesium.Entity)) {
6720
+ return false;
6721
+ }
6722
+ return shouldCullEntity(viewer, visual);
6723
+ }
6724
+ VisualRegisterCuller.ShouldCull = ShouldCull;
6725
+ /**
6726
+ * Whether the last cull pass decided this graphic was out of frame.
6727
+ */
6680
6728
  function IsCulled(viewer, rego, visual) {
6681
6729
  if (isCullingIgnored(viewer, rego)) {
6682
6730
  return false;
@@ -6685,20 +6733,24 @@
6685
6733
  return false;
6686
6734
  }
6687
6735
  if (visual instanceof Cesium.Entity) {
6688
- let status = visual[VisualRegisterCuller.VISUAL_CULL_KEY];
6689
- if (status == null) {
6690
- status = visual[VisualRegisterCuller.VISUAL_CULL_KEY] = shouldCullEntity(viewer, visual);
6691
- }
6692
- return status;
6736
+ return visual[VisualRegisterCuller.VISUAL_CULL_KEY] == true;
6693
6737
  }
6694
6738
  return false;
6695
6739
  }
6696
6740
  VisualRegisterCuller.IsCulled = IsCulled;
6741
+ /**
6742
+ * Asks for the next cull pass to actually re-measure, and brings that pass forward.
6743
+ */
6697
6744
  function MarkShouldRecheck(viewer) {
6745
+ var _a, _b;
6746
+ if (!viewer || ((_a = viewer.isDestroyed) === null || _a === void 0 ? void 0 : _a.call(viewer))) {
6747
+ return;
6748
+ }
6698
6749
  viewer[SHOULD_RECHECK_KEY] = true;
6750
+ (_b = viewer[RECHECK_KICK_KEY]) === null || _b === void 0 ? void 0 : _b.call(viewer);
6699
6751
  }
6700
6752
  VisualRegisterCuller.MarkShouldRecheck = MarkShouldRecheck;
6701
- })(VisualRegisterCuller || (VisualRegisterCuller = {}));
6753
+ })(exports.VisualRegisterCuller || (exports.VisualRegisterCuller = {}));
6702
6754
 
6703
6755
  function isTilesetFeatureAlive(visual) {
6704
6756
  const cTileset = visual === null || visual === void 0 ? void 0 : visual.tileset;
@@ -6785,7 +6837,7 @@
6785
6837
  }
6786
6838
  // A sub-object can be culled while the siblings are not.
6787
6839
  // We only cull things that give us some benefit. For example clamped to ground graphics are expensive to keep rendered.
6788
- show = show ? !VisualRegisterCuller.IsCulled(viewer, rego, visual) : false;
6840
+ show = show ? !exports.VisualRegisterCuller.IsCulled(viewer, rego, visual) : false;
6789
6841
  if (visual._parentEntity && !ignoreParent) {
6790
6842
  updateCEntityShow(viewer, visual._parentEntity, rego, show, false, depth + 1);
6791
6843
  }
@@ -7138,7 +7190,7 @@
7138
7190
  this.tilesets = new Map();
7139
7191
  this.viewer = params.viewer;
7140
7192
  this.apiGetters = params.apiGetters;
7141
- this.cameraCullerDispose = VisualRegisterCuller.Monitor({
7193
+ this.cameraCullerDispose = exports.VisualRegisterCuller.Monitor({
7142
7194
  register: this
7143
7195
  });
7144
7196
  }
@@ -8150,6 +8202,26 @@
8150
8202
  exports.CesiumEntityStyler.UpdateColorSetting("highlight", color);
8151
8203
  }
8152
8204
  }
8205
+ /**
8206
+ * Whether any rego for this entity is currently held as being edited.
8207
+ */
8208
+ IsEditing(params) {
8209
+ const { entityId, menuItemId } = params;
8210
+ const regos = this.rego[entityId];
8211
+ if (!(regos === null || regos === void 0 ? void 0 : regos.length)) {
8212
+ return false;
8213
+ }
8214
+ for (let i = 0; i < regos.length; i++) {
8215
+ const rego = regos[i];
8216
+ if (menuItemId && rego.menuItemId !== menuItemId) {
8217
+ continue;
8218
+ }
8219
+ if (rego.editing) {
8220
+ return true;
8221
+ }
8222
+ }
8223
+ return false;
8224
+ }
8153
8225
  /**
8154
8226
  * Marks visuals as being actively edited, which exempts them from culling until it is turned back off.
8155
8227
  */
@@ -8170,12 +8242,15 @@
8170
8242
  if (menuItemId && rego.menuItemId !== menuItemId) {
8171
8243
  continue;
8172
8244
  }
8173
- if (Boolean(rego.editing) == Boolean(editing)) {
8245
+ const wasEditing = Boolean(rego.editing);
8246
+ if (wasEditing == Boolean(editing) && editing) {
8174
8247
  continue;
8175
8248
  }
8176
8249
  // Null rather than false, so the rego does not carry a key for every visual ever edited.
8177
8250
  rego.editing = editing ? true : null;
8178
- changed = true;
8251
+ if (wasEditing != Boolean(editing)) {
8252
+ changed = true;
8253
+ }
8179
8254
  if (editing) {
8180
8255
  const parts = exports.EntityUtils.GatherEntity({
8181
8256
  entity: rego.visual
@@ -8185,17 +8260,17 @@
8185
8260
  if (!(part instanceof Cesium.Entity)) {
8186
8261
  continue;
8187
8262
  }
8188
- const wasCulled = part[VisualRegisterCuller.VISUAL_CULL_KEY];
8189
- delete part[VisualRegisterCuller.VISUAL_CULL_KEY];
8263
+ const removalPending = exports.VisualRegisterCuller.CancelQueuedSceneChange(part);
8264
+ const wasCulled = part[exports.VisualRegisterCuller.VISUAL_CULL_KEY] == true || removalPending;
8265
+ delete part[exports.VisualRegisterCuller.VISUAL_CULL_KEY];
8190
8266
  if (wasCulled && !IsCEntityInScene(this.viewer, part)) {
8191
8267
  AddCEntityToScene(this.viewer, part, rego.collection);
8192
8268
  }
8193
8269
  }
8194
8270
  }
8195
8271
  else {
8196
- // The geometry almost certainly moved, so what was measured before is worthless.
8197
- VisualRegisterCuller.InvalidateBounds(rego.visual);
8198
- VisualRegisterCuller.MarkShouldRecheck(this.viewer);
8272
+ exports.VisualRegisterCuller.InvalidateBounds(rego.visual);
8273
+ exports.VisualRegisterCuller.MarkShouldRecheck(this.viewer);
8199
8274
  }
8200
8275
  }
8201
8276
  }
@@ -8669,6 +8744,9 @@
8669
8744
  // Tilesets will often add -> remove -> add because of how tiles load in and out of the scene.
8670
8745
  // To avoid flickering, we'll just replace rather than remove -> add.
8671
8746
  if (!rego.tilesetId && params.removePrior != false) {
8747
+ if (!rego.editing && this.IsEditing({ entityId: rego.entityId, menuItemId: rego.menuItemId })) {
8748
+ rego.editing = true;
8749
+ }
8672
8750
  this.RemoveRegos({
8673
8751
  entityId: rego.entityId,
8674
8752
  menuItemId: rego.menuItemId,
@@ -36928,7 +37006,7 @@
36928
37006
  model._radius = radius;
36929
37007
  model._radiusLoaded = true;
36930
37008
  if (params.viewer && params.viewer.scene && !params.viewer.isDestroyed()) {
36931
- VisualRegisterCuller.MarkShouldRecheck(params.viewer);
37009
+ exports.VisualRegisterCuller.MarkShouldRecheck(params.viewer);
36932
37010
  }
36933
37011
  }
36934
37012
  // Rough estimate on when the model is ready in the scene.
@@ -39533,8 +39611,9 @@
39533
39611
  if (bandCheck) {
39534
39612
  cEntity._bandCheck = bandCheck;
39535
39613
  }
39536
- VisualRegisterCuller.InvalidateBounds(cEntity);
39614
+ exports.VisualRegisterCuller.InvalidateBounds(cEntity);
39537
39615
  });
39616
+ exports.VisualRegisterCuller.MarkShouldRecheck(params.viewer);
39538
39617
  return {
39539
39618
  entities: cEntities,
39540
39619
  updated
@@ -40300,7 +40379,7 @@
40300
40379
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
40301
40380
  })(exports.StyleUtils || (exports.StyleUtils = {}));
40302
40381
 
40303
- const VERSION = "7.0.7";
40382
+ const VERSION = "7.0.9";
40304
40383
  /**
40305
40384
  * Updates the environment instance used by bruce-cesium to one specified.
40306
40385
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.