bruce-cesium 2.1.5 → 2.1.7

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, DelayQueue, BatchedDataGetter, EntityRelationType, EntityCoords, EntityFilterGetter, EntitySource, MenuItem, EntityRelation, ENVIRONMENT, ProjectView, ProjectViewBookmark, ProjectViewTile, ProjectViewLegacyTile, ProgramKey, Camera } from 'bruce-models';
2
2
  import * as Cesium from 'cesium';
3
- import { Cartesian2, Cartographic, CallbackProperty, Cartesian3, Color, Rectangle, Math as Math$1, SceneMode, Entity, Primitive, Cesium3DTileFeature, HeightReference, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, PolygonHierarchy, ShadowMode, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Cesium3DTileColorBlendMode, HeadingPitchRange, createOsmBuildings, Cesium3DTileStyle, KmlDataSource, OrthographicFrustum, JulianDate, NearFarScalar, EllipsoidGeodesic, EllipsoidTerrainProvider, sampleTerrainMostDetailed, CesiumInspector, PolygonPipeline, createWorldTerrain, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, Cesium3DTileset, Matrix4, Matrix3, IonResource, ColorMaterialProperty, EasingFunction, GeometryInstance } from 'cesium';
3
+ import { Cartesian2, Cartographic, CallbackProperty, Cartesian3, Color, Rectangle, Math as Math$1, HeightReference, Entity, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, PolygonHierarchy, ShadowMode, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Primitive, Cesium3DTileFeature, HeadingPitchRange, SceneMode, Cesium3DTileColorBlendMode, Cesium3DTileStyle, createOsmBuildings, KmlDataSource, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, OrthographicFrustum, JulianDate, NearFarScalar, PolygonPipeline, CesiumInspector, EllipsoidGeodesic, sampleTerrainMostDetailed, Cesium3DTileset, Matrix4, Matrix3, IonResource, ColorMaterialProperty, EasingFunction, GeometryInstance } from 'cesium';
4
4
 
5
5
  var TIME_LAG = 300;
6
6
  var POSITION_CHECK_TIMER = 950;
@@ -549,6 +549,34 @@ var DrawingUtils;
549
549
  DrawingUtils.EnsurePosHeight = EnsurePosHeight;
550
550
  })(DrawingUtils || (DrawingUtils = {}));
551
551
 
552
+ /**
553
+ * Returns if a given visual is alive and in the scene.
554
+ * @param viewer
555
+ * @param visual
556
+ * @returns
557
+ */
558
+ function isAlive(viewer, visual) {
559
+ if (!(viewer === null || viewer === void 0 ? void 0 : viewer.scene) || viewer.isDestroyed()) {
560
+ return false;
561
+ }
562
+ if (visual instanceof Entity) {
563
+ return viewer.entities.contains(visual);
564
+ }
565
+ else if (visual instanceof Primitive) {
566
+ return viewer.scene.primitives.contains(visual);
567
+ }
568
+ else if (visual instanceof Cesium3DTileFeature) {
569
+ var cTileset = visual === null || visual === void 0 ? void 0 : visual.tileset;
570
+ if (!cTileset) {
571
+ return false;
572
+ }
573
+ if (cTileset.isDestroyed() || !viewer.scene.primitives.contains(cTileset)) {
574
+ return false;
575
+ }
576
+ return true;
577
+ }
578
+ return false;
579
+ }
552
580
  function traverseEntity(cEntity, arr, ignoreParent) {
553
581
  if (cEntity._parentEntity && !ignoreParent) {
554
582
  traverseEntity(cEntity._parentEntity, arr, false);
@@ -597,6 +625,9 @@ function applyOpacityToGraphic(viewer, entity, graphicKey, materialKey, opacity)
597
625
  }
598
626
  }
599
627
  function revertAppliedEntityOpacity(viewer, entity) {
628
+ if (!isAlive(viewer, entity)) {
629
+ return;
630
+ }
600
631
  entity[NEW_OPACITY_KEY] = null;
601
632
  if (entity instanceof Entity) {
602
633
  var processKey = function (graphicKey, materialKey) {
@@ -626,6 +657,9 @@ function revertAppliedEntityOpacity(viewer, entity) {
626
657
  }
627
658
  }
628
659
  function applyOpacityToEntity(viewer, opacity, entity) {
660
+ if (!isAlive(viewer, entity)) {
661
+ return;
662
+ }
629
663
  entity[NEW_OPACITY_KEY] = opacity;
630
664
  if (entity instanceof Entity) {
631
665
  var processKey = function (graphicKey, materialKey) {
@@ -665,7 +699,7 @@ function applyOpacityToEntity(viewer, opacity, entity) {
665
699
  }
666
700
  }
667
701
  function findOpacity(entity) {
668
- return entity[NEW_OPACITY_KEY];
702
+ return entity ? entity[NEW_OPACITY_KEY] : null;
669
703
  }
670
704
  function GetValue(viewer, obj) {
671
705
  if (obj === null || obj === void 0 ? void 0 : obj.getValue) {
@@ -1972,7 +2006,9 @@ var EntityRenderEngine;
1972
2006
  })];
1973
2007
  case 5:
1974
2008
  cEntity = _d.sent();
1975
- cEntity._renderGroup = getRenderGroupId(zoomItem, (_c = params.viewer) === null || _c === void 0 ? void 0 : _c.terrainProvider);
2009
+ if (cEntity) {
2010
+ cEntity._renderGroup = getRenderGroupId(zoomItem, (_c = params.viewer) === null || _c === void 0 ? void 0 : _c.terrainProvider);
2011
+ }
1976
2012
  cEntities[entity.Bruce.ID] = cEntity;
1977
2013
  _d.label = 6;
1978
2014
  case 6:
@@ -2035,11 +2071,17 @@ var EntityRenderEngine;
2035
2071
  }
2036
2072
  var bColor = style.lineColor ? Calculator.GetColor(style.lineColor, entity, params.tags) : null;
2037
2073
  var cColor = bColor ? colorToCColor(bColor) : Color.RED;
2074
+ if (cColor.alpha <= 0) {
2075
+ return null;
2076
+ }
2038
2077
  var width = style.lineWidth ? Calculator.GetNumber(style.lineWidth, entity, params.tags) : null;
2039
2078
  if (width == null) {
2040
2079
  width = 4;
2041
2080
  }
2042
2081
  width = EnsureNumber(width);
2082
+ if (width < 0.01) {
2083
+ width = 0;
2084
+ }
2043
2085
  if (width <= 0) {
2044
2086
  return null;
2045
2087
  }
@@ -2135,7 +2177,12 @@ var EntityRenderEngine;
2135
2177
  width = 4;
2136
2178
  }
2137
2179
  width = EnsureNumber(width);
2138
- if (width <= 0) {
2180
+ if (width < 0.01) {
2181
+ width = 0;
2182
+ }
2183
+ // If both outline and fill is not available then don't render anything.
2184
+ if ((width <= 0 || cLineColor.alpha <= 0) &&
2185
+ cFillColor.alpha <= 0) {
2139
2186
  return null;
2140
2187
  }
2141
2188
  var heightRef = getHeightRef(style);
@@ -3586,6 +3633,34 @@ var RelationRenderEngine;
3586
3633
  })(Parabola = RelationRenderEngine.Parabola || (RelationRenderEngine.Parabola = {}));
3587
3634
  })(RelationRenderEngine || (RelationRenderEngine = {}));
3588
3635
 
3636
+ /**
3637
+ * Returns if a given visual is alive and in the scene.
3638
+ * @param viewer
3639
+ * @param visual
3640
+ * @returns
3641
+ */
3642
+ function isAlive$1(viewer, visual) {
3643
+ if (!(viewer === null || viewer === void 0 ? void 0 : viewer.scene) || viewer.isDestroyed()) {
3644
+ return false;
3645
+ }
3646
+ if (visual instanceof Entity) {
3647
+ return viewer.entities.contains(visual);
3648
+ }
3649
+ else if (visual instanceof Primitive) {
3650
+ return viewer.scene.primitives.contains(visual);
3651
+ }
3652
+ else if (visual instanceof Cesium3DTileFeature) {
3653
+ var cTileset = visual === null || visual === void 0 ? void 0 : visual.tileset;
3654
+ if (!cTileset) {
3655
+ return false;
3656
+ }
3657
+ if (cTileset.isDestroyed() || !viewer.scene.primitives.contains(cTileset)) {
3658
+ return false;
3659
+ }
3660
+ return true;
3661
+ }
3662
+ return false;
3663
+ }
3589
3664
  function removeEntity(viewer, visual) {
3590
3665
  unmarkEntity(visual, false);
3591
3666
  if (visual instanceof Entity) {
@@ -3626,6 +3701,9 @@ function updateCEntityShow(viewer, visual, show, ignoreParent) {
3626
3701
  }
3627
3702
  }
3628
3703
  function updateEntityShow(viewer, visual, show) {
3704
+ if (!isAlive$1(viewer, visual)) {
3705
+ return;
3706
+ }
3629
3707
  if (visual instanceof Entity) {
3630
3708
  updateCEntityShow(viewer, visual, show, false);
3631
3709
  }
@@ -3709,6 +3787,9 @@ function unmarkEntity(visual, ignoreParent) {
3709
3787
  var ORG_COLOR_KEY = "_org_color_";
3710
3788
  function select(viewer, visual, color) {
3711
3789
  var _a;
3790
+ if (!isAlive$1(viewer, visual)) {
3791
+ return;
3792
+ }
3712
3793
  if (!color) {
3713
3794
  color = Color.fromAlpha(Color.YELLOW, 0.5);
3714
3795
  }
@@ -3768,6 +3849,9 @@ function select(viewer, visual, color) {
3768
3849
  }
3769
3850
  }
3770
3851
  function deselect(viewer, visual) {
3852
+ if (!isAlive$1(viewer, visual)) {
3853
+ return;
3854
+ }
3771
3855
  if (visual instanceof Entity) {
3772
3856
  var entities = EntityUtils.GatherEntity({
3773
3857
  entity: visual
@@ -4735,7 +4819,7 @@ function colorToCColor$2(color) {
4735
4819
  * @param cTileset
4736
4820
  * @returns
4737
4821
  */
4738
- function isAlive(viewer, cTileset) {
4822
+ function isAlive$2(viewer, cTileset) {
4739
4823
  if (!(viewer === null || viewer === void 0 ? void 0 : viewer.scene)) {
4740
4824
  return false;
4741
4825
  }
@@ -4959,7 +5043,7 @@ var TilesetRenderEngine;
4959
5043
  cTileset_1.readyPromise.then(function () {
4960
5044
  var _a, _b, _c, _d;
4961
5045
  try {
4962
- if (!isAlive(params.viewer, cTileset_1)) {
5046
+ if (!isAlive$2(params.viewer, cTileset_1)) {
4963
5047
  return;
4964
5048
  }
4965
5049
  (_a = GetMemoryWatcher(params.viewer)) === null || _a === void 0 ? void 0 : _a.Watch(cTileset_1);
@@ -5008,7 +5092,7 @@ var TilesetRenderEngine;
5008
5092
  cTileset_2.readyPromise.then(function () {
5009
5093
  var _a;
5010
5094
  try {
5011
- if (!isAlive(params.viewer, cTileset_2)) {
5095
+ if (!isAlive$2(params.viewer, cTileset_2)) {
5012
5096
  return;
5013
5097
  }
5014
5098
  (_a = GetMemoryWatcher(params.viewer)) === null || _a === void 0 ? void 0 : _a.Watch(cTileset_2);
@@ -5086,7 +5170,7 @@ var TilesetRenderEngine;
5086
5170
  cTileset.readyPromise.then(function () {
5087
5171
  var _a;
5088
5172
  try {
5089
- if (!isAlive(viewer, cTileset)) {
5173
+ if (!isAlive$2(viewer, cTileset)) {
5090
5174
  return;
5091
5175
  }
5092
5176
  (_a = GetMemoryWatcher(params.viewer)) === null || _a === void 0 ? void 0 : _a.Watch(cTileset);
@@ -5572,7 +5656,7 @@ var TilesetRenderEngine;
5572
5656
  MemoryWatcher.prototype.clean = function () {
5573
5657
  var _this = this;
5574
5658
  // Remove all dead tilesets.
5575
- this.watched = this.watched.filter(function (x) { return isAlive(_this.viewer, x); });
5659
+ this.watched = this.watched.filter(function (x) { return isAlive$2(_this.viewer, x); });
5576
5660
  // Check if viewer is destroyed.
5577
5661
  if (!this.viewer || this.viewer.isDestroyed()) {
5578
5662
  this.destroy();