bruce-cesium 7.7.8 → 7.7.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.
@@ -926,6 +926,32 @@
926
926
  const GRAZING_SINE = 0.12;
927
927
  // Closest the view may get to straight up or down while orbiting, in radians, so the camera never flips over.
928
928
  const ORBIT_POLE_MARGIN = Cesium.Math.toRadians(1);
929
+ // How far above the ground a camera coming down from above stops, until pushed on through.
930
+ const GROUND_STANDOFF = 2;
931
+ // Height above the ground within which a descent slows, so the ground is approached rather than hit.
932
+ const GROUND_APPROACH = 10;
933
+ // The slowest a descent gets near the ground, as a share of its usual speed.
934
+ const GROUND_APPROACH_FLOOR = 0.5;
935
+ // How far below the ground a push through it lands, so the camera is clearly under it.
936
+ const GROUND_BREAK_DEPTH = 1.5;
937
+ // Wheel notches of pushing at the ground that take the camera through it, with and without data found below it.
938
+ const PUSH_NOTCHES_DATA_BELOW = 3;
939
+ const PUSH_NOTCHES_NOTHING_BELOW = 10;
940
+ // Pushes further apart than this start counting again.
941
+ const PUSH_WINDOW_MS = 1200;
942
+ // How far below the ground something must reach to count as data underground, in metres.
943
+ const UNDERGROUND_MARGIN = 3;
944
+ // How long a scan of the scene for underground data and stand-in ground is trusted, in milliseconds.
945
+ const SCENE_SCAN_MS = 2000;
946
+ // The most entities one scan looks at, so a large scene is sampled rather than walked each time.
947
+ const SCENE_SCAN_ENTITIES = 3000;
948
+ // Zoom speed, as a share of the usual, toward a point that is a guess (nothing drawn there) or while terrain loads.
949
+ const ZOOM_GUESS_SHARE = 0.5;
950
+ const ZOOM_LOADING_SHARE = 0.7;
951
+ // The highest a camera zooms out to with the globe hidden, which CesiumJS's controller cannot navigate.
952
+ const HIDDEN_GLOBE_MAX_HEIGHT = 10000000;
953
+ // Marks a tileset that stands in for the globe, such as Google's photorealistic tiles.
954
+ const GROUND_TILESET_KEY = "_nextspace_camera_ground";
929
955
  var EDrag;
930
956
  (function (EDrag) {
931
957
  EDrag["Pan"] = "pan";
@@ -955,6 +981,9 @@
955
981
  zoomFrame: null,
956
982
  zoomPosition: null,
957
983
  lastDistance: 100,
984
+ push: { notches: 0, at: 0 },
985
+ scan: null,
986
+ undergroundOverride: null,
958
987
  saved: {
959
988
  rotateEventTypes: controller.rotateEventTypes,
960
989
  zoomEventTypes: controller.zoomEventTypes,
@@ -1011,6 +1040,25 @@
1011
1040
  return Boolean(viewer === null || viewer === void 0 ? void 0 : viewer[CESIUM_CAMERA_CONTROLS_KEY]);
1012
1041
  }
1013
1042
  CameraControls.IsAttached = IsAttached;
1043
+ /**
1044
+ * Marks a tileset as standing in for the globe (Google's photorealistic tiles), so the camera treats it as ground.
1045
+ */
1046
+ function SetGroundTileset(tileset, isGround) {
1047
+ if (tileset) {
1048
+ tileset[GROUND_TILESET_KEY] = isGround;
1049
+ }
1050
+ }
1051
+ CameraControls.SetGroundTileset = SetGroundTileset;
1052
+ /**
1053
+ * Says whether the scene has data underground, which makes the ground easier to push through; null scans for it.
1054
+ */
1055
+ function SetUndergroundData(viewer, present) {
1056
+ const state = viewer === null || viewer === void 0 ? void 0 : viewer[CESIUM_CAMERA_CONTROLS_KEY];
1057
+ if (state) {
1058
+ state.undergroundOverride = present;
1059
+ }
1060
+ }
1061
+ CameraControls.SetUndergroundData = SetUndergroundData;
1014
1062
  /**
1015
1063
  * Switches to navigating model-space measured from the frame getFrame returns, or back to geospatial with null.
1016
1064
  */
@@ -1091,8 +1139,27 @@
1091
1139
  if (state.getModelSpaceFrame) {
1092
1140
  return true;
1093
1141
  }
1142
+ // CesiumJS's controller measures against the globe, so with it hidden these controls keep the camera at any height.
1143
+ if (!globeShown(state)) {
1144
+ return true;
1145
+ }
1094
1146
  return heightOf(state, camera.positionWC) < GEO_HANDOFF_HEIGHT;
1095
1147
  }
1148
+ function globeShown(state) {
1149
+ const globe = state.viewer.scene.globe;
1150
+ return Boolean(globe) && globe.show !== false;
1151
+ }
1152
+ /*
1153
+ * The terrain's height at a place from the tiles loaded, undefined with the globe hidden or nothing loaded there.
1154
+ */
1155
+ function terrainHeightAt(state, carto) {
1156
+ const globe = state.viewer.scene.globe;
1157
+ if (!carto || !globeShown(state) || typeof globe.getHeight !== "function") {
1158
+ return undefined;
1159
+ }
1160
+ const height = globe.getHeight(carto);
1161
+ return Number.isFinite(height) ? height : undefined;
1162
+ }
1096
1163
  function ellipsoidOf(state) {
1097
1164
  var _a, _b;
1098
1165
  return (_b = (_a = state.viewer.scene.globe) === null || _a === void 0 ? void 0 : _a.ellipsoid) !== null && _b !== void 0 ? _b : Cesium.Ellipsoid.WGS84;
@@ -1119,16 +1186,19 @@
1119
1186
  * The level plane standing in for the ground when nothing is drawn under the cursor.
1120
1187
  */
1121
1188
  function groundPlane(state) {
1189
+ var _a;
1122
1190
  if (state.getModelSpaceFrame) {
1123
1191
  const frame = state.getModelSpaceFrame();
1124
1192
  return Cesium.Plane.fromPointNormal(Cesium.Matrix4.getTranslation(frame, new Cesium.Cartesian3()), upAt(state, null));
1125
1193
  }
1126
1194
  const camera = state.viewer.camera;
1127
1195
  const ellipsoid = ellipsoidOf(state);
1128
- const surface = ellipsoid.scaleToGeodeticSurface(camera.positionWC, new Cesium.Cartesian3());
1129
- if (!surface) {
1196
+ const carto = ellipsoid.cartesianToCartographic(camera.positionWC);
1197
+ if (!carto) {
1130
1198
  return null;
1131
1199
  }
1200
+ // Level with the terrain under the camera, not sea level, so a guess over high ground is not far too deep.
1201
+ const surface = Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, (_a = terrainHeightAt(state, carto)) !== null && _a !== void 0 ? _a : 0, ellipsoid);
1132
1202
  return Cesium.Plane.fromPointNormal(surface, ellipsoid.geodeticSurfaceNormal(surface, new Cesium.Cartesian3()));
1133
1203
  }
1134
1204
  /*
@@ -1166,14 +1236,44 @@
1166
1236
  }
1167
1237
  const plausible = plausibleDistance(state);
1168
1238
  if (isAhead(camera, picked) && Cesium.Cartesian3.distance(picked, camera.positionWC) < plausible) {
1169
- return picked;
1239
+ return { point: picked, source: "pick", ground: isGroundPick(state, position) };
1170
1240
  }
1171
1241
  const ground = groundPlane(state);
1172
1242
  const onGround = ground ? Cesium.IntersectionTests.rayPlane(ray, ground) : null;
1173
1243
  if (isAhead(camera, onGround) && Cesium.Cartesian3.distance(onGround, camera.positionWC) < plausible) {
1174
- return onGround;
1244
+ // The plane stands in for the ground only where there is ground to stand in for.
1245
+ return { point: onGround, source: "plane", ground: !state.getModelSpaceFrame && hasGround(state) };
1246
+ }
1247
+ return { point: Cesium.Ray.getPoint(ray, state.lastDistance), source: "last", ground: false };
1248
+ }
1249
+ /*
1250
+ * Whether what is drawn under a screen position is the ground: the globe, or a tileset standing in for it.
1251
+ */
1252
+ function isGroundPick(state, position) {
1253
+ var _a, _b, _c;
1254
+ if (state.getModelSpaceFrame) {
1255
+ return false;
1256
+ }
1257
+ const scene = state.viewer.scene;
1258
+ let picked;
1259
+ try {
1260
+ picked = typeof scene.pick === "function" ? scene.pick(position) : undefined;
1261
+ }
1262
+ catch (e) {
1263
+ picked = undefined;
1175
1264
  }
1176
- return Cesium.Ray.getPoint(ray, state.lastDistance);
1265
+ if (!picked) {
1266
+ // Nothing pickable means the globe, when it is drawn.
1267
+ return globeShown(state);
1268
+ }
1269
+ const tileset = (_b = (_a = picked.tileset) !== null && _a !== void 0 ? _a : picked.primitive) !== null && _b !== void 0 ? _b : (_c = picked.content) === null || _c === void 0 ? void 0 : _c.tileset;
1270
+ return Boolean(tileset === null || tileset === void 0 ? void 0 : tileset[GROUND_TILESET_KEY]);
1271
+ }
1272
+ /*
1273
+ * Whether there is ground to come down onto: the globe drawn, or a tileset standing in for it.
1274
+ */
1275
+ function hasGround(state) {
1276
+ return globeShown(state) || scanScene(state).groundTileset;
1177
1277
  }
1178
1278
  function isAhead(camera, point) {
1179
1279
  if (!point || !Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z)) {
@@ -1234,14 +1334,15 @@
1234
1334
  return;
1235
1335
  }
1236
1336
  const position = canvasPosition(viewer, e);
1237
- const target = pickTarget(state, position);
1238
- if (!target) {
1337
+ const picked = pickTarget(state, position);
1338
+ if (!picked) {
1239
1339
  return;
1240
1340
  }
1341
+ const target = picked.point;
1241
1342
  const camera = viewer.camera;
1242
1343
  const distance = Cesium.Cartesian3.distance(camera.positionWC, target);
1243
1344
  state.lastDistance = Math.max(distance, MIN_ZOOM_DISTANCE);
1244
- const drag = { kind, pointerId: e.pointerId, last: position, target, up: upAt(state, target), distance };
1345
+ const drag = { kind, pointerId: e.pointerId, last: position, target, up: upAt(state, target), distance, picked };
1245
1346
  if (kind === EDrag.Pan) {
1246
1347
  drag.plane = panPlane(camera, target, drag.up);
1247
1348
  }
@@ -1284,7 +1385,7 @@
1284
1385
  break;
1285
1386
  case EDrag.Zoom:
1286
1387
  // Dragging down zooms in, as it does in CesiumJS.
1287
- moveAlong(state, drag.direction, drag.target, dy / DRAG_PIXELS_PER_NOTCH);
1388
+ moveAlong(state, drag.direction, drag.picked, dy / DRAG_PIXELS_PER_NOTCH);
1288
1389
  break;
1289
1390
  }
1290
1391
  drag.last = position;
@@ -1317,6 +1418,14 @@
1317
1418
  if (length > limit) {
1318
1419
  Cesium.Cartesian3.multiplyByScalar(delta, limit / length, delta);
1319
1420
  }
1421
+ // A pan never takes a camera above the ground down through it; it keeps the sideways part of the move.
1422
+ if (wouldSinkBelowGround(state, camera.position, delta)) {
1423
+ const up = upAt(state, camera.position);
1424
+ const down = Cesium.Cartesian3.dot(delta, up);
1425
+ if (down < 0) {
1426
+ Cesium.Cartesian3.subtract(delta, Cesium.Cartesian3.multiplyByScalar(up, down, new Cesium.Cartesian3()), delta);
1427
+ }
1428
+ }
1320
1429
  Cesium.Cartesian3.add(camera.position, delta, camera.position);
1321
1430
  }
1322
1431
  /*
@@ -1338,7 +1447,13 @@
1338
1447
  const right = Cesium.Cartesian3.cross(camera.direction, up, new Cesium.Cartesian3());
1339
1448
  if (Cesium.Cartesian3.magnitude(right) > Cesium.Math.EPSILON6) {
1340
1449
  Cesium.Cartesian3.normalize(right, right);
1450
+ const before = Cesium.Cartesian3.clone(camera.position);
1341
1451
  rotateAbout(camera, drag.target, right, pitch);
1452
+ // Orbiting does not swing a camera above the ground down through it; the tilt that would is undone.
1453
+ const moved = Cesium.Cartesian3.subtract(camera.position, before, new Cesium.Cartesian3());
1454
+ if (wouldSinkBelowGround(state, before, moved)) {
1455
+ rotateAbout(camera, drag.target, right, -pitch);
1456
+ }
1342
1457
  }
1343
1458
  levelCamera(camera, upAt(state, camera.position));
1344
1459
  }
@@ -1425,22 +1540,262 @@
1425
1540
  /*
1426
1541
  * The move for some notches toward a target along a direction, a share of the distance with a floor so it never stalls.
1427
1542
  */
1428
- function zoomStep(state, direction, target, notches) {
1543
+ function zoomStep(state, direction, picked, notches) {
1429
1544
  const camera = state.viewer.camera;
1430
- const distance = Math.max(Cesium.Cartesian3.distance(camera.positionWC, target), MIN_ZOOM_DISTANCE);
1545
+ const target = picked.point;
1546
+ // Where the camera will be once the glide already under way ends, which this step continues from.
1547
+ const from = Cesium.Cartesian3.add(camera.positionWC, state.pendingZoom, new Cesium.Cartesian3());
1548
+ const distance = Math.max(Cesium.Cartesian3.distance(from, target), MIN_ZOOM_DISTANCE);
1431
1549
  state.lastDistance = distance;
1432
- let length = distance * ZOOM_SHARE * notches;
1550
+ let length = distance * ZOOM_SHARE * notches * zoomSpeedShare(state, picked);
1433
1551
  // A geospatial camera zooming out hands over to CesiumJS once it is high enough, so only model-space is capped.
1434
1552
  if (length < 0 && state.getModelSpaceFrame) {
1435
1553
  const origin = Cesium.Matrix4.getTranslation(state.getModelSpaceFrame(), new Cesium.Cartesian3());
1436
- const pending = Cesium.Cartesian3.add(camera.positionWC, state.pendingZoom, new Cesium.Cartesian3());
1437
- const range = Cesium.Cartesian3.distance(pending, origin);
1554
+ const range = Cesium.Cartesian3.distance(from, origin);
1438
1555
  length = Math.max(length, range - MODEL_SPACE_MAX_RANGE);
1439
1556
  if (length >= 0) {
1440
1557
  return new Cesium.Cartesian3();
1441
1558
  }
1442
1559
  }
1443
- return Cesium.Cartesian3.multiplyByScalar(Cesium.Cartesian3.normalize(direction, new Cesium.Cartesian3()), length, new Cesium.Cartesian3());
1560
+ const unit = Cesium.Cartesian3.normalize(direction, new Cesium.Cartesian3());
1561
+ // With the globe hidden there is no hand-over, so zooming out stops where the Earth is a dot.
1562
+ if (length < 0 && !state.getModelSpaceFrame && !globeShown(state)) {
1563
+ const rise = -Cesium.Cartesian3.dot(unit, upAt(state, from));
1564
+ const headroom = HIDDEN_GLOBE_MAX_HEIGHT - heightOf(state, from);
1565
+ if (rise > 0) {
1566
+ length = Math.max(length, -Math.max(headroom, 0) / rise);
1567
+ }
1568
+ if (length >= 0) {
1569
+ return new Cesium.Cartesian3();
1570
+ }
1571
+ }
1572
+ const step = Cesium.Cartesian3.multiplyByScalar(unit, length, new Cesium.Cartesian3());
1573
+ return length > 0 ? resistDescent(state, from, step, picked, notches) : step;
1574
+ }
1575
+ /*
1576
+ * How fast to zoom toward a target: slower toward a guess, or while the terrain that would give a real one loads.
1577
+ */
1578
+ function zoomSpeedShare(state, picked) {
1579
+ let share = 1;
1580
+ if (picked.source !== "pick") {
1581
+ share *= ZOOM_GUESS_SHARE;
1582
+ }
1583
+ const globe = state.viewer.scene.globe;
1584
+ if (!state.getModelSpaceFrame && globeShown(state) && globe.tilesLoaded === false) {
1585
+ share *= ZOOM_LOADING_SHARE;
1586
+ }
1587
+ return share;
1588
+ }
1589
+ /*
1590
+ * The ground a move comes down onto: the ground picked, else the terrain under where the move ends; null for none.
1591
+ */
1592
+ function groundUnderMove(state, from, step, picked) {
1593
+ var _a, _b;
1594
+ if (state.getModelSpaceFrame || !hasGround(state)) {
1595
+ return null;
1596
+ }
1597
+ if (picked === null || picked === void 0 ? void 0 : picked.ground) {
1598
+ return { point: picked.point, up: upAt(state, picked.point) };
1599
+ }
1600
+ if (!globeShown(state)) {
1601
+ return null;
1602
+ }
1603
+ const ellipsoid = ellipsoidOf(state);
1604
+ const end = Cesium.Cartesian3.add(from, step, new Cesium.Cartesian3());
1605
+ const carto = ellipsoid.cartesianToCartographic(end);
1606
+ if (!carto) {
1607
+ return null;
1608
+ }
1609
+ const height = (_b = (_a = terrainHeightAt(state, carto)) !== null && _a !== void 0 ? _a : terrainHeightAt(state, ellipsoid.cartesianToCartographic(from))) !== null && _b !== void 0 ? _b : 0;
1610
+ const point = Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, height, ellipsoid);
1611
+ return { point, up: ellipsoid.geodeticSurfaceNormal(point, new Cesium.Cartesian3()) };
1612
+ }
1613
+ /*
1614
+ * Whether a move takes a camera that is above the ground to within the stand-off of it or below.
1615
+ */
1616
+ function wouldSinkBelowGround(state, from, step) {
1617
+ const ground = groundUnderMove(state, from, step, null);
1618
+ if (!ground) {
1619
+ return false;
1620
+ }
1621
+ const before = Cesium.Cartesian3.dot(Cesium.Cartesian3.subtract(from, ground.point, new Cesium.Cartesian3()), ground.up);
1622
+ const after = before + Cesium.Cartesian3.dot(step, ground.up);
1623
+ return before > 0 && after < Math.min(GROUND_STANDOFF, before);
1624
+ }
1625
+ /*
1626
+ * Slows a camera coming down from above as it nears the ground and stops it just above, until pushed on enough to
1627
+ * pass through; harder when nothing is known to be underground. A camera already below the ground moves freely.
1628
+ */
1629
+ function resistDescent(state, from, step, picked, notches) {
1630
+ const ground = groundUnderMove(state, from, step, picked);
1631
+ const length = Cesium.Cartesian3.magnitude(step);
1632
+ if (!ground || length === 0) {
1633
+ return step;
1634
+ }
1635
+ const above = Cesium.Cartesian3.dot(Cesium.Cartesian3.subtract(from, ground.point, new Cesium.Cartesian3()), ground.up);
1636
+ const unit = Cesium.Cartesian3.divideByScalar(step, length, new Cesium.Cartesian3());
1637
+ const sink = -Cesium.Cartesian3.dot(unit, ground.up);
1638
+ if (above <= 0 || sink <= 0) {
1639
+ return step;
1640
+ }
1641
+ let allowed = length;
1642
+ if (above < GROUND_APPROACH) {
1643
+ allowed *= Math.max(above / GROUND_APPROACH, GROUND_APPROACH_FLOOR);
1644
+ }
1645
+ const toStandOff = Math.max(above - GROUND_STANDOFF, 0) / sink;
1646
+ if (allowed <= toStandOff) {
1647
+ return Cesium.Cartesian3.multiplyByScalar(unit, allowed, new Cesium.Cartesian3());
1648
+ }
1649
+ // Held at the stand-off: each push counts, and enough close together go through.
1650
+ const now = Date.now();
1651
+ if (now - state.push.at > PUSH_WINDOW_MS) {
1652
+ state.push.notches = 0;
1653
+ }
1654
+ state.push.at = now;
1655
+ state.push.notches += Math.abs(notches);
1656
+ const needed = scanScene(state).undergroundData ? PUSH_NOTCHES_DATA_BELOW : PUSH_NOTCHES_NOTHING_BELOW;
1657
+ if (state.push.notches >= needed) {
1658
+ state.push.notches = 0;
1659
+ // A shallow push would land far along the ground to get under it, so it goes no further than a usual step.
1660
+ const through = Math.min((above + GROUND_BREAK_DEPTH) / sink, Math.max(length, (above + GROUND_BREAK_DEPTH) * 4));
1661
+ return Cesium.Cartesian3.multiplyByScalar(unit, through, new Cesium.Cartesian3());
1662
+ }
1663
+ return Cesium.Cartesian3.multiplyByScalar(unit, toStandOff, new Cesium.Cartesian3());
1664
+ }
1665
+ /*
1666
+ * What the scene holds that the camera cares about, rescanned at most every couple of seconds.
1667
+ */
1668
+ function scanScene(state) {
1669
+ var _a, _b;
1670
+ const now = Date.now();
1671
+ if (state.scan && now - state.scan.at < SCENE_SCAN_MS) {
1672
+ return applyOverride(state, state.scan);
1673
+ }
1674
+ const scene = state.viewer.scene;
1675
+ const found = { at: now, undergroundData: false, groundTileset: false };
1676
+ // Seeing through the ground is turned on to look at what is under it.
1677
+ if ((_b = (_a = scene.globe) === null || _a === void 0 ? void 0 : _a.translucency) === null || _b === void 0 ? void 0 : _b.enabled) {
1678
+ found.undergroundData = true;
1679
+ }
1680
+ const visit = (primitive) => {
1681
+ if (!primitive || primitive.show === false || (primitive.isDestroyed && primitive.isDestroyed())) {
1682
+ return;
1683
+ }
1684
+ if (typeof primitive.length === "number" && typeof primitive.get === "function") {
1685
+ for (let i = 0; i < primitive.length; i++) {
1686
+ visit(primitive.get(i));
1687
+ }
1688
+ return;
1689
+ }
1690
+ if (primitive[GROUND_TILESET_KEY]) {
1691
+ found.groundTileset = true;
1692
+ return;
1693
+ }
1694
+ if (!found.undergroundData && reachesBelowGround(state, lowestPointOf(primitive))) {
1695
+ found.undergroundData = true;
1696
+ }
1697
+ };
1698
+ visit(scene.primitives);
1699
+ if (!found.undergroundData) {
1700
+ found.undergroundData = entitiesBelowGround(state);
1701
+ }
1702
+ state.scan = found;
1703
+ return applyOverride(state, found);
1704
+ }
1705
+ function applyOverride(state, found) {
1706
+ return state.undergroundOverride == null ? found : { ...found, undergroundData: state.undergroundOverride };
1707
+ }
1708
+ /*
1709
+ * The lowest point of a tileset or model: its root box's lowest corner, or its bounding sphere's centre.
1710
+ */
1711
+ function lowestPointOf(primitive) {
1712
+ var _a, _b, _c;
1713
+ const volume = (_a = primitive === null || primitive === void 0 ? void 0 : primitive.root) === null || _a === void 0 ? void 0 : _a.boundingVolume;
1714
+ if (volume) {
1715
+ const region = Number.isFinite(volume.minimumHeight) && volume.rectangle;
1716
+ if (region) {
1717
+ return Cesium.Cartesian3.fromRadians(Cesium.Rectangle.center(volume.rectangle).longitude, Cesium.Rectangle.center(volume.rectangle).latitude, volume.minimumHeight);
1718
+ }
1719
+ const box = volume.boundingVolume;
1720
+ const corners = box instanceof Cesium.OrientedBoundingBox && typeof Cesium.OrientedBoundingBox.computeCorners === "function" ? Cesium.OrientedBoundingBox.computeCorners(box) : null;
1721
+ if (corners === null || corners === void 0 ? void 0 : corners.length) {
1722
+ return lowestOf(corners);
1723
+ }
1724
+ }
1725
+ // A sphere's centre, as its radius reaches below the ground for anything standing on it.
1726
+ return (_c = (_b = primitive === null || primitive === void 0 ? void 0 : primitive.boundingSphere) === null || _b === void 0 ? void 0 : _b.center) !== null && _c !== void 0 ? _c : null;
1727
+ }
1728
+ function lowestOf(points) {
1729
+ var _a, _b;
1730
+ let lowest = null;
1731
+ let lowestHeight = Number.POSITIVE_INFINITY;
1732
+ for (const point of points) {
1733
+ const height = (_b = (_a = Cesium.Cartographic.fromCartesian(point)) === null || _a === void 0 ? void 0 : _a.height) !== null && _b !== void 0 ? _b : Number.POSITIVE_INFINITY;
1734
+ if (height < lowestHeight) {
1735
+ lowestHeight = height;
1736
+ lowest = point;
1737
+ }
1738
+ }
1739
+ return lowest;
1740
+ }
1741
+ /*
1742
+ * Whether a point is clearly below the ground at its place: the terrain there, else sea level.
1743
+ */
1744
+ function reachesBelowGround(state, point) {
1745
+ var _a;
1746
+ if (!point) {
1747
+ return false;
1748
+ }
1749
+ const carto = ellipsoidOf(state).cartesianToCartographic(point);
1750
+ if (!carto) {
1751
+ return false;
1752
+ }
1753
+ return carto.height < ((_a = terrainHeightAt(state, carto)) !== null && _a !== void 0 ? _a : 0) - UNDERGROUND_MARGIN;
1754
+ }
1755
+ /*
1756
+ * Whether any of the first entities sits clearly below the ground: a point, or a line's first or last vertex.
1757
+ */
1758
+ function entitiesBelowGround(state) {
1759
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
1760
+ const viewer = state.viewer;
1761
+ const collections = [viewer.entities];
1762
+ const sources = viewer.dataSources;
1763
+ for (let i = 0; i < ((_a = sources === null || sources === void 0 ? void 0 : sources.length) !== null && _a !== void 0 ? _a : 0); i++) {
1764
+ collections.push((_b = sources.get(i)) === null || _b === void 0 ? void 0 : _b.entities);
1765
+ }
1766
+ const time = (_d = (_c = viewer.clock) === null || _c === void 0 ? void 0 : _c.currentTime) !== null && _d !== void 0 ? _d : Cesium.JulianDate.now();
1767
+ let seen = 0;
1768
+ for (const collection of collections) {
1769
+ for (const entity of (_e = collection === null || collection === void 0 ? void 0 : collection.values) !== null && _e !== void 0 ? _e : []) {
1770
+ if (seen++ >= SCENE_SCAN_ENTITIES) {
1771
+ return false;
1772
+ }
1773
+ if (!entity || entity.show === false) {
1774
+ continue;
1775
+ }
1776
+ const graphic = (_j = (_h = (_g = (_f = entity.model) !== null && _f !== void 0 ? _f : entity.point) !== null && _g !== void 0 ? _g : entity.billboard) !== null && _h !== void 0 ? _h : entity.box) !== null && _j !== void 0 ? _j : entity.cylinder;
1777
+ const reference = (_l = (_k = graphic === null || graphic === void 0 ? void 0 : graphic.heightReference) === null || _k === void 0 ? void 0 : _k.getValue) === null || _l === void 0 ? void 0 : _l.call(_k, time);
1778
+ if (reference === Cesium.HeightReference.CLAMP_TO_GROUND) {
1779
+ continue;
1780
+ }
1781
+ const position = (_o = (_m = entity.position) === null || _m === void 0 ? void 0 : _m.getValue) === null || _o === void 0 ? void 0 : _o.call(_m, time);
1782
+ if (position) {
1783
+ const relative = reference === Cesium.HeightReference.RELATIVE_TO_GROUND;
1784
+ const height = relative ? (_p = ellipsoidOf(state).cartesianToCartographic(position)) === null || _p === void 0 ? void 0 : _p.height : null;
1785
+ if (relative ? height < -UNDERGROUND_MARGIN : reachesBelowGround(state, position)) {
1786
+ return true;
1787
+ }
1788
+ }
1789
+ const line = entity.polyline;
1790
+ if (line && !((_r = (_q = line.clampToGround) === null || _q === void 0 ? void 0 : _q.getValue) === null || _r === void 0 ? void 0 : _r.call(_q, time))) {
1791
+ const positions = (_u = (_t = (_s = line.positions) === null || _s === void 0 ? void 0 : _s.getValue) === null || _t === void 0 ? void 0 : _t.call(_s, time)) !== null && _u !== void 0 ? _u : [];
1792
+ if (positions.length && (reachesBelowGround(state, positions[0]) || reachesBelowGround(state, positions[positions.length - 1]))) {
1793
+ return true;
1794
+ }
1795
+ }
1796
+ }
1797
+ }
1798
+ return false;
1444
1799
  }
1445
1800
 
1446
1801
  const CESIUM_INSPECTOR_KEY = "_nextspace_inspector";
@@ -30838,6 +31193,8 @@
30838
31193
  this.doDispose();
30839
31194
  return;
30840
31195
  }
31196
+ // Photorealistic tiles cover the Earth, so the camera treats them as the ground when the globe is hidden.
31197
+ exports.CameraControls.SetGroundTileset(this.cTileset, true);
30841
31198
  this.viewer.scene.primitives.add(this.cTileset);
30842
31199
  this.applyColorMask();
30843
31200
  this.viewer.scene.requestRender();
@@ -59801,7 +60158,7 @@ void main() {
59801
60158
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
59802
60159
  })(exports.StyleUtils || (exports.StyleUtils = {}));
59803
60160
 
59804
- const VERSION = "7.7.8";
60161
+ const VERSION = "7.7.9";
59805
60162
  /**
59806
60163
  * Updates the environment instance used by bruce-cesium to one specified.
59807
60164
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.