bruce-cesium 7.1.5 → 7.1.6

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 * as Cesium from 'cesium';
2
- import { Cartographic, ColorMaterialProperty, Entity, Color, ConstantProperty, CallbackProperty, Primitive, Cesium3DTileFeature, DistanceDisplayCondition, ShaderSource, Cartesian3, Math as Math$1, Ellipsoid, Transforms, Matrix4, Geometry, GeometryAttribute, ComponentDatatype, PrimitiveType, BoundingSphere, GeometryPipeline, sampleTerrain, Texture, PixelFormat, Sampler, TextureWrap, TextureMinificationFilter, TextureMagnificationFilter, VertexArray, BufferUsage, ShaderProgram, RenderState, BlendingState, DrawCommand, Pass, Cartesian2, HeightReference, HorizontalOrigin, VerticalOrigin, ClassificationType, ConstantPositionProperty, ArcType, CornerType, ShadowMode, ColorBlendMode, HeadingPitchRoll, Model, JulianDate, Quaternion, ImageMaterialProperty, PolygonHierarchy, PolylineGraphics, Rectangle, SceneTransforms, NearFarScalar, Matrix3, KmlDataSource, GeoJsonDataSource, SceneMode, Ion, IonResource, Cesium3DTileStyle, HeadingPitchRange, Cesium3DTileColorBlendMode, OrthographicFrustum, EasingFunction, EllipsoidTerrainProvider, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, Cesium3DTileset, Intersect, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, EllipsoidGeodesic, sampleTerrainMostDetailed, defined, CustomDataSource, PolygonPipeline, CesiumInspector, ClockRange, GeometryInstance, ScreenSpaceEventHandler, ScreenSpaceEventType, Fullscreen, CzmlDataSource } from 'cesium';
3
- import { Cartes, Entity as Entity$1, ENVIRONMENT, Api, Calculator, ClientFile, EntityTag, EntityType, LRUCache, ObjectUtils, Style, Carto, Geometry as Geometry$1, EntityLod, MenuItem, ProjectView, ProjectViewBookmark, Tileset, ZoomControl, Bounds, Color as Color$1, BruceEvent, EntityCoords, DataLab, DelayQueue, EntityHistoricData, BruceApi, AccountConcept, RecordChangeFeed, EntityRelation, ProgramKey, EntitySource, Camera, ProjectViewTile, ProjectViewLegacyTile, Account, AccountLimits, Session, UrlUtils, ProjectViewBookmarkGroup, EntityAttachment, EntityAttachmentType, EntityAttribute, MathUtils, EntityRelationType } from 'bruce-models';
2
+ import { Cartographic, ColorMaterialProperty, Entity, Color, ConstantProperty, CallbackProperty, Primitive, Cesium3DTileFeature, ShaderSource, Cartesian3, Math as Math$1, Ellipsoid, Transforms, Matrix4, Geometry, GeometryAttribute, ComponentDatatype, PrimitiveType, BoundingSphere, GeometryPipeline, sampleTerrain, Texture, PixelFormat, Sampler, TextureWrap, TextureMinificationFilter, TextureMagnificationFilter, VertexArray, BufferUsage, ShaderProgram, RenderState, BlendingState, DrawCommand, Pass, Cartesian2, DistanceDisplayCondition, JulianDate, Quaternion, HeadingPitchRoll, ClassificationType, ArcType, HeightReference, CornerType, ShadowMode, ConstantPositionProperty, HorizontalOrigin, VerticalOrigin, ColorBlendMode, Model, ImageMaterialProperty, PolygonHierarchy, PolylineGraphics, Rectangle, SceneTransforms, NearFarScalar, Matrix3, KmlDataSource, GeoJsonDataSource, SceneMode, Cesium3DTileStyle, HeadingPitchRange, Ion, IonResource, Cesium3DTileColorBlendMode, Cesium3DTileset, EllipsoidTerrainProvider, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, Intersect, EllipsoidGeodesic, sampleTerrainMostDetailed, defined, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, OrthographicFrustum, EasingFunction, PolygonPipeline, GeometryInstance, CustomDataSource, CesiumInspector, ClockRange, ScreenSpaceEventHandler, ScreenSpaceEventType, Fullscreen, CzmlDataSource } from 'cesium';
3
+ import { Cartes, Entity as Entity$1, ENVIRONMENT, Calculator, Carto, EntityTag, EntityType, Geometry as Geometry$1, ObjectUtils, Style, Api, ClientFile, LRUCache, MenuItem, ProjectView, ProjectViewBookmark, Tileset, ZoomControl, EntityLod, Bounds, Color as Color$1, BruceEvent, EntityCoords, DataLab, DelayQueue, BruceApi, EntityHistoricData, AccountConcept, RecordChangeFeed, EntityRelation, ProgramKey, EntitySource, ProjectViewLegacyTile, ProjectViewTile, Camera, Account, AccountLimits, Session, UrlUtils, EntityAttachment, EntityAttachmentType, EntityAttribute, MathUtils, ProjectViewBookmarkGroup, EntityRelationType } from 'bruce-models';
4
4
 
5
5
  /**
6
6
  * Ensures a number is returned from a given value.
@@ -3587,6 +3587,7 @@ var SimplifyGeometry;
3587
3587
  if (!geometry || !isTurfAvailable() || !turf.simplify) {
3588
3588
  return geometry;
3589
3589
  }
3590
+ const original = geometry;
3590
3591
  // Convert to geojson so that we can interact with turf.
3591
3592
  const gFeature = Geometry$1.ToGeoJsonFeature({
3592
3593
  geometry: geometry
@@ -3607,13 +3608,97 @@ var SimplifyGeometry;
3607
3608
  });
3608
3609
  }
3609
3610
  // Converting back to Bruce geometry.
3610
- geometry = (_a = Geometry$1.FromGeoJson({
3611
+ const simplified = (_a = Geometry$1.FromGeoJson({
3611
3612
  geoJson: gFeature
3612
3613
  })) === null || _a === void 0 ? void 0 : _a.geometry;
3613
- return geometry;
3614
+ // A polygon we cannot vouch for is worse than an unsimplified one, so fall back instead of shipping it.
3615
+ if (!simplified || !isSafeToRender(simplified)) {
3616
+ return original;
3617
+ }
3618
+ return simplified;
3614
3619
  }
3615
3620
  SimplifyGeometry.Simplify = Simplify;
3621
+ /**
3622
+ * Whether a simplified geometry still describes something a renderer can triangulate.
3623
+ * @param geometry the simplification result.
3624
+ * @returns false when any polygon has a collapsed ring, a hole outside its outer ring, or a hole
3625
+ * wound the same way as its outer ring.
3626
+ */
3627
+ function IsSafeToRender(geometry) {
3628
+ return isSafeToRender(geometry);
3629
+ }
3630
+ SimplifyGeometry.IsSafeToRender = IsSafeToRender;
3616
3631
  })(SimplifyGeometry || (SimplifyGeometry = {}));
3632
+ // A ring needs three distinct corners plus the closing repeat before it encloses any area.
3633
+ const MIN_RING_POSITIONS = 4;
3634
+ function isSafeToRender(geometry) {
3635
+ let safe = true;
3636
+ const check = (g) => {
3637
+ if (!safe) {
3638
+ return;
3639
+ }
3640
+ if (g === null || g === void 0 ? void 0 : g.MultiGeometry) {
3641
+ g.MultiGeometry.forEach(check);
3642
+ return;
3643
+ }
3644
+ if (!(g === null || g === void 0 ? void 0 : g.Polygon) || g.Polygon.length === 0) {
3645
+ return;
3646
+ }
3647
+ let outer = null;
3648
+ let outerIsClockwise = false;
3649
+ for (let i = 0; i < g.Polygon.length; i++) {
3650
+ const points = Geometry$1.ParsePoints(g.Polygon[i].LinearRing);
3651
+ if (!points || points.length < MIN_RING_POSITIONS) {
3652
+ safe = false;
3653
+ return;
3654
+ }
3655
+ const clockwise = signedRingArea(points) < 0;
3656
+ if (g.Polygon[i].Facing !== "in") {
3657
+ outer = points;
3658
+ outerIsClockwise = clockwise;
3659
+ continue;
3660
+ }
3661
+ // A hole with no outer ring ahead of it cannot be subtracted from anything.
3662
+ if (!outer) {
3663
+ safe = false;
3664
+ return;
3665
+ }
3666
+ if (clockwise === outerIsClockwise) {
3667
+ safe = false;
3668
+ return;
3669
+ }
3670
+ for (let j = 0; j < points.length; j++) {
3671
+ if (!isPointInRing(points[j], outer)) {
3672
+ safe = false;
3673
+ return;
3674
+ }
3675
+ }
3676
+ }
3677
+ };
3678
+ check(geometry);
3679
+ return safe;
3680
+ }
3681
+ function signedRingArea(points) {
3682
+ let sum = 0;
3683
+ for (let i = 0; i < points.length; i++) {
3684
+ const a = points[i];
3685
+ const b = points[(i + 1) % points.length];
3686
+ sum += a.longitude * b.latitude - b.longitude * a.latitude;
3687
+ }
3688
+ return sum / 2;
3689
+ }
3690
+ function isPointInRing(point, ring) {
3691
+ let inside = false;
3692
+ for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
3693
+ const a = ring[i];
3694
+ const b = ring[j];
3695
+ if ((a.latitude > point.latitude) !== (b.latitude > point.latitude)
3696
+ && point.longitude < (b.longitude - a.longitude) * (point.latitude - a.latitude) / (b.latitude - a.latitude) + a.longitude) {
3697
+ inside = !inside;
3698
+ }
3699
+ }
3700
+ return inside;
3701
+ }
3617
3702
  /**
3618
3703
  * Runs through all found polygons and runs unkink through turf on them.
3619
3704
  * @param feature
@@ -3655,9 +3740,26 @@ function untangleFeature(feature) {
3655
3740
  }
3656
3741
  // Recreate the rings and reapply to the collection.
3657
3742
  if (outer.length > 0) {
3658
- const combinedCoords = [outer[0]];
3743
+ // Unkinking a self touching boundary splits it into pieces. Keeping whichever piece
3744
+ // happened to come back first can discard most of the shape, so keep the biggest one.
3745
+ let keep = outer[0];
3746
+ if (outer.length > 1) {
3747
+ let best = Math.abs(ringArea(keep));
3748
+ for (let i = 1; i < outer.length; i++) {
3749
+ const area = Math.abs(ringArea(outer[i]));
3750
+ if (area > best) {
3751
+ best = area;
3752
+ keep = outer[i];
3753
+ }
3754
+ }
3755
+ }
3756
+ const combinedCoords = [keep];
3659
3757
  for (let i = 0; i < inner.length; i++) {
3660
- combinedCoords.push(inner[i]);
3758
+ // A hole belonging to a piece that was just discarded is no longer inside anything,
3759
+ // and a hole crossing the boundary is what tears the fill.
3760
+ if (isRingInsideRing(inner[i], keep)) {
3761
+ combinedCoords.push(inner[i]);
3762
+ }
3661
3763
  }
3662
3764
  // Add the combined coordinates to the collection
3663
3765
  const polygon = {
@@ -3805,6 +3907,30 @@ function unionFeature(feature) {
3805
3907
  feature.geometry = collection;
3806
3908
  }
3807
3909
  }
3910
+ function ringArea(ring) {
3911
+ let sum = 0;
3912
+ for (let i = 0; i < ring.length; i++) {
3913
+ const a = ring[i];
3914
+ const b = ring[(i + 1) % ring.length];
3915
+ sum += a[0] * b[1] - b[0] * a[1];
3916
+ }
3917
+ return sum / 2;
3918
+ }
3919
+ function isRingInsideRing(inner, outer) {
3920
+ for (let i = 0; i < inner.length; i++) {
3921
+ let inside = false;
3922
+ for (let a = 0, b = outer.length - 1; a < outer.length; b = a++) {
3923
+ if ((outer[a][1] > inner[i][1]) !== (outer[b][1] > inner[i][1])
3924
+ && inner[i][0] < (outer[b][0] - outer[a][0]) * (inner[i][1] - outer[a][1]) / (outer[b][1] - outer[a][1]) + outer[a][0]) {
3925
+ inside = !inside;
3926
+ }
3927
+ }
3928
+ if (!inside) {
3929
+ return false;
3930
+ }
3931
+ }
3932
+ return true;
3933
+ }
3808
3934
  function dedupeCoordinates(inputCoords) {
3809
3935
  return inputCoords.map(ring => {
3810
3936
  if (ring.length < 2) {
@@ -43383,7 +43509,7 @@ var StyleUtils;
43383
43509
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
43384
43510
  })(StyleUtils || (StyleUtils = {}));
43385
43511
 
43386
- const VERSION = "7.1.5";
43512
+ const VERSION = "7.1.6";
43387
43513
  /**
43388
43514
  * Updates the environment instance used by bruce-cesium to one specified.
43389
43515
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.