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