bruce-cesium 2.4.3 → 2.4.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
- 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, AbstractApi, EntityAttachment, EntityAttachmentType, EntityAttribute } from 'bruce-models';
1
+ import { BruceEvent, Cartes, Carto, Entity as Entity$1, Geometry, Tileset, MathUtils, LRUCache, ZoomControl, Style, EntityTag, Calculator, EntityLod, EntityType, ClientFile, ObjectUtils, Bounds, DelayQueue, BatchedDataGetter, EntityRelationType, 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, Cartesian2, CallbackProperty, Cartesian3, Color, Rectangle, Math as Math$1, Entity, Primitive, Cesium3DTileFeature, HeightReference, DistanceDisplayCondition, NearFarScalar, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, HeadingPitchRoll, Transforms, ColorBlendMode, SceneMode, Cesium3DTileColorBlendMode, HeadingPitchRange, createOsmBuildings, Cesium3DTileStyle, KmlDataSource, OrthographicFrustum, JulianDate, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, CesiumInspector, defined, Cesium3DTileset, Matrix4, Matrix3, IonResource, ColorMaterialProperty, EasingFunction, GeometryInstance, ScreenSpaceEventHandler, ScreenSpaceEventType, PolygonPipeline, EllipsoidGeodesic, sampleTerrainMostDetailed, Model, Ion, BoundingSphere } from 'cesium';
3
+ import { Cartographic, Cartesian2, CallbackProperty, Cartesian3, Color, Rectangle, Math as Math$1, Entity, Primitive, Cesium3DTileFeature, SceneMode, Cesium3DTileColorBlendMode, HeadingPitchRange, createOsmBuildings, Cesium3DTileStyle, HeightReference, DistanceDisplayCondition, NearFarScalar, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, HeadingPitchRoll, Transforms, ColorBlendMode, KmlDataSource, OrthographicFrustum, JulianDate, CesiumInspector, defined, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, Cesium3DTileset, Matrix4, Matrix3, IonResource, EllipsoidGeodesic, sampleTerrainMostDetailed, Model, PolygonPipeline, ScreenSpaceEventHandler, ScreenSpaceEventType, ColorMaterialProperty, EasingFunction, GeometryInstance, Ion, BoundingSphere } from 'cesium';
4
4
 
5
5
  var TIME_LAG = 300;
6
6
  var POSITION_CHECK_TIMER = 950;
@@ -1740,7 +1740,14 @@ function getRenderGroupId(zoomItem, terrain) {
1740
1740
  return zoomItem.MinZoom + "-" + zoomItem.MaxZoom + "-" + shouldApplyFlatFix(terrain);
1741
1741
  }
1742
1742
  var _fileValidationCache = {};
1743
- function getDisplayCondition(min, max) {
1743
+ /**
1744
+ * @param min
1745
+ * @param max
1746
+ * @param meterSize size of "thing" in meters, eg polyline is 0.5 meters width. If size is provided we can potentially cull it earlier.
1747
+ * @param isPolygon
1748
+ * @returns
1749
+ */
1750
+ function getDisplayCondition(min, max, meterSize, isPolygon) {
1744
1751
  // Max is required.
1745
1752
  if (isNaN(+max)) {
1746
1753
  return undefined;
@@ -1755,8 +1762,78 @@ function getDisplayCondition(min, max) {
1755
1762
  if (min > 0) {
1756
1763
  min = (+min) * 0.8;
1757
1764
  }
1765
+ meterSize = +meterSize;
1766
+ if (!isNaN(meterSize) && meterSize > 0) {
1767
+ // A 1m thing at 2000m distance is barely visible, so we can cull it.
1768
+ // So we'll multiply this magic distance by the size of the thing and determine when it'll be too small to see.
1769
+ var METER_DISTANCE_PER_METER = isPolygon ? 100 : 2000;
1770
+ var newMax = meterSize * METER_DISTANCE_PER_METER;
1771
+ // Enforcing a minimum max distance in case something goes wrong we want stuff to always be visible when close.
1772
+ var MIN_MAX = 300;
1773
+ newMax = Math.max(newMax, MIN_MAX);
1774
+ //console.log(`meterSize ${isPolygon ? "polygon" : "thing"} of ${meterSize}m was provided so max was changed from ${max}m to ${Math.min(newMax, max)}m`)
1775
+ max = Math.min(newMax, max);
1776
+ if (max < min) {
1777
+ return undefined;
1778
+ }
1779
+ }
1758
1780
  return new DistanceDisplayCondition(min, max);
1759
1781
  }
1782
+ /**
1783
+ * Returns an entity's "size" used for distance display condition calcs.
1784
+ * This will return the distance in meters between the two boundary corners.
1785
+ * @param entity
1786
+ */
1787
+ function getSizeOfPolygonEntity(entity) {
1788
+ var _a, _b;
1789
+ if (!entity) {
1790
+ return null;
1791
+ }
1792
+ var hasResetBounds = false;
1793
+ var resetBounds = function () {
1794
+ hasResetBounds = true;
1795
+ entity.boundaries = Bounds.FromEntity(entity);
1796
+ return entity.boundaries;
1797
+ };
1798
+ var checkHasArea = function () {
1799
+ var _a, _b, _c, _d;
1800
+ return ((_a = entity.boundaries) === null || _a === void 0 ? void 0 : _a.minLongitude) != ((_b = entity.boundaries) === null || _b === void 0 ? void 0 : _b.maxLongitude) || ((_c = entity.boundaries) === null || _c === void 0 ? void 0 : _c.minLatitude) != ((_d = entity.boundaries) === null || _d === void 0 ? void 0 : _d.maxLatitude);
1801
+ };
1802
+ // Create bounds if missing entirely.
1803
+ if (!entity.boundaries) {
1804
+ resetBounds();
1805
+ }
1806
+ if (!((_a = entity.boundaries) === null || _a === void 0 ? void 0 : _a.minLatitude)) {
1807
+ return null;
1808
+ }
1809
+ // Check for bounds that are a single point.
1810
+ if (!checkHasArea()) {
1811
+ // Already tried to reconstruct, so we'll just give up.
1812
+ if (hasResetBounds) {
1813
+ return null;
1814
+ }
1815
+ resetBounds();
1816
+ // Check after reconstruction. If still bad then give up.
1817
+ if (!((_b = entity.boundaries) === null || _b === void 0 ? void 0 : _b.minLatitude) || !checkHasArea()) {
1818
+ return null;
1819
+ }
1820
+ }
1821
+ var bounds = entity === null || entity === void 0 ? void 0 : entity.boundaries;
1822
+ var minLat = +(bounds === null || bounds === void 0 ? void 0 : bounds.minLatitude);
1823
+ var maxLat = +(bounds === null || bounds === void 0 ? void 0 : bounds.maxLatitude);
1824
+ var minLon = +(bounds === null || bounds === void 0 ? void 0 : bounds.minLongitude);
1825
+ var maxLon = +(bounds === null || bounds === void 0 ? void 0 : bounds.maxLongitude);
1826
+ if (isNaN(minLat) || isNaN(maxLat) || isNaN(minLon) || isNaN(maxLon)) {
1827
+ return null;
1828
+ }
1829
+ var p1 = Cartesian3.fromDegrees(minLon, minLat);
1830
+ var p2 = Cartesian3.fromDegrees(maxLon, maxLat);
1831
+ var length = Cartesian3.distance(p1, p2);
1832
+ if (isNaN(length) || length <= 0) {
1833
+ return null;
1834
+ }
1835
+ return length;
1836
+ }
1760
1837
  var EntityRenderEngine;
1761
1838
  (function (EntityRenderEngine) {
1762
1839
  function Render(params) {
@@ -2361,7 +2438,7 @@ var EntityRenderEngine;
2361
2438
  classificationType: ClassificationType.TERRAIN,
2362
2439
  heightReference: heightRef,
2363
2440
  zIndex: getZIndex(style, entity, params.tags),
2364
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance),
2441
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance, width),
2365
2442
  cornerType: CornerType.MITERED,
2366
2443
  shadows: ShadowMode.ENABLED,
2367
2444
  fill: true
@@ -2479,6 +2556,7 @@ var EntityRenderEngine;
2479
2556
  return points.map(function (x) { return Cartesian3.fromDegrees(EnsureNumber(x.longitude), EnsureNumber(x.latitude), EnsureNumber(flattenPoints ? 0 : x.altitude)); });
2480
2557
  });
2481
2558
  var zIndex = getZIndex(style, entity, params.tags);
2559
+ var size = getSizeOfPolygonEntity(entity);
2482
2560
  var cEntity = new Entity({
2483
2561
  polygon: {
2484
2562
  hierarchy: new PolygonHierarchy(posses, holePosses.map(function (x) { return new PolygonHierarchy(x); })),
@@ -2490,7 +2568,7 @@ var EntityRenderEngine;
2490
2568
  classificationType: ClassificationType.BOTH,
2491
2569
  perPositionHeight: heightRef == HeightReference.CLAMP_TO_GROUND ? false : true,
2492
2570
  zIndex: zIndex,
2493
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
2571
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance, size, true)
2494
2572
  },
2495
2573
  position: EntityUtils.GetPos({
2496
2574
  viewer: params.viewer,
@@ -2527,7 +2605,7 @@ var EntityRenderEngine;
2527
2605
  zIndex: zIndex + 1,
2528
2606
  cornerType: CornerType.MITERED,
2529
2607
  classificationType: ClassificationType.TERRAIN,
2530
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance),
2608
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance, width),
2531
2609
  shadows: ShadowMode.ENABLED
2532
2610
  },
2533
2611
  show: false
@@ -2558,7 +2636,7 @@ var EntityRenderEngine;
2558
2636
  zIndex: zIndex + 1,
2559
2637
  cornerType: CornerType.MITERED,
2560
2638
  classificationType: ClassificationType.TERRAIN,
2561
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance),
2639
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance, width),
2562
2640
  shadows: ShadowMode.ENABLED,
2563
2641
  },
2564
2642
  show: false
@@ -14449,7 +14527,7 @@ var ViewerUtils;
14449
14527
  ViewerUtils.CreateWidgets = CreateWidgets;
14450
14528
  })(ViewerUtils || (ViewerUtils = {}));
14451
14529
 
14452
- var VERSION$1 = "2.4.3";
14530
+ var VERSION$1 = "2.4.5";
14453
14531
 
14454
14532
  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 };
14455
14533
  //# sourceMappingURL=bruce-cesium.es5.js.map