bruce-cesium 7.8.0 → 7.8.1

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.
@@ -7218,6 +7218,10 @@
7218
7218
  const ICON_STACK_SCALE = 0.6;
7219
7219
  // How far an angled leader runs sideways before the label starts.
7220
7220
  const ANGLED_LEADER_RUN = 28;
7221
+ // How far a pin's white body reaches past the icon it wraps, before its tip.
7222
+ const PIN_RIM = 7;
7223
+ // A pin is drawn in one fixed look for now: a white body with a faint edge and a soft shadow.
7224
+ const PIN_COLOR = "#ffffff";
7221
7225
  // Clearance between a point or billboard glyph and the ring drawn around it.
7222
7226
  const ICON_RING_PADDING = 4;
7223
7227
  // Small points still get a ring as large as the default near ring.
@@ -7651,6 +7655,12 @@
7651
7655
  color.brighten(ICON_BACKGROUND_BLEND, new Cesium.Color());
7652
7656
  return shade.withAlpha(alpha).toCssColorString();
7653
7657
  }
7658
+ /*
7659
+ * An icon's look on a pin: one with no chip of its own takes the pin's colour, which its glyph then contrasts with.
7660
+ */
7661
+ function pinLook(look) {
7662
+ return look.iconBackground ? look : { ...look, iconBackground: PIN_COLOR };
7663
+ }
7654
7664
  function iconLook(options) {
7655
7665
  return {
7656
7666
  icon: options.icon || undefined,
@@ -9442,7 +9452,9 @@
9442
9452
  target.addEventListener(type, event => event.stopPropagation());
9443
9453
  }
9444
9454
  };
9445
- const normalLeader = (_m = look.leader) !== null && _m !== void 0 ? _m : presentation === "text";
9455
+ // A pin needs an icon to wrap; a photo keeps its own shape, and plain text keeps a straight stem.
9456
+ const pin = this.options.leaderStyle === "pin" && look.leader !== false && presentation !== "text" && !look.iconPhoto;
9457
+ const normalLeader = (_m = look.leader) !== null && _m !== void 0 ? _m : (presentation === "text" || pin);
9446
9458
  const angled = this.options.leaderStyle === "angled";
9447
9459
  let leader = normalLeader;
9448
9460
  const content = document.createElement("span");
@@ -9453,6 +9465,8 @@
9453
9465
  let iconElement;
9454
9466
  let iconContainer;
9455
9467
  let fitIconBackground;
9468
+ let pinHolder;
9469
+ let pinBody;
9456
9470
  let iconStack;
9457
9471
  let stackedFits = [];
9458
9472
  let displayedStack = "[]";
@@ -9473,7 +9487,8 @@
9473
9487
  content.style.flexDirection = shape === "rect" ? "column-reverse" : "";
9474
9488
  };
9475
9489
  if (presentation !== "text") {
9476
- const built = this.buildIcon(look, counter, placePhoto);
9490
+ // Without a chip of its own the icon sits on the pin's white body, so its colour is inferred from that.
9491
+ const built = this.buildIcon(pin ? pinLook(look) : look, counter, placePhoto);
9477
9492
  startPhoto = built.start;
9478
9493
  const icon = iconElement = built.icon;
9479
9494
  fitIconBackground = built.fit;
@@ -9498,6 +9513,20 @@
9498
9513
  iconStack.style.cssText = "display:none;gap:2px;align-items:center;justify-items:center;flex:none;";
9499
9514
  makeClickable(iconStack);
9500
9515
  iconContainer.append(iconStack, icon);
9516
+ if (pin) {
9517
+ // The shadow sits on an unturned holder so it falls the same way whichever way the tip points.
9518
+ pinHolder = document.createElement("span");
9519
+ pinHolder.className = "entity-label-pin";
9520
+ pinHolder.style.cssText = "position:absolute;left:50%;top:50%;z-index:-1;pointer-events:none;" +
9521
+ "filter:drop-shadow(1px 2px 2px rgba(0, 0, 0, 0.35));";
9522
+ pinBody = document.createElement("span");
9523
+ pinBody.style.cssText = `position:absolute;inset:0;background:${PIN_COLOR};border:1px solid rgba(0, 0, 0, 0.14);` +
9524
+ "box-sizing:border-box;border-radius:50% 50% 0 50%;";
9525
+ pinHolder.appendChild(pinBody);
9526
+ iconContainer.prepend(pinHolder);
9527
+ // Text beside or above keeps its usual gap from the body rather than from the icon inside it.
9528
+ content.style.gap = `${6 + PIN_RIM}px`;
9529
+ }
9501
9530
  content.appendChild(iconContainer);
9502
9531
  }
9503
9532
  if (presentation !== "icon") {
@@ -9668,6 +9697,36 @@
9668
9697
  run, side: (rightwards ? "right" : "left")
9669
9698
  };
9670
9699
  };
9700
+ /*
9701
+ * Where the icon sits in the label, and how far the pin's tip reaches from its centre, in layout pixels.
9702
+ * Measured from the icon's container, so a cluster's icon stack is wrapped the same way as a lone icon.
9703
+ */
9704
+ const measurePin = () => {
9705
+ const scale = layer.coordinates.scaleX;
9706
+ const radius = Math.max(iconContainer.offsetWidth, iconContainer.offsetHeight) / 2 + PIN_RIM;
9707
+ return {
9708
+ x: (iconContainer.offsetLeft + iconContainer.offsetWidth / 2) / scale,
9709
+ y: (iconContainer.offsetTop + iconContainer.offsetHeight / 2) / layer.coordinates.scaleY,
9710
+ radius: radius / scale,
9711
+ // The body's one square corner, half a diagonal from its centre.
9712
+ tip: radius * Math.SQRT2 / scale
9713
+ };
9714
+ };
9715
+ /*
9716
+ * A pin stands over its anchor with the icon centred on it, and hangs below when there is no room above.
9717
+ * Off to the side it is only clamped back on screen, and its tip turns to keep pointing at the anchor.
9718
+ */
9719
+ const fitPin = (anchorX, anchorY, stem, width, height, shape) => {
9720
+ const canvas = this.viewer.canvas;
9721
+ const reach = stem + shape.tip;
9722
+ const above = anchorY - reach - shape.y;
9723
+ const below = anchorY + reach - shape.y;
9724
+ const upwards = above >= 0 || (below + height > canvas.clientHeight && anchorY >= canvas.clientHeight - anchorY);
9725
+ return {
9726
+ x: Math.max(0, Math.min(anchorX - shape.x, canvas.clientWidth - width)),
9727
+ y: upwards ? above : below
9728
+ };
9729
+ };
9671
9730
  /*
9672
9731
  * The on-screen centre and half-size of a point or billboard glyph, relative to its projected position.
9673
9732
  * Read every frame, since styling and selection can rescale a billboard in place.
@@ -9784,7 +9843,7 @@
9784
9843
  }
9785
9844
  let cursorMotion = this.cursorMotion;
9786
9845
  const project = () => {
9787
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
9846
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
9788
9847
  if (this.disposed || !this.viewer || this.viewer.isDestroyed() || ((_a = this.visible) === null || _a === void 0 ? void 0 : _a.call(this)) === false ||
9789
9848
  (presentation === "icon" && this.options.iconScale === 0)) {
9790
9849
  return null;
@@ -9901,6 +9960,10 @@
9901
9960
  else if (this.options.leaderLength != null) {
9902
9961
  leaderLength = Math.max(0, this.options.leaderLength);
9903
9962
  }
9963
+ else if (pin) {
9964
+ // The tip itself is the leader, so by default it touches what it marks.
9965
+ leaderLength = 0;
9966
+ }
9904
9967
  else if (transientPivot) {
9905
9968
  // Cursor callouts must not jump when the next hover target has a different extent.
9906
9969
  leaderLength = 96;
@@ -9917,14 +9980,15 @@
9917
9980
  if (visual instanceof Cesium.Entity && (visual.polygon || visual.polyline))
9918
9981
  leaderLength /= 3;
9919
9982
  }
9920
- if (boxAnchor && this.options.leaderLength == null) {
9983
+ if (boxAnchor && this.options.leaderLength == null && !pin) {
9921
9984
  leaderLength += (MODEL_BOX_STEM - leaderLength) * boxBlend;
9922
9985
  }
9923
9986
  if (cursorAmount > 0) {
9924
9987
  leaderLength += (96 - leaderLength) * cursorAmount;
9925
9988
  }
9926
9989
  // Measured from the ring, so the visible stem is the same length whatever the glyph's size.
9927
- leaderLength += iconRing;
9990
+ // A pin's tip rests on the glyph instead, since no ring is drawn around it.
9991
+ leaderLength += pin ? (_t = icon === null || icon === void 0 ? void 0 : icon.radius) !== null && _t !== void 0 ? _t : 0 : iconRing;
9928
9992
  y = anchorY - leaderLength;
9929
9993
  }
9930
9994
  else if (hover && !reused && !pinned) {
@@ -9936,7 +10000,7 @@
9936
10000
  const width = ele.offsetWidth / coordinates.scaleX;
9937
10001
  const height = ele.offsetHeight / coordinates.scaleY;
9938
10002
  let clusterBounds;
9939
- if ((_t = this.options.cluster) === null || _t === void 0 ? void 0 : _t.enabled) {
10003
+ if ((_u = this.options.cluster) === null || _u === void 0 ? void 0 : _u.enabled) {
9940
10004
  const textWidth = (sourceText === null || sourceText === void 0 ? void 0 : sourceText.offsetWidth) || 0;
9941
10005
  const textHeight = (sourceText === null || sourceText === void 0 ? void 0 : sourceText.offsetHeight) || 0;
9942
10006
  // A photo is never part of the footprint, so its arrival cannot change which cluster a label joins.
@@ -9948,7 +10012,7 @@
9948
10012
  const baseWidth = ((above ? Math.max(textWidth, iconWidth) : textWidth + iconWidth + gap) + 16) / coordinates.scaleX;
9949
10013
  const baseHeight = ((above ? textHeight + iconHeight + gap : Math.max(textHeight, iconHeight)) + 12) / coordinates.scaleY;
9950
10014
  clusterBounds = {
9951
- x: leader ? x : x - baseWidth / 2,
10015
+ x: leader && !pin ? x : x - baseWidth / 2,
9952
10016
  y: leader ? y - baseHeight : y - baseHeight / 2, width: baseWidth, height: baseHeight
9953
10017
  };
9954
10018
  }
@@ -9959,7 +10023,9 @@
9959
10023
  // Membership uses the unclamped source footprint, never the summary's changing dimensions.
9960
10024
  let leaderRun;
9961
10025
  let leaderSide;
9962
- if (leader && angled) {
10026
+ if (leader && pin)
10027
+ ({ x, y } = fitPin(anchorX, anchorY, leaderLength, width, height, measurePin()));
10028
+ else if (leader && angled) {
9963
10029
  const fit = fitAngledLeader(anchorX, anchorY, leaderLength, width, height);
9964
10030
  ({ x, y } = fit);
9965
10031
  ({ run: leaderRun, side: leaderSide } = fit);
@@ -9970,16 +10036,16 @@
9970
10036
  if (!leader && (bounds.x + bounds.width < 0 || bounds.y + bounds.height < 0 || bounds.x > this.viewer.canvas.clientWidth || bounds.y > this.viewer.canvas.clientHeight)) {
9971
10037
  return null;
9972
10038
  }
9973
- const state = (_u = this.visualRegister) === null || _u === void 0 ? void 0 : _u.GetState({ entityId: (_v = this.rego) === null || _v === void 0 ? void 0 : _v.entityId, menuItemId: (_w = this.rego) === null || _w === void 0 ? void 0 : _w.menuItemId });
10039
+ const state = (_v = this.visualRegister) === null || _v === void 0 ? void 0 : _v.GetState({ entityId: (_w = this.rego) === null || _w === void 0 ? void 0 : _w.entityId, menuItemId: (_x = this.rego) === null || _x === void 0 ? void 0 : _x.menuItemId });
9974
10040
  const opacity = this.prePositioned || hoverOnly || MAX_DISTANCE === Infinity ? 1 : 1 - distance / MAX_DISTANCE;
9975
10041
  return {
9976
- canFlip: leader && presentation !== "icon", hasLeader: leader,
10042
+ canFlip: leader && presentation !== "icon" && !pin, hasLeader: leader,
9977
10043
  textWrapped: ((sourceNaturalText === null || sourceNaturalText === void 0 ? void 0 : sourceNaturalText.offsetWidth) || 0) > TEXT_MAX_WIDTH,
9978
10044
  transient: this.Transient || Boolean(hover) || cursorAmount > 0,
9979
10045
  extendedGeometry: visual instanceof Cesium.Entity && Boolean(visual.polygon || visual.polyline || visual.corridor),
9980
10046
  viewportWidth: this.viewer.canvas.clientWidth,
9981
- id: this.id, entityKey: ((_x = this.rego) === null || _x === void 0 ? void 0 : _x.entityId) ? JSON.stringify([this.rego.entityId, this.rego.menuItemId || "", this.Transient && !this.Persistent ? "hover" : ""]) : undefined,
9982
- entityId: (_y = this.rego) === null || _y === void 0 ? void 0 : _y.entityId, group: this.groupId, x, y, width, height, anchorX, anchorY, depth, leaderLength, leaderRun, leaderSide, distance,
10047
+ id: this.id, entityKey: ((_y = this.rego) === null || _y === void 0 ? void 0 : _y.entityId) ? JSON.stringify([this.rego.entityId, this.rego.menuItemId || "", this.Transient && !this.Persistent ? "hover" : ""]) : undefined,
10048
+ entityId: (_z = this.rego) === null || _z === void 0 ? void 0 : _z.entityId, group: this.groupId, x, y, width, height, anchorX, anchorY, depth, leaderLength, leaderRun, leaderSide, distance,
9983
10049
  iconRadius: icon === null || icon === void 0 ? void 0 : icon.radius, modelBox: boxed || undefined, boxBlend, follows: !pinned && Boolean(transientPivot || cursorMotion.target),
9984
10050
  // Priority shows the hovered member individually without dragging its cluster along.
9985
10051
  opacity: waiting ? 0 : opacity, priority: hover || cursorAmount > 0 || (state === null || state === void 0 ? void 0 : state.highlighted) ? 1 : 0, options: this.options, text: originalText, clusterBounds
@@ -9996,7 +10062,8 @@
9996
10062
  lineEle.style.display = show && leader ? "block" : "none";
9997
10063
  if (runEle)
9998
10064
  runEle.style.display = show && leader ? "block" : "none";
9999
- this.anchor.style.display = show && leader && !(((_a = placement.frame) === null || _a === void 0 ? void 0 : _a.boxBlend) >= 1) ? "block" : "none";
10065
+ // A pin's tip marks the anchor itself, so it has no ring there.
10066
+ this.anchor.style.display = show && leader && !pin && !(((_a = placement.frame) === null || _a === void 0 ? void 0 : _a.boxBlend) >= 1) ? "block" : "none";
10000
10067
  if (!show) {
10001
10068
  displacement = { x: 0, y: 0 };
10002
10069
  nudge = { x: 0, y: 0, fromX: 0, fromY: 0, targetX: 0, targetY: 0, start: 0 };
@@ -10053,7 +10120,7 @@
10053
10120
  const looks = ((_d = placement.icons) === null || _d === void 0 ? void 0 : _d.length) ? [iconLook(this.options), ...placement.icons] : [];
10054
10121
  // One small size for all, so no icon in the arrangement reads as more important than another.
10055
10122
  const size = (this.options.iconSize || 24) * ((_e = this.options.iconScale) !== null && _e !== void 0 ? _e : 1) * ICON_STACK_SCALE;
10056
- const built = looks.map(look => this.buildIcon({ ...look, iconSize: size }, counter));
10123
+ const built = looks.map(look => this.buildIcon({ ...(pin ? pinLook(look) : look), iconSize: size }, counter));
10057
10124
  // A stack is on show already, so its photos load straight away.
10058
10125
  built.forEach(({ start }) => start === null || start === void 0 ? void 0 : start());
10059
10126
  // Two sit side by side; three make a triangle with the representative on top.
@@ -10147,7 +10214,9 @@
10147
10214
  }
10148
10215
  const ringShare = 1 - (frame.boxBlend || 0);
10149
10216
  const radius = ringShare > 0 && ringAnimation.inner > 0 ? ringAnimation.outer * ringShare : 0;
10150
- const stem = (leader ? (angled ? fitAngledLeader : fitLeader)(frame.anchorX, frame.anchorY, Math.max(frame.leaderLength, radius ? radius + 4 : 0), ele.offsetWidth / coordinates.scaleX, ele.offsetHeight / coordinates.scaleY, radius) : undefined);
10217
+ const pinShape = leader && pin ? measurePin() : undefined;
10218
+ const stem = (pinShape ? fitPin(frame.anchorX, frame.anchorY, frame.leaderLength, ele.offsetWidth / coordinates.scaleX, ele.offsetHeight / coordinates.scaleY, pinShape) :
10219
+ leader ? (angled ? fitAngledLeader : fitLeader)(frame.anchorX, frame.anchorY, Math.max(frame.leaderLength, radius ? radius + 4 : 0), ele.offsetWidth / coordinates.scaleX, ele.offsetHeight / coordinates.scaleY, radius) : undefined);
10151
10220
  const position = { x: (stem || frame).x, y: (stem || frame).y };
10152
10221
  const width = ele.offsetWidth / coordinates.scaleX;
10153
10222
  const height = ele.offsetHeight / coordinates.scaleY;
@@ -10158,7 +10227,7 @@
10158
10227
  const beside = side === "left" ? frame.anchorX - run - width : frame.anchorX + run;
10159
10228
  position.x = Math.max(0, Math.min(beside, this.viewer.canvas.clientWidth - width));
10160
10229
  }
10161
- else if (leader && placement.textSide === "left") {
10230
+ else if (leader && !pin && placement.textSide === "left") {
10162
10231
  position.x = Math.max(0, Math.min(frame.anchorX - width, this.viewer.canvas.clientWidth - width));
10163
10232
  }
10164
10233
  const gap = (_t = (_s = this.options.pointerAvoidance) === null || _s === void 0 ? void 0 : _s.gap) !== null && _t !== void 0 ? _t : 12;
@@ -10239,8 +10308,23 @@
10239
10308
  const straightY = frame.anchorY < position.y ? position.y : frame.anchorY > position.y + height ? position.y + height : frame.anchorY;
10240
10309
  const beside = angled && (frame.anchorX < position.x || frame.anchorX > position.x + width);
10241
10310
  const elbowY = position.y + height / 2;
10242
- const endX = beside ? frame.anchorX : straightX;
10243
- const endY = beside ? elbowY : straightY;
10311
+ let endX = beside ? frame.anchorX : straightX;
10312
+ let endY = beside ? elbowY : straightY;
10313
+ if (pinShape) {
10314
+ // Aimed from wherever clamping or a nudge left it; a stem, if any, meets the tip.
10315
+ const centreX = position.x + pinShape.x, centreY = position.y + pinShape.y;
10316
+ const aim = Math.atan2(frame.anchorY - centreY, frame.anchorX - centreX);
10317
+ const reach = Math.min(pinShape.tip, Math.hypot(frame.anchorX - centreX, frame.anchorY - centreY));
10318
+ endX = centreX + Math.cos(aim) * reach;
10319
+ endY = centreY + Math.sin(aim) * reach;
10320
+ const size = `${pinShape.radius * 2 * coordinates.scaleX}px`;
10321
+ if (pinHolder.style.width !== size) {
10322
+ pinHolder.style.width = pinHolder.style.height = size;
10323
+ pinHolder.style.margin = `-${pinShape.radius * coordinates.scaleX}px`;
10324
+ }
10325
+ // The body's square corner starts at the lower right, a quarter turn short of pointing down.
10326
+ pinBody.style.transform = `rotate(${aim - Math.PI / 4}rad)`;
10327
+ }
10244
10328
  const runToX = frame.anchorX < position.x ? position.x : position.x + width;
10245
10329
  const dx = endX - frame.anchorX, dy = endY - frame.anchorY;
10246
10330
  const length = Math.hypot(dx, dy);
@@ -60195,7 +60279,7 @@ void main() {
60195
60279
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
60196
60280
  })(exports.StyleUtils || (exports.StyleUtils = {}));
60197
60281
 
60198
- const VERSION = "7.8.0";
60282
+ const VERSION = "7.8.1";
60199
60283
  /**
60200
60284
  * Updates the environment instance used by bruce-cesium to one specified.
60201
60285
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.