bruce-cesium 7.0.4 → 7.0.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.
@@ -6073,7 +6073,17 @@
6073
6073
  * Cesium's own flat ellipsoid. Deliberately not FlatTerrain, see shouldCullEntity.
6074
6074
  */
6075
6075
  const UNRECOGNISED_TERRAIN_ID = "unrecognised-terrain";
6076
+ // Keyed by entity id alone. A cached sphere is only as good as the geometry it was measured from, so anything
6077
+ // changing that geometry has to call InvalidateBounds, see it for why nothing can be inferred instead.
6076
6078
  const boundingSphereCache = new BModels.LRUCache(100000);
6079
+ /*
6080
+ * Forgets what is known about an entity's extent, so the next check measures it again.
6081
+ */
6082
+ function invalidateBounds(entityIds) {
6083
+ for (let i = 0; i < entityIds.length; i++) {
6084
+ boundingSphereCache.Delete(entityIds[i]);
6085
+ }
6086
+ }
6077
6087
  function getPositionsFromEntity(viewer, entity) {
6078
6088
  let positions = [];
6079
6089
  let heightRef;
@@ -6191,9 +6201,10 @@
6191
6201
  const terrainId = (_c = (_b = (_a = exports.ViewUtils.GatherTerrainTile({
6192
6202
  viewer
6193
6203
  })) === null || _a === void 0 ? void 0 : _a.terrain) === null || _b === void 0 ? void 0 : _b.tilesetId) !== null && _c !== void 0 ? _c : UNRECOGNISED_TERRAIN_ID;
6194
- const cacheKey = terrainId + cEntity.id;
6204
+ const cacheKey = cEntity.id;
6195
6205
  const cacheData = boundingSphereCache.Get(cacheKey);
6196
- if (cacheData) {
6206
+ // A sphere measured under different terrain cannot be reused, since the height treatment differs.
6207
+ if (cacheData && (cacheData == -1 || cacheData.terrainId == terrainId)) {
6197
6208
  boundingSphere = cacheData;
6198
6209
  }
6199
6210
  else {
@@ -6249,7 +6260,8 @@
6249
6260
  }
6250
6261
  boundingSphere = {
6251
6262
  heightRef: positions.heightRef,
6252
- sphere: sphere
6263
+ sphere: sphere,
6264
+ terrainId: terrainId
6253
6265
  };
6254
6266
  if (!doNotCache) {
6255
6267
  boundingSphereCache.Set(cacheKey, boundingSphere);
@@ -6344,6 +6356,8 @@
6344
6356
  rego.relation != null ||
6345
6357
  // Explicitly being either shown or hidden.
6346
6358
  rego.overrideShow != null ||
6359
+ // Being dragged around right now, so its extent is changing faster than we could measure it.
6360
+ rego.editing == true ||
6347
6361
  // Part of a collection we did not create, eg. a geojson data source, which may have its own rules for
6348
6362
  // what is in the scene. Our own per-menu-item data sources are fair game.
6349
6363
  (rego.collection && !IsCCollectionOwned(rego.collection)) ||
@@ -6632,6 +6646,38 @@
6632
6646
  return isCullingIgnored(viewer, rego);
6633
6647
  }
6634
6648
  VisualRegisterCuller.IsCullingIgnored = IsCullingIgnored;
6649
+ /**
6650
+ * Discards what the culler knows about an entity's extent, so its next check measures the geometry again.
6651
+ * @param visuals an entity, an entity id, or an array of either.
6652
+ */
6653
+ function InvalidateBounds(visuals) {
6654
+ const list = Array.isArray(visuals) ? visuals : [visuals];
6655
+ const ids = [];
6656
+ for (let i = 0; i < list.length; i++) {
6657
+ const item = list[i];
6658
+ if (!item) {
6659
+ continue;
6660
+ }
6661
+ if (typeof item == "string") {
6662
+ ids.push(item);
6663
+ continue;
6664
+ }
6665
+ const parts = exports.EntityUtils.GatherEntity({
6666
+ entity: item
6667
+ });
6668
+ for (let j = 0; j < parts.length; j++) {
6669
+ const part = parts[j];
6670
+ if (!(part instanceof Cesium.Entity)) {
6671
+ continue;
6672
+ }
6673
+ ids.push(part.id);
6674
+ // The per-entity answer is derived from the sphere, so it goes stale with it.
6675
+ delete part[VisualRegisterCuller.VISUAL_CULL_KEY];
6676
+ }
6677
+ }
6678
+ invalidateBounds(ids);
6679
+ }
6680
+ VisualRegisterCuller.InvalidateBounds = InvalidateBounds;
6635
6681
  function IsCulled(viewer, rego, visual) {
6636
6682
  if (isCullingIgnored(viewer, rego)) {
6637
6683
  return false;
@@ -8098,6 +8144,58 @@
8098
8144
  exports.CesiumEntityStyler.UpdateColorSetting("highlight", color);
8099
8145
  }
8100
8146
  }
8147
+ /**
8148
+ * Marks visuals as being actively edited, which exempts them from culling until it is turned back off.
8149
+ */
8150
+ SetEditing(params) {
8151
+ var _a, _b;
8152
+ const { entityIds, editing, menuItemId, requestRender } = params;
8153
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
8154
+ return;
8155
+ }
8156
+ let changed = false;
8157
+ for (let i = 0; i < entityIds.length; i++) {
8158
+ const regos = this.rego[entityIds[i]];
8159
+ if (!regos) {
8160
+ continue;
8161
+ }
8162
+ for (let j = 0; j < regos.length; j++) {
8163
+ const rego = regos[j];
8164
+ if (menuItemId && rego.menuItemId !== menuItemId) {
8165
+ continue;
8166
+ }
8167
+ if (Boolean(rego.editing) == Boolean(editing)) {
8168
+ continue;
8169
+ }
8170
+ // Null rather than false, so the rego does not carry a key for every visual ever edited.
8171
+ rego.editing = editing ? true : null;
8172
+ changed = true;
8173
+ if (editing) {
8174
+ const parts = exports.EntityUtils.GatherEntity({
8175
+ entity: rego.visual
8176
+ });
8177
+ for (let k = 0; k < parts.length; k++) {
8178
+ const part = parts[k];
8179
+ if (!(part instanceof Cesium.Entity)) {
8180
+ continue;
8181
+ }
8182
+ const wasCulled = part[VisualRegisterCuller.VISUAL_CULL_KEY];
8183
+ delete part[VisualRegisterCuller.VISUAL_CULL_KEY];
8184
+ if (wasCulled && !IsCEntityInScene(this.viewer, part)) {
8185
+ AddCEntityToScene(this.viewer, part, rego.collection);
8186
+ }
8187
+ }
8188
+ }
8189
+ else {
8190
+ // The geometry almost certainly moved, so what was measured before is worthless.
8191
+ VisualRegisterCuller.InvalidateBounds(rego.visual);
8192
+ }
8193
+ }
8194
+ }
8195
+ if (changed && requestRender != false) {
8196
+ (_b = (_a = this.viewer) === null || _a === void 0 ? void 0 : _a.scene) === null || _b === void 0 ? void 0 : _b.requestRender();
8197
+ }
8198
+ }
8101
8199
  SetSelected(params) {
8102
8200
  var _a;
8103
8201
  let { entityIds, selected, refreshIfSelected, requestRender, menuItemId, source } = params;
@@ -39428,6 +39526,7 @@
39428
39526
  if (bandCheck) {
39429
39527
  cEntity._bandCheck = bandCheck;
39430
39528
  }
39529
+ VisualRegisterCuller.InvalidateBounds(cEntity);
39431
39530
  });
39432
39531
  return {
39433
39532
  entities: cEntities,
@@ -40194,7 +40293,7 @@
40194
40293
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
40195
40294
  })(exports.StyleUtils || (exports.StyleUtils = {}));
40196
40295
 
40197
- const VERSION = "7.0.4";
40296
+ const VERSION = "7.0.5";
40198
40297
  /**
40199
40298
  * Updates the environment instance used by bruce-cesium to one specified.
40200
40299
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.