bruce-cesium 7.7.7 → 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.
Files changed (51) hide show
  1. package/dist/bruce-cesium.es5.js +2649 -69
  2. package/dist/bruce-cesium.es5.js.map +1 -1
  3. package/dist/bruce-cesium.umd.js +2628 -66
  4. package/dist/bruce-cesium.umd.js.map +1 -1
  5. package/dist/lib/bruce-cesium.js +6 -1
  6. package/dist/lib/bruce-cesium.js.map +1 -1
  7. package/dist/lib/rendering/entity-render-engine-model3d.js +2 -2
  8. package/dist/lib/rendering/entity-render-engine-model3d.js.map +1 -1
  9. package/dist/lib/rendering/entity-render-engine-polygon.js +5 -4
  10. package/dist/lib/rendering/entity-render-engine-polygon.js.map +1 -1
  11. package/dist/lib/rendering/entity-render-engine-polyline.js +2 -1
  12. package/dist/lib/rendering/entity-render-engine-polyline.js.map +1 -1
  13. package/dist/lib/rendering/render-managers/common/entity-simulation.js +1 -1
  14. package/dist/lib/rendering/render-managers/common/entity-simulation.js.map +1 -1
  15. package/dist/lib/rendering/render-managers/tilesets/tileset-google-photos-render-manager.js +3 -0
  16. package/dist/lib/rendering/render-managers/tilesets/tileset-google-photos-render-manager.js.map +1 -1
  17. package/dist/lib/rendering/tileset-render-engine.js +47 -14
  18. package/dist/lib/rendering/tileset-render-engine.js.map +1 -1
  19. package/dist/lib/rendering/view-render-engine.js +30 -24
  20. package/dist/lib/rendering/view-render-engine.js.map +1 -1
  21. package/dist/lib/rendering/visuals-register.js +93 -8
  22. package/dist/lib/rendering/visuals-register.js.map +1 -1
  23. package/dist/lib/rendering/xgrids-render-engine.js +20 -3
  24. package/dist/lib/rendering/xgrids-render-engine.js.map +1 -1
  25. package/dist/lib/utils/cesium-map-grid.js +807 -0
  26. package/dist/lib/utils/cesium-map-grid.js.map +1 -0
  27. package/dist/lib/utils/device-profile.js +302 -0
  28. package/dist/lib/utils/device-profile.js.map +1 -0
  29. package/dist/lib/utils/gltf-generator.js +307 -0
  30. package/dist/lib/utils/gltf-generator.js.map +1 -0
  31. package/dist/lib/utils/gltf-gizmo.js +136 -0
  32. package/dist/lib/utils/gltf-gizmo.js.map +1 -0
  33. package/dist/lib/utils/view-utils.js +9 -0
  34. package/dist/lib/utils/view-utils.js.map +1 -1
  35. package/dist/lib/viewer/camera-controls.js +899 -0
  36. package/dist/lib/viewer/camera-controls.js.map +1 -0
  37. package/dist/lib/viewer/viewer-utils.js +9 -1
  38. package/dist/lib/viewer/viewer-utils.js.map +1 -1
  39. package/dist/types/bruce-cesium.d.ts +6 -1
  40. package/dist/types/rendering/tileset-render-engine.d.ts +10 -2
  41. package/dist/types/rendering/view-render-engine.d.ts +4 -0
  42. package/dist/types/rendering/visuals-register.d.ts +4 -0
  43. package/dist/types/rendering/xgrids-render-engine.d.ts +2 -0
  44. package/dist/types/utils/cesium-map-grid.d.ts +23 -0
  45. package/dist/types/utils/device-profile.d.ts +84 -0
  46. package/dist/types/utils/gltf-generator.d.ts +104 -0
  47. package/dist/types/utils/gltf-gizmo.d.ts +18 -0
  48. package/dist/types/utils/view-utils.d.ts +4 -0
  49. package/dist/types/viewer/camera-controls.d.ts +27 -0
  50. package/dist/types/viewer/viewer-utils.d.ts +1 -0
  51. package/package.json +3 -2
@@ -0,0 +1,899 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CameraControls = void 0;
4
+ const Cesium = require("cesium");
5
+ const CESIUM_CAMERA_CONTROLS_KEY = "_nextspace_camera_controls";
6
+ // How far a wheel notch or its drag equivalent moves the camera, as a share of the distance to what it points at.
7
+ const ZOOM_SHARE = 0.18;
8
+ // The distance a zoom step treats anything closer as, so the camera keeps moving through a surface instead of stalling.
9
+ const MIN_ZOOM_DISTANCE = 4;
10
+ // How far from the origin zooming out may take a model-space camera, beyond which the scene is a dot on a planet.
11
+ const MODEL_SPACE_MAX_RANGE = 250000;
12
+ // Above this height a geospatial scene is a planet, which CesiumJS's own controller navigates better.
13
+ const GEO_HANDOFF_HEIGHT = 15000;
14
+ // The furthest a depth pick is trusted from a camera close to the ground; further up the limit grows with height.
15
+ const PLAUSIBLE_PICK_FLOOR = 1000;
16
+ // Pixels of right drag that make one wheel notch.
17
+ const DRAG_PIXELS_PER_NOTCH = 40;
18
+ // Share of the outstanding wheel movement applied each animation frame.
19
+ const ZOOM_EASE = 0.35;
20
+ // A pan plane seen closer to edge on than this (sine of the angle) is swapped for one facing the camera.
21
+ const GRAZING_SINE = 0.12;
22
+ // Closest the view may get to straight up or down while orbiting, in radians, so the camera never flips over.
23
+ const ORBIT_POLE_MARGIN = Cesium.Math.toRadians(1);
24
+ // How far above the ground a camera coming down from above stops, until pushed on through.
25
+ const GROUND_STANDOFF = 2;
26
+ // Height above the ground within which a descent slows, so the ground is approached rather than hit.
27
+ const GROUND_APPROACH = 10;
28
+ // The slowest a descent gets near the ground, as a share of its usual speed.
29
+ const GROUND_APPROACH_FLOOR = 0.5;
30
+ // How far below the ground a push through it lands, so the camera is clearly under it.
31
+ const GROUND_BREAK_DEPTH = 1.5;
32
+ // Wheel notches of pushing at the ground that take the camera through it, with and without data found below it.
33
+ const PUSH_NOTCHES_DATA_BELOW = 3;
34
+ const PUSH_NOTCHES_NOTHING_BELOW = 10;
35
+ // Pushes further apart than this start counting again.
36
+ const PUSH_WINDOW_MS = 1200;
37
+ // How far below the ground something must reach to count as data underground, in metres.
38
+ const UNDERGROUND_MARGIN = 3;
39
+ // How long a scan of the scene for underground data and stand-in ground is trusted, in milliseconds.
40
+ const SCENE_SCAN_MS = 2000;
41
+ // The most entities one scan looks at, so a large scene is sampled rather than walked each time.
42
+ const SCENE_SCAN_ENTITIES = 3000;
43
+ // Zoom speed, as a share of the usual, toward a point that is a guess (nothing drawn there) or while terrain loads.
44
+ const ZOOM_GUESS_SHARE = 0.5;
45
+ const ZOOM_LOADING_SHARE = 0.7;
46
+ // The highest a camera zooms out to with the globe hidden, which CesiumJS's controller cannot navigate.
47
+ const HIDDEN_GLOBE_MAX_HEIGHT = 10000000;
48
+ // Marks a tileset that stands in for the globe, such as Google's photorealistic tiles.
49
+ const GROUND_TILESET_KEY = "_nextspace_camera_ground";
50
+ var EDrag;
51
+ (function (EDrag) {
52
+ EDrag["Pan"] = "pan";
53
+ EDrag["Orbit"] = "orbit";
54
+ EDrag["Zoom"] = "zoom";
55
+ })(EDrag || (EDrag = {}));
56
+ /**
57
+ * Mouse navigation that keeps moving near, through and below the ground, where CesiumJS's own controller stalls.
58
+ */
59
+ var CameraControls;
60
+ (function (CameraControls) {
61
+ /**
62
+ * Takes over mouse drag and wheel navigation close to the ground; CesiumJS keeps planet scale, pinch and look.
63
+ */
64
+ function Attach(viewer) {
65
+ var _a, _b, _c;
66
+ if (!viewer || viewer.isDestroyed() || viewer[CESIUM_CAMERA_CONTROLS_KEY]) {
67
+ return;
68
+ }
69
+ const scene = viewer.scene;
70
+ const controller = scene === null || scene === void 0 ? void 0 : scene.screenSpaceCameraController;
71
+ if (!controller || !scene.canvas || !scene.preUpdate) {
72
+ return;
73
+ }
74
+ const state = {
75
+ viewer,
76
+ getModelSpaceFrame: null,
77
+ drag: null,
78
+ touches: new Set(),
79
+ pendingZoom: new Cesium.Cartesian3(),
80
+ zoomFrame: null,
81
+ zoomPosition: null,
82
+ lastDistance: 100,
83
+ push: { notches: 0, at: 0 },
84
+ scan: null,
85
+ undergroundOverride: null,
86
+ saved: {
87
+ rotateEventTypes: controller.rotateEventTypes,
88
+ zoomEventTypes: controller.zoomEventTypes,
89
+ tiltEventTypes: controller.tiltEventTypes,
90
+ enableCollisionDetection: controller.enableCollisionDetection,
91
+ backFaceAlpha: (_b = (_a = scene.globe) === null || _a === void 0 ? void 0 : _a.translucency) === null || _b === void 0 ? void 0 : _b.backFaceAlpha,
92
+ showSkirts: (_c = scene.globe) === null || _c === void 0 ? void 0 : _c.showSkirts
93
+ },
94
+ ours: false,
95
+ removals: []
96
+ };
97
+ viewer[CESIUM_CAMERA_CONTROLS_KEY] = state;
98
+ // The camera may go below the ground; zooming slows near a surface, so it takes a deliberate push.
99
+ controller.enableCollisionDetection = false;
100
+ const canvas = scene.canvas;
101
+ const listen = (target, type, handler, options) => {
102
+ target.addEventListener(type, handler, options);
103
+ state.removals.push(() => target.removeEventListener(type, handler, options));
104
+ };
105
+ listen(canvas, "pointerdown", (e) => onPointerDown(state, e));
106
+ listen(window, "pointermove", (e) => onPointerMove(state, e));
107
+ listen(window, "pointerup", (e) => onPointerUp(state, e));
108
+ listen(window, "pointercancel", (e) => onPointerUp(state, e));
109
+ listen(canvas, "wheel", (e) => onWheel(state, e), { passive: true });
110
+ state.removals.push(scene.preUpdate.addEventListener(() => syncController(state)));
111
+ syncController(state);
112
+ scene.requestRender();
113
+ }
114
+ CameraControls.Attach = Attach;
115
+ /**
116
+ * Hands navigation back to CesiumJS's own camera controller, as it was before Attach.
117
+ */
118
+ function Detach(viewer) {
119
+ const state = viewer === null || viewer === void 0 ? void 0 : viewer[CESIUM_CAMERA_CONTROLS_KEY];
120
+ if (!state) {
121
+ return;
122
+ }
123
+ SetModelSpace(viewer, null);
124
+ viewer[CESIUM_CAMERA_CONTROLS_KEY] = null;
125
+ state.removals.forEach((removal) => removal());
126
+ state.removals = [];
127
+ if (state.zoomFrame != null) {
128
+ cancelAnimationFrame(state.zoomFrame);
129
+ }
130
+ if (viewer.isDestroyed()) {
131
+ return;
132
+ }
133
+ restoreCesiumGestures(state);
134
+ viewer.scene.screenSpaceCameraController.enableCollisionDetection = state.saved.enableCollisionDetection;
135
+ viewer.scene.requestRender();
136
+ }
137
+ CameraControls.Detach = Detach;
138
+ function IsAttached(viewer) {
139
+ return Boolean(viewer === null || viewer === void 0 ? void 0 : viewer[CESIUM_CAMERA_CONTROLS_KEY]);
140
+ }
141
+ CameraControls.IsAttached = IsAttached;
142
+ /**
143
+ * Marks a tileset as standing in for the globe (Google's photorealistic tiles), so the camera treats it as ground.
144
+ */
145
+ function SetGroundTileset(tileset, isGround) {
146
+ if (tileset) {
147
+ tileset[GROUND_TILESET_KEY] = isGround;
148
+ }
149
+ }
150
+ CameraControls.SetGroundTileset = SetGroundTileset;
151
+ /**
152
+ * Says whether the scene has data underground, which makes the ground easier to push through; null scans for it.
153
+ */
154
+ function SetUndergroundData(viewer, present) {
155
+ const state = viewer === null || viewer === void 0 ? void 0 : viewer[CESIUM_CAMERA_CONTROLS_KEY];
156
+ if (state) {
157
+ state.undergroundOverride = present;
158
+ }
159
+ }
160
+ CameraControls.SetUndergroundData = SetUndergroundData;
161
+ /**
162
+ * Switches to navigating model-space measured from the frame getFrame returns, or back to geospatial with null.
163
+ */
164
+ function SetModelSpace(viewer, getFrame) {
165
+ const state = viewer === null || viewer === void 0 ? void 0 : viewer[CESIUM_CAMERA_CONTROLS_KEY];
166
+ if (!state || viewer.isDestroyed()) {
167
+ return;
168
+ }
169
+ const wasModelSpace = Boolean(state.getModelSpaceFrame);
170
+ state.getModelSpaceFrame = getFrame !== null && getFrame !== void 0 ? getFrame : null;
171
+ syncController(state);
172
+ if (wasModelSpace === Boolean(getFrame)) {
173
+ return;
174
+ }
175
+ const globe = viewer.scene.globe;
176
+ const translucency = globe === null || globe === void 0 ? void 0 : globe.translucency;
177
+ if (getFrame) {
178
+ // The ground is see-through from below, so what stands on it stays in view underground.
179
+ if (translucency && typeof translucency.backFaceAlpha === "number") {
180
+ translucency.backFaceAlpha = 0.5;
181
+ }
182
+ // Skirts hide seams flat model-space ground never has, and below it they are walls.
183
+ if (typeof state.saved.showSkirts === "boolean") {
184
+ globe.showSkirts = false;
185
+ }
186
+ }
187
+ else {
188
+ if (translucency && typeof state.saved.backFaceAlpha === "number") {
189
+ translucency.backFaceAlpha = state.saved.backFaceAlpha;
190
+ }
191
+ if (typeof state.saved.showSkirts === "boolean") {
192
+ globe.showSkirts = state.saved.showSkirts;
193
+ }
194
+ }
195
+ viewer.scene.requestRender();
196
+ }
197
+ CameraControls.SetModelSpace = SetModelSpace;
198
+ })(CameraControls = exports.CameraControls || (exports.CameraControls = {}));
199
+ function restoreCesiumGestures(state) {
200
+ const controller = state.viewer.scene.screenSpaceCameraController;
201
+ controller.rotateEventTypes = state.saved.rotateEventTypes;
202
+ controller.zoomEventTypes = state.saved.zoomEventTypes;
203
+ controller.tiltEventTypes = state.saved.tiltEventTypes;
204
+ }
205
+ /*
206
+ * Decides each frame who has the mouse: these controls near the ground, CesiumJS for planets, orthographic and tracking.
207
+ */
208
+ function syncController(state) {
209
+ const viewer = state.viewer;
210
+ if (viewer.isDestroyed() || state.drag) {
211
+ return;
212
+ }
213
+ const ours = shouldControl(state);
214
+ if (ours === state.ours) {
215
+ return;
216
+ }
217
+ state.ours = ours;
218
+ if (ours) {
219
+ const controller = viewer.scene.screenSpaceCameraController;
220
+ controller.rotateEventTypes = [];
221
+ controller.zoomEventTypes = [Cesium.CameraEventType.PINCH];
222
+ controller.tiltEventTypes = [Cesium.CameraEventType.PINCH];
223
+ }
224
+ else {
225
+ restoreCesiumGestures(state);
226
+ }
227
+ }
228
+ function shouldControl(state) {
229
+ const viewer = state.viewer;
230
+ const camera = viewer.camera;
231
+ if (viewer.scene.mode !== Cesium.SceneMode.SCENE3D || camera.frustum instanceof Cesium.OrthographicFrustum) {
232
+ return false;
233
+ }
234
+ // A camera following something is CesiumJS's to move.
235
+ if (!Cesium.Matrix4.equals(camera.transform, Cesium.Matrix4.IDENTITY)) {
236
+ return false;
237
+ }
238
+ if (state.getModelSpaceFrame) {
239
+ return true;
240
+ }
241
+ // CesiumJS's controller measures against the globe, so with it hidden these controls keep the camera at any height.
242
+ if (!globeShown(state)) {
243
+ return true;
244
+ }
245
+ return heightOf(state, camera.positionWC) < GEO_HANDOFF_HEIGHT;
246
+ }
247
+ function globeShown(state) {
248
+ const globe = state.viewer.scene.globe;
249
+ return Boolean(globe) && globe.show !== false;
250
+ }
251
+ /*
252
+ * The terrain's height at a place from the tiles loaded, undefined with the globe hidden or nothing loaded there.
253
+ */
254
+ function terrainHeightAt(state, carto) {
255
+ const globe = state.viewer.scene.globe;
256
+ if (!carto || !globeShown(state) || typeof globe.getHeight !== "function") {
257
+ return undefined;
258
+ }
259
+ const height = globe.getHeight(carto);
260
+ return Number.isFinite(height) ? height : undefined;
261
+ }
262
+ function ellipsoidOf(state) {
263
+ var _a, _b;
264
+ return (_b = (_a = state.viewer.scene.globe) === null || _a === void 0 ? void 0 : _a.ellipsoid) !== null && _b !== void 0 ? _b : Cesium.Ellipsoid.WGS84;
265
+ }
266
+ function heightOf(state, position) {
267
+ const carto = ellipsoidOf(state).cartesianToCartographic(position);
268
+ return carto ? carto.height : Number.POSITIVE_INFINITY;
269
+ }
270
+ function canvasPosition(viewer, e) {
271
+ const rect = viewer.scene.canvas.getBoundingClientRect();
272
+ return new Cesium.Cartesian2(e.clientX - rect.left, e.clientY - rect.top);
273
+ }
274
+ /*
275
+ * Up at a point: the model-space frame's up in model-space, else the ellipsoid's surface normal there.
276
+ */
277
+ function upAt(state, position) {
278
+ if (state.getModelSpaceFrame) {
279
+ const up = Cesium.Matrix4.multiplyByPointAsVector(state.getModelSpaceFrame(), Cesium.Cartesian3.UNIT_Z, new Cesium.Cartesian3());
280
+ return Cesium.Cartesian3.normalize(up, up);
281
+ }
282
+ return ellipsoidOf(state).geodeticSurfaceNormal(position, new Cesium.Cartesian3());
283
+ }
284
+ /*
285
+ * The level plane standing in for the ground when nothing is drawn under the cursor.
286
+ */
287
+ function groundPlane(state) {
288
+ var _a;
289
+ if (state.getModelSpaceFrame) {
290
+ const frame = state.getModelSpaceFrame();
291
+ return Cesium.Plane.fromPointNormal(Cesium.Matrix4.getTranslation(frame, new Cesium.Cartesian3()), upAt(state, null));
292
+ }
293
+ const camera = state.viewer.camera;
294
+ const ellipsoid = ellipsoidOf(state);
295
+ const carto = ellipsoid.cartesianToCartographic(camera.positionWC);
296
+ if (!carto) {
297
+ return null;
298
+ }
299
+ // Level with the terrain under the camera, not sea level, so a guess over high ground is not far too deep.
300
+ const surface = Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, (_a = terrainHeightAt(state, carto)) !== null && _a !== void 0 ? _a : 0, ellipsoid);
301
+ return Cesium.Plane.fromPointNormal(surface, ellipsoid.geodeticSurfaceNormal(surface, new Cesium.Cartesian3()));
302
+ }
303
+ /*
304
+ * How far away a depth pick is believable, since below ground the depth buffer can hold the globe's inside.
305
+ */
306
+ function plausibleDistance(state) {
307
+ const camera = state.viewer.camera;
308
+ if (state.getModelSpaceFrame) {
309
+ const origin = Cesium.Matrix4.getTranslation(state.getModelSpaceFrame(), new Cesium.Cartesian3());
310
+ return Math.max(PLAUSIBLE_PICK_FLOOR, Cesium.Cartesian3.distance(camera.positionWC, origin) * 10);
311
+ }
312
+ const height = Math.abs(heightOf(state, camera.positionWC) - (Number(state.viewer.scene.globeHeight) || 0));
313
+ const horizon = Math.sqrt(2 * ellipsoidOf(state).maximumRadius * Math.max(height, 0));
314
+ return Math.max(PLAUSIBLE_PICK_FLOOR, height * 10, horizon * 1.5);
315
+ }
316
+ /*
317
+ * The point under a screen position: what is drawn there, else the ground plane, else a point at the last distance.
318
+ */
319
+ function pickTarget(state, position) {
320
+ const viewer = state.viewer;
321
+ const scene = viewer.scene;
322
+ const camera = viewer.camera;
323
+ const ray = camera.getPickRay(position);
324
+ if (!ray) {
325
+ return null;
326
+ }
327
+ let picked;
328
+ if (scene.pickPositionSupported) {
329
+ try {
330
+ picked = scene.pickPosition(position);
331
+ }
332
+ catch (e) {
333
+ picked = null;
334
+ }
335
+ }
336
+ const plausible = plausibleDistance(state);
337
+ if (isAhead(camera, picked) && Cesium.Cartesian3.distance(picked, camera.positionWC) < plausible) {
338
+ return { point: picked, source: "pick", ground: isGroundPick(state, position) };
339
+ }
340
+ const ground = groundPlane(state);
341
+ const onGround = ground ? Cesium.IntersectionTests.rayPlane(ray, ground) : null;
342
+ if (isAhead(camera, onGround) && Cesium.Cartesian3.distance(onGround, camera.positionWC) < plausible) {
343
+ // The plane stands in for the ground only where there is ground to stand in for.
344
+ return { point: onGround, source: "plane", ground: !state.getModelSpaceFrame && hasGround(state) };
345
+ }
346
+ return { point: Cesium.Ray.getPoint(ray, state.lastDistance), source: "last", ground: false };
347
+ }
348
+ /*
349
+ * Whether what is drawn under a screen position is the ground: the globe, or a tileset standing in for it.
350
+ */
351
+ function isGroundPick(state, position) {
352
+ var _a, _b, _c;
353
+ if (state.getModelSpaceFrame) {
354
+ return false;
355
+ }
356
+ const scene = state.viewer.scene;
357
+ let picked;
358
+ try {
359
+ picked = typeof scene.pick === "function" ? scene.pick(position) : undefined;
360
+ }
361
+ catch (e) {
362
+ picked = undefined;
363
+ }
364
+ if (!picked) {
365
+ // Nothing pickable means the globe, when it is drawn.
366
+ return globeShown(state);
367
+ }
368
+ 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;
369
+ return Boolean(tileset === null || tileset === void 0 ? void 0 : tileset[GROUND_TILESET_KEY]);
370
+ }
371
+ /*
372
+ * Whether there is ground to come down onto: the globe drawn, or a tileset standing in for it.
373
+ */
374
+ function hasGround(state) {
375
+ return globeShown(state) || scanScene(state).groundTileset;
376
+ }
377
+ function isAhead(camera, point) {
378
+ if (!point || !Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z)) {
379
+ return false;
380
+ }
381
+ const toPoint = Cesium.Cartesian3.subtract(point, camera.positionWC, new Cesium.Cartesian3());
382
+ return Cesium.Cartesian3.dot(toPoint, camera.directionWC) > 0;
383
+ }
384
+ /*
385
+ * Picks which gesture a button and its modifiers start, matching CesiumJS's own mapping.
386
+ */
387
+ function dragKind(e) {
388
+ if (e.shiftKey) {
389
+ // Shift drag looks around, which CesiumJS still handles.
390
+ return null;
391
+ }
392
+ if (e.button === 1 || (e.ctrlKey && (e.button === 0 || e.button === 2))) {
393
+ return EDrag.Orbit;
394
+ }
395
+ if (e.button === 0) {
396
+ return EDrag.Pan;
397
+ }
398
+ if (e.button === 2) {
399
+ return EDrag.Zoom;
400
+ }
401
+ return null;
402
+ }
403
+ function allows(state, kind) {
404
+ const controller = state.viewer.scene.screenSpaceCameraController;
405
+ if (!controller.enableInputs) {
406
+ return false;
407
+ }
408
+ switch (kind) {
409
+ case EDrag.Pan:
410
+ return controller.enableRotate;
411
+ case EDrag.Orbit:
412
+ return controller.enableTilt;
413
+ case EDrag.Zoom:
414
+ return controller.enableZoom;
415
+ }
416
+ return false;
417
+ }
418
+ function onPointerDown(state, e) {
419
+ const viewer = state.viewer;
420
+ if (viewer.isDestroyed() || !state.ours) {
421
+ return;
422
+ }
423
+ if (e.pointerType === "touch") {
424
+ state.touches.add(e.pointerId);
425
+ // A second finger makes it a pinch, which CesiumJS handles.
426
+ if (state.touches.size > 1) {
427
+ endDrag(state);
428
+ return;
429
+ }
430
+ }
431
+ const kind = dragKind(e);
432
+ if (!kind || !allows(state, kind)) {
433
+ return;
434
+ }
435
+ const position = canvasPosition(viewer, e);
436
+ const picked = pickTarget(state, position);
437
+ if (!picked) {
438
+ return;
439
+ }
440
+ const target = picked.point;
441
+ const camera = viewer.camera;
442
+ const distance = Cesium.Cartesian3.distance(camera.positionWC, target);
443
+ state.lastDistance = Math.max(distance, MIN_ZOOM_DISTANCE);
444
+ const drag = { kind, pointerId: e.pointerId, last: position, target, up: upAt(state, target), distance, picked };
445
+ if (kind === EDrag.Pan) {
446
+ drag.plane = panPlane(camera, target, drag.up);
447
+ }
448
+ else if (kind === EDrag.Zoom) {
449
+ drag.direction = Cesium.Cartesian3.normalize(Cesium.Cartesian3.subtract(target, camera.positionWC, new Cesium.Cartesian3()), new Cesium.Cartesian3());
450
+ }
451
+ state.drag = drag;
452
+ }
453
+ /*
454
+ * A level plane through the grabbed point, or one facing the camera when the level one is seen edge on.
455
+ */
456
+ function panPlane(camera, target, up) {
457
+ if (Math.abs(Cesium.Cartesian3.dot(camera.directionWC, up)) > GRAZING_SINE) {
458
+ return Cesium.Plane.fromPointNormal(target, up);
459
+ }
460
+ return Cesium.Plane.fromPointNormal(target, Cesium.Cartesian3.negate(camera.directionWC, new Cesium.Cartesian3()));
461
+ }
462
+ function onPointerMove(state, e) {
463
+ const drag = state.drag;
464
+ const viewer = state.viewer;
465
+ if (!drag || drag.pointerId !== e.pointerId || viewer.isDestroyed()) {
466
+ return;
467
+ }
468
+ if (!allows(state, drag.kind)) {
469
+ endDrag(state);
470
+ return;
471
+ }
472
+ const position = canvasPosition(viewer, e);
473
+ const dx = position.x - drag.last.x;
474
+ const dy = position.y - drag.last.y;
475
+ if (dx === 0 && dy === 0) {
476
+ return;
477
+ }
478
+ switch (drag.kind) {
479
+ case EDrag.Pan:
480
+ pan(state, drag, position);
481
+ break;
482
+ case EDrag.Orbit:
483
+ orbit(state, drag, dx, dy);
484
+ break;
485
+ case EDrag.Zoom:
486
+ // Dragging down zooms in, as it does in CesiumJS.
487
+ moveAlong(state, drag.direction, drag.picked, dy / DRAG_PIXELS_PER_NOTCH);
488
+ break;
489
+ }
490
+ drag.last = position;
491
+ viewer.scene.requestRender();
492
+ }
493
+ function onPointerUp(state, e) {
494
+ var _a;
495
+ state.touches.delete(e.pointerId);
496
+ if (((_a = state.drag) === null || _a === void 0 ? void 0 : _a.pointerId) === e.pointerId) {
497
+ endDrag(state);
498
+ }
499
+ }
500
+ function endDrag(state) {
501
+ state.drag = null;
502
+ }
503
+ /*
504
+ * Slides the camera so the grabbed point stays under the cursor.
505
+ */
506
+ function pan(state, drag, position) {
507
+ const camera = state.viewer.camera;
508
+ const ray = camera.getPickRay(position);
509
+ const hit = ray ? Cesium.IntersectionTests.rayPlane(ray, drag.plane) : null;
510
+ if (!isAhead(camera, hit)) {
511
+ return;
512
+ }
513
+ const delta = Cesium.Cartesian3.subtract(drag.target, hit, new Cesium.Cartesian3());
514
+ // Near the horizon a pixel covers kilometres, so one move is capped at a few times the grab distance.
515
+ const limit = Math.max(drag.distance, MIN_ZOOM_DISTANCE) * 3;
516
+ const length = Cesium.Cartesian3.magnitude(delta);
517
+ if (length > limit) {
518
+ Cesium.Cartesian3.multiplyByScalar(delta, limit / length, delta);
519
+ }
520
+ // A pan never takes a camera above the ground down through it; it keeps the sideways part of the move.
521
+ if (wouldSinkBelowGround(state, camera.position, delta)) {
522
+ const up = upAt(state, camera.position);
523
+ const down = Cesium.Cartesian3.dot(delta, up);
524
+ if (down < 0) {
525
+ Cesium.Cartesian3.subtract(delta, Cesium.Cartesian3.multiplyByScalar(up, down, new Cesium.Cartesian3()), delta);
526
+ }
527
+ }
528
+ Cesium.Cartesian3.add(camera.position, delta, camera.position);
529
+ }
530
+ /*
531
+ * Turns the camera around the grabbed point: sideways about up there, and up or down about the camera's right.
532
+ */
533
+ function orbit(state, drag, dx, dy) {
534
+ const viewer = state.viewer;
535
+ const camera = viewer.camera;
536
+ const canvas = viewer.scene.canvas;
537
+ const up = drag.up;
538
+ const heading = -dx / Math.max(canvas.clientWidth, 1) * Math.PI * 2;
539
+ // Dragging down looks further down, as CesiumJS's own tilt does.
540
+ let pitch = -dy / Math.max(canvas.clientHeight, 1) * Math.PI;
541
+ // Keeps the view from tipping past straight up or down, where it would flip over.
542
+ const elevation = Math.asin(Cesium.Math.clamp(Cesium.Cartesian3.dot(camera.direction, up), -1, 1));
543
+ const limit = Math.PI / 2 - ORBIT_POLE_MARGIN;
544
+ pitch = Cesium.Math.clamp(elevation + pitch, -limit, limit) - elevation;
545
+ rotateAbout(camera, drag.target, up, heading);
546
+ const right = Cesium.Cartesian3.cross(camera.direction, up, new Cesium.Cartesian3());
547
+ if (Cesium.Cartesian3.magnitude(right) > Cesium.Math.EPSILON6) {
548
+ Cesium.Cartesian3.normalize(right, right);
549
+ const before = Cesium.Cartesian3.clone(camera.position);
550
+ rotateAbout(camera, drag.target, right, pitch);
551
+ // Orbiting does not swing a camera above the ground down through it; the tilt that would is undone.
552
+ const moved = Cesium.Cartesian3.subtract(camera.position, before, new Cesium.Cartesian3());
553
+ if (wouldSinkBelowGround(state, before, moved)) {
554
+ rotateAbout(camera, drag.target, right, -pitch);
555
+ }
556
+ }
557
+ levelCamera(camera, upAt(state, camera.position));
558
+ }
559
+ function rotateAbout(camera, pivot, axis, angle) {
560
+ if (!angle) {
561
+ return;
562
+ }
563
+ const rotation = Cesium.Matrix3.fromQuaternion(Cesium.Quaternion.fromAxisAngle(axis, angle));
564
+ const offset = Cesium.Cartesian3.subtract(camera.position, pivot, new Cesium.Cartesian3());
565
+ Cesium.Matrix3.multiplyByVector(rotation, offset, offset);
566
+ Cesium.Cartesian3.add(pivot, offset, camera.position);
567
+ Cesium.Matrix3.multiplyByVector(rotation, camera.direction, camera.direction);
568
+ Cesium.Matrix3.multiplyByVector(rotation, camera.up, camera.up);
569
+ Cesium.Matrix3.multiplyByVector(rotation, camera.right, camera.right);
570
+ }
571
+ /*
572
+ * Takes any roll out, so the horizon stays level however the camera has turned.
573
+ */
574
+ function levelCamera(camera, up) {
575
+ const direction = Cesium.Cartesian3.normalize(camera.direction, camera.direction);
576
+ const right = Cesium.Cartesian3.cross(direction, up, new Cesium.Cartesian3());
577
+ if (Cesium.Cartesian3.magnitude(right) < Cesium.Math.EPSILON6) {
578
+ return;
579
+ }
580
+ Cesium.Cartesian3.normalize(right, camera.right);
581
+ Cesium.Cartesian3.cross(camera.right, direction, camera.up);
582
+ Cesium.Cartesian3.normalize(camera.up, camera.up);
583
+ }
584
+ function onWheel(state, e) {
585
+ const viewer = state.viewer;
586
+ if (viewer.isDestroyed() || !state.ours || !allows(state, EDrag.Zoom)) {
587
+ return;
588
+ }
589
+ let notches = e.deltaMode === 1 ? e.deltaY / 3 : e.deltaMode === 2 ? e.deltaY : e.deltaY / 100;
590
+ notches = Cesium.Math.clamp(-notches, -3, 3);
591
+ if (!notches) {
592
+ return;
593
+ }
594
+ const position = canvasPosition(viewer, e);
595
+ const camera = viewer.camera;
596
+ const target = pickTarget(state, position);
597
+ const ray = camera.getPickRay(position);
598
+ if (!target || !ray) {
599
+ return;
600
+ }
601
+ const step = zoomStep(state, ray.direction, target, notches);
602
+ Cesium.Cartesian3.add(state.pendingZoom, step, state.pendingZoom);
603
+ state.zoomPosition = Cesium.Cartesian3.clone(camera.position);
604
+ if (state.zoomFrame == null) {
605
+ state.zoomFrame = requestAnimationFrame(() => easeZoom(state));
606
+ }
607
+ }
608
+ /*
609
+ * Applies part of the outstanding wheel movement each frame, so a notch glides rather than jumps.
610
+ */
611
+ function easeZoom(state) {
612
+ state.zoomFrame = null;
613
+ const viewer = state.viewer;
614
+ if (viewer.isDestroyed() || !viewer[CESIUM_CAMERA_CONTROLS_KEY]) {
615
+ return;
616
+ }
617
+ // A tool locking the camera mid glide (walkthrough, a camera lock) owns it from then on.
618
+ if (!allows(state, EDrag.Zoom) ||
619
+ !state.zoomPosition ||
620
+ !Cesium.Cartesian3.equalsEpsilon(viewer.camera.position, state.zoomPosition, 0, 1e-3)) {
621
+ state.pendingZoom = new Cesium.Cartesian3();
622
+ return;
623
+ }
624
+ const remaining = Cesium.Cartesian3.magnitude(state.pendingZoom);
625
+ const share = remaining < 0.01 ? 1 : ZOOM_EASE;
626
+ const step = Cesium.Cartesian3.multiplyByScalar(state.pendingZoom, share, new Cesium.Cartesian3());
627
+ Cesium.Cartesian3.subtract(state.pendingZoom, step, state.pendingZoom);
628
+ Cesium.Cartesian3.add(viewer.camera.position, step, viewer.camera.position);
629
+ state.zoomPosition = Cesium.Cartesian3.clone(viewer.camera.position);
630
+ viewer.scene.requestRender();
631
+ if (share < 1) {
632
+ state.zoomFrame = requestAnimationFrame(() => easeZoom(state));
633
+ }
634
+ }
635
+ function moveAlong(state, direction, target, notches) {
636
+ const step = zoomStep(state, direction, target, notches);
637
+ Cesium.Cartesian3.add(state.viewer.camera.position, step, state.viewer.camera.position);
638
+ }
639
+ /*
640
+ * The move for some notches toward a target along a direction, a share of the distance with a floor so it never stalls.
641
+ */
642
+ function zoomStep(state, direction, picked, notches) {
643
+ const camera = state.viewer.camera;
644
+ const target = picked.point;
645
+ // Where the camera will be once the glide already under way ends, which this step continues from.
646
+ const from = Cesium.Cartesian3.add(camera.positionWC, state.pendingZoom, new Cesium.Cartesian3());
647
+ const distance = Math.max(Cesium.Cartesian3.distance(from, target), MIN_ZOOM_DISTANCE);
648
+ state.lastDistance = distance;
649
+ let length = distance * ZOOM_SHARE * notches * zoomSpeedShare(state, picked);
650
+ // A geospatial camera zooming out hands over to CesiumJS once it is high enough, so only model-space is capped.
651
+ if (length < 0 && state.getModelSpaceFrame) {
652
+ const origin = Cesium.Matrix4.getTranslation(state.getModelSpaceFrame(), new Cesium.Cartesian3());
653
+ const range = Cesium.Cartesian3.distance(from, origin);
654
+ length = Math.max(length, range - MODEL_SPACE_MAX_RANGE);
655
+ if (length >= 0) {
656
+ return new Cesium.Cartesian3();
657
+ }
658
+ }
659
+ const unit = Cesium.Cartesian3.normalize(direction, new Cesium.Cartesian3());
660
+ // With the globe hidden there is no hand-over, so zooming out stops where the Earth is a dot.
661
+ if (length < 0 && !state.getModelSpaceFrame && !globeShown(state)) {
662
+ const rise = -Cesium.Cartesian3.dot(unit, upAt(state, from));
663
+ const headroom = HIDDEN_GLOBE_MAX_HEIGHT - heightOf(state, from);
664
+ if (rise > 0) {
665
+ length = Math.max(length, -Math.max(headroom, 0) / rise);
666
+ }
667
+ if (length >= 0) {
668
+ return new Cesium.Cartesian3();
669
+ }
670
+ }
671
+ const step = Cesium.Cartesian3.multiplyByScalar(unit, length, new Cesium.Cartesian3());
672
+ return length > 0 ? resistDescent(state, from, step, picked, notches) : step;
673
+ }
674
+ /*
675
+ * How fast to zoom toward a target: slower toward a guess, or while the terrain that would give a real one loads.
676
+ */
677
+ function zoomSpeedShare(state, picked) {
678
+ let share = 1;
679
+ if (picked.source !== "pick") {
680
+ share *= ZOOM_GUESS_SHARE;
681
+ }
682
+ const globe = state.viewer.scene.globe;
683
+ if (!state.getModelSpaceFrame && globeShown(state) && globe.tilesLoaded === false) {
684
+ share *= ZOOM_LOADING_SHARE;
685
+ }
686
+ return share;
687
+ }
688
+ /*
689
+ * The ground a move comes down onto: the ground picked, else the terrain under where the move ends; null for none.
690
+ */
691
+ function groundUnderMove(state, from, step, picked) {
692
+ var _a, _b;
693
+ if (state.getModelSpaceFrame || !hasGround(state)) {
694
+ return null;
695
+ }
696
+ if (picked === null || picked === void 0 ? void 0 : picked.ground) {
697
+ return { point: picked.point, up: upAt(state, picked.point) };
698
+ }
699
+ if (!globeShown(state)) {
700
+ return null;
701
+ }
702
+ const ellipsoid = ellipsoidOf(state);
703
+ const end = Cesium.Cartesian3.add(from, step, new Cesium.Cartesian3());
704
+ const carto = ellipsoid.cartesianToCartographic(end);
705
+ if (!carto) {
706
+ return null;
707
+ }
708
+ const height = (_b = (_a = terrainHeightAt(state, carto)) !== null && _a !== void 0 ? _a : terrainHeightAt(state, ellipsoid.cartesianToCartographic(from))) !== null && _b !== void 0 ? _b : 0;
709
+ const point = Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, height, ellipsoid);
710
+ return { point, up: ellipsoid.geodeticSurfaceNormal(point, new Cesium.Cartesian3()) };
711
+ }
712
+ /*
713
+ * Whether a move takes a camera that is above the ground to within the stand-off of it or below.
714
+ */
715
+ function wouldSinkBelowGround(state, from, step) {
716
+ const ground = groundUnderMove(state, from, step, null);
717
+ if (!ground) {
718
+ return false;
719
+ }
720
+ const before = Cesium.Cartesian3.dot(Cesium.Cartesian3.subtract(from, ground.point, new Cesium.Cartesian3()), ground.up);
721
+ const after = before + Cesium.Cartesian3.dot(step, ground.up);
722
+ return before > 0 && after < Math.min(GROUND_STANDOFF, before);
723
+ }
724
+ /*
725
+ * Slows a camera coming down from above as it nears the ground and stops it just above, until pushed on enough to
726
+ * pass through; harder when nothing is known to be underground. A camera already below the ground moves freely.
727
+ */
728
+ function resistDescent(state, from, step, picked, notches) {
729
+ const ground = groundUnderMove(state, from, step, picked);
730
+ const length = Cesium.Cartesian3.magnitude(step);
731
+ if (!ground || length === 0) {
732
+ return step;
733
+ }
734
+ const above = Cesium.Cartesian3.dot(Cesium.Cartesian3.subtract(from, ground.point, new Cesium.Cartesian3()), ground.up);
735
+ const unit = Cesium.Cartesian3.divideByScalar(step, length, new Cesium.Cartesian3());
736
+ const sink = -Cesium.Cartesian3.dot(unit, ground.up);
737
+ if (above <= 0 || sink <= 0) {
738
+ return step;
739
+ }
740
+ let allowed = length;
741
+ if (above < GROUND_APPROACH) {
742
+ allowed *= Math.max(above / GROUND_APPROACH, GROUND_APPROACH_FLOOR);
743
+ }
744
+ const toStandOff = Math.max(above - GROUND_STANDOFF, 0) / sink;
745
+ if (allowed <= toStandOff) {
746
+ return Cesium.Cartesian3.multiplyByScalar(unit, allowed, new Cesium.Cartesian3());
747
+ }
748
+ // Held at the stand-off: each push counts, and enough close together go through.
749
+ const now = Date.now();
750
+ if (now - state.push.at > PUSH_WINDOW_MS) {
751
+ state.push.notches = 0;
752
+ }
753
+ state.push.at = now;
754
+ state.push.notches += Math.abs(notches);
755
+ const needed = scanScene(state).undergroundData ? PUSH_NOTCHES_DATA_BELOW : PUSH_NOTCHES_NOTHING_BELOW;
756
+ if (state.push.notches >= needed) {
757
+ state.push.notches = 0;
758
+ // A shallow push would land far along the ground to get under it, so it goes no further than a usual step.
759
+ const through = Math.min((above + GROUND_BREAK_DEPTH) / sink, Math.max(length, (above + GROUND_BREAK_DEPTH) * 4));
760
+ return Cesium.Cartesian3.multiplyByScalar(unit, through, new Cesium.Cartesian3());
761
+ }
762
+ return Cesium.Cartesian3.multiplyByScalar(unit, toStandOff, new Cesium.Cartesian3());
763
+ }
764
+ /*
765
+ * What the scene holds that the camera cares about, rescanned at most every couple of seconds.
766
+ */
767
+ function scanScene(state) {
768
+ var _a, _b;
769
+ const now = Date.now();
770
+ if (state.scan && now - state.scan.at < SCENE_SCAN_MS) {
771
+ return applyOverride(state, state.scan);
772
+ }
773
+ const scene = state.viewer.scene;
774
+ const found = { at: now, undergroundData: false, groundTileset: false };
775
+ // Seeing through the ground is turned on to look at what is under it.
776
+ if ((_b = (_a = scene.globe) === null || _a === void 0 ? void 0 : _a.translucency) === null || _b === void 0 ? void 0 : _b.enabled) {
777
+ found.undergroundData = true;
778
+ }
779
+ const visit = (primitive) => {
780
+ if (!primitive || primitive.show === false || (primitive.isDestroyed && primitive.isDestroyed())) {
781
+ return;
782
+ }
783
+ if (typeof primitive.length === "number" && typeof primitive.get === "function") {
784
+ for (let i = 0; i < primitive.length; i++) {
785
+ visit(primitive.get(i));
786
+ }
787
+ return;
788
+ }
789
+ if (primitive[GROUND_TILESET_KEY]) {
790
+ found.groundTileset = true;
791
+ return;
792
+ }
793
+ if (!found.undergroundData && reachesBelowGround(state, lowestPointOf(primitive))) {
794
+ found.undergroundData = true;
795
+ }
796
+ };
797
+ visit(scene.primitives);
798
+ if (!found.undergroundData) {
799
+ found.undergroundData = entitiesBelowGround(state);
800
+ }
801
+ state.scan = found;
802
+ return applyOverride(state, found);
803
+ }
804
+ function applyOverride(state, found) {
805
+ return state.undergroundOverride == null ? found : { ...found, undergroundData: state.undergroundOverride };
806
+ }
807
+ /*
808
+ * The lowest point of a tileset or model: its root box's lowest corner, or its bounding sphere's centre.
809
+ */
810
+ function lowestPointOf(primitive) {
811
+ var _a, _b, _c;
812
+ const volume = (_a = primitive === null || primitive === void 0 ? void 0 : primitive.root) === null || _a === void 0 ? void 0 : _a.boundingVolume;
813
+ if (volume) {
814
+ const region = Number.isFinite(volume.minimumHeight) && volume.rectangle;
815
+ if (region) {
816
+ return Cesium.Cartesian3.fromRadians(Cesium.Rectangle.center(volume.rectangle).longitude, Cesium.Rectangle.center(volume.rectangle).latitude, volume.minimumHeight);
817
+ }
818
+ const box = volume.boundingVolume;
819
+ const corners = box instanceof Cesium.OrientedBoundingBox && typeof Cesium.OrientedBoundingBox.computeCorners === "function" ? Cesium.OrientedBoundingBox.computeCorners(box) : null;
820
+ if (corners === null || corners === void 0 ? void 0 : corners.length) {
821
+ return lowestOf(corners);
822
+ }
823
+ }
824
+ // A sphere's centre, as its radius reaches below the ground for anything standing on it.
825
+ 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;
826
+ }
827
+ function lowestOf(points) {
828
+ var _a, _b;
829
+ let lowest = null;
830
+ let lowestHeight = Number.POSITIVE_INFINITY;
831
+ for (const point of points) {
832
+ const height = (_b = (_a = Cesium.Cartographic.fromCartesian(point)) === null || _a === void 0 ? void 0 : _a.height) !== null && _b !== void 0 ? _b : Number.POSITIVE_INFINITY;
833
+ if (height < lowestHeight) {
834
+ lowestHeight = height;
835
+ lowest = point;
836
+ }
837
+ }
838
+ return lowest;
839
+ }
840
+ /*
841
+ * Whether a point is clearly below the ground at its place: the terrain there, else sea level.
842
+ */
843
+ function reachesBelowGround(state, point) {
844
+ var _a;
845
+ if (!point) {
846
+ return false;
847
+ }
848
+ const carto = ellipsoidOf(state).cartesianToCartographic(point);
849
+ if (!carto) {
850
+ return false;
851
+ }
852
+ return carto.height < ((_a = terrainHeightAt(state, carto)) !== null && _a !== void 0 ? _a : 0) - UNDERGROUND_MARGIN;
853
+ }
854
+ /*
855
+ * Whether any of the first entities sits clearly below the ground: a point, or a line's first or last vertex.
856
+ */
857
+ function entitiesBelowGround(state) {
858
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
859
+ const viewer = state.viewer;
860
+ const collections = [viewer.entities];
861
+ const sources = viewer.dataSources;
862
+ for (let i = 0; i < ((_a = sources === null || sources === void 0 ? void 0 : sources.length) !== null && _a !== void 0 ? _a : 0); i++) {
863
+ collections.push((_b = sources.get(i)) === null || _b === void 0 ? void 0 : _b.entities);
864
+ }
865
+ const time = (_d = (_c = viewer.clock) === null || _c === void 0 ? void 0 : _c.currentTime) !== null && _d !== void 0 ? _d : Cesium.JulianDate.now();
866
+ let seen = 0;
867
+ for (const collection of collections) {
868
+ for (const entity of (_e = collection === null || collection === void 0 ? void 0 : collection.values) !== null && _e !== void 0 ? _e : []) {
869
+ if (seen++ >= SCENE_SCAN_ENTITIES) {
870
+ return false;
871
+ }
872
+ if (!entity || entity.show === false) {
873
+ continue;
874
+ }
875
+ 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;
876
+ 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);
877
+ if (reference === Cesium.HeightReference.CLAMP_TO_GROUND) {
878
+ continue;
879
+ }
880
+ const position = (_o = (_m = entity.position) === null || _m === void 0 ? void 0 : _m.getValue) === null || _o === void 0 ? void 0 : _o.call(_m, time);
881
+ if (position) {
882
+ const relative = reference === Cesium.HeightReference.RELATIVE_TO_GROUND;
883
+ const height = relative ? (_p = ellipsoidOf(state).cartesianToCartographic(position)) === null || _p === void 0 ? void 0 : _p.height : null;
884
+ if (relative ? height < -UNDERGROUND_MARGIN : reachesBelowGround(state, position)) {
885
+ return true;
886
+ }
887
+ }
888
+ const line = entity.polyline;
889
+ if (line && !((_r = (_q = line.clampToGround) === null || _q === void 0 ? void 0 : _q.getValue) === null || _r === void 0 ? void 0 : _r.call(_q, time))) {
890
+ 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 : [];
891
+ if (positions.length && (reachesBelowGround(state, positions[0]) || reachesBelowGround(state, positions[positions.length - 1]))) {
892
+ return true;
893
+ }
894
+ }
895
+ }
896
+ }
897
+ return false;
898
+ }
899
+ //# sourceMappingURL=camera-controls.js.map