bruce-cesium 3.4.8 → 3.4.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.
@@ -81,463 +81,878 @@
81
81
  }
82
82
  }
83
83
 
84
+ var TIME_LAG = 300;
85
+ var POSITION_CHECK_TIMER = 950;
86
+ var DEFAULT_GROUNDED_HEIGHT = 300;
87
+ var MINIMUM_VIEW_AREA_SIZE_DEGREES = 0.01;
88
+ var NET_STEP_PERCENT = 5;
89
+ var BORDER_STEPS = 3;
90
+ var ESearchStatus;
91
+ (function (ESearchStatus) {
92
+ ESearchStatus[ESearchStatus["LocationFound"] = 1] = "LocationFound";
93
+ ESearchStatus[ESearchStatus["LocationChanged"] = 2] = "LocationChanged";
94
+ ESearchStatus[ESearchStatus["LocationMissing"] = 3] = "LocationMissing";
95
+ })(ESearchStatus || (ESearchStatus = {}));
84
96
  /**
85
- * Ensures a number is returned from a given value.
86
- * If given value cannot be parsed it will return defaultNum.
87
- * @param value
88
- * @param defaultNum default is 0.
97
+ * @param viewer
98
+ * @param center the previously calculated center of the view area. This is in degrees.
89
99
  * @returns
90
100
  */
91
- function EnsureNumber(value, defaultNum) {
92
- if (!defaultNum) {
93
- defaultNum = 0;
94
- }
95
- value = Number(value);
96
- if (isNaN(value)) {
97
- return defaultNum;
98
- }
99
- return value;
100
- }
101
-
102
- (function (MeasureUtils) {
103
- /**
104
- * Returns the total distance in meters between an array of points.
105
- * This distance is NOT following the terrain.
106
- * @param posses
107
- * @returns
108
- */
109
- function MeasurePolyline(params) {
110
- var posses = params.posses;
111
- if (posses.length < 2) {
112
- return {
113
- totalLength: 0
114
- };
101
+ function netScanViewForBoundaries(viewer, center) {
102
+ var maxLong = -2 * Math.PI;
103
+ var minLong = 2 * Math.PI;
104
+ var maxLat = -2 * Math.PI;
105
+ var minLat = 2 * Math.PI;
106
+ var found = 0;
107
+ var updateMinMax = function (lon, lat) {
108
+ // Check to see if given lon/lat (in radians) are within valid range.
109
+ if (lon < -Math.PI || lon > Math.PI || lat < -Math.PI / 2 || lat > Math.PI / 2) {
110
+ return;
115
111
  }
116
- var totalLength = 0;
117
- var pos1 = null;
118
- var pos2 = null;
119
- for (var i = 0; i < posses.length; i++) {
120
- if (pos1 == null) {
121
- pos1 = posses[i];
122
- }
123
- else if (pos2 == null) {
124
- pos2 = posses[i];
125
- totalLength += Cesium.Cartesian3.distance(pos1, pos2);
126
- pos1 = pos2;
127
- pos2 = null;
112
+ maxLong = Math.max(maxLong, lon);
113
+ maxLat = Math.max(maxLat, lat);
114
+ minLong = Math.min(minLong, lon);
115
+ minLat = Math.min(minLat, lat);
116
+ };
117
+ var updateMinMaxForPoint = function (stepX, stepY) {
118
+ var x = Math.round(0 + (viewer.container.clientWidth / 100) * (stepX * NET_STEP_PERCENT));
119
+ var y = Math.round(0 + (viewer.container.clientHeight / 100) * (stepY * NET_STEP_PERCENT));
120
+ var winPos = new Cesium.Cartesian2(x, y);
121
+ try {
122
+ var intersection = getAdjustedGroundIntersectionOfCameraRay(viewer, winPos);
123
+ if (intersection) {
124
+ var point = Cesium.Cartographic.fromCartesian(intersection, viewer.scene.globe.ellipsoid);
125
+ updateMinMax(point.longitude, point.latitude);
126
+ found++;
128
127
  }
129
128
  }
130
- return {
131
- totalLength: totalLength
132
- };
133
- }
134
- MeasureUtils.MeasurePolyline = MeasurePolyline;
135
- function MeasurePolygon(params) {
136
- var posses = params.posses;
137
- posses = [].concat(posses);
138
- if (!bruceModels.Cartes.IsRing3Closed(posses)) {
139
- posses.push(posses[0].clone());
129
+ catch (e) {
130
+ console.error(e);
140
131
  }
141
- if (posses.length < 3) {
142
- return {
143
- area: 0,
144
- perimeter: 0
145
- };
132
+ };
133
+ // Outer circle.
134
+ updateMinMaxForPoint(BORDER_STEPS, BORDER_STEPS);
135
+ updateMinMaxForPoint((100 / NET_STEP_PERCENT) - BORDER_STEPS, BORDER_STEPS);
136
+ updateMinMaxForPoint(BORDER_STEPS, (100 / NET_STEP_PERCENT) - BORDER_STEPS);
137
+ updateMinMaxForPoint((100 / NET_STEP_PERCENT) - BORDER_STEPS, (100 / NET_STEP_PERCENT) - BORDER_STEPS);
138
+ // Inner circle.
139
+ updateMinMaxForPoint(BORDER_STEPS * 2, BORDER_STEPS * 2);
140
+ updateMinMaxForPoint((100 / NET_STEP_PERCENT) - BORDER_STEPS * 2, BORDER_STEPS * 2);
141
+ updateMinMaxForPoint(BORDER_STEPS * 2, (100 / NET_STEP_PERCENT) - BORDER_STEPS * 2);
142
+ updateMinMaxForPoint((100 / NET_STEP_PERCENT) - BORDER_STEPS * 2, (100 / NET_STEP_PERCENT) - BORDER_STEPS * 2);
143
+ // If we failed to find intersections and a center-point was provided, then we can use that to make some guesses.
144
+ // This happens if terrain is hidden, and there's nothing to intersect with.
145
+ if (center && found <= 0) {
146
+ updateMinMax(Cesium.Math.toRadians(center.longitude), Cesium.Math.toRadians(center.latitude));
147
+ found += 1;
148
+ // We'll use the camera height as an indicator on size of the rect.
149
+ var size = viewer.camera.positionCartographic.height;
150
+ var pitch = viewer.camera.pitch;
151
+ var distance = size / Math.tan(pitch);
152
+ var p1 = _offsetPoint({
153
+ altitude: center.altitude,
154
+ latitude: center.latitude,
155
+ longitude: center.longitude
156
+ }, distance, 45);
157
+ var p2 = _offsetPoint({
158
+ altitude: center.altitude,
159
+ latitude: center.latitude,
160
+ longitude: center.longitude
161
+ }, -distance, 45);
162
+ if (p1 === null || p1 === void 0 ? void 0 : p1.latitude) {
163
+ updateMinMax(Cesium.Math.toRadians(p1.longitude), Cesium.Math.toRadians(p1.latitude));
146
164
  }
147
- var area = 0;
148
- var indices = Cesium.PolygonPipeline.triangulate(posses, []);
149
- for (var i = 0; i < indices.length; i += 3) {
150
- var vector1 = posses[indices[i]];
151
- var vector2 = posses[indices[i + 1]];
152
- var vector3 = posses[indices[i + 2]];
153
- var vectorC = Cesium.Cartesian3.subtract(vector2, vector1, new Cesium.Cartesian3());
154
- var vectorD = Cesium.Cartesian3.subtract(vector3, vector1, new Cesium.Cartesian3());
155
- var areaVector = Cesium.Cartesian3.cross(vectorC, vectorD, new Cesium.Cartesian3());
156
- area += Cesium.Cartesian3.magnitude(areaVector) / 2.0;
165
+ if (p2 === null || p2 === void 0 ? void 0 : p2.latitude) {
166
+ updateMinMax(Cesium.Math.toRadians(p2.longitude), Cesium.Math.toRadians(p2.latitude));
157
167
  }
158
- var perimeter = MeasurePolyline({
159
- posses: posses
160
- }).totalLength;
161
- return {
162
- area: area,
163
- perimeter: perimeter
168
+ }
169
+ if (found > 0) {
170
+ var viewRect = {
171
+ east: maxLong,
172
+ west: minLong,
173
+ north: maxLat,
174
+ south: minLat
164
175
  };
176
+ return viewRect;
165
177
  }
166
- MeasureUtils.MeasurePolygon = MeasurePolygon;
167
- })(exports.MeasureUtils || (exports.MeasureUtils = {}));
168
-
169
- var C3 = [Cesium.Cartesian3][0];
170
- function getT(t, alpha, p0, p1) {
171
- var d = C3.subtract(p1, p0, new C3);
172
- var a = C3.dot(d, d);
173
- var b = Math.pow(a, alpha * 0.5);
174
- return b + t;
178
+ return null;
175
179
  }
176
- function catmullRom(p0, p1, p2, p3, t) {
177
- var t0 = 0;
178
- var t1 = getT(t0, 0.5, p0, p1);
179
- var t2 = getT(t1, 0.5, p1, p2);
180
- var t3 = getT(t2, 0.5, p2, p3);
181
- t = Cesium.Math.lerp(t1, t2, t);
182
- var _a = [function (l, r) { return C3.add(l, r, new C3); }, function (l, r) { return C3.multiplyByScalar(l, r, new C3); }], add = _a[0], mul = _a[1];
183
- var A1 = add(mul(p0, (t1 - t) / (t1 - t0)), mul(p1, (t - t0) / (t1 - t0)));
184
- var A2 = add(mul(p1, (t2 - t) / (t2 - t1)), mul(p2, (t - t1) / (t2 - t1)));
185
- var A3 = add(mul(p2, (t3 - t) / (t3 - t2)), mul(p3, (t - t2) / (t3 - t2)));
186
- var B1 = add(mul(A1, (t2 - t) / (t2 - t0)), mul(A2, (t - t0) / (t2 - t0)));
187
- var B2 = add(mul(A2, (t3 - t) / (t3 - t1)), mul(A3, (t - t1) / (t3 - t1)));
188
- var C = add(mul(B1, (t2 - t) / (t2 - t1)), mul(B2, (t - t1) / (t2 - t1)));
189
- return C;
180
+ /**
181
+ * Moves a given point by a given distance towards a heading.
182
+ * @param point in degrees.
183
+ * @param distance in meters.
184
+ * @param heading in degrees.
185
+ * @returns
186
+ */
187
+ function _offsetPoint(point, distance, heading) {
188
+ // Radius of earth.
189
+ var radius = 6371e3;
190
+ var δ = distance / radius;
191
+ var θ = Cesium.Math.toRadians(heading);
192
+ var φ1 = Cesium.Math.toRadians(point.latitude);
193
+ var λ1 = Cesium.Math.toRadians(point.longitude);
194
+ var sinφ2 = Math.sin(φ1) * Math.cos(δ) + Math.cos(φ1) * Math.sin(δ) * Math.cos(θ);
195
+ var φ2 = Math.asin(sinφ2);
196
+ var y = Math.sin(θ) * Math.sin(δ) * Math.cos(φ1);
197
+ var x = Math.cos(δ) - Math.sin(φ1) * sinφ2;
198
+ var λ2 = λ1 + Math.atan2(y, x);
199
+ return {
200
+ altitude: point.altitude,
201
+ latitude: Cesium.Math.toDegrees(φ2),
202
+ longitude: Cesium.Math.toDegrees(λ2)
203
+ };
190
204
  }
191
- (function (DrawingUtils) {
192
- /**
193
- * Returns the point across a polyline at a given distance.
194
- * If the distance exceeds the length of the line, the point will be placed at the end of the line.
195
- * @param viewer
196
- * @param positions
197
- * @param distance
198
- * @returns
199
- */
200
- function PointAcrossPolyline(params) {
201
- var viewer = params.viewer, positions = params.posses, distance = params.distance;
202
- if (distance <= 0 && positions.length > 0) {
203
- return {
204
- point: positions[0]
205
- };
206
- }
207
- else if (positions.length > 1) {
208
- var currentDistance = 0;
209
- var totalLength = exports.MeasureUtils.MeasurePolyline({
210
- posses: positions,
211
- }).totalLength;
212
- if (distance > totalLength) {
213
- return {
214
- point: positions[positions.length - 1]
215
- };
216
- }
217
- for (var i = 0; i < positions.length - 1; i++) {
218
- var length_1 = Cesium.Cartesian3.distance(positions[i], positions[i + 1]);
219
- if (length_1 + currentDistance >= distance) {
220
- var carto1 = Cesium.Cartographic.fromCartesian(positions[i]);
221
- var carto2 = Cesium.Cartographic.fromCartesian(positions[i + 1]);
222
- var geodesic = new Cesium.EllipsoidGeodesic(carto1, carto2, viewer.scene.globe.ellipsoid);
223
- //const position = geodesic.interpolateUsingSurfaceDistance(distance - currentDistance);
224
- var position = geodesic.interpolateUsingFraction((distance - currentDistance) / length_1);
225
- var height = (carto1.height + carto2.height) / 2;
226
- return {
227
- point: Cesium.Cartesian3.fromRadians(position.longitude, position.latitude, height)
228
- };
229
- }
230
- else {
231
- currentDistance += length_1;
232
- }
233
- }
234
- }
235
- return {
236
- point: positions.length ? positions[positions.length - 1] : null
237
- };
238
- }
239
- DrawingUtils.PointAcrossPolyline = PointAcrossPolyline;
240
- /**
241
- * Returns terrain height from current viewer's provider.
242
- * On error or flat terrain, it will return 0.
243
- * If an error occurred it will be attached to the result.
244
- * @param pos3d
245
- * @param viewer
246
- * @returns
247
- */
248
- function GetTerrainHeight(params) {
249
- return __awaiter(this, void 0, void 0, function () {
250
- var pos3d, viewer, sample, height, e_1;
251
- return __generator(this, function (_a) {
252
- switch (_a.label) {
253
- case 0:
254
- pos3d = params.pos3d, viewer = params.viewer;
255
- _a.label = 1;
256
- case 1:
257
- _a.trys.push([1, 3, , 4]);
258
- // If the terrain provider is not ready let's not ping it.
259
- if (!viewer.terrainProvider || viewer.terrainProvider["ready"] == false) {
260
- return [2 /*return*/, {
261
- height: 0,
262
- error: "Terrain provider not ready."
263
- }];
264
- }
265
- if (viewer.scene.terrainProvider instanceof Cesium.EllipsoidTerrainProvider) {
266
- return [2 /*return*/, {
267
- height: 0
268
- }];
269
- }
270
- return [4 /*yield*/, Cesium.sampleTerrainMostDetailed(viewer.scene.terrainProvider, [Cesium.Cartographic.fromCartesian(pos3d)])];
271
- case 2:
272
- sample = _a.sent();
273
- height = (sample === null || sample === void 0 ? void 0 : sample.length) ? sample[0].height : null;
274
- if (isNaN(height)) {
275
- return [2 /*return*/, {
276
- height: 0,
277
- error: "NaN"
278
- }];
279
- }
280
- return [2 /*return*/, {
281
- height: height
282
- }];
283
- case 3:
284
- e_1 = _a.sent();
285
- return [2 /*return*/, {
286
- height: 0,
287
- error: e_1
288
- }];
289
- case 4: return [2 /*return*/];
290
- }
291
- });
292
- });
205
+ /**
206
+ * @param pos3d
207
+ * @param distance in meters
208
+ * @param heading in degrees
209
+ * @returns
210
+ */
211
+ function _offsetPos3d(pos3d, distance, heading) {
212
+ var carto = Cesium.Cartographic.fromCartesian(pos3d);
213
+ var newCarto = _offsetPoint({
214
+ altitude: carto.height,
215
+ latitude: Cesium.Math.toDegrees(carto.latitude),
216
+ longitude: Cesium.Math.toDegrees(carto.longitude)
217
+ }, distance, heading);
218
+ return Cesium.Cartesian3.fromDegrees(newCarto.longitude, newCarto.latitude, newCarto.altitude);
219
+ }
220
+ /**
221
+ * Returns the intersection of the camera ray with the ground.
222
+ * @param viewer
223
+ * @param screenPos
224
+ * @returns
225
+ */
226
+ function getAdjustedGroundIntersectionOfCameraRay(viewer, screenPos) {
227
+ var ray = viewer.camera.getPickRay(screenPos);
228
+ var intersection = ray ? viewer.scene.globe.pick(ray, viewer.scene) : null;
229
+ if (intersection) {
230
+ return intersection;
293
231
  }
294
- DrawingUtils.GetTerrainHeight = GetTerrainHeight;
295
- function EnsurePosHeight(params) {
296
- var pos3d = params.pos3d, viewer = params.viewer, desiredHeightRef = params.desiredHeightRef, heightRef = params.heightRef;
297
- var carto = bruceModels.Cartes.ValidateCartes3(pos3d) ? Cesium.Cartographic.fromCartesian(pos3d) : null;
298
- if (!(carto === null || carto === void 0 ? void 0 : carto.latitude)) {
299
- return pos3d;
300
- }
301
- if (heightRef == null) {
302
- heightRef = Cesium.HeightReference.CLAMP_TO_GROUND;
303
- }
304
- if (desiredHeightRef == null) {
305
- desiredHeightRef = Cesium.HeightReference.CLAMP_TO_GROUND;
306
- }
307
- if (heightRef == desiredHeightRef) {
308
- return pos3d;
309
- }
310
- if (heightRef == Cesium.HeightReference.NONE) {
311
- // Turn absolute into clamped.
312
- if (desiredHeightRef == Cesium.HeightReference.CLAMP_TO_GROUND) {
313
- return Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, 0);
314
- }
315
- // Turn absolute into relative (remove terrain height).
316
- else if (desiredHeightRef == Cesium.HeightReference.RELATIVE_TO_GROUND) {
317
- var terrainHeight = EnsureNumber(viewer.scene.globe.getHeight(carto), 0);
318
- return Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height - terrainHeight);
319
- }
320
- }
321
- else if (heightRef == Cesium.HeightReference.CLAMP_TO_GROUND) {
322
- var terrainHeight = EnsureNumber(viewer.scene.globe.getHeight(carto), 0);
323
- return Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, terrainHeight);
324
- }
325
- else if (heightRef == Cesium.HeightReference.RELATIVE_TO_GROUND) {
326
- // Turn relative into absolute (add terrain height).
327
- if (desiredHeightRef == Cesium.HeightReference.NONE) {
328
- var terrainHeight = EnsureNumber(viewer.scene.globe.getHeight(carto), 0);
329
- return Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height + terrainHeight);
330
- }
331
- // Turn relative into clamped.
332
- else if (desiredHeightRef == Cesium.HeightReference.CLAMP_TO_GROUND) {
333
- return Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, 0);
334
- }
335
- }
336
- return pos3d;
232
+ return null;
233
+ }
234
+ /**
235
+ * Returns the intersection of the camera ray with the ground.
236
+ * If no intersection is found, then a "guess" is made based on the camera angle and height.
237
+ * The guess is made at the center of the view! It ignores the screenPos.
238
+ * @param viewer
239
+ * @param screenPos
240
+ * @returns
241
+ */
242
+ function getGroundCenterOfCameraRay(viewer, screenPos) {
243
+ var _a, _b;
244
+ var ray = viewer.camera.getPickRay(screenPos);
245
+ var intersection = ray ? viewer.scene.globe.pick(ray, viewer.scene) : null;
246
+ if (intersection) {
247
+ return intersection;
337
248
  }
338
- DrawingUtils.EnsurePosHeight = EnsurePosHeight;
249
+ // The fallback will be to "guess" where the intersection might be.
250
+ // This happens if terrain is hidden, and there's nothing to intersect with.
251
+ // We will use the camera angle + camera height.
252
+ // Eg: if camera is looking straight down and is 100 meters above the ground, then the intersection will be 100 meters below the camera.
253
+ var cameraHeight = viewer.camera.positionCartographic.height;
254
+ if (!isNaN(cameraHeight) && cameraHeight != null && ((_b = (_a = viewer.camera) === null || _a === void 0 ? void 0 : _a.position) === null || _b === void 0 ? void 0 : _b.clone)) {
255
+ var cameraPos3d = viewer.camera.position.clone();
256
+ var pitch = viewer.camera.pitch;
257
+ var distance = cameraHeight / Math.tan(pitch);
258
+ return _offsetPos3d(cameraPos3d, -distance, Cesium.Math.toDegrees(viewer.camera.heading));
259
+ }
260
+ return null;
261
+ }
262
+ function areBoundsEqual(a, b) {
263
+ return a.north == b.north && a.south == b.south && a.east == b.east && a.west == b.west;
264
+ }
265
+ function arePosEqual(a, b) {
266
+ return a.latitude == b.latitude && a.longitude == b.longitude;
267
+ }
268
+ (function (CesiumViewMonitor) {
339
269
  /**
340
- * Returns an accurate 3d position from a given screen position.
341
- * @param viewer
342
- * @param cursor
343
- * @returns
270
+ * Monitors and emits events when the Cesium view changes.
344
271
  */
345
- DrawingUtils.GetAccuratePosition = (function () {
346
- var cachedPick = null;
347
- var cacheTimestamp = null;
348
- var cachedCameraState = null;
349
- return function (viewer, cursor, pickOnly) {
350
- if (pickOnly === void 0) { pickOnly = false; }
351
- var scene = viewer.scene;
352
- var camera = scene.camera;
353
- // Check if we can use cached position.
354
- if (cachedPick && cacheTimestamp) {
355
- var timeElapsed = Date.now() - cacheTimestamp;
356
- var isWithinCacheDuration = timeElapsed < 3000; // 3 seconds
357
- var isNearPreviousPick = Cesium.Cartesian2.distanceSquared(cursor, cachedPick.cursor) < 9; // 3 pixels
358
- var directionDot = Cesium.Cartesian3.dot(camera.directionWC, cachedCameraState.direction);
359
- var directionLengths = Cesium.Cartesian3.magnitude(camera.directionWC) * Cesium.Cartesian3.magnitude(cachedCameraState.direction);
360
- var angle = Math.acos(directionDot / directionLengths);
361
- var hasCameraMoved = Math.abs(camera.positionWC.x - cachedCameraState.position.x) > 2 || // 2 meters
362
- Math.abs(camera.positionWC.y - cachedCameraState.position.y) > 2 ||
363
- angle > Cesium.Math.toRadians(5); // 5 degrees
364
- if (isWithinCacheDuration && isNearPreviousPick && !hasCameraMoved) {
365
- return cachedPick.position;
272
+ var Monitor = /** @class */ (function () {
273
+ function Monitor(viewer) {
274
+ var _this = this;
275
+ this.target = null;
276
+ this.bounds = null;
277
+ this.disposed = false;
278
+ this.updatedEvent = null;
279
+ this.entity = null;
280
+ this.updating = false;
281
+ this.viewer = viewer;
282
+ this.tryEmitUpdate();
283
+ this.checkInterval = setInterval(function () {
284
+ _this.updateQueue();
285
+ }, POSITION_CHECK_TIMER);
286
+ }
287
+ Object.defineProperty(Monitor.prototype, "Disposed", {
288
+ get: function () {
289
+ return this.disposed;
290
+ },
291
+ enumerable: false,
292
+ configurable: true
293
+ });
294
+ Monitor.prototype.createEntity = function () {
295
+ var _this = this;
296
+ if (this.entity) {
297
+ return;
298
+ }
299
+ this.entity = this.viewer.entities.add({
300
+ position: new Cesium.CallbackProperty(function () {
301
+ return _this.target ? Cesium.Cartesian3.fromDegrees(_this.target.longitude, _this.target.latitude) : null;
302
+ }, false),
303
+ point: {
304
+ pixelSize: 8,
305
+ color: Cesium.Color.ORANGE,
306
+ heightReference: Cesium.HeightReference.NONE
307
+ },
308
+ rectangle: {
309
+ coordinates: new Cesium.CallbackProperty(function () {
310
+ return _this.bounds ? Cesium.Rectangle.fromDegrees(_this.bounds.west, _this.bounds.south, _this.bounds.east, _this.bounds.north) : null;
311
+ }, false),
312
+ material: Cesium.Color.fromCssColorString('#ff0000').withAlpha(0.4),
313
+ zIndex: 1,
314
+ heightReference: Cesium.HeightReference.NONE
366
315
  }
316
+ });
317
+ };
318
+ Monitor.prototype.destroyEntity = function () {
319
+ if (this.entity && this.viewer.entities.contains(this.entity)) {
320
+ this.viewer.entities.remove(this.entity);
367
321
  }
368
- // Actual picking logic
369
- // https://community.cesium.com/t/scene-pick-returning-point-inside-the-globe/18940/9
370
- var pos3d = null;
371
- // Means we can accurately pick right now.
372
- if (!pickOnly && scene.globe.depthTestAgainstTerrain) {
373
- pos3d = scene.pickPosition(cursor);
322
+ this.entity = null;
323
+ };
324
+ Monitor.prototype.Updated = function () {
325
+ if (!this.updatedEvent) {
326
+ this.updatedEvent = new bruceModels.BruceEvent();
374
327
  }
375
- // Means we cannot guarantee an accurate pick.
376
- // We want to prioritize pick-position when we can, so we'll try use it and if the result is sus then we'll use some fallbacks.
377
- else {
378
- if (!pickOnly) {
379
- pos3d = scene.pickPosition(cursor);
380
- }
381
- if (Cesium.defined(pos3d)) {
382
- var carto = Cesium.Cartographic.fromCartesian(pos3d);
383
- if (!Cesium.defined(carto) || carto.height < 0) {
384
- pos3d = null;
385
- }
386
- }
387
- if (!Cesium.defined(pos3d)) {
388
- pos3d = null;
389
- var ray = scene.camera.getPickRay(cursor);
390
- if (scene.pickPositionSupported) {
391
- var pickedObject = scene.pick(cursor, 1, 1);
392
- if (Cesium.defined(pickedObject) &&
393
- (pickedObject instanceof Cesium.Cesium3DTileFeature ||
394
- pickedObject.primitive instanceof Cesium.Cesium3DTileset ||
395
- pickedObject.primitive instanceof Cesium.Model)) {
396
- pos3d = scene.pickPosition(cursor);
397
- }
328
+ return this.updatedEvent;
329
+ };
330
+ Monitor.prototype.GetBounds = function () {
331
+ return this.bounds;
332
+ };
333
+ Monitor.prototype.GetTarget = function () {
334
+ return this.target;
335
+ };
336
+ Monitor.prototype.DoUpdate = function () {
337
+ this.tryEmitUpdate();
338
+ };
339
+ Monitor.prototype.Dispose = function () {
340
+ if (this.disposed) {
341
+ return;
342
+ }
343
+ this.disposed = true;
344
+ clearInterval(this.checkInterval);
345
+ this.destroyEntity();
346
+ };
347
+ Monitor.prototype.tryDoUpdate = function () {
348
+ var _a;
349
+ return __awaiter(this, void 0, void 0, function () {
350
+ var viewRect, center, camera, terrData, cameraPosition, terrHeight, viewRectRad, windowPosition, intersection, point, viewRectRad, centerLong, centerLat;
351
+ return __generator(this, function (_b) {
352
+ switch (_b.label) {
353
+ case 0:
354
+ if (!this.viewer || this.viewer.isDestroyed()) {
355
+ this.Dispose();
356
+ return [2 /*return*/, ESearchStatus.LocationMissing];
357
+ }
358
+ viewRect = null;
359
+ center = null;
360
+ camera = this.viewer.camera;
361
+ return [4 /*yield*/, exports.DrawingUtils.GetTerrainHeight({
362
+ pos3d: camera.position,
363
+ viewer: this.viewer
364
+ })];
365
+ case 1:
366
+ terrData = _b.sent();
367
+ cameraPosition = this.viewer.camera.positionCartographic;
368
+ terrHeight = terrData.error ? cameraPosition.height + DEFAULT_GROUNDED_HEIGHT : terrData.height;
369
+ // We are almost at the ground, screw horizon, just load around.
370
+ if (terrHeight && ((cameraPosition.height - terrHeight) < DEFAULT_GROUNDED_HEIGHT)) {
371
+ // View area calculation.
372
+ viewRect = {};
373
+ viewRectRad = netScanViewForBoundaries(this.viewer);
374
+ if (viewRectRad &&
375
+ viewRectRad.east &&
376
+ viewRectRad.west &&
377
+ viewRectRad.north &&
378
+ viewRectRad.south) {
379
+ viewRect.east = Cesium.Math.toDegrees(Math.max(viewRectRad.east, cameraPosition.longitude));
380
+ viewRect.west = Cesium.Math.toDegrees(Math.min(viewRectRad.west, cameraPosition.longitude));
381
+ viewRect.south = Cesium.Math.toDegrees(Math.min(viewRectRad.south, cameraPosition.latitude));
382
+ viewRect.north = Cesium.Math.toDegrees(Math.max(viewRectRad.north, cameraPosition.latitude));
383
+ }
384
+ else {
385
+ viewRect.east = cameraPosition.longitude;
386
+ viewRect.west = cameraPosition.longitude;
387
+ viewRect.south = cameraPosition.latitude;
388
+ viewRect.north = cameraPosition.latitude;
389
+ }
390
+ center = {};
391
+ center.latitude = Cesium.Math.toDegrees(camera.positionCartographic.latitude);
392
+ center.longitude = Cesium.Math.toDegrees(camera.positionCartographic.longitude);
393
+ }
394
+ else {
395
+ windowPosition = new Cesium.Cartesian2(this.viewer.container.clientWidth / 2, this.viewer.container.clientHeight / 2);
396
+ intersection = getGroundCenterOfCameraRay(this.viewer, windowPosition);
397
+ point = null;
398
+ if (intersection) {
399
+ point = Cesium.Cartographic.fromCartesian(intersection, this.viewer.scene.globe.ellipsoid);
400
+ }
401
+ if (point) {
402
+ center = {};
403
+ center.latitude = Cesium.Math.toDegrees(point.latitude);
404
+ center.longitude = Cesium.Math.toDegrees(point.longitude);
405
+ viewRectRad = netScanViewForBoundaries(this.viewer, center);
406
+ if (viewRectRad) {
407
+ viewRect = {};
408
+ viewRect.east = Cesium.Math.toDegrees(viewRectRad.east);
409
+ viewRect.west = Cesium.Math.toDegrees(viewRectRad.west);
410
+ viewRect.south = Cesium.Math.toDegrees(viewRectRad.south);
411
+ viewRect.north = Cesium.Math.toDegrees(viewRectRad.north);
412
+ }
413
+ }
414
+ }
415
+ // Minimal field of view.
416
+ if (viewRect) {
417
+ centerLong = (viewRect.east + viewRect.west) / 2;
418
+ centerLat = (viewRect.north + viewRect.south) / 2;
419
+ viewRect.east = Math.max(viewRect.east, centerLong + (MINIMUM_VIEW_AREA_SIZE_DEGREES / 2));
420
+ viewRect.west = Math.min(viewRect.west, centerLong - (MINIMUM_VIEW_AREA_SIZE_DEGREES / 2));
421
+ viewRect.south = Math.min(viewRect.south, centerLat - (MINIMUM_VIEW_AREA_SIZE_DEGREES / 2));
422
+ viewRect.north = Math.max(viewRect.north, centerLat + (MINIMUM_VIEW_AREA_SIZE_DEGREES / 2));
423
+ viewRect.alt = (_a = this.viewer.scene.camera.positionCartographic) === null || _a === void 0 ? void 0 : _a.height;
424
+ }
425
+ if (center && viewRect) {
426
+ if ((!this.target || (this.target && !arePosEqual(this.target, center))) ||
427
+ (!this.bounds || (this.bounds && !areBoundsEqual(this.bounds, viewRect)))) {
428
+ this.target = center;
429
+ this.bounds = viewRect;
430
+ return [2 /*return*/, ESearchStatus.LocationChanged];
431
+ }
432
+ return [2 /*return*/, ESearchStatus.LocationFound];
433
+ }
434
+ return [2 /*return*/, ESearchStatus.LocationMissing];
398
435
  }
399
- if (!pickOnly && !Cesium.defined(pos3d)) {
400
- pos3d = scene.globe.pick(ray, scene);
436
+ });
437
+ });
438
+ };
439
+ Monitor.prototype.tryEmitUpdate = function () {
440
+ var _a;
441
+ return __awaiter(this, void 0, void 0, function () {
442
+ var searchResult, interest, e_1;
443
+ return __generator(this, function (_b) {
444
+ switch (_b.label) {
445
+ case 0:
446
+ if (this.updating) {
447
+ return [2 /*return*/];
448
+ }
449
+ this.updating = true;
450
+ _b.label = 1;
451
+ case 1:
452
+ _b.trys.push([1, 3, , 4]);
453
+ return [4 /*yield*/, this.tryDoUpdate()];
454
+ case 2:
455
+ searchResult = _b.sent();
456
+ if (searchResult == ESearchStatus.LocationChanged) {
457
+ interest = {
458
+ bounds: this.bounds,
459
+ target: this.target
460
+ };
461
+ // this.createEntity();
462
+ (_a = this.updatedEvent) === null || _a === void 0 ? void 0 : _a.Trigger(interest);
463
+ }
464
+ else if (searchResult == ESearchStatus.LocationMissing) {
465
+ this.updateQueue();
466
+ }
467
+ return [3 /*break*/, 4];
468
+ case 3:
469
+ e_1 = _b.sent();
470
+ console.error(e_1);
471
+ this.updateQueue();
472
+ return [3 /*break*/, 4];
473
+ case 4:
474
+ this.updating = false;
475
+ return [2 /*return*/];
401
476
  }
402
- }
477
+ });
478
+ });
479
+ };
480
+ Monitor.prototype.queuePosition = function (lag) {
481
+ var _this = this;
482
+ if (this.pendingTimeout) {
483
+ clearTimeout(this.pendingTimeout);
403
484
  }
404
- // Update cache.
405
- cachedPick = {
406
- position: pos3d,
407
- cursor: cursor.clone()
408
- };
409
- cacheTimestamp = Date.now();
410
- cachedCameraState = {
411
- position: camera.positionWC.clone(),
412
- direction: camera.directionWC.clone()
413
- };
414
- return pos3d;
485
+ this.pendingTimeout = setTimeout(function () {
486
+ if (!_this.disposed) {
487
+ _this.tryEmitUpdate();
488
+ }
489
+ }, lag);
415
490
  };
416
- })();
491
+ Monitor.prototype.updateQueue = function () {
492
+ this.queuePosition(TIME_LAG);
493
+ };
494
+ return Monitor;
495
+ }());
496
+ CesiumViewMonitor.Monitor = Monitor;
497
+ })(exports.CesiumViewMonitor || (exports.CesiumViewMonitor = {}));
498
+
499
+ /**
500
+ * Ensures a number is returned from a given value.
501
+ * If given value cannot be parsed it will return defaultNum.
502
+ * @param value
503
+ * @param defaultNum default is 0.
504
+ * @returns
505
+ */
506
+ function EnsureNumber(value, defaultNum) {
507
+ if (!defaultNum) {
508
+ defaultNum = 0;
509
+ }
510
+ value = Number(value);
511
+ if (isNaN(value)) {
512
+ return defaultNum;
513
+ }
514
+ return value;
515
+ }
516
+
517
+ (function (MeasureUtils) {
417
518
  /**
418
- * Smooths a given set of points.
419
- * @param points
420
- * @param multiplier
421
- * @param closed: true if this is a closed shape. Eg: polygon.
519
+ * Returns the total distance in meters between an array of points.
520
+ * This distance is NOT following the terrain.
521
+ * @param posses
422
522
  * @returns
423
523
  */
424
- function SmoothPoints(points, multiplier, closed) {
425
- if (points.length < 4 || multiplier < 2) {
426
- return points;
427
- }
428
- if (!closed) {
429
- points.unshift(C3.subtract(points[0], points[1], new C3));
430
- points.push(C3.subtract(points[points.length - 1], points[points.length - 2], new C3));
431
- }
432
- else {
433
- points.unshift(points[points.length - 1]);
434
- points.unshift(points[points.length - 2]);
435
- points.push(points[2]);
524
+ function MeasurePolyline(params) {
525
+ var posses = params.posses;
526
+ if (posses.length < 2) {
527
+ return {
528
+ totalLength: 0
529
+ };
436
530
  }
437
- var splinePoints = [];
438
- var _loop_1 = function (i) {
439
- var _a = [0, 1, 2, 3].map(function (n) { return points[i + n]; }), P0 = _a[0], P1 = _a[1], P2 = _a[2], P3 = _a[3];
440
- for (var j = 0; j <= multiplier; j++) {
441
- splinePoints.push(catmullRom(P0, P1, P2, P3, j / multiplier));
531
+ var totalLength = 0;
532
+ var pos1 = null;
533
+ var pos2 = null;
534
+ for (var i = 0; i < posses.length; i++) {
535
+ if (pos1 == null) {
536
+ pos1 = posses[i];
537
+ }
538
+ else if (pos2 == null) {
539
+ pos2 = posses[i];
540
+ totalLength += Cesium.Cartesian3.distance(pos1, pos2);
541
+ pos1 = pos2;
542
+ pos2 = null;
442
543
  }
443
- };
444
- for (var i = 0; i < points.length - 3; i++) {
445
- _loop_1(i);
446
544
  }
447
- return splinePoints;
545
+ return {
546
+ totalLength: totalLength
547
+ };
448
548
  }
449
- DrawingUtils.SmoothPoints = SmoothPoints;
549
+ MeasureUtils.MeasurePolyline = MeasurePolyline;
550
+ function MeasurePolygon(params) {
551
+ var posses = params.posses;
552
+ posses = [].concat(posses);
553
+ if (!bruceModels.Cartes.IsRing3Closed(posses)) {
554
+ posses.push(posses[0].clone());
555
+ }
556
+ if (posses.length < 3) {
557
+ return {
558
+ area: 0,
559
+ perimeter: 0
560
+ };
561
+ }
562
+ var area = 0;
563
+ var indices = Cesium.PolygonPipeline.triangulate(posses, []);
564
+ for (var i = 0; i < indices.length; i += 3) {
565
+ var vector1 = posses[indices[i]];
566
+ var vector2 = posses[indices[i + 1]];
567
+ var vector3 = posses[indices[i + 2]];
568
+ var vectorC = Cesium.Cartesian3.subtract(vector2, vector1, new Cesium.Cartesian3());
569
+ var vectorD = Cesium.Cartesian3.subtract(vector3, vector1, new Cesium.Cartesian3());
570
+ var areaVector = Cesium.Cartesian3.cross(vectorC, vectorD, new Cesium.Cartesian3());
571
+ area += Cesium.Cartesian3.magnitude(areaVector) / 2.0;
572
+ }
573
+ var perimeter = MeasurePolyline({
574
+ posses: posses
575
+ }).totalLength;
576
+ return {
577
+ area: area,
578
+ perimeter: perimeter
579
+ };
580
+ }
581
+ MeasureUtils.MeasurePolygon = MeasurePolygon;
582
+ })(exports.MeasureUtils || (exports.MeasureUtils = {}));
583
+
584
+ var C3 = [Cesium.Cartesian3][0];
585
+ function getT(t, alpha, p0, p1) {
586
+ var d = C3.subtract(p1, p0, new C3);
587
+ var a = C3.dot(d, d);
588
+ var b = Math.pow(a, alpha * 0.5);
589
+ return b + t;
590
+ }
591
+ function catmullRom(p0, p1, p2, p3, t) {
592
+ var t0 = 0;
593
+ var t1 = getT(t0, 0.5, p0, p1);
594
+ var t2 = getT(t1, 0.5, p1, p2);
595
+ var t3 = getT(t2, 0.5, p2, p3);
596
+ t = Cesium.Math.lerp(t1, t2, t);
597
+ var _a = [function (l, r) { return C3.add(l, r, new C3); }, function (l, r) { return C3.multiplyByScalar(l, r, new C3); }], add = _a[0], mul = _a[1];
598
+ var A1 = add(mul(p0, (t1 - t) / (t1 - t0)), mul(p1, (t - t0) / (t1 - t0)));
599
+ var A2 = add(mul(p1, (t2 - t) / (t2 - t1)), mul(p2, (t - t1) / (t2 - t1)));
600
+ var A3 = add(mul(p2, (t3 - t) / (t3 - t2)), mul(p3, (t - t2) / (t3 - t2)));
601
+ var B1 = add(mul(A1, (t2 - t) / (t2 - t0)), mul(A2, (t - t0) / (t2 - t0)));
602
+ var B2 = add(mul(A2, (t3 - t) / (t3 - t1)), mul(A3, (t - t1) / (t3 - t1)));
603
+ var C = add(mul(B1, (t2 - t) / (t2 - t1)), mul(B2, (t - t1) / (t2 - t1)));
604
+ return C;
605
+ }
606
+ (function (DrawingUtils) {
607
+ /**
608
+ * Returns the point across a polyline at a given distance.
609
+ * If the distance exceeds the length of the line, the point will be placed at the end of the line.
610
+ * @param viewer
611
+ * @param positions
612
+ * @param distance
613
+ * @returns
614
+ */
615
+ function PointAcrossPolyline(params) {
616
+ var viewer = params.viewer, positions = params.posses, distance = params.distance;
617
+ if (distance <= 0 && positions.length > 0) {
618
+ return {
619
+ point: positions[0]
620
+ };
621
+ }
622
+ else if (positions.length > 1) {
623
+ var currentDistance = 0;
624
+ var totalLength = exports.MeasureUtils.MeasurePolyline({
625
+ posses: positions,
626
+ }).totalLength;
627
+ if (distance > totalLength) {
628
+ return {
629
+ point: positions[positions.length - 1]
630
+ };
631
+ }
632
+ for (var i = 0; i < positions.length - 1; i++) {
633
+ var length_1 = Cesium.Cartesian3.distance(positions[i], positions[i + 1]);
634
+ if (length_1 + currentDistance >= distance) {
635
+ var carto1 = Cesium.Cartographic.fromCartesian(positions[i]);
636
+ var carto2 = Cesium.Cartographic.fromCartesian(positions[i + 1]);
637
+ var geodesic = new Cesium.EllipsoidGeodesic(carto1, carto2, viewer.scene.globe.ellipsoid);
638
+ //const position = geodesic.interpolateUsingSurfaceDistance(distance - currentDistance);
639
+ var position = geodesic.interpolateUsingFraction((distance - currentDistance) / length_1);
640
+ var height = (carto1.height + carto2.height) / 2;
641
+ return {
642
+ point: Cesium.Cartesian3.fromRadians(position.longitude, position.latitude, height)
643
+ };
644
+ }
645
+ else {
646
+ currentDistance += length_1;
647
+ }
648
+ }
649
+ }
650
+ return {
651
+ point: positions.length ? positions[positions.length - 1] : null
652
+ };
653
+ }
654
+ DrawingUtils.PointAcrossPolyline = PointAcrossPolyline;
450
655
  /**
656
+ * Returns terrain height from current viewer's provider.
657
+ * On error or flat terrain, it will return 0.
658
+ * If an error occurred it will be attached to the result.
451
659
  * @param pos3d
452
- * @param minimumHeight height relative to ground
660
+ * @param viewer
661
+ * @returns
453
662
  */
454
- function RaisePos3d(viewer, pos3d, minimumHeight) {
455
- if (minimumHeight === void 0) { minimumHeight = 0; }
663
+ function GetTerrainHeight(params) {
456
664
  return __awaiter(this, void 0, void 0, function () {
457
- var carto, terrainCarto, sample, terrainHeight;
665
+ var pos3d, viewer, sample, height, e_1;
458
666
  return __generator(this, function (_a) {
459
667
  switch (_a.label) {
460
668
  case 0:
669
+ pos3d = params.pos3d, viewer = params.viewer;
670
+ _a.label = 1;
671
+ case 1:
672
+ _a.trys.push([1, 3, , 4]);
461
673
  // If the terrain provider is not ready let's not ping it.
462
674
  if (!viewer.terrainProvider || viewer.terrainProvider["ready"] == false) {
463
- return [2 /*return*/, pos3d];
675
+ return [2 /*return*/, {
676
+ height: 0,
677
+ error: "Terrain provider not ready."
678
+ }];
464
679
  }
465
- carto = Cesium.Cartographic.fromCartesian(pos3d);
466
- terrainCarto = carto.clone();
467
- terrainCarto.height = 0;
468
- if (!(viewer.scene.terrainProvider instanceof Cesium.EllipsoidTerrainProvider)) return [3 /*break*/, 1];
469
- carto.height = Math.max(carto.height, minimumHeight);
470
- return [3 /*break*/, 3];
471
- case 1: return [4 /*yield*/, Cesium.sampleTerrainMostDetailed(viewer.scene.terrainProvider, [terrainCarto])];
680
+ if (viewer.scene.terrainProvider instanceof Cesium.EllipsoidTerrainProvider) {
681
+ return [2 /*return*/, {
682
+ height: 0
683
+ }];
684
+ }
685
+ return [4 /*yield*/, Cesium.sampleTerrainMostDetailed(viewer.scene.terrainProvider, [Cesium.Cartographic.fromCartesian(pos3d)])];
472
686
  case 2:
473
687
  sample = _a.sent();
474
- terrainHeight = (sample === null || sample === void 0 ? void 0 : sample.length) ? sample[0].height : null;
475
- if (terrainHeight != null) {
476
- carto.height = Math.max(carto.height, terrainHeight + minimumHeight);
688
+ height = (sample === null || sample === void 0 ? void 0 : sample.length) ? sample[0].height : null;
689
+ if (isNaN(height)) {
690
+ return [2 /*return*/, {
691
+ height: 0,
692
+ error: "NaN"
693
+ }];
477
694
  }
478
- _a.label = 3;
479
- case 3: return [2 /*return*/, Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height)];
695
+ return [2 /*return*/, {
696
+ height: height
697
+ }];
698
+ case 3:
699
+ e_1 = _a.sent();
700
+ return [2 /*return*/, {
701
+ height: 0,
702
+ error: e_1
703
+ }];
704
+ case 4: return [2 /*return*/];
480
705
  }
481
706
  });
482
707
  });
483
708
  }
484
- DrawingUtils.RaisePos3d = RaisePos3d;
485
- })(exports.DrawingUtils || (exports.DrawingUtils = {}));
486
-
487
- /**
488
- * Returns if a given visual can be styled by this utility.
489
- * @param viewer
490
- * @param visual
491
- * @returns
492
- */
493
- function isAlive(viewer, visual) {
494
- if (!(viewer === null || viewer === void 0 ? void 0 : viewer.scene) || viewer.isDestroyed()) {
495
- return false;
496
- }
497
- if (visual instanceof Cesium.Entity) {
498
- return true;
499
- }
500
- else if (visual instanceof Cesium.Primitive) {
501
- return true;
502
- }
503
- else if (visual instanceof Cesium.Cesium3DTileFeature) {
504
- var cTileset = visual === null || visual === void 0 ? void 0 : visual.tileset;
505
- if (!cTileset) {
506
- return false;
709
+ DrawingUtils.GetTerrainHeight = GetTerrainHeight;
710
+ function EnsurePosHeight(params) {
711
+ var pos3d = params.pos3d, viewer = params.viewer, desiredHeightRef = params.desiredHeightRef, heightRef = params.heightRef;
712
+ var carto = bruceModels.Cartes.ValidateCartes3(pos3d) ? Cesium.Cartographic.fromCartesian(pos3d) : null;
713
+ if (!(carto === null || carto === void 0 ? void 0 : carto.latitude)) {
714
+ return pos3d;
507
715
  }
508
- if (cTileset.isDestroyed() || !viewer.scene.primitives.contains(cTileset)) {
509
- return false;
716
+ if (heightRef == null) {
717
+ heightRef = Cesium.HeightReference.CLAMP_TO_GROUND;
510
718
  }
511
- return true;
512
- }
513
- return false;
514
- }
515
- var _selectColor = Cesium.Color.fromAlpha(Cesium.Color.YELLOW, 0.5);
516
- var _highlightColor = Cesium.Color.fromCssColorString("#33b1ff").withAlpha(0.5);
517
- var STORE_COLOR_PREFIX = "_storeColor_";
518
- function getStoreKey(key) {
519
- return STORE_COLOR_PREFIX + key;
520
- }
521
- var STORE_KEY_STATE_PREFIX = "_storeKeyState_";
522
- function getStoreStateKey(key) {
523
- return STORE_KEY_STATE_PREFIX + key;
524
- }
525
- var LAST_APPLIED_OPACITY_KEY = "_lastAppliedOpacityKey";
526
- /**
527
- * Returns a color property from a graphic.
528
- * This will turn materials properties into colors before returning them.
529
- * @param viewer
530
- * @param prop
531
- * @returns
532
- */
533
- function getCesiumColorValue(viewer, prop) {
534
- if (!prop) {
535
- return Cesium.Color.WHITE;
536
- }
537
- if (prop.getValue) {
538
- prop = prop.getValue(viewer.scene.lastRenderTime);
719
+ if (desiredHeightRef == null) {
720
+ desiredHeightRef = Cesium.HeightReference.CLAMP_TO_GROUND;
721
+ }
722
+ if (heightRef == desiredHeightRef) {
723
+ return pos3d;
724
+ }
725
+ if (heightRef == Cesium.HeightReference.NONE) {
726
+ // Turn absolute into clamped.
727
+ if (desiredHeightRef == Cesium.HeightReference.CLAMP_TO_GROUND) {
728
+ return Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, 0);
729
+ }
730
+ // Turn absolute into relative (remove terrain height).
731
+ else if (desiredHeightRef == Cesium.HeightReference.RELATIVE_TO_GROUND) {
732
+ var terrainHeight = EnsureNumber(viewer.scene.globe.getHeight(carto), 0);
733
+ return Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height - terrainHeight);
734
+ }
735
+ }
736
+ else if (heightRef == Cesium.HeightReference.CLAMP_TO_GROUND) {
737
+ var terrainHeight = EnsureNumber(viewer.scene.globe.getHeight(carto), 0);
738
+ return Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, terrainHeight);
739
+ }
740
+ else if (heightRef == Cesium.HeightReference.RELATIVE_TO_GROUND) {
741
+ // Turn relative into absolute (add terrain height).
742
+ if (desiredHeightRef == Cesium.HeightReference.NONE) {
743
+ var terrainHeight = EnsureNumber(viewer.scene.globe.getHeight(carto), 0);
744
+ return Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height + terrainHeight);
745
+ }
746
+ // Turn relative into clamped.
747
+ else if (desiredHeightRef == Cesium.HeightReference.CLAMP_TO_GROUND) {
748
+ return Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, 0);
749
+ }
750
+ }
751
+ return pos3d;
539
752
  }
540
- if (prop instanceof Cesium.Color) {
753
+ DrawingUtils.EnsurePosHeight = EnsurePosHeight;
754
+ /**
755
+ * Returns an accurate 3d position from a given screen position.
756
+ * @param viewer
757
+ * @param cursor
758
+ * @returns
759
+ */
760
+ DrawingUtils.GetAccuratePosition = (function () {
761
+ var cachedPick = null;
762
+ var cacheTimestamp = null;
763
+ var cachedCameraState = null;
764
+ return function (viewer, cursor, pickOnly) {
765
+ if (pickOnly === void 0) { pickOnly = false; }
766
+ var scene = viewer.scene;
767
+ var camera = scene.camera;
768
+ // Check if we can use cached position.
769
+ if (cachedPick && cacheTimestamp) {
770
+ var timeElapsed = Date.now() - cacheTimestamp;
771
+ var isWithinCacheDuration = timeElapsed < 3000; // 3 seconds
772
+ var isNearPreviousPick = Cesium.Cartesian2.distanceSquared(cursor, cachedPick.cursor) < 9; // 3 pixels
773
+ var directionDot = Cesium.Cartesian3.dot(camera.directionWC, cachedCameraState.direction);
774
+ var directionLengths = Cesium.Cartesian3.magnitude(camera.directionWC) * Cesium.Cartesian3.magnitude(cachedCameraState.direction);
775
+ var angle = Math.acos(directionDot / directionLengths);
776
+ var hasCameraMoved = Math.abs(camera.positionWC.x - cachedCameraState.position.x) > 2 || // 2 meters
777
+ Math.abs(camera.positionWC.y - cachedCameraState.position.y) > 2 ||
778
+ angle > Cesium.Math.toRadians(5); // 5 degrees
779
+ if (isWithinCacheDuration && isNearPreviousPick && !hasCameraMoved) {
780
+ return cachedPick.position;
781
+ }
782
+ }
783
+ // Actual picking logic
784
+ // https://community.cesium.com/t/scene-pick-returning-point-inside-the-globe/18940/9
785
+ var pos3d = null;
786
+ // Means we can accurately pick right now.
787
+ if (!pickOnly && scene.globe.depthTestAgainstTerrain) {
788
+ pos3d = scene.pickPosition(cursor);
789
+ }
790
+ // Means we cannot guarantee an accurate pick.
791
+ // We want to prioritize pick-position when we can, so we'll try use it and if the result is sus then we'll use some fallbacks.
792
+ else {
793
+ if (!pickOnly) {
794
+ pos3d = scene.pickPosition(cursor);
795
+ }
796
+ if (Cesium.defined(pos3d)) {
797
+ var carto = Cesium.Cartographic.fromCartesian(pos3d);
798
+ if (!Cesium.defined(carto) || carto.height < 0) {
799
+ pos3d = null;
800
+ }
801
+ }
802
+ if (!Cesium.defined(pos3d)) {
803
+ pos3d = null;
804
+ var ray = scene.camera.getPickRay(cursor);
805
+ if (scene.pickPositionSupported) {
806
+ var pickedObject = scene.pick(cursor, 1, 1);
807
+ if (Cesium.defined(pickedObject) &&
808
+ (pickedObject instanceof Cesium.Cesium3DTileFeature ||
809
+ pickedObject.primitive instanceof Cesium.Cesium3DTileset ||
810
+ pickedObject.primitive instanceof Cesium.Model)) {
811
+ pos3d = scene.pickPosition(cursor);
812
+ }
813
+ }
814
+ if (!pickOnly && !Cesium.defined(pos3d)) {
815
+ pos3d = scene.globe.pick(ray, scene);
816
+ }
817
+ }
818
+ }
819
+ // Update cache.
820
+ cachedPick = {
821
+ position: pos3d,
822
+ cursor: cursor.clone()
823
+ };
824
+ cacheTimestamp = Date.now();
825
+ cachedCameraState = {
826
+ position: camera.positionWC.clone(),
827
+ direction: camera.directionWC.clone()
828
+ };
829
+ return pos3d;
830
+ };
831
+ })();
832
+ /**
833
+ * Smooths a given set of points.
834
+ * @param points
835
+ * @param multiplier
836
+ * @param closed: true if this is a closed shape. Eg: polygon.
837
+ * @returns
838
+ */
839
+ function SmoothPoints(points, multiplier, closed) {
840
+ if (points.length < 4 || multiplier < 2) {
841
+ return points;
842
+ }
843
+ if (!closed) {
844
+ points.unshift(C3.subtract(points[0], points[1], new C3));
845
+ points.push(C3.subtract(points[points.length - 1], points[points.length - 2], new C3));
846
+ }
847
+ else {
848
+ points.unshift(points[points.length - 1]);
849
+ points.unshift(points[points.length - 2]);
850
+ points.push(points[2]);
851
+ }
852
+ var splinePoints = [];
853
+ var _loop_1 = function (i) {
854
+ var _a = [0, 1, 2, 3].map(function (n) { return points[i + n]; }), P0 = _a[0], P1 = _a[1], P2 = _a[2], P3 = _a[3];
855
+ for (var j = 0; j <= multiplier; j++) {
856
+ splinePoints.push(catmullRom(P0, P1, P2, P3, j / multiplier));
857
+ }
858
+ };
859
+ for (var i = 0; i < points.length - 3; i++) {
860
+ _loop_1(i);
861
+ }
862
+ return splinePoints;
863
+ }
864
+ DrawingUtils.SmoothPoints = SmoothPoints;
865
+ /**
866
+ * @param pos3d
867
+ * @param minimumHeight height relative to ground
868
+ */
869
+ function RaisePos3d(viewer, pos3d, minimumHeight) {
870
+ if (minimumHeight === void 0) { minimumHeight = 0; }
871
+ return __awaiter(this, void 0, void 0, function () {
872
+ var carto, terrainCarto, sample, terrainHeight;
873
+ return __generator(this, function (_a) {
874
+ switch (_a.label) {
875
+ case 0:
876
+ // If the terrain provider is not ready let's not ping it.
877
+ if (!viewer.terrainProvider || viewer.terrainProvider["ready"] == false) {
878
+ return [2 /*return*/, pos3d];
879
+ }
880
+ carto = Cesium.Cartographic.fromCartesian(pos3d);
881
+ terrainCarto = carto.clone();
882
+ terrainCarto.height = 0;
883
+ if (!(viewer.scene.terrainProvider instanceof Cesium.EllipsoidTerrainProvider)) return [3 /*break*/, 1];
884
+ carto.height = Math.max(carto.height, minimumHeight);
885
+ return [3 /*break*/, 3];
886
+ case 1: return [4 /*yield*/, Cesium.sampleTerrainMostDetailed(viewer.scene.terrainProvider, [terrainCarto])];
887
+ case 2:
888
+ sample = _a.sent();
889
+ terrainHeight = (sample === null || sample === void 0 ? void 0 : sample.length) ? sample[0].height : null;
890
+ if (terrainHeight != null) {
891
+ carto.height = Math.max(carto.height, terrainHeight + minimumHeight);
892
+ }
893
+ _a.label = 3;
894
+ case 3: return [2 /*return*/, Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height)];
895
+ }
896
+ });
897
+ });
898
+ }
899
+ DrawingUtils.RaisePos3d = RaisePos3d;
900
+ })(exports.DrawingUtils || (exports.DrawingUtils = {}));
901
+
902
+ /**
903
+ * Returns if a given visual can be styled by this utility.
904
+ * @param viewer
905
+ * @param visual
906
+ * @returns
907
+ */
908
+ function isAlive(viewer, visual) {
909
+ if (!(viewer === null || viewer === void 0 ? void 0 : viewer.scene) || viewer.isDestroyed()) {
910
+ return false;
911
+ }
912
+ if (visual instanceof Cesium.Entity) {
913
+ return true;
914
+ }
915
+ else if (visual instanceof Cesium.Primitive) {
916
+ return true;
917
+ }
918
+ else if (visual instanceof Cesium.Cesium3DTileFeature) {
919
+ var cTileset = visual === null || visual === void 0 ? void 0 : visual.tileset;
920
+ if (!cTileset) {
921
+ return false;
922
+ }
923
+ if (cTileset.isDestroyed() || !viewer.scene.primitives.contains(cTileset)) {
924
+ return false;
925
+ }
926
+ return true;
927
+ }
928
+ return false;
929
+ }
930
+ var _selectColor = Cesium.Color.fromAlpha(Cesium.Color.YELLOW, 0.5);
931
+ var _highlightColor = Cesium.Color.fromCssColorString("#33b1ff").withAlpha(0.5);
932
+ var STORE_COLOR_PREFIX = "_storeColor_";
933
+ function getStoreKey(key) {
934
+ return STORE_COLOR_PREFIX + key;
935
+ }
936
+ var STORE_KEY_STATE_PREFIX = "_storeKeyState_";
937
+ function getStoreStateKey(key) {
938
+ return STORE_KEY_STATE_PREFIX + key;
939
+ }
940
+ var LAST_APPLIED_OPACITY_KEY = "_lastAppliedOpacityKey";
941
+ /**
942
+ * Returns a color property from a graphic.
943
+ * This will turn materials properties into colors before returning them.
944
+ * @param viewer
945
+ * @param prop
946
+ * @returns
947
+ */
948
+ function getCesiumColorValue(viewer, prop) {
949
+ if (!prop) {
950
+ return Cesium.Color.WHITE;
951
+ }
952
+ if (prop.getValue) {
953
+ prop = prop.getValue(viewer.scene.lastRenderTime);
954
+ }
955
+ if (prop instanceof Cesium.Color) {
541
956
  return prop;
542
957
  }
543
958
  var tmp = prop === null || prop === void 0 ? void 0 : prop.color;
@@ -6532,7 +6947,6 @@
6532
6947
  if (visible == null) {
6533
6948
  visible = getShowState(rego);
6534
6949
  }
6535
- console.log("entityId", rego.entityId, "visible", visible, "overrideShow", rego.overrideShow);
6536
6950
  updateEntityShow(viewer, rego, visible);
6537
6951
  if (rego.best) {
6538
6952
  var isLabelled = register.GetIsLabelled({
@@ -13390,7 +13804,7 @@
13390
13804
  configurable: true
13391
13805
  });
13392
13806
  Manager.prototype.Init = function () {
13393
- var _a;
13807
+ var _this = this;
13394
13808
  var files = this.item.KML;
13395
13809
  if (!files) {
13396
13810
  return;
@@ -13398,31 +13812,47 @@
13398
13812
  if (!Array.isArray(files)) {
13399
13813
  files = [files];
13400
13814
  }
13401
- for (var i = 0; i < files.length; i++) {
13402
- var file = files[i];
13403
- var fileId = (_a = file === null || file === void 0 ? void 0 : file.ClientFile) === null || _a === void 0 ? void 0 : _a.ID;
13404
- var externalURL = file === null || file === void 0 ? void 0 : file.fileUrl;
13405
- if (!fileId && !externalURL) {
13406
- continue;
13407
- }
13408
- var api = this.apiGetter.getApi();
13409
- var fileUrl = void 0;
13410
- if (fileId) {
13411
- fileUrl = bruceModels.ClientFile.GetUrl({
13412
- api: api,
13413
- fileId: fileId,
13414
- viaCdn: true
13415
- });
13416
- }
13417
- else if (externalURL) {
13418
- fileUrl = externalURL;
13419
- }
13420
- var source = new Cesium.KmlDataSource();
13421
- source.load(fileUrl);
13422
- this.viewer.dataSources.add(source);
13423
- this.dataSources.push(source);
13424
- this.viewer.scene.requestRender();
13425
- }
13815
+ (function () { return __awaiter(_this, void 0, void 0, function () {
13816
+ var api, i, file, fileId, externalURL, fileUrl, source;
13817
+ var _a;
13818
+ return __generator(this, function (_b) {
13819
+ switch (_b.label) {
13820
+ case 0:
13821
+ api = this.apiGetter.getApi();
13822
+ return [4 /*yield*/, api.Loading];
13823
+ case 1:
13824
+ _b.sent();
13825
+ if (this.disposed) {
13826
+ return [2 /*return*/];
13827
+ }
13828
+ for (i = 0; i < files.length; i++) {
13829
+ file = files[i];
13830
+ fileId = (_a = file === null || file === void 0 ? void 0 : file.ClientFile) === null || _a === void 0 ? void 0 : _a.ID;
13831
+ externalURL = file === null || file === void 0 ? void 0 : file.fileUrl;
13832
+ if (!fileId && !externalURL) {
13833
+ continue;
13834
+ }
13835
+ fileUrl = void 0;
13836
+ if (fileId) {
13837
+ fileUrl = bruceModels.ClientFile.GetUrl({
13838
+ api: api,
13839
+ fileId: fileId,
13840
+ viaCdn: true
13841
+ });
13842
+ }
13843
+ else if (externalURL) {
13844
+ fileUrl = externalURL;
13845
+ }
13846
+ source = new Cesium.KmlDataSource();
13847
+ source.load(fileUrl);
13848
+ this.viewer.dataSources.add(source);
13849
+ this.dataSources.push(source);
13850
+ this.viewer.scene.requestRender();
13851
+ }
13852
+ return [2 /*return*/];
13853
+ }
13854
+ });
13855
+ }); })();
13426
13856
  };
13427
13857
  Manager.prototype.Dispose = function () {
13428
13858
  var _a;
@@ -20918,634 +21348,219 @@
20918
21348
  imagery = JSON.parse(JSON.stringify(imagery));
20919
21349
  for (i = 0; i < imagery.length; i++) {
20920
21350
  layer = imagery[i];
20921
- if (layer.tilesetId == bruceModels.ProjectViewTile.EDefaultImagery.BingMapsAerial) {
20922
- layer.tilesetId = bruceModels.ProjectViewTile.EDefaultImagery.MapboxSatellite;
20923
- console.warn("Cesium Ion token not set, using mapbox satellite instead of bing maps aerial.");
20924
- }
20925
- else if (layer.tilesetId == bruceModels.ProjectViewTile.EDefaultImagery.BingMapsAerialWithLabels) {
20926
- layer.tilesetId = bruceModels.ProjectViewTile.EDefaultImagery.MapboxSatellite;
20927
- console.warn("Cesium Ion token not set, using mapbox satellite instead of bing maps aerial with labels.");
20928
- }
20929
- else if (layer.tilesetId == bruceModels.ProjectViewTile.EDefaultImagery.BingMapsRoads) {
20930
- layer.tilesetId = bruceModels.ProjectViewTile.EDefaultImagery.MapBoxStreets;
20931
- console.warn("Cesium Ion token not set, using mapbox streets instead of bing maps roads.");
20932
- }
20933
- }
20934
- }
20935
- }
20936
- // We don't wait for imageries to load, this does not affect rendering other things.
20937
- exports.TileRenderEngine.Map.Navigator.Render({
20938
- apiGetter: params.apiGetter,
20939
- tiles: imagery,
20940
- viewer: params.manager.Viewer,
20941
- });
20942
- legacyRelationIds = bSettings === null || bSettings === void 0 ? void 0 : bSettings.renderedEntityRelations;
20943
- if (!legacyRelationIds) {
20944
- legacyRelationIds = [];
20945
- }
20946
- relations = bSettings === null || bSettings === void 0 ? void 0 : bSettings.renderedRelations;
20947
- if (!relations) {
20948
- relations = [];
20949
- }
20950
- viewer.scene.requestRender();
20951
- curEnabled = params.manager.GetEnabledItemIds();
20952
- newItemIds = (_5 = bSettings === null || bSettings === void 0 ? void 0 : bSettings.menuItemIds) !== null && _5 !== void 0 ? _5 : [];
20953
- for (_i = 0, curEnabled_1 = curEnabled; _i < curEnabled_1.length; _i++) {
20954
- id = curEnabled_1[_i];
20955
- shouldRemove = void 0;
20956
- if (id == RELATION_MENU_ITEM_ID) {
20957
- rendered = params.manager.GetEnabledItem(id);
20958
- shouldRemove = false;
20959
- if (!legacyRelationIds.length && !relations.length) {
20960
- shouldRemove = true;
20961
- }
20962
- // If we're about to render legacy relationships but a non-legacy item is currently enabled then we remove it.
20963
- else if (legacyRelationIds.length && (rendered === null || rendered === void 0 ? void 0 : rendered.type) != bruceModels.MenuItem.EType.Relations) {
20964
- shouldRemove = true;
20965
- }
20966
- // If we're about to render non-legacy relationships but a legacy item is currently enabled then we remove it.
20967
- else if (relations.length && (rendered === null || rendered === void 0 ? void 0 : rendered.type) != bruceModels.MenuItem.EType.Relationships) {
20968
- shouldRemove = true;
20969
- }
20970
- }
20971
- else {
20972
- shouldRemove = newItemIds.indexOf(id) === -1;
20973
- }
20974
- if (shouldRemove) {
20975
- params.manager.RemoveItemById({
20976
- menuItemId: id
20977
- });
20978
- }
20979
- }
20980
- if (!bookmark) return [3 /*break*/, 15];
20981
- return [4 /*yield*/, exports.MenuItemCreator.RenderBookmarkItems({
20982
- getters: params.getters,
20983
- manager: params.manager,
20984
- view: view,
20985
- bookmark: bookmark
20986
- })];
20987
- case 14:
20988
- _8.sent();
20989
- if (!assertIteration$1(params.viewer, iteration)) {
20990
- return [2 /*return*/];
20991
- }
20992
- _8.label = 15;
20993
- case 15:
20994
- if (legacyRelationIds.length || relations.length) {
20995
- if (relations.length) {
20996
- menuItem = {
20997
- id: RELATION_MENU_ITEM_ID,
20998
- Caption: "Entity relations",
20999
- relations: relations,
21000
- Type: bruceModels.MenuItem.EType.Relationships
21001
- };
21002
- params.manager.RenderItem({
21003
- getters: params.getters,
21004
- item: menuItem
21005
- });
21006
- }
21007
- else if (legacyRelationIds.length) {
21008
- menuItem = {
21009
- id: RELATION_MENU_ITEM_ID,
21010
- Caption: "Entity relations",
21011
- BruceEntity: {
21012
- EntityIds: legacyRelationIds
21013
- },
21014
- Type: bruceModels.MenuItem.EType.Relations
21015
- };
21016
- params.manager.RenderItem({
21017
- getters: params.getters,
21018
- item: menuItem
21019
- });
21020
- }
21021
- if (!assertIteration$1(params.viewer, iteration)) {
21022
- return [2 /*return*/];
21023
- }
21024
- }
21025
- gOcclusion = bSettings === null || bSettings === void 0 ? void 0 : bSettings.groundOcclusion;
21026
- if (gOcclusion == null) {
21027
- gOcclusion = (_6 = defaults === null || defaults === void 0 ? void 0 : defaults.settings) === null || _6 === void 0 ? void 0 : _6.groundOcclusion;
21028
- }
21029
- if (gOcclusion == null) {
21030
- // TODO: Need global default.
21031
- gOcclusion = true;
21032
- }
21033
- scene.globe.depthTestAgainstTerrain = Boolean(gOcclusion);
21034
- return [2 /*return*/];
21035
- }
21036
- });
21037
- });
21038
- }
21039
- (function (ViewRenderEngine) {
21040
- function Render(params) {
21041
- var _a;
21042
- return __awaiter(this, void 0, void 0, function () {
21043
- var iteration, api, view, _b, bookmark, bookmarkId, _c, version, bWidget;
21044
- return __generator(this, function (_d) {
21045
- switch (_d.label) {
21046
- case 0:
21047
- if (!params.manager && params.viewer) {
21048
- params.manager = exports.ViewerUtils.GetManager({
21049
- viewer: params.viewer,
21050
- createIfMissing: true
21051
- });
21052
- }
21053
- else if (!params.viewer && params.manager) {
21054
- params.viewer = params.manager.Viewer;
21055
- }
21056
- iteration = newIteration$1(params.viewer);
21057
- if (!params.getters) {
21058
- params.getters = bruceModels.ENVIRONMENT.Api();
21059
- }
21060
- if (params.apiGetter && !params.getters) {
21061
- console.warn("ViewRenderEngine.Render(): Please pass getters instead of apiGetter. This is now deprecated due to needing access to other kinds of apis.");
21062
- }
21063
- else if (!params.apiGetter) {
21064
- params.apiGetter = params.getters.GetBruceGetter();
21065
- }
21066
- api = params.getters.GetBruceApi();
21067
- if (!params.view) return [3 /*break*/, 1];
21068
- _b = params.view;
21069
- return [3 /*break*/, 3];
21070
- case 1: return [4 /*yield*/, bruceModels.ProjectView.Get({
21071
- api: api,
21072
- viewId: params.viewId
21073
- })];
21074
- case 2:
21075
- _b = (_d.sent()).view;
21076
- _d.label = 3;
21077
- case 3:
21078
- view = _b;
21079
- bookmark = params.bookmark;
21080
- if (!!bookmark) return [3 /*break*/, 7];
21081
- bookmarkId = params.bookmarkId;
21082
- if (!bookmarkId) {
21083
- bookmarkId = view.DefaultUISlideID;
21084
- }
21085
- if (!bookmarkId) return [3 /*break*/, 5];
21086
- return [4 /*yield*/, bruceModels.ProjectViewBookmark.Get({
21087
- api: api,
21088
- viewId: params.viewId,
21089
- bookmarkId: bookmarkId
21090
- })];
21091
- case 4:
21092
- _c = (_d.sent()).bookmark;
21093
- return [3 /*break*/, 6];
21094
- case 5:
21095
- _c = null;
21096
- _d.label = 6;
21097
- case 6:
21098
- bookmark = _c;
21099
- _d.label = 7;
21100
- case 7:
21101
- if (!assertIteration$1(params.viewer, iteration)) {
21102
- return [2 /*return*/];
21103
- }
21104
- version = view.DataVersion;
21105
- if (!(version == 1)) return [3 /*break*/, 9];
21106
- return [4 /*yield*/, renderLegacyNavigator(iteration, params, bookmark, view)];
21107
- case 8:
21108
- _d.sent();
21109
- return [3 /*break*/, 11];
21110
- case 9: return [4 /*yield*/, renderNavigator(iteration, params, bookmark, view, params.getters)];
21111
- case 10:
21112
- _d.sent();
21113
- _d.label = 11;
21114
- case 11:
21115
- if (!assertIteration$1(params.viewer, iteration)) {
21116
- return [2 /*return*/];
21117
- }
21118
- bWidget = (_a = params.viewer) === null || _a === void 0 ? void 0 : _a[VIEWER_BOOKMARKS_WIDGET_KEY];
21119
- if (bWidget) {
21120
- bWidget.ViewId = params.viewId ? params.viewId : view === null || view === void 0 ? void 0 : view.ID;
21121
- bWidget.LastEnabledBookmarkId = params.bookmarkId ? params.bookmarkId : bookmark === null || bookmark === void 0 ? void 0 : bookmark.ID;
21122
- }
21123
- return [2 /*return*/];
21124
- }
21125
- });
21126
- });
21127
- }
21128
- ViewRenderEngine.Render = Render;
21129
- })(exports.ViewRenderEngine || (exports.ViewRenderEngine = {}));
21130
-
21131
- var TIME_LAG = 300;
21132
- var POSITION_CHECK_TIMER = 950;
21133
- var DEFAULT_GROUNDED_HEIGHT = 300;
21134
- var MINIMUM_VIEW_AREA_SIZE_DEGREES = 0.01;
21135
- var NET_STEP_PERCENT = 5;
21136
- var BORDER_STEPS = 3;
21137
- var ESearchStatus;
21138
- (function (ESearchStatus) {
21139
- ESearchStatus[ESearchStatus["LocationFound"] = 1] = "LocationFound";
21140
- ESearchStatus[ESearchStatus["LocationChanged"] = 2] = "LocationChanged";
21141
- ESearchStatus[ESearchStatus["LocationMissing"] = 3] = "LocationMissing";
21142
- })(ESearchStatus || (ESearchStatus = {}));
21143
- /**
21144
- * @param viewer
21145
- * @param center the previously calculated center of the view area. This is in degrees.
21146
- * @returns
21147
- */
21148
- function netScanViewForBoundaries(viewer, center) {
21149
- var maxLong = -2 * Math.PI;
21150
- var minLong = 2 * Math.PI;
21151
- var maxLat = -2 * Math.PI;
21152
- var minLat = 2 * Math.PI;
21153
- var found = 0;
21154
- var updateMinMax = function (lon, lat) {
21155
- // Check to see if given lon/lat (in radians) are within valid range.
21156
- if (lon < -Math.PI || lon > Math.PI || lat < -Math.PI / 2 || lat > Math.PI / 2) {
21157
- return;
21158
- }
21159
- maxLong = Math.max(maxLong, lon);
21160
- maxLat = Math.max(maxLat, lat);
21161
- minLong = Math.min(minLong, lon);
21162
- minLat = Math.min(minLat, lat);
21163
- };
21164
- var updateMinMaxForPoint = function (stepX, stepY) {
21165
- var x = Math.round(0 + (viewer.container.clientWidth / 100) * (stepX * NET_STEP_PERCENT));
21166
- var y = Math.round(0 + (viewer.container.clientHeight / 100) * (stepY * NET_STEP_PERCENT));
21167
- var winPos = new Cesium.Cartesian2(x, y);
21168
- try {
21169
- var intersection = getAdjustedGroundIntersectionOfCameraRay(viewer, winPos);
21170
- if (intersection) {
21171
- var point = Cesium.Cartographic.fromCartesian(intersection, viewer.scene.globe.ellipsoid);
21172
- updateMinMax(point.longitude, point.latitude);
21173
- found++;
21174
- }
21175
- }
21176
- catch (e) {
21177
- console.error(e);
21178
- }
21179
- };
21180
- // Outer circle.
21181
- updateMinMaxForPoint(BORDER_STEPS, BORDER_STEPS);
21182
- updateMinMaxForPoint((100 / NET_STEP_PERCENT) - BORDER_STEPS, BORDER_STEPS);
21183
- updateMinMaxForPoint(BORDER_STEPS, (100 / NET_STEP_PERCENT) - BORDER_STEPS);
21184
- updateMinMaxForPoint((100 / NET_STEP_PERCENT) - BORDER_STEPS, (100 / NET_STEP_PERCENT) - BORDER_STEPS);
21185
- // Inner circle.
21186
- updateMinMaxForPoint(BORDER_STEPS * 2, BORDER_STEPS * 2);
21187
- updateMinMaxForPoint((100 / NET_STEP_PERCENT) - BORDER_STEPS * 2, BORDER_STEPS * 2);
21188
- updateMinMaxForPoint(BORDER_STEPS * 2, (100 / NET_STEP_PERCENT) - BORDER_STEPS * 2);
21189
- updateMinMaxForPoint((100 / NET_STEP_PERCENT) - BORDER_STEPS * 2, (100 / NET_STEP_PERCENT) - BORDER_STEPS * 2);
21190
- // If we failed to find intersections and a center-point was provided, then we can use that to make some guesses.
21191
- // This happens if terrain is hidden, and there's nothing to intersect with.
21192
- if (center && found <= 0) {
21193
- updateMinMax(Cesium.Math.toRadians(center.longitude), Cesium.Math.toRadians(center.latitude));
21194
- found += 1;
21195
- // We'll use the camera height as an indicator on size of the rect.
21196
- var size = viewer.camera.positionCartographic.height;
21197
- var pitch = viewer.camera.pitch;
21198
- var distance = size / Math.tan(pitch);
21199
- var p1 = _offsetPoint({
21200
- altitude: center.altitude,
21201
- latitude: center.latitude,
21202
- longitude: center.longitude
21203
- }, distance, 45);
21204
- var p2 = _offsetPoint({
21205
- altitude: center.altitude,
21206
- latitude: center.latitude,
21207
- longitude: center.longitude
21208
- }, -distance, 45);
21209
- if (p1 === null || p1 === void 0 ? void 0 : p1.latitude) {
21210
- updateMinMax(Cesium.Math.toRadians(p1.longitude), Cesium.Math.toRadians(p1.latitude));
21211
- }
21212
- if (p2 === null || p2 === void 0 ? void 0 : p2.latitude) {
21213
- updateMinMax(Cesium.Math.toRadians(p2.longitude), Cesium.Math.toRadians(p2.latitude));
21214
- }
21215
- }
21216
- if (found > 0) {
21217
- var viewRect = {
21218
- east: maxLong,
21219
- west: minLong,
21220
- north: maxLat,
21221
- south: minLat
21222
- };
21223
- return viewRect;
21224
- }
21225
- return null;
21226
- }
21227
- /**
21228
- * Moves a given point by a given distance towards a heading.
21229
- * @param point in degrees.
21230
- * @param distance in meters.
21231
- * @param heading in degrees.
21232
- * @returns
21233
- */
21234
- function _offsetPoint(point, distance, heading) {
21235
- // Radius of earth.
21236
- var radius = 6371e3;
21237
- var δ = distance / radius;
21238
- var θ = Cesium.Math.toRadians(heading);
21239
- var φ1 = Cesium.Math.toRadians(point.latitude);
21240
- var λ1 = Cesium.Math.toRadians(point.longitude);
21241
- var sinφ2 = Math.sin(φ1) * Math.cos(δ) + Math.cos(φ1) * Math.sin(δ) * Math.cos(θ);
21242
- var φ2 = Math.asin(sinφ2);
21243
- var y = Math.sin(θ) * Math.sin(δ) * Math.cos(φ1);
21244
- var x = Math.cos(δ) - Math.sin(φ1) * sinφ2;
21245
- var λ2 = λ1 + Math.atan2(y, x);
21246
- return {
21247
- altitude: point.altitude,
21248
- latitude: Cesium.Math.toDegrees(φ2),
21249
- longitude: Cesium.Math.toDegrees(λ2)
21250
- };
21251
- }
21252
- /**
21253
- * @param pos3d
21254
- * @param distance in meters
21255
- * @param heading in degrees
21256
- * @returns
21257
- */
21258
- function _offsetPos3d(pos3d, distance, heading) {
21259
- var carto = Cesium.Cartographic.fromCartesian(pos3d);
21260
- var newCarto = _offsetPoint({
21261
- altitude: carto.height,
21262
- latitude: Cesium.Math.toDegrees(carto.latitude),
21263
- longitude: Cesium.Math.toDegrees(carto.longitude)
21264
- }, distance, heading);
21265
- return Cesium.Cartesian3.fromDegrees(newCarto.longitude, newCarto.latitude, newCarto.altitude);
21266
- }
21267
- /**
21268
- * Returns the intersection of the camera ray with the ground.
21269
- * @param viewer
21270
- * @param screenPos
21271
- * @returns
21272
- */
21273
- function getAdjustedGroundIntersectionOfCameraRay(viewer, screenPos) {
21274
- var ray = viewer.camera.getPickRay(screenPos);
21275
- var intersection = ray ? viewer.scene.globe.pick(ray, viewer.scene) : null;
21276
- if (intersection) {
21277
- return intersection;
21278
- }
21279
- return null;
21280
- }
21281
- /**
21282
- * Returns the intersection of the camera ray with the ground.
21283
- * If no intersection is found, then a "guess" is made based on the camera angle and height.
21284
- * The guess is made at the center of the view! It ignores the screenPos.
21285
- * @param viewer
21286
- * @param screenPos
21287
- * @returns
21288
- */
21289
- function getGroundCenterOfCameraRay(viewer, screenPos) {
21290
- var _a, _b;
21291
- var ray = viewer.camera.getPickRay(screenPos);
21292
- var intersection = ray ? viewer.scene.globe.pick(ray, viewer.scene) : null;
21293
- if (intersection) {
21294
- return intersection;
21295
- }
21296
- // The fallback will be to "guess" where the intersection might be.
21297
- // This happens if terrain is hidden, and there's nothing to intersect with.
21298
- // We will use the camera angle + camera height.
21299
- // Eg: if camera is looking straight down and is 100 meters above the ground, then the intersection will be 100 meters below the camera.
21300
- var cameraHeight = viewer.camera.positionCartographic.height;
21301
- if (!isNaN(cameraHeight) && cameraHeight != null && ((_b = (_a = viewer.camera) === null || _a === void 0 ? void 0 : _a.position) === null || _b === void 0 ? void 0 : _b.clone)) {
21302
- var cameraPos3d = viewer.camera.position.clone();
21303
- var pitch = viewer.camera.pitch;
21304
- var distance = cameraHeight / Math.tan(pitch);
21305
- return _offsetPos3d(cameraPos3d, -distance, Cesium.Math.toDegrees(viewer.camera.heading));
21306
- }
21307
- return null;
21308
- }
21309
- function areBoundsEqual(a, b) {
21310
- return a.north == b.north && a.south == b.south && a.east == b.east && a.west == b.west;
21311
- }
21312
- function arePosEqual(a, b) {
21313
- return a.latitude == b.latitude && a.longitude == b.longitude;
21314
- }
21315
- (function (CesiumViewMonitor) {
21316
- /**
21317
- * Monitors and emits events when the Cesium view changes.
21318
- */
21319
- var Monitor = /** @class */ (function () {
21320
- function Monitor(viewer) {
21321
- var _this = this;
21322
- this.target = null;
21323
- this.bounds = null;
21324
- this.disposed = false;
21325
- this.updatedEvent = null;
21326
- this.entity = null;
21327
- this.updating = false;
21328
- this.viewer = viewer;
21329
- this.tryEmitUpdate();
21330
- this.checkInterval = setInterval(function () {
21331
- _this.updateQueue();
21332
- }, POSITION_CHECK_TIMER);
21333
- }
21334
- Object.defineProperty(Monitor.prototype, "Disposed", {
21335
- get: function () {
21336
- return this.disposed;
21337
- },
21338
- enumerable: false,
21339
- configurable: true
21340
- });
21341
- Monitor.prototype.createEntity = function () {
21342
- var _this = this;
21343
- if (this.entity) {
21344
- return;
21345
- }
21346
- this.entity = this.viewer.entities.add({
21347
- position: new Cesium.CallbackProperty(function () {
21348
- return _this.target ? Cesium.Cartesian3.fromDegrees(_this.target.longitude, _this.target.latitude) : null;
21349
- }, false),
21350
- point: {
21351
- pixelSize: 8,
21352
- color: Cesium.Color.ORANGE,
21353
- heightReference: Cesium.HeightReference.NONE
21354
- },
21355
- rectangle: {
21356
- coordinates: new Cesium.CallbackProperty(function () {
21357
- return _this.bounds ? Cesium.Rectangle.fromDegrees(_this.bounds.west, _this.bounds.south, _this.bounds.east, _this.bounds.north) : null;
21358
- }, false),
21359
- material: Cesium.Color.fromCssColorString('#ff0000').withAlpha(0.4),
21360
- zIndex: 1,
21361
- heightReference: Cesium.HeightReference.NONE
21362
- }
21363
- });
21364
- };
21365
- Monitor.prototype.destroyEntity = function () {
21366
- if (this.entity && this.viewer.entities.contains(this.entity)) {
21367
- this.viewer.entities.remove(this.entity);
21368
- }
21369
- this.entity = null;
21370
- };
21371
- Monitor.prototype.Updated = function () {
21372
- if (!this.updatedEvent) {
21373
- this.updatedEvent = new bruceModels.BruceEvent();
21374
- }
21375
- return this.updatedEvent;
21376
- };
21377
- Monitor.prototype.GetBounds = function () {
21378
- return this.bounds;
21379
- };
21380
- Monitor.prototype.GetTarget = function () {
21381
- return this.target;
21382
- };
21383
- Monitor.prototype.DoUpdate = function () {
21384
- this.tryEmitUpdate();
21385
- };
21386
- Monitor.prototype.Dispose = function () {
21387
- if (this.disposed) {
21388
- return;
21389
- }
21390
- this.disposed = true;
21391
- clearInterval(this.checkInterval);
21392
- this.destroyEntity();
21393
- };
21394
- Monitor.prototype.tryDoUpdate = function () {
21395
- var _a;
21396
- return __awaiter(this, void 0, void 0, function () {
21397
- var viewRect, center, camera, terrData, cameraPosition, terrHeight, viewRectRad, windowPosition, intersection, point, viewRectRad, centerLong, centerLat;
21398
- return __generator(this, function (_b) {
21399
- switch (_b.label) {
21400
- case 0:
21401
- if (!this.viewer || this.viewer.isDestroyed()) {
21402
- this.Dispose();
21403
- return [2 /*return*/, ESearchStatus.LocationMissing];
21404
- }
21405
- viewRect = null;
21406
- center = null;
21407
- camera = this.viewer.camera;
21408
- return [4 /*yield*/, exports.DrawingUtils.GetTerrainHeight({
21409
- pos3d: camera.position,
21410
- viewer: this.viewer
21411
- })];
21412
- case 1:
21413
- terrData = _b.sent();
21414
- cameraPosition = this.viewer.camera.positionCartographic;
21415
- terrHeight = terrData.error ? cameraPosition.height + DEFAULT_GROUNDED_HEIGHT : terrData.height;
21416
- // We are almost at the ground, screw horizon, just load around.
21417
- if (terrHeight && ((cameraPosition.height - terrHeight) < DEFAULT_GROUNDED_HEIGHT)) {
21418
- // View area calculation.
21419
- viewRect = {};
21420
- viewRectRad = netScanViewForBoundaries(this.viewer);
21421
- if (viewRectRad &&
21422
- viewRectRad.east &&
21423
- viewRectRad.west &&
21424
- viewRectRad.north &&
21425
- viewRectRad.south) {
21426
- viewRect.east = Cesium.Math.toDegrees(Math.max(viewRectRad.east, cameraPosition.longitude));
21427
- viewRect.west = Cesium.Math.toDegrees(Math.min(viewRectRad.west, cameraPosition.longitude));
21428
- viewRect.south = Cesium.Math.toDegrees(Math.min(viewRectRad.south, cameraPosition.latitude));
21429
- viewRect.north = Cesium.Math.toDegrees(Math.max(viewRectRad.north, cameraPosition.latitude));
21430
- }
21431
- else {
21432
- viewRect.east = cameraPosition.longitude;
21433
- viewRect.west = cameraPosition.longitude;
21434
- viewRect.south = cameraPosition.latitude;
21435
- viewRect.north = cameraPosition.latitude;
21436
- }
21437
- center = {};
21438
- center.latitude = Cesium.Math.toDegrees(camera.positionCartographic.latitude);
21439
- center.longitude = Cesium.Math.toDegrees(camera.positionCartographic.longitude);
21440
- }
21441
- else {
21442
- windowPosition = new Cesium.Cartesian2(this.viewer.container.clientWidth / 2, this.viewer.container.clientHeight / 2);
21443
- intersection = getGroundCenterOfCameraRay(this.viewer, windowPosition);
21444
- point = null;
21445
- if (intersection) {
21446
- point = Cesium.Cartographic.fromCartesian(intersection, this.viewer.scene.globe.ellipsoid);
21447
- }
21448
- if (point) {
21449
- center = {};
21450
- center.latitude = Cesium.Math.toDegrees(point.latitude);
21451
- center.longitude = Cesium.Math.toDegrees(point.longitude);
21452
- viewRectRad = netScanViewForBoundaries(this.viewer, center);
21453
- if (viewRectRad) {
21454
- viewRect = {};
21455
- viewRect.east = Cesium.Math.toDegrees(viewRectRad.east);
21456
- viewRect.west = Cesium.Math.toDegrees(viewRectRad.west);
21457
- viewRect.south = Cesium.Math.toDegrees(viewRectRad.south);
21458
- viewRect.north = Cesium.Math.toDegrees(viewRectRad.north);
21459
- }
21460
- }
21461
- }
21462
- // Minimal field of view.
21463
- if (viewRect) {
21464
- centerLong = (viewRect.east + viewRect.west) / 2;
21465
- centerLat = (viewRect.north + viewRect.south) / 2;
21466
- viewRect.east = Math.max(viewRect.east, centerLong + (MINIMUM_VIEW_AREA_SIZE_DEGREES / 2));
21467
- viewRect.west = Math.min(viewRect.west, centerLong - (MINIMUM_VIEW_AREA_SIZE_DEGREES / 2));
21468
- viewRect.south = Math.min(viewRect.south, centerLat - (MINIMUM_VIEW_AREA_SIZE_DEGREES / 2));
21469
- viewRect.north = Math.max(viewRect.north, centerLat + (MINIMUM_VIEW_AREA_SIZE_DEGREES / 2));
21470
- viewRect.alt = (_a = this.viewer.scene.camera.positionCartographic) === null || _a === void 0 ? void 0 : _a.height;
21471
- }
21472
- if (center && viewRect) {
21473
- if ((!this.target || (this.target && !arePosEqual(this.target, center))) ||
21474
- (!this.bounds || (this.bounds && !areBoundsEqual(this.bounds, viewRect)))) {
21475
- this.target = center;
21476
- this.bounds = viewRect;
21477
- return [2 /*return*/, ESearchStatus.LocationChanged];
21351
+ if (layer.tilesetId == bruceModels.ProjectViewTile.EDefaultImagery.BingMapsAerial) {
21352
+ layer.tilesetId = bruceModels.ProjectViewTile.EDefaultImagery.MapboxSatellite;
21353
+ console.warn("Cesium Ion token not set, using mapbox satellite instead of bing maps aerial.");
21354
+ }
21355
+ else if (layer.tilesetId == bruceModels.ProjectViewTile.EDefaultImagery.BingMapsAerialWithLabels) {
21356
+ layer.tilesetId = bruceModels.ProjectViewTile.EDefaultImagery.MapboxSatellite;
21357
+ console.warn("Cesium Ion token not set, using mapbox satellite instead of bing maps aerial with labels.");
21358
+ }
21359
+ else if (layer.tilesetId == bruceModels.ProjectViewTile.EDefaultImagery.BingMapsRoads) {
21360
+ layer.tilesetId = bruceModels.ProjectViewTile.EDefaultImagery.MapBoxStreets;
21361
+ console.warn("Cesium Ion token not set, using mapbox streets instead of bing maps roads.");
21478
21362
  }
21479
- return [2 /*return*/, ESearchStatus.LocationFound];
21480
21363
  }
21481
- return [2 /*return*/, ESearchStatus.LocationMissing];
21364
+ }
21482
21365
  }
21483
- });
21484
- });
21485
- };
21486
- Monitor.prototype.tryEmitUpdate = function () {
21487
- var _a;
21488
- return __awaiter(this, void 0, void 0, function () {
21489
- var searchResult, interest, e_1;
21490
- return __generator(this, function (_b) {
21491
- switch (_b.label) {
21492
- case 0:
21493
- if (this.updating) {
21494
- return [2 /*return*/];
21366
+ // We don't wait for imageries to load, this does not affect rendering other things.
21367
+ exports.TileRenderEngine.Map.Navigator.Render({
21368
+ apiGetter: params.apiGetter,
21369
+ tiles: imagery,
21370
+ viewer: params.manager.Viewer,
21371
+ });
21372
+ legacyRelationIds = bSettings === null || bSettings === void 0 ? void 0 : bSettings.renderedEntityRelations;
21373
+ if (!legacyRelationIds) {
21374
+ legacyRelationIds = [];
21375
+ }
21376
+ relations = bSettings === null || bSettings === void 0 ? void 0 : bSettings.renderedRelations;
21377
+ if (!relations) {
21378
+ relations = [];
21379
+ }
21380
+ viewer.scene.requestRender();
21381
+ curEnabled = params.manager.GetEnabledItemIds();
21382
+ newItemIds = (_5 = bSettings === null || bSettings === void 0 ? void 0 : bSettings.menuItemIds) !== null && _5 !== void 0 ? _5 : [];
21383
+ for (_i = 0, curEnabled_1 = curEnabled; _i < curEnabled_1.length; _i++) {
21384
+ id = curEnabled_1[_i];
21385
+ shouldRemove = void 0;
21386
+ if (id == RELATION_MENU_ITEM_ID) {
21387
+ rendered = params.manager.GetEnabledItem(id);
21388
+ shouldRemove = false;
21389
+ if (!legacyRelationIds.length && !relations.length) {
21390
+ shouldRemove = true;
21495
21391
  }
21496
- this.updating = true;
21497
- _b.label = 1;
21498
- case 1:
21499
- _b.trys.push([1, 3, , 4]);
21500
- return [4 /*yield*/, this.tryDoUpdate()];
21501
- case 2:
21502
- searchResult = _b.sent();
21503
- if (searchResult == ESearchStatus.LocationChanged) {
21504
- interest = {
21505
- bounds: this.bounds,
21506
- target: this.target
21507
- };
21508
- // this.createEntity();
21509
- (_a = this.updatedEvent) === null || _a === void 0 ? void 0 : _a.Trigger(interest);
21392
+ // If we're about to render legacy relationships but a non-legacy item is currently enabled then we remove it.
21393
+ else if (legacyRelationIds.length && (rendered === null || rendered === void 0 ? void 0 : rendered.type) != bruceModels.MenuItem.EType.Relations) {
21394
+ shouldRemove = true;
21510
21395
  }
21511
- else if (searchResult == ESearchStatus.LocationMissing) {
21512
- this.updateQueue();
21396
+ // If we're about to render non-legacy relationships but a legacy item is currently enabled then we remove it.
21397
+ else if (relations.length && (rendered === null || rendered === void 0 ? void 0 : rendered.type) != bruceModels.MenuItem.EType.Relationships) {
21398
+ shouldRemove = true;
21513
21399
  }
21514
- return [3 /*break*/, 4];
21515
- case 3:
21516
- e_1 = _b.sent();
21517
- console.error(e_1);
21518
- this.updateQueue();
21519
- return [3 /*break*/, 4];
21520
- case 4:
21521
- this.updating = false;
21400
+ }
21401
+ else {
21402
+ shouldRemove = newItemIds.indexOf(id) === -1;
21403
+ }
21404
+ if (shouldRemove) {
21405
+ params.manager.RemoveItemById({
21406
+ menuItemId: id
21407
+ });
21408
+ }
21409
+ }
21410
+ if (!bookmark) return [3 /*break*/, 15];
21411
+ return [4 /*yield*/, exports.MenuItemCreator.RenderBookmarkItems({
21412
+ getters: params.getters,
21413
+ manager: params.manager,
21414
+ view: view,
21415
+ bookmark: bookmark
21416
+ })];
21417
+ case 14:
21418
+ _8.sent();
21419
+ if (!assertIteration$1(params.viewer, iteration)) {
21420
+ return [2 /*return*/];
21421
+ }
21422
+ _8.label = 15;
21423
+ case 15:
21424
+ if (legacyRelationIds.length || relations.length) {
21425
+ if (relations.length) {
21426
+ menuItem = {
21427
+ id: RELATION_MENU_ITEM_ID,
21428
+ Caption: "Entity relations",
21429
+ relations: relations,
21430
+ Type: bruceModels.MenuItem.EType.Relationships
21431
+ };
21432
+ params.manager.RenderItem({
21433
+ getters: params.getters,
21434
+ item: menuItem
21435
+ });
21436
+ }
21437
+ else if (legacyRelationIds.length) {
21438
+ menuItem = {
21439
+ id: RELATION_MENU_ITEM_ID,
21440
+ Caption: "Entity relations",
21441
+ BruceEntity: {
21442
+ EntityIds: legacyRelationIds
21443
+ },
21444
+ Type: bruceModels.MenuItem.EType.Relations
21445
+ };
21446
+ params.manager.RenderItem({
21447
+ getters: params.getters,
21448
+ item: menuItem
21449
+ });
21450
+ }
21451
+ if (!assertIteration$1(params.viewer, iteration)) {
21522
21452
  return [2 /*return*/];
21453
+ }
21523
21454
  }
21524
- });
21525
- });
21526
- };
21527
- Monitor.prototype.queuePosition = function (lag) {
21528
- var _this = this;
21529
- if (this.pendingTimeout) {
21530
- clearTimeout(this.pendingTimeout);
21455
+ gOcclusion = bSettings === null || bSettings === void 0 ? void 0 : bSettings.groundOcclusion;
21456
+ if (gOcclusion == null) {
21457
+ gOcclusion = (_6 = defaults === null || defaults === void 0 ? void 0 : defaults.settings) === null || _6 === void 0 ? void 0 : _6.groundOcclusion;
21458
+ }
21459
+ if (gOcclusion == null) {
21460
+ // TODO: Need global default.
21461
+ gOcclusion = true;
21462
+ }
21463
+ scene.globe.depthTestAgainstTerrain = Boolean(gOcclusion);
21464
+ return [2 /*return*/];
21531
21465
  }
21532
- this.pendingTimeout = setTimeout(function () {
21533
- if (!_this.disposed) {
21534
- _this.tryEmitUpdate();
21466
+ });
21467
+ });
21468
+ }
21469
+ (function (ViewRenderEngine) {
21470
+ function Render(params) {
21471
+ var _a;
21472
+ return __awaiter(this, void 0, void 0, function () {
21473
+ var iteration, api, view, _b, bookmark, bookmarkId, _c, version, bWidget;
21474
+ return __generator(this, function (_d) {
21475
+ switch (_d.label) {
21476
+ case 0:
21477
+ if (!params.manager && params.viewer) {
21478
+ params.manager = exports.ViewerUtils.GetManager({
21479
+ viewer: params.viewer,
21480
+ createIfMissing: true
21481
+ });
21482
+ }
21483
+ else if (!params.viewer && params.manager) {
21484
+ params.viewer = params.manager.Viewer;
21485
+ }
21486
+ iteration = newIteration$1(params.viewer);
21487
+ if (!params.getters) {
21488
+ params.getters = bruceModels.ENVIRONMENT.Api();
21489
+ }
21490
+ if (params.apiGetter && !params.getters) {
21491
+ console.warn("ViewRenderEngine.Render(): Please pass getters instead of apiGetter. This is now deprecated due to needing access to other kinds of apis.");
21492
+ }
21493
+ else if (!params.apiGetter) {
21494
+ params.apiGetter = params.getters.GetBruceGetter();
21495
+ }
21496
+ api = params.getters.GetBruceApi();
21497
+ if (!params.view) return [3 /*break*/, 1];
21498
+ _b = params.view;
21499
+ return [3 /*break*/, 3];
21500
+ case 1: return [4 /*yield*/, bruceModels.ProjectView.Get({
21501
+ api: api,
21502
+ viewId: params.viewId
21503
+ })];
21504
+ case 2:
21505
+ _b = (_d.sent()).view;
21506
+ _d.label = 3;
21507
+ case 3:
21508
+ view = _b;
21509
+ bookmark = params.bookmark;
21510
+ if (!!bookmark) return [3 /*break*/, 7];
21511
+ bookmarkId = params.bookmarkId;
21512
+ if (!bookmarkId) {
21513
+ bookmarkId = view.DefaultUISlideID;
21514
+ }
21515
+ if (!bookmarkId) return [3 /*break*/, 5];
21516
+ return [4 /*yield*/, bruceModels.ProjectViewBookmark.Get({
21517
+ api: api,
21518
+ viewId: params.viewId,
21519
+ bookmarkId: bookmarkId
21520
+ })];
21521
+ case 4:
21522
+ _c = (_d.sent()).bookmark;
21523
+ return [3 /*break*/, 6];
21524
+ case 5:
21525
+ _c = null;
21526
+ _d.label = 6;
21527
+ case 6:
21528
+ bookmark = _c;
21529
+ _d.label = 7;
21530
+ case 7:
21531
+ if (!assertIteration$1(params.viewer, iteration)) {
21532
+ return [2 /*return*/];
21533
+ }
21534
+ version = view.DataVersion;
21535
+ if (!(version == 1)) return [3 /*break*/, 9];
21536
+ return [4 /*yield*/, renderLegacyNavigator(iteration, params, bookmark, view)];
21537
+ case 8:
21538
+ _d.sent();
21539
+ return [3 /*break*/, 11];
21540
+ case 9: return [4 /*yield*/, renderNavigator(iteration, params, bookmark, view, params.getters)];
21541
+ case 10:
21542
+ _d.sent();
21543
+ _d.label = 11;
21544
+ case 11:
21545
+ if (!assertIteration$1(params.viewer, iteration)) {
21546
+ return [2 /*return*/];
21547
+ }
21548
+ bWidget = (_a = params.viewer) === null || _a === void 0 ? void 0 : _a[VIEWER_BOOKMARKS_WIDGET_KEY];
21549
+ if (bWidget) {
21550
+ bWidget.ViewId = params.viewId ? params.viewId : view === null || view === void 0 ? void 0 : view.ID;
21551
+ bWidget.LastEnabledBookmarkId = params.bookmarkId ? params.bookmarkId : bookmark === null || bookmark === void 0 ? void 0 : bookmark.ID;
21552
+ }
21553
+ return [2 /*return*/];
21535
21554
  }
21536
- }, lag);
21537
- };
21538
- Monitor.prototype.updateQueue = function () {
21539
- this.queuePosition(TIME_LAG);
21540
- };
21541
- return Monitor;
21542
- }());
21543
- CesiumViewMonitor.Monitor = Monitor;
21544
- })(exports.CesiumViewMonitor || (exports.CesiumViewMonitor = {}));
21555
+ });
21556
+ });
21557
+ }
21558
+ ViewRenderEngine.Render = Render;
21559
+ })(exports.ViewRenderEngine || (exports.ViewRenderEngine = {}));
21545
21560
 
21546
- var VERSION$1 = "3.4.8";
21561
+ var VERSION = "3.4.9";
21547
21562
 
21548
- exports.VERSION = VERSION$1;
21563
+ exports.VERSION = VERSION;
21549
21564
  exports.CesiumParabola = CesiumParabola;
21550
21565
  exports.CESIUM_INSPECTOR_KEY = CESIUM_INSPECTOR_KEY;
21551
21566
  exports.Draw3dPolygon = Draw3dPolygon;