bruce-cesium 2.4.2 → 2.4.4

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, PolygonHierarchy, ShadowMode, CornerType, HeadingPitchRoll, Transforms, ColorBlendMode, SceneMode, Cesium3DTileColorBlendMode, HeadingPitchRange, createOsmBuildings, Cesium3DTileStyle, OrthographicFrustum, JulianDate, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, CesiumInspector, defined, KmlDataSource, Cesium3DTileset, Matrix4, Matrix3, IonResource, PolygonPipeline, EllipsoidGeodesic, sampleTerrainMostDetailed, Model, ColorMaterialProperty, EasingFunction, GeometryInstance, ScreenSpaceEventHandler, ScreenSpaceEventType, Ion, BoundingSphere } from 'cesium';
3
+ import { Cartographic, Cartesian2, CallbackProperty, Cartesian3, Color, Rectangle, Math as Math$1, HeightReference, DistanceDisplayCondition, NearFarScalar, Entity, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, HeadingPitchRoll, Transforms, ColorBlendMode, SceneMode, Primitive, Cesium3DTileFeature, Cesium3DTileColorBlendMode, HeadingPitchRange, Cesium3DTileStyle, createOsmBuildings, KmlDataSource, OrthographicFrustum, JulianDate, CesiumInspector, defined, Cesium3DTileset, Matrix4, Matrix3, IonResource, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, EllipsoidGeodesic, sampleTerrainMostDetailed, Model, ColorMaterialProperty, EasingFunction, GeometryInstance, ScreenSpaceEventHandler, ScreenSpaceEventType, PolygonPipeline, 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) {
@@ -2338,8 +2415,13 @@ var EntityRenderEngine;
2338
2415
  if (width <= 0) {
2339
2416
  return null;
2340
2417
  }
2418
+ var units = style.lineWidthUnits;
2419
+ // Px for backward compatibility. Meters are less prone to crashes.
2420
+ if (units != "px" && units != "m") {
2421
+ units = "px";
2422
+ }
2341
2423
  var cEntity = new Entity({
2342
- polyline: {
2424
+ polyline: units == "px" ? {
2343
2425
  positions: posses,
2344
2426
  material: cColor,
2345
2427
  width: width,
@@ -2348,7 +2430,19 @@ var EntityRenderEngine;
2348
2430
  zIndex: getZIndex(style, entity, params.tags),
2349
2431
  clampToGround: heightRef == HeightReference.CLAMP_TO_GROUND,
2350
2432
  distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
2351
- },
2433
+ } : null,
2434
+ corridor: units == "m" ? {
2435
+ positions: posses,
2436
+ material: cColor,
2437
+ width: width,
2438
+ classificationType: ClassificationType.TERRAIN,
2439
+ heightReference: heightRef,
2440
+ zIndex: getZIndex(style, entity, params.tags),
2441
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance, width),
2442
+ cornerType: CornerType.MITERED,
2443
+ shadows: ShadowMode.ENABLED,
2444
+ fill: true
2445
+ } : null,
2352
2446
  position: EntityUtils.GetPos({
2353
2447
  viewer: params.viewer,
2354
2448
  entity: entity,
@@ -2462,6 +2556,7 @@ var EntityRenderEngine;
2462
2556
  return points.map(function (x) { return Cartesian3.fromDegrees(EnsureNumber(x.longitude), EnsureNumber(x.latitude), EnsureNumber(flattenPoints ? 0 : x.altitude)); });
2463
2557
  });
2464
2558
  var zIndex = getZIndex(style, entity, params.tags);
2559
+ var size = getSizeOfPolygonEntity(entity);
2465
2560
  var cEntity = new Entity({
2466
2561
  polygon: {
2467
2562
  hierarchy: new PolygonHierarchy(posses, holePosses.map(function (x) { return new PolygonHierarchy(x); })),
@@ -2473,7 +2568,7 @@ var EntityRenderEngine;
2473
2568
  classificationType: ClassificationType.BOTH,
2474
2569
  perPositionHeight: heightRef == HeightReference.CLAMP_TO_GROUND ? false : true,
2475
2570
  zIndex: zIndex,
2476
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
2571
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance, size, true)
2477
2572
  },
2478
2573
  position: EntityUtils.GetPos({
2479
2574
  viewer: params.viewer,
@@ -2510,7 +2605,7 @@ var EntityRenderEngine;
2510
2605
  zIndex: zIndex + 1,
2511
2606
  cornerType: CornerType.MITERED,
2512
2607
  classificationType: ClassificationType.TERRAIN,
2513
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance),
2608
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance, width),
2514
2609
  shadows: ShadowMode.ENABLED
2515
2610
  },
2516
2611
  show: false
@@ -2541,7 +2636,7 @@ var EntityRenderEngine;
2541
2636
  zIndex: zIndex + 1,
2542
2637
  cornerType: CornerType.MITERED,
2543
2638
  classificationType: ClassificationType.TERRAIN,
2544
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance),
2639
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance, width),
2545
2640
  shadows: ShadowMode.ENABLED,
2546
2641
  },
2547
2642
  show: false
@@ -14432,7 +14527,7 @@ var ViewerUtils;
14432
14527
  ViewerUtils.CreateWidgets = CreateWidgets;
14433
14528
  })(ViewerUtils || (ViewerUtils = {}));
14434
14529
 
14435
- var VERSION$1 = "2.4.2";
14530
+ var VERSION$1 = "2.4.4";
14436
14531
 
14437
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 };
14438
14533
  //# sourceMappingURL=bruce-cesium.es5.js.map