bruce-cesium 2.9.5 → 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.
@@ -1,6 +1,6 @@
1
- import { BruceEvent, Cartes, Carto, Entity as Entity$1, Geometry, Tileset, MathUtils, LRUCache, ZoomControl, Style, EntityTag, Calculator, EntityLod, EntityType, ClientFile, ObjectUtils, Bounds, EntityRelationType, DelayQueue, BatchedDataGetter, EntityCoords, EntityFilterGetter, EntitySource, MenuItem, EntityRelation, ENVIRONMENT, ProjectView, ProjectViewBookmark, ProjectViewTile, ProjectViewLegacyTile, ProgramKey, Camera, AbstractApi, EntityAttachment, EntityAttachmentType, EntityAttribute } from 'bruce-models';
1
+ import { BruceEvent, Cartes, ProjectViewTile, Carto, Entity as Entity$1, Geometry, Tileset, MathUtils, LRUCache, ZoomControl, Style, EntityTag, Calculator, EntityLod, EntityType, ClientFile, ObjectUtils, Bounds, EntityRelationType, DelayQueue, BatchedDataGetter, EntityCoords, EntityFilterGetter, EntitySource, MenuItem, EntityRelation, ENVIRONMENT, ProjectView, ProjectViewBookmark, ProjectViewLegacyTile, ProgramKey, Camera, AbstractApi, EntityAttachment, EntityAttachmentType, EntityAttribute } from 'bruce-models';
2
2
  import * as Cesium from 'cesium';
3
- import { Cartographic, Cartesian2, CallbackProperty, Cartesian3, Color, Rectangle, Math as Math$1, JulianDate, Entity, Primitive, Cesium3DTileFeature, SceneMode, HeightReference, DistanceDisplayCondition, NearFarScalar, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Cesium3DTileColorBlendMode, HeadingPitchRange, Cesium3DTileStyle, KmlDataSource, createOsmBuildings, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, SceneTransforms, CesiumInspector, OrthographicFrustum, defined, Cesium3DTileset, Matrix4, Matrix3, IonResource, Ion, EllipsoidGeodesic, sampleTerrainMostDetailed, Model, EasingFunction, PolygonPipeline, ColorMaterialProperty, GeometryInstance, ScreenSpaceEventHandler, ScreenSpaceEventType, BoundingSphere } from 'cesium';
3
+ import { Cartographic, Cartesian2, CallbackProperty, Cartesian3, Color, Rectangle, Math as Math$1, JulianDate, Entity, Primitive, Cesium3DTileFeature, HeightReference, DistanceDisplayCondition, NearFarScalar, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, SceneMode, Cesium3DTileColorBlendMode, HeadingPitchRange, createOsmBuildings, Cesium3DTileStyle, KmlDataSource, SceneTransforms, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, CesiumInspector, OrthographicFrustum, defined, EllipsoidGeodesic, sampleTerrainMostDetailed, Cesium3DTileset, Model, EasingFunction, PolygonPipeline, Matrix4, Matrix3, IonResource, Ion, ScreenSpaceEventHandler, ScreenSpaceEventType, ColorMaterialProperty, GeometryInstance, BoundingSphere } from 'cesium';
4
4
 
5
5
  var TIME_LAG = 300;
6
6
  var POSITION_CHECK_TIMER = 950;
@@ -727,6 +727,213 @@ var DrawingUtils;
727
727
  DrawingUtils.RaisePos3d = RaisePos3d;
728
728
  })(DrawingUtils || (DrawingUtils = {}));
729
729
 
730
+ var CESIUM_INSPECTOR_KEY = "_nextspace_inspector";
731
+ var ViewUtils;
732
+ (function (ViewUtils) {
733
+ function GatherLegacyMapTiles(params) {
734
+ var viewer = params.viewer;
735
+ var collection = viewer.imageryLayers;
736
+ var tiles = [];
737
+ for (var i = 0; i < collection.length; i++) {
738
+ var layer = collection.get(i);
739
+ if (layer._bName) {
740
+ tiles.push({
741
+ alpha: layer.alpha,
742
+ brightness: layer.brightness,
743
+ contrast: layer.contrast,
744
+ hue: layer.hue,
745
+ saturation: layer.saturation,
746
+ gamma: layer.gamma,
747
+ title: layer._bName,
748
+ });
749
+ }
750
+ }
751
+ return {
752
+ imagery: tiles.reverse()
753
+ };
754
+ }
755
+ ViewUtils.GatherLegacyMapTiles = GatherLegacyMapTiles;
756
+ function GatherLegacyTerrainTile(params) {
757
+ var viewer = params.viewer;
758
+ var enabled = viewer.terrainProvider;
759
+ if (enabled === null || enabled === void 0 ? void 0 : enabled._bName) {
760
+ return {
761
+ terrain: enabled._bName
762
+ };
763
+ }
764
+ return {
765
+ terrain: "flatterrain"
766
+ };
767
+ }
768
+ ViewUtils.GatherLegacyTerrainTile = GatherLegacyTerrainTile;
769
+ function GatherMapTiles(params) {
770
+ var viewer = params.viewer;
771
+ var imagery = viewer.imageryLayers;
772
+ var tiles = [];
773
+ var _loop_1 = function (i) {
774
+ var provider = imagery.get(i);
775
+ if (provider._bMeta) {
776
+ var idCombo_1 = provider._bMeta.accountId + provider._bMeta.tilesetId;
777
+ if (!tiles.find(function (x) { return x.accountId + x.tilesetId === idCombo_1; })) {
778
+ tiles.push({
779
+ accountId: provider._bMeta.accountId,
780
+ tilesetId: provider._bMeta.tilesetId,
781
+ alpha: provider.alpha,
782
+ brightness: provider.brightness,
783
+ contrast: provider.contrast,
784
+ hue: provider.hue,
785
+ saturation: provider.saturation,
786
+ gamma: provider.gamma
787
+ });
788
+ }
789
+ }
790
+ };
791
+ for (var i = 0; i < imagery.length; i++) {
792
+ _loop_1(i);
793
+ }
794
+ return {
795
+ imagery: tiles
796
+ };
797
+ }
798
+ ViewUtils.GatherMapTiles = GatherMapTiles;
799
+ function GatherTerrainTile(params) {
800
+ var viewer = params.viewer;
801
+ var provider = viewer.terrainProvider;
802
+ if (provider._bMeta) {
803
+ return {
804
+ terrain: {
805
+ accountId: provider._bMeta.accountId,
806
+ tilesetId: provider._bMeta.tilesetId,
807
+ }
808
+ };
809
+ }
810
+ else if (provider instanceof EllipsoidTerrainProvider) {
811
+ return {
812
+ terrain: {
813
+ tilesetId: ProjectViewTile.EDefaultTerrain.FlatTerrain,
814
+ accountId: null
815
+ }
816
+ };
817
+ }
818
+ return null;
819
+ }
820
+ ViewUtils.GatherTerrainTile = GatherTerrainTile;
821
+ function SetTerrainWireframeStatus(params) {
822
+ if (!params.viewer[CESIUM_INSPECTOR_KEY]) {
823
+ var InspectorClass = CesiumInspector;
824
+ if (InspectorClass) {
825
+ var inspector = new InspectorClass(document.createElement("div"), params.viewer.scene);
826
+ inspector.container.style.display = "none";
827
+ params.viewer[CESIUM_INSPECTOR_KEY] = inspector;
828
+ params.viewer.scene.requestRender();
829
+ }
830
+ }
831
+ if (params.viewer[CESIUM_INSPECTOR_KEY]) {
832
+ params.viewer[CESIUM_INSPECTOR_KEY].viewModel.wireframe = params.status;
833
+ }
834
+ }
835
+ ViewUtils.SetTerrainWireframeStatus = SetTerrainWireframeStatus;
836
+ function GetTerrainWireframeStatus(params) {
837
+ var _a, _b;
838
+ if (!params.viewer[CESIUM_INSPECTOR_KEY]) {
839
+ return false;
840
+ }
841
+ return (_b = (_a = params.viewer[CESIUM_INSPECTOR_KEY]) === null || _a === void 0 ? void 0 : _a.viewModel) === null || _b === void 0 ? void 0 : _b.wireframe;
842
+ }
843
+ ViewUtils.GetTerrainWireframeStatus = GetTerrainWireframeStatus;
844
+ /**
845
+ * Changes between perspective and orthographic view.
846
+ * When Cesium stops being bad at picking positions in 2d mode we'll use the flat earth mode instead.
847
+ * @param params
848
+ */
849
+ function Set2dStatus(params) {
850
+ var viewer = params.viewer, is2d = params.status, moveCamera = params.moveCamera;
851
+ var curLens2d = viewer.camera.frustum instanceof OrthographicFrustum;
852
+ if (curLens2d && !is2d) {
853
+ viewer.camera.switchToPerspectiveFrustum();
854
+ viewer.scene.screenSpaceCameraController.enableTilt = true;
855
+ viewer.scene.requestRender();
856
+ }
857
+ else if (!curLens2d && is2d) {
858
+ viewer.camera.switchToOrthographicFrustum();
859
+ viewer.scene.screenSpaceCameraController.enableTilt = false;
860
+ if (moveCamera != false) {
861
+ try {
862
+ // Face camera downwards to make it look 2d.
863
+ // We want to try make it look at the center-point of the current view.
864
+ // If center cannot be calculated then we'll simply raise the camera and face it downwards.
865
+ var scene = viewer.scene;
866
+ var windowPosition = new Cartesian2(scene.canvas.clientWidth / 2, scene.canvas.clientHeight / 2);
867
+ var ray = viewer.camera.getPickRay(windowPosition);
868
+ var intersection = scene.globe.pick(ray, scene);
869
+ var center = void 0;
870
+ if (defined(intersection)) {
871
+ center = Cartographic.fromCartesian(intersection);
872
+ }
873
+ // Use current camera position if we can't calculate the center.
874
+ else {
875
+ center = Cartographic.fromCartesian(viewer.camera.position);
876
+ center.height = 0;
877
+ }
878
+ center.height = viewer.camera.positionCartographic.height + 100;
879
+ viewer.camera.setView({
880
+ destination: Cartographic.toCartesian(center),
881
+ orientation: {
882
+ heading: 0.0,
883
+ pitch: Math$1.toRadians(-90.0),
884
+ roll: 0.0
885
+ }
886
+ });
887
+ }
888
+ catch (e) {
889
+ console.error(e);
890
+ }
891
+ }
892
+ viewer.scene.requestRender();
893
+ }
894
+ }
895
+ ViewUtils.Set2dStatus = Set2dStatus;
896
+ function Get2dStatus(params) {
897
+ var viewer = params.viewer;
898
+ return viewer.camera.frustum instanceof OrthographicFrustum;
899
+ }
900
+ ViewUtils.Get2dStatus = Get2dStatus;
901
+ function SetLockedCameraStatus(params) {
902
+ var viewer = params.viewer, status = params.status;
903
+ var scene = viewer === null || viewer === void 0 ? void 0 : viewer.scene;
904
+ if (!scene) {
905
+ return;
906
+ }
907
+ if (status) {
908
+ scene.screenSpaceCameraController.enableInputs = false;
909
+ scene.screenSpaceCameraController.enableTranslate = false;
910
+ scene.screenSpaceCameraController.enableZoom = false;
911
+ scene.screenSpaceCameraController.enableRotate = false;
912
+ scene.screenSpaceCameraController.enableTilt = false;
913
+ }
914
+ else {
915
+ scene.screenSpaceCameraController.enableInputs = true;
916
+ scene.screenSpaceCameraController.enableTranslate = true;
917
+ scene.screenSpaceCameraController.enableZoom = true;
918
+ scene.screenSpaceCameraController.enableRotate = true;
919
+ if (!ViewUtils.Get2dStatus({ viewer: viewer })) {
920
+ scene.screenSpaceCameraController.enableTilt = true;
921
+ }
922
+ }
923
+ viewer.scene.requestRender();
924
+ }
925
+ ViewUtils.SetLockedCameraStatus = SetLockedCameraStatus;
926
+ function GetLockedCameraStatus(params) {
927
+ var _a;
928
+ var scene = (_a = params.viewer) === null || _a === void 0 ? void 0 : _a.scene;
929
+ if (!scene) {
930
+ return false;
931
+ }
932
+ return !scene.screenSpaceCameraController.enableTranslate;
933
+ }
934
+ ViewUtils.GetLockedCameraStatus = GetLockedCameraStatus;
935
+ })(ViewUtils || (ViewUtils = {}));
936
+
730
937
  /**
731
938
  * Returns if a given visual is alive and in the scene.
732
939
  * @param viewer
@@ -887,14 +1094,526 @@ function GetValue(viewer, obj) {
887
1094
  if (obj === null || obj === void 0 ? void 0 : obj.getValue) {
888
1095
  return obj.getValue(viewer.scene.lastRenderTime);
889
1096
  }
890
- return obj;
891
- }
892
- var EntityUtils;
893
- (function (EntityUtils) {
1097
+ return obj;
1098
+ }
1099
+ var EntityUtils;
1100
+ (function (EntityUtils) {
1101
+ /**
1102
+ * Returns the location for given entity or entities.
1103
+ * If available it will also compute a rectangle.
1104
+ * It is recommended to fly-to a rectangle if available as it will ensure the full geometry is in view.
1105
+ * @param params
1106
+ */
1107
+ function GetLocation(params) {
1108
+ var _a;
1109
+ return __awaiter(this, void 0, void 0, function () {
1110
+ 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;
1111
+ var _this = this;
1112
+ return __generator(this, function (_b) {
1113
+ switch (_b.label) {
1114
+ case 0:
1115
+ api = params.api, viewer = params.viewer, samples = params.samples, visualRegister = params.visualRegister, minimumAlt = params.minimumAlt, paddingAlt = params.paddingAlt;
1116
+ if (!paddingAlt) {
1117
+ paddingAlt = 0;
1118
+ }
1119
+ MAX_DISTANCE_BETWEEN_SAMPLES = 5000;
1120
+ MAX_TERRAIN_SAMPLES = 25;
1121
+ terrainSamples = 0;
1122
+ MAX_API_CALLS = 10;
1123
+ apiCalls = 0;
1124
+ MAX_VALID_SAMPLES = 20;
1125
+ validSamples = 0;
1126
+ MIN_RECT_DIAGONAL_LENGTH = isNaN(minimumAlt) || minimumAlt == null ? 0 : minimumAlt * 10;
1127
+ if (MIN_RECT_DIAGONAL_LENGTH < 1500) {
1128
+ MIN_RECT_DIAGONAL_LENGTH = 1500;
1129
+ }
1130
+ data = {
1131
+ pos3d: null,
1132
+ rectangle: null
1133
+ };
1134
+ processPosHeight = function (pos3d, heightRef) { return __awaiter(_this, void 0, void 0, function () {
1135
+ var carto, baseHeight, terrData, height, carto;
1136
+ return __generator(this, function (_a) {
1137
+ switch (_a.label) {
1138
+ case 0:
1139
+ if (!(!isNaN(minimumAlt) && minimumAlt != null)) return [3 /*break*/, 5];
1140
+ carto = Cartographic.fromCartesian(pos3d);
1141
+ if (!(carto === null || carto === void 0 ? void 0 : carto.latitude)) return [3 /*break*/, 4];
1142
+ baseHeight = 0;
1143
+ if (!(heightRef == null || heightRef == HeightReference.RELATIVE_TO_GROUND || heightRef == HeightReference.NONE)) return [3 /*break*/, 3];
1144
+ if (!(terrainSamples > MAX_TERRAIN_SAMPLES)) return [3 /*break*/, 1];
1145
+ baseHeight = viewer.scene.globe.getHeight(carto);
1146
+ return [3 /*break*/, 3];
1147
+ case 1: return [4 /*yield*/, DrawingUtils.GetTerrainHeight({
1148
+ pos3d: pos3d,
1149
+ viewer: viewer
1150
+ })];
1151
+ case 2:
1152
+ terrData = _a.sent();
1153
+ baseHeight = terrData === null || terrData === void 0 ? void 0 : terrData.height;
1154
+ terrainSamples += 1;
1155
+ _a.label = 3;
1156
+ case 3:
1157
+ if (baseHeight != undefined && !isNaN(baseHeight)) {
1158
+ height = baseHeight + minimumAlt;
1159
+ if (height > carto.height) {
1160
+ carto.height = height;
1161
+ }
1162
+ return [2 /*return*/, Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height + paddingAlt)];
1163
+ }
1164
+ _a.label = 4;
1165
+ case 4: return [3 /*break*/, 6];
1166
+ case 5:
1167
+ if (paddingAlt) {
1168
+ carto = Cartographic.fromCartesian(pos3d);
1169
+ if (carto === null || carto === void 0 ? void 0 : carto.latitude) {
1170
+ return [2 /*return*/, Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height + paddingAlt)];
1171
+ }
1172
+ }
1173
+ _a.label = 6;
1174
+ case 6: return [2 /*return*/, pos3d];
1175
+ }
1176
+ });
1177
+ }); };
1178
+ ensureHeightRefs = function (posses, sample) { return __awaiter(_this, void 0, void 0, function () {
1179
+ var heightRef, returnHeightRef, i, _a, _b;
1180
+ return __generator(this, function (_c) {
1181
+ switch (_c.label) {
1182
+ case 0:
1183
+ if (!(posses === null || posses === void 0 ? void 0 : posses.length)) return [3 /*break*/, 4];
1184
+ heightRef = sample.heightRef;
1185
+ returnHeightRef = sample.returnHeightRef;
1186
+ i = 0;
1187
+ _c.label = 1;
1188
+ case 1:
1189
+ if (!(i < posses.length)) return [3 /*break*/, 4];
1190
+ if (heightRef != null && returnHeightRef != null && heightRef != returnHeightRef) {
1191
+ posses[i] = DrawingUtils.EnsurePosHeight({
1192
+ desiredHeightRef: returnHeightRef,
1193
+ heightRef: heightRef,
1194
+ pos3d: posses[i],
1195
+ viewer: viewer
1196
+ });
1197
+ }
1198
+ _a = posses;
1199
+ _b = i;
1200
+ return [4 /*yield*/, processPosHeight(posses[i], returnHeightRef)];
1201
+ case 2:
1202
+ _a[_b] = _c.sent();
1203
+ _c.label = 3;
1204
+ case 3:
1205
+ i++;
1206
+ return [3 /*break*/, 1];
1207
+ case 4: return [2 /*return*/];
1208
+ }
1209
+ });
1210
+ }); };
1211
+ getEntityPositions = function (sample) { return __awaiter(_this, void 0, void 0, function () {
1212
+ 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;
1213
+ var _this = this;
1214
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1215
+ return __generator(this, function (_o) {
1216
+ switch (_o.label) {
1217
+ case 0:
1218
+ entityId = sample.entityId, entity = sample.entity, tileset = sample.tileset, tilesetId = sample.tilesetId;
1219
+ if (!!entity) return [3 /*break*/, 9];
1220
+ lat = 0;
1221
+ lon = 0;
1222
+ if (!(apiCalls < MAX_API_CALLS)) return [3 /*break*/, 9];
1223
+ // Counting this whole area as a single call because it has a single purpose.
1224
+ apiCalls += 1;
1225
+ _o.label = 1;
1226
+ case 1:
1227
+ _o.trys.push([1, 3, , 4]);
1228
+ return [4 /*yield*/, Entity$1.Get({
1229
+ api: api,
1230
+ entityId: entityId,
1231
+ expandLocation: false
1232
+ })];
1233
+ case 2:
1234
+ entity = (_o.sent()).entity;
1235
+ lat = +((_a = entity === null || entity === void 0 ? void 0 : entity.location) === null || _a === void 0 ? void 0 : _a.latitude);
1236
+ lon = +((_b = entity === null || entity === void 0 ? void 0 : entity.location) === null || _b === void 0 ? void 0 : _b.longitude);
1237
+ return [3 /*break*/, 4];
1238
+ case 3:
1239
+ e_1 = _o.sent();
1240
+ console.error(e_1);
1241
+ return [3 /*break*/, 4];
1242
+ case 4:
1243
+ if (!(entity && (isNaN(lat) || isNaN(lon) || (lat == 0 && lon == 0)))) return [3 /*break*/, 9];
1244
+ _o.label = 5;
1245
+ case 5:
1246
+ _o.trys.push([5, 7, , 9]);
1247
+ return [4 /*yield*/, Entity$1.Get({
1248
+ api: api,
1249
+ entityId: entityId,
1250
+ expandLocation: true
1251
+ })];
1252
+ case 6:
1253
+ entity = (_o.sent()).entity;
1254
+ return [3 /*break*/, 9];
1255
+ case 7:
1256
+ e_2 = _o.sent();
1257
+ console.warn(e_2);
1258
+ return [4 /*yield*/, Entity$1.Get({
1259
+ api: api,
1260
+ entityId: entityId,
1261
+ expandLocation: false
1262
+ })];
1263
+ case 8:
1264
+ entity = (_o.sent()).entity;
1265
+ return [3 /*break*/, 9];
1266
+ case 9:
1267
+ if (!entity) {
1268
+ return [2 /*return*/, []];
1269
+ }
1270
+ if (!tilesetId) {
1271
+ tilesetId = ((_c = entity.tilesetID) === null || _c === void 0 ? void 0 : _c.length) ? entity.tilesetID[0] : tilesetId;
1272
+ }
1273
+ evaluateRendered = function () { return __awaiter(_this, void 0, void 0, function () {
1274
+ var rego, posses, visual, visualHeightRef, hierarchy, hPosses, hPossesSample, step, i, pPosses, pPossesSample, step, i, pPosses, pPossesSample, step, i, pos3d_1;
1275
+ return __generator(this, function (_a) {
1276
+ switch (_a.label) {
1277
+ case 0:
1278
+ rego = visualRegister ? visualRegister.GetRego({
1279
+ entityId: entity.Bruce.ID,
1280
+ }) : null;
1281
+ posses = [];
1282
+ if (!((rego === null || rego === void 0 ? void 0 : rego.visual) instanceof Entity)) return [3 /*break*/, 14];
1283
+ visual = rego.visual;
1284
+ visualHeightRef = HeightReference.RELATIVE_TO_GROUND;
1285
+ if (!visual.model) return [3 /*break*/, 1];
1286
+ visualHeightRef = GetValue(viewer, visual.model.heightReference);
1287
+ return [3 /*break*/, 12];
1288
+ case 1:
1289
+ if (!visual.polygon) return [3 /*break*/, 4];
1290
+ visualHeightRef = GetValue(viewer, visual.polygon.heightReference);
1291
+ hierarchy = GetValue(viewer, visual.polygon.hierarchy);
1292
+ if (!(hierarchy === null || hierarchy === void 0 ? void 0 : hierarchy.positions)) return [3 /*break*/, 3];
1293
+ hPosses = hierarchy.positions.map(function (x) { return x.clone ? x.clone() : x; });
1294
+ hPossesSample = [];
1295
+ step = Math.floor(hPosses.length / 5);
1296
+ for (i = 0; i < hPosses.length; i += step) {
1297
+ hPossesSample.push(hPosses[i]);
1298
+ }
1299
+ return [4 /*yield*/, ensureHeightRefs(hPossesSample, __assign(__assign({}, sample), { heightRef: visualHeightRef }))];
1300
+ case 2:
1301
+ _a.sent();
1302
+ posses = posses.concat(hPossesSample);
1303
+ _a.label = 3;
1304
+ case 3: return [3 /*break*/, 12];
1305
+ case 4:
1306
+ if (!visual.polyline) return [3 /*break*/, 7];
1307
+ visualHeightRef = GetValue(viewer, visual.polyline.clampToGround) ?
1308
+ HeightReference.CLAMP_TO_GROUND : HeightReference.NONE;
1309
+ pPosses = GetValue(viewer, visual.polyline.positions);
1310
+ if (!(pPosses === null || pPosses === void 0 ? void 0 : pPosses.length)) return [3 /*break*/, 6];
1311
+ // Grab 5 positions from the polyline at varied indexes.
1312
+ pPosses = pPosses.map(function (x) { return x.clone ? x.clone() : x; });
1313
+ pPossesSample = [];
1314
+ step = Math.floor(pPosses.length / 5);
1315
+ for (i = 0; i < pPosses.length; i += step) {
1316
+ pPossesSample.push(pPosses[i]);
1317
+ }
1318
+ return [4 /*yield*/, ensureHeightRefs(pPossesSample, __assign(__assign({}, sample), { heightRef: visualHeightRef }))];
1319
+ case 5:
1320
+ _a.sent();
1321
+ posses = posses.concat(pPossesSample);
1322
+ _a.label = 6;
1323
+ case 6: return [3 /*break*/, 12];
1324
+ case 7:
1325
+ if (!visual.billboard) return [3 /*break*/, 8];
1326
+ visualHeightRef = GetValue(viewer, visual.billboard.heightReference);
1327
+ return [3 /*break*/, 12];
1328
+ case 8:
1329
+ if (!visual.corridor) return [3 /*break*/, 11];
1330
+ visualHeightRef = GetValue(viewer, visual.corridor.heightReference);
1331
+ pPosses = GetValue(viewer, visual.corridor.positions);
1332
+ if (!(pPosses === null || pPosses === void 0 ? void 0 : pPosses.length)) return [3 /*break*/, 10];
1333
+ // Grab 5 positions from the corridor at varied indexes.
1334
+ pPosses = pPosses.map(function (x) { return x.clone ? x.clone() : x; });
1335
+ pPossesSample = [];
1336
+ step = Math.floor(pPosses.length / 5);
1337
+ for (i = 0; i < pPosses.length; i += step) {
1338
+ pPossesSample.push(pPosses[i]);
1339
+ }
1340
+ return [4 /*yield*/, ensureHeightRefs(pPossesSample, __assign(__assign({}, sample), { heightRef: visualHeightRef }))];
1341
+ case 9:
1342
+ _a.sent();
1343
+ posses = posses.concat(pPossesSample);
1344
+ _a.label = 10;
1345
+ case 10: return [3 /*break*/, 12];
1346
+ case 11:
1347
+ if (visual.ellipse) {
1348
+ visualHeightRef = GetValue(viewer, visual.ellipse.heightReference);
1349
+ }
1350
+ else if (visual.point) {
1351
+ visualHeightRef = GetValue(viewer, visual.point.heightReference);
1352
+ }
1353
+ _a.label = 12;
1354
+ case 12:
1355
+ pos3d_1 = GetValue(viewer, visual.position);
1356
+ if (!(pos3d_1 === null || pos3d_1 === void 0 ? void 0 : pos3d_1.x)) return [3 /*break*/, 14];
1357
+ pos3d_1 = DrawingUtils.EnsurePosHeight({
1358
+ desiredHeightRef: sample.returnHeightRef,
1359
+ heightRef: visualHeightRef,
1360
+ pos3d: pos3d_1,
1361
+ viewer: viewer
1362
+ });
1363
+ return [4 /*yield*/, processPosHeight(pos3d_1, sample.returnHeightRef)];
1364
+ case 13:
1365
+ pos3d_1 = _a.sent();
1366
+ posses.push(pos3d_1);
1367
+ _a.label = 14;
1368
+ case 14: return [2 /*return*/, posses];
1369
+ }
1370
+ });
1371
+ }); };
1372
+ evaluateRecord = function () { return __awaiter(_this, void 0, void 0, function () {
1373
+ var posses, location_1, latitude, longitude, pos3d_2, pointStr, points, point, pos3d_3, lineStr, points, pPosses, pRings, boundary, points, pPosses, point, bPosses;
1374
+ return __generator(this, function (_a) {
1375
+ switch (_a.label) {
1376
+ case 0:
1377
+ posses = [];
1378
+ if (entity.location && Carto.ValidateCarto(entity.location)) {
1379
+ location_1 = entity.location;
1380
+ latitude = EnsureNumber(location_1.latitude);
1381
+ longitude = EnsureNumber(location_1.longitude);
1382
+ // Disallowing exact 0.
1383
+ if (latitude || longitude) {
1384
+ pos3d_2 = Cartesian3.fromDegrees(longitude, latitude, EnsureNumber(location_1.altitude));
1385
+ posses.push(pos3d_2);
1386
+ }
1387
+ }
1388
+ if (!(entity.geometry && typeof entity.geometry == "object")) return [3 /*break*/, 4];
1389
+ pointStr = entity.geometry.Point;
1390
+ if (pointStr && typeof pointStr == "string") {
1391
+ points = Geometry.ParsePoints(pointStr);
1392
+ point = points.length > 0 ? points[0] : null;
1393
+ if (point && Carto.ValidateCarto(point)) {
1394
+ pos3d_3 = Cartesian3.fromDegrees(EnsureNumber(point.longitude), EnsureNumber(point.latitude), EnsureNumber(point.altitude));
1395
+ posses.push(pos3d_3);
1396
+ }
1397
+ }
1398
+ lineStr = entity.geometry.LineString;
1399
+ if (!(lineStr && typeof lineStr == "string")) return [3 /*break*/, 2];
1400
+ points = Geometry.ParsePoints(lineStr);
1401
+ if (!(points.length > 0)) return [3 /*break*/, 2];
1402
+ pPosses = points.map(function (x) { return Cartesian3.fromDegrees(EnsureNumber(x.longitude), EnsureNumber(x.latitude), EnsureNumber(x.altitude)); });
1403
+ return [4 /*yield*/, ensureHeightRefs(pPosses, sample)];
1404
+ case 1:
1405
+ _a.sent();
1406
+ posses = posses.concat(pPosses);
1407
+ _a.label = 2;
1408
+ case 2:
1409
+ pRings = entity.geometry.Polygon;
1410
+ if (!(pRings && typeof pRings == "object")) return [3 /*break*/, 4];
1411
+ boundary = pRings.find(function (x) { return x.Facing == Geometry.EPolygonRingType.Boundaries; });
1412
+ if (!(boundary === null || boundary === void 0 ? void 0 : boundary.LinearRing)) return [3 /*break*/, 4];
1413
+ points = Geometry.ParsePoints(boundary.LinearRing);
1414
+ pPosses = points.map(function (x) { return Cartesian3.fromDegrees(EnsureNumber(x.longitude), EnsureNumber(x.latitude), EnsureNumber(x.altitude)); });
1415
+ return [4 /*yield*/, ensureHeightRefs(pPosses, sample)];
1416
+ case 3:
1417
+ _a.sent();
1418
+ posses = posses.concat(pPosses);
1419
+ _a.label = 4;
1420
+ case 4:
1421
+ if (!entity.boundaries) return [3 /*break*/, 6];
1422
+ point = {
1423
+ latitude: (EnsureNumber(entity.boundaries.minLatitude) + EnsureNumber(entity.boundaries.maxLatitude)) / 2,
1424
+ longitude: (EnsureNumber(entity.boundaries.minLongitude) + EnsureNumber(entity.boundaries.maxLongitude)) / 2,
1425
+ altitude: 0
1426
+ };
1427
+ if (!(point.latitude || point.longitude)) return [3 /*break*/, 6];
1428
+ bPosses = [
1429
+ Cartesian3.fromDegrees(EnsureNumber(entity.boundaries.minLongitude), EnsureNumber(entity.boundaries.minLatitude), EnsureNumber(entity.boundaries.minAltitude)),
1430
+ Cartesian3.fromDegrees(EnsureNumber(entity.boundaries.maxLongitude), EnsureNumber(entity.boundaries.maxLatitude), EnsureNumber(entity.boundaries.maxAltitude))
1431
+ ];
1432
+ return [4 /*yield*/, ensureHeightRefs(bPosses, sample)];
1433
+ case 5:
1434
+ _a.sent();
1435
+ posses = posses.concat(bPosses);
1436
+ _a.label = 6;
1437
+ case 6: return [2 /*return*/, posses];
1438
+ }
1439
+ });
1440
+ }); };
1441
+ return [4 /*yield*/, evaluateRendered()];
1442
+ case 10:
1443
+ renderedPosses = _o.sent();
1444
+ if (renderedPosses === null || renderedPosses === void 0 ? void 0 : renderedPosses.length) {
1445
+ return [2 /*return*/, renderedPosses];
1446
+ }
1447
+ return [4 /*yield*/, evaluateRecord()];
1448
+ case 11:
1449
+ recordPosses = _o.sent();
1450
+ if (recordPosses === null || recordPosses === void 0 ? void 0 : recordPosses.length) {
1451
+ return [2 /*return*/, recordPosses];
1452
+ }
1453
+ if (!!tileset) return [3 /*break*/, 13];
1454
+ if (!(tilesetId && apiCalls < MAX_API_CALLS)) return [3 /*break*/, 13];
1455
+ apiCalls += 1;
1456
+ return [4 /*yield*/, Tileset.Get({
1457
+ api: api,
1458
+ tilesetId: tilesetId
1459
+ })];
1460
+ case 12:
1461
+ tileset = (_o.sent()).tileset;
1462
+ _o.label = 13;
1463
+ case 13:
1464
+ tSettings = tileset === null || tileset === void 0 ? void 0 : tileset.settings;
1465
+ pos3d = null;
1466
+ 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];
1467
+ if ((_f = entity === null || entity === void 0 ? void 0 : entity.location) === null || _f === void 0 ? void 0 : _f.longitude) {
1468
+ alt = +entity.location.altitude;
1469
+ if (isNaN(alt)) {
1470
+ alt = 0;
1471
+ }
1472
+ pos3d = Cartesian3.fromDegrees(+entity.location.longitude, +entity.location.latitude, alt);
1473
+ }
1474
+ else {
1475
+ alt = +tSettings.location.altitude;
1476
+ if (isNaN(alt)) {
1477
+ alt = 0;
1478
+ }
1479
+ pos3d = Cartesian3.fromDegrees(+tSettings.location.longitude, +tSettings.location.latitude, alt);
1480
+ }
1481
+ if (!(entity === null || entity === void 0 ? void 0 : entity.worldPosition)) return [3 /*break*/, 15];
1482
+ heading = 0;
1483
+ pitch = 0;
1484
+ roll = 0;
1485
+ if ((_g = entity === null || entity === void 0 ? void 0 : entity.transform) === null || _g === void 0 ? void 0 : _g.heading) {
1486
+ heading = entity.transform.heading;
1487
+ }
1488
+ else if ((_h = tSettings === null || tSettings === void 0 ? void 0 : tSettings.transform) === null || _h === void 0 ? void 0 : _h.heading) {
1489
+ heading = tSettings.transform.heading;
1490
+ }
1491
+ if ((_j = entity === null || entity === void 0 ? void 0 : entity.transform) === null || _j === void 0 ? void 0 : _j.pitch) {
1492
+ pitch = entity.transform.pitch;
1493
+ }
1494
+ else if ((_k = tSettings === null || tSettings === void 0 ? void 0 : tSettings.transform) === null || _k === void 0 ? void 0 : _k.pitch) {
1495
+ pitch = tSettings.transform.pitch;
1496
+ }
1497
+ if ((_l = entity === null || entity === void 0 ? void 0 : entity.transform) === null || _l === void 0 ? void 0 : _l.roll) {
1498
+ roll = entity.transform.roll;
1499
+ }
1500
+ else if ((_m = tSettings === null || tSettings === void 0 ? void 0 : tSettings.transform) === null || _m === void 0 ? void 0 : _m.roll) {
1501
+ roll = tSettings.transform.roll;
1502
+ }
1503
+ heading = +heading;
1504
+ if (isNaN(heading)) {
1505
+ heading = 0;
1506
+ }
1507
+ pitch = +pitch;
1508
+ if (isNaN(pitch)) {
1509
+ pitch = 0;
1510
+ }
1511
+ roll = +roll;
1512
+ if (isNaN(roll)) {
1513
+ roll = 0;
1514
+ }
1515
+ matrix4 = entity.worldPosition;
1516
+ offset = new Cartesian3(+matrix4[0][3], +matrix4[1][3], +matrix4[2][3]);
1517
+ if (entity.worldPivot) //the position from worldMatrix + center of geometry offset
1518
+ {
1519
+ offset = new Cartesian3(entity.worldPivot[0], entity.worldPivot[1], entity.worldPivot[2]);
1520
+ }
1521
+ m1 = Transforms.eastNorthUpToFixedFrame(pos3d);
1522
+ hpr = HeadingPitchRoll.fromDegrees(heading, pitch, roll, new HeadingPitchRoll());
1523
+ transform = Matrix3.fromHeadingPitchRoll(hpr);
1524
+ transformedOffset = Matrix3.multiplyByVector(transform, offset, new Cartesian3());
1525
+ pos3d = Matrix4.multiplyByPoint(m1, transformedOffset, new Cartesian3());
1526
+ if (!(pos3d === null || pos3d === void 0 ? void 0 : pos3d.x)) return [3 /*break*/, 15];
1527
+ return [4 /*yield*/, processPosHeight(pos3d, HeightReference.NONE)];
1528
+ case 14:
1529
+ pos3d = _o.sent();
1530
+ _o.label = 15;
1531
+ case 15:
1532
+ if (pos3d) {
1533
+ return [2 /*return*/, [pos3d]];
1534
+ }
1535
+ return [2 /*return*/, []];
1536
+ }
1537
+ });
1538
+ }); };
1539
+ allPosses = [];
1540
+ i = 0;
1541
+ _b.label = 1;
1542
+ case 1:
1543
+ if (!(i < samples.length)) return [3 /*break*/, 4];
1544
+ sample = samples[i];
1545
+ return [4 /*yield*/, getEntityPositions(sample)];
1546
+ case 2:
1547
+ samplePosses = _b.sent();
1548
+ if (samplePosses === null || samplePosses === void 0 ? void 0 : samplePosses.length) {
1549
+ valid = !(allPosses === null || allPosses === void 0 ? void 0 : allPosses.length);
1550
+ if (!valid) {
1551
+ for (j = 0; j < samplePosses.length; j++) {
1552
+ samplePos = samplePosses[j];
1553
+ for (k = 0; k < allPosses.length; k++) {
1554
+ allPos = allPosses[k];
1555
+ distance = Cartesian3.distance(samplePos, allPos);
1556
+ if (distance < MAX_DISTANCE_BETWEEN_SAMPLES) {
1557
+ valid = true;
1558
+ break;
1559
+ }
1560
+ }
1561
+ if (valid) {
1562
+ break;
1563
+ }
1564
+ }
1565
+ }
1566
+ if (valid) {
1567
+ allPosses = allPosses.concat(samplePosses);
1568
+ validSamples += 1;
1569
+ if (validSamples >= MAX_VALID_SAMPLES) {
1570
+ return [3 /*break*/, 4];
1571
+ }
1572
+ }
1573
+ }
1574
+ _b.label = 3;
1575
+ case 3:
1576
+ i++;
1577
+ return [3 /*break*/, 1];
1578
+ case 4:
1579
+ if (allPosses.length > 1) {
1580
+ rect = allPosses.length == 1 ? null : Rectangle.fromCartesianArray(allPosses);
1581
+ factor = 0.1;
1582
+ marginX = rect.width * factor / 2;
1583
+ marginY = rect.height * factor / 2;
1584
+ rect.east += marginX;
1585
+ rect.west -= marginX;
1586
+ rect.north += marginY;
1587
+ rect.south -= marginY;
1588
+ diagonalLen = Cartesian3.distance(Cartesian3.fromRadians(rect.west, rect.north), Cartesian3.fromRadians(rect.east, rect.south));
1589
+ terrData = ViewUtils.GatherTerrainTile({
1590
+ viewer: viewer
1591
+ });
1592
+ if (((_a = terrData === null || terrData === void 0 ? void 0 : terrData.terrain) === null || _a === void 0 ? void 0 : _a.tilesetId) == ProjectViewTile.EDefaultTerrain.FlatTerrain) {
1593
+ MIN_RECT_DIAGONAL_LENGTH = 0;
1594
+ }
1595
+ posCarto = Cartographic.fromCartesian(allPosses[0]);
1596
+ height = posCarto.height + (diagonalLen * 1.5);
1597
+ data.pos3d = Cartesian3.fromRadians(posCarto.longitude, posCarto.latitude, height);
1598
+ MIN_POSSES_LEN = 10;
1599
+ if (diagonalLen >= MIN_RECT_DIAGONAL_LENGTH && allPosses.length >= MIN_POSSES_LEN) {
1600
+ data.rectangle = rect;
1601
+ }
1602
+ }
1603
+ else if (allPosses.length == 1) {
1604
+ data.pos3d = allPosses[0];
1605
+ }
1606
+ return [2 /*return*/, data];
1607
+ }
1608
+ });
1609
+ });
1610
+ }
1611
+ EntityUtils.GetLocation = GetLocation;
894
1612
  /**
895
1613
  * Returns an entity's position.
896
1614
  * This will attempt to calculate it from multiple sources of data.
897
1615
  * @param params
1616
+ * @deprecated use GetLocation instead.
898
1617
  * @returns
899
1618
  */
900
1619
  function GetPos(params) {
@@ -906,9 +1625,9 @@ var EntityUtils;
906
1625
  if ((rego === null || rego === void 0 ? void 0 : rego.visual) instanceof Entity) {
907
1626
  var visual = rego.visual;
908
1627
  if (visual.position) {
909
- var pos3d_1 = GetValue(viewer, visual.position);
1628
+ var pos3d_4 = GetValue(viewer, visual.position);
910
1629
  // Fix height reference.
911
- if (pos3d_1 === null || pos3d_1 === void 0 ? void 0 : pos3d_1.x) {
1630
+ if (pos3d_4 === null || pos3d_4 === void 0 ? void 0 : pos3d_4.x) {
912
1631
  var visualHeightRef = HeightReference.RELATIVE_TO_GROUND;
913
1632
  if (visual.model) {
914
1633
  visualHeightRef = GetValue(viewer, visual.model.heightReference);
@@ -935,7 +1654,7 @@ var EntityUtils;
935
1654
  return DrawingUtils.EnsurePosHeight({
936
1655
  desiredHeightRef: params.returnHeightRef,
937
1656
  heightRef: visualHeightRef,
938
- pos3d: pos3d_1,
1657
+ pos3d: pos3d_4,
939
1658
  viewer: viewer
940
1659
  });
941
1660
  }
@@ -945,12 +1664,12 @@ var EntityUtils;
945
1664
  }
946
1665
  function evaluateRecord() {
947
1666
  if (entity.location && Carto.ValidateCarto(entity.location)) {
948
- var location_1 = entity.location;
949
- var latitude = EnsureNumber(location_1.latitude);
950
- var longitude = EnsureNumber(location_1.longitude);
1667
+ var location_2 = entity.location;
1668
+ var latitude = EnsureNumber(location_2.latitude);
1669
+ var longitude = EnsureNumber(location_2.longitude);
951
1670
  // Disallowing exact 0.
952
1671
  if (latitude || longitude) {
953
- return Cartesian3.fromDegrees(longitude, latitude, EnsureNumber(location_1.altitude));
1672
+ return Cartesian3.fromDegrees(longitude, latitude, EnsureNumber(location_2.altitude));
954
1673
  }
955
1674
  }
956
1675
  if (entity.geometry && typeof entity.geometry == "object") {
@@ -1028,12 +1747,13 @@ var EntityUtils;
1028
1747
  * Returns the position of the entity.
1029
1748
  * This is an async variant that checks for related tilesets.
1030
1749
  * @param params
1750
+ * @deprecated use GetLocation instead.
1031
1751
  * @returns
1032
1752
  */
1033
1753
  function GetPosAsync(params) {
1034
1754
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1035
1755
  return __awaiter(this, void 0, void 0, function () {
1036
- 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;
1756
+ 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;
1037
1757
  return __generator(this, function (_o) {
1038
1758
  switch (_o.label) {
1039
1759
  case 0:
@@ -1055,8 +1775,8 @@ var EntityUtils;
1055
1775
  lon = +((_b = entity === null || entity === void 0 ? void 0 : entity.location) === null || _b === void 0 ? void 0 : _b.longitude);
1056
1776
  return [3 /*break*/, 4];
1057
1777
  case 3:
1058
- e_1 = _o.sent();
1059
- console.error(e_1);
1778
+ e_3 = _o.sent();
1779
+ console.error(e_3);
1060
1780
  return [3 /*break*/, 4];
1061
1781
  case 4:
1062
1782
  if (!(entity && (isNaN(lat) || isNaN(lon) || (lat == 0 && lon == 0)))) return [3 /*break*/, 9];
@@ -1072,8 +1792,8 @@ var EntityUtils;
1072
1792
  entity = (_o.sent()).entity;
1073
1793
  return [3 /*break*/, 9];
1074
1794
  case 7:
1075
- e_2 = _o.sent();
1076
- console.warn(e_2);
1795
+ e_4 = _o.sent();
1796
+ console.warn(e_4);
1077
1797
  return [4 /*yield*/, Entity$1.Get({
1078
1798
  api: api,
1079
1799
  entityId: entityId,
@@ -1205,90 +1925,107 @@ var EntityUtils;
1205
1925
  * @param entities
1206
1926
  */
1207
1927
  function LookAtEntities(params) {
1208
- var viewer = params.viewer, entities = params.entities;
1209
- // Removing cesium tileset features for now as it's not accurate.
1210
- entities = [].concat(entities).filter(function (x) { return !(x instanceof Cesium3DTileFeature); });
1211
- if (!entities.length) {
1212
- return;
1213
- }
1214
- var _a = [Rectangle, Cartographic, Cartesian3, Matrix3, Matrix4, EasingFunction], C3 = _a[2], M4 = _a[4];
1215
- var cutoffDistance = 2000;
1216
- var hoverHeight = 2000;
1217
- var duration = 0.5;
1218
- var centers = function (p) {
1219
- var PM = p.modelMatrix;
1220
- var instances = (function (i) { return (i instanceof GeometryInstance ? [i] : i); })(p.geometryInstances);
1221
- return instances.map(function (g) {
1222
- var _M = M4.multiply(PM, g.modelMatrix, new M4);
1223
- var G = g.geometry;
1224
- var _p = G.attributes.position;
1225
- var b = G.boundingSphere;
1226
- return [b.center, b.radius];
1227
- });
1228
- };
1229
- var currentTime = JulianDate.now();
1230
- var target = entities.flatMap(function (e) {
1231
- var _a;
1232
- if (e instanceof Cartesian3) {
1233
- return [[e, 0]];
1234
- }
1235
- if (e instanceof Entity) {
1236
- return [[(_a = e.position) === null || _a === void 0 ? void 0 : _a.getValue(currentTime), 0]];
1237
- }
1238
- if (e instanceof Primitive) {
1239
- return centers(e);
1240
- }
1241
- if (e instanceof Cesium3DTileFeature) {
1242
- var s = e.tileset.boundingSphere;
1243
- return [[s.center, s.radius]];
1244
- }
1245
- });
1246
- var bounds = function (list) {
1247
- var min = list[0][0];
1248
- var max = min;
1249
- for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
1250
- var _a = list_1[_i], p_1 = _a[0], r = _a[1];
1251
- var pMin = C3.subtract(p_1, new C3(r), new C3);
1252
- var pMax = C3.add(p_1, new C3(r), new C3);
1253
- min = C3.minimumByComponent(pMin, min, new C3);
1254
- max = C3.maximumByComponent(pMax, max, new C3);
1255
- }
1256
- var c = C3.multiplyByScalar(C3.add(max, min, new C3), 0.5, new C3);
1257
- return c;
1258
- };
1259
- var center = bounds(target);
1260
- var orient = function (p) {
1261
- var d = C3.subtract(center, p, new C3);
1262
- var dir = C3.normalize(d, new C3);
1263
- var up = viewer.scene.globe.ellipsoid.geodeticSurfaceNormal(center);
1264
- return [p, dir, up];
1265
- };
1266
- var shorten = function (v, l) {
1267
- var c = l / C3.magnitude(v);
1268
- return C3.multiplyByScalar(v, c, new C3);
1269
- };
1270
- var camera = viewer.camera;
1271
- var _b = orient(camera.position), p = _b[0], direction = _b[1], up = _b[2];
1272
- var orientation = { direction: direction, up: up };
1273
- camera.flyTo({
1274
- destination: p,
1275
- orientation: orientation,
1276
- duration: duration,
1277
- complete: function () {
1278
- if (C3.distance(p, center) > cutoffDistance) {
1279
- var d = C3.subtract(p, center, new C3);
1280
- d = shorten(d, cutoffDistance);
1281
- var h = C3.multiplyByScalar(C3.normalize(up, new C3), hoverHeight, new C3);
1282
- d = C3.add(d, h, new C3);
1283
- d = shorten(d, cutoffDistance);
1284
- d = C3.add(d, center, new C3);
1285
- var _a = orient(d), direction_1 = _a[1], u = _a[2];
1286
- camera.flyTo({
1287
- destination: d,
1288
- orientation: { direction: direction_1, up: u }
1289
- });
1928
+ return __awaiter(this, void 0, void 0, function () {
1929
+ 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;
1930
+ return __generator(this, function (_c) {
1931
+ switch (_c.label) {
1932
+ case 0:
1933
+ viewer = params.viewer, entities = params.entities;
1934
+ // Removing cesium tileset features for now as it's not accurate.
1935
+ entities = [].concat(entities).filter(function (x) { return !(x instanceof Cesium3DTileFeature); });
1936
+ if (!entities.length) {
1937
+ return [2 /*return*/];
1938
+ }
1939
+ _a = [Rectangle, Cartographic, Cartesian3, Matrix3, Matrix4, EasingFunction], R = _a[0], CT = _a[1], C3 = _a[2], M3 = _a[3], M4 = _a[4], E = _a[5];
1940
+ duration = 0.5;
1941
+ centers = function (p) {
1942
+ var PM = p.modelMatrix;
1943
+ var instances = (function (i) { return (i instanceof GeometryInstance ? [i] : i); })(p.geometryInstances);
1944
+ return instances.map(function (g) {
1945
+ var _M = M4.multiply(PM, g.modelMatrix, new M4);
1946
+ var G = g.geometry;
1947
+ var _p = G.attributes.position;
1948
+ var b = G.boundingSphere;
1949
+ return [b.center, b.radius];
1950
+ });
1951
+ };
1952
+ currentTime = JulianDate.now();
1953
+ target = entities.flatMap(function (e) {
1954
+ var _a;
1955
+ if (e instanceof Cartesian3) {
1956
+ return [[e, 0]];
1957
+ }
1958
+ if (e instanceof Entity) {
1959
+ return [[(_a = e.position) === null || _a === void 0 ? void 0 : _a.getValue(currentTime), 0]];
1960
+ }
1961
+ if (e instanceof Primitive) {
1962
+ return centers(e);
1963
+ }
1964
+ if (e instanceof Cesium3DTileFeature) {
1965
+ var s = e.tileset.boundingSphere;
1966
+ return [[s.center, s.radius]];
1967
+ }
1968
+ });
1969
+ bounds = function (list) {
1970
+ var min = list[0][0];
1971
+ var max = min;
1972
+ for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
1973
+ var _a = list_1[_i], p_1 = _a[0], r = _a[1];
1974
+ var pMin = C3.subtract(p_1, new C3(r), new C3);
1975
+ var pMax = C3.add(p_1, new C3(r), new C3);
1976
+ min = C3.minimumByComponent(pMin, min, new C3);
1977
+ max = C3.maximumByComponent(pMax, max, new C3);
1978
+ }
1979
+ var c = C3.multiplyByScalar(C3.add(max, min, new C3), 0.5, new C3);
1980
+ return c;
1981
+ };
1982
+ center = bounds(target);
1983
+ orient = function (p) {
1984
+ var d = C3.subtract(center, p, new C3);
1985
+ var dir = C3.normalize(d, new C3);
1986
+ var up = viewer.scene.globe.ellipsoid.geodeticSurfaceNormal(center);
1987
+ return [p, dir, up];
1988
+ };
1989
+ camera = viewer.camera;
1990
+ _b = orient(camera.position), p = _b[0], direction = _b[1], up = _b[2];
1991
+ orientation = { direction: direction, up: up };
1992
+ if (!(p === null || p === void 0 ? void 0 : p.x)) return [3 /*break*/, 2];
1993
+ return [4 /*yield*/, DrawingUtils.GetTerrainHeight({
1994
+ pos3d: p,
1995
+ viewer: viewer
1996
+ })];
1997
+ case 1:
1998
+ terrData = _c.sent();
1999
+ MIN_HEIGHT = terrData.height + 300;
2000
+ carto = Cartographic.fromCartesian(p);
2001
+ if (carto.height < MIN_HEIGHT) {
2002
+ carto.height = MIN_HEIGHT;
2003
+ p = Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height);
2004
+ }
2005
+ camera.flyTo({
2006
+ destination: p,
2007
+ orientation: orientation,
2008
+ duration: duration,
2009
+ complete: function () {
2010
+ // if (C3.distance(p, center) > cutoffDistance) {
2011
+ // let d = C3.subtract(p, center, new C3);
2012
+ // d = shorten(d, cutoffDistance);
2013
+ // const h = C3.multiplyByScalar(C3.normalize(up, new C3), hoverHeight, new C3);
2014
+ // d = C3.add(d, h, new C3);
2015
+ // d = shorten(d, cutoffDistance);
2016
+ // d = C3.add(d, center, new C3);
2017
+ // const [ _p, direction, u ] = orient(d);
2018
+ // camera.flyTo({
2019
+ // destination: d,
2020
+ // orientation: { direction, up: u }
2021
+ // });
2022
+ // }
2023
+ }
2024
+ });
2025
+ _c.label = 2;
2026
+ case 2: return [2 /*return*/];
1290
2027
  }
1291
- }
2028
+ });
1292
2029
  });
1293
2030
  }
1294
2031
  EntityUtils.LookAtEntities = LookAtEntities;
@@ -12779,213 +13516,6 @@ var TileRenderEngine;
12779
13516
  })(Terrain = TileRenderEngine.Terrain || (TileRenderEngine.Terrain = {}));
12780
13517
  })(TileRenderEngine || (TileRenderEngine = {}));
12781
13518
 
12782
- var CESIUM_INSPECTOR_KEY = "_nextspace_inspector";
12783
- var ViewUtils;
12784
- (function (ViewUtils) {
12785
- function GatherLegacyMapTiles(params) {
12786
- var viewer = params.viewer;
12787
- var collection = viewer.imageryLayers;
12788
- var tiles = [];
12789
- for (var i = 0; i < collection.length; i++) {
12790
- var layer = collection.get(i);
12791
- if (layer._bName) {
12792
- tiles.push({
12793
- alpha: layer.alpha,
12794
- brightness: layer.brightness,
12795
- contrast: layer.contrast,
12796
- hue: layer.hue,
12797
- saturation: layer.saturation,
12798
- gamma: layer.gamma,
12799
- title: layer._bName,
12800
- });
12801
- }
12802
- }
12803
- return {
12804
- imagery: tiles.reverse()
12805
- };
12806
- }
12807
- ViewUtils.GatherLegacyMapTiles = GatherLegacyMapTiles;
12808
- function GatherLegacyTerrainTile(params) {
12809
- var viewer = params.viewer;
12810
- var enabled = viewer.terrainProvider;
12811
- if (enabled === null || enabled === void 0 ? void 0 : enabled._bName) {
12812
- return {
12813
- terrain: enabled._bName
12814
- };
12815
- }
12816
- return {
12817
- terrain: "flatterrain"
12818
- };
12819
- }
12820
- ViewUtils.GatherLegacyTerrainTile = GatherLegacyTerrainTile;
12821
- function GatherMapTiles(params) {
12822
- var viewer = params.viewer;
12823
- var imagery = viewer.imageryLayers;
12824
- var tiles = [];
12825
- var _loop_1 = function (i) {
12826
- var provider = imagery.get(i);
12827
- if (provider._bMeta) {
12828
- var idCombo_1 = provider._bMeta.accountId + provider._bMeta.tilesetId;
12829
- if (!tiles.find(function (x) { return x.accountId + x.tilesetId === idCombo_1; })) {
12830
- tiles.push({
12831
- accountId: provider._bMeta.accountId,
12832
- tilesetId: provider._bMeta.tilesetId,
12833
- alpha: provider.alpha,
12834
- brightness: provider.brightness,
12835
- contrast: provider.contrast,
12836
- hue: provider.hue,
12837
- saturation: provider.saturation,
12838
- gamma: provider.gamma
12839
- });
12840
- }
12841
- }
12842
- };
12843
- for (var i = 0; i < imagery.length; i++) {
12844
- _loop_1(i);
12845
- }
12846
- return {
12847
- imagery: tiles
12848
- };
12849
- }
12850
- ViewUtils.GatherMapTiles = GatherMapTiles;
12851
- function GatherTerrainTile(params) {
12852
- var viewer = params.viewer;
12853
- var provider = viewer.terrainProvider;
12854
- if (provider._bMeta) {
12855
- return {
12856
- terrain: {
12857
- accountId: provider._bMeta.accountId,
12858
- tilesetId: provider._bMeta.tilesetId,
12859
- }
12860
- };
12861
- }
12862
- else if (provider instanceof EllipsoidTerrainProvider) {
12863
- return {
12864
- terrain: {
12865
- tilesetId: ProjectViewTile.EDefaultTerrain.FlatTerrain,
12866
- accountId: null
12867
- }
12868
- };
12869
- }
12870
- return null;
12871
- }
12872
- ViewUtils.GatherTerrainTile = GatherTerrainTile;
12873
- function SetTerrainWireframeStatus(params) {
12874
- if (!params.viewer[CESIUM_INSPECTOR_KEY]) {
12875
- var InspectorClass = CesiumInspector;
12876
- if (InspectorClass) {
12877
- var inspector = new InspectorClass(document.createElement("div"), params.viewer.scene);
12878
- inspector.container.style.display = "none";
12879
- params.viewer[CESIUM_INSPECTOR_KEY] = inspector;
12880
- params.viewer.scene.requestRender();
12881
- }
12882
- }
12883
- if (params.viewer[CESIUM_INSPECTOR_KEY]) {
12884
- params.viewer[CESIUM_INSPECTOR_KEY].viewModel.wireframe = params.status;
12885
- }
12886
- }
12887
- ViewUtils.SetTerrainWireframeStatus = SetTerrainWireframeStatus;
12888
- function GetTerrainWireframeStatus(params) {
12889
- var _a, _b;
12890
- if (!params.viewer[CESIUM_INSPECTOR_KEY]) {
12891
- return false;
12892
- }
12893
- return (_b = (_a = params.viewer[CESIUM_INSPECTOR_KEY]) === null || _a === void 0 ? void 0 : _a.viewModel) === null || _b === void 0 ? void 0 : _b.wireframe;
12894
- }
12895
- ViewUtils.GetTerrainWireframeStatus = GetTerrainWireframeStatus;
12896
- /**
12897
- * Changes between perspective and orthographic view.
12898
- * When Cesium stops being bad at picking positions in 2d mode we'll use the flat earth mode instead.
12899
- * @param params
12900
- */
12901
- function Set2dStatus(params) {
12902
- var viewer = params.viewer, is2d = params.status, moveCamera = params.moveCamera;
12903
- var curLens2d = viewer.camera.frustum instanceof OrthographicFrustum;
12904
- if (curLens2d && !is2d) {
12905
- viewer.camera.switchToPerspectiveFrustum();
12906
- viewer.scene.screenSpaceCameraController.enableTilt = true;
12907
- viewer.scene.requestRender();
12908
- }
12909
- else if (!curLens2d && is2d) {
12910
- viewer.camera.switchToOrthographicFrustum();
12911
- viewer.scene.screenSpaceCameraController.enableTilt = false;
12912
- if (moveCamera != false) {
12913
- try {
12914
- // Face camera downwards to make it look 2d.
12915
- // We want to try make it look at the center-point of the current view.
12916
- // If center cannot be calculated then we'll simply raise the camera and face it downwards.
12917
- var scene = viewer.scene;
12918
- var windowPosition = new Cartesian2(scene.canvas.clientWidth / 2, scene.canvas.clientHeight / 2);
12919
- var ray = viewer.camera.getPickRay(windowPosition);
12920
- var intersection = scene.globe.pick(ray, scene);
12921
- var center = void 0;
12922
- if (defined(intersection)) {
12923
- center = Cartographic.fromCartesian(intersection);
12924
- }
12925
- // Use current camera position if we can't calculate the center.
12926
- else {
12927
- center = Cartographic.fromCartesian(viewer.camera.position);
12928
- center.height = 0;
12929
- }
12930
- center.height = viewer.camera.positionCartographic.height + 100;
12931
- viewer.camera.setView({
12932
- destination: Cartographic.toCartesian(center),
12933
- orientation: {
12934
- heading: 0.0,
12935
- pitch: Math$1.toRadians(-90.0),
12936
- roll: 0.0
12937
- }
12938
- });
12939
- }
12940
- catch (e) {
12941
- console.error(e);
12942
- }
12943
- }
12944
- viewer.scene.requestRender();
12945
- }
12946
- }
12947
- ViewUtils.Set2dStatus = Set2dStatus;
12948
- function Get2dStatus(params) {
12949
- var viewer = params.viewer;
12950
- return viewer.camera.frustum instanceof OrthographicFrustum;
12951
- }
12952
- ViewUtils.Get2dStatus = Get2dStatus;
12953
- function SetLockedCameraStatus(params) {
12954
- var viewer = params.viewer, status = params.status;
12955
- var scene = viewer === null || viewer === void 0 ? void 0 : viewer.scene;
12956
- if (!scene) {
12957
- return;
12958
- }
12959
- if (status) {
12960
- scene.screenSpaceCameraController.enableInputs = false;
12961
- scene.screenSpaceCameraController.enableTranslate = false;
12962
- scene.screenSpaceCameraController.enableZoom = false;
12963
- scene.screenSpaceCameraController.enableRotate = false;
12964
- scene.screenSpaceCameraController.enableTilt = false;
12965
- }
12966
- else {
12967
- scene.screenSpaceCameraController.enableInputs = true;
12968
- scene.screenSpaceCameraController.enableTranslate = true;
12969
- scene.screenSpaceCameraController.enableZoom = true;
12970
- scene.screenSpaceCameraController.enableRotate = true;
12971
- if (!ViewUtils.Get2dStatus({ viewer: viewer })) {
12972
- scene.screenSpaceCameraController.enableTilt = true;
12973
- }
12974
- }
12975
- viewer.scene.requestRender();
12976
- }
12977
- ViewUtils.SetLockedCameraStatus = SetLockedCameraStatus;
12978
- function GetLockedCameraStatus(params) {
12979
- var _a;
12980
- var scene = (_a = params.viewer) === null || _a === void 0 ? void 0 : _a.scene;
12981
- if (!scene) {
12982
- return false;
12983
- }
12984
- return !scene.screenSpaceCameraController.enableTranslate;
12985
- }
12986
- ViewUtils.GetLockedCameraStatus = GetLockedCameraStatus;
12987
- })(ViewUtils || (ViewUtils = {}));
12988
-
12989
13519
  var VIEWER_BOOKMARKS_WIDGET_KEY = "_viewerBookmarksWidget";
12990
13520
  var WidgetBookmarks = /** @class */ (function (_super) {
12991
13521
  __extends(WidgetBookmarks, _super);
@@ -16739,7 +17269,7 @@ var ViewerUtils;
16739
17269
  ViewerUtils.CreateWidgets = CreateWidgets;
16740
17270
  })(ViewerUtils || (ViewerUtils = {}));
16741
17271
 
16742
- var VERSION$1 = "2.9.5";
17272
+ var VERSION$1 = "2.9.6";
16743
17273
 
16744
17274
  export { VERSION$1 as VERSION, CesiumViewMonitor, ViewerUtils, MenuItemManager, EntityRenderEngine, MenuItemCreator, VisualsRegister, RenderManager, EntitiesIdsRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, TilesetCadRenderManager, TilesetArbRenderManager, TilesetEntitiesRenderManager, TilesetOsmRenderManager, TilesetPointcloudRenderManager, TilesetGooglePhotosRenderManager, DataSourceStaticKmlManager, RelationsRenderManager, SharedGetters, CesiumParabola, EntityLabel, ViewRenderEngine, TileRenderEngine, TilesetRenderEngine, CESIUM_INSPECTOR_KEY, ViewUtils, DrawingUtils, MeasureUtils, EntityUtils, Draw3dPolygon, Draw3dPolyline };
16745
17275
  //# sourceMappingURL=bruce-cesium.es5.js.map