bruce-cesium 7.8.6 → 7.8.8

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.
@@ -9670,6 +9670,11 @@
9670
9670
  if (!entityIds.length) {
9671
9671
  return;
9672
9672
  }
9673
+ if (this.options.reportClick) {
9674
+ const keys = event;
9675
+ this.visualRegister.ClickLabelEntities(entityIds, Boolean(keys.ctrlKey || keys.metaKey || keys.shiftKey));
9676
+ return;
9677
+ }
9673
9678
  this.visualRegister.ClearSelected({ requestRender: false });
9674
9679
  this.visualRegister.SetSelected({ entityIds, selected: true });
9675
9680
  };
@@ -10340,7 +10345,7 @@
10340
10345
  let displacement = { x: 0, y: 0 };
10341
10346
  let nudge = { x: 0, y: 0, fromX: 0, fromY: 0, targetX: 0, targetY: 0, start: 0 };
10342
10347
  const apply = (placement) => {
10343
- var _a, _b, _c, _d, _e;
10348
+ var _a, _b, _c, _d, _e, _f;
10344
10349
  const show = (placement === null || placement === void 0 ? void 0 : placement.visible) && placement.opacity > 0;
10345
10350
  if (!show && hiddenLast) {
10346
10351
  return;
@@ -10401,6 +10406,11 @@
10401
10406
  ele.style.opacity = String(opacity);
10402
10407
  ele.style.zIndex = String(placement.zIndex);
10403
10408
  ele.dataset.clusterCount = String(placement.members.length || 1);
10409
+ // Every Entity a cluster stands for, so a box selection takes them all, not only the one drawn.
10410
+ const clusterIds = placement.members.length ? placement.entityIds.join(" ") : "";
10411
+ if (((_d = ele.dataset.clusterIds) !== null && _d !== void 0 ? _d : "") !== clusterIds) {
10412
+ ele.dataset.clusterIds = clusterIds;
10413
+ }
10404
10414
  countElement.style.display = placement.members.length ? "block" : "none";
10405
10415
  countElement.style.order = placement.textSide === "left" ? "-1" : "0";
10406
10416
  const count = placement.members.length ? String(placement.members.length) : "";
@@ -10413,9 +10423,9 @@
10413
10423
  const stack = JSON.stringify(placement.icons || []);
10414
10424
  if (iconStack && stack !== displayedStack) {
10415
10425
  displayedStack = stack;
10416
- const looks = ((_d = placement.icons) === null || _d === void 0 ? void 0 : _d.length) ? [iconLook(this.options), ...placement.icons] : [];
10426
+ const looks = ((_e = placement.icons) === null || _e === void 0 ? void 0 : _e.length) ? [iconLook(this.options), ...placement.icons] : [];
10417
10427
  // One small size for all, so no icon in the arrangement reads as more important than another.
10418
- const size = (this.options.iconSize || 24) * ((_e = this.options.iconScale) !== null && _e !== void 0 ? _e : 1) * ICON_STACK_SCALE;
10428
+ const size = (this.options.iconSize || 24) * ((_f = this.options.iconScale) !== null && _f !== void 0 ? _f : 1) * ICON_STACK_SCALE;
10419
10429
  const built = looks.map(look => this.buildIcon({ ...(pin ? pinLook(look) : look), iconSize: size }, counter));
10420
10430
  // A stack is on show already, so its photos load straight away.
10421
10431
  built.forEach(({ start }) => start === null || start === void 0 ? void 0 : start());
@@ -11424,6 +11434,10 @@
11424
11434
  this.imagesAsking = new Set();
11425
11435
  this.imagesTimer = null;
11426
11436
  this.placesInteractive = false;
11437
+ // Whether a click on an Entity label is reported to the app instead of selecting the Entity.
11438
+ this.entitiesInteractive = false;
11439
+ // The Entity labels the app has picked, by group, drawn with the same glow as a picked place.
11440
+ this.selectedEntities = new Map();
11427
11441
  }
11428
11442
  notify() {
11429
11443
  try {
@@ -11626,6 +11640,42 @@
11626
11640
  }
11627
11641
  this.refresh(keys);
11628
11642
  }
11643
+ /*
11644
+ * Whether a click on an Entity label is reported to the app rather than selecting its Entity.
11645
+ */
11646
+ SetEntitiesInteractive(on) {
11647
+ if (this.entitiesInteractive === on) {
11648
+ return;
11649
+ }
11650
+ this.entitiesInteractive = on;
11651
+ const keys = new Set();
11652
+ for (const group of this.active.values()) {
11653
+ for (const [key, item] of group.items) {
11654
+ if (!item.placeId) {
11655
+ keys.add(key);
11656
+ }
11657
+ }
11658
+ }
11659
+ this.refresh(keys);
11660
+ }
11661
+ /*
11662
+ * Replaces which of a group's Entity labels glow as picked, redrawing only those that changed.
11663
+ */
11664
+ SetSelectedEntities(id, entityIds) {
11665
+ var _a;
11666
+ const before = (_a = this.selectedEntities.get(id)) !== null && _a !== void 0 ? _a : new Set();
11667
+ const after = new Set((entityIds !== null && entityIds !== void 0 ? entityIds : []).filter(key => typeof key === "string" && key && !IsPlaceKey(key)));
11668
+ const changed = new Set([...before, ...after].filter(key => before.has(key) !== after.has(key)));
11669
+ if (after.size) {
11670
+ this.selectedEntities.set(id, after);
11671
+ }
11672
+ else {
11673
+ this.selectedEntities.delete(id);
11674
+ }
11675
+ if (changed.size && this.active.has(id)) {
11676
+ this.refresh(changed);
11677
+ }
11678
+ }
11629
11679
  Get() {
11630
11680
  return Array.from(this.definitions.keys(), id => {
11631
11681
  var _a;
@@ -11676,7 +11726,7 @@
11676
11726
  * One member's label settings, with any image its own text links to but before its default image.
11677
11727
  */
11678
11728
  compose(group, entityId, menuItemId) {
11679
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
11729
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
11680
11730
  const item = group.items.get(entityId);
11681
11731
  const entity = (_a = item.entity) !== null && _a !== void 0 ? _a : { Bruce: { ID: entityId, Name: item.text } };
11682
11732
  let iconPriority = (_b = group.definition.options) === null || _b === void 0 ? void 0 : _b.iconPriority;
@@ -11734,6 +11784,13 @@
11734
11784
  options.iconClass = named.iconClass;
11735
11785
  options.iconUrl = named.iconUrl;
11736
11786
  }
11787
+ if (!item.placeId && this.entitiesInteractive) {
11788
+ options.selectOnClick = true;
11789
+ options.reportClick = true;
11790
+ }
11791
+ if (!item.placeId && ((_r = this.selectedEntities.get(group.definition.id)) === null || _r === void 0 ? void 0 : _r.has(entityId))) {
11792
+ options.highlightColor = PLACE_SELECTED_COLOR;
11793
+ }
11737
11794
  if (item.placeId) {
11738
11795
  // Clickable only when the app asks, and reported then, as there is no Entity to select.
11739
11796
  options.selectOnClick = this.placesInteractive;
@@ -11756,7 +11813,7 @@
11756
11813
  }
11757
11814
  if (options.attributes && item.entity && !(expression && resolvedText != null)) {
11758
11815
  options.text = [
11759
- (_t = (_r = options.text) !== null && _r !== void 0 ? _r : (_s = item.entity.Bruce) === null || _s === void 0 ? void 0 : _s.Name) !== null && _t !== void 0 ? _t : entityId,
11816
+ (_u = (_s = options.text) !== null && _s !== void 0 ? _s : (_t = item.entity.Bruce) === null || _t === void 0 ? void 0 : _t.Name) !== null && _u !== void 0 ? _u : entityId,
11760
11817
  ...options.attributes.map(path => BModels.Entity.GetValue({ entity: item.entity, path })).filter(value => value != null).map(String)
11761
11818
  ].join("\n");
11762
11819
  }
@@ -11918,6 +11975,7 @@
11918
11975
  Remove(id) {
11919
11976
  var _a;
11920
11977
  const known = this.definitions.delete(id);
11978
+ this.selectedEntities.delete(id);
11921
11979
  this.visibility.delete(id);
11922
11980
  this.errors.delete(id);
11923
11981
  (_a = this.pending.get(id)) === null || _a === void 0 ? void 0 : _a.abort();
@@ -11950,6 +12008,7 @@
11950
12008
  this.active.clear();
11951
12009
  this.members.clear();
11952
12010
  this.definitions.clear();
12011
+ this.selectedEntities.clear();
11953
12012
  this.visibility.clear();
11954
12013
  this.errors.clear();
11955
12014
  this.refresh(affected);
@@ -11969,6 +12028,7 @@
11969
12028
  this.active.clear();
11970
12029
  this.members.clear();
11971
12030
  this.definitions.clear();
12031
+ this.selectedEntities.clear();
11972
12032
  this.visibility.clear();
11973
12033
  this.errors.clear();
11974
12034
  }
@@ -13902,6 +13962,7 @@
13902
13962
  }
13903
13963
  get OnLabelGroupsChanged() { return this.labelGroupsChanged; }
13904
13964
  get OnLabelPlaceClick() { return this.labelPlaceClicked; }
13965
+ get OnLabelEntityClick() { return this.labelEntityClicked; }
13905
13966
  constructor(params) {
13906
13967
  var _a, _b, _c, _d, _e, _f, _g;
13907
13968
  this.id = BModels.ObjectUtils.UId();
@@ -13956,6 +14017,7 @@
13956
14017
  this.shadowsRemoval = null;
13957
14018
  this.labelGroupsChanged = new BModels.BruceEvent();
13958
14019
  this.labelPlaceClicked = new BModels.BruceEvent();
14020
+ this.labelEntityClicked = new BModels.BruceEvent();
13959
14021
  this.hoverRingState = {};
13960
14022
  this.retiringHoverLabels = new Map();
13961
14023
  /*
@@ -14956,6 +15018,7 @@
14956
15018
  (_c = this.labelGroups) === null || _c === void 0 ? void 0 : _c.Dispose();
14957
15019
  this.labelGroupsChanged.Clear();
14958
15020
  this.labelPlaceClicked.Clear();
15021
+ this.labelEntityClicked.Clear();
14959
15022
  for (const regos of Object.values(this.rego)) {
14960
15023
  for (const rego of regos)
14961
15024
  exports.EntityLabel.Detatch({ rego, force: true });
@@ -16751,6 +16814,35 @@
16751
16814
  this.labelPlaceClicked.Trigger({ places, additive });
16752
16815
  }
16753
16816
  }
16817
+ /*
16818
+ * Whether Entity label clicks go to OnLabelEntityClick rather than selecting. Off by default.
16819
+ */
16820
+ SetLabelEntitiesInteractive(on) {
16821
+ if (this.disposed) {
16822
+ return;
16823
+ }
16824
+ if (!this.labelGroups) {
16825
+ this.labelGroups = new exports.EntityLabelGroup.Manager(this, () => this.labelGroupsChanged.Trigger(undefined));
16826
+ }
16827
+ this.labelGroups.SetEntitiesInteractive(on);
16828
+ }
16829
+ /*
16830
+ * Called by a label clicked while Entity labels are interactive, with the Entities it stands for.
16831
+ */
16832
+ ClickLabelEntities(entityIds, additive) {
16833
+ const labels = entityIds.map(entityId => { var _a; return ({ groupId: (_a = this.GetLabelGroupFor(entityId)) === null || _a === void 0 ? void 0 : _a.groupId, entityId }); })
16834
+ .filter(label => label.groupId);
16835
+ if (labels.length) {
16836
+ this.labelEntityClicked.Trigger({ labels, additive });
16837
+ }
16838
+ }
16839
+ /*
16840
+ * Which of a group's Entity labels glow as picked by the app.
16841
+ */
16842
+ SetLabelGroupSelected(id, entityIds) {
16843
+ var _a;
16844
+ (_a = this.labelGroups) === null || _a === void 0 ? void 0 : _a.SetSelectedEntities(id, entityIds);
16845
+ }
16754
16846
  /*
16755
16847
  * Replaces a group's places without reading its source again. False when no such group was set.
16756
16848
  */
@@ -48653,6 +48745,103 @@
48653
48745
  }
48654
48746
  }
48655
48747
 
48748
+ /*
48749
+ * Keeps glTF and 3D Tiles pickable where a GPU shader compiler mangles CesiumJS's lit pick shaders.
48750
+ */
48751
+ const PICK_LIGHTING_PATCH_KEY = "_nextspacePickLightingPatch";
48752
+ // Added by CesiumJS's ImageBasedLightingPipelineStage; every use in its shaders sits behind an #ifdef.
48753
+ const IBL_DEFINE = "USE_IBL_LIGHTING";
48754
+ /**
48755
+ * Removes image based lighting from a derived "pick" shader's fragment options, returning whether it did.
48756
+ */
48757
+ function StripPickLighting(keyword, options) {
48758
+ const fragment = options === null || options === void 0 ? void 0 : options.fragmentShaderSource;
48759
+ const defines = fragment === null || fragment === void 0 ? void 0 : fragment.defines;
48760
+ if (keyword !== "pick" ||
48761
+ !Array.isArray(defines) ||
48762
+ !defines.includes(IBL_DEFINE)) {
48763
+ return false;
48764
+ }
48765
+ fragment.defines = defines.filter(x => x !== IBL_DEFINE);
48766
+ return true;
48767
+ }
48768
+ /**
48769
+ * Compiles a viewer's pick shaders unlit, since NVIDIA via ANGLE (Edge 155, CesiumJS 1.120) drops every lit pick.
48770
+ */
48771
+ function InstallPickLightingPatch(viewer) {
48772
+ var _a, _b;
48773
+ const cache = (_b = (_a = viewer === null || viewer === void 0 ? void 0 : viewer.scene) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.shaderCache;
48774
+ if (!cache || typeof cache.createDerivedShaderProgram !== "function") {
48775
+ return false;
48776
+ }
48777
+ if (cache[PICK_LIGHTING_PATCH_KEY]) {
48778
+ return true;
48779
+ }
48780
+ const original = cache.createDerivedShaderProgram;
48781
+ cache.createDerivedShaderProgram = function (shaderProgram, keyword, options) {
48782
+ try {
48783
+ StripPickLighting(keyword, options);
48784
+ }
48785
+ catch (e) {
48786
+ console.error("Failed to strip lighting from a pick shader.", e);
48787
+ }
48788
+ return original.call(this, shaderProgram, keyword, options);
48789
+ };
48790
+ cache[PICK_LIGHTING_PATCH_KEY] = true;
48791
+ return true;
48792
+ }
48793
+
48794
+ /*
48795
+ * Makes a click on a ground clamped polygon pick that polygon rather than another one batched with it.
48796
+ */
48797
+ const PICK_GROUND_PATCH_KEY = "_nextspacePickGroundPatch";
48798
+ // Before CesiumJS 1.135 this keeps any pick fragment over the globe, so far batched polygons win the pick.
48799
+ const BROKEN_CULL = "uv.y <= 1.0 || logDepthOrDepth != 0.0)";
48800
+ // The same test the render path uses: the ground under the pixel lies within this polygon's extents.
48801
+ const FIXED_CULL = "uv.y <= 1.0 && logDepthOrDepth != 0.0)";
48802
+ /**
48803
+ * Corrects the extents cull in a ground primitive pick shader's fragment options, returning whether it did.
48804
+ */
48805
+ function FixPickGround(options) {
48806
+ const fragment = options === null || options === void 0 ? void 0 : options.fragmentShaderSource;
48807
+ const defines = fragment === null || fragment === void 0 ? void 0 : fragment.defines;
48808
+ const sources = fragment === null || fragment === void 0 ? void 0 : fragment.sources;
48809
+ if (!Array.isArray(defines) ||
48810
+ !Array.isArray(sources) ||
48811
+ !defines.includes("PICK") ||
48812
+ !defines.includes("CULL_FRAGMENTS") ||
48813
+ !sources.some(x => typeof x === "string" && x.includes(BROKEN_CULL))) {
48814
+ return false;
48815
+ }
48816
+ fragment.sources = sources.map(x => typeof x === "string" ? x.replace(BROKEN_CULL, FIXED_CULL) : x);
48817
+ return true;
48818
+ }
48819
+ /**
48820
+ * Patches a viewer's shader cache so batched ground clamped polygons pick only where they cover the ground.
48821
+ */
48822
+ function InstallPickGroundPatch(viewer) {
48823
+ var _a, _b;
48824
+ const cache = (_b = (_a = viewer === null || viewer === void 0 ? void 0 : viewer.scene) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.shaderCache;
48825
+ if (!cache || typeof cache.getShaderProgram !== "function") {
48826
+ return false;
48827
+ }
48828
+ if (cache[PICK_GROUND_PATCH_KEY]) {
48829
+ return true;
48830
+ }
48831
+ const original = cache.getShaderProgram;
48832
+ cache.getShaderProgram = function (options) {
48833
+ try {
48834
+ FixPickGround(options);
48835
+ }
48836
+ catch (e) {
48837
+ console.error("Failed to fix a ground pick shader.", e);
48838
+ }
48839
+ return original.call(this, options);
48840
+ };
48841
+ cache[PICK_GROUND_PATCH_KEY] = true;
48842
+ return true;
48843
+ }
48844
+
48656
48845
  const CESIUM_VIEWER_MANAGER_KEY = "_cesiumViewerManager";
48657
48846
  const CESIUM_VIEWER_EVENT_TRACKER_KEY = "_cesiumViewerEventTracker";
48658
48847
  const BACKGROUND_RENDERING_KEY = "_backgroundRendering";
@@ -48737,6 +48926,8 @@
48737
48926
  // Newer cesium is much dimmer by default so we shift brightness a bit.
48738
48927
  exports.ViewUtils.ApplyDefaultBrightness(viewer);
48739
48928
  backgroundRendering(viewer);
48929
+ InstallPickLightingPatch(viewer);
48930
+ InstallPickGroundPatch(viewer);
48740
48931
  if (cameraControls != false) {
48741
48932
  exports.CameraControls.Attach(viewer);
48742
48933
  if (exports.ViewUtils.GetModelSpace(viewer)) {
@@ -60898,7 +61089,7 @@ void main() {
60898
61089
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
60899
61090
  })(exports.StyleUtils || (exports.StyleUtils = {}));
60900
61091
 
60901
- const VERSION = "7.8.6";
61092
+ const VERSION = "7.8.8";
60902
61093
  /**
60903
61094
  * Updates the environment instance used by bruce-cesium to one specified.
60904
61095
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.