bruce-cesium 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +0 -0
  2. package/dist/bruce-cesium.es5.js +2766 -0
  3. package/dist/bruce-cesium.es5.js.map +1 -0
  4. package/dist/bruce-cesium.umd.js +2766 -0
  5. package/dist/bruce-cesium.umd.js.map +1 -0
  6. package/dist/lib/bruce-cesium.js +25 -0
  7. package/dist/lib/bruce-cesium.js.map +1 -0
  8. package/dist/lib/rendering/entity-render-engine.js +803 -0
  9. package/dist/lib/rendering/entity-render-engine.js.map +1 -0
  10. package/dist/lib/rendering/menu-item-manager.js +178 -0
  11. package/dist/lib/rendering/menu-item-manager.js.map +1 -0
  12. package/dist/lib/rendering/render-helper.js +169 -0
  13. package/dist/lib/rendering/render-helper.js.map +1 -0
  14. package/dist/lib/rendering/render-managers/entities/entities-ids-render-manager.js +138 -0
  15. package/dist/lib/rendering/render-managers/entities/entities-ids-render-manager.js.map +1 -0
  16. package/dist/lib/rendering/render-managers/entities/entities-loaded-render-manager.js +135 -0
  17. package/dist/lib/rendering/render-managers/entities/entities-loaded-render-manager.js.map +1 -0
  18. package/dist/lib/rendering/render-managers/entities/entities-render-manager.js +212 -0
  19. package/dist/lib/rendering/render-managers/entities/entities-render-manager.js.map +1 -0
  20. package/dist/lib/rendering/render-managers/entities/entity-render-manager.js +133 -0
  21. package/dist/lib/rendering/render-managers/entities/entity-render-manager.js.map +1 -0
  22. package/dist/lib/rendering/render-managers/render-manager.js +32 -0
  23. package/dist/lib/rendering/render-managers/render-manager.js.map +1 -0
  24. package/dist/lib/rendering/render-managers/tilesets/tileset-cad-render-manager.js +229 -0
  25. package/dist/lib/rendering/render-managers/tilesets/tileset-cad-render-manager.js.map +1 -0
  26. package/dist/lib/rendering/tileset-render-engine.js +472 -0
  27. package/dist/lib/rendering/tileset-render-engine.js.map +1 -0
  28. package/dist/lib/rendering/visuals-register.js +199 -0
  29. package/dist/lib/rendering/visuals-register.js.map +1 -0
  30. package/dist/lib/utils/drawing-utils.js +35 -0
  31. package/dist/lib/utils/drawing-utils.js.map +1 -0
  32. package/dist/lib/utils/entity-utils.js +67 -0
  33. package/dist/lib/utils/entity-utils.js.map +1 -0
  34. package/dist/lib/utils/measure-utils.js +29 -0
  35. package/dist/lib/utils/measure-utils.js.map +1 -0
  36. package/dist/lib/viewer/cesium-view-monitor.js +222 -0
  37. package/dist/lib/viewer/cesium-view-monitor.js.map +1 -0
  38. package/dist/lib/viewer/viewer-utils.js +76 -0
  39. package/dist/lib/viewer/viewer-utils.js.map +1 -0
  40. package/dist/types/bruce-cesium.d.ts +12 -0
  41. package/dist/types/rendering/entity-render-engine.d.ts +93 -0
  42. package/dist/types/rendering/menu-item-manager.d.ts +11 -0
  43. package/dist/types/rendering/render-helper.d.ts +11 -0
  44. package/dist/types/rendering/render-managers/entities/entities-ids-render-manager.d.ts +21 -0
  45. package/dist/types/rendering/render-managers/entities/entities-loaded-render-manager.d.ts +21 -0
  46. package/dist/types/rendering/render-managers/entities/entities-render-manager.d.ts +27 -0
  47. package/dist/types/rendering/render-managers/entities/entity-render-manager.d.ts +20 -0
  48. package/dist/types/rendering/render-managers/render-manager.d.ts +18 -0
  49. package/dist/types/rendering/render-managers/tilesets/tileset-cad-render-manager.d.ts +26 -0
  50. package/dist/types/rendering/tileset-render-engine.d.ts +43 -0
  51. package/dist/types/rendering/visuals-register.d.ts +24 -0
  52. package/dist/types/utils/drawing-utils.d.ts +4 -0
  53. package/dist/types/utils/entity-utils.d.ts +5 -0
  54. package/dist/types/utils/measure-utils.d.ts +4 -0
  55. package/dist/types/viewer/cesium-view-monitor.d.ts +22 -0
  56. package/dist/types/viewer/viewer-utils.d.ts +15 -0
  57. package/package.json +75 -0
@@ -0,0 +1,2766 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('bruce-models'), require('cesium')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'bruce-models', 'cesium'], factory) :
4
+ (factory((global.bruceCesium = {}),global.bruceModels,global.Cesium));
5
+ }(this, (function (exports,bruceModels,Cesium) { 'use strict';
6
+
7
+ var TIME_LAG = 300;
8
+ var POSITION_CHECK_TIMER = 950;
9
+ var DEFAULT_GROUNDED_HEIGHT = 300;
10
+ var MINIMUM_VIEW_AREA_SIZE_DEGREES = 0.01;
11
+ var NET_STEP_PERCENT = 5;
12
+ var BORDER_STEPS = 3;
13
+ var ESearchStatus;
14
+ (function (ESearchStatus) {
15
+ ESearchStatus[ESearchStatus["LocationFound"] = 1] = "LocationFound";
16
+ ESearchStatus[ESearchStatus["LocationChanged"] = 2] = "LocationChanged";
17
+ ESearchStatus[ESearchStatus["LocationMissing"] = 3] = "LocationMissing";
18
+ })(ESearchStatus || (ESearchStatus = {}));
19
+ function netScanViewForBoundaries(viewer) {
20
+ var maxLong = -2 * Math.PI;
21
+ var minLong = 2 * Math.PI;
22
+ var maxLat = -2 * Math.PI;
23
+ var minLat = 2 * Math.PI;
24
+ var found = 0;
25
+ var updateMinMaxForPoint = function (stepX, stepY) {
26
+ var x = Math.round(0 + (viewer.container.clientWidth / 100) * (stepX * NET_STEP_PERCENT));
27
+ var y = Math.round(0 + (viewer.container.clientHeight / 100) * (stepY * NET_STEP_PERCENT));
28
+ var winPos = new Cesium.Cartesian2(x, y);
29
+ try {
30
+ var intersection = getAdjustedGroundIntersectionOfCameraRay(viewer, winPos);
31
+ if (intersection) {
32
+ var point = Cesium.Cartographic.fromCartesian(intersection, viewer.scene.globe.ellipsoid);
33
+ maxLong = Math.max(maxLong, point.longitude);
34
+ maxLat = Math.max(maxLat, point.latitude);
35
+ minLong = Math.min(minLong, point.longitude);
36
+ minLat = Math.min(minLat, point.latitude);
37
+ found++;
38
+ }
39
+ }
40
+ catch (_a) {
41
+ }
42
+ };
43
+ // Outer circle.
44
+ updateMinMaxForPoint(BORDER_STEPS, BORDER_STEPS);
45
+ updateMinMaxForPoint((100 / NET_STEP_PERCENT) - BORDER_STEPS, BORDER_STEPS);
46
+ updateMinMaxForPoint(BORDER_STEPS, (100 / NET_STEP_PERCENT) - BORDER_STEPS);
47
+ updateMinMaxForPoint((100 / NET_STEP_PERCENT) - BORDER_STEPS, (100 / NET_STEP_PERCENT) - BORDER_STEPS);
48
+ // Inner circle.
49
+ updateMinMaxForPoint(BORDER_STEPS * 2, BORDER_STEPS * 2);
50
+ updateMinMaxForPoint((100 / NET_STEP_PERCENT) - BORDER_STEPS * 2, BORDER_STEPS * 2);
51
+ updateMinMaxForPoint(BORDER_STEPS * 2, (100 / NET_STEP_PERCENT) - BORDER_STEPS * 2);
52
+ updateMinMaxForPoint((100 / NET_STEP_PERCENT) - BORDER_STEPS * 2, (100 / NET_STEP_PERCENT) - BORDER_STEPS * 2);
53
+ if (found > 0) {
54
+ var viewRect = {
55
+ east: maxLong,
56
+ west: minLong,
57
+ north: maxLat,
58
+ south: minLat
59
+ };
60
+ return viewRect;
61
+ }
62
+ return null;
63
+ }
64
+ function getAdjustedGroundIntersectionOfCameraRay(viewer, screenPos) {
65
+ var ray = viewer.camera.getPickRay(screenPos);
66
+ var intersection = ray ? viewer.scene.globe.pick(ray, viewer.scene) : null;
67
+ if (intersection) {
68
+ return intersection;
69
+ }
70
+ return null;
71
+ }
72
+ function areBoundsEqual(a, b) {
73
+ return a.north == b.north && a.south == b.south && a.east == b.east && a.west == b.west;
74
+ }
75
+ function arePosEqual(a, b) {
76
+ return a.latitude == b.latitude && a.longitude == b.longitude;
77
+ }
78
+ var CesiumViewMonitor = /** @class */ (function () {
79
+ function CesiumViewMonitor(viewer) {
80
+ var _this = this;
81
+ this.target = null;
82
+ this.bounds = null;
83
+ this.disposed = false;
84
+ this.updatedEvent = null;
85
+ this.viewer = viewer;
86
+ this.checkInterval = setInterval(function () {
87
+ _this.updateQueue();
88
+ }, POSITION_CHECK_TIMER);
89
+ }
90
+ Object.defineProperty(CesiumViewMonitor.prototype, "Disposed", {
91
+ get: function () {
92
+ return this.disposed;
93
+ },
94
+ enumerable: false,
95
+ configurable: true
96
+ });
97
+ CesiumViewMonitor.prototype.Updated = function () {
98
+ if (!this.updatedEvent) {
99
+ this.updatedEvent = new bruceModels.BruceEvent();
100
+ }
101
+ return this.updatedEvent;
102
+ };
103
+ CesiumViewMonitor.prototype.GetBounds = function () {
104
+ return this.bounds;
105
+ };
106
+ CesiumViewMonitor.prototype.GetTarget = function () {
107
+ return this.target;
108
+ };
109
+ CesiumViewMonitor.prototype.DoUpdate = function () {
110
+ this.tryEmitUpdate();
111
+ };
112
+ CesiumViewMonitor.prototype.Dispose = function () {
113
+ if (this.disposed) {
114
+ return;
115
+ }
116
+ this.disposed = true;
117
+ clearInterval(this.checkInterval);
118
+ };
119
+ CesiumViewMonitor.prototype.tryDoUpdate = function () {
120
+ var viewRect = null;
121
+ var center = null;
122
+ var camera = this.viewer.camera;
123
+ var terrainHeight = this.viewer.scene.globe.getHeight(camera.positionCartographic);
124
+ var cameraPosition = this.viewer.camera.positionCartographic;
125
+ // We are almost at the ground, screw horizon, just load around.
126
+ if (terrainHeight && ((cameraPosition.height - terrainHeight) < DEFAULT_GROUNDED_HEIGHT)) {
127
+ // View area calculation.
128
+ viewRect = {};
129
+ var viewRectRad = netScanViewForBoundaries(this.viewer);
130
+ if (viewRectRad &&
131
+ viewRectRad.east &&
132
+ viewRectRad.west &&
133
+ viewRectRad.north &&
134
+ viewRectRad.south) {
135
+ viewRect.east = Cesium.Math.toDegrees(Math.max(viewRectRad.east, cameraPosition.longitude));
136
+ viewRect.west = Cesium.Math.toDegrees(Math.min(viewRectRad.west, cameraPosition.longitude));
137
+ viewRect.south = Cesium.Math.toDegrees(Math.min(viewRectRad.south, cameraPosition.latitude));
138
+ viewRect.north = Cesium.Math.toDegrees(Math.max(viewRectRad.north, cameraPosition.latitude));
139
+ }
140
+ else {
141
+ viewRect.east = cameraPosition.longitude;
142
+ viewRect.west = cameraPosition.longitude;
143
+ viewRect.south = cameraPosition.latitude;
144
+ viewRect.north = cameraPosition.latitude;
145
+ }
146
+ center = {};
147
+ center.latitude = Cesium.Math.toDegrees(camera.positionCartographic.latitude);
148
+ center.longitude = Cesium.Math.toDegrees(camera.positionCartographic.longitude);
149
+ }
150
+ else {
151
+ // View area calculation.
152
+ var windowPosition = new Cesium.Cartesian2(this.viewer.container.clientWidth / 2, this.viewer.container.clientHeight / 2);
153
+ var intersection = getAdjustedGroundIntersectionOfCameraRay(this.viewer, windowPosition);
154
+ var point = null;
155
+ if (intersection) {
156
+ point = Cesium.Cartographic.fromCartesian(intersection, this.viewer.scene.globe.ellipsoid);
157
+ }
158
+ if (point) {
159
+ center = {};
160
+ center.latitude = Cesium.Math.toDegrees(point.latitude);
161
+ center.longitude = Cesium.Math.toDegrees(point.longitude);
162
+ var viewRectRad = netScanViewForBoundaries(this.viewer);
163
+ if (viewRectRad) {
164
+ viewRect = {};
165
+ viewRect.east = Cesium.Math.toDegrees(viewRectRad.east);
166
+ viewRect.west = Cesium.Math.toDegrees(viewRectRad.west);
167
+ viewRect.south = Cesium.Math.toDegrees(viewRectRad.south);
168
+ viewRect.north = Cesium.Math.toDegrees(viewRectRad.north);
169
+ }
170
+ }
171
+ }
172
+ // Minimal field of view.
173
+ if (viewRect) {
174
+ var centerLong = (viewRect.east + viewRect.west) / 2;
175
+ var centerLat = (viewRect.north + viewRect.south) / 2;
176
+ viewRect.east = Math.max(viewRect.east, centerLong + (MINIMUM_VIEW_AREA_SIZE_DEGREES / 2));
177
+ viewRect.west = Math.min(viewRect.west, centerLong - (MINIMUM_VIEW_AREA_SIZE_DEGREES / 2));
178
+ viewRect.south = Math.min(viewRect.south, centerLat - (MINIMUM_VIEW_AREA_SIZE_DEGREES / 2));
179
+ viewRect.north = Math.max(viewRect.north, centerLat + (MINIMUM_VIEW_AREA_SIZE_DEGREES / 2));
180
+ }
181
+ if (center && viewRect) {
182
+ if ((!this.target || (this.target && !arePosEqual(this.target, center))) ||
183
+ (!this.bounds || (this.bounds && !areBoundsEqual(this.bounds, viewRect)))) {
184
+ this.target = center;
185
+ this.bounds = viewRect;
186
+ return ESearchStatus.LocationChanged;
187
+ }
188
+ return ESearchStatus.LocationFound;
189
+ }
190
+ return ESearchStatus.LocationMissing;
191
+ };
192
+ CesiumViewMonitor.prototype.tryEmitUpdate = function () {
193
+ var _a;
194
+ var searchResult = this.tryDoUpdate();
195
+ if (searchResult == ESearchStatus.LocationChanged) {
196
+ var interest = {
197
+ bounds: this.bounds,
198
+ target: this.target
199
+ };
200
+ (_a = this.updatedEvent) === null || _a === void 0 ? void 0 : _a.Trigger(interest);
201
+ }
202
+ else if (searchResult == ESearchStatus.LocationMissing) {
203
+ this.updateQueue();
204
+ }
205
+ };
206
+ CesiumViewMonitor.prototype.queuePosition = function (lag) {
207
+ var _this = this;
208
+ if (this.pendingTimeout) {
209
+ clearTimeout(this.pendingTimeout);
210
+ }
211
+ this.pendingTimeout = setTimeout(function () {
212
+ if (!_this.disposed) {
213
+ _this.tryEmitUpdate();
214
+ }
215
+ }, lag);
216
+ };
217
+ CesiumViewMonitor.prototype.updateQueue = function () {
218
+ this.queuePosition(TIME_LAG);
219
+ };
220
+ return CesiumViewMonitor;
221
+ }());
222
+
223
+ (function (ViewerUtils) {
224
+ function InitViewer(container) {
225
+ if (container._cViewer) {
226
+ throw new Error("Container already has a viewer.");
227
+ }
228
+ var cViewer = new Cesium.Viewer(container, {
229
+ imageryProvider: new Cesium.ArcGisMapServerImageryProvider({
230
+ url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
231
+ enablePickFeatures: false
232
+ })
233
+ });
234
+ cViewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
235
+ cViewer.camera.percentageChanged = 0.05;
236
+ ViewerUtils.DestroyWidget(cViewer.timeline);
237
+ ViewerUtils.DestroyWidget(cViewer.vrButton);
238
+ ViewerUtils.DestroyWidget(cViewer.sceneModePicker);
239
+ ViewerUtils.DestroyWidget(cViewer.homeButton);
240
+ ViewerUtils.DestroyWidget(cViewer.fullscreenButton);
241
+ ViewerUtils.DestroyWidget(cViewer.baseLayerPicker);
242
+ ViewerUtils.StyleContainer(cViewer);
243
+ container._cViewer = cViewer;
244
+ return cViewer;
245
+ }
246
+ ViewerUtils.InitViewer = InitViewer;
247
+ function GetViewerFromContainer(container) {
248
+ return container._cViewer;
249
+ }
250
+ ViewerUtils.GetViewerFromContainer = GetViewerFromContainer;
251
+ function DestroyWidget(widget) {
252
+ if (widget && !widget.isDestroyed()) {
253
+ widget.destroy();
254
+ }
255
+ }
256
+ ViewerUtils.DestroyWidget = DestroyWidget;
257
+ function StyleContainer(viewer) {
258
+ var _a;
259
+ var container = viewer.container;
260
+ var genContainer = (_a = container.getElementsByClassName("cesium-viewer")) === null || _a === void 0 ? void 0 : _a[0];
261
+ if (genContainer) {
262
+ var children = genContainer.children;
263
+ for (var i = 0; i < children.length; i++) {
264
+ var child = children[i];
265
+ if (!child.classList.contains("cesium-viewer-cesiumWidgetContainer")) {
266
+ child.style.display = "none";
267
+ }
268
+ }
269
+ }
270
+ var canvas = viewer.canvas;
271
+ canvas.style.width = "100%";
272
+ canvas.style.height = "100%";
273
+ var widget = canvas.parentElement;
274
+ widget.style.width = "100%";
275
+ widget.style.height = "100%";
276
+ widget.style.touchAction = "none";
277
+ var widgetContainer = widget.parentElement;
278
+ widgetContainer.style.width = "100%";
279
+ widgetContainer.style.height = "100%";
280
+ var viewerContainer = widgetContainer.parentElement;
281
+ viewerContainer.style.fontFamily = "sans-serif";
282
+ viewerContainer.style.fontSize = "16px";
283
+ viewerContainer.style.overflow = "hidden";
284
+ viewerContainer.style.display = "block";
285
+ viewerContainer.style.position = "relative";
286
+ viewerContainer.style.top = "0";
287
+ viewerContainer.style.left = "0";
288
+ viewerContainer.style.width = "100%";
289
+ viewerContainer.style.height = "100%";
290
+ }
291
+ ViewerUtils.StyleContainer = StyleContainer;
292
+ })(exports.ViewerUtils || (exports.ViewerUtils = {}));
293
+
294
+ /*! *****************************************************************************
295
+ Copyright (c) Microsoft Corporation. All rights reserved.
296
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
297
+ this file except in compliance with the License. You may obtain a copy of the
298
+ License at http://www.apache.org/licenses/LICENSE-2.0
299
+
300
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
301
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
302
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
303
+ MERCHANTABLITY OR NON-INFRINGEMENT.
304
+
305
+ See the Apache Version 2.0 License for specific language governing permissions
306
+ and limitations under the License.
307
+ ***************************************************************************** */
308
+
309
+ var __assign = function() {
310
+ __assign = Object.assign || function __assign(t) {
311
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
312
+ s = arguments[i];
313
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
314
+ }
315
+ return t;
316
+ };
317
+ return __assign.apply(this, arguments);
318
+ };
319
+
320
+ function __awaiter(thisArg, _arguments, P, generator) {
321
+ return new (P || (P = Promise))(function (resolve, reject) {
322
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
323
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
324
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
325
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
326
+ });
327
+ }
328
+
329
+ function __generator(thisArg, body) {
330
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
331
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
332
+ function verb(n) { return function (v) { return step([n, v]); }; }
333
+ function step(op) {
334
+ if (f) throw new TypeError("Generator is already executing.");
335
+ while (_) try {
336
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
337
+ if (y = 0, t) op = [op[0] & 2, t.value];
338
+ switch (op[0]) {
339
+ case 0: case 1: t = op; break;
340
+ case 4: _.label++; return { value: op[1], done: false };
341
+ case 5: _.label++; y = op[1]; op = [0]; continue;
342
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
343
+ default:
344
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
345
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
346
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
347
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
348
+ if (t[2]) _.ops.pop();
349
+ _.trys.pop(); continue;
350
+ }
351
+ op = body.call(thisArg, _);
352
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
353
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
354
+ }
355
+ }
356
+
357
+ var DrawingUtils;
358
+ (function (DrawingUtils) {
359
+ function PointAcrossPolyline(viewer, positions, distance) {
360
+ if (positions.length > 1) {
361
+ var currentDistance = 0;
362
+ for (var i = 0; i < positions.length - 1; i++) {
363
+ var length_1 = Cesium.Cartesian3.distance(positions[i], positions[i + 1]);
364
+ if (length_1 + currentDistance >= distance) {
365
+ var carto1 = Cesium.Cartographic.fromCartesian(positions[i]);
366
+ var carto2 = Cesium.Cartographic.fromCartesian(positions[i + 1]);
367
+ var geodesic = new Cesium.EllipsoidGeodesic(carto1, carto2, viewer.scene.globe.ellipsoid);
368
+ var position = geodesic.interpolateUsingSurfaceDistance(distance - currentDistance);
369
+ var height = (carto1.height + carto2.height) / 2;
370
+ return Cesium.Cartesian3.fromRadians(position.longitude, position.latitude, height);
371
+ }
372
+ else {
373
+ currentDistance += length_1;
374
+ }
375
+ }
376
+ }
377
+ else if (positions.length > 0) {
378
+ return positions[0];
379
+ }
380
+ else {
381
+ return null;
382
+ }
383
+ return positions[positions.length - 1];
384
+ }
385
+ DrawingUtils.PointAcrossPolyline = PointAcrossPolyline;
386
+ })(DrawingUtils || (DrawingUtils = {}));
387
+
388
+ var MeasureUtils;
389
+ (function (MeasureUtils) {
390
+ function MeasurePolyline(posses) {
391
+ if (posses.length < 2) {
392
+ return 0;
393
+ }
394
+ var totalLength = 0;
395
+ var pos1 = null;
396
+ var pos2 = null;
397
+ for (var i = 0; i < posses.length; i++) {
398
+ if (pos1 == null) {
399
+ pos1 = posses[i];
400
+ }
401
+ else if (pos2 == null) {
402
+ pos2 = posses[i];
403
+ totalLength += Cesium.Cartesian3.distance(pos1, pos2);
404
+ pos1 = pos2;
405
+ pos2 = null;
406
+ }
407
+ }
408
+ return totalLength;
409
+ }
410
+ MeasureUtils.MeasurePolyline = MeasurePolyline;
411
+ })(MeasureUtils || (MeasureUtils = {}));
412
+
413
+ var EntityUtils;
414
+ (function (EntityUtils) {
415
+ function GetPos(viewer, entity) {
416
+ if (entity.location && bruceModels.Carto.ValidateCarto(entity.location)) {
417
+ var location_1 = entity.location;
418
+ return Cesium.Cartesian3.fromDegrees(location_1.longitude, location_1.latitude, location_1.altitude);
419
+ }
420
+ if (entity.geometry && typeof entity.geometry == "object") {
421
+ var pointStr = entity.geometry.Point;
422
+ if (pointStr && typeof pointStr == "string") {
423
+ var points = bruceModels.Geometry.ParsePoints(pointStr);
424
+ var point = points.length > 0 ? points[0] : null;
425
+ if (point && bruceModels.Carto.ValidateCarto(point)) {
426
+ return Cesium.Cartesian3.fromDegrees(point.longitude, point.latitude, point.altitude);
427
+ }
428
+ }
429
+ var lineStr = entity.geometry.LineString;
430
+ if (lineStr && typeof lineStr == "string") {
431
+ var points = bruceModels.Geometry.ParsePoints(lineStr);
432
+ if (points.length > 0) {
433
+ var posses = points.map(function (x) { return Cesium.Cartesian3.fromDegrees(x.longitude, x.latitude, x.altitude); });
434
+ var length_1 = MeasureUtils.MeasurePolyline(posses);
435
+ if (length_1 > 0) {
436
+ var point = DrawingUtils.PointAcrossPolyline(viewer, posses, length_1 / 2);
437
+ if (point && bruceModels.Cartes.ValidateCartes3(point)) {
438
+ return point;
439
+ }
440
+ }
441
+ else {
442
+ return posses[0];
443
+ }
444
+ }
445
+ }
446
+ var pRings = entity.geometry.Polygon;
447
+ if (pRings && typeof pRings == "object") {
448
+ var boundary = pRings.find(function (x) { return x.Facing == bruceModels.Geometry.EPolygonRingType.Boundaries; });
449
+ if (boundary === null || boundary === void 0 ? void 0 : boundary.LinearRing) {
450
+ var points = bruceModels.Geometry.ParsePoints(boundary.LinearRing);
451
+ var point = bruceModels.Carto.GetCenter(points);
452
+ if (point && bruceModels.Carto.ValidateCarto(point)) {
453
+ return Cesium.Cartesian3.fromDegrees(point.longitude, point.latitude, point.altitude);
454
+ }
455
+ }
456
+ }
457
+ }
458
+ if (entity.boundaries) {
459
+ var point = {
460
+ latitude: (entity.boundaries.minLatitude + entity.boundaries.maxLatitude) / 2,
461
+ longitude: (entity.boundaries.minLongitude + entity.boundaries.maxLongitude) / 2,
462
+ altitude: 0
463
+ };
464
+ if (point && bruceModels.Carto.ValidateCarto(point)) {
465
+ return Cesium.Cartesian3.fromDegrees(point.longitude, point.latitude, point.altitude);
466
+ }
467
+ }
468
+ return null;
469
+ }
470
+ EntityUtils.GetPos = GetPos;
471
+ })(EntityUtils || (EntityUtils = {}));
472
+
473
+ (function (RenderManager) {
474
+ var Utils;
475
+ (function (Utils) {
476
+ function DetermineZoomItem(viewer, entity, zoomControl) {
477
+ var pos = EntityUtils.GetPos(viewer, entity);
478
+ if (!pos) {
479
+ return null;
480
+ }
481
+ var cameraPos = viewer.camera.position;
482
+ var distance = Cesium.Cartesian3.distance(pos, cameraPos);
483
+ return GetZoomControlFromDistance(zoomControl, distance);
484
+ }
485
+ Utils.DetermineZoomItem = DetermineZoomItem;
486
+ function GetZoomControlFromDistance(zoomControl, distance) {
487
+ for (var i = 0; i < zoomControl.length; i++) {
488
+ var zoomItem = zoomControl[i];
489
+ if ((distance >= zoomItem.MinZoom) && (distance <= zoomItem.MaxZoom)) {
490
+ return zoomItem;
491
+ }
492
+ }
493
+ return null;
494
+ }
495
+ Utils.GetZoomControlFromDistance = GetZoomControlFromDistance;
496
+ })(Utils = RenderManager.Utils || (RenderManager.Utils = {}));
497
+ })(exports.RenderManager || (exports.RenderManager = {}));
498
+
499
+ function colorToCColor(color) {
500
+ return new Cesium.Color(color.red ? color.red / 255 : 0, color.green ? color.green / 255 : 0, color.blue ? color.blue / 255 : 0, color.alpha);
501
+ }
502
+ function getPolygonStyleExtrusion(pStyle, entity, tags, heightRef) {
503
+ var _a;
504
+ var attrPath = pStyle.extrusionPath;
505
+ if (!pStyle.useExtrusion || !attrPath) {
506
+ return null;
507
+ }
508
+ try {
509
+ var extrusion = +bruceModels.Calculator.GetValue(attrPath, entity, tags);
510
+ if (!extrusion && extrusion != 0) {
511
+ return null;
512
+ }
513
+ /*
514
+ Cesium extrudes in strange way.
515
+ If you want something that is 50 meters above sea, and 5 meters tall,
516
+ You need to extrude by 55 meters, if you extrude by 5 it will extrude from sea and look flat.
517
+ */
518
+ var height = (_a = entity.location) === null || _a === void 0 ? void 0 : _a.altitude;
519
+ return heightRef == Cesium.HeightReference.RELATIVE_TO_GROUND ? extrusion + height : extrusion;
520
+ }
521
+ catch (e) {
522
+ console.error(e);
523
+ }
524
+ return 0;
525
+ }
526
+ function getPolygonExtrusion(entity, tags, ring, posses, heightRef, pStyle) {
527
+ var _a;
528
+ var data = {
529
+ value: undefined,
530
+ exHeightRef: Cesium.HeightReference.RELATIVE_TO_GROUND,
531
+ posses: null
532
+ };
533
+ // Step 1. Try get using style.
534
+ var extrusion = getPolygonStyleExtrusion(pStyle, entity, tags, heightRef);
535
+ if (extrusion) {
536
+ if (heightRef == Cesium.HeightReference.NONE) {
537
+ // Let's normalize all point heights to be the same (at entity altitude).
538
+ // This let's us have a consistent extrusion height, and be adjustable easier by user.
539
+ var alt_1 = (_a = entity === null || entity === void 0 ? void 0 : entity.location) === null || _a === void 0 ? void 0 : _a.altitude;
540
+ if (!alt_1) {
541
+ alt_1 = 0;
542
+ }
543
+ var points = posses.map(function (x) { return Cesium.Cartographic.fromCartesian(x); });
544
+ points.forEach(function (point) {
545
+ point.height = alt_1;
546
+ });
547
+ posses = points.map(function (x) { return Cesium.Cartesian3.fromRadians(x.longitude, x.latitude, x.height); });
548
+ }
549
+ }
550
+ // Step 2. Try get using geometry data.
551
+ else {
552
+ data.exHeightRef = undefined;
553
+ if (ring.Height && ring.Height > 0) {
554
+ var points = posses.map(function (x) { return Cesium.Cartographic.fromCartesian(x); });
555
+ if (points.length <= 0) {
556
+ data.value = ring.Height;
557
+ }
558
+ else {
559
+ var highest = null;
560
+ for (var i = 0; i < points.length; i++) {
561
+ var pointHeight = points[i].height;
562
+ if (pointHeight > highest || highest === null) {
563
+ highest = pointHeight;
564
+ }
565
+ }
566
+ highest = (highest === null ? 0 : highest) + ring.Height;
567
+ data.value = highest;
568
+ }
569
+ data.exHeightRef = Cesium.HeightReference.NONE;
570
+ }
571
+ }
572
+ data.posses = posses;
573
+ return data;
574
+ }
575
+ function getHeightRef(style) {
576
+ var _a;
577
+ var heightRef = Cesium.HeightReference.CLAMP_TO_GROUND;
578
+ var altOptionId = (_a = style === null || style === void 0 ? void 0 : style.altitudeOption) === null || _a === void 0 ? void 0 : _a.id;
579
+ if (altOptionId == 1) {
580
+ heightRef = Cesium.HeightReference.NONE;
581
+ }
582
+ else if (altOptionId == 2) {
583
+ heightRef = Cesium.HeightReference.RELATIVE_TO_GROUND;
584
+ }
585
+ return heightRef;
586
+ }
587
+ function getZIndex(style, entity, tags) {
588
+ var zIndex = (style === null || style === void 0 ? void 0 : style.zIndex) ? +bruceModels.Calculator.GetValue(style === null || style === void 0 ? void 0 : style.zIndex, entity, tags) : 0;
589
+ if (zIndex == null) {
590
+ zIndex = 0;
591
+ }
592
+ return zIndex;
593
+ }
594
+ function getStyle(api, entity, styleId) {
595
+ return __awaiter(this, void 0, void 0, function () {
596
+ var style, type;
597
+ return __generator(this, function (_a) {
598
+ switch (_a.label) {
599
+ case 0:
600
+ style = null;
601
+ if (!styleId) return [3 /*break*/, 2];
602
+ return [4 /*yield*/, bruceModels.Style.Get(api, styleId)];
603
+ case 1:
604
+ style = _a.sent();
605
+ _a.label = 2;
606
+ case 2:
607
+ if (!!style) return [3 /*break*/, 5];
608
+ return [4 /*yield*/, bruceModels.EntityType.Get(api, entity.Bruce["EntityType.ID"])];
609
+ case 3:
610
+ type = _a.sent();
611
+ if (!type["DisplaySetting.ID"]) return [3 /*break*/, 5];
612
+ return [4 /*yield*/, bruceModels.Style.Get(api, type["DisplaySetting.ID"])];
613
+ case 4:
614
+ style = _a.sent();
615
+ _a.label = 5;
616
+ case 5: return [2 /*return*/, style];
617
+ }
618
+ });
619
+ });
620
+ }
621
+ function getExistingCEntity(entityId, menuItemId, item, visualRegister) {
622
+ var visuals = visualRegister.GetVisuals(entityId, menuItemId);
623
+ return visuals.length > 0 ? visuals[0] : null;
624
+ }
625
+ function getRenderGroupId(zoomItem) {
626
+ if (!zoomItem) {
627
+ return null;
628
+ }
629
+ return zoomItem.MinZoom + "-" + zoomItem.MaxZoom;
630
+ }
631
+ (function (EntityRenderEngine) {
632
+ function Render(params) {
633
+ return __awaiter(this, void 0, void 0, function () {
634
+ var groupRenderParams, cEntities, models, polygons, polylines, points, i, entity, id, zoomItem, displayType, newRenderId, existing, oldRenderId, mParams, mEntities, i, entity, id, cEntity, pParams, pEntities, i, entity, cEntity, pParams, pEntities, i, entity, cEntity, pParams, pEntities, i, entity, cEntity;
635
+ return __generator(this, function (_a) {
636
+ switch (_a.label) {
637
+ case 0:
638
+ groupRenderParams = {
639
+ api: params.api,
640
+ viewer: params.viewer,
641
+ entities: [],
642
+ zoomItems: {},
643
+ menuItemId: params.menuItemId,
644
+ visualRegister: params.visualRegister
645
+ };
646
+ cEntities = {};
647
+ models = [];
648
+ polygons = [];
649
+ polylines = [];
650
+ points = [];
651
+ // Initial sorting.
652
+ for (i = 0; i < params.entities.length; i++) {
653
+ entity = params.entities[i];
654
+ id = entity.Bruce.ID;
655
+ zoomItem = exports.RenderManager.Utils.DetermineZoomItem(params.viewer, entity, params.zoomControl);
656
+ displayType = zoomItem === null || zoomItem === void 0 ? void 0 : zoomItem.DisplayType;
657
+ if (!displayType) {
658
+ displayType = bruceModels.ZoomControl.EDisplayType.Hidden;
659
+ }
660
+ if (displayType != bruceModels.ZoomControl.EDisplayType.Hidden) {
661
+ newRenderId = getRenderGroupId(zoomItem);
662
+ existing = getExistingCEntity(id, params.menuItemId, zoomItem, params.visualRegister);
663
+ oldRenderId = existing === null || existing === void 0 ? void 0 : existing._renderGroup;
664
+ if (newRenderId == oldRenderId) {
665
+ cEntities[id] = existing;
666
+ }
667
+ else {
668
+ if (displayType == bruceModels.ZoomControl.EDisplayType.Model3D) {
669
+ models.push(entity);
670
+ }
671
+ else if (displayType == bruceModels.ZoomControl.EDisplayType.Geometry) {
672
+ polygons.push(entity);
673
+ }
674
+ else {
675
+ points.push(entity);
676
+ }
677
+ groupRenderParams.zoomItems[id] = zoomItem;
678
+ }
679
+ }
680
+ }
681
+ if (!(models.length > 0)) return [3 /*break*/, 2];
682
+ mParams = __assign(__assign({}, groupRenderParams), { entities: models });
683
+ return [4 /*yield*/, Model3d.RenderGroup(mParams)];
684
+ case 1:
685
+ mEntities = _a.sent();
686
+ for (i = 0; i < mParams.entities.length; i++) {
687
+ entity = mParams.entities[i];
688
+ id = entity.Bruce.ID;
689
+ cEntity = mEntities[id];
690
+ if (cEntity) {
691
+ cEntities[id] = cEntity;
692
+ }
693
+ else {
694
+ polygons.push(entity);
695
+ }
696
+ }
697
+ _a.label = 2;
698
+ case 2:
699
+ if (!(polygons.length > 0)) return [3 /*break*/, 4];
700
+ pParams = __assign(__assign({}, groupRenderParams), { entities: models });
701
+ return [4 /*yield*/, Polygon.RenderGroup(pParams)];
702
+ case 3:
703
+ pEntities = _a.sent();
704
+ for (i = 0; i < pParams.entities.length; i++) {
705
+ entity = pParams.entities[i];
706
+ cEntity = pEntities[entity.Bruce.ID];
707
+ if (cEntity) {
708
+ cEntities[entity.Bruce.ID] = cEntity;
709
+ }
710
+ else {
711
+ polylines.push(entity);
712
+ }
713
+ }
714
+ _a.label = 4;
715
+ case 4:
716
+ if (!(polylines.length > 0)) return [3 /*break*/, 6];
717
+ pParams = __assign(__assign({}, groupRenderParams), { entities: models });
718
+ return [4 /*yield*/, Polyline.RenderGroup(pParams)];
719
+ case 5:
720
+ pEntities = _a.sent();
721
+ for (i = 0; i < pParams.entities.length; i++) {
722
+ entity = pParams.entities[i];
723
+ cEntity = pEntities[entity.Bruce.ID];
724
+ if (cEntity) {
725
+ cEntities[entity.Bruce.ID] = cEntity;
726
+ }
727
+ else {
728
+ points.push(entity);
729
+ }
730
+ }
731
+ _a.label = 6;
732
+ case 6:
733
+ if (!(points.length > 0)) return [3 /*break*/, 8];
734
+ pParams = __assign(__assign({}, groupRenderParams), { entities: models });
735
+ return [4 /*yield*/, Point.RenderGroup(pParams)];
736
+ case 7:
737
+ pEntities = _a.sent();
738
+ for (i = 0; i < pParams.entities.length; i++) {
739
+ entity = pParams.entities[i];
740
+ cEntity = pEntities[entity.Bruce.ID];
741
+ if (cEntity) {
742
+ cEntities[entity.Bruce.ID] = cEntity;
743
+ }
744
+ }
745
+ _a.label = 8;
746
+ case 8: return [2 /*return*/, cEntities];
747
+ }
748
+ });
749
+ });
750
+ }
751
+ EntityRenderEngine.Render = Render;
752
+ function Remove(viewer, entity) {
753
+ if (entity._parentEntity) {
754
+ Remove(viewer, entity._parentEntity);
755
+ }
756
+ if (entity._siblingGraphics) {
757
+ for (var i = 0; i < entity._siblingGraphics.length; i++) {
758
+ var sibling = entity._siblingGraphics[i];
759
+ Remove(viewer, sibling);
760
+ }
761
+ }
762
+ if (viewer.entities.contains(entity)) {
763
+ viewer.entities.remove(entity);
764
+ }
765
+ }
766
+ EntityRenderEngine.Remove = Remove;
767
+ var Point;
768
+ (function (Point) {
769
+ function Render(params) {
770
+ var entity = params.entity;
771
+ var style = params.style;
772
+ var bColor = style.color ? bruceModels.Calculator.GetValue(style.color, entity, params.tags) : null;
773
+ var cColor = bColor ? colorToCColor(bColor) : Cesium.Color.RED;
774
+ var size = style.size ? bruceModels.Calculator.GetValue(style.size, entity, params.tags) : null;
775
+ if (size == null) {
776
+ size = 30;
777
+ }
778
+ if (size <= 0) {
779
+ return null;
780
+ }
781
+ var cEntity = new Cesium.Entity({
782
+ point: {
783
+ pixelSize: size,
784
+ color: cColor,
785
+ heightReference: getHeightRef(style)
786
+ },
787
+ position: EntityUtils.GetPos(params.viewer, entity),
788
+ show: false
789
+ });
790
+ params.viewer.entities.add(cEntity);
791
+ return cEntity;
792
+ }
793
+ Point.Render = Render;
794
+ function RenderGroup(params) {
795
+ var _a, _b;
796
+ return __awaiter(this, void 0, void 0, function () {
797
+ var cEntities, i, entity, zoomItem, style, tagIds, tags, pStyle, cEntity;
798
+ return __generator(this, function (_c) {
799
+ switch (_c.label) {
800
+ case 0:
801
+ cEntities = {};
802
+ i = 0;
803
+ _c.label = 1;
804
+ case 1:
805
+ if (!(i < params.entities.length)) return [3 /*break*/, 6];
806
+ entity = params.entities[i];
807
+ zoomItem = params.zoomItems[entity.Bruce.ID];
808
+ return [4 /*yield*/, getStyle(params.api, entity, zoomItem.StyleID)];
809
+ case 2:
810
+ style = _c.sent();
811
+ tagIds = entity.Bruce["Layer.ID"];
812
+ tags = [];
813
+ if (!(tagIds && tagIds.length > 0)) return [3 /*break*/, 4];
814
+ return [4 /*yield*/, bruceModels.EntityTag.GetListByIds(params.api, tagIds)];
815
+ case 3:
816
+ tags = _c.sent();
817
+ _c.label = 4;
818
+ case 4:
819
+ pStyle = (_b = (_a = style === null || style === void 0 ? void 0 : style.Settings) === null || _a === void 0 ? void 0 : _a.pointStyle) !== null && _b !== void 0 ? _b : {};
820
+ cEntity = Render({
821
+ entity: entity,
822
+ style: pStyle,
823
+ tags: tags,
824
+ viewer: params.viewer
825
+ });
826
+ cEntity._renderGroup = getRenderGroupId(zoomItem);
827
+ cEntities[entity.Bruce.ID] = cEntity;
828
+ _c.label = 5;
829
+ case 5:
830
+ i++;
831
+ return [3 /*break*/, 1];
832
+ case 6: return [2 /*return*/, cEntities];
833
+ }
834
+ });
835
+ });
836
+ }
837
+ Point.RenderGroup = RenderGroup;
838
+ })(Point = EntityRenderEngine.Point || (EntityRenderEngine.Point = {}));
839
+ var Polyline;
840
+ (function (Polyline) {
841
+ function Render(params) {
842
+ var _a;
843
+ var entity = params.entity;
844
+ var line = (_a = entity.geometry) === null || _a === void 0 ? void 0 : _a.LineString;
845
+ var points = line && typeof line == "string" ? bruceModels.Geometry.ParsePoints(line) : [];
846
+ if (!points || points.length < 2) {
847
+ return null;
848
+ }
849
+ var isValid = true;
850
+ for (var i = 0; i < points.length; i++) {
851
+ if (!bruceModels.Carto.ValidateCarto(points[i])) {
852
+ isValid = false;
853
+ break;
854
+ }
855
+ }
856
+ if (!isValid) {
857
+ return null;
858
+ }
859
+ var posses = points.map(function (x) { return Cesium.Cartesian3.fromDegrees(x.longitude, x.latitude, x.altitude); });
860
+ // Making sure no 0 length lines coming through.
861
+ // Ideally we would measure the full line but I fear that's too expensive.
862
+ if (posses.length == 2 || posses.length == 3) {
863
+ var totalDistance = 0;
864
+ for (var i = 0; i < posses.length; i++) {
865
+ var pos1 = posses[i];
866
+ var pos2 = posses[i + 1];
867
+ if (pos1 && pos2) {
868
+ totalDistance += Cesium.Cartesian3.distance(pos1, pos2);
869
+ }
870
+ }
871
+ if (totalDistance < 0.001) {
872
+ return null;
873
+ }
874
+ }
875
+ var style = params.style;
876
+ var bColor = style.lineColor ? bruceModels.Calculator.GetValue(style.lineColor, entity, params.tags) : null;
877
+ var cColor = bColor ? colorToCColor(bColor) : Cesium.Color.RED;
878
+ var width = style.lineWidth ? bruceModels.Calculator.GetValue(style.lineWidth, entity, params.tags) : null;
879
+ if (width == null) {
880
+ width = 4;
881
+ }
882
+ if (width <= 0) {
883
+ return null;
884
+ }
885
+ var heightRef = getHeightRef(style);
886
+ var cEntity = new Cesium.Entity({
887
+ polyline: {
888
+ positions: posses,
889
+ material: cColor,
890
+ width: width,
891
+ classificationType: Cesium.ClassificationType.TERRAIN,
892
+ arcType: Cesium.ArcType.GEODESIC,
893
+ zIndex: getZIndex(style, entity, params.tags),
894
+ clampToGround: heightRef == Cesium.HeightReference.CLAMP_TO_GROUND
895
+ },
896
+ position: EntityUtils.GetPos(params.viewer, entity),
897
+ show: false
898
+ });
899
+ params.viewer.entities.add(cEntity);
900
+ return cEntity;
901
+ }
902
+ Polyline.Render = Render;
903
+ function RenderGroup(params) {
904
+ var _a, _b;
905
+ return __awaiter(this, void 0, void 0, function () {
906
+ var cEntities, i, entity, zoomItem, style, tagIds, tags, lStyle, cEntity;
907
+ return __generator(this, function (_c) {
908
+ switch (_c.label) {
909
+ case 0:
910
+ cEntities = {};
911
+ i = 0;
912
+ _c.label = 1;
913
+ case 1:
914
+ if (!(i < params.entities.length)) return [3 /*break*/, 6];
915
+ entity = params.entities[i];
916
+ zoomItem = params.zoomItems[entity.Bruce.ID];
917
+ return [4 /*yield*/, getStyle(params.api, entity, zoomItem.StyleID)];
918
+ case 2:
919
+ style = _c.sent();
920
+ tagIds = entity.Bruce["Layer.ID"];
921
+ tags = [];
922
+ if (!(tagIds && tagIds.length > 0)) return [3 /*break*/, 4];
923
+ return [4 /*yield*/, bruceModels.EntityTag.GetListByIds(params.api, tagIds)];
924
+ case 3:
925
+ tags = _c.sent();
926
+ _c.label = 4;
927
+ case 4:
928
+ lStyle = (_b = (_a = style === null || style === void 0 ? void 0 : style.Settings) === null || _a === void 0 ? void 0 : _a.polylineStyle) !== null && _b !== void 0 ? _b : {};
929
+ cEntity = Render({
930
+ entity: entity,
931
+ style: lStyle,
932
+ tags: tags,
933
+ viewer: params.viewer
934
+ });
935
+ if (cEntity) {
936
+ cEntity._renderGroup = getRenderGroupId(zoomItem);
937
+ cEntities[entity.Bruce.ID] = cEntity;
938
+ }
939
+ _c.label = 5;
940
+ case 5:
941
+ i++;
942
+ return [3 /*break*/, 1];
943
+ case 6: return [2 /*return*/, cEntities];
944
+ }
945
+ });
946
+ });
947
+ }
948
+ Polyline.RenderGroup = RenderGroup;
949
+ })(Polyline = EntityRenderEngine.Polyline || (EntityRenderEngine.Polyline = {}));
950
+ var Polygon;
951
+ (function (Polygon) {
952
+ function Render(params) {
953
+ var _a;
954
+ var entity = params.entity;
955
+ var pRings = (_a = entity.geometry) === null || _a === void 0 ? void 0 : _a.Polygon;
956
+ if (pRings == null || pRings.length <= 0) {
957
+ return null;
958
+ }
959
+ var style = params.style;
960
+ var bFillColor = bruceModels.Calculator.GetValue(style.fillColor, entity, params.tags);
961
+ var cFillColor = bFillColor ? colorToCColor(bFillColor) : Cesium.Color.RED;
962
+ var bLineColor = bruceModels.Calculator.GetValue(style.lineColor, entity, params.tags);
963
+ var cLineColor = bLineColor ? colorToCColor(bLineColor) : Cesium.Color.RED;
964
+ var width = style.lineWidth ? bruceModels.Calculator.GetValue(style.lineWidth, entity, params.tags) : null;
965
+ if (width == null) {
966
+ width = 4;
967
+ }
968
+ if (width <= 0) {
969
+ return null;
970
+ }
971
+ var heightRef = getHeightRef(style);
972
+ var outerRing = pRings.find(function (x) { return x.Facing == bruceModels.Geometry.EPolygonRingType.Boundaries; });
973
+ var points = bruceModels.Geometry.ParsePoints(outerRing === null || outerRing === void 0 ? void 0 : outerRing.LinearRing);
974
+ var posses = points.map(function (x) { return Cesium.Cartesian3.fromDegrees(x.longitude, x.latitude, x.altitude); });
975
+ var extrusion = getPolygonExtrusion(entity, params.tags, outerRing, posses, heightRef, style);
976
+ posses = extrusion.posses;
977
+ var holeRings = pRings.filter(function (x) { return x.Facing == bruceModels.Geometry.EPolygonRingType.Hole; });
978
+ var holePosses = holeRings.map(function (x) {
979
+ var points = bruceModels.Geometry.ParsePoints(x.LinearRing);
980
+ return points.map(function (x) { return Cesium.Cartesian3.fromDegrees(x.longitude, x.latitude, x.altitude); });
981
+ });
982
+ var zIndex = getZIndex(style, entity, params.tags);
983
+ var cEntity = new Cesium.Entity({
984
+ polygon: {
985
+ hierarchy: new Cesium.PolygonHierarchy(posses, holePosses.map(function (x) { return new Cesium.PolygonHierarchy(x); })),
986
+ material: cFillColor,
987
+ extrudedHeight: extrusion.value,
988
+ extrudedHeightReference: extrusion.exHeightRef,
989
+ shadows: Cesium.ShadowMode.ENABLED,
990
+ heightReference: heightRef,
991
+ classificationType: Cesium.ClassificationType.BOTH,
992
+ perPositionHeight: heightRef == Cesium.HeightReference.CLAMP_TO_GROUND ? false : true,
993
+ zIndex: zIndex
994
+ },
995
+ position: EntityUtils.GetPos(params.viewer, entity),
996
+ show: false
997
+ });
998
+ cEntity._siblingGraphics = [];
999
+ for (var i = 0; i < holePosses.length; i++) {
1000
+ var posses_1 = holePosses[i];
1001
+ var cEntityHole = new Cesium.Entity({
1002
+ polyline: new Cesium.PolylineGraphics({
1003
+ positions: posses_1,
1004
+ material: cLineColor,
1005
+ width: width,
1006
+ clampToGround: heightRef == Cesium.HeightReference.CLAMP_TO_GROUND,
1007
+ classificationType: Cesium.ClassificationType.TERRAIN,
1008
+ arcType: Cesium.ArcType.GEODESIC,
1009
+ zIndex: zIndex
1010
+ }),
1011
+ show: false
1012
+ });
1013
+ cEntity._siblingGraphics.push(cEntityHole);
1014
+ cEntityHole._parentEntity = cEntity;
1015
+ params.viewer.entities.add(cEntityHole);
1016
+ }
1017
+ params.viewer.entities.add(cEntity);
1018
+ return cEntity;
1019
+ }
1020
+ Polygon.Render = Render;
1021
+ function RenderGroup(params) {
1022
+ var _a, _b;
1023
+ return __awaiter(this, void 0, void 0, function () {
1024
+ var cEntities, i, entity, zoomItem, style, tagIds, tags, pStyle, cEntity;
1025
+ return __generator(this, function (_c) {
1026
+ switch (_c.label) {
1027
+ case 0:
1028
+ cEntities = {};
1029
+ i = 0;
1030
+ _c.label = 1;
1031
+ case 1:
1032
+ if (!(i < params.entities.length)) return [3 /*break*/, 6];
1033
+ entity = params.entities[i];
1034
+ zoomItem = params.zoomItems[entity.Bruce.ID];
1035
+ return [4 /*yield*/, getStyle(params.api, entity, zoomItem.StyleID)];
1036
+ case 2:
1037
+ style = _c.sent();
1038
+ tagIds = entity.Bruce["Layer.ID"];
1039
+ tags = [];
1040
+ if (!(tagIds && tagIds.length > 0)) return [3 /*break*/, 4];
1041
+ return [4 /*yield*/, bruceModels.EntityTag.GetListByIds(params.api, tagIds)];
1042
+ case 3:
1043
+ tags = _c.sent();
1044
+ _c.label = 4;
1045
+ case 4:
1046
+ pStyle = (_b = (_a = style === null || style === void 0 ? void 0 : style.Settings) === null || _a === void 0 ? void 0 : _a.polygonStyle) !== null && _b !== void 0 ? _b : {};
1047
+ cEntity = Render({
1048
+ entity: entity,
1049
+ style: pStyle,
1050
+ tags: tags,
1051
+ viewer: params.viewer
1052
+ });
1053
+ if (cEntity) {
1054
+ cEntity._renderGroup = getRenderGroupId(zoomItem);
1055
+ cEntities[entity.Bruce.ID] = cEntity;
1056
+ }
1057
+ _c.label = 5;
1058
+ case 5:
1059
+ i++;
1060
+ return [3 /*break*/, 1];
1061
+ case 6: return [2 /*return*/, cEntities];
1062
+ }
1063
+ });
1064
+ });
1065
+ }
1066
+ Polygon.RenderGroup = RenderGroup;
1067
+ })(Polygon = EntityRenderEngine.Polygon || (EntityRenderEngine.Polygon = {}));
1068
+ var Model3d;
1069
+ (function (Model3d) {
1070
+ function Render(params) {
1071
+ var entity = params.entity;
1072
+ var transform = entity === null || entity === void 0 ? void 0 : entity.transform;
1073
+ var heading = transform ? +transform.heading : 0;
1074
+ heading = (heading + 90) % 360;
1075
+ var pitch = transform ? +transform.pitch : 0;
1076
+ var roll = transform ? +transform.roll : 0;
1077
+ var scale = transform ? +transform.scale : 1;
1078
+ if (scale <= 0) {
1079
+ scale = 1;
1080
+ }
1081
+ var style = params.style;
1082
+ var styleScale = (style === null || style === void 0 ? void 0 : style.scale) ? +bruceModels.Calculator.GetValue(style === null || style === void 0 ? void 0 : style.scale, entity, params.tags) : null;
1083
+ if (!styleScale) {
1084
+ styleScale = 1;
1085
+ }
1086
+ scale *= styleScale;
1087
+ var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
1088
+ var heightRef = getHeightRef(style);
1089
+ var pos = EntityUtils.GetPos(params.viewer, entity);
1090
+ if (heightRef == Cesium.HeightReference.CLAMP_TO_GROUND) {
1091
+ var carto = Cesium.Cartographic.fromCartesian(pos);
1092
+ pos = Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, 0);
1093
+ heightRef = Cesium.HeightReference.RELATIVE_TO_GROUND;
1094
+ }
1095
+ var orientation = Cesium.Transforms.headingPitchRollQuaternion(pos, hpr);
1096
+ var blendMode = null;
1097
+ var blendAmount = null;
1098
+ var color = null;
1099
+ if (style === null || style === void 0 ? void 0 : style.customize) {
1100
+ blendMode = style.fillColorBlendMode;
1101
+ if (!blendMode) {
1102
+ blendMode = Cesium.ColorBlendMode.HIGHLIGHT;
1103
+ }
1104
+ if (blendMode == Cesium.ColorBlendMode.MIX) {
1105
+ blendAmount = style.fillColorBlendAmount;
1106
+ if (!blendAmount) {
1107
+ blendAmount = 0.5;
1108
+ }
1109
+ }
1110
+ var bColor = bruceModels.Calculator.GetValue(style.fillColor, entity, params.tags);
1111
+ if (bColor) {
1112
+ color = colorToCColor(bColor);
1113
+ }
1114
+ }
1115
+ var cEntity = new Cesium.Entity({
1116
+ model: {
1117
+ uri: params.lodUrl,
1118
+ heightReference: heightRef,
1119
+ scale: scale,
1120
+ shadows: Cesium.ShadowMode.ENABLED,
1121
+ colorBlendAmount: blendAmount,
1122
+ colorBlendMode: blendMode,
1123
+ color: color
1124
+ },
1125
+ orientation: orientation,
1126
+ position: pos,
1127
+ show: false
1128
+ });
1129
+ params.viewer.entities.add(cEntity);
1130
+ return cEntity;
1131
+ }
1132
+ Model3d.Render = Render;
1133
+ function RenderGroup(params) {
1134
+ var _a, _b, _c, _d;
1135
+ return __awaiter(this, void 0, void 0, function () {
1136
+ var cEntities, reqBody, i, entity, zoomItem, style, tagIds, tags, mStyle, group, level, catId, lodData, _loop_1, i;
1137
+ return __generator(this, function (_e) {
1138
+ switch (_e.label) {
1139
+ case 0:
1140
+ cEntities = {};
1141
+ reqBody = {
1142
+ "strict": false,
1143
+ "externalSources": false,
1144
+ "Items": []
1145
+ };
1146
+ i = 0;
1147
+ _e.label = 1;
1148
+ case 1:
1149
+ if (!(i < params.entities.length)) return [3 /*break*/, 6];
1150
+ entity = params.entities[i];
1151
+ zoomItem = params.zoomItems[entity.Bruce.ID];
1152
+ return [4 /*yield*/, getStyle(params.api, entity, zoomItem.StyleID)];
1153
+ case 2:
1154
+ style = _e.sent();
1155
+ tagIds = entity.Bruce["Layer.ID"];
1156
+ tags = [];
1157
+ if (!(tagIds && tagIds.length > 0)) return [3 /*break*/, 4];
1158
+ return [4 /*yield*/, bruceModels.EntityTag.GetListByIds(params.api, tagIds)];
1159
+ case 3:
1160
+ tags = _e.sent();
1161
+ _e.label = 4;
1162
+ case 4:
1163
+ mStyle = (_b = (_a = style === null || style === void 0 ? void 0 : style.Settings) === null || _a === void 0 ? void 0 : _a.polygonStyle) !== null && _b !== void 0 ? _b : {};
1164
+ group = mStyle.lodGroup ? bruceModels.Calculator.GetValue(mStyle.lodGroup, entity, tags) : null;
1165
+ if (!group) {
1166
+ group = "DEFAULT";
1167
+ }
1168
+ level = +zoomItem.LODLevel;
1169
+ if (!level) {
1170
+ level = 0;
1171
+ }
1172
+ catId = zoomItem.LODCategoryID;
1173
+ if (!catId) {
1174
+ catId = "glb";
1175
+ }
1176
+ reqBody.Items.push({
1177
+ "entityId": entity.Bruce.ID,
1178
+ "categoryId": catId,
1179
+ "group": group,
1180
+ "level": level
1181
+ });
1182
+ _e.label = 5;
1183
+ case 5:
1184
+ i++;
1185
+ return [3 /*break*/, 1];
1186
+ case 6: return [4 /*yield*/, bruceModels.EntityLod.GetLods(params.api, reqBody)];
1187
+ case 7:
1188
+ lodData = _e.sent();
1189
+ _loop_1 = function (i) {
1190
+ var entity, zoomItem, style, tagIds, tags, lod, mStyle, cEntity;
1191
+ return __generator(this, function (_a) {
1192
+ switch (_a.label) {
1193
+ case 0:
1194
+ entity = params.entities[i];
1195
+ zoomItem = params.zoomItems[entity.Bruce.ID];
1196
+ return [4 /*yield*/, getStyle(params.api, entity, zoomItem.StyleID)];
1197
+ case 1:
1198
+ style = _a.sent();
1199
+ tagIds = entity.Bruce["Layer.ID"];
1200
+ tags = [];
1201
+ if (!(tagIds && tagIds.length > 0)) return [3 /*break*/, 3];
1202
+ return [4 /*yield*/, bruceModels.EntityTag.GetListByIds(params.api, tagIds)];
1203
+ case 2:
1204
+ tags = _a.sent();
1205
+ _a.label = 3;
1206
+ case 3:
1207
+ lod = lodData.find(function (x) { return x.entityId == entity.Bruce.ID; });
1208
+ if (!(lod === null || lod === void 0 ? void 0 : lod.clientFileId)) {
1209
+ return [2 /*return*/, "continue"];
1210
+ }
1211
+ mStyle = (_d = (_c = style === null || style === void 0 ? void 0 : style.Settings) === null || _c === void 0 ? void 0 : _c.polygonStyle) !== null && _d !== void 0 ? _d : {};
1212
+ cEntity = Render({
1213
+ entity: entity,
1214
+ style: mStyle,
1215
+ tags: tags,
1216
+ viewer: params.viewer,
1217
+ lodUrl: bruceModels.ClientFile.GetUrl(params.api, lod.clientFileId)
1218
+ });
1219
+ if (cEntity) {
1220
+ cEntity._renderGroup = getRenderGroupId(zoomItem);
1221
+ cEntities[entity.Bruce.ID] = cEntity;
1222
+ }
1223
+ return [2 /*return*/];
1224
+ }
1225
+ });
1226
+ };
1227
+ i = 0;
1228
+ _e.label = 8;
1229
+ case 8:
1230
+ if (!(i < params.entities.length)) return [3 /*break*/, 11];
1231
+ return [5 /*yield**/, _loop_1(i)];
1232
+ case 9:
1233
+ _e.sent();
1234
+ _e.label = 10;
1235
+ case 10:
1236
+ i++;
1237
+ return [3 /*break*/, 8];
1238
+ case 11: return [2 /*return*/, cEntities];
1239
+ }
1240
+ });
1241
+ });
1242
+ }
1243
+ Model3d.RenderGroup = RenderGroup;
1244
+ })(Model3d = EntityRenderEngine.Model3d || (EntityRenderEngine.Model3d = {}));
1245
+ })(exports.EntityRenderEngine || (exports.EntityRenderEngine = {}));
1246
+
1247
+ (function (EntitiesRenderManager) {
1248
+ var Manager = /** @class */ (function () {
1249
+ function Manager(viewer, visualsManager, api, item) {
1250
+ this.getter = null;
1251
+ this.getterSub = null;
1252
+ this.disposed = false;
1253
+ this.renderedEntities = {};
1254
+ this.entityCheckQueue = null;
1255
+ this.entityCheckRemoval = null;
1256
+ this.isRunningCheck = false;
1257
+ this.viewMonitorRemoval = null;
1258
+ this.viewer = viewer;
1259
+ this.api = api;
1260
+ this.item = item;
1261
+ this.visualsManager = visualsManager;
1262
+ }
1263
+ Object.defineProperty(Manager.prototype, "Disposed", {
1264
+ get: function () {
1265
+ return this.disposed;
1266
+ },
1267
+ enumerable: false,
1268
+ configurable: true
1269
+ });
1270
+ Manager.prototype.Init = function () {
1271
+ return __awaiter(this, void 0, void 0, function () {
1272
+ var _this = this;
1273
+ return __generator(this, function (_a) {
1274
+ if (this.disposed) {
1275
+ throw (new Error("This item is disposed."));
1276
+ }
1277
+ this.getter = new bruceModels.EntityFilterGetter.Getter(this.api, new CesiumViewMonitor(this.viewer), this.item.BruceEntity["EntityType.ID"], 500, {});
1278
+ this.getter.IncludeMenuItem(this.item.id, [], 0, 100000);
1279
+ this.getterSub = this.getter.OnUpdate.Subscribe(function (entities) {
1280
+ _this.onGetterUpdate(entities);
1281
+ });
1282
+ this.viewMonitorRemoval = new CesiumViewMonitor(this.viewer).Updated().Subscribe(function () {
1283
+ _this.entityCheckQueue.Call();
1284
+ });
1285
+ this.entityCheckQueue = new bruceModels.DelayQueue(function () {
1286
+ _this.doEntityCheck();
1287
+ }, 3000);
1288
+ return [2 /*return*/];
1289
+ });
1290
+ });
1291
+ };
1292
+ Manager.prototype.Dispose = function () {
1293
+ var _a, _b, _c;
1294
+ if (this.disposed) {
1295
+ return;
1296
+ }
1297
+ (_a = this.getterSub) === null || _a === void 0 ? void 0 : _a.call(this);
1298
+ this.getterSub = null;
1299
+ this.disposed = true;
1300
+ this.visualsManager.RemoveByMenuItemId(this.item.id);
1301
+ (_b = this.entityCheckRemoval) === null || _b === void 0 ? void 0 : _b.call(this);
1302
+ (_c = this.viewMonitorRemoval) === null || _c === void 0 ? void 0 : _c.call(this);
1303
+ };
1304
+ Manager.prototype.doEntityCheck = function () {
1305
+ return __awaiter(this, void 0, void 0, function () {
1306
+ var ids_1, CHECK_BATCH_SIZE_1, checkBatch, e_1;
1307
+ var _this = this;
1308
+ return __generator(this, function (_a) {
1309
+ switch (_a.label) {
1310
+ case 0:
1311
+ if (this.isRunningCheck) {
1312
+ this.entityCheckQueue.Call();
1313
+ return [2 /*return*/];
1314
+ }
1315
+ this.isRunningCheck = true;
1316
+ _a.label = 1;
1317
+ case 1:
1318
+ _a.trys.push([1, 5, , 6]);
1319
+ ids_1 = Object.keys(this.renderedEntities);
1320
+ if (this.disposed) {
1321
+ return [2 /*return*/];
1322
+ }
1323
+ if (!(ids_1.length > 0)) return [3 /*break*/, 4];
1324
+ CHECK_BATCH_SIZE_1 = 150;
1325
+ checkBatch = function () { return __awaiter(_this, void 0, void 0, function () {
1326
+ var entityIds, entities;
1327
+ return __generator(this, function (_a) {
1328
+ switch (_a.label) {
1329
+ case 0:
1330
+ entityIds = ids_1.splice(0, CHECK_BATCH_SIZE_1);
1331
+ return [4 /*yield*/, bruceModels.Entity.GetListByIds(this.api, entityIds)];
1332
+ case 1:
1333
+ entities = _a.sent();
1334
+ if (this.disposed) {
1335
+ return [2 /*return*/];
1336
+ }
1337
+ this.distributeGenerateBatches(entities);
1338
+ return [2 /*return*/];
1339
+ }
1340
+ });
1341
+ }); };
1342
+ _a.label = 2;
1343
+ case 2:
1344
+ if (!(ids_1.length > 0)) return [3 /*break*/, 4];
1345
+ return [4 /*yield*/, checkBatch()];
1346
+ case 3:
1347
+ _a.sent();
1348
+ return [3 /*break*/, 2];
1349
+ case 4: return [3 /*break*/, 6];
1350
+ case 5:
1351
+ e_1 = _a.sent();
1352
+ console.error(e_1);
1353
+ return [3 /*break*/, 6];
1354
+ case 6:
1355
+ this.isRunningCheck = false;
1356
+ return [2 /*return*/];
1357
+ }
1358
+ });
1359
+ });
1360
+ };
1361
+ Manager.prototype.distributeGenerateBatches = function (entities) {
1362
+ var BATCH_SIZE = 50;
1363
+ while (entities.length > 0) {
1364
+ var batch = entities.splice(0, BATCH_SIZE);
1365
+ this.onGetterUpdate(batch);
1366
+ }
1367
+ };
1368
+ Manager.prototype.onGetterUpdate = function (entities) {
1369
+ return __awaiter(this, void 0, void 0, function () {
1370
+ var cEntities, i, id, cEntity, visuals;
1371
+ return __generator(this, function (_a) {
1372
+ switch (_a.label) {
1373
+ case 0:
1374
+ if (this.disposed) {
1375
+ return [2 /*return*/];
1376
+ }
1377
+ return [4 /*yield*/, exports.EntityRenderEngine.Render({
1378
+ viewer: this.viewer,
1379
+ api: this.api,
1380
+ entities: entities,
1381
+ menuItemId: this.item.id,
1382
+ visualRegister: this.visualsManager,
1383
+ zoomControl: this.item.CameraZoomSettings
1384
+ })];
1385
+ case 1:
1386
+ cEntities = _a.sent();
1387
+ for (i = 0; i < entities.length; i++) {
1388
+ id = entities[i].Bruce.ID;
1389
+ cEntity = cEntities[id];
1390
+ this.renderedEntities[id] = !!cEntity;
1391
+ if (cEntity) {
1392
+ visuals = this.visualsManager.GetVisuals(id, this.item.id);
1393
+ if (visuals.length != 1 || (visuals.length > 0 && visuals[0] != cEntity)) {
1394
+ this.visualsManager.Add({
1395
+ entityId: id,
1396
+ menuItemId: this.item.id,
1397
+ visuals: [cEntity],
1398
+ priority: 0
1399
+ });
1400
+ }
1401
+ }
1402
+ else {
1403
+ this.visualsManager.Remove(id, this.item.id);
1404
+ }
1405
+ }
1406
+ return [2 /*return*/];
1407
+ }
1408
+ });
1409
+ });
1410
+ };
1411
+ return Manager;
1412
+ }());
1413
+ EntitiesRenderManager.Manager = Manager;
1414
+ })(exports.EntitiesRenderManager || (exports.EntitiesRenderManager = {}));
1415
+
1416
+ (function (EntitiesLoadedRenderManager) {
1417
+ var Manager = /** @class */ (function () {
1418
+ function Manager(viewer, visualsManager, api, item) {
1419
+ this.getter = null;
1420
+ this.getterSub = null;
1421
+ this.disposed = false;
1422
+ this.renderedEntities = {};
1423
+ this.viewer = viewer;
1424
+ this.api = api;
1425
+ this.item = item;
1426
+ this.visualsManager = visualsManager;
1427
+ }
1428
+ Object.defineProperty(Manager.prototype, "Disposed", {
1429
+ get: function () {
1430
+ return this.disposed;
1431
+ },
1432
+ enumerable: false,
1433
+ configurable: true
1434
+ });
1435
+ Manager.prototype.Init = function () {
1436
+ return __awaiter(this, void 0, void 0, function () {
1437
+ var _this = this;
1438
+ return __generator(this, function (_a) {
1439
+ if (this.disposed) {
1440
+ throw (new Error("This item is disposed."));
1441
+ }
1442
+ this.getter = new bruceModels.BatchedDataGetter.Getter(this.item.BruceEntity.Entities, new CesiumViewMonitor(this.viewer), 500);
1443
+ this.getterSub = this.getter.OnUpdate.Subscribe(function (entities) {
1444
+ _this.onGetterUpdate(entities);
1445
+ });
1446
+ return [2 /*return*/];
1447
+ });
1448
+ });
1449
+ };
1450
+ Manager.prototype.Dispose = function () {
1451
+ var _a;
1452
+ if (this.disposed) {
1453
+ return;
1454
+ }
1455
+ (_a = this.getterSub) === null || _a === void 0 ? void 0 : _a.call(this);
1456
+ this.getterSub = null;
1457
+ this.disposed = true;
1458
+ this.visualsManager.RemoveByMenuItemId(this.item.id);
1459
+ };
1460
+ Manager.prototype.onGetterUpdate = function (entities) {
1461
+ return __awaiter(this, void 0, void 0, function () {
1462
+ var cEntities, i, id, cEntity, visuals;
1463
+ return __generator(this, function (_a) {
1464
+ switch (_a.label) {
1465
+ case 0:
1466
+ if (this.disposed) {
1467
+ return [2 /*return*/];
1468
+ }
1469
+ return [4 /*yield*/, exports.EntityRenderEngine.Render({
1470
+ viewer: this.viewer,
1471
+ api: this.api,
1472
+ entities: entities,
1473
+ menuItemId: this.item.id,
1474
+ visualRegister: this.visualsManager,
1475
+ zoomControl: this.item.CameraZoomSettings
1476
+ })];
1477
+ case 1:
1478
+ cEntities = _a.sent();
1479
+ for (i = 0; i < entities.length; i++) {
1480
+ id = entities[i].Bruce.ID;
1481
+ cEntity = cEntities[id];
1482
+ this.renderedEntities[id] = !!cEntity;
1483
+ if (cEntity) {
1484
+ visuals = this.visualsManager.GetVisuals(id, this.item.id);
1485
+ if (visuals.length != 1 || (visuals.length > 0 && visuals[0] != cEntity)) {
1486
+ this.visualsManager.Add({
1487
+ entityId: id,
1488
+ menuItemId: this.item.id,
1489
+ visuals: [cEntity],
1490
+ priority: 0
1491
+ });
1492
+ }
1493
+ }
1494
+ else {
1495
+ this.visualsManager.Remove(id, this.item.id);
1496
+ }
1497
+ }
1498
+ return [2 /*return*/];
1499
+ }
1500
+ });
1501
+ });
1502
+ };
1503
+ return Manager;
1504
+ }());
1505
+ EntitiesLoadedRenderManager.Manager = Manager;
1506
+ })(exports.EntitiesLoadedRenderManager || (exports.EntitiesLoadedRenderManager = {}));
1507
+
1508
+ (function (EntitiesIdsRenderManager) {
1509
+ var Manager = /** @class */ (function () {
1510
+ function Manager(viewer, visualsManager, api, item) {
1511
+ this.getter = null;
1512
+ this.getterSub = null;
1513
+ this.disposed = false;
1514
+ this.renderedEntities = {};
1515
+ this.viewer = viewer;
1516
+ this.api = api;
1517
+ this.item = item;
1518
+ this.visualsManager = visualsManager;
1519
+ }
1520
+ Object.defineProperty(Manager.prototype, "Disposed", {
1521
+ get: function () {
1522
+ return this.disposed;
1523
+ },
1524
+ enumerable: false,
1525
+ configurable: true
1526
+ });
1527
+ Manager.prototype.Init = function () {
1528
+ return __awaiter(this, void 0, void 0, function () {
1529
+ var _this = this;
1530
+ return __generator(this, function (_a) {
1531
+ if (this.disposed) {
1532
+ throw (new Error("This item is disposed."));
1533
+ }
1534
+ this.getter = new bruceModels.BatchedDataGetter.Getter(this.item.BruceEntity.EntityIds, new CesiumViewMonitor(this.viewer), 500);
1535
+ this.getterSub = this.getter.OnUpdate.Subscribe(function (ids) {
1536
+ _this.onGetterUpdate(ids);
1537
+ });
1538
+ return [2 /*return*/];
1539
+ });
1540
+ });
1541
+ };
1542
+ Manager.prototype.Dispose = function () {
1543
+ var _a;
1544
+ if (this.disposed) {
1545
+ return;
1546
+ }
1547
+ (_a = this.getterSub) === null || _a === void 0 ? void 0 : _a.call(this);
1548
+ this.getterSub = null;
1549
+ this.disposed = true;
1550
+ this.visualsManager.RemoveByMenuItemId(this.item.id);
1551
+ };
1552
+ Manager.prototype.onGetterUpdate = function (entityIds) {
1553
+ return __awaiter(this, void 0, void 0, function () {
1554
+ var entities, cEntities, i, id, cEntity, visuals;
1555
+ return __generator(this, function (_a) {
1556
+ switch (_a.label) {
1557
+ case 0:
1558
+ if (this.disposed) {
1559
+ return [2 /*return*/];
1560
+ }
1561
+ return [4 /*yield*/, bruceModels.Entity.GetListByIds(this.api, entityIds)];
1562
+ case 1:
1563
+ entities = _a.sent();
1564
+ return [4 /*yield*/, exports.EntityRenderEngine.Render({
1565
+ viewer: this.viewer,
1566
+ api: this.api,
1567
+ entities: entities,
1568
+ menuItemId: this.item.id,
1569
+ visualRegister: this.visualsManager,
1570
+ zoomControl: this.item.CameraZoomSettings
1571
+ })];
1572
+ case 2:
1573
+ cEntities = _a.sent();
1574
+ for (i = 0; i < entities.length; i++) {
1575
+ id = entities[i].Bruce.ID;
1576
+ cEntity = cEntities[id];
1577
+ this.renderedEntities[id] = !!cEntity;
1578
+ if (cEntity) {
1579
+ visuals = this.visualsManager.GetVisuals(id, this.item.id);
1580
+ if (visuals.length != 1 || (visuals.length > 0 && visuals[0] != cEntity)) {
1581
+ this.visualsManager.Add({
1582
+ entityId: id,
1583
+ menuItemId: this.item.id,
1584
+ visuals: [cEntity],
1585
+ priority: 0
1586
+ });
1587
+ }
1588
+ }
1589
+ else {
1590
+ this.visualsManager.Remove(id, this.item.id);
1591
+ }
1592
+ }
1593
+ return [2 /*return*/];
1594
+ }
1595
+ });
1596
+ });
1597
+ };
1598
+ return Manager;
1599
+ }());
1600
+ EntitiesIdsRenderManager.Manager = Manager;
1601
+ })(exports.EntitiesIdsRenderManager || (exports.EntitiesIdsRenderManager = {}));
1602
+
1603
+ (function (EntityRenderManager) {
1604
+ var Manager = /** @class */ (function () {
1605
+ function Manager(viewer, visualsManager, api, item) {
1606
+ this.getter = null;
1607
+ this.getterSub = null;
1608
+ this.disposed = false;
1609
+ this.viewer = viewer;
1610
+ this.api = api;
1611
+ this.item = item;
1612
+ this.visualsManager = visualsManager;
1613
+ }
1614
+ Object.defineProperty(Manager.prototype, "Disposed", {
1615
+ get: function () {
1616
+ return this.disposed;
1617
+ },
1618
+ enumerable: false,
1619
+ configurable: true
1620
+ });
1621
+ Manager.prototype.Init = function () {
1622
+ return __awaiter(this, void 0, void 0, function () {
1623
+ var _this = this;
1624
+ return __generator(this, function (_a) {
1625
+ if (this.disposed) {
1626
+ throw (new Error("This item is disposed."));
1627
+ }
1628
+ this.getter = new bruceModels.BatchedDataGetter.Getter([this.item.BruceEntity.EntityId], new CesiumViewMonitor(this.viewer), 1);
1629
+ this.getterSub = this.getter.OnUpdate.Subscribe(function (ids) {
1630
+ _this.onGetterUpdate(ids[0]);
1631
+ });
1632
+ return [2 /*return*/];
1633
+ });
1634
+ });
1635
+ };
1636
+ Manager.prototype.Dispose = function () {
1637
+ var _a;
1638
+ if (this.disposed) {
1639
+ return;
1640
+ }
1641
+ this.disposed = true;
1642
+ (_a = this.getterSub) === null || _a === void 0 ? void 0 : _a.call(this);
1643
+ this.getterSub = null;
1644
+ this.visualsManager.RemoveByMenuItemId(this.item.id);
1645
+ };
1646
+ Manager.prototype.onGetterUpdate = function (id) {
1647
+ return __awaiter(this, void 0, void 0, function () {
1648
+ var entity, cEntities, cEntity, visuals;
1649
+ return __generator(this, function (_a) {
1650
+ switch (_a.label) {
1651
+ case 0:
1652
+ if (this.disposed) {
1653
+ return [2 /*return*/];
1654
+ }
1655
+ return [4 /*yield*/, bruceModels.Entity.Get(this.api, id)];
1656
+ case 1:
1657
+ entity = _a.sent();
1658
+ return [4 /*yield*/, exports.EntityRenderEngine.Render({
1659
+ viewer: this.viewer,
1660
+ api: this.api,
1661
+ entities: [entity],
1662
+ menuItemId: this.item.id,
1663
+ visualRegister: this.visualsManager,
1664
+ zoomControl: this.item.CameraZoomSettings
1665
+ })];
1666
+ case 2:
1667
+ cEntities = _a.sent();
1668
+ cEntity = cEntities[id];
1669
+ if (cEntity) {
1670
+ visuals = this.visualsManager.GetVisuals(id, this.item.id);
1671
+ if (visuals.length != 1 || (visuals.length > 0 && visuals[0] != cEntity)) {
1672
+ this.visualsManager.Add({
1673
+ entityId: entity.Bruce.ID,
1674
+ menuItemId: this.item.id,
1675
+ visuals: [cEntity],
1676
+ priority: 0
1677
+ });
1678
+ }
1679
+ }
1680
+ else {
1681
+ this.visualsManager.Remove(id, this.item.id);
1682
+ }
1683
+ return [2 /*return*/];
1684
+ }
1685
+ });
1686
+ });
1687
+ };
1688
+ return Manager;
1689
+ }());
1690
+ EntityRenderManager.Manager = Manager;
1691
+ })(exports.EntityRenderManager || (exports.EntityRenderManager = {}));
1692
+
1693
+ function colorToCColor$1(color) {
1694
+ return new Cesium.Color(color.red ? color.red / 255 : 0, color.green ? color.green / 255 : 0, color.blue ? color.blue / 255 : 0, color.alpha);
1695
+ }
1696
+ var TilesetRenderEngine;
1697
+ (function (TilesetRenderEngine) {
1698
+ function ApplySettings(cTileset, tileset) {
1699
+ if (tileset.type == bruceModels.Tileset.EType.Cad) {
1700
+ var settings = tileset.settings;
1701
+ var root = cTileset.root;
1702
+ var transform = settings.transform;
1703
+ if (!transform) {
1704
+ transform = {
1705
+ heading: 0,
1706
+ pitch: 0,
1707
+ roll: 0,
1708
+ scale: 1
1709
+ };
1710
+ }
1711
+ var point = settings.location;
1712
+ var pos = Cesium.Cartesian3.fromDegrees(point.longitude, point.latitude, point.altitude);
1713
+ var hpr = Cesium.HeadingPitchRoll.fromDegrees(transform.heading, transform.pitch, transform.roll, new Cesium.HeadingPitchRoll());
1714
+ root.transform = Cesium.Transforms.headingPitchRollToFixedFrame(pos, hpr);
1715
+ var scale = +(transform === null || transform === void 0 ? void 0 : transform.scale);
1716
+ if (!scale || scale <= 0) {
1717
+ scale = 0.000001;
1718
+ }
1719
+ var scaleMatrix = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(scale, scale, scale), new Cesium.Matrix4());
1720
+ root.transform = Cesium.Matrix4.multiply(root.transform, scaleMatrix, root.transform);
1721
+ // Force matrix to update
1722
+ root.updateTransform();
1723
+ var maxScreenSpaceError = settings.maximumScreenSpaceError;
1724
+ if (maxScreenSpaceError || maxScreenSpaceError == 0) {
1725
+ cTileset.maximumScreenSpaceError = maxScreenSpaceError;
1726
+ }
1727
+ }
1728
+ else {
1729
+ throw ("Not implemented.");
1730
+ }
1731
+ }
1732
+ TilesetRenderEngine.ApplySettings = ApplySettings;
1733
+ function Render(params) {
1734
+ if (params.tileset.type == bruceModels.Tileset.EType.Cad) {
1735
+ var cTileset_1 = new Cesium.Cesium3DTileset({
1736
+ url: bruceModels.Tileset.GetPublicFileUrl(params.api, params.tileset.id, "tileset.json") + "?generation=" + params.tileset.generateVersion
1737
+ });
1738
+ params.viewer.scene.primitives.add(cTileset_1);
1739
+ cTileset_1.readyPromise.then(function () {
1740
+ ApplySettings(cTileset_1, params.tileset);
1741
+ });
1742
+ return cTileset_1;
1743
+ }
1744
+ else {
1745
+ throw ("Not implemented.");
1746
+ }
1747
+ }
1748
+ TilesetRenderEngine.Render = Render;
1749
+ var CadStyler = /** @class */ (function () {
1750
+ function CadStyler(api, cTileset, fallbackStyleId, styleMapping) {
1751
+ this.disposed = false;
1752
+ this.loadedEntities = {};
1753
+ this.styleMappingLoaded = false;
1754
+ this.styleMappingsLoaded = {};
1755
+ this.fallbackStyle = null;
1756
+ this.runningQueues = 0;
1757
+ this.recordLoadQueue = [];
1758
+ this.recordCheckQueue = [];
1759
+ this.api = api;
1760
+ this.cTileset = cTileset;
1761
+ this.fallbackStyleId = fallbackStyleId;
1762
+ this.styleMapping = styleMapping;
1763
+ this.loadStyles();
1764
+ }
1765
+ Object.defineProperty(CadStyler.prototype, "Disposed", {
1766
+ get: function () {
1767
+ return this.disposed;
1768
+ },
1769
+ enumerable: false,
1770
+ configurable: true
1771
+ });
1772
+ CadStyler.prototype.QueueEntities = function (entities) {
1773
+ for (var i = 0; i < entities.length; i++) {
1774
+ var entity = entities[i];
1775
+ this.queueTilesetFeatureStyle(entity);
1776
+ }
1777
+ if (this.recordLoadQueue.length > 0) {
1778
+ this.processQueue();
1779
+ }
1780
+ };
1781
+ CadStyler.prototype.processQueue = function () {
1782
+ return __awaiter(this, void 0, void 0, function () {
1783
+ var MAX_BATCHES, BATCH_DELAY, batch, rerun, entityIds, entities, _loop_1, this_1, i;
1784
+ var _this = this;
1785
+ return __generator(this, function (_a) {
1786
+ switch (_a.label) {
1787
+ case 0:
1788
+ MAX_BATCHES = 2;
1789
+ BATCH_DELAY = 200;
1790
+ if (this.runningQueues >= MAX_BATCHES) {
1791
+ return [2 /*return*/];
1792
+ }
1793
+ else if (this.disposed) {
1794
+ return [2 /*return*/];
1795
+ }
1796
+ this.runningQueues += 1;
1797
+ batch = [];
1798
+ rerun = false;
1799
+ _a.label = 1;
1800
+ case 1:
1801
+ _a.trys.push([1, , 4, 5]);
1802
+ batch = this.getEntitiesForQueue();
1803
+ entityIds = batch.map(function (x) { return x.entityId; });
1804
+ if (!(entityIds.length > 0)) return [3 /*break*/, 3];
1805
+ return [4 /*yield*/, bruceModels.Entity.GetListByIds(this.api, entityIds)];
1806
+ case 2:
1807
+ entities = _a.sent();
1808
+ _loop_1 = function (i) {
1809
+ var record = entities[i];
1810
+ var feature = batch.find(function (x) { var _a; return (x === null || x === void 0 ? void 0 : x.entityId) == ((_a = record === null || record === void 0 ? void 0 : record.Bruce) === null || _a === void 0 ? void 0 : _a.ID); });
1811
+ if (feature) {
1812
+ this_1.styleTilesetFeatureFullData(feature, record);
1813
+ }
1814
+ };
1815
+ this_1 = this;
1816
+ for (i = 0; i < entities.length; i++) {
1817
+ _loop_1(i);
1818
+ }
1819
+ rerun = batch.length > 0;
1820
+ _a.label = 3;
1821
+ case 3: return [3 /*break*/, 5];
1822
+ case 4:
1823
+ setTimeout(function () {
1824
+ _this.runningQueues -= 1;
1825
+ if (rerun) {
1826
+ _this.processQueue();
1827
+ }
1828
+ }, BATCH_DELAY);
1829
+ return [7 /*endfinally*/];
1830
+ case 5: return [2 /*return*/];
1831
+ }
1832
+ });
1833
+ });
1834
+ };
1835
+ CadStyler.prototype.getEntitiesForQueue = function () {
1836
+ var BATCH_SIZE = 30;
1837
+ var batchHashes = this.recordLoadQueue.splice(0, BATCH_SIZE);
1838
+ var entities = [];
1839
+ for (var i = 0; i < batchHashes.length; i++) {
1840
+ var id = batchHashes[i];
1841
+ var entity = this.loadedEntities[id];
1842
+ if (entity) {
1843
+ entities.push(entity);
1844
+ }
1845
+ }
1846
+ return entities;
1847
+ };
1848
+ CadStyler.prototype.Dispose = function () {
1849
+ if (this.disposed) {
1850
+ return;
1851
+ }
1852
+ this.disposed = true;
1853
+ clearInterval(this.queueLoadInterval);
1854
+ clearInterval(this.queueCheckInterval);
1855
+ };
1856
+ CadStyler.prototype.loadStyles = function () {
1857
+ var _a, _b;
1858
+ return __awaiter(this, void 0, void 0, function () {
1859
+ var fallbackStyleId, data, e_1, styleMapping, modelTree, entityTypeIds, _loop_2, i, i, styleMap, styleId, entityType, e_2, data, e_3;
1860
+ return __generator(this, function (_c) {
1861
+ switch (_c.label) {
1862
+ case 0:
1863
+ fallbackStyleId = this.fallbackStyleId;
1864
+ if (!(fallbackStyleId && fallbackStyleId > 0)) return [3 /*break*/, 4];
1865
+ _c.label = 1;
1866
+ case 1:
1867
+ _c.trys.push([1, 3, , 4]);
1868
+ return [4 /*yield*/, bruceModels.Style.Get(this.api, fallbackStyleId)];
1869
+ case 2:
1870
+ data = _c.sent();
1871
+ this.fallbackStyle = data;
1872
+ return [3 /*break*/, 4];
1873
+ case 3:
1874
+ e_1 = _c.sent();
1875
+ console.error(e_1);
1876
+ return [3 /*break*/, 4];
1877
+ case 4:
1878
+ styleMapping = this.styleMapping;
1879
+ if (!styleMapping) {
1880
+ styleMapping = [];
1881
+ }
1882
+ this.styleMapping = styleMapping;
1883
+ // It is default style.
1884
+ // We have to get all possible entity type ids and append them to mapping.
1885
+ if (!fallbackStyleId) {
1886
+ try {
1887
+ modelTree = (_b = (_a = this.cTileset) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.modelTree;
1888
+ if (modelTree) {
1889
+ entityTypeIds = this.getEntityTypeIdsFromModelTree(modelTree);
1890
+ _loop_2 = function (i) {
1891
+ var entityTypeId = entityTypeIds[i];
1892
+ if (styleMapping.findIndex(function (x) { return x.EntityTypeID == entityTypeId; }) <= -1) {
1893
+ styleMapping.push({
1894
+ EntityTypeID: entityTypeId,
1895
+ StyleID: null,
1896
+ style: null
1897
+ });
1898
+ }
1899
+ };
1900
+ for (i = 0; i < entityTypeIds.length; i++) {
1901
+ _loop_2(i);
1902
+ }
1903
+ }
1904
+ }
1905
+ catch (e) {
1906
+ console.log(e);
1907
+ }
1908
+ }
1909
+ i = 0;
1910
+ _c.label = 5;
1911
+ case 5:
1912
+ if (!(i < styleMapping.length)) return [3 /*break*/, 15];
1913
+ if (this.disposed) {
1914
+ return [3 /*break*/, 15];
1915
+ }
1916
+ styleMap = styleMapping[i];
1917
+ if (!!styleMap.style) return [3 /*break*/, 13];
1918
+ styleId = styleMap.StyleID;
1919
+ if (!!styleId) return [3 /*break*/, 9];
1920
+ _c.label = 6;
1921
+ case 6:
1922
+ _c.trys.push([6, 8, , 9]);
1923
+ return [4 /*yield*/, bruceModels.EntityType.Get(this.api, styleMap.EntityTypeID)];
1924
+ case 7:
1925
+ entityType = _c.sent();
1926
+ styleId = entityType === null || entityType === void 0 ? void 0 : entityType["DisplaySetting.ID"];
1927
+ return [3 /*break*/, 9];
1928
+ case 8:
1929
+ e_2 = _c.sent();
1930
+ console.error(e_2);
1931
+ return [3 /*break*/, 9];
1932
+ case 9:
1933
+ if (!styleId) return [3 /*break*/, 13];
1934
+ _c.label = 10;
1935
+ case 10:
1936
+ _c.trys.push([10, 12, , 13]);
1937
+ return [4 /*yield*/, bruceModels.Style.Get(this.api, styleId)];
1938
+ case 11:
1939
+ data = _c.sent();
1940
+ if (data) {
1941
+ styleMap.style = data;
1942
+ styleMap.StyleID = styleId;
1943
+ }
1944
+ return [3 /*break*/, 13];
1945
+ case 12:
1946
+ e_3 = _c.sent();
1947
+ console.error(e_3);
1948
+ return [3 /*break*/, 13];
1949
+ case 13:
1950
+ if (styleMap.EntityTypeID && styleMap.style) {
1951
+ this.styleMappingsLoaded[styleMap.EntityTypeID] = true;
1952
+ this.processTilesetFeatureCheckQueue();
1953
+ this.processQueue();
1954
+ }
1955
+ _c.label = 14;
1956
+ case 14:
1957
+ i++;
1958
+ return [3 /*break*/, 5];
1959
+ case 15:
1960
+ this.styleMappingLoaded = true;
1961
+ if (!!this.disposed) return [3 /*break*/, 17];
1962
+ return [4 /*yield*/, this.processTilesetFeatureCheckQueue()];
1963
+ case 16:
1964
+ _c.sent();
1965
+ this.processQueue();
1966
+ _c.label = 17;
1967
+ case 17: return [2 /*return*/];
1968
+ }
1969
+ });
1970
+ });
1971
+ };
1972
+ CadStyler.prototype.getEntityTypeIdsFromModelTree = function (modelTree) {
1973
+ var entityTypeIds = [];
1974
+ this.digEntityTypeIdsFromModelTreeBranch(modelTree, entityTypeIds);
1975
+ return entityTypeIds;
1976
+ };
1977
+ CadStyler.prototype.digEntityTypeIdsFromModelTreeBranch = function (branch, arr) {
1978
+ if (branch) {
1979
+ // Does not yet include this entity type id.
1980
+ if (branch.typeId && !arr.includes(branch.typeId)) {
1981
+ arr.push(branch.typeId);
1982
+ }
1983
+ if (branch.children) {
1984
+ for (var i = 0; i < branch.children.length; i++) {
1985
+ var child = branch.children[i];
1986
+ this.digEntityTypeIdsFromModelTreeBranch(child, arr);
1987
+ }
1988
+ }
1989
+ }
1990
+ };
1991
+ CadStyler.prototype.processTilesetFeatureCheckQueue = function () {
1992
+ return __awaiter(this, void 0, void 0, function () {
1993
+ var BATCH_CHECK_SIZE;
1994
+ var _this = this;
1995
+ return __generator(this, function (_a) {
1996
+ BATCH_CHECK_SIZE = 1000;
1997
+ return [2 /*return*/, new Promise(function (res) {
1998
+ clearInterval(_this.queueCheckInterval);
1999
+ _this.queueCheckInterval = setInterval(function () {
2000
+ if (_this.disposed) {
2001
+ clearInterval(_this.queueCheckInterval);
2002
+ res();
2003
+ return;
2004
+ }
2005
+ // Construct batch for loaded styles.
2006
+ var batch = [];
2007
+ if (_this.styleMappingLoaded) {
2008
+ batch = _this.recordCheckQueue.splice(0, BATCH_CHECK_SIZE);
2009
+ }
2010
+ else {
2011
+ for (var i = 0; i < _this.recordCheckQueue.length; i++) {
2012
+ var hash = _this.recordCheckQueue[i];
2013
+ var entity = _this.loadedEntities[hash];
2014
+ if (entity) {
2015
+ var entityTypeId = entity.entityTypeId;
2016
+ if (entityTypeId) {
2017
+ if (_this.styleMappingsLoaded[entityTypeId] == true) {
2018
+ batch.push(hash);
2019
+ }
2020
+ }
2021
+ }
2022
+ if (batch.length >= BATCH_CHECK_SIZE) {
2023
+ break;
2024
+ }
2025
+ }
2026
+ var _loop_3 = function (i) {
2027
+ var hash = batch[i];
2028
+ var index = _this.recordCheckQueue.findIndex(function (x) { return x == hash; });
2029
+ if (index > -1) {
2030
+ _this.recordCheckQueue.splice(index, 1);
2031
+ }
2032
+ };
2033
+ for (var i = 0; i < batch.length; i++) {
2034
+ _loop_3(i);
2035
+ }
2036
+ }
2037
+ if (batch.length) {
2038
+ for (var i = 0; i < batch.length; i++) {
2039
+ var item = batch[i];
2040
+ var entity = _this.loadedEntities[item];
2041
+ if (entity) {
2042
+ _this.queueTilesetFeatureStyle(entity);
2043
+ }
2044
+ }
2045
+ }
2046
+ else {
2047
+ clearInterval(_this.queueCheckInterval);
2048
+ res();
2049
+ }
2050
+ }, 50);
2051
+ })];
2052
+ });
2053
+ });
2054
+ };
2055
+ CadStyler.prototype.queueTilesetFeatureStyle = function (entity) {
2056
+ if (this.styleMappingLoaded || this.styleMappingsLoaded[entity.entityTypeId] == true) {
2057
+ var needsData = this.getTilesetFeatureNeedsFullData(entity.entityId, entity.entityTypeId);
2058
+ if (needsData) {
2059
+ if (this.recordLoadQueue.findIndex(function (x) { return x == entity.entityId; })) {
2060
+ this.recordLoadQueue.push(entity.entityId);
2061
+ }
2062
+ }
2063
+ else {
2064
+ this.styleTilesetFeature(entity);
2065
+ }
2066
+ }
2067
+ else {
2068
+ this.recordCheckQueue.push(entity.entityId);
2069
+ }
2070
+ };
2071
+ CadStyler.prototype.styleTilesetFeature = function (entity) {
2072
+ this.styleTilesetFeatureFullData(entity, null);
2073
+ };
2074
+ CadStyler.prototype.styleTilesetFeatureFullData = function (entity, data) {
2075
+ var _a;
2076
+ var style = this.getTilesetFeatureStyle(entity.entityId, entity.entityTypeId);
2077
+ if (!style) {
2078
+ return;
2079
+ }
2080
+ var bColor = (((_a = style.modelStyle) === null || _a === void 0 ? void 0 : _a.fillColor) ? bruceModels.Calculator.GetValue(style.modelStyle.fillColor, data, []) : null);
2081
+ if (bColor != null) {
2082
+ var cColor = colorToCColor$1(bColor);
2083
+ var visual = entity.visuals.length > 0 ? entity.visuals[0] : null;
2084
+ if (visual && visual instanceof Cesium.Cesium3DTileFeature) {
2085
+ visual.color = cColor;
2086
+ }
2087
+ }
2088
+ };
2089
+ CadStyler.prototype.getTilesetFeatureStyle = function (entityId, entityTypeId) {
2090
+ var _a, _b, _c;
2091
+ // Locate what style is applicable to the feature.
2092
+ var style = null;
2093
+ if (entityTypeId) {
2094
+ style = (_a = this.styleMapping.find(function (x) { return x.EntityTypeID == entityTypeId; })) === null || _a === void 0 ? void 0 : _a.style;
2095
+ }
2096
+ if (!style) {
2097
+ style = this.fallbackStyle;
2098
+ }
2099
+ if (!style) {
2100
+ return null;
2101
+ }
2102
+ if (!((_c = (_b = style.Settings) === null || _b === void 0 ? void 0 : _b.modelStyle) === null || _c === void 0 ? void 0 : _c.customize)) {
2103
+ return null;
2104
+ }
2105
+ return style.Settings;
2106
+ };
2107
+ CadStyler.prototype.getTilesetFeatureNeedsFullData = function (entityId, entityTypeId) {
2108
+ var _a;
2109
+ var style = this.getTilesetFeatureStyle(entityId, entityTypeId);
2110
+ if (!style) {
2111
+ return false;
2112
+ }
2113
+ var fill = (_a = style === null || style === void 0 ? void 0 : style.modelStyle) === null || _a === void 0 ? void 0 : _a.fillColor;
2114
+ if (!fill || fill.length <= 0) {
2115
+ return false;
2116
+ }
2117
+ return fill[0].type != 0;
2118
+ };
2119
+ return CadStyler;
2120
+ }());
2121
+ TilesetRenderEngine.CadStyler = CadStyler;
2122
+ })(TilesetRenderEngine || (TilesetRenderEngine = {}));
2123
+
2124
+ (function (TilesetCadRenderManager) {
2125
+ var Manager = /** @class */ (function () {
2126
+ function Manager(viewer, visualsManager, api, item) {
2127
+ this.disposed = false;
2128
+ this.cTileset = null;
2129
+ this.styler = null;
2130
+ this.viewer = viewer;
2131
+ this.api = api;
2132
+ this.item = item;
2133
+ this.visualsManager = visualsManager;
2134
+ }
2135
+ Object.defineProperty(Manager.prototype, "Disposed", {
2136
+ get: function () {
2137
+ return this.disposed;
2138
+ },
2139
+ enumerable: false,
2140
+ configurable: true
2141
+ });
2142
+ Manager.prototype.Init = function () {
2143
+ var _a;
2144
+ return __awaiter(this, void 0, void 0, function () {
2145
+ var tilesetId, tileset, cTileset;
2146
+ var _this = this;
2147
+ return __generator(this, function (_b) {
2148
+ switch (_b.label) {
2149
+ case 0:
2150
+ tilesetId = (_a = this.item.tileset) === null || _a === void 0 ? void 0 : _a.TilesetID;
2151
+ if (!tilesetId) {
2152
+ return [2 /*return*/];
2153
+ }
2154
+ return [4 /*yield*/, bruceModels.Tileset.Get(this.api, tilesetId)];
2155
+ case 1:
2156
+ tileset = _b.sent();
2157
+ if (!tileset) {
2158
+ return [2 /*return*/];
2159
+ }
2160
+ cTileset = this.cTileset = TilesetRenderEngine.Render({
2161
+ api: this.api,
2162
+ tileset: tileset,
2163
+ viewer: this.viewer
2164
+ });
2165
+ cTileset.readyPromise.then(function () {
2166
+ _this.onCTilesetLoad();
2167
+ });
2168
+ cTileset.tileLoad.addEventListener(function (tile) {
2169
+ _this.mapCTile(tile);
2170
+ });
2171
+ this.styler = new TilesetRenderEngine.CadStyler(this.api, this.cTileset, this.item.styleId, this.item.StyleMapping);
2172
+ return [2 /*return*/];
2173
+ }
2174
+ });
2175
+ });
2176
+ };
2177
+ Manager.prototype.onCTilesetLoad = function () {
2178
+ if (this.disposed) {
2179
+ return;
2180
+ }
2181
+ if (this.item.FlyTo) {
2182
+ this.viewer.zoomTo(this.cTileset, new Cesium.HeadingPitchRange(0.0, -0.5, this.cTileset.boundingSphere.radius / 4.0));
2183
+ }
2184
+ };
2185
+ Manager.prototype.mapCTile = function (tile) {
2186
+ var content = tile.content;
2187
+ for (var i = 0; i < content.featuresLength; i++) {
2188
+ var feature = content.getFeature(i);
2189
+ var rego = this.mapTilesetFeature(feature);
2190
+ if (rego === null || rego === void 0 ? void 0 : rego.entityId) {
2191
+ this.styler.QueueEntities([rego]);
2192
+ }
2193
+ }
2194
+ };
2195
+ Manager.prototype.mapTilesetFeature = function (feature) {
2196
+ var _a, _b, _c;
2197
+ var version = (_c = (_b = (_a = feature === null || feature === void 0 ? void 0 : feature.tileset) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.modelTree) === null || _c === void 0 ? void 0 : _c.version;
2198
+ if (!version) {
2199
+ version = 1;
2200
+ }
2201
+ var rego = {
2202
+ entityId: null,
2203
+ entityTypeId: null,
2204
+ menuItemId: this.item.id,
2205
+ priority: 0,
2206
+ visuals: [feature]
2207
+ };
2208
+ if (version == 1) {
2209
+ var pathStr = feature.getProperty("BrucePath");
2210
+ if (pathStr != undefined) {
2211
+ var path = pathStr.split("|");
2212
+ var entityTypeId = this.getEntityTypeByPath(path);
2213
+ rego.entityTypeId = entityTypeId;
2214
+ rego.entityId = path[path.length - 1];
2215
+ }
2216
+ }
2217
+ else if (version == 2) {
2218
+ var geomId = +feature.getProperty("GeomId");
2219
+ if (geomId != null && (!!geomId || geomId == 0)) {
2220
+ var meta = this.getMetaByGeomId(geomId, feature.tileset);
2221
+ if (meta) {
2222
+ rego.entityId = meta.id;
2223
+ rego.entityTypeId = meta.typeId;
2224
+ }
2225
+ }
2226
+ }
2227
+ else {
2228
+ console.log("Unhandled tileset tree version = " + version);
2229
+ }
2230
+ if (rego === null || rego === void 0 ? void 0 : rego.entityId) {
2231
+ this.visualsManager.Add(rego);
2232
+ return rego;
2233
+ }
2234
+ return null;
2235
+ };
2236
+ Manager.prototype.getMetaByGeomId = function (geomId, tileset) {
2237
+ var _a;
2238
+ var modelTree = (_a = tileset === null || tileset === void 0 ? void 0 : tileset.extensions) === null || _a === void 0 ? void 0 : _a.modelTree;
2239
+ return this.digMetaByGeomId(geomId, modelTree, []);
2240
+ };
2241
+ Manager.prototype.digMetaByGeomId = function (geomId, branch, path) {
2242
+ path = [].concat(path);
2243
+ path.push(branch.id);
2244
+ if (branch.geomId == geomId) {
2245
+ return { id: path[path.length - 1], typeId: branch.typeId };
2246
+ }
2247
+ else if (branch.children) {
2248
+ for (var i = 0; i < branch.children.length; i++) {
2249
+ var meta = this.digMetaByGeomId(geomId, branch.children[i], path);
2250
+ if (meta) {
2251
+ return meta;
2252
+ }
2253
+ }
2254
+ }
2255
+ return null;
2256
+ };
2257
+ Manager.prototype.getEntityTypeByPath = function (path) {
2258
+ var _a, _b;
2259
+ var modelTree = (_b = (_a = this.cTileset) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.modelTree;
2260
+ if (modelTree) {
2261
+ var data = this.digModelTreeByPath(modelTree, path);
2262
+ if (data) {
2263
+ return data.typeId;
2264
+ }
2265
+ }
2266
+ return null;
2267
+ };
2268
+ Manager.prototype.digModelTreeByPath = function (branch, path) {
2269
+ // Dereference.
2270
+ path = JSON.parse(JSON.stringify(path));
2271
+ if (path.length <= 0) {
2272
+ return null;
2273
+ }
2274
+ var pathTop = path.splice(0, 1)[0];
2275
+ if (pathTop != branch.id) {
2276
+ return null;
2277
+ }
2278
+ else if (path.length == 0 && pathTop == branch.id) {
2279
+ return branch;
2280
+ }
2281
+ else if (branch.children) {
2282
+ for (var i = 0; i < branch.children.length; i++) {
2283
+ var foundPath = this.digModelTreeByPath(branch.children[i], path);
2284
+ if (foundPath) {
2285
+ return foundPath;
2286
+ }
2287
+ }
2288
+ }
2289
+ return null;
2290
+ };
2291
+ Manager.prototype.Dispose = function () {
2292
+ if (this.disposed) {
2293
+ return;
2294
+ }
2295
+ this.disposed = true;
2296
+ if (this.cTileset) {
2297
+ this.cTileset.show = false;
2298
+ }
2299
+ this.styler.Dispose();
2300
+ this.visualsManager.RemoveByMenuItemId(this.item.id);
2301
+ };
2302
+ return Manager;
2303
+ }());
2304
+ TilesetCadRenderManager.Manager = Manager;
2305
+ })(exports.TilesetCadRenderManager || (exports.TilesetCadRenderManager = {}));
2306
+
2307
+ var MenuItemManager = /** @class */ (function () {
2308
+ function MenuItemManager(viewer, visualsRegister) {
2309
+ this.items = [];
2310
+ this.viewer = viewer;
2311
+ this.visualsRegister = visualsRegister;
2312
+ }
2313
+ MenuItemManager.prototype.RenderItem = function (api, item) {
2314
+ var _a;
2315
+ return __awaiter(this, void 0, void 0, function () {
2316
+ var rItem, i, childId;
2317
+ return __generator(this, function (_b) {
2318
+ switch (_b.label) {
2319
+ case 0:
2320
+ rItem = {
2321
+ id: (_a = item.id) !== null && _a !== void 0 ? _a : bruceModels.ObjectUtils.UId(),
2322
+ childIds: [],
2323
+ item: item,
2324
+ renderManager: null,
2325
+ type: item.Type
2326
+ };
2327
+ switch (item.Type) {
2328
+ case bruceModels.MenuItem.EType.Entities:
2329
+ rItem.renderManager = new exports.EntitiesRenderManager.Manager(this.viewer, this.visualsRegister, api, item);
2330
+ break;
2331
+ case bruceModels.MenuItem.EType.EntitiesLoaded:
2332
+ rItem.renderManager = new exports.EntitiesLoadedRenderManager.Manager(this.viewer, this.visualsRegister, api, item);
2333
+ break;
2334
+ case bruceModels.MenuItem.EType.EntitiesIds:
2335
+ rItem.renderManager = new exports.EntitiesIdsRenderManager.Manager(this.viewer, this.visualsRegister, api, item);
2336
+ break;
2337
+ case bruceModels.MenuItem.EType.Entity:
2338
+ rItem.renderManager = new exports.EntityRenderManager.Manager(this.viewer, this.visualsRegister, api, item);
2339
+ case bruceModels.MenuItem.EType.CadTileset:
2340
+ rItem.renderManager = new exports.TilesetCadRenderManager.Manager(this.viewer, this.visualsRegister, api, item);
2341
+ break;
2342
+ case bruceModels.MenuItem.EType.Osm:
2343
+ // TODO;
2344
+ break;
2345
+ case bruceModels.MenuItem.EType.PointCloud:
2346
+ // TODO;
2347
+ break;
2348
+ case bruceModels.MenuItem.EType.EntityTileset:
2349
+ // TODO;
2350
+ break;
2351
+ case bruceModels.MenuItem.EType.Kml:
2352
+ // TODO;
2353
+ break;
2354
+ // Any "none" type can be ignored. These are just containers for other items.
2355
+ case bruceModels.MenuItem.EType.None:
2356
+ case "":
2357
+ case null:
2358
+ break;
2359
+ default:
2360
+ throw ("Menu item type is not implemented.");
2361
+ }
2362
+ if (!rItem.renderManager) return [3 /*break*/, 2];
2363
+ return [4 /*yield*/, rItem.renderManager.Init()];
2364
+ case 1:
2365
+ _b.sent();
2366
+ _b.label = 2;
2367
+ case 2:
2368
+ this.items.push(rItem);
2369
+ if (!item.Children) return [3 /*break*/, 6];
2370
+ i = 0;
2371
+ _b.label = 3;
2372
+ case 3:
2373
+ if (!(i < item.Children.length)) return [3 /*break*/, 6];
2374
+ return [4 /*yield*/, this.RenderItem(api, item.Children[i])];
2375
+ case 4:
2376
+ childId = _b.sent();
2377
+ rItem.childIds.push(childId);
2378
+ _b.label = 5;
2379
+ case 5:
2380
+ i++;
2381
+ return [3 /*break*/, 3];
2382
+ case 6: return [2 /*return*/, rItem.id];
2383
+ }
2384
+ });
2385
+ });
2386
+ };
2387
+ MenuItemManager.prototype.RemoveItemById = function (id) {
2388
+ return __awaiter(this, void 0, void 0, function () {
2389
+ var item, _loop_1, this_1, i;
2390
+ return __generator(this, function (_a) {
2391
+ switch (_a.label) {
2392
+ case 0:
2393
+ item = this.items.find(function (x) { return x.id === id; });
2394
+ if (!item) return [3 /*break*/, 5];
2395
+ _loop_1 = function (i) {
2396
+ var child;
2397
+ return __generator(this, function (_a) {
2398
+ switch (_a.label) {
2399
+ case 0:
2400
+ child = this_1.items.find(function (x) { return x.id === item.childIds[i]; });
2401
+ if (!child) return [3 /*break*/, 2];
2402
+ return [4 /*yield*/, this_1.RemoveItemById(child.id)];
2403
+ case 1:
2404
+ _a.sent();
2405
+ _a.label = 2;
2406
+ case 2: return [2 /*return*/];
2407
+ }
2408
+ });
2409
+ };
2410
+ this_1 = this;
2411
+ i = 0;
2412
+ _a.label = 1;
2413
+ case 1:
2414
+ if (!(i < item.childIds.length)) return [3 /*break*/, 4];
2415
+ return [5 /*yield**/, _loop_1(i)];
2416
+ case 2:
2417
+ _a.sent();
2418
+ _a.label = 3;
2419
+ case 3:
2420
+ i++;
2421
+ return [3 /*break*/, 1];
2422
+ case 4:
2423
+ try {
2424
+ item.renderManager.Dispose();
2425
+ }
2426
+ catch (e) {
2427
+ console.error(e);
2428
+ }
2429
+ this.items = this.items.filter(function (x) { return x.id !== id; });
2430
+ _a.label = 5;
2431
+ case 5: return [2 /*return*/];
2432
+ }
2433
+ });
2434
+ });
2435
+ };
2436
+ return MenuItemManager;
2437
+ }());
2438
+
2439
+ (function (RenderHelper) {
2440
+ function RenderEntities(manager, api, entityIds) {
2441
+ return __awaiter(this, void 0, void 0, function () {
2442
+ var item;
2443
+ return __generator(this, function (_a) {
2444
+ switch (_a.label) {
2445
+ case 0:
2446
+ item = {
2447
+ Caption: "Rendering Loaded Entities",
2448
+ Type: bruceModels.MenuItem.EType.EntitiesLoaded,
2449
+ id: bruceModels.ObjectUtils.UId(),
2450
+ Children: [],
2451
+ BruceEntity: {
2452
+ EntityIds: entityIds
2453
+ },
2454
+ CameraZoomSettings: [
2455
+ {
2456
+ DisplayType: bruceModels.ZoomControl.EDisplayType.Model3D,
2457
+ LODCategoryID: "glb",
2458
+ LODLevel: 0,
2459
+ MaxZoom: 100000,
2460
+ MinZoom: 0,
2461
+ StyleID: 0 // 0 = Attempt to get entity type's default.
2462
+ }
2463
+ ]
2464
+ };
2465
+ return [4 /*yield*/, manager.RenderItem(api, item)];
2466
+ case 1: return [2 /*return*/, _a.sent()];
2467
+ }
2468
+ });
2469
+ });
2470
+ }
2471
+ RenderHelper.RenderEntities = RenderEntities;
2472
+ function RenderEntityTypes(manager, api, typeIds) {
2473
+ var _a;
2474
+ return __awaiter(this, void 0, void 0, function () {
2475
+ var groupItem, i, typeId, menuItem;
2476
+ return __generator(this, function (_b) {
2477
+ switch (_b.label) {
2478
+ case 0:
2479
+ groupItem = {
2480
+ Caption: "Rendering Entity Types",
2481
+ Type: bruceModels.MenuItem.EType.None,
2482
+ id: bruceModels.ObjectUtils.UId(),
2483
+ Children: []
2484
+ };
2485
+ for (i = 0; i < typeIds.length; i++) {
2486
+ typeId = typeIds[i];
2487
+ menuItem = bruceModels.MenuItem.CreateFromTypeId(typeId, 0);
2488
+ (_a = groupItem.Children) === null || _a === void 0 ? void 0 : _a.push(menuItem);
2489
+ }
2490
+ return [4 /*yield*/, manager.RenderItem(api, groupItem)];
2491
+ case 1: return [2 /*return*/, _b.sent()];
2492
+ }
2493
+ });
2494
+ });
2495
+ }
2496
+ RenderHelper.RenderEntityTypes = RenderEntityTypes;
2497
+ function RenderEntityFilter(viewer, api, filter) {
2498
+ return __awaiter(this, void 0, void 0, function () {
2499
+ return __generator(this, function (_a) {
2500
+ throw (new Error("Not implemented."));
2501
+ });
2502
+ });
2503
+ }
2504
+ RenderHelper.RenderEntityFilter = RenderEntityFilter;
2505
+ function RenderBookmark(viewer, api, viewId, bookmarkId) {
2506
+ return __awaiter(this, void 0, void 0, function () {
2507
+ return __generator(this, function (_a) {
2508
+ throw (new Error("Not implemented."));
2509
+ });
2510
+ });
2511
+ }
2512
+ RenderHelper.RenderBookmark = RenderBookmark;
2513
+ function RenderMenuItems(manager, api, menuItems) {
2514
+ var _a;
2515
+ return __awaiter(this, void 0, void 0, function () {
2516
+ var groupItem, i, menuItem;
2517
+ return __generator(this, function (_b) {
2518
+ switch (_b.label) {
2519
+ case 0:
2520
+ groupItem = {
2521
+ Caption: "Rendering Menu Items",
2522
+ Type: bruceModels.MenuItem.EType.None,
2523
+ id: bruceModels.ObjectUtils.UId(),
2524
+ Children: []
2525
+ };
2526
+ for (i = 0; i < menuItems.length; i++) {
2527
+ menuItem = menuItems[i];
2528
+ (_a = groupItem.Children) === null || _a === void 0 ? void 0 : _a.push(menuItem);
2529
+ }
2530
+ return [4 /*yield*/, manager.RenderItem(api, groupItem)];
2531
+ case 1: return [2 /*return*/, _b.sent()];
2532
+ }
2533
+ });
2534
+ });
2535
+ }
2536
+ RenderHelper.RenderMenuItems = RenderMenuItems;
2537
+ function RenderTileset(manager, api, tilesetId) {
2538
+ return __awaiter(this, void 0, void 0, function () {
2539
+ var tileset, menuItem;
2540
+ return __generator(this, function (_a) {
2541
+ switch (_a.label) {
2542
+ case 0: return [4 /*yield*/, bruceModels.Tileset.Get(api, tilesetId)];
2543
+ case 1:
2544
+ tileset = _a.sent();
2545
+ if (!(tileset.type == bruceModels.Tileset.EType.Cad)) return [3 /*break*/, 3];
2546
+ menuItem = {
2547
+ Caption: "Rendering Tileset",
2548
+ FlyTo: true,
2549
+ id: bruceModels.ObjectUtils.UId(),
2550
+ tileset: {
2551
+ TilesetID: tilesetId
2552
+ },
2553
+ Type: bruceModels.MenuItem.EType.CadTileset,
2554
+ styleId: 0,
2555
+ Children: []
2556
+ };
2557
+ return [4 /*yield*/, manager.RenderItem(api, menuItem)];
2558
+ case 2: return [2 /*return*/, _a.sent()];
2559
+ case 3: throw (new Error("Tileset type not supported."));
2560
+ }
2561
+ });
2562
+ });
2563
+ }
2564
+ RenderHelper.RenderTileset = RenderTileset;
2565
+ })(exports.RenderHelper || (exports.RenderHelper = {}));
2566
+
2567
+ function removeEntity(viewer, visuals) {
2568
+ unmarkEntity(visuals);
2569
+ for (var i = 0; i < visuals.length; i++) {
2570
+ var visual = visuals[i];
2571
+ if (visual instanceof Cesium.Entity) {
2572
+ exports.EntityRenderEngine.Remove(viewer, visual);
2573
+ }
2574
+ else if (visual instanceof Cesium.Primitive) {
2575
+ viewer.scene.primitives.remove(visual);
2576
+ }
2577
+ else if (visual instanceof Cesium.Cesium3DTileFeature) {
2578
+ visual.show = false;
2579
+ }
2580
+ }
2581
+ }
2582
+ function updateCEntityShow(viewer, visual, show) {
2583
+ if (visual._parentEntity) {
2584
+ updateCEntityShow(viewer, visual._parentEntity, show);
2585
+ }
2586
+ if (visual._siblingGraphics) {
2587
+ for (var i = 0; i < visual._siblingGraphics.length; i++) {
2588
+ var sibling = visual._siblingGraphics[i];
2589
+ updateCEntityShow(viewer, sibling, show);
2590
+ }
2591
+ }
2592
+ visual.show = show;
2593
+ }
2594
+ function updateEntityShow(viewer, visual, show) {
2595
+ if (visual instanceof Cesium.Entity) {
2596
+ updateCEntityShow(viewer, visual, show);
2597
+ }
2598
+ else if (visual instanceof Cesium.Primitive) {
2599
+ visual.show = show;
2600
+ }
2601
+ else if (visual instanceof Cesium.Cesium3DTileFeature) {
2602
+ visual.show = show;
2603
+ }
2604
+ }
2605
+ function updateEntity(viewer, entityRegos) {
2606
+ var highestPriority = null;
2607
+ for (var i = 0; i < entityRegos.length; i++) {
2608
+ var rego = entityRegos[i];
2609
+ if (highestPriority === null || rego.priority > highestPriority.priority) {
2610
+ highestPriority = rego;
2611
+ }
2612
+ }
2613
+ for (var i = 0; i < entityRegos.length; i++) {
2614
+ var rego = entityRegos[i];
2615
+ for (var j = 0; j < rego.visuals.length; j++) {
2616
+ var visual = rego.visuals[j];
2617
+ updateEntityShow(viewer, visual, rego === highestPriority);
2618
+ }
2619
+ }
2620
+ }
2621
+ function markEntity(register, rego, visuals) {
2622
+ for (var i = 0; i < visuals.length; i++) {
2623
+ var visual = visuals[i];
2624
+ var vis = visual;
2625
+ vis._register = register;
2626
+ vis._rego = rego;
2627
+ if (visual instanceof Cesium.Entity) {
2628
+ var visEnt = visual;
2629
+ if (visEnt._parentEntity) {
2630
+ markEntity(register, rego, [visEnt._parentEntity]);
2631
+ }
2632
+ if (visEnt._siblingGraphics) {
2633
+ markEntity(register, rego, visEnt._siblingGraphics);
2634
+ }
2635
+ }
2636
+ }
2637
+ }
2638
+ function unmarkEntity(visuals) {
2639
+ for (var i = 0; i < visuals.length; i++) {
2640
+ var visual = visuals[i];
2641
+ var vis = visual;
2642
+ vis._register = null;
2643
+ if (visual instanceof Cesium.Entity) {
2644
+ var visEnt = visual;
2645
+ if (visEnt._parentEntity) {
2646
+ unmarkEntity([visEnt._parentEntity]);
2647
+ }
2648
+ if (visEnt._siblingGraphics) {
2649
+ unmarkEntity(visEnt._siblingGraphics);
2650
+ }
2651
+ }
2652
+ }
2653
+ }
2654
+ var VisualsRegister = /** @class */ (function () {
2655
+ function VisualsRegister(viewer) {
2656
+ this.id = bruceModels.ObjectUtils.UId();
2657
+ this.rego = {};
2658
+ this.viewer = viewer;
2659
+ }
2660
+ Object.defineProperty(VisualsRegister.prototype, "Id", {
2661
+ get: function () {
2662
+ return this.id;
2663
+ },
2664
+ enumerable: false,
2665
+ configurable: true
2666
+ });
2667
+ VisualsRegister.prototype.Add = function (rego) {
2668
+ var _a;
2669
+ this.Remove(rego.entityId, rego.menuItemId, false);
2670
+ var entityId = rego.entityId;
2671
+ var entityRegos = (_a = this.rego[entityId]) !== null && _a !== void 0 ? _a : [];
2672
+ entityRegos.push(rego);
2673
+ this.rego[entityId] = entityRegos;
2674
+ markEntity(this, rego, rego.visuals);
2675
+ updateEntity(this.viewer, this.rego[entityId]);
2676
+ };
2677
+ VisualsRegister.prototype.GetVisuals = function (entityId, menuItemId) {
2678
+ var _a;
2679
+ var entityRegos = this.rego[entityId];
2680
+ if (!entityRegos) {
2681
+ return [];
2682
+ }
2683
+ var visuals = (_a = entityRegos.find(function (r) { return r.menuItemId === menuItemId; })) === null || _a === void 0 ? void 0 : _a.visuals;
2684
+ return visuals !== null && visuals !== void 0 ? visuals : [];
2685
+ };
2686
+ VisualsRegister.prototype.RemoveByEntityId = function (id) {
2687
+ var entityRegos = this.rego[id];
2688
+ if (!entityRegos) {
2689
+ return;
2690
+ }
2691
+ for (var i = 0; i < entityRegos.length; i++) {
2692
+ var rego = entityRegos[i];
2693
+ removeEntity(this.viewer, rego.visuals);
2694
+ }
2695
+ this.rego[id] = [];
2696
+ delete this.rego[id];
2697
+ };
2698
+ VisualsRegister.prototype.RemoveByMenuItemId = function (id) {
2699
+ for (var entityId in this.rego) {
2700
+ var entityRegos = this.rego[entityId];
2701
+ if (entityRegos) {
2702
+ var rego = entityRegos.find(function (r) { return r.menuItemId === id; });
2703
+ if (!rego) {
2704
+ continue;
2705
+ }
2706
+ removeEntity(this.viewer, rego.visuals);
2707
+ var doesInclude = this.rego[entityId].find(function (r) { return r.menuItemId === id; });
2708
+ if (doesInclude) {
2709
+ this.rego[entityId] = entityRegos.filter(function (r) { return r.menuItemId !== id; });
2710
+ updateEntity(this.viewer, this.rego[entityId]);
2711
+ }
2712
+ }
2713
+ }
2714
+ };
2715
+ VisualsRegister.prototype.Remove = function (entityId, menuItemId, _doUpdate) {
2716
+ if (_doUpdate === void 0) { _doUpdate = true; }
2717
+ var entityRegos = this.rego[entityId];
2718
+ if (!entityRegos) {
2719
+ return;
2720
+ }
2721
+ var rego = entityRegos.find(function (r) { return r.menuItemId === menuItemId; });
2722
+ if (!rego) {
2723
+ return;
2724
+ }
2725
+ for (var i = 0; i < rego.visuals.length; i++) {
2726
+ var visual = rego.visuals[i];
2727
+ if (visual instanceof Cesium.Entity) {
2728
+ this.viewer.entities.remove(visual);
2729
+ }
2730
+ else if (visual instanceof Cesium.Primitive) {
2731
+ this.viewer.scene.primitives.remove(visual);
2732
+ }
2733
+ else if (visual instanceof Cesium.Cesium3DTileFeature) {
2734
+ visual.show = false;
2735
+ }
2736
+ }
2737
+ this.rego[entityId] = entityRegos.filter(function (r) { return r.menuItemId !== menuItemId; });
2738
+ if (_doUpdate) {
2739
+ updateEntity(this.viewer, this.rego[entityId]);
2740
+ }
2741
+ };
2742
+ VisualsRegister.prototype.GetFromCursor = function (cursor) {
2743
+ var _a;
2744
+ var found = [];
2745
+ var picked = this.viewer.scene.drillPick(new Cesium.Cartesian2(cursor.x, cursor.y), 5);
2746
+ for (var i = 0; i < picked.length; i++) {
2747
+ var object = picked[i];
2748
+ var entity = (object && object.id && object.id instanceof Cesium.Entity ? object.id : object);
2749
+ var visual = entity;
2750
+ if (((_a = visual === null || visual === void 0 ? void 0 : visual._register) === null || _a === void 0 ? void 0 : _a.Id) == this.id) {
2751
+ found.push(visual._rego);
2752
+ }
2753
+ }
2754
+ return found;
2755
+ };
2756
+ return VisualsRegister;
2757
+ }());
2758
+
2759
+ exports.CesiumViewMonitor = CesiumViewMonitor;
2760
+ exports.MenuItemManager = MenuItemManager;
2761
+ exports.VisualsRegister = VisualsRegister;
2762
+
2763
+ Object.defineProperty(exports, '__esModule', { value: true });
2764
+
2765
+ })));
2766
+ //# sourceMappingURL=bruce-cesium.umd.js.map