bruce-cesium 7.9.3 → 7.9.4

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.
@@ -1,6 +1,6 @@
1
1
  import * as Cesium from 'cesium';
2
- import { Cartographic, ColorMaterialProperty, Entity, Color, ConstantProperty, CallbackProperty, Primitive, Cesium3DTileFeature, ConstantPositionProperty, HeightReference, DistanceDisplayCondition, Math as Math$1, Cartesian3, JulianDate, Quaternion, Transforms, HeadingPitchRoll, Matrix4, ColorBlendMode, Model, ClassificationType, ArcType, CornerType, HorizontalOrigin, VerticalOrigin, ShaderSource, Ellipsoid, Geometry, GeometryAttribute, ComponentDatatype, PrimitiveType, BoundingSphere, GeometryPipeline, Cartesian2, Cartesian4, sampleTerrain, Texture, PixelFormat, Sampler, TextureWrap, TextureMinificationFilter, TextureMagnificationFilter, PixelDatatype, VertexArray, BufferUsage, ShaderProgram, RenderState, BlendingState, DrawCommand, Pass, SceneMode, IntersectionTests, Ray, SceneTransforms, ImageMaterialProperty, PolygonHierarchy, PolylineGraphics, Rectangle, NearFarScalar, Matrix3, KmlDataSource, GeoJsonDataSource, FeatureDetection, HeadingPitchRange, Ion, Cesium3DTileStyle, IonResource, Cesium3DTileset, EllipsoidTerrainProvider, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, Cesium3DTileColorBlendMode, OrthographicFrustum, EasingFunction, Intersect, WebGLConstants, EllipsoidGeodesic, sampleTerrainMostDetailed, PolygonPipeline, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, CesiumInspector, defined, ClockRange, ShadowMode, DynamicEnvironmentMapManager, PrimitiveCollection, PolylineCollection, LabelCollection, LabelStyle, Material, GeometryInstance, Event, CustomDataSource, CameraEventType, Plane, OrientedBoundingBox, ScreenSpaceEventHandler, ScreenSpaceEventType, Fullscreen, CzmlDataSource } from 'cesium';
3
- import { Cartes, LRUCache, Carto, ProjectViewTile, EntityHistoricData, BruceEvent, DelayQueue, Entity as Entity$1, EntityTag, PathUtils, ClientFile, ENVIRONMENT, EntityAttachmentType, EntityRelationType, EntityType, Tileset, Calculator, DataLab, Style, ObjectUtils, MenuItem, ZoomControl, AccountConcept, RecordChangeFeed, EntityLod, UrlUtils, Geometry as Geometry$1, Api, ProjectView, ProjectViewBookmark, Assembly, EntityCoords, ClientFileValueMap, Color as Color$1, Bounds, EntityRelation, BruceApi, EntitySource, ProgramKey, ProjectViewLegacyTile, Camera, Account, AccountLimits, Session, ProjectViewBookmarkGroup, EntityAttachment, EntityAttribute, MathUtils } from 'bruce-models';
2
+ import { Cartographic, ColorMaterialProperty, Entity, Color, ConstantProperty, CallbackProperty, Primitive, Cesium3DTileFeature, ConstantPositionProperty, HeightReference, DistanceDisplayCondition, Math as Math$1, Cartesian3, JulianDate, Quaternion, Transforms, HeadingPitchRoll, Matrix4, ClassificationType, ArcType, CornerType, ShaderSource, Ellipsoid, Geometry, GeometryAttribute, ComponentDatatype, PrimitiveType, BoundingSphere, GeometryPipeline, Cartesian2, Cartesian4, sampleTerrain, Texture, PixelFormat, Sampler, TextureWrap, TextureMinificationFilter, TextureMagnificationFilter, PixelDatatype, VertexArray, BufferUsage, ShaderProgram, RenderState, BlendingState, DrawCommand, Pass, HorizontalOrigin, VerticalOrigin, SceneMode, IntersectionTests, Ray, SceneTransforms, ColorBlendMode, Model, ImageMaterialProperty, PolygonHierarchy, PolylineGraphics, Rectangle, NearFarScalar, Matrix3, KmlDataSource, GeoJsonDataSource, Cesium3DTileStyle, Cesium3DTileColorBlendMode, HeadingPitchRange, Ion, IonResource, OrthographicFrustum, EasingFunction, EllipsoidTerrainProvider, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, Intersect, FeatureDetection, Cesium3DTileset, WebGLConstants, EllipsoidGeodesic, sampleTerrainMostDetailed, PolygonPipeline, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, PrimitiveCollection, ShadowMode, PolylineCollection, LabelCollection, LabelStyle, Material, CustomDataSource, Event, CesiumInspector, defined, ClockRange, DynamicEnvironmentMapManager, ScreenSpaceEventHandler, ScreenSpaceEventType, CameraEventType, Plane, OrientedBoundingBox, GeometryInstance, Fullscreen, CzmlDataSource } from 'cesium';
3
+ import { Cartes, LRUCache, Carto, ProjectViewTile, EntityHistoricData, BruceEvent, DelayQueue, Entity as Entity$1, EntityTag, PathUtils, ClientFile, ENVIRONMENT, EntityAttachmentType, EntityRelationType, EntityType, Tileset, Calculator, DataLab, Style, ObjectUtils, MenuItem, ZoomControl, AccountConcept, RecordChangeFeed, Geometry as Geometry$1, Api, ProjectView, ProjectViewBookmark, EntityLod, UrlUtils, Bounds, ClientFileValueMap, Color as Color$1, Assembly, EntityCoords, BruceApi, EntityRelation, EntitySource, Camera, ProgramKey, ProjectViewLegacyTile, Account, AccountLimits, Session, ProjectViewBookmarkGroup, EntityAttachment, EntityAttribute, MathUtils } from 'bruce-models';
4
4
 
5
5
  /**
6
6
  * Ensures a number is returned from a given value.
@@ -1367,6 +1367,11 @@ const PUSH_NOTCHES_DATA_BELOW = 3;
1367
1367
  const PUSH_NOTCHES_NOTHING_BELOW = 10;
1368
1368
  // Pushes further apart than this start counting again.
1369
1369
  const PUSH_WINDOW_MS = 1200;
1370
+ // How long after a zoom newly loaded terrain may lift the camera, and how much longer while loading.
1371
+ const SURFACE_HOLD_MS = 4000;
1372
+ const SURFACE_LOADING_MS = 30000;
1373
+ // No visible ground lies lower; a stand-in tileset below this is a coarse tile cutting under the curve.
1374
+ const GROUND_FLOOR = -500;
1370
1375
  // How far below the ground something must reach to count as data underground, in metres.
1371
1376
  const UNDERGROUND_MARGIN = 3;
1372
1377
  // How long a scan of the scene for underground data and stand-in ground is trusted, in milliseconds.
@@ -1416,6 +1421,7 @@ var CameraControls;
1416
1421
  push: { notches: 0, at: 0 },
1417
1422
  scan: null,
1418
1423
  undergroundOverride: null,
1424
+ surface: { above: false, through: false, until: 0, at: null },
1419
1425
  saved: {
1420
1426
  rotateEventTypes: controller.rotateEventTypes,
1421
1427
  zoomEventTypes: controller.zoomEventTypes,
@@ -1440,7 +1446,10 @@ var CameraControls;
1440
1446
  listen(window, "pointerup", (e) => onPointerUp(state, e));
1441
1447
  listen(window, "pointercancel", (e) => onPointerUp(state, e));
1442
1448
  listen(canvas, "wheel", (e) => onWheel(state, e), { passive: true });
1443
- state.removals.push(scene.preUpdate.addEventListener(() => syncController(state)));
1449
+ state.removals.push(scene.preUpdate.addEventListener(() => {
1450
+ syncController(state);
1451
+ keepAboveGround(state);
1452
+ }));
1444
1453
  syncController(state);
1445
1454
  scene.requestRender();
1446
1455
  }
@@ -1592,6 +1601,38 @@ function terrainHeightAt(state, carto) {
1592
1601
  const height = globe.getHeight(carto);
1593
1602
  return Number.isFinite(height) ? height : undefined;
1594
1603
  }
1604
+ /*
1605
+ * The ground's height at a place: the loaded terrain, or the tileset standing in for a hidden globe.
1606
+ */
1607
+ function groundHeightAt(state, carto) {
1608
+ var _a;
1609
+ if (globeShown(state)) {
1610
+ return terrainHeightAt(state, carto);
1611
+ }
1612
+ const tileset = scanScene(state).ground;
1613
+ if (!carto || !tileset || ((_a = tileset.isDestroyed) === null || _a === void 0 ? void 0 : _a.call(tileset)) || typeof tileset.getHeight !== "function") {
1614
+ return undefined;
1615
+ }
1616
+ try {
1617
+ // Only tiles drawn this frame answer, which near the camera are the finest loaded.
1618
+ const height = tileset.getHeight(carto, state.viewer.scene);
1619
+ return Number.isFinite(height) && height > GROUND_FLOOR ? height : undefined;
1620
+ }
1621
+ catch (e) {
1622
+ return undefined;
1623
+ }
1624
+ }
1625
+ /*
1626
+ * Whether the ground is still loading: the globe's tiles, or the stand-in tileset's.
1627
+ */
1628
+ function groundLoading(state) {
1629
+ var _a;
1630
+ if (globeShown(state)) {
1631
+ return state.viewer.scene.globe.tilesLoaded === false;
1632
+ }
1633
+ const tileset = scanScene(state).ground;
1634
+ return Boolean(tileset && !((_a = tileset.isDestroyed) === null || _a === void 0 ? void 0 : _a.call(tileset)) && tileset.tilesLoaded === false);
1635
+ }
1595
1636
  function ellipsoidOf(state) {
1596
1637
  var _a, _b;
1597
1638
  return (_b = (_a = state.viewer.scene.globe) === null || _a === void 0 ? void 0 : _a.ellipsoid) !== null && _b !== void 0 ? _b : Ellipsoid.WGS84;
@@ -1629,8 +1670,8 @@ function groundPlane(state) {
1629
1670
  if (!carto) {
1630
1671
  return null;
1631
1672
  }
1632
- // Level with the terrain under the camera, not sea level, so a guess over high ground is not far too deep.
1633
- const surface = Cartesian3.fromRadians(carto.longitude, carto.latitude, (_a = terrainHeightAt(state, carto)) !== null && _a !== void 0 ? _a : 0, ellipsoid);
1673
+ // Level with the ground under the camera, not sea level, so a guess over high ground is not far too deep.
1674
+ const surface = Cartesian3.fromRadians(carto.longitude, carto.latitude, (_a = groundHeightAt(state, carto)) !== null && _a !== void 0 ? _a : 0, ellipsoid);
1634
1675
  return Plane.fromPointNormal(surface, ellipsoid.geodeticSurfaceNormal(surface, new Cartesian3()));
1635
1676
  }
1636
1677
  /*
@@ -1654,6 +1695,15 @@ const GAP_SLACK = 0.5;
1654
1695
  // Directions around the centre, and how many must hold nearer pixels for the centre to be surrounded.
1655
1696
  const GAP_SECTORS = 8;
1656
1697
  const GAP_SECTORS_NEAR = 6;
1698
+ // How far around the cursor, in CSS pixels, nearer parts limit a zoom, and the most buffer pixels read.
1699
+ const CLEARANCE_RADIUS_PX = 24;
1700
+ const CLEARANCE_RADIUS_MAX = 64;
1701
+ // The share of that window that must be nearer, so a stray pixel or a thin cable does not slow the zoom.
1702
+ const CLEARANCE_SHARE = 0.05;
1703
+ // A pixel at least this share of the level ground's distance on its ray is ground, and never limits.
1704
+ const CLEARANCE_GROUND = 0.9;
1705
+ // A pan or orbit grabbing this many times farther than the reach grabs at the reach instead.
1706
+ const CLEARANCE_GRAB = 2;
1657
1707
  const PACKED_DEPTH = new Cartesian4(1, 1 / 255, 1 / 65025, 1 / 16581375);
1658
1708
  /*
1659
1709
  * Distances along the view axis drawn around a window position, rows bottom-up, Infinity where nothing is drawn.
@@ -1702,6 +1752,21 @@ function readDepthDistances(scene, position, radius) {
1702
1752
  }
1703
1753
  return distances;
1704
1754
  }
1755
+ /*
1756
+ * The depth window around a position for the gap search and the reach, or null when unreadable.
1757
+ */
1758
+ function readWindow(scene, position) {
1759
+ const scale = scene.drawingBufferWidth / scene.canvas.clientWidth;
1760
+ const clearance = Math.min(Math.round(CLEARANCE_RADIUS_PX * (Number.isFinite(scale) ? scale : 1)), CLEARANCE_RADIUS_MAX);
1761
+ const radius = Math.max(GAP_RADII[GAP_RADII.length - 1], clearance);
1762
+ try {
1763
+ const distances = readDepthDistances(scene, position, radius);
1764
+ return distances ? { distances, radius } : null;
1765
+ }
1766
+ catch (e) {
1767
+ return null;
1768
+ }
1769
+ }
1705
1770
  /*
1706
1771
  * Offsets of the surface pixel around the centre for each radius where clearly nearer pixels surround it.
1707
1772
  */
@@ -1739,15 +1804,7 @@ function FindGapSurfaces(distances, radius) {
1739
1804
  /*
1740
1805
  * The point cloud surface around a pick that looked through a gap between its points, or null when it did not.
1741
1806
  */
1742
- function fillGap(scene, position, picked) {
1743
- const radius = GAP_RADII[GAP_RADII.length - 1];
1744
- let distances = null;
1745
- try {
1746
- distances = readDepthDistances(scene, position, radius);
1747
- }
1748
- catch (e) {
1749
- return null;
1750
- }
1807
+ function fillGap(scene, position, picked, distances, radius) {
1751
1808
  if (!distances) {
1752
1809
  return null;
1753
1810
  }
@@ -1767,9 +1824,80 @@ function fillGap(scene, position, picked) {
1767
1824
  return null;
1768
1825
  }
1769
1826
  /*
1770
- * The point under a screen position: what is drawn there, else the ground plane, else a point at the last distance.
1827
+ * The view-axis distance within which a share of the window around the cursor is drawn, ground aside.
1828
+ */
1829
+ function NearClearance(distances, radius, groundAt) {
1830
+ const width = 2 * radius + 1;
1831
+ const near = [];
1832
+ for (let dy = -radius; dy <= radius; dy++) {
1833
+ for (let dx = -radius; dx <= radius; dx++) {
1834
+ const distance = distances[(radius + dy) * width + (radius + dx)];
1835
+ if (!Number.isFinite(distance)) {
1836
+ continue;
1837
+ }
1838
+ const ground = groundAt ? groundAt(dx, dy) : Infinity;
1839
+ if (!(ground > 0 && distance >= ground * CLEARANCE_GROUND)) {
1840
+ near.push(distance);
1841
+ }
1842
+ }
1843
+ }
1844
+ const needed = Math.max(1, Math.ceil(width * width * CLEARANCE_SHARE));
1845
+ if (near.length < needed) {
1846
+ return Infinity;
1847
+ }
1848
+ near.sort((a, b) => a - b);
1849
+ return near[needed - 1];
1850
+ }
1851
+ /*
1852
+ * The level ground's view-axis distance through each window pixel, or null when there is no ground.
1853
+ */
1854
+ function groundDistances(state, position) {
1855
+ const scene = state.viewer.scene;
1856
+ const camera = scene.camera;
1857
+ const frustum = camera.frustum;
1858
+ if (!(state.getModelSpaceFrame || hasGround(state)) ||
1859
+ typeof (frustum === null || frustum === void 0 ? void 0 : frustum.getPixelDimensions) !== "function") {
1860
+ return null;
1861
+ }
1862
+ const plane = groundPlane(state);
1863
+ if (!plane) {
1864
+ return null;
1865
+ }
1866
+ const width = scene.drawingBufferWidth;
1867
+ const height = scene.drawingBufferHeight;
1868
+ // The size of one buffer pixel one metre ahead, which turns a pixel offset into a ray direction.
1869
+ const pixel = frustum.getPixelDimensions(width, height, 1, 1, new Cartesian2());
1870
+ const above = Plane.getPointDistance(plane, camera.positionWC);
1871
+ const normal = plane.normal;
1872
+ const along = Cartesian3.dot(camera.directionWC, normal);
1873
+ const right = Cartesian3.dot(camera.rightWC, normal);
1874
+ const up = Cartesian3.dot(camera.upWC, normal);
1875
+ // The cursor's offset from the centre in buffer pixels, rows bottom-up as the window's are.
1876
+ const x = Math.floor(position.x * width / scene.canvas.clientWidth) + 0.5 - width / 2;
1877
+ const y = height / 2 - Math.floor(position.y * height / scene.canvas.clientHeight) - 0.5;
1878
+ return (dx, dy) => {
1879
+ const rate = along + (x + dx) * pixel.x * right + (y + dy) * pixel.y * up;
1880
+ return rate < 0 ? -above / rate : Infinity;
1881
+ };
1882
+ }
1883
+ /*
1884
+ * The point under a screen position, and how far a zoom toward it may go before passing parts beside it.
1771
1885
  */
1772
1886
  function pickTarget(state, position) {
1887
+ const scene = state.viewer.scene;
1888
+ // Read before anything else picks, while the depth still holds the frame on screen.
1889
+ const depths = scene.pickPositionSupported ? readWindow(scene, position) : null;
1890
+ const target = pickPoint(state, position, depths);
1891
+ if (target && depths) {
1892
+ target.reach = NearClearance(depths.distances, depths.radius, groundDistances(state, position));
1893
+ target.reachFrom = Cartesian3.clone(state.viewer.camera.positionWC);
1894
+ }
1895
+ return target;
1896
+ }
1897
+ /*
1898
+ * The point under a screen position: what is drawn there, else the ground plane, else a point at the last distance.
1899
+ */
1900
+ function pickPoint(state, position, depths) {
1773
1901
  const viewer = state.viewer;
1774
1902
  const scene = viewer.scene;
1775
1903
  const camera = viewer.camera;
@@ -1794,12 +1922,16 @@ function pickTarget(state, position) {
1794
1922
  }
1795
1923
  const plausible = plausibleDistance(state);
1796
1924
  // A click between point cloud points sees the background; turning or zooming about that throws the camera far off.
1797
- const surface = scene.pickPositionSupported ? fillGap(scene, position, ahead !== null && ahead !== void 0 ? ahead : null) : null;
1925
+ const surface = depths ? fillGap(scene, position, ahead !== null && ahead !== void 0 ? ahead : null, depths.distances, depths.radius) : null;
1798
1926
  if (isAhead(camera, surface) && Cartesian3.distance(surface, camera.positionWC) < plausible) {
1799
1927
  return { point: surface, source: "pick", ground: false };
1800
1928
  }
1801
1929
  if (isAhead(camera, picked) && Cartesian3.distance(picked, camera.positionWC) < plausible) {
1802
- return { point: picked, source: "pick", ground: isGroundPick(state, position) };
1930
+ const ground = isGroundPick(state, position);
1931
+ // Right after a jump a stand-in tileset's coarse tiles cut far under the curve; use sea level.
1932
+ if (!ground || globeShown(state) || heightOf(state, picked) > GROUND_FLOOR) {
1933
+ return { point: picked, source: "pick", ground };
1934
+ }
1803
1935
  }
1804
1936
  const ground = groundPlane(state);
1805
1937
  const onGround = ground ? IntersectionTests.rayPlane(ray, ground) : null;
@@ -1901,8 +2033,8 @@ function onPointerDown(state, e) {
1901
2033
  if (!picked) {
1902
2034
  return;
1903
2035
  }
1904
- const target = picked.point;
1905
2036
  const camera = viewer.camera;
2037
+ const target = kind === EDrag.Zoom ? picked.point : GrabPoint(camera, position, picked);
1906
2038
  const distance = Cartesian3.distance(camera.positionWC, target);
1907
2039
  state.lastDistance = Math.max(distance, MIN_ZOOM_DISTANCE);
1908
2040
  const drag = { kind, pointerId: e.pointerId, last: position, target, up: upAt(state, target), distance, picked };
@@ -1910,10 +2042,28 @@ function onPointerDown(state, e) {
1910
2042
  drag.plane = panPlane(camera, target, drag.up);
1911
2043
  }
1912
2044
  else if (kind === EDrag.Zoom) {
2045
+ holdSurface(state);
1913
2046
  drag.direction = Cartesian3.normalize(Cartesian3.subtract(target, camera.positionWC, new Cartesian3()), new Cartesian3());
1914
2047
  }
1915
2048
  state.drag = drag;
1916
2049
  }
2050
+ /*
2051
+ * Where a pan or orbit takes hold: the pick, or beside the cursor when it looked far past parts there.
2052
+ */
2053
+ function GrabPoint(camera, position, picked) {
2054
+ const reach = picked.reach;
2055
+ const ray = camera.getPickRay(position);
2056
+ if (!ray || reach == null || !Number.isFinite(reach)) {
2057
+ return picked.point;
2058
+ }
2059
+ const facing = Cartesian3.dot(ray.direction, camera.directionWC);
2060
+ const depth = Cartesian3.dot(Cartesian3.subtract(picked.point, camera.positionWC, new Cartesian3()), camera.directionWC);
2061
+ if (facing <= 0 || depth <= reach * CLEARANCE_GRAB) {
2062
+ return picked.point;
2063
+ }
2064
+ // The reach is along the view axis, so the ray goes a little further to the same depth.
2065
+ return Ray.getPoint(ray, Math.max(reach, MIN_ZOOM_DISTANCE) / facing);
2066
+ }
1917
2067
  /*
1918
2068
  * A level plane through the grabbed point, or one facing the camera when the level one is seen edge on.
1919
2069
  */
@@ -2062,6 +2212,7 @@ function onWheel(state, e) {
2062
2212
  if (!target || !ray) {
2063
2213
  return;
2064
2214
  }
2215
+ holdSurface(state);
2065
2216
  const step = zoomStep(state, ray.direction, target, notches);
2066
2217
  Cartesian3.add(state.pendingZoom, step, state.pendingZoom);
2067
2218
  state.zoomPosition = Cartesian3.clone(camera.position);
@@ -2090,6 +2241,8 @@ function easeZoom(state) {
2090
2241
  const step = Cartesian3.multiplyByScalar(state.pendingZoom, share, new Cartesian3());
2091
2242
  Cartesian3.subtract(state.pendingZoom, step, state.pendingZoom);
2092
2243
  Cartesian3.add(viewer.camera.position, step, viewer.camera.position);
2244
+ zoomMoved(state);
2245
+ keepAboveGround(state);
2093
2246
  state.zoomPosition = Cartesian3.clone(viewer.camera.position);
2094
2247
  viewer.scene.requestRender();
2095
2248
  if (share < 1) {
@@ -2099,6 +2252,7 @@ function easeZoom(state) {
2099
2252
  function moveAlong(state, direction, target, notches) {
2100
2253
  const step = zoomStep(state, direction, target, notches);
2101
2254
  Cartesian3.add(state.viewer.camera.position, step, state.viewer.camera.position);
2255
+ zoomMoved(state);
2102
2256
  }
2103
2257
  /*
2104
2258
  * The move for some notches toward a target along a direction, a share of the distance with a floor so it never stalls.
@@ -2108,7 +2262,14 @@ function zoomStep(state, direction, picked, notches) {
2108
2262
  const target = picked.point;
2109
2263
  // Where the camera will be once the glide already under way ends, which this step continues from.
2110
2264
  const from = Cartesian3.add(camera.positionWC, state.pendingZoom, new Cartesian3());
2111
- const distance = Math.max(Cartesian3.distance(from, target), MIN_ZOOM_DISTANCE);
2265
+ const unit = Cartesian3.normalize(direction, new Cartesian3());
2266
+ let distance = Cartesian3.distance(from, target);
2267
+ // Between parts of a model, each step goes as far as it would on the nearest part around the cursor.
2268
+ if (picked.reach != null && picked.reachFrom) {
2269
+ const travelled = Cartesian3.dot(Cartesian3.subtract(from, picked.reachFrom, new Cartesian3()), unit);
2270
+ distance = Math.min(distance, picked.reach - travelled);
2271
+ }
2272
+ distance = Math.max(distance, MIN_ZOOM_DISTANCE);
2112
2273
  state.lastDistance = distance;
2113
2274
  let length = distance * ZOOM_SHARE * notches * zoomSpeedShare(state, picked);
2114
2275
  // A geospatial camera zooming out hands over to CesiumJS once it is high enough, so only model-space is capped.
@@ -2120,7 +2281,6 @@ function zoomStep(state, direction, picked, notches) {
2120
2281
  return new Cartesian3();
2121
2282
  }
2122
2283
  }
2123
- const unit = Cartesian3.normalize(direction, new Cartesian3());
2124
2284
  // With the globe hidden there is no hand-over, so zooming out stops where the Earth is a dot.
2125
2285
  if (length < 0 && !state.getModelSpaceFrame && !globeShown(state)) {
2126
2286
  const rise = -Cartesian3.dot(unit, upAt(state, from));
@@ -2136,15 +2296,14 @@ function zoomStep(state, direction, picked, notches) {
2136
2296
  return length > 0 ? resistDescent(state, from, step, picked, notches) : step;
2137
2297
  }
2138
2298
  /*
2139
- * How fast to zoom toward a target: slower toward a guess, or while the terrain that would give a real one loads.
2299
+ * How fast to zoom toward a target: slower toward a guess, or while the ground that would give a real one loads.
2140
2300
  */
2141
2301
  function zoomSpeedShare(state, picked) {
2142
2302
  let share = 1;
2143
2303
  if (picked.source !== "pick") {
2144
2304
  share *= ZOOM_GUESS_SHARE;
2145
2305
  }
2146
- const globe = state.viewer.scene.globe;
2147
- if (!state.getModelSpaceFrame && globeShown(state) && globe.tilesLoaded === false) {
2306
+ if (!state.getModelSpaceFrame && groundLoading(state)) {
2148
2307
  share *= ZOOM_LOADING_SHARE;
2149
2308
  }
2150
2309
  return share;
@@ -2160,16 +2319,17 @@ function groundUnderMove(state, from, step, picked) {
2160
2319
  if (picked === null || picked === void 0 ? void 0 : picked.ground) {
2161
2320
  return { point: picked.point, up: upAt(state, picked.point) };
2162
2321
  }
2163
- if (!globeShown(state)) {
2164
- return null;
2165
- }
2166
2322
  const ellipsoid = ellipsoidOf(state);
2167
2323
  const end = Cartesian3.add(from, step, new Cartesian3());
2168
2324
  const carto = ellipsoid.cartesianToCartographic(end);
2169
2325
  if (!carto) {
2170
2326
  return null;
2171
2327
  }
2172
- const height = (_b = (_a = terrainHeightAt(state, carto)) !== null && _a !== void 0 ? _a : terrainHeightAt(state, ellipsoid.cartesianToCartographic(from))) !== null && _b !== void 0 ? _b : 0;
2328
+ // Unloaded terrain counts as sea level; an unknown stand-in tileset counts as nothing.
2329
+ const height = (_b = (_a = groundHeightAt(state, carto)) !== null && _a !== void 0 ? _a : groundHeightAt(state, ellipsoid.cartesianToCartographic(from))) !== null && _b !== void 0 ? _b : (globeShown(state) ? 0 : null);
2330
+ if (height == null) {
2331
+ return null;
2332
+ }
2173
2333
  const point = Cartesian3.fromRadians(carto.longitude, carto.latitude, height, ellipsoid);
2174
2334
  return { point, up: ellipsoid.geodeticSurfaceNormal(point, new Cartesian3()) };
2175
2335
  }
@@ -2219,12 +2379,77 @@ function resistDescent(state, from, step, picked, notches) {
2219
2379
  const needed = scanScene(state).undergroundData ? PUSH_NOTCHES_DATA_BELOW : PUSH_NOTCHES_NOTHING_BELOW;
2220
2380
  if (state.push.notches >= needed) {
2221
2381
  state.push.notches = 0;
2382
+ state.surface = { above: false, through: true, until: now + SURFACE_HOLD_MS, at: null };
2222
2383
  // A shallow push would land far along the ground to get under it, so it goes no further than a usual step.
2223
2384
  const through = Math.min((above + GROUND_BREAK_DEPTH) / sink, Math.max(length, (above + GROUND_BREAK_DEPTH) * 4));
2224
2385
  return Cartesian3.multiplyByScalar(unit, through, new Cartesian3());
2225
2386
  }
2226
2387
  return Cartesian3.multiplyByScalar(unit, toStandOff, new Cartesian3());
2227
2388
  }
2389
+ /*
2390
+ * The camera's height above the loaded ground under it, or undefined without ground or in model-space.
2391
+ */
2392
+ function heightAboveGround(state) {
2393
+ if (state.getModelSpaceFrame || !hasGround(state)) {
2394
+ return undefined;
2395
+ }
2396
+ const carto = ellipsoidOf(state).cartesianToCartographic(state.viewer.camera.positionWC);
2397
+ const ground = carto ? groundHeightAt(state, carto) : undefined;
2398
+ return ground == null ? undefined : carto.height - ground;
2399
+ }
2400
+ /*
2401
+ * Notes whether the camera is above the ground as a zoom begins, unless it is being pushed through it.
2402
+ */
2403
+ function holdSurface(state) {
2404
+ var _a;
2405
+ const now = Date.now();
2406
+ if (state.surface.through && now < state.surface.until) {
2407
+ return;
2408
+ }
2409
+ const at = Cartesian3.clone(state.viewer.camera.positionWC);
2410
+ // Ground not loaded yet counts as sea level, as it does for a descent.
2411
+ const above = (_a = heightAboveGround(state)) !== null && _a !== void 0 ? _a : (hasGround(state) && !state.getModelSpaceFrame ? heightOf(state, at) : undefined);
2412
+ state.surface = { above: above != null && above > 0, through: false, until: now + SURFACE_HOLD_MS, at };
2413
+ }
2414
+ /*
2415
+ * Lifts a camera a zoom kept above the ground back over finer ground that loads in higher.
2416
+ */
2417
+ function keepAboveGround(state) {
2418
+ const surface = state.surface;
2419
+ const now = Date.now();
2420
+ if (!surface.above || !state.ours || now > surface.until + SURFACE_LOADING_MS) {
2421
+ return;
2422
+ }
2423
+ // Ground that has finished loading does not move under a still camera.
2424
+ if (now > surface.until && !groundLoading(state)) {
2425
+ return;
2426
+ }
2427
+ const camera = state.viewer.camera;
2428
+ // A bookmark, fly-to or pan moved it since, which may mean to go below the ground.
2429
+ if (!surface.at || !Cartesian3.equalsEpsilon(camera.positionWC, surface.at, 0, 1e-3)) {
2430
+ surface.above = false;
2431
+ return;
2432
+ }
2433
+ const above = heightAboveGround(state);
2434
+ if (above == null || above >= GROUND_STANDOFF / 2) {
2435
+ return;
2436
+ }
2437
+ const ellipsoid = ellipsoidOf(state);
2438
+ const carto = ellipsoid.cartesianToCartographic(camera.positionWC);
2439
+ Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height - above + GROUND_STANDOFF, ellipsoid, camera.position);
2440
+ // What is left of the glide would take it straight back down.
2441
+ state.pendingZoom = new Cartesian3();
2442
+ surface.at = Cartesian3.clone(camera.position);
2443
+ state.viewer.scene.requestRender();
2444
+ }
2445
+ /*
2446
+ * Notes where a zoom just put the camera, so the ground hold can tell its moves from others.
2447
+ */
2448
+ function zoomMoved(state) {
2449
+ if (state.surface.at) {
2450
+ Cartesian3.clone(state.viewer.camera.positionWC, state.surface.at);
2451
+ }
2452
+ }
2228
2453
  /*
2229
2454
  * What the scene holds that the camera cares about, rescanned at most every couple of seconds.
2230
2455
  */
@@ -2235,7 +2460,7 @@ function scanScene(state) {
2235
2460
  return applyOverride(state, state.scan);
2236
2461
  }
2237
2462
  const scene = state.viewer.scene;
2238
- const found = { at: now, undergroundData: false, groundTileset: false };
2463
+ const found = { at: now, undergroundData: false, groundTileset: false, ground: null };
2239
2464
  // Seeing through the ground is turned on to look at what is under it.
2240
2465
  if ((_b = (_a = scene.globe) === null || _a === void 0 ? void 0 : _a.translucency) === null || _b === void 0 ? void 0 : _b.enabled) {
2241
2466
  found.undergroundData = true;
@@ -2252,6 +2477,7 @@ function scanScene(state) {
2252
2477
  }
2253
2478
  if (primitive[GROUND_TILESET_KEY]) {
2254
2479
  found.groundTileset = true;
2480
+ found.ground = primitive;
2255
2481
  return;
2256
2482
  }
2257
2483
  if (!found.undergroundData && reachesBelowGround(state, lowestPointOf(primitive))) {
@@ -62094,7 +62320,7 @@ var StyleUtils;
62094
62320
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
62095
62321
  })(StyleUtils || (StyleUtils = {}));
62096
62322
 
62097
- const VERSION = "7.9.3";
62323
+ const VERSION = "7.9.4";
62098
62324
  /**
62099
62325
  * Updates the environment instance used by bruce-cesium to one specified.
62100
62326
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.
@@ -62111,5 +62337,5 @@ const getENVIRONMENT = () => {
62111
62337
  return ENVIRONMENT;
62112
62338
  };
62113
62339
 
62114
- export { VERSION, setENVIRONMENT, getENVIRONMENT, ClusterItems, PointClustering, PointClusterSize, CesiumAnimatedInOut, DisplacedSurfacePrimitive, CesiumAnimatedProperty, isStyleChanged, isOutlineChanged$1 as isOutlineChanged, StyleEffective, EntityRenderEngine, EntityRenderEngineModel3d, EntityRenderEnginePoint, extractMetadataFromFileUrl, EntityRenderEnginePolygon, EntityRenderEnginePolyline, TextureFrameSeriesAnimator, TextureValueLabels, MenuItemCreator, MenuItemManager, MenuItemStyles, MenuItemStyleOverlay, CesiumParabola, EntityLabel, EntityLabelGroup, LiveCursor, SharedGetters, EntitySimulation, DataSourceStaticKmlManager, DataLabRenderManager, EntitiesIdsRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, AssemblyRenderManager, GoogleSearchRenderManager, RelationsRenderManager, RenderManager, TilesetArbRenderManager, TilesetCadRenderManager, TilesetEntitiesRenderManager, TilesetGooglePhotosRenderManager, TilesetOsmRenderManager, TilesetPointcloudRenderManager, TileRenderEngine, createTileset, TilesetRenderEngine, ViewRenderEngine, VisualRegisterCuller, VisualsRegister, XGridsRenderEngine, CesiumEntityStyler, DrawingUtils, EntityUtils, MeasureUtils, StyleUtils, CESIUM_INSPECTOR_KEY, CESIUM_TIMELINE_KEY, CESIUM_TIMELINE_LIVE_KEY, CESIUM_TIMELINE_LIVE_PADDING_KEY, CESIUM_TIMELINE_INTERVAL_KEY, CESIUM_MODEL_SPACE_KEY, CESIUM_MODEL_SPACE_POSITIONING_KEY, DEFAULT_LIVE_PADDING_SECONDS, DEFAULT_BRIGHTNESS_SHIFT, DEFAULT_LIGHT_INTENSITY, LIGHTING_SETTINGS_VERSION, LIGHT_INTENSITY_COMPENSATION, MAX_COMPENSATED_LIGHT_INTENSITY, ViewUtils, CesiumMapGrid, GltfGenerator, GltfGizmo, DeviceProfile, CesiumViewMonitor, CameraControls, FindGapSurfaces, ViewGroundArea, ViewerEventTracker, ViewerUtils, Draw3dPolygon, Draw3dPolyline, MeasureCreator, Walkthrough, WidgetControlViewBar, WidgetControlViewBarSearch, WidgetLeftPanelTab, WidgetLeftPanelTabBookmarks, WidgetLeftPanelTabDashboard, EMenuItemState, WidgetLeftPanelTabMenuItems, Widget, VIEWER_BOOKMARKS_WIDGET_KEY, WidgetBookmarks, WidgetBranding, ECursor, WidgetCursorBar, WidgetEmbeddedInfoView, WidgetInfoView, VIEWER_LEFT_PANEL_WIDGET_KEY, VIEWER_LEFT_PANEL_CSS_VAR_LEFT, CreateTabIconSvg, WidgetLeftPanel, WidgetNavCompass$$1 as WidgetNavCompass, VIEWER_VIEW_BAR_WIDGET_KEY, WidgetViewBar };
62340
+ export { VERSION, setENVIRONMENT, getENVIRONMENT, ClusterItems, PointClustering, PointClusterSize, CesiumAnimatedInOut, DisplacedSurfacePrimitive, CesiumAnimatedProperty, isStyleChanged, isOutlineChanged$1 as isOutlineChanged, StyleEffective, EntityRenderEngine, EntityRenderEngineModel3d, EntityRenderEnginePoint, extractMetadataFromFileUrl, EntityRenderEnginePolygon, EntityRenderEnginePolyline, TextureFrameSeriesAnimator, TextureValueLabels, MenuItemCreator, MenuItemManager, MenuItemStyles, MenuItemStyleOverlay, CesiumParabola, EntityLabel, EntityLabelGroup, LiveCursor, SharedGetters, EntitySimulation, DataSourceStaticKmlManager, DataLabRenderManager, EntitiesIdsRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, AssemblyRenderManager, GoogleSearchRenderManager, RelationsRenderManager, RenderManager, TilesetArbRenderManager, TilesetCadRenderManager, TilesetEntitiesRenderManager, TilesetGooglePhotosRenderManager, TilesetOsmRenderManager, TilesetPointcloudRenderManager, TileRenderEngine, createTileset, TilesetRenderEngine, ViewRenderEngine, VisualRegisterCuller, VisualsRegister, XGridsRenderEngine, CesiumEntityStyler, DrawingUtils, EntityUtils, MeasureUtils, StyleUtils, CESIUM_INSPECTOR_KEY, CESIUM_TIMELINE_KEY, CESIUM_TIMELINE_LIVE_KEY, CESIUM_TIMELINE_LIVE_PADDING_KEY, CESIUM_TIMELINE_INTERVAL_KEY, CESIUM_MODEL_SPACE_KEY, CESIUM_MODEL_SPACE_POSITIONING_KEY, DEFAULT_LIVE_PADDING_SECONDS, DEFAULT_BRIGHTNESS_SHIFT, DEFAULT_LIGHT_INTENSITY, LIGHTING_SETTINGS_VERSION, LIGHT_INTENSITY_COMPENSATION, MAX_COMPENSATED_LIGHT_INTENSITY, ViewUtils, CesiumMapGrid, GltfGenerator, GltfGizmo, DeviceProfile, CesiumViewMonitor, CameraControls, FindGapSurfaces, NearClearance, GrabPoint, ViewGroundArea, ViewerEventTracker, ViewerUtils, Draw3dPolygon, Draw3dPolyline, MeasureCreator, Walkthrough, WidgetControlViewBar, WidgetControlViewBarSearch, WidgetLeftPanelTab, WidgetLeftPanelTabBookmarks, WidgetLeftPanelTabDashboard, EMenuItemState, WidgetLeftPanelTabMenuItems, Widget, VIEWER_BOOKMARKS_WIDGET_KEY, WidgetBookmarks, WidgetBranding, ECursor, WidgetCursorBar, WidgetEmbeddedInfoView, WidgetInfoView, VIEWER_LEFT_PANEL_WIDGET_KEY, VIEWER_LEFT_PANEL_CSS_VAR_LEFT, CreateTabIconSvg, WidgetLeftPanel, WidgetNavCompass$$1 as WidgetNavCompass, VIEWER_VIEW_BAR_WIDGET_KEY, WidgetViewBar };
62115
62341
  //# sourceMappingURL=bruce-cesium.es5.js.map