bruce-cesium 2.9.4 → 2.9.6

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.
@@ -727,6 +727,212 @@
727
727
  DrawingUtils.RaisePos3d = RaisePos3d;
728
728
  })(exports.DrawingUtils || (exports.DrawingUtils = {}));
729
729
 
730
+ var CESIUM_INSPECTOR_KEY = "_nextspace_inspector";
731
+ (function (ViewUtils) {
732
+ function GatherLegacyMapTiles(params) {
733
+ var viewer = params.viewer;
734
+ var collection = viewer.imageryLayers;
735
+ var tiles = [];
736
+ for (var i = 0; i < collection.length; i++) {
737
+ var layer = collection.get(i);
738
+ if (layer._bName) {
739
+ tiles.push({
740
+ alpha: layer.alpha,
741
+ brightness: layer.brightness,
742
+ contrast: layer.contrast,
743
+ hue: layer.hue,
744
+ saturation: layer.saturation,
745
+ gamma: layer.gamma,
746
+ title: layer._bName,
747
+ });
748
+ }
749
+ }
750
+ return {
751
+ imagery: tiles.reverse()
752
+ };
753
+ }
754
+ ViewUtils.GatherLegacyMapTiles = GatherLegacyMapTiles;
755
+ function GatherLegacyTerrainTile(params) {
756
+ var viewer = params.viewer;
757
+ var enabled = viewer.terrainProvider;
758
+ if (enabled === null || enabled === void 0 ? void 0 : enabled._bName) {
759
+ return {
760
+ terrain: enabled._bName
761
+ };
762
+ }
763
+ return {
764
+ terrain: "flatterrain"
765
+ };
766
+ }
767
+ ViewUtils.GatherLegacyTerrainTile = GatherLegacyTerrainTile;
768
+ function GatherMapTiles(params) {
769
+ var viewer = params.viewer;
770
+ var imagery = viewer.imageryLayers;
771
+ var tiles = [];
772
+ var _loop_1 = function (i) {
773
+ var provider = imagery.get(i);
774
+ if (provider._bMeta) {
775
+ var idCombo_1 = provider._bMeta.accountId + provider._bMeta.tilesetId;
776
+ if (!tiles.find(function (x) { return x.accountId + x.tilesetId === idCombo_1; })) {
777
+ tiles.push({
778
+ accountId: provider._bMeta.accountId,
779
+ tilesetId: provider._bMeta.tilesetId,
780
+ alpha: provider.alpha,
781
+ brightness: provider.brightness,
782
+ contrast: provider.contrast,
783
+ hue: provider.hue,
784
+ saturation: provider.saturation,
785
+ gamma: provider.gamma
786
+ });
787
+ }
788
+ }
789
+ };
790
+ for (var i = 0; i < imagery.length; i++) {
791
+ _loop_1(i);
792
+ }
793
+ return {
794
+ imagery: tiles
795
+ };
796
+ }
797
+ ViewUtils.GatherMapTiles = GatherMapTiles;
798
+ function GatherTerrainTile(params) {
799
+ var viewer = params.viewer;
800
+ var provider = viewer.terrainProvider;
801
+ if (provider._bMeta) {
802
+ return {
803
+ terrain: {
804
+ accountId: provider._bMeta.accountId,
805
+ tilesetId: provider._bMeta.tilesetId,
806
+ }
807
+ };
808
+ }
809
+ else if (provider instanceof Cesium.EllipsoidTerrainProvider) {
810
+ return {
811
+ terrain: {
812
+ tilesetId: bruceModels.ProjectViewTile.EDefaultTerrain.FlatTerrain,
813
+ accountId: null
814
+ }
815
+ };
816
+ }
817
+ return null;
818
+ }
819
+ ViewUtils.GatherTerrainTile = GatherTerrainTile;
820
+ function SetTerrainWireframeStatus(params) {
821
+ if (!params.viewer[CESIUM_INSPECTOR_KEY]) {
822
+ var InspectorClass = Cesium.CesiumInspector;
823
+ if (InspectorClass) {
824
+ var inspector = new InspectorClass(document.createElement("div"), params.viewer.scene);
825
+ inspector.container.style.display = "none";
826
+ params.viewer[CESIUM_INSPECTOR_KEY] = inspector;
827
+ params.viewer.scene.requestRender();
828
+ }
829
+ }
830
+ if (params.viewer[CESIUM_INSPECTOR_KEY]) {
831
+ params.viewer[CESIUM_INSPECTOR_KEY].viewModel.wireframe = params.status;
832
+ }
833
+ }
834
+ ViewUtils.SetTerrainWireframeStatus = SetTerrainWireframeStatus;
835
+ function GetTerrainWireframeStatus(params) {
836
+ var _a, _b;
837
+ if (!params.viewer[CESIUM_INSPECTOR_KEY]) {
838
+ return false;
839
+ }
840
+ return (_b = (_a = params.viewer[CESIUM_INSPECTOR_KEY]) === null || _a === void 0 ? void 0 : _a.viewModel) === null || _b === void 0 ? void 0 : _b.wireframe;
841
+ }
842
+ ViewUtils.GetTerrainWireframeStatus = GetTerrainWireframeStatus;
843
+ /**
844
+ * Changes between perspective and orthographic view.
845
+ * When Cesium stops being bad at picking positions in 2d mode we'll use the flat earth mode instead.
846
+ * @param params
847
+ */
848
+ function Set2dStatus(params) {
849
+ var viewer = params.viewer, is2d = params.status, moveCamera = params.moveCamera;
850
+ var curLens2d = viewer.camera.frustum instanceof Cesium.OrthographicFrustum;
851
+ if (curLens2d && !is2d) {
852
+ viewer.camera.switchToPerspectiveFrustum();
853
+ viewer.scene.screenSpaceCameraController.enableTilt = true;
854
+ viewer.scene.requestRender();
855
+ }
856
+ else if (!curLens2d && is2d) {
857
+ viewer.camera.switchToOrthographicFrustum();
858
+ viewer.scene.screenSpaceCameraController.enableTilt = false;
859
+ if (moveCamera != false) {
860
+ try {
861
+ // Face camera downwards to make it look 2d.
862
+ // We want to try make it look at the center-point of the current view.
863
+ // If center cannot be calculated then we'll simply raise the camera and face it downwards.
864
+ var scene = viewer.scene;
865
+ var windowPosition = new Cesium.Cartesian2(scene.canvas.clientWidth / 2, scene.canvas.clientHeight / 2);
866
+ var ray = viewer.camera.getPickRay(windowPosition);
867
+ var intersection = scene.globe.pick(ray, scene);
868
+ var center = void 0;
869
+ if (Cesium.defined(intersection)) {
870
+ center = Cesium.Cartographic.fromCartesian(intersection);
871
+ }
872
+ // Use current camera position if we can't calculate the center.
873
+ else {
874
+ center = Cesium.Cartographic.fromCartesian(viewer.camera.position);
875
+ center.height = 0;
876
+ }
877
+ center.height = viewer.camera.positionCartographic.height + 100;
878
+ viewer.camera.setView({
879
+ destination: Cesium.Cartographic.toCartesian(center),
880
+ orientation: {
881
+ heading: 0.0,
882
+ pitch: Cesium.Math.toRadians(-90.0),
883
+ roll: 0.0
884
+ }
885
+ });
886
+ }
887
+ catch (e) {
888
+ console.error(e);
889
+ }
890
+ }
891
+ viewer.scene.requestRender();
892
+ }
893
+ }
894
+ ViewUtils.Set2dStatus = Set2dStatus;
895
+ function Get2dStatus(params) {
896
+ var viewer = params.viewer;
897
+ return viewer.camera.frustum instanceof Cesium.OrthographicFrustum;
898
+ }
899
+ ViewUtils.Get2dStatus = Get2dStatus;
900
+ function SetLockedCameraStatus(params) {
901
+ var viewer = params.viewer, status = params.status;
902
+ var scene = viewer === null || viewer === void 0 ? void 0 : viewer.scene;
903
+ if (!scene) {
904
+ return;
905
+ }
906
+ if (status) {
907
+ scene.screenSpaceCameraController.enableInputs = false;
908
+ scene.screenSpaceCameraController.enableTranslate = false;
909
+ scene.screenSpaceCameraController.enableZoom = false;
910
+ scene.screenSpaceCameraController.enableRotate = false;
911
+ scene.screenSpaceCameraController.enableTilt = false;
912
+ }
913
+ else {
914
+ scene.screenSpaceCameraController.enableInputs = true;
915
+ scene.screenSpaceCameraController.enableTranslate = true;
916
+ scene.screenSpaceCameraController.enableZoom = true;
917
+ scene.screenSpaceCameraController.enableRotate = true;
918
+ if (!ViewUtils.Get2dStatus({ viewer: viewer })) {
919
+ scene.screenSpaceCameraController.enableTilt = true;
920
+ }
921
+ }
922
+ viewer.scene.requestRender();
923
+ }
924
+ ViewUtils.SetLockedCameraStatus = SetLockedCameraStatus;
925
+ function GetLockedCameraStatus(params) {
926
+ var _a;
927
+ var scene = (_a = params.viewer) === null || _a === void 0 ? void 0 : _a.scene;
928
+ if (!scene) {
929
+ return false;
930
+ }
931
+ return !scene.screenSpaceCameraController.enableTranslate;
932
+ }
933
+ ViewUtils.GetLockedCameraStatus = GetLockedCameraStatus;
934
+ })(exports.ViewUtils || (exports.ViewUtils = {}));
935
+
730
936
  /**
731
937
  * Returns if a given visual is alive and in the scene.
732
938
  * @param viewer
@@ -890,10 +1096,522 @@
890
1096
  return obj;
891
1097
  }
892
1098
  (function (EntityUtils) {
1099
+ /**
1100
+ * Returns the location for given entity or entities.
1101
+ * If available it will also compute a rectangle.
1102
+ * It is recommended to fly-to a rectangle if available as it will ensure the full geometry is in view.
1103
+ * @param params
1104
+ */
1105
+ function GetLocation(params) {
1106
+ var _a;
1107
+ return __awaiter(this, void 0, void 0, function () {
1108
+ var api, viewer, samples, visualRegister, minimumAlt, paddingAlt, MAX_DISTANCE_BETWEEN_SAMPLES, MAX_TERRAIN_SAMPLES, terrainSamples, MAX_API_CALLS, apiCalls, MAX_VALID_SAMPLES, validSamples, MIN_RECT_DIAGONAL_LENGTH, data, processPosHeight, ensureHeightRefs, getEntityPositions, allPosses, i, sample, samplePosses, valid, j, samplePos, k, allPos, distance, rect, factor, marginX, marginY, diagonalLen, terrData, posCarto, height, MIN_POSSES_LEN;
1109
+ var _this = this;
1110
+ return __generator(this, function (_b) {
1111
+ switch (_b.label) {
1112
+ case 0:
1113
+ api = params.api, viewer = params.viewer, samples = params.samples, visualRegister = params.visualRegister, minimumAlt = params.minimumAlt, paddingAlt = params.paddingAlt;
1114
+ if (!paddingAlt) {
1115
+ paddingAlt = 0;
1116
+ }
1117
+ MAX_DISTANCE_BETWEEN_SAMPLES = 5000;
1118
+ MAX_TERRAIN_SAMPLES = 25;
1119
+ terrainSamples = 0;
1120
+ MAX_API_CALLS = 10;
1121
+ apiCalls = 0;
1122
+ MAX_VALID_SAMPLES = 20;
1123
+ validSamples = 0;
1124
+ MIN_RECT_DIAGONAL_LENGTH = isNaN(minimumAlt) || minimumAlt == null ? 0 : minimumAlt * 10;
1125
+ if (MIN_RECT_DIAGONAL_LENGTH < 1500) {
1126
+ MIN_RECT_DIAGONAL_LENGTH = 1500;
1127
+ }
1128
+ data = {
1129
+ pos3d: null,
1130
+ rectangle: null
1131
+ };
1132
+ processPosHeight = function (pos3d, heightRef) { return __awaiter(_this, void 0, void 0, function () {
1133
+ var carto, baseHeight, terrData, height, carto;
1134
+ return __generator(this, function (_a) {
1135
+ switch (_a.label) {
1136
+ case 0:
1137
+ if (!(!isNaN(minimumAlt) && minimumAlt != null)) return [3 /*break*/, 5];
1138
+ carto = Cesium.Cartographic.fromCartesian(pos3d);
1139
+ if (!(carto === null || carto === void 0 ? void 0 : carto.latitude)) return [3 /*break*/, 4];
1140
+ baseHeight = 0;
1141
+ if (!(heightRef == null || heightRef == Cesium.HeightReference.RELATIVE_TO_GROUND || heightRef == Cesium.HeightReference.NONE)) return [3 /*break*/, 3];
1142
+ if (!(terrainSamples > MAX_TERRAIN_SAMPLES)) return [3 /*break*/, 1];
1143
+ baseHeight = viewer.scene.globe.getHeight(carto);
1144
+ return [3 /*break*/, 3];
1145
+ case 1: return [4 /*yield*/, exports.DrawingUtils.GetTerrainHeight({
1146
+ pos3d: pos3d,
1147
+ viewer: viewer
1148
+ })];
1149
+ case 2:
1150
+ terrData = _a.sent();
1151
+ baseHeight = terrData === null || terrData === void 0 ? void 0 : terrData.height;
1152
+ terrainSamples += 1;
1153
+ _a.label = 3;
1154
+ case 3:
1155
+ if (baseHeight != undefined && !isNaN(baseHeight)) {
1156
+ height = baseHeight + minimumAlt;
1157
+ if (height > carto.height) {
1158
+ carto.height = height;
1159
+ }
1160
+ return [2 /*return*/, Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height + paddingAlt)];
1161
+ }
1162
+ _a.label = 4;
1163
+ case 4: return [3 /*break*/, 6];
1164
+ case 5:
1165
+ if (paddingAlt) {
1166
+ carto = Cesium.Cartographic.fromCartesian(pos3d);
1167
+ if (carto === null || carto === void 0 ? void 0 : carto.latitude) {
1168
+ return [2 /*return*/, Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height + paddingAlt)];
1169
+ }
1170
+ }
1171
+ _a.label = 6;
1172
+ case 6: return [2 /*return*/, pos3d];
1173
+ }
1174
+ });
1175
+ }); };
1176
+ ensureHeightRefs = function (posses, sample) { return __awaiter(_this, void 0, void 0, function () {
1177
+ var heightRef, returnHeightRef, i, _a, _b;
1178
+ return __generator(this, function (_c) {
1179
+ switch (_c.label) {
1180
+ case 0:
1181
+ if (!(posses === null || posses === void 0 ? void 0 : posses.length)) return [3 /*break*/, 4];
1182
+ heightRef = sample.heightRef;
1183
+ returnHeightRef = sample.returnHeightRef;
1184
+ i = 0;
1185
+ _c.label = 1;
1186
+ case 1:
1187
+ if (!(i < posses.length)) return [3 /*break*/, 4];
1188
+ if (heightRef != null && returnHeightRef != null && heightRef != returnHeightRef) {
1189
+ posses[i] = exports.DrawingUtils.EnsurePosHeight({
1190
+ desiredHeightRef: returnHeightRef,
1191
+ heightRef: heightRef,
1192
+ pos3d: posses[i],
1193
+ viewer: viewer
1194
+ });
1195
+ }
1196
+ _a = posses;
1197
+ _b = i;
1198
+ return [4 /*yield*/, processPosHeight(posses[i], returnHeightRef)];
1199
+ case 2:
1200
+ _a[_b] = _c.sent();
1201
+ _c.label = 3;
1202
+ case 3:
1203
+ i++;
1204
+ return [3 /*break*/, 1];
1205
+ case 4: return [2 /*return*/];
1206
+ }
1207
+ });
1208
+ }); };
1209
+ getEntityPositions = function (sample) { return __awaiter(_this, void 0, void 0, function () {
1210
+ var entityId, entity, tileset, tilesetId, lat, lon, e_1, e_2, evaluateRendered, evaluateRecord, renderedPosses, recordPosses, tSettings, pos3d, alt, alt, heading, pitch, roll, matrix4, offset, m1, hpr, transform, transformedOffset;
1211
+ var _this = this;
1212
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1213
+ return __generator(this, function (_o) {
1214
+ switch (_o.label) {
1215
+ case 0:
1216
+ entityId = sample.entityId, entity = sample.entity, tileset = sample.tileset, tilesetId = sample.tilesetId;
1217
+ if (!!entity) return [3 /*break*/, 9];
1218
+ lat = 0;
1219
+ lon = 0;
1220
+ if (!(apiCalls < MAX_API_CALLS)) return [3 /*break*/, 9];
1221
+ // Counting this whole area as a single call because it has a single purpose.
1222
+ apiCalls += 1;
1223
+ _o.label = 1;
1224
+ case 1:
1225
+ _o.trys.push([1, 3, , 4]);
1226
+ return [4 /*yield*/, bruceModels.Entity.Get({
1227
+ api: api,
1228
+ entityId: entityId,
1229
+ expandLocation: false
1230
+ })];
1231
+ case 2:
1232
+ entity = (_o.sent()).entity;
1233
+ lat = +((_a = entity === null || entity === void 0 ? void 0 : entity.location) === null || _a === void 0 ? void 0 : _a.latitude);
1234
+ lon = +((_b = entity === null || entity === void 0 ? void 0 : entity.location) === null || _b === void 0 ? void 0 : _b.longitude);
1235
+ return [3 /*break*/, 4];
1236
+ case 3:
1237
+ e_1 = _o.sent();
1238
+ console.error(e_1);
1239
+ return [3 /*break*/, 4];
1240
+ case 4:
1241
+ if (!(entity && (isNaN(lat) || isNaN(lon) || (lat == 0 && lon == 0)))) return [3 /*break*/, 9];
1242
+ _o.label = 5;
1243
+ case 5:
1244
+ _o.trys.push([5, 7, , 9]);
1245
+ return [4 /*yield*/, bruceModels.Entity.Get({
1246
+ api: api,
1247
+ entityId: entityId,
1248
+ expandLocation: true
1249
+ })];
1250
+ case 6:
1251
+ entity = (_o.sent()).entity;
1252
+ return [3 /*break*/, 9];
1253
+ case 7:
1254
+ e_2 = _o.sent();
1255
+ console.warn(e_2);
1256
+ return [4 /*yield*/, bruceModels.Entity.Get({
1257
+ api: api,
1258
+ entityId: entityId,
1259
+ expandLocation: false
1260
+ })];
1261
+ case 8:
1262
+ entity = (_o.sent()).entity;
1263
+ return [3 /*break*/, 9];
1264
+ case 9:
1265
+ if (!entity) {
1266
+ return [2 /*return*/, []];
1267
+ }
1268
+ if (!tilesetId) {
1269
+ tilesetId = ((_c = entity.tilesetID) === null || _c === void 0 ? void 0 : _c.length) ? entity.tilesetID[0] : tilesetId;
1270
+ }
1271
+ evaluateRendered = function () { return __awaiter(_this, void 0, void 0, function () {
1272
+ var rego, posses, visual, visualHeightRef, hierarchy, hPosses, hPossesSample, step, i, pPosses, pPossesSample, step, i, pPosses, pPossesSample, step, i, pos3d_1;
1273
+ return __generator(this, function (_a) {
1274
+ switch (_a.label) {
1275
+ case 0:
1276
+ rego = visualRegister ? visualRegister.GetRego({
1277
+ entityId: entity.Bruce.ID,
1278
+ }) : null;
1279
+ posses = [];
1280
+ if (!((rego === null || rego === void 0 ? void 0 : rego.visual) instanceof Cesium.Entity)) return [3 /*break*/, 14];
1281
+ visual = rego.visual;
1282
+ visualHeightRef = Cesium.HeightReference.RELATIVE_TO_GROUND;
1283
+ if (!visual.model) return [3 /*break*/, 1];
1284
+ visualHeightRef = GetValue(viewer, visual.model.heightReference);
1285
+ return [3 /*break*/, 12];
1286
+ case 1:
1287
+ if (!visual.polygon) return [3 /*break*/, 4];
1288
+ visualHeightRef = GetValue(viewer, visual.polygon.heightReference);
1289
+ hierarchy = GetValue(viewer, visual.polygon.hierarchy);
1290
+ if (!(hierarchy === null || hierarchy === void 0 ? void 0 : hierarchy.positions)) return [3 /*break*/, 3];
1291
+ hPosses = hierarchy.positions.map(function (x) { return x.clone ? x.clone() : x; });
1292
+ hPossesSample = [];
1293
+ step = Math.floor(hPosses.length / 5);
1294
+ for (i = 0; i < hPosses.length; i += step) {
1295
+ hPossesSample.push(hPosses[i]);
1296
+ }
1297
+ return [4 /*yield*/, ensureHeightRefs(hPossesSample, __assign(__assign({}, sample), { heightRef: visualHeightRef }))];
1298
+ case 2:
1299
+ _a.sent();
1300
+ posses = posses.concat(hPossesSample);
1301
+ _a.label = 3;
1302
+ case 3: return [3 /*break*/, 12];
1303
+ case 4:
1304
+ if (!visual.polyline) return [3 /*break*/, 7];
1305
+ visualHeightRef = GetValue(viewer, visual.polyline.clampToGround) ?
1306
+ Cesium.HeightReference.CLAMP_TO_GROUND : Cesium.HeightReference.NONE;
1307
+ pPosses = GetValue(viewer, visual.polyline.positions);
1308
+ if (!(pPosses === null || pPosses === void 0 ? void 0 : pPosses.length)) return [3 /*break*/, 6];
1309
+ // Grab 5 positions from the polyline at varied indexes.
1310
+ pPosses = pPosses.map(function (x) { return x.clone ? x.clone() : x; });
1311
+ pPossesSample = [];
1312
+ step = Math.floor(pPosses.length / 5);
1313
+ for (i = 0; i < pPosses.length; i += step) {
1314
+ pPossesSample.push(pPosses[i]);
1315
+ }
1316
+ return [4 /*yield*/, ensureHeightRefs(pPossesSample, __assign(__assign({}, sample), { heightRef: visualHeightRef }))];
1317
+ case 5:
1318
+ _a.sent();
1319
+ posses = posses.concat(pPossesSample);
1320
+ _a.label = 6;
1321
+ case 6: return [3 /*break*/, 12];
1322
+ case 7:
1323
+ if (!visual.billboard) return [3 /*break*/, 8];
1324
+ visualHeightRef = GetValue(viewer, visual.billboard.heightReference);
1325
+ return [3 /*break*/, 12];
1326
+ case 8:
1327
+ if (!visual.corridor) return [3 /*break*/, 11];
1328
+ visualHeightRef = GetValue(viewer, visual.corridor.heightReference);
1329
+ pPosses = GetValue(viewer, visual.corridor.positions);
1330
+ if (!(pPosses === null || pPosses === void 0 ? void 0 : pPosses.length)) return [3 /*break*/, 10];
1331
+ // Grab 5 positions from the corridor at varied indexes.
1332
+ pPosses = pPosses.map(function (x) { return x.clone ? x.clone() : x; });
1333
+ pPossesSample = [];
1334
+ step = Math.floor(pPosses.length / 5);
1335
+ for (i = 0; i < pPosses.length; i += step) {
1336
+ pPossesSample.push(pPosses[i]);
1337
+ }
1338
+ return [4 /*yield*/, ensureHeightRefs(pPossesSample, __assign(__assign({}, sample), { heightRef: visualHeightRef }))];
1339
+ case 9:
1340
+ _a.sent();
1341
+ posses = posses.concat(pPossesSample);
1342
+ _a.label = 10;
1343
+ case 10: return [3 /*break*/, 12];
1344
+ case 11:
1345
+ if (visual.ellipse) {
1346
+ visualHeightRef = GetValue(viewer, visual.ellipse.heightReference);
1347
+ }
1348
+ else if (visual.point) {
1349
+ visualHeightRef = GetValue(viewer, visual.point.heightReference);
1350
+ }
1351
+ _a.label = 12;
1352
+ case 12:
1353
+ pos3d_1 = GetValue(viewer, visual.position);
1354
+ if (!(pos3d_1 === null || pos3d_1 === void 0 ? void 0 : pos3d_1.x)) return [3 /*break*/, 14];
1355
+ pos3d_1 = exports.DrawingUtils.EnsurePosHeight({
1356
+ desiredHeightRef: sample.returnHeightRef,
1357
+ heightRef: visualHeightRef,
1358
+ pos3d: pos3d_1,
1359
+ viewer: viewer
1360
+ });
1361
+ return [4 /*yield*/, processPosHeight(pos3d_1, sample.returnHeightRef)];
1362
+ case 13:
1363
+ pos3d_1 = _a.sent();
1364
+ posses.push(pos3d_1);
1365
+ _a.label = 14;
1366
+ case 14: return [2 /*return*/, posses];
1367
+ }
1368
+ });
1369
+ }); };
1370
+ evaluateRecord = function () { return __awaiter(_this, void 0, void 0, function () {
1371
+ var posses, location_1, latitude, longitude, pos3d_2, pointStr, points, point, pos3d_3, lineStr, points, pPosses, pRings, boundary, points, pPosses, point, bPosses;
1372
+ return __generator(this, function (_a) {
1373
+ switch (_a.label) {
1374
+ case 0:
1375
+ posses = [];
1376
+ if (entity.location && bruceModels.Carto.ValidateCarto(entity.location)) {
1377
+ location_1 = entity.location;
1378
+ latitude = EnsureNumber(location_1.latitude);
1379
+ longitude = EnsureNumber(location_1.longitude);
1380
+ // Disallowing exact 0.
1381
+ if (latitude || longitude) {
1382
+ pos3d_2 = Cesium.Cartesian3.fromDegrees(longitude, latitude, EnsureNumber(location_1.altitude));
1383
+ posses.push(pos3d_2);
1384
+ }
1385
+ }
1386
+ if (!(entity.geometry && typeof entity.geometry == "object")) return [3 /*break*/, 4];
1387
+ pointStr = entity.geometry.Point;
1388
+ if (pointStr && typeof pointStr == "string") {
1389
+ points = bruceModels.Geometry.ParsePoints(pointStr);
1390
+ point = points.length > 0 ? points[0] : null;
1391
+ if (point && bruceModels.Carto.ValidateCarto(point)) {
1392
+ pos3d_3 = Cesium.Cartesian3.fromDegrees(EnsureNumber(point.longitude), EnsureNumber(point.latitude), EnsureNumber(point.altitude));
1393
+ posses.push(pos3d_3);
1394
+ }
1395
+ }
1396
+ lineStr = entity.geometry.LineString;
1397
+ if (!(lineStr && typeof lineStr == "string")) return [3 /*break*/, 2];
1398
+ points = bruceModels.Geometry.ParsePoints(lineStr);
1399
+ if (!(points.length > 0)) return [3 /*break*/, 2];
1400
+ pPosses = points.map(function (x) { return Cesium.Cartesian3.fromDegrees(EnsureNumber(x.longitude), EnsureNumber(x.latitude), EnsureNumber(x.altitude)); });
1401
+ return [4 /*yield*/, ensureHeightRefs(pPosses, sample)];
1402
+ case 1:
1403
+ _a.sent();
1404
+ posses = posses.concat(pPosses);
1405
+ _a.label = 2;
1406
+ case 2:
1407
+ pRings = entity.geometry.Polygon;
1408
+ if (!(pRings && typeof pRings == "object")) return [3 /*break*/, 4];
1409
+ boundary = pRings.find(function (x) { return x.Facing == bruceModels.Geometry.EPolygonRingType.Boundaries; });
1410
+ if (!(boundary === null || boundary === void 0 ? void 0 : boundary.LinearRing)) return [3 /*break*/, 4];
1411
+ points = bruceModels.Geometry.ParsePoints(boundary.LinearRing);
1412
+ pPosses = points.map(function (x) { return Cesium.Cartesian3.fromDegrees(EnsureNumber(x.longitude), EnsureNumber(x.latitude), EnsureNumber(x.altitude)); });
1413
+ return [4 /*yield*/, ensureHeightRefs(pPosses, sample)];
1414
+ case 3:
1415
+ _a.sent();
1416
+ posses = posses.concat(pPosses);
1417
+ _a.label = 4;
1418
+ case 4:
1419
+ if (!entity.boundaries) return [3 /*break*/, 6];
1420
+ point = {
1421
+ latitude: (EnsureNumber(entity.boundaries.minLatitude) + EnsureNumber(entity.boundaries.maxLatitude)) / 2,
1422
+ longitude: (EnsureNumber(entity.boundaries.minLongitude) + EnsureNumber(entity.boundaries.maxLongitude)) / 2,
1423
+ altitude: 0
1424
+ };
1425
+ if (!(point.latitude || point.longitude)) return [3 /*break*/, 6];
1426
+ bPosses = [
1427
+ Cesium.Cartesian3.fromDegrees(EnsureNumber(entity.boundaries.minLongitude), EnsureNumber(entity.boundaries.minLatitude), EnsureNumber(entity.boundaries.minAltitude)),
1428
+ Cesium.Cartesian3.fromDegrees(EnsureNumber(entity.boundaries.maxLongitude), EnsureNumber(entity.boundaries.maxLatitude), EnsureNumber(entity.boundaries.maxAltitude))
1429
+ ];
1430
+ return [4 /*yield*/, ensureHeightRefs(bPosses, sample)];
1431
+ case 5:
1432
+ _a.sent();
1433
+ posses = posses.concat(bPosses);
1434
+ _a.label = 6;
1435
+ case 6: return [2 /*return*/, posses];
1436
+ }
1437
+ });
1438
+ }); };
1439
+ return [4 /*yield*/, evaluateRendered()];
1440
+ case 10:
1441
+ renderedPosses = _o.sent();
1442
+ if (renderedPosses === null || renderedPosses === void 0 ? void 0 : renderedPosses.length) {
1443
+ return [2 /*return*/, renderedPosses];
1444
+ }
1445
+ return [4 /*yield*/, evaluateRecord()];
1446
+ case 11:
1447
+ recordPosses = _o.sent();
1448
+ if (recordPosses === null || recordPosses === void 0 ? void 0 : recordPosses.length) {
1449
+ return [2 /*return*/, recordPosses];
1450
+ }
1451
+ if (!!tileset) return [3 /*break*/, 13];
1452
+ if (!(tilesetId && apiCalls < MAX_API_CALLS)) return [3 /*break*/, 13];
1453
+ apiCalls += 1;
1454
+ return [4 /*yield*/, bruceModels.Tileset.Get({
1455
+ api: api,
1456
+ tilesetId: tilesetId
1457
+ })];
1458
+ case 12:
1459
+ tileset = (_o.sent()).tileset;
1460
+ _o.label = 13;
1461
+ case 13:
1462
+ tSettings = tileset === null || tileset === void 0 ? void 0 : tileset.settings;
1463
+ pos3d = null;
1464
+ if (!(((_d = entity.location) === null || _d === void 0 ? void 0 : _d.longitude) || ((_e = tSettings === null || tSettings === void 0 ? void 0 : tSettings.location) === null || _e === void 0 ? void 0 : _e.longitude))) return [3 /*break*/, 15];
1465
+ if ((_f = entity === null || entity === void 0 ? void 0 : entity.location) === null || _f === void 0 ? void 0 : _f.longitude) {
1466
+ alt = +entity.location.altitude;
1467
+ if (isNaN(alt)) {
1468
+ alt = 0;
1469
+ }
1470
+ pos3d = Cesium.Cartesian3.fromDegrees(+entity.location.longitude, +entity.location.latitude, alt);
1471
+ }
1472
+ else {
1473
+ alt = +tSettings.location.altitude;
1474
+ if (isNaN(alt)) {
1475
+ alt = 0;
1476
+ }
1477
+ pos3d = Cesium.Cartesian3.fromDegrees(+tSettings.location.longitude, +tSettings.location.latitude, alt);
1478
+ }
1479
+ if (!(entity === null || entity === void 0 ? void 0 : entity.worldPosition)) return [3 /*break*/, 15];
1480
+ heading = 0;
1481
+ pitch = 0;
1482
+ roll = 0;
1483
+ if ((_g = entity === null || entity === void 0 ? void 0 : entity.transform) === null || _g === void 0 ? void 0 : _g.heading) {
1484
+ heading = entity.transform.heading;
1485
+ }
1486
+ else if ((_h = tSettings === null || tSettings === void 0 ? void 0 : tSettings.transform) === null || _h === void 0 ? void 0 : _h.heading) {
1487
+ heading = tSettings.transform.heading;
1488
+ }
1489
+ if ((_j = entity === null || entity === void 0 ? void 0 : entity.transform) === null || _j === void 0 ? void 0 : _j.pitch) {
1490
+ pitch = entity.transform.pitch;
1491
+ }
1492
+ else if ((_k = tSettings === null || tSettings === void 0 ? void 0 : tSettings.transform) === null || _k === void 0 ? void 0 : _k.pitch) {
1493
+ pitch = tSettings.transform.pitch;
1494
+ }
1495
+ if ((_l = entity === null || entity === void 0 ? void 0 : entity.transform) === null || _l === void 0 ? void 0 : _l.roll) {
1496
+ roll = entity.transform.roll;
1497
+ }
1498
+ else if ((_m = tSettings === null || tSettings === void 0 ? void 0 : tSettings.transform) === null || _m === void 0 ? void 0 : _m.roll) {
1499
+ roll = tSettings.transform.roll;
1500
+ }
1501
+ heading = +heading;
1502
+ if (isNaN(heading)) {
1503
+ heading = 0;
1504
+ }
1505
+ pitch = +pitch;
1506
+ if (isNaN(pitch)) {
1507
+ pitch = 0;
1508
+ }
1509
+ roll = +roll;
1510
+ if (isNaN(roll)) {
1511
+ roll = 0;
1512
+ }
1513
+ matrix4 = entity.worldPosition;
1514
+ offset = new Cesium.Cartesian3(+matrix4[0][3], +matrix4[1][3], +matrix4[2][3]);
1515
+ if (entity.worldPivot) //the position from worldMatrix + center of geometry offset
1516
+ {
1517
+ offset = new Cesium.Cartesian3(entity.worldPivot[0], entity.worldPivot[1], entity.worldPivot[2]);
1518
+ }
1519
+ m1 = Cesium.Transforms.eastNorthUpToFixedFrame(pos3d);
1520
+ hpr = Cesium.HeadingPitchRoll.fromDegrees(heading, pitch, roll, new Cesium.HeadingPitchRoll());
1521
+ transform = Cesium.Matrix3.fromHeadingPitchRoll(hpr);
1522
+ transformedOffset = Cesium.Matrix3.multiplyByVector(transform, offset, new Cesium.Cartesian3());
1523
+ pos3d = Cesium.Matrix4.multiplyByPoint(m1, transformedOffset, new Cesium.Cartesian3());
1524
+ if (!(pos3d === null || pos3d === void 0 ? void 0 : pos3d.x)) return [3 /*break*/, 15];
1525
+ return [4 /*yield*/, processPosHeight(pos3d, Cesium.HeightReference.NONE)];
1526
+ case 14:
1527
+ pos3d = _o.sent();
1528
+ _o.label = 15;
1529
+ case 15:
1530
+ if (pos3d) {
1531
+ return [2 /*return*/, [pos3d]];
1532
+ }
1533
+ return [2 /*return*/, []];
1534
+ }
1535
+ });
1536
+ }); };
1537
+ allPosses = [];
1538
+ i = 0;
1539
+ _b.label = 1;
1540
+ case 1:
1541
+ if (!(i < samples.length)) return [3 /*break*/, 4];
1542
+ sample = samples[i];
1543
+ return [4 /*yield*/, getEntityPositions(sample)];
1544
+ case 2:
1545
+ samplePosses = _b.sent();
1546
+ if (samplePosses === null || samplePosses === void 0 ? void 0 : samplePosses.length) {
1547
+ valid = !(allPosses === null || allPosses === void 0 ? void 0 : allPosses.length);
1548
+ if (!valid) {
1549
+ for (j = 0; j < samplePosses.length; j++) {
1550
+ samplePos = samplePosses[j];
1551
+ for (k = 0; k < allPosses.length; k++) {
1552
+ allPos = allPosses[k];
1553
+ distance = Cesium.Cartesian3.distance(samplePos, allPos);
1554
+ if (distance < MAX_DISTANCE_BETWEEN_SAMPLES) {
1555
+ valid = true;
1556
+ break;
1557
+ }
1558
+ }
1559
+ if (valid) {
1560
+ break;
1561
+ }
1562
+ }
1563
+ }
1564
+ if (valid) {
1565
+ allPosses = allPosses.concat(samplePosses);
1566
+ validSamples += 1;
1567
+ if (validSamples >= MAX_VALID_SAMPLES) {
1568
+ return [3 /*break*/, 4];
1569
+ }
1570
+ }
1571
+ }
1572
+ _b.label = 3;
1573
+ case 3:
1574
+ i++;
1575
+ return [3 /*break*/, 1];
1576
+ case 4:
1577
+ if (allPosses.length > 1) {
1578
+ rect = allPosses.length == 1 ? null : Cesium.Rectangle.fromCartesianArray(allPosses);
1579
+ factor = 0.1;
1580
+ marginX = rect.width * factor / 2;
1581
+ marginY = rect.height * factor / 2;
1582
+ rect.east += marginX;
1583
+ rect.west -= marginX;
1584
+ rect.north += marginY;
1585
+ rect.south -= marginY;
1586
+ diagonalLen = Cesium.Cartesian3.distance(Cesium.Cartesian3.fromRadians(rect.west, rect.north), Cesium.Cartesian3.fromRadians(rect.east, rect.south));
1587
+ terrData = exports.ViewUtils.GatherTerrainTile({
1588
+ viewer: viewer
1589
+ });
1590
+ if (((_a = terrData === null || terrData === void 0 ? void 0 : terrData.terrain) === null || _a === void 0 ? void 0 : _a.tilesetId) == bruceModels.ProjectViewTile.EDefaultTerrain.FlatTerrain) {
1591
+ MIN_RECT_DIAGONAL_LENGTH = 0;
1592
+ }
1593
+ posCarto = Cesium.Cartographic.fromCartesian(allPosses[0]);
1594
+ height = posCarto.height + (diagonalLen * 1.5);
1595
+ data.pos3d = Cesium.Cartesian3.fromRadians(posCarto.longitude, posCarto.latitude, height);
1596
+ MIN_POSSES_LEN = 10;
1597
+ if (diagonalLen >= MIN_RECT_DIAGONAL_LENGTH && allPosses.length >= MIN_POSSES_LEN) {
1598
+ data.rectangle = rect;
1599
+ }
1600
+ }
1601
+ else if (allPosses.length == 1) {
1602
+ data.pos3d = allPosses[0];
1603
+ }
1604
+ return [2 /*return*/, data];
1605
+ }
1606
+ });
1607
+ });
1608
+ }
1609
+ EntityUtils.GetLocation = GetLocation;
893
1610
  /**
894
1611
  * Returns an entity's position.
895
1612
  * This will attempt to calculate it from multiple sources of data.
896
1613
  * @param params
1614
+ * @deprecated use GetLocation instead.
897
1615
  * @returns
898
1616
  */
899
1617
  function GetPos(params) {
@@ -905,9 +1623,9 @@
905
1623
  if ((rego === null || rego === void 0 ? void 0 : rego.visual) instanceof Cesium.Entity) {
906
1624
  var visual = rego.visual;
907
1625
  if (visual.position) {
908
- var pos3d_1 = GetValue(viewer, visual.position);
1626
+ var pos3d_4 = GetValue(viewer, visual.position);
909
1627
  // Fix height reference.
910
- if (pos3d_1 === null || pos3d_1 === void 0 ? void 0 : pos3d_1.x) {
1628
+ if (pos3d_4 === null || pos3d_4 === void 0 ? void 0 : pos3d_4.x) {
911
1629
  var visualHeightRef = Cesium.HeightReference.RELATIVE_TO_GROUND;
912
1630
  if (visual.model) {
913
1631
  visualHeightRef = GetValue(viewer, visual.model.heightReference);
@@ -934,7 +1652,7 @@
934
1652
  return exports.DrawingUtils.EnsurePosHeight({
935
1653
  desiredHeightRef: params.returnHeightRef,
936
1654
  heightRef: visualHeightRef,
937
- pos3d: pos3d_1,
1655
+ pos3d: pos3d_4,
938
1656
  viewer: viewer
939
1657
  });
940
1658
  }
@@ -944,12 +1662,12 @@
944
1662
  }
945
1663
  function evaluateRecord() {
946
1664
  if (entity.location && bruceModels.Carto.ValidateCarto(entity.location)) {
947
- var location_1 = entity.location;
948
- var latitude = EnsureNumber(location_1.latitude);
949
- var longitude = EnsureNumber(location_1.longitude);
1665
+ var location_2 = entity.location;
1666
+ var latitude = EnsureNumber(location_2.latitude);
1667
+ var longitude = EnsureNumber(location_2.longitude);
950
1668
  // Disallowing exact 0.
951
1669
  if (latitude || longitude) {
952
- return Cesium.Cartesian3.fromDegrees(longitude, latitude, EnsureNumber(location_1.altitude));
1670
+ return Cesium.Cartesian3.fromDegrees(longitude, latitude, EnsureNumber(location_2.altitude));
953
1671
  }
954
1672
  }
955
1673
  if (entity.geometry && typeof entity.geometry == "object") {
@@ -1027,12 +1745,13 @@
1027
1745
  * Returns the position of the entity.
1028
1746
  * This is an async variant that checks for related tilesets.
1029
1747
  * @param params
1748
+ * @deprecated use GetLocation instead.
1030
1749
  * @returns
1031
1750
  */
1032
1751
  function GetPosAsync(params) {
1033
1752
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1034
1753
  return __awaiter(this, void 0, void 0, function () {
1035
- var viewer, entityId, entity, tileset, tilesetId, visualRegister, returnHeightRef, recordHeightRef, api, lat, lon, e_1, e_2, pos3d, tSettings, alt, alt, heading, pitch, roll, matrix4, offset, m1, hpr, transform, transformedOffset;
1754
+ var viewer, entityId, entity, tileset, tilesetId, visualRegister, returnHeightRef, recordHeightRef, api, lat, lon, e_3, e_4, pos3d, tSettings, alt, alt, heading, pitch, roll, matrix4, offset, m1, hpr, transform, transformedOffset;
1036
1755
  return __generator(this, function (_o) {
1037
1756
  switch (_o.label) {
1038
1757
  case 0:
@@ -1054,8 +1773,8 @@
1054
1773
  lon = +((_b = entity === null || entity === void 0 ? void 0 : entity.location) === null || _b === void 0 ? void 0 : _b.longitude);
1055
1774
  return [3 /*break*/, 4];
1056
1775
  case 3:
1057
- e_1 = _o.sent();
1058
- console.error(e_1);
1776
+ e_3 = _o.sent();
1777
+ console.error(e_3);
1059
1778
  return [3 /*break*/, 4];
1060
1779
  case 4:
1061
1780
  if (!(entity && (isNaN(lat) || isNaN(lon) || (lat == 0 && lon == 0)))) return [3 /*break*/, 9];
@@ -1071,8 +1790,8 @@
1071
1790
  entity = (_o.sent()).entity;
1072
1791
  return [3 /*break*/, 9];
1073
1792
  case 7:
1074
- e_2 = _o.sent();
1075
- console.warn(e_2);
1793
+ e_4 = _o.sent();
1794
+ console.warn(e_4);
1076
1795
  return [4 /*yield*/, bruceModels.Entity.Get({
1077
1796
  api: api,
1078
1797
  entityId: entityId,
@@ -1189,105 +1908,122 @@
1189
1908
  */
1190
1909
  function GatherEntity(params) {
1191
1910
  var entity = params.entity;
1192
- if (entity instanceof Cesium.Entity) {
1193
- var cEntity = entity;
1194
- var items = [];
1195
- traverseEntity(cEntity, items, false);
1196
- return items;
1197
- }
1198
- return [entity];
1199
- }
1200
- EntityUtils.GatherEntity = GatherEntity;
1201
- /**
1202
- * Looks at given entities with least amount of movement.
1203
- * @param viewer
1204
- * @param entities
1205
- */
1206
- function LookAtEntities(params) {
1207
- var viewer = params.viewer, entities = params.entities;
1208
- // Removing cesium tileset features for now as it's not accurate.
1209
- entities = [].concat(entities).filter(function (x) { return !(x instanceof Cesium.Cesium3DTileFeature); });
1210
- if (!entities.length) {
1211
- return;
1212
- }
1213
- var _a = [Cesium.Rectangle, Cesium.Cartographic, Cesium.Cartesian3, Cesium.Matrix3, Cesium.Matrix4, Cesium.EasingFunction], C3 = _a[2], M4 = _a[4];
1214
- var cutoffDistance = 2000;
1215
- var hoverHeight = 2000;
1216
- var duration = 0.5;
1217
- var centers = function (p) {
1218
- var PM = p.modelMatrix;
1219
- var instances = (function (i) { return (i instanceof Cesium.GeometryInstance ? [i] : i); })(p.geometryInstances);
1220
- return instances.map(function (g) {
1221
- var _M = M4.multiply(PM, g.modelMatrix, new M4);
1222
- var G = g.geometry;
1223
- var _p = G.attributes.position;
1224
- var b = G.boundingSphere;
1225
- return [b.center, b.radius];
1226
- });
1227
- };
1228
- var currentTime = Cesium.JulianDate.now();
1229
- var target = entities.flatMap(function (e) {
1230
- var _a;
1231
- if (e instanceof Cesium.Cartesian3) {
1232
- return [[e, 0]];
1233
- }
1234
- if (e instanceof Cesium.Entity) {
1235
- return [[(_a = e.position) === null || _a === void 0 ? void 0 : _a.getValue(currentTime), 0]];
1236
- }
1237
- if (e instanceof Cesium.Primitive) {
1238
- return centers(e);
1239
- }
1240
- if (e instanceof Cesium.Cesium3DTileFeature) {
1241
- var s = e.tileset.boundingSphere;
1242
- return [[s.center, s.radius]];
1243
- }
1244
- });
1245
- var bounds = function (list) {
1246
- var min = list[0][0];
1247
- var max = min;
1248
- for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
1249
- var _a = list_1[_i], p_1 = _a[0], r = _a[1];
1250
- var pMin = C3.subtract(p_1, new C3(r), new C3);
1251
- var pMax = C3.add(p_1, new C3(r), new C3);
1252
- min = C3.minimumByComponent(pMin, min, new C3);
1253
- max = C3.maximumByComponent(pMax, max, new C3);
1254
- }
1255
- var c = C3.multiplyByScalar(C3.add(max, min, new C3), 0.5, new C3);
1256
- return c;
1257
- };
1258
- var center = bounds(target);
1259
- var orient = function (p) {
1260
- var d = C3.subtract(center, p, new C3);
1261
- var dir = C3.normalize(d, new C3);
1262
- var up = viewer.scene.globe.ellipsoid.geodeticSurfaceNormal(center);
1263
- return [p, dir, up];
1264
- };
1265
- var shorten = function (v, l) {
1266
- var c = l / C3.magnitude(v);
1267
- return C3.multiplyByScalar(v, c, new C3);
1268
- };
1269
- var camera = viewer.camera;
1270
- var _b = orient(camera.position), p = _b[0], direction = _b[1], up = _b[2];
1271
- var orientation = { direction: direction, up: up };
1272
- camera.flyTo({
1273
- destination: p,
1274
- orientation: orientation,
1275
- duration: duration,
1276
- complete: function () {
1277
- if (C3.distance(p, center) > cutoffDistance) {
1278
- var d = C3.subtract(p, center, new C3);
1279
- d = shorten(d, cutoffDistance);
1280
- var h = C3.multiplyByScalar(C3.normalize(up, new C3), hoverHeight, new C3);
1281
- d = C3.add(d, h, new C3);
1282
- d = shorten(d, cutoffDistance);
1283
- d = C3.add(d, center, new C3);
1284
- var _a = orient(d), direction_1 = _a[1], u = _a[2];
1285
- camera.flyTo({
1286
- destination: d,
1287
- orientation: { direction: direction_1, up: u }
1288
- });
1911
+ if (entity instanceof Cesium.Entity) {
1912
+ var cEntity = entity;
1913
+ var items = [];
1914
+ traverseEntity(cEntity, items, false);
1915
+ return items;
1916
+ }
1917
+ return [entity];
1918
+ }
1919
+ EntityUtils.GatherEntity = GatherEntity;
1920
+ /**
1921
+ * Looks at given entities with least amount of movement.
1922
+ * @param viewer
1923
+ * @param entities
1924
+ */
1925
+ function LookAtEntities(params) {
1926
+ return __awaiter(this, void 0, void 0, function () {
1927
+ var viewer, entities, _a, R, CT, C3, M3, M4, E, duration, centers, currentTime, target, bounds, center, orient, camera, _b, p, direction, up, orientation, terrData, MIN_HEIGHT, carto;
1928
+ return __generator(this, function (_c) {
1929
+ switch (_c.label) {
1930
+ case 0:
1931
+ viewer = params.viewer, entities = params.entities;
1932
+ // Removing cesium tileset features for now as it's not accurate.
1933
+ entities = [].concat(entities).filter(function (x) { return !(x instanceof Cesium.Cesium3DTileFeature); });
1934
+ if (!entities.length) {
1935
+ return [2 /*return*/];
1936
+ }
1937
+ _a = [Cesium.Rectangle, Cesium.Cartographic, Cesium.Cartesian3, Cesium.Matrix3, Cesium.Matrix4, Cesium.EasingFunction], R = _a[0], CT = _a[1], C3 = _a[2], M3 = _a[3], M4 = _a[4], E = _a[5];
1938
+ duration = 0.5;
1939
+ centers = function (p) {
1940
+ var PM = p.modelMatrix;
1941
+ var instances = (function (i) { return (i instanceof Cesium.GeometryInstance ? [i] : i); })(p.geometryInstances);
1942
+ return instances.map(function (g) {
1943
+ var _M = M4.multiply(PM, g.modelMatrix, new M4);
1944
+ var G = g.geometry;
1945
+ var _p = G.attributes.position;
1946
+ var b = G.boundingSphere;
1947
+ return [b.center, b.radius];
1948
+ });
1949
+ };
1950
+ currentTime = Cesium.JulianDate.now();
1951
+ target = entities.flatMap(function (e) {
1952
+ var _a;
1953
+ if (e instanceof Cesium.Cartesian3) {
1954
+ return [[e, 0]];
1955
+ }
1956
+ if (e instanceof Cesium.Entity) {
1957
+ return [[(_a = e.position) === null || _a === void 0 ? void 0 : _a.getValue(currentTime), 0]];
1958
+ }
1959
+ if (e instanceof Cesium.Primitive) {
1960
+ return centers(e);
1961
+ }
1962
+ if (e instanceof Cesium.Cesium3DTileFeature) {
1963
+ var s = e.tileset.boundingSphere;
1964
+ return [[s.center, s.radius]];
1965
+ }
1966
+ });
1967
+ bounds = function (list) {
1968
+ var min = list[0][0];
1969
+ var max = min;
1970
+ for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
1971
+ var _a = list_1[_i], p_1 = _a[0], r = _a[1];
1972
+ var pMin = C3.subtract(p_1, new C3(r), new C3);
1973
+ var pMax = C3.add(p_1, new C3(r), new C3);
1974
+ min = C3.minimumByComponent(pMin, min, new C3);
1975
+ max = C3.maximumByComponent(pMax, max, new C3);
1976
+ }
1977
+ var c = C3.multiplyByScalar(C3.add(max, min, new C3), 0.5, new C3);
1978
+ return c;
1979
+ };
1980
+ center = bounds(target);
1981
+ orient = function (p) {
1982
+ var d = C3.subtract(center, p, new C3);
1983
+ var dir = C3.normalize(d, new C3);
1984
+ var up = viewer.scene.globe.ellipsoid.geodeticSurfaceNormal(center);
1985
+ return [p, dir, up];
1986
+ };
1987
+ camera = viewer.camera;
1988
+ _b = orient(camera.position), p = _b[0], direction = _b[1], up = _b[2];
1989
+ orientation = { direction: direction, up: up };
1990
+ if (!(p === null || p === void 0 ? void 0 : p.x)) return [3 /*break*/, 2];
1991
+ return [4 /*yield*/, exports.DrawingUtils.GetTerrainHeight({
1992
+ pos3d: p,
1993
+ viewer: viewer
1994
+ })];
1995
+ case 1:
1996
+ terrData = _c.sent();
1997
+ MIN_HEIGHT = terrData.height + 300;
1998
+ carto = Cesium.Cartographic.fromCartesian(p);
1999
+ if (carto.height < MIN_HEIGHT) {
2000
+ carto.height = MIN_HEIGHT;
2001
+ p = Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height);
2002
+ }
2003
+ camera.flyTo({
2004
+ destination: p,
2005
+ orientation: orientation,
2006
+ duration: duration,
2007
+ complete: function () {
2008
+ // if (C3.distance(p, center) > cutoffDistance) {
2009
+ // let d = C3.subtract(p, center, new C3);
2010
+ // d = shorten(d, cutoffDistance);
2011
+ // const h = C3.multiplyByScalar(C3.normalize(up, new C3), hoverHeight, new C3);
2012
+ // d = C3.add(d, h, new C3);
2013
+ // d = shorten(d, cutoffDistance);
2014
+ // d = C3.add(d, center, new C3);
2015
+ // const [ _p, direction, u ] = orient(d);
2016
+ // camera.flyTo({
2017
+ // destination: d,
2018
+ // orientation: { direction, up: u }
2019
+ // });
2020
+ // }
2021
+ }
2022
+ });
2023
+ _c.label = 2;
2024
+ case 2: return [2 /*return*/];
1289
2025
  }
1290
- }
2026
+ });
1291
2027
  });
1292
2028
  }
1293
2029
  EntityUtils.LookAtEntities = LookAtEntities;
@@ -1965,6 +2701,24 @@
1965
2701
  _billboardCache.Set(key, data);
1966
2702
  return data;
1967
2703
  };
2704
+ /**
2705
+ * Removes duplicate points in a row and returns a new array.
2706
+ * Passed array is not mutated.
2707
+ * @param posses
2708
+ */
2709
+ function cullDuplicatePoints(posses) {
2710
+ var newPosses = [];
2711
+ var lastPos = null;
2712
+ for (var i = 0; i < posses.length; i++) {
2713
+ var pos = posses[i];
2714
+ // Avoiding 'Cesium.Cartesian3.equals' because passed data might be just a json blob in certain cases.
2715
+ if (pos && (!lastPos || (pos.x != lastPos.x || pos.y != lastPos.y || pos.z != lastPos.z))) {
2716
+ newPosses.push(pos);
2717
+ lastPos = pos;
2718
+ }
2719
+ }
2720
+ return newPosses;
2721
+ }
1968
2722
  (function (EntityRenderEngine) {
1969
2723
  function Render(params) {
1970
2724
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -2095,10 +2849,13 @@
2095
2849
  }
2096
2850
  });
2097
2851
  rendered = rendered.concat(Object.values(cLines));
2852
+ if (!!rendered.length) return [3 /*break*/, 4];
2098
2853
  return [4 /*yield*/, Point.RenderGroup(pParams)];
2099
2854
  case 3:
2100
2855
  cPoints = _k.sent();
2101
2856
  rendered = rendered.concat(Object.values(cPoints));
2857
+ _k.label = 4;
2858
+ case 4:
2102
2859
  rendered = rendered.filter(function (x) { return x != null; });
2103
2860
  if (rendered.length) {
2104
2861
  rootEntity_1 = new Cesium.Entity({});
@@ -2549,6 +3306,7 @@
2549
3306
  flattenPoints = true;
2550
3307
  }
2551
3308
  var posses = points.map(function (x) { return Cesium.Cartesian3.fromDegrees(EnsureNumber(x.longitude), EnsureNumber(x.latitude), EnsureNumber(flattenPoints ? 0 : x.altitude)); });
3309
+ posses = cullDuplicatePoints(posses);
2552
3310
  // 5 points should be enough to tell most bad data.
2553
3311
  var CHECK_POINTS = 5;
2554
3312
  var MIN_LEN = 0.001;
@@ -2727,6 +3485,10 @@
2727
3485
  bruceModels.Cartes.CloseRing3(posses);
2728
3486
  var extrusion = getPolygonExtrusion(entity, params.tags, outerRing, posses, heightRef, style);
2729
3487
  posses = extrusion.posses;
3488
+ posses = cullDuplicatePoints(posses);
3489
+ if (posses.length < 4) {
3490
+ return null;
3491
+ }
2730
3492
  var flattenPoints = false;
2731
3493
  if (heightRef == Cesium.HeightReference.CLAMP_TO_GROUND && shouldApplyFlatFix((_b = params.viewer) === null || _b === void 0 ? void 0 : _b.terrainProvider)) {
2732
3494
  heightRef = Cesium.HeightReference.NONE;
@@ -2735,8 +3497,10 @@
2735
3497
  var holeRings = pRings.filter(function (x) { return x.Facing == bruceModels.Geometry.EPolygonRingType.Hole; });
2736
3498
  var holePosses = holeRings.map(function (x) {
2737
3499
  var points = bruceModels.Geometry.ParsePoints(x.LinearRing);
2738
- return points.map(function (x) { return Cesium.Cartesian3.fromDegrees(EnsureNumber(x.longitude), EnsureNumber(x.latitude), EnsureNumber(flattenPoints ? 0 : x.altitude)); });
2739
- });
3500
+ var holePosses = points.map(function (x) { return Cesium.Cartesian3.fromDegrees(EnsureNumber(x.longitude), EnsureNumber(x.latitude), EnsureNumber(flattenPoints ? 0 : x.altitude)); });
3501
+ holePosses = cullDuplicatePoints(holePosses);
3502
+ return holePosses;
3503
+ }).filter(function (x) { return x.length >= 4; });
2740
3504
  var zIndex = getZIndex(style, entity, params.tags);
2741
3505
  var size = getSizeOfPolygonEntity(entity);
2742
3506
  var classification = Cesium.ClassificationType.TERRAIN;
@@ -12696,212 +13460,6 @@
12696
13460
  })(Terrain = TileRenderEngine.Terrain || (TileRenderEngine.Terrain = {}));
12697
13461
  })(exports.TileRenderEngine || (exports.TileRenderEngine = {}));
12698
13462
 
12699
- var CESIUM_INSPECTOR_KEY = "_nextspace_inspector";
12700
- (function (ViewUtils) {
12701
- function GatherLegacyMapTiles(params) {
12702
- var viewer = params.viewer;
12703
- var collection = viewer.imageryLayers;
12704
- var tiles = [];
12705
- for (var i = 0; i < collection.length; i++) {
12706
- var layer = collection.get(i);
12707
- if (layer._bName) {
12708
- tiles.push({
12709
- alpha: layer.alpha,
12710
- brightness: layer.brightness,
12711
- contrast: layer.contrast,
12712
- hue: layer.hue,
12713
- saturation: layer.saturation,
12714
- gamma: layer.gamma,
12715
- title: layer._bName,
12716
- });
12717
- }
12718
- }
12719
- return {
12720
- imagery: tiles.reverse()
12721
- };
12722
- }
12723
- ViewUtils.GatherLegacyMapTiles = GatherLegacyMapTiles;
12724
- function GatherLegacyTerrainTile(params) {
12725
- var viewer = params.viewer;
12726
- var enabled = viewer.terrainProvider;
12727
- if (enabled === null || enabled === void 0 ? void 0 : enabled._bName) {
12728
- return {
12729
- terrain: enabled._bName
12730
- };
12731
- }
12732
- return {
12733
- terrain: "flatterrain"
12734
- };
12735
- }
12736
- ViewUtils.GatherLegacyTerrainTile = GatherLegacyTerrainTile;
12737
- function GatherMapTiles(params) {
12738
- var viewer = params.viewer;
12739
- var imagery = viewer.imageryLayers;
12740
- var tiles = [];
12741
- var _loop_1 = function (i) {
12742
- var provider = imagery.get(i);
12743
- if (provider._bMeta) {
12744
- var idCombo_1 = provider._bMeta.accountId + provider._bMeta.tilesetId;
12745
- if (!tiles.find(function (x) { return x.accountId + x.tilesetId === idCombo_1; })) {
12746
- tiles.push({
12747
- accountId: provider._bMeta.accountId,
12748
- tilesetId: provider._bMeta.tilesetId,
12749
- alpha: provider.alpha,
12750
- brightness: provider.brightness,
12751
- contrast: provider.contrast,
12752
- hue: provider.hue,
12753
- saturation: provider.saturation,
12754
- gamma: provider.gamma
12755
- });
12756
- }
12757
- }
12758
- };
12759
- for (var i = 0; i < imagery.length; i++) {
12760
- _loop_1(i);
12761
- }
12762
- return {
12763
- imagery: tiles
12764
- };
12765
- }
12766
- ViewUtils.GatherMapTiles = GatherMapTiles;
12767
- function GatherTerrainTile(params) {
12768
- var viewer = params.viewer;
12769
- var provider = viewer.terrainProvider;
12770
- if (provider._bMeta) {
12771
- return {
12772
- terrain: {
12773
- accountId: provider._bMeta.accountId,
12774
- tilesetId: provider._bMeta.tilesetId,
12775
- }
12776
- };
12777
- }
12778
- else if (provider instanceof Cesium.EllipsoidTerrainProvider) {
12779
- return {
12780
- terrain: {
12781
- tilesetId: bruceModels.ProjectViewTile.EDefaultTerrain.FlatTerrain,
12782
- accountId: null
12783
- }
12784
- };
12785
- }
12786
- return null;
12787
- }
12788
- ViewUtils.GatherTerrainTile = GatherTerrainTile;
12789
- function SetTerrainWireframeStatus(params) {
12790
- if (!params.viewer[CESIUM_INSPECTOR_KEY]) {
12791
- var InspectorClass = Cesium.CesiumInspector;
12792
- if (InspectorClass) {
12793
- var inspector = new InspectorClass(document.createElement("div"), params.viewer.scene);
12794
- inspector.container.style.display = "none";
12795
- params.viewer[CESIUM_INSPECTOR_KEY] = inspector;
12796
- params.viewer.scene.requestRender();
12797
- }
12798
- }
12799
- if (params.viewer[CESIUM_INSPECTOR_KEY]) {
12800
- params.viewer[CESIUM_INSPECTOR_KEY].viewModel.wireframe = params.status;
12801
- }
12802
- }
12803
- ViewUtils.SetTerrainWireframeStatus = SetTerrainWireframeStatus;
12804
- function GetTerrainWireframeStatus(params) {
12805
- var _a, _b;
12806
- if (!params.viewer[CESIUM_INSPECTOR_KEY]) {
12807
- return false;
12808
- }
12809
- return (_b = (_a = params.viewer[CESIUM_INSPECTOR_KEY]) === null || _a === void 0 ? void 0 : _a.viewModel) === null || _b === void 0 ? void 0 : _b.wireframe;
12810
- }
12811
- ViewUtils.GetTerrainWireframeStatus = GetTerrainWireframeStatus;
12812
- /**
12813
- * Changes between perspective and orthographic view.
12814
- * When Cesium stops being bad at picking positions in 2d mode we'll use the flat earth mode instead.
12815
- * @param params
12816
- */
12817
- function Set2dStatus(params) {
12818
- var viewer = params.viewer, is2d = params.status, moveCamera = params.moveCamera;
12819
- var curLens2d = viewer.camera.frustum instanceof Cesium.OrthographicFrustum;
12820
- if (curLens2d && !is2d) {
12821
- viewer.camera.switchToPerspectiveFrustum();
12822
- viewer.scene.screenSpaceCameraController.enableTilt = true;
12823
- viewer.scene.requestRender();
12824
- }
12825
- else if (!curLens2d && is2d) {
12826
- viewer.camera.switchToOrthographicFrustum();
12827
- viewer.scene.screenSpaceCameraController.enableTilt = false;
12828
- if (moveCamera != false) {
12829
- try {
12830
- // Face camera downwards to make it look 2d.
12831
- // We want to try make it look at the center-point of the current view.
12832
- // If center cannot be calculated then we'll simply raise the camera and face it downwards.
12833
- var scene = viewer.scene;
12834
- var windowPosition = new Cesium.Cartesian2(scene.canvas.clientWidth / 2, scene.canvas.clientHeight / 2);
12835
- var ray = viewer.camera.getPickRay(windowPosition);
12836
- var intersection = scene.globe.pick(ray, scene);
12837
- var center = void 0;
12838
- if (Cesium.defined(intersection)) {
12839
- center = Cesium.Cartographic.fromCartesian(intersection);
12840
- }
12841
- // Use current camera position if we can't calculate the center.
12842
- else {
12843
- center = Cesium.Cartographic.fromCartesian(viewer.camera.position);
12844
- center.height = 0;
12845
- }
12846
- center.height = viewer.camera.positionCartographic.height + 100;
12847
- viewer.camera.setView({
12848
- destination: Cesium.Cartographic.toCartesian(center),
12849
- orientation: {
12850
- heading: 0.0,
12851
- pitch: Cesium.Math.toRadians(-90.0),
12852
- roll: 0.0
12853
- }
12854
- });
12855
- }
12856
- catch (e) {
12857
- console.error(e);
12858
- }
12859
- }
12860
- viewer.scene.requestRender();
12861
- }
12862
- }
12863
- ViewUtils.Set2dStatus = Set2dStatus;
12864
- function Get2dStatus(params) {
12865
- var viewer = params.viewer;
12866
- return viewer.camera.frustum instanceof Cesium.OrthographicFrustum;
12867
- }
12868
- ViewUtils.Get2dStatus = Get2dStatus;
12869
- function SetLockedCameraStatus(params) {
12870
- var viewer = params.viewer, status = params.status;
12871
- var scene = viewer === null || viewer === void 0 ? void 0 : viewer.scene;
12872
- if (!scene) {
12873
- return;
12874
- }
12875
- if (status) {
12876
- scene.screenSpaceCameraController.enableInputs = false;
12877
- scene.screenSpaceCameraController.enableTranslate = false;
12878
- scene.screenSpaceCameraController.enableZoom = false;
12879
- scene.screenSpaceCameraController.enableRotate = false;
12880
- scene.screenSpaceCameraController.enableTilt = false;
12881
- }
12882
- else {
12883
- scene.screenSpaceCameraController.enableInputs = true;
12884
- scene.screenSpaceCameraController.enableTranslate = true;
12885
- scene.screenSpaceCameraController.enableZoom = true;
12886
- scene.screenSpaceCameraController.enableRotate = true;
12887
- if (!ViewUtils.Get2dStatus({ viewer: viewer })) {
12888
- scene.screenSpaceCameraController.enableTilt = true;
12889
- }
12890
- }
12891
- viewer.scene.requestRender();
12892
- }
12893
- ViewUtils.SetLockedCameraStatus = SetLockedCameraStatus;
12894
- function GetLockedCameraStatus(params) {
12895
- var _a;
12896
- var scene = (_a = params.viewer) === null || _a === void 0 ? void 0 : _a.scene;
12897
- if (!scene) {
12898
- return false;
12899
- }
12900
- return !scene.screenSpaceCameraController.enableTranslate;
12901
- }
12902
- ViewUtils.GetLockedCameraStatus = GetLockedCameraStatus;
12903
- })(exports.ViewUtils || (exports.ViewUtils = {}));
12904
-
12905
13463
  var VIEWER_BOOKMARKS_WIDGET_KEY = "_viewerBookmarksWidget";
12906
13464
  var WidgetBookmarks = /** @class */ (function (_super) {
12907
13465
  __extends(WidgetBookmarks, _super);
@@ -16653,7 +17211,7 @@
16653
17211
  ViewerUtils.CreateWidgets = CreateWidgets;
16654
17212
  })(exports.ViewerUtils || (exports.ViewerUtils = {}));
16655
17213
 
16656
- var VERSION$1 = "2.9.4";
17214
+ var VERSION$1 = "2.9.6";
16657
17215
 
16658
17216
  exports.VERSION = VERSION$1;
16659
17217
  exports.CesiumViewMonitor = CesiumViewMonitor;