bruce-cesium 1.6.3 → 1.6.5

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,5 +1,5 @@
1
- import { BruceEvent, Cartes, Carto, Entity as Entity$1, Geometry, Tileset, ZoomControl, Style, EntityTag, Calculator, EntityLod, EntityType, ClientFile, ObjectUtils, DelayQueue, BatchedDataGetter, EntityRelationType, EntityCoords, EntityFilterGetter, EntitySource, MenuItem, EntityRelation, ProjectView, ProjectViewBookmark, ProjectViewTile, ProjectViewLegacyTile, ProgramKey, Camera } from 'bruce-models';
2
- import { Cartesian2, Cartographic, Math as Math$1, Color, HeightReference, Cartesian3, EllipsoidTerrainProvider, Entity, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, PolygonHierarchy, ShadowMode, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Primitive, Cesium3DTileFeature, SceneMode, createOsmBuildings, Cesium3DTileStyle, Rectangle, Cesium3DTileColorBlendMode, HeadingPitchRange, KmlDataSource, CallbackProperty, OrthographicFrustum, JulianDate, createWorldTerrain, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, Cesium3DTileset, Matrix4, IonResource, EllipsoidGeodesic, sampleTerrainMostDetailed, ColorMaterialProperty, Matrix3, EasingFunction, GeometryInstance, PolygonPipeline } from 'cesium';
1
+ import { BruceEvent, Cartes, Carto, Entity as Entity$1, Geometry, Tileset, MathUtils, LRUCache, ZoomControl, Style, EntityTag, Calculator, EntityLod, EntityType, ClientFile, ObjectUtils, DelayQueue, BatchedDataGetter, EntityRelationType, EntityCoords, EntityFilterGetter, EntitySource, MenuItem, EntityRelation, ProjectView, ProjectViewBookmark, ProjectViewTile, ProjectViewLegacyTile, ProgramKey, Camera } from 'bruce-models';
2
+ import { Cartesian2, Cartographic, Math as Math$1, Entity, Primitive, Cesium3DTileFeature, Color, HeightReference, Cartesian3, EllipsoidTerrainProvider, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, PolygonHierarchy, ShadowMode, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, SceneMode, HeadingPitchRange, createOsmBuildings, Cesium3DTileStyle, Rectangle, Cesium3DTileColorBlendMode, KmlDataSource, CallbackProperty, OrthographicFrustum, JulianDate, EllipsoidGeodesic, sampleTerrainMostDetailed, createWorldTerrain, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, PolygonPipeline, Cesium3DTileset, Matrix4, IonResource, ColorMaterialProperty, Matrix3, EasingFunction, GeometryInstance } from 'cesium';
3
3
 
4
4
  var TIME_LAG = 300;
5
5
  var POSITION_CHECK_TIMER = 950;
@@ -766,7 +766,12 @@ var EntityUtils;
766
766
  function evaluateRecord() {
767
767
  if (entity.location && Carto.ValidateCarto(entity.location)) {
768
768
  var location_1 = entity.location;
769
- return Cartesian3.fromDegrees(EnsureNumber(location_1.longitude), EnsureNumber(location_1.latitude), EnsureNumber(location_1.altitude));
769
+ var latitude = EnsureNumber(location_1.latitude);
770
+ var longitude = EnsureNumber(location_1.longitude);
771
+ // Disallowing exact 0.
772
+ if (latitude || longitude) {
773
+ return Cartesian3.fromDegrees(longitude, latitude, EnsureNumber(location_1.altitude));
774
+ }
770
775
  }
771
776
  if (entity.geometry && typeof entity.geometry == "object") {
772
777
  var pointStr = entity.geometry.Point;
@@ -818,8 +823,11 @@ var EntityUtils;
818
823
  longitude: (EnsureNumber(entity.boundaries.minLongitude) + EnsureNumber(entity.boundaries.maxLongitude)) / 2,
819
824
  altitude: 0
820
825
  };
821
- if (point && Carto.ValidateCarto(point)) {
822
- return Cartesian3.fromDegrees(point.longitude, point.latitude, point.altitude);
826
+ // Disallowing exact 0.
827
+ if (point.latitude || point.longitude) {
828
+ if (Carto.ValidateCarto(point)) {
829
+ return Cartesian3.fromDegrees(point.longitude, point.latitude, point.altitude);
830
+ }
823
831
  }
824
832
  }
825
833
  }
@@ -1093,6 +1101,177 @@ var EntityUtils;
1093
1101
  EntityUtils.GetOpacity = GetOpacity;
1094
1102
  })(EntityUtils || (EntityUtils = {}));
1095
1103
 
1104
+ function distanceToSegment(fromPoint, toPoint1, toPoint2) {
1105
+ var ab = Cartesian3.subtract(toPoint2, toPoint1, new Cartesian3());
1106
+ var ap = Cartesian3.subtract(fromPoint, toPoint1, new Cartesian3());
1107
+ var e = Cartesian3.dot(ap, ab);
1108
+ if (e <= 0) {
1109
+ return Cartesian3.distance(fromPoint, toPoint1);
1110
+ }
1111
+ var f = Cartesian3.dot(ab, ab);
1112
+ if (e >= f) {
1113
+ return Cartesian3.distance(fromPoint, toPoint2);
1114
+ }
1115
+ var proj = Cartesian3.multiplyByScalar(ab, e / f, new Cartesian3());
1116
+ var projECEF = Cartesian3.add(toPoint1, proj, new Cartesian3());
1117
+ return Cartesian3.distance(fromPoint, projECEF);
1118
+ }
1119
+ function pointInsidePolygon(point, polygon) {
1120
+ var inside = false;
1121
+ var x = point.latitude;
1122
+ var y = point.longitude;
1123
+ for (var i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
1124
+ var xi = +polygon[i].latitude;
1125
+ var yi = +polygon[i].longitude;
1126
+ var xj = +polygon[j].latitude;
1127
+ var yj = +polygon[j].longitude;
1128
+ if (isNaN(xi) || isNaN(yi) || isNaN(xj) || isNaN(yj)) {
1129
+ continue;
1130
+ }
1131
+ var intersect = (yi > y) !== (yj > y) && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
1132
+ if (intersect) {
1133
+ inside = !inside;
1134
+ }
1135
+ }
1136
+ return inside;
1137
+ }
1138
+ function distanceToPolygon(point, polygon) {
1139
+ if (pointInsidePolygon(point, polygon)) {
1140
+ var avgAltitude = polygon.reduce(function (sum, vertex) { return sum + vertex.altitude; }, 0) / polygon.length;
1141
+ return Math.abs(point.altitude - avgAltitude);
1142
+ }
1143
+ var pointECEF = Cartesian3.fromDegrees(point.longitude, point.latitude, point.altitude);
1144
+ var minDistance = Infinity;
1145
+ for (var i = 0; i < polygon.length; i++) {
1146
+ var point1 = polygon[i];
1147
+ var point1Latitude = EnsureNumber(point1.latitude);
1148
+ var point1Longitude = EnsureNumber(point1.longitude);
1149
+ if (!point1Latitude && !point1Longitude) {
1150
+ continue;
1151
+ }
1152
+ var point2 = polygon[(i + 1) % polygon.length];
1153
+ var point2Latitude = EnsureNumber(point2.latitude);
1154
+ var point2Longitude = EnsureNumber(point2.longitude);
1155
+ if (!point2Latitude && !point2Longitude) {
1156
+ continue;
1157
+ }
1158
+ var coord1ECEF = Cartesian3.fromDegrees(point1Longitude, point1Latitude, EnsureNumber(point1.altitude));
1159
+ var coord2ECEF = Cartesian3.fromDegrees(point2Longitude, point2Latitude, EnsureNumber(point2.altitude));
1160
+ var distance = distanceToSegment(pointECEF, coord1ECEF, coord2ECEF);
1161
+ minDistance = Math.min(minDistance, distance);
1162
+ }
1163
+ return minDistance;
1164
+ }
1165
+ // Cache for distance calculations.
1166
+ // It will keep only the most recent 3000 entries.
1167
+ var distanceCache = new LRUCache(3000);
1168
+ function createCacheKey(point, entity) {
1169
+ try {
1170
+ var pointData = {
1171
+ latitude: MathUtils.Round(+point.latitude, 5),
1172
+ longitude: MathUtils.Round(+point.longitude, 5),
1173
+ altitude: MathUtils.Round(+point.altitude, 4)
1174
+ };
1175
+ var entityData = __assign(__assign(__assign({}, entity.location), entity.geometry), entity.boundaries);
1176
+ return JSON.stringify(pointData) + '|' + JSON.stringify(entityData);
1177
+ }
1178
+ catch (e) {
1179
+ console.error(e);
1180
+ return null;
1181
+ }
1182
+ }
1183
+ /**
1184
+ * Calculates distance while accounting for polylines and polygons.
1185
+ * It does not account for multi-geometry.
1186
+ * @param point
1187
+ * @param entity
1188
+ * @returns
1189
+ */
1190
+ function calculateDistance(point, entity) {
1191
+ var cacheKey = createCacheKey(point, entity);
1192
+ var cachedResult = cacheKey ? distanceCache.Get(cacheKey) : null;
1193
+ if (cachedResult || cachedResult == 0) {
1194
+ return cachedResult;
1195
+ }
1196
+ var minDistance = Infinity;
1197
+ var pointPos = Cartesian3.fromDegrees(point.longitude, point.latitude, point.altitude);
1198
+ // We'll start by using the entity location if it's available.
1199
+ var entityPos3d = null;
1200
+ if (entity.location && entity.location.latitude) {
1201
+ var latitude = EnsureNumber(entity.location.latitude);
1202
+ var longitude = EnsureNumber(entity.location.longitude);
1203
+ // Disallowing exact 0.
1204
+ if (latitude || longitude) {
1205
+ var altitude = EnsureNumber(entity.location.altitude);
1206
+ entityPos3d = Cartesian3.fromDegrees(longitude, latitude, altitude);
1207
+ }
1208
+ }
1209
+ if (!isNaN(entityPos3d.x)) {
1210
+ minDistance = Cartesian3.distance(pointPos, entityPos3d);
1211
+ }
1212
+ // Check geometry if it's available.
1213
+ if (entity.geometry) {
1214
+ var passedGeometry = false;
1215
+ if (entity.geometry.Polygon) {
1216
+ var polygonRings = entity.geometry.Polygon;
1217
+ var polygon = typeof polygonRings == "string" ? String(polygonRings) : polygonRings.length ? polygonRings[0].LinearRing : "";
1218
+ var points = polygon ? Geometry.ParsePoints(polygon) : [];
1219
+ if (points.length > 2) {
1220
+ var distance = distanceToPolygon(point, points);
1221
+ if (!isNaN(distance)) {
1222
+ minDistance = Math.min(minDistance, distance);
1223
+ passedGeometry = true;
1224
+ }
1225
+ }
1226
+ }
1227
+ if (!passedGeometry && entity.geometry.LineString) {
1228
+ var points = Geometry.ParsePoints(entity.geometry.LineString);
1229
+ if (points.length > 1) {
1230
+ var pointsLen = points.length;
1231
+ for (var i = 0; i < pointsLen; i++) {
1232
+ var point1 = points[i];
1233
+ var point1Latitude = EnsureNumber(point1.latitude);
1234
+ var point1Longitude = EnsureNumber(point1.longitude);
1235
+ if (!point1Latitude && !point1Longitude) {
1236
+ continue;
1237
+ }
1238
+ var point2 = points[(i + 1) % pointsLen];
1239
+ var point2Latitude = EnsureNumber(point2.latitude);
1240
+ var point2Longitude = EnsureNumber(point2.longitude);
1241
+ if (!point2Latitude && !point2Longitude) {
1242
+ continue;
1243
+ }
1244
+ var coord1ECEF = Cartesian3.fromDegrees(point1Longitude, point1Latitude, EnsureNumber(point1.altitude));
1245
+ var coord2ECEF = Cartesian3.fromDegrees(point2Longitude, point2Latitude, EnsureNumber(point2.altitude));
1246
+ var distance = distanceToSegment(pointPos, coord1ECEF, coord2ECEF);
1247
+ if (!isNaN(distance)) {
1248
+ minDistance = Math.min(minDistance, distance);
1249
+ passedGeometry = true;
1250
+ }
1251
+ }
1252
+ }
1253
+ }
1254
+ }
1255
+ // Backup is using boundaries.
1256
+ if (minDistance === Infinity && entity.boundaries) {
1257
+ var point_1 = {
1258
+ latitude: (EnsureNumber(entity.boundaries.minLatitude) + EnsureNumber(entity.boundaries.maxLatitude)) / 2,
1259
+ longitude: (EnsureNumber(entity.boundaries.minLongitude) + EnsureNumber(entity.boundaries.maxLongitude)) / 2,
1260
+ altitude: 0
1261
+ };
1262
+ // Disallowing exact 0.
1263
+ if (point_1.latitude || point_1.longitude) {
1264
+ if (Carto.ValidateCarto(point_1)) {
1265
+ var boundsPoint = Cartesian3.fromDegrees(point_1.longitude, point_1.latitude, point_1.altitude);
1266
+ minDistance = Cartesian3.distance(pointPos, boundsPoint);
1267
+ }
1268
+ }
1269
+ }
1270
+ if (cacheKey) {
1271
+ distanceCache.Set(cacheKey, minDistance);
1272
+ }
1273
+ return minDistance;
1274
+ }
1096
1275
  var RenderManager;
1097
1276
  (function (RenderManager) {
1098
1277
  function DetermineZoomItem(params) {
@@ -1105,11 +1284,15 @@ var RenderManager;
1105
1284
  return null;
1106
1285
  }
1107
1286
  var is2d = viewer.scene.mode === SceneMode.SCENE2D;
1108
- var cameraPos = viewer.camera.position;
1109
- if (!Cartes.ValidateCartes3(cameraPos)) {
1287
+ var cameraPos = viewer.camera.positionCartographic;
1288
+ if (!cameraPos || !cameraPos.latitude) {
1110
1289
  return null;
1111
1290
  }
1112
- var distance = Cartesian3.distance(pos, cameraPos);
1291
+ var distance = calculateDistance({
1292
+ altitude: cameraPos.height,
1293
+ latitude: Math$1.toDegrees(cameraPos.latitude),
1294
+ longitude: Math$1.toDegrees(cameraPos.longitude)
1295
+ }, entity);
1113
1296
  var zoomItem = (!distance && distance != 0) ? null : GetZoomControlFromDistance({
1114
1297
  zoomControl: zoomControl,
1115
1298
  distance: distance
@@ -2303,6 +2486,8 @@ var EntityRenderEngine;
2303
2486
  })(Model3d = EntityRenderEngine.Model3d || (EntityRenderEngine.Model3d = {}));
2304
2487
  })(EntityRenderEngine || (EntityRenderEngine = {}));
2305
2488
 
2489
+ var BATCH_SIZE = 500;
2490
+ var CHECK_BATCH_SIZE = 250;
2306
2491
  /**
2307
2492
  * Manager for rendering Bruce entities.
2308
2493
  * This will request entities based on setup menu item filter.
@@ -2377,7 +2562,7 @@ var EntitiesRenderManager;
2377
2562
  this.getter = this.sharedGetters.GetOrCreateFilterGetter({
2378
2563
  api: api,
2379
2564
  attrFilter: (_e = this.item.BruceEntity.Filter) !== null && _e !== void 0 ? _e : {},
2380
- batchSize: 500,
2565
+ batchSize: BATCH_SIZE,
2381
2566
  typeId: this.item.BruceEntity["EntityType.ID"],
2382
2567
  monitor: this.monitor,
2383
2568
  viewer: this.viewer,
@@ -2455,7 +2640,7 @@ var EntitiesRenderManager;
2455
2640
  };
2456
2641
  Manager.prototype.doEntityCheck = function (ids) {
2457
2642
  return __awaiter(this, void 0, void 0, function () {
2458
- var api, CHECK_BATCH_SIZE_1, checkBatch, e_1;
2643
+ var api, checkBatch, e_1;
2459
2644
  var _this = this;
2460
2645
  return __generator(this, function (_a) {
2461
2646
  switch (_a.label) {
@@ -2479,13 +2664,12 @@ var EntitiesRenderManager;
2479
2664
  return [2 /*return*/];
2480
2665
  }
2481
2666
  if (!(ids.length > 0)) return [3 /*break*/, 4];
2482
- CHECK_BATCH_SIZE_1 = 150;
2483
2667
  checkBatch = function () { return __awaiter(_this, void 0, void 0, function () {
2484
2668
  var entityIds, entities;
2485
2669
  return __generator(this, function (_a) {
2486
2670
  switch (_a.label) {
2487
2671
  case 0:
2488
- entityIds = ids.splice(0, CHECK_BATCH_SIZE_1);
2672
+ entityIds = ids.splice(0, CHECK_BATCH_SIZE);
2489
2673
  return [4 /*yield*/, Entity$1.GetListByIds({
2490
2674
  api: api,
2491
2675
  entityIds: entityIds
@@ -2521,7 +2705,6 @@ var EntitiesRenderManager;
2521
2705
  };
2522
2706
  Manager.prototype.distributeForRender = function (entities) {
2523
2707
  var _this = this;
2524
- var BATCH_SIZE = 300;
2525
2708
  this.renderQueue = this.renderQueue.concat(entities);
2526
2709
  if (!this.renderQueueInterval && this.renderQueue.length) {
2527
2710
  this.renderQueueInterval = setInterval(function () {
@@ -2606,6 +2789,8 @@ var EntitiesRenderManager;
2606
2789
  EntitiesRenderManager.Manager = Manager;
2607
2790
  })(EntitiesRenderManager || (EntitiesRenderManager = {}));
2608
2791
 
2792
+ var BATCH_SIZE$1 = 500;
2793
+ var CHECK_BATCH_SIZE$1 = 250;
2609
2794
  /**
2610
2795
  * Render manager for a group of pre-loaded entities.
2611
2796
  * The entities may or may not have records.
@@ -2640,7 +2825,7 @@ var EntitiesLoadedRenderManager;
2640
2825
  if (this.disposed) {
2641
2826
  throw (new Error("This item is disposed."));
2642
2827
  }
2643
- this.getter = new BatchedDataGetter.Getter(this.item.BruceEntity.Entities, this.monitor, 500);
2828
+ this.getter = new BatchedDataGetter.Getter(this.item.BruceEntity.Entities, this.monitor, BATCH_SIZE$1);
2644
2829
  this.getterSub = this.getter.OnUpdate.Subscribe(function (entities) {
2645
2830
  _this.onGetterUpdate(entities);
2646
2831
  });
@@ -2686,7 +2871,7 @@ var EntitiesLoadedRenderManager;
2686
2871
  };
2687
2872
  Manager.prototype.doEntityCheck = function (ids) {
2688
2873
  return __awaiter(this, void 0, void 0, function () {
2689
- var api, CHECK_BATCH_SIZE_1, checkBatch, e_1;
2874
+ var api, checkBatch, e_1;
2690
2875
  var _this = this;
2691
2876
  return __generator(this, function (_a) {
2692
2877
  switch (_a.label) {
@@ -2699,13 +2884,12 @@ var EntitiesLoadedRenderManager;
2699
2884
  return [2 /*return*/];
2700
2885
  }
2701
2886
  if (!(ids.length > 0)) return [3 /*break*/, 4];
2702
- CHECK_BATCH_SIZE_1 = 150;
2703
2887
  checkBatch = function () { return __awaiter(_this, void 0, void 0, function () {
2704
2888
  var entityIds, entities;
2705
2889
  return __generator(this, function (_a) {
2706
2890
  switch (_a.label) {
2707
2891
  case 0:
2708
- entityIds = ids.splice(0, CHECK_BATCH_SIZE_1);
2892
+ entityIds = ids.splice(0, CHECK_BATCH_SIZE$1);
2709
2893
  return [4 /*yield*/, Entity$1.GetListByIds({
2710
2894
  api: api,
2711
2895
  entityIds: entityIds
@@ -4099,6 +4283,7 @@ var VisualsRegister;
4099
4283
  VisualsRegister.Register = Register;
4100
4284
  })(VisualsRegister || (VisualsRegister = {}));
4101
4285
 
4286
+ var BATCH_SIZE$2 = 500;
4102
4287
  /**
4103
4288
  * Render manager for rendering an array of entity ids.
4104
4289
  * This will render them in batches to avoid overloading the viewer.
@@ -4132,7 +4317,7 @@ var EntitiesIdsRenderManager;
4132
4317
  if (this.disposed) {
4133
4318
  throw (new Error("This item is disposed."));
4134
4319
  }
4135
- this.getter = new BatchedDataGetter.Getter(this.item.BruceEntity.EntityIds, this.monitor, 500);
4320
+ this.getter = new BatchedDataGetter.Getter(this.item.BruceEntity.EntityIds, this.monitor, BATCH_SIZE$2);
4136
4321
  this.getterSub = this.getter.OnUpdate.Subscribe(function (ids) {
4137
4322
  _this.onGetterUpdate(ids);
4138
4323
  });
@@ -5496,7 +5681,7 @@ var SharedGetters;
5496
5681
  })(SharedGetters || (SharedGetters = {}));
5497
5682
 
5498
5683
  var MAX_BATCHES = 2;
5499
- var BATCH_SIZE = 30;
5684
+ var BATCH_SIZE$3 = 30;
5500
5685
  var BATCH_DELAY = 200;
5501
5686
  var MAX_RANGE = 3000;
5502
5687
  var TilesetOsmRenderManager;
@@ -5691,7 +5876,7 @@ var TilesetOsmRenderManager;
5691
5876
  var isClose = this.getIsVisualWithinRange(feature, MAX_RANGE);
5692
5877
  if (isClose) {
5693
5878
  batch.push(feature);
5694
- if (batch.length >= BATCH_SIZE) {
5879
+ if (batch.length >= BATCH_SIZE$3) {
5695
5880
  return batch;
5696
5881
  }
5697
5882
  }
@@ -5796,7 +5981,7 @@ var TilesetOsmRenderManager;
5796
5981
  delete this._loadedCesiumEntities[key];
5797
5982
  this.totalLoaded -= 1;
5798
5983
  removed += 1;
5799
- if (removed >= BATCH_SIZE) {
5984
+ if (removed >= BATCH_SIZE$3) {
5800
5985
  return true;
5801
5986
  }
5802
5987
  }