bruce-cesium 2.7.4 → 2.7.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,6 +1,6 @@
1
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';
2
2
  import * as Cesium from 'cesium';
3
- import { Cartographic, Entity, Primitive, Cesium3DTileFeature, Color, Cartesian2, JulianDate, Cartesian3, SceneMode, Math as Math$1, CallbackProperty, Rectangle, HeightReference, DistanceDisplayCondition, NearFarScalar, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, HeadingPitchRoll, Transforms, ColorBlendMode, Cesium3DTileColorBlendMode, HeadingPitchRange, createOsmBuildings, Cesium3DTileStyle, KmlDataSource, EllipsoidTerrainProvider, CesiumInspector, OrthographicFrustum, defined, createWorldTerrain, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, EllipsoidGeodesic, sampleTerrainMostDetailed, Cesium3DTileset, Model, PolygonPipeline, Matrix4, Matrix3, IonResource, ScreenSpaceEventHandler, ScreenSpaceEventType, ColorMaterialProperty, EasingFunction, GeometryInstance, Ion, BoundingSphere } from 'cesium';
3
+ import { Cartographic, Cartesian2, CallbackProperty, Cartesian3, Color, Rectangle, Math as Math$1, JulianDate, SceneMode, Entity, Primitive, Cesium3DTileFeature, HeightReference, DistanceDisplayCondition, NearFarScalar, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, HeadingPitchRoll, Transforms, ColorBlendMode, Cesium3DTileColorBlendMode, HeadingPitchRange, createOsmBuildings, Cesium3DTileStyle, KmlDataSource, OrthographicFrustum, EasingFunction, EllipsoidTerrainProvider, CesiumInspector, defined, Cesium3DTileset, Matrix4, Matrix3, IonResource, createWorldTerrain, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, EllipsoidGeodesic, sampleTerrainMostDetailed, Model, PolygonPipeline, ColorMaterialProperty, GeometryInstance, ScreenSpaceEventHandler, ScreenSpaceEventType, Ion, BoundingSphere } from 'cesium';
4
4
 
5
5
  var TIME_LAG = 300;
6
6
  var POSITION_CHECK_TIMER = 950;
@@ -1766,7 +1766,7 @@ function getName(api, entity) {
1766
1766
  }
1767
1767
  function getStyle(api, entity, styleId) {
1768
1768
  return __awaiter(this, void 0, void 0, function () {
1769
- var style, e_2, typeId, type, e_3;
1769
+ var style, e_2, typeId, type, e_3, hideError, error, code;
1770
1770
  return __generator(this, function (_a) {
1771
1771
  switch (_a.label) {
1772
1772
  case 0:
@@ -1809,7 +1809,18 @@ function getStyle(api, entity, styleId) {
1809
1809
  return [3 /*break*/, 9];
1810
1810
  case 8:
1811
1811
  e_3 = _a.sent();
1812
- console.error(e_3);
1812
+ hideError = false;
1813
+ // TODO: we need a util for extracting code + message rather than writing all this every time.
1814
+ if (e_3 && typeof e_3 == "object" && e_3.ERROR) {
1815
+ error = e_3.ERROR;
1816
+ code = error && typeof error == "object" ? error.Code : "";
1817
+ // Avoiding logging a common error.
1818
+ // This happens when rendering entities that don't have records.
1819
+ hideError = String(code).toLowerCase() == "notfound";
1820
+ }
1821
+ if (!hideError) {
1822
+ console.error(e_3);
1823
+ }
1813
1824
  return [3 /*break*/, 9];
1814
1825
  case 9: return [2 /*return*/, style];
1815
1826
  }
@@ -5519,16 +5530,14 @@ var EntitiesRenderManager;
5519
5530
  viewer: this.viewer,
5520
5531
  // Unfortunately this searches as an "AND" rather than "OR" which does not meet our needs here.
5521
5532
  // So for multiple tags we'll manually sort on UI end...
5522
- tagIds: tagsToRender.length == 1 ? tagsToRender : [],
5533
+ tagIds: (tagsToRender === null || tagsToRender === void 0 ? void 0 : tagsToRender.length) ? tagsToRender : [],
5523
5534
  debugShowBounds: Boolean(window === null || window === void 0 ? void 0 : window.ENTITIES_RENDER_MANAGER_SHOW_BOUNDS),
5524
5535
  cdn: this.item.cdnEnabled
5525
5536
  });
5526
5537
  var minMax = RenderManager.GetZoomMinMax({
5527
5538
  zoomControl: this.item.CameraZoomSettings
5528
5539
  });
5529
- // Unfortunately this searches as an "AND" rather than "OR" which does not meet our needs here.
5530
- // So for multiple tags we'll manually sort on UI end...
5531
- this.getter.IncludeMenuItem(this.item.id, tagsToRender.length == 1 ? tagsToRender : [], minMax[0], minMax[1]);
5540
+ this.getter.IncludeMenuItem(this.item.id, (tagsToRender === null || tagsToRender === void 0 ? void 0 : tagsToRender.length) ? tagsToRender : [], minMax[0], minMax[1]);
5532
5541
  this.getterSub = this.getter.OnUpdate.Subscribe(function (entities) {
5533
5542
  if (isTagItem) {
5534
5543
  _this.distributeForRender(entities.filter(function (entity) {
@@ -12436,71 +12445,43 @@ var ViewRenderEngine;
12436
12445
  })(ViewRenderEngine || (ViewRenderEngine = {}));
12437
12446
 
12438
12447
  var DEFAULT_SMOOTH_MULTIPLIER = 0;
12439
- function avgDistanceFromPointPair(refPoint, pos1, pos2) {
12440
- var carto1 = Cartographic.fromCartesian(refPoint);
12441
- var carto2 = Cartographic.fromCartesian(pos1);
12442
- var carto3 = Cartographic.fromCartesian(pos2);
12443
- var x1 = carto1.longitude;
12444
- var y1 = carto1.latitude;
12445
- var x2 = carto2.longitude;
12446
- var y2 = carto2.latitude;
12447
- var x3 = carto3.longitude;
12448
- var y3 = carto3.latitude;
12449
- var A = x1 - x2;
12450
- var B = y1 - y2;
12451
- var C = x3 - x2;
12452
- var D = y3 - y2;
12453
- var dot = A * C + B * D;
12454
- var lenSq = C * C + D * D;
12455
- var param = dot / lenSq;
12456
- var xx;
12457
- var yy;
12458
- if (param < 0 || x2 == x3 && y2 == y3) {
12459
- xx = x2;
12460
- yy = y2;
12461
- }
12462
- else if (param > 1) {
12463
- xx = x3;
12464
- yy = y3;
12448
+ function distanceToSegment$1(p, v, w) {
12449
+ var l2 = Cartesian3.distanceSquared(v, w);
12450
+ if (l2 === 0) {
12451
+ return Cartesian3.distance(p, v);
12465
12452
  }
12466
- else {
12467
- xx = x2 + param * C;
12468
- yy = y2 + param * D;
12453
+ var t = Cartesian3.dot(Cartesian3.subtract(p, v, new Cartesian3()), Cartesian3.subtract(w, v, new Cartesian3())) / l2;
12454
+ if (t < 0) {
12455
+ return Cartesian3.distance(p, v);
12456
+ }
12457
+ if (t > 1) {
12458
+ return Cartesian3.distance(p, w);
12469
12459
  }
12470
- var dx = x1 - xx;
12471
- var dy = y1 - yy;
12472
- return Math.sqrt(dx * dx + dy * dy);
12460
+ var projection = Cartesian3.add(v, Cartesian3.multiplyByScalar(Cartesian3.subtract(w, v, new Cartesian3()), t, new Cartesian3()), new Cartesian3());
12461
+ return Cartesian3.distance(p, projection);
12473
12462
  }
12463
+ /**
12464
+ * Returns splice index into a list of positions to insert a new position.
12465
+ * @param positions List of positions to insert into.
12466
+ * @param pos3d New position to insert.
12467
+ * @returns Index to insert at.
12468
+ */
12474
12469
  function getInsertIndex(positions, pos3d) {
12475
12470
  if (positions.length < 2) {
12476
12471
  return 0;
12477
12472
  }
12473
+ var minDistance = Infinity;
12478
12474
  var index = -1;
12479
- if (positions) {
12480
- var distance = void 0;
12481
- for (var j = 0; j < positions.length; j++) {
12482
- var pos1 = positions[j];
12483
- var pos2 = void 0;
12484
- var pos2Index = -1;
12485
- if (j >= positions.length - 1) {
12486
- pos2 = positions[0];
12487
- pos2Index = 0;
12488
- }
12489
- else {
12490
- pos2 = positions[j + 1];
12491
- pos2Index = j + 1;
12492
- }
12493
- if (Cartes.ValidateCartes3(pos1), Cartes.ValidateCartes3(pos2)) {
12494
- var length_1 = avgDistanceFromPointPair(pos3d, pos1, pos2);
12495
- if (index == -1 || length_1 < distance) {
12496
- var insertIndex = pos2Index == 0 ? 0 : j > pos2Index ? j : pos2Index;
12497
- index = insertIndex;
12498
- distance = length_1;
12499
- }
12500
- }
12475
+ for (var i = 0; i < positions.length; i++) {
12476
+ var pos1 = positions[i];
12477
+ var pos2 = i < positions.length - 1 ? positions[i + 1] : positions[0];
12478
+ var dist = distanceToSegment$1(pos3d, pos1, pos2);
12479
+ if (dist < minDistance) {
12480
+ minDistance = dist;
12481
+ index = i + 1;
12501
12482
  }
12502
12483
  }
12503
- return index == -1 ? 0 : index;
12484
+ return index;
12504
12485
  }
12505
12486
  var OUTLINE_COLOR = "rgba(51, 177, 255, 0.2)";
12506
12487
  var FILL_COLOR = "#33B1FF";
@@ -12903,71 +12884,61 @@ var Draw3dPolygon = /** @class */ (function () {
12903
12884
  }());
12904
12885
 
12905
12886
  var DEFAULT_SMOOTH_MULTIPLIER$1 = 0;
12906
- function avgDistanceFromPointPair$1(refPoint, pos1, pos2) {
12907
- var carto1 = Cartographic.fromCartesian(refPoint);
12908
- var carto2 = Cartographic.fromCartesian(pos1);
12909
- var carto3 = Cartographic.fromCartesian(pos2);
12910
- var x1 = carto1.longitude;
12911
- var y1 = carto1.latitude;
12912
- var x2 = carto2.longitude;
12913
- var y2 = carto2.latitude;
12914
- var x3 = carto3.longitude;
12915
- var y3 = carto3.latitude;
12916
- var A = x1 - x2;
12917
- var B = y1 - y2;
12918
- var C = x3 - x2;
12919
- var D = y3 - y2;
12920
- var dot = A * C + B * D;
12921
- var lenSq = C * C + D * D;
12922
- var param = dot / lenSq;
12923
- var xx;
12924
- var yy;
12925
- if (param < 0 || x2 == x3 && y2 == y3) {
12926
- xx = x2;
12927
- yy = y2;
12928
- }
12929
- else if (param > 1) {
12930
- xx = x3;
12931
- yy = y3;
12887
+ function distanceToSegment$2(p, v, w) {
12888
+ var l2 = Cartesian3.distanceSquared(v, w);
12889
+ if (l2 === 0) {
12890
+ return Cartesian3.distance(p, v);
12932
12891
  }
12933
- else {
12934
- xx = x2 + param * C;
12935
- yy = y2 + param * D;
12892
+ var t = Cartesian3.dot(Cartesian3.subtract(p, v, new Cartesian3()), Cartesian3.subtract(w, v, new Cartesian3())) / l2;
12893
+ if (t < 0) {
12894
+ return Cartesian3.distance(p, v);
12936
12895
  }
12937
- var dx = x1 - xx;
12938
- var dy = y1 - yy;
12939
- return Math.sqrt(dx * dx + dy * dy);
12896
+ if (t > 1) {
12897
+ return Cartesian3.distance(p, w);
12898
+ }
12899
+ var projection = Cartesian3.add(v, Cartesian3.multiplyByScalar(Cartesian3.subtract(w, v, new Cartesian3()), t, new Cartesian3()), new Cartesian3());
12900
+ return Cartesian3.distance(p, projection);
12940
12901
  }
12902
+ /**
12903
+ * Returns splice index into a list of positions to insert a new position.
12904
+ * @param positions List of positions to insert into.
12905
+ * @param pos3d New position to insert.
12906
+ * @returns Index to insert at.
12907
+ */
12941
12908
  function getInsertIndex$1(positions, pos3d) {
12942
12909
  if (positions.length < 2) {
12943
12910
  return 0;
12944
12911
  }
12945
- var index = 0;
12946
- if (positions) {
12947
- var marginalShift = function (pos) {
12948
- var SHIFT = 0.001;
12949
- pos = pos.clone();
12950
- return new Cartesian3(pos.x + SHIFT, pos.y + SHIFT, pos.z + SHIFT);
12951
- };
12952
- var distance = avgDistanceFromPointPair$1(pos3d, positions[0], marginalShift(positions[0]));
12953
- var endDistance = avgDistanceFromPointPair$1(pos3d, positions[positions.length - 1], marginalShift(positions[positions.length - 1]));
12954
- if (endDistance < distance) {
12955
- index = positions.length;
12956
- distance = endDistance;
12957
- }
12958
- for (var j = 0; j < positions.length; j++) {
12959
- var pos1 = positions[j];
12960
- var pos2 = positions[j + 1];
12961
- var pos2Index = j + 1;
12962
- if (Cartes.ValidateCartes3(pos1), Cartes.ValidateCartes3(pos2)) {
12963
- var length_1 = avgDistanceFromPointPair$1(pos3d, pos1, pos2);
12964
- if (length_1 < distance) {
12965
- var insertIndex = pos2Index == 0 ? 0 : j > pos2Index ? j : pos2Index;
12966
- index = insertIndex;
12967
- distance = length_1;
12968
- }
12969
- }
12970
- }
12912
+ var minDistance = Infinity;
12913
+ var index = -1;
12914
+ // Check against segments
12915
+ for (var i = 0; i < positions.length - 1; i++) {
12916
+ var pos1 = positions[i];
12917
+ var pos2 = positions[i + 1];
12918
+ var dist = distanceToSegment$2(pos3d, pos1, pos2);
12919
+ if (dist < minDistance) {
12920
+ minDistance = dist;
12921
+ index = i + 1;
12922
+ }
12923
+ }
12924
+ // Check against start point
12925
+ var startDist = Cartesian3.distance(pos3d, positions[0]);
12926
+ if (startDist <= minDistance) {
12927
+ index = 0;
12928
+ minDistance = startDist;
12929
+ console.log("Insert at start");
12930
+ }
12931
+ else {
12932
+ console.log("Start distance was longer than cur distance. ".concat(startDist, " > ").concat(minDistance));
12933
+ }
12934
+ // Check against end point
12935
+ var endDist = Cartesian3.distance(pos3d, positions[positions.length - 1]);
12936
+ if (endDist <= minDistance) {
12937
+ index = positions.length;
12938
+ console.log("Insert at end");
12939
+ }
12940
+ else {
12941
+ console.log("End distance was longer than cur distance. ".concat(endDist, " > ").concat(minDistance));
12971
12942
  }
12972
12943
  return index;
12973
12944
  }
@@ -15272,7 +15243,7 @@ var ViewerUtils;
15272
15243
  ViewerUtils.CreateWidgets = CreateWidgets;
15273
15244
  })(ViewerUtils || (ViewerUtils = {}));
15274
15245
 
15275
- var VERSION$1 = "2.7.4";
15246
+ var VERSION$1 = "2.7.5";
15276
15247
 
15277
15248
  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, ViewRenderEngine, TileRenderEngine, TilesetRenderEngine, CESIUM_INSPECTOR_KEY, ViewUtils, DrawingUtils, MeasureUtils, EntityUtils, Draw3dPolygon, Draw3dPolyline };
15278
15249
  //# sourceMappingURL=bruce-cesium.es5.js.map