bruce-cesium 4.1.7 → 4.1.8

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, ProjectViewTile, DelayQueue, ZoomControl, Style, EntityTag, Calculator, EntityLod, EntityType, ClientFile, ObjectUtils, Bounds, Api, EntityRelationType, ENVIRONMENT, EntityHistoricData, EntityCoords, EntitySource, MenuItem, EntityRelation, ProgramKey, AbstractApi, ProjectViewBookmark, EntityAttachment, EntityAttachmentType, EntityAttribute, ProjectView, ProjectViewLegacyTile, Camera } from 'bruce-models';
2
2
  import * as Cesium from 'cesium';
3
- import { Cartographic, Cartesian2, Math as Math$1, Cartesian3, CallbackProperty, Color, HeightReference, Rectangle, JulianDate, DistanceDisplayCondition, NearFarScalar, Model, ColorMaterialProperty, Entity, HorizontalOrigin, VerticalOrigin, ConstantProperty, ConstantPositionProperty, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, ColorBlendMode, HeadingPitchRoll, Transforms, Primitive, Cesium3DTileFeature, SceneMode, GeoJsonDataSource, Cesium3DTileColorBlendMode, HeadingPitchRange, Ion, Cesium3DTileStyle, KmlDataSource, SceneTransforms, OrthographicFrustum, EasingFunction, EllipsoidTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, IonImageryProvider, CesiumTerrainProvider, Cesium3DTileset, Matrix4, Matrix3, IonResource, CesiumInspector, defined, ClockRange, EllipsoidGeodesic, sampleTerrainMostDetailed, PolygonPipeline, BoundingSphere, GeometryInstance, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, ScreenSpaceEventHandler, ScreenSpaceEventType, CzmlDataSource, Quaternion, Intersect } from 'cesium';
3
+ import { Cartographic, Cartesian2, Math as Math$1, Cartesian3, CallbackProperty, Color, HeightReference, Rectangle, JulianDate, SceneMode, Entity, Primitive, Cesium3DTileFeature, DistanceDisplayCondition, NearFarScalar, Model, ColorMaterialProperty, HorizontalOrigin, VerticalOrigin, ConstantProperty, ConstantPositionProperty, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, ColorBlendMode, HeadingPitchRoll, Transforms, GeoJsonDataSource, Cesium3DTileColorBlendMode, HeadingPitchRange, Ion, Cesium3DTileStyle, KmlDataSource, SceneTransforms, OrthographicFrustum, EasingFunction, EllipsoidTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, IonImageryProvider, CesiumTerrainProvider, CesiumInspector, defined, ClockRange, EllipsoidGeodesic, sampleTerrainMostDetailed, Cesium3DTileset, Matrix4, Matrix3, IonResource, PolygonPipeline, BoundingSphere, GeometryInstance, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, ScreenSpaceEventHandler, ScreenSpaceEventType, CzmlDataSource, Quaternion, Intersect } from 'cesium';
4
4
 
5
5
  /*! *****************************************************************************
6
6
  Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4646,6 +4646,235 @@ function OneTimeError(key, message) {
4646
4646
  }
4647
4647
  }
4648
4648
 
4649
+ /**
4650
+ * Util for simplifying geometry on the fly.
4651
+ */
4652
+ var SimplifyGeometry;
4653
+ (function (SimplifyGeometry) {
4654
+ /**
4655
+ * Returns the total number of points in the geometry.
4656
+ * @param geometry
4657
+ * @returns
4658
+ */
4659
+ function CountPoints(geometry) {
4660
+ var count = 0;
4661
+ var traverse = function (geometry) {
4662
+ if (geometry.MultiGeometry) {
4663
+ for (var i = 0; i < geometry.MultiGeometry.length; i++) {
4664
+ traverse(geometry.MultiGeometry[i]);
4665
+ }
4666
+ }
4667
+ else if (geometry.Polygon) {
4668
+ for (var i = 0; i < geometry.Polygon.length; i++) {
4669
+ var polygon = geometry.Polygon[i];
4670
+ count += Geometry.ParsePoints(polygon.LinearRing).length;
4671
+ }
4672
+ }
4673
+ else if (geometry.LineString) {
4674
+ count += Geometry.ParsePoints(geometry.LineString).length;
4675
+ }
4676
+ else if (geometry.Point) {
4677
+ count += 1;
4678
+ }
4679
+ };
4680
+ traverse(geometry);
4681
+ return count;
4682
+ }
4683
+ SimplifyGeometry.CountPoints = CountPoints;
4684
+ /**
4685
+ * Simplifies input geometry.
4686
+ * This will turn it into GeoJSON, run it through turf, then back to Bruce geometry.
4687
+ * @param geometry
4688
+ */
4689
+ function Simplify(geometry, tolerance) {
4690
+ if (!geometry || tolerance <= 0 || !turf || !turf.simplify) {
4691
+ return geometry;
4692
+ }
4693
+ var geoJson = toGeoJson(geometry);
4694
+ // Union overlapping shapes
4695
+ var combinedFeatures = [];
4696
+ geoJson.features.forEach(function (feature) {
4697
+ var unioned = false;
4698
+ for (var i = 0; i < combinedFeatures.length; i++) {
4699
+ try {
4700
+ var unionResult = turf.union(combinedFeatures[i], feature);
4701
+ if (unionResult) {
4702
+ combinedFeatures[i] = unionResult;
4703
+ unioned = true;
4704
+ break;
4705
+ }
4706
+ }
4707
+ catch (error) {
4708
+ // Ignore the error if union fails, and continue
4709
+ }
4710
+ }
4711
+ if (!unioned) {
4712
+ combinedFeatures.push(feature);
4713
+ }
4714
+ });
4715
+ geoJson = {
4716
+ type: "FeatureCollection",
4717
+ features: combinedFeatures,
4718
+ };
4719
+ // Simplify the combined result.
4720
+ var simplified = turf.simplify(geoJson, { tolerance: tolerance, highQuality: true, mutate: true });
4721
+ return fromGeoJson(simplified);
4722
+ }
4723
+ SimplifyGeometry.Simplify = Simplify;
4724
+ })(SimplifyGeometry || (SimplifyGeometry = {}));
4725
+ /**
4726
+ * Converts Bruce geometry to GeoJSON.
4727
+ * @param geometry
4728
+ * @returns
4729
+ */
4730
+ function toGeoJson(geometry) {
4731
+ var features = [];
4732
+ var excludeAltitude = false;
4733
+ var areCoordinatesEqual = function (coord1, coord2) {
4734
+ return coord1[0] === coord2[0] && coord1[1] === coord2[1] && (coord1[2] === coord2[2] || (coord1.length < 3 && coord2.length < 3));
4735
+ };
4736
+ var removeConsecutiveDuplicates = function (coordinates) {
4737
+ return coordinates.filter(function (coord, index, array) {
4738
+ return index === 0 || !areCoordinatesEqual(coord, array[index - 1]);
4739
+ });
4740
+ };
4741
+ var closePolygonCoordinates = function (coordinates) {
4742
+ if (coordinates.length > 0 && !areCoordinatesEqual(coordinates[0], coordinates[coordinates.length - 1])) {
4743
+ var firstPointCopy = [].concat(coordinates[0]);
4744
+ coordinates.push(firstPointCopy);
4745
+ }
4746
+ return coordinates;
4747
+ };
4748
+ var processGeometry = function (geometry) {
4749
+ var _a, _b;
4750
+ var feature = {
4751
+ type: "Feature",
4752
+ properties: {},
4753
+ geometry: null
4754
+ };
4755
+ if ((_a = geometry.MultiGeometry) === null || _a === void 0 ? void 0 : _a.length) {
4756
+ geometry.MultiGeometry.forEach(function (geo) { return processGeometry(geo); });
4757
+ return;
4758
+ }
4759
+ else if ((_b = geometry.Polygon) === null || _b === void 0 ? void 0 : _b.length) {
4760
+ var sortedPolygons = geometry.Polygon.sort(function (a, b) {
4761
+ return a.Facing === Geometry.EPolygonRingType.Boundaries ? -1 : 1;
4762
+ });
4763
+ var coordinates = sortedPolygons.map(function (polygonRing) {
4764
+ return closePolygonCoordinates(removeConsecutiveDuplicates(polygonRing.LinearRing.split(' ').map(function (coord) {
4765
+ var _a = coord.split(',').map(Number), lon = _a[0], lat = _a[1], alt = _a[2];
4766
+ return [lon, lat, alt !== undefined ? alt : 0];
4767
+ })));
4768
+ });
4769
+ // Check if the polygon has at least 4 points.
4770
+ var isValidPolygon = coordinates.every(function (polygon) { return polygon.length >= 4; });
4771
+ if (!isValidPolygon) {
4772
+ // Perhaps try other geometry instead of returning?
4773
+ return;
4774
+ }
4775
+ feature.geometry = {
4776
+ type: "Polygon",
4777
+ coordinates: coordinates,
4778
+ };
4779
+ }
4780
+ else if (geometry.LineString) {
4781
+ var coordinates = removeConsecutiveDuplicates(geometry.LineString.split(' ').map(function (coord) {
4782
+ var _a = coord.split(',').map(Number), lon = _a[0], lat = _a[1], alt = _a[2];
4783
+ return [lon, lat, alt !== undefined ? alt : 0];
4784
+ }));
4785
+ // Check if the polyline has at least 2 points.
4786
+ if (coordinates.length < 2) {
4787
+ // Perhaps try other geometry instead of returning?
4788
+ return;
4789
+ }
4790
+ feature.geometry = {
4791
+ type: "LineString",
4792
+ coordinates: coordinates,
4793
+ };
4794
+ }
4795
+ else if (geometry.Point) {
4796
+ var _c = geometry.Point.split(',').map(Number), lon = _c[0], lat = _c[1], alt = _c[2];
4797
+ var coordinates = excludeAltitude ? [lon, lat] : [lon, lat, alt !== undefined ? alt : 0];
4798
+ feature.geometry = {
4799
+ type: "Point",
4800
+ coordinates: coordinates,
4801
+ };
4802
+ }
4803
+ if (feature.geometry) {
4804
+ features.push(feature);
4805
+ }
4806
+ };
4807
+ try {
4808
+ processGeometry(geometry);
4809
+ }
4810
+ catch (e) {
4811
+ console.error(e);
4812
+ return null;
4813
+ }
4814
+ var geoJson = {
4815
+ type: "FeatureCollection",
4816
+ features: features,
4817
+ };
4818
+ return geoJson;
4819
+ }
4820
+ /**
4821
+ * Converts GeoJSON to Bruce geometry.
4822
+ * @param geoJson
4823
+ * @returns
4824
+ */
4825
+ function fromGeoJson(geoJson) {
4826
+ if (geoJson.features.length === 0) {
4827
+ return {};
4828
+ }
4829
+ var geometry = {
4830
+ Polygon: [],
4831
+ MultiGeometry: []
4832
+ };
4833
+ if (geoJson.features.length > 1) {
4834
+ geoJson.features.forEach(function (feature) {
4835
+ var featureGeometry = fromGeoJson({
4836
+ type: "FeatureCollection",
4837
+ features: [feature]
4838
+ });
4839
+ geometry.MultiGeometry.push(featureGeometry);
4840
+ });
4841
+ return geometry;
4842
+ }
4843
+ var feature = geoJson.features[0];
4844
+ var _a = feature.geometry, type = _a.type, coordinates = _a.coordinates;
4845
+ switch (type) {
4846
+ case "Polygon":
4847
+ coordinates.forEach(function (polygon, index) {
4848
+ var linearRing = polygon.map(function (coord) { return coord.join(','); }).join(' ');
4849
+ geometry.Polygon.push({
4850
+ LinearRing: linearRing,
4851
+ Facing: index === 0 ? Geometry.EPolygonRingType.Boundaries : Geometry.EPolygonRingType.Hole
4852
+ });
4853
+ });
4854
+ break;
4855
+ case "LineString":
4856
+ geometry.LineString = coordinates.map(function (coord) { return coord.join(','); }).join(' ');
4857
+ break;
4858
+ case "Point":
4859
+ geometry.Point = coordinates.join(',');
4860
+ break;
4861
+ case "MultiPolygon":
4862
+ coordinates.forEach(function (multiPolygon) {
4863
+ var multiPolygonGeometry = { Polygon: [] };
4864
+ multiPolygon.forEach(function (polygon, index) {
4865
+ var linearRing = polygon.map(function (coord) { return coord.join(','); }).join(' ');
4866
+ multiPolygonGeometry.Polygon.push({
4867
+ LinearRing: linearRing,
4868
+ Facing: index === 0 ? Geometry.EPolygonRingType.Boundaries : Geometry.EPolygonRingType.Hole
4869
+ });
4870
+ });
4871
+ geometry.MultiGeometry.push(multiPolygonGeometry);
4872
+ });
4873
+ break;
4874
+ }
4875
+ return geometry;
4876
+ }
4877
+
4649
4878
  function colorToCColor(color) {
4650
4879
  return new Color(color.red ? color.red / 255 : 0, color.green ? color.green / 255 : 0, color.blue ? color.blue / 255 : 0, color.alpha);
4651
4880
  }
@@ -5321,7 +5550,7 @@ var EntityRenderEngine;
5321
5550
  function Render(params) {
5322
5551
  var _a, _b, _c, _d, _e, _f, _g;
5323
5552
  return __awaiter(this, void 0, void 0, function () {
5324
- var groupRenderParams, i, entity, geometry, updated, cEntities, models, multiGeometry, polygons, polylines, points, i, entity, id, zoomItem, displayType, existingRego, newRenderId, oldRenderId, geometry, mParams, mEntities, i, entity, id, cEntity, _loop_1, i, pParams, pEntities, i, entity, cEntity, pParams, pEntities, i, entity, cEntity, pParams, pEntities, i, entity, cEntity;
5553
+ var groupRenderParams, i, entity, geometry, optimized, updated, cEntities, models, multiGeometry, polygons, polylines, points, i, entity, id, zoomItem, displayType, existingRego, newRenderId, oldRenderId, geometry, mParams, mEntities, i, entity, id, cEntity, _loop_1, i, pParams, pEntities, i, entity, cEntity, pParams, pEntities, i, entity, cEntity, pParams, pEntities, i, entity, cEntity;
5325
5554
  return __generator(this, function (_h) {
5326
5555
  switch (_h.label) {
5327
5556
  case 0:
@@ -5340,17 +5569,37 @@ var EntityRenderEngine;
5340
5569
  entity: entity,
5341
5570
  path: ["Bruce", "VectorGeometry"]
5342
5571
  });
5343
- if (((_a = geometry === null || geometry === void 0 ? void 0 : geometry.MultiGeometry) === null || _a === void 0 ? void 0 : _a.length) == 1) {
5344
- // Not migrated to internal, set in both places.
5345
- if (entity.geometry) {
5346
- entity.geometry = __assign(__assign(__assign({}, entity.geometry), geometry.MultiGeometry[0]), { MultiGeometry: [] });
5347
- entity.Bruce.VectorGeometry = entity.geometry;
5572
+ // Optimize geometry if requested.
5573
+ // This will attempt to merge and simplify before rendering.
5574
+ // Note that this modifies the Entity object.
5575
+ if (params.optimizeGeometry) {
5576
+ if (params.optimizeMinPoints == null) {
5577
+ params.optimizeMinPoints = 1000;
5348
5578
  }
5349
- // Migrated to internal, we'll set it there.
5350
- else if (entity.Bruce.VectorGeometry) {
5351
- entity.Bruce.VectorGeometry = __assign(__assign(__assign({}, entity.Bruce.VectorGeometry), geometry.MultiGeometry[0]), { MultiGeometry: [] });
5579
+ if (geometry && SimplifyGeometry.CountPoints(geometry) >= params.optimizeMinPoints) {
5580
+ if (params.optimizeTolerance == null) {
5581
+ params.optimizeTolerance = 0.0005;
5582
+ }
5583
+ optimized = SimplifyGeometry.Simplify(geometry, params.optimizeTolerance);
5584
+ if (optimized) {
5585
+ // Continue on with the rendering using the optimized geometry.
5586
+ geometry = optimized;
5587
+ // Dereference the Entity object now that we have done a destructive operation.
5588
+ entity = Object.assign({}, entity);
5589
+ entity.Bruce = Object.assign({}, entity.Bruce);
5590
+ params.entities[i] = entity;
5591
+ }
5352
5592
  }
5353
5593
  }
5594
+ // We are using the new path.
5595
+ // This ensures we don't have a duplicate.
5596
+ entity.geometry = null;
5597
+ if (((_a = geometry === null || geometry === void 0 ? void 0 : geometry.MultiGeometry) === null || _a === void 0 ? void 0 : _a.length) == 1) {
5598
+ entity.Bruce.VectorGeometry = geometry.MultiGeometry[0];
5599
+ }
5600
+ else {
5601
+ entity.Bruce.VectorGeometry = geometry;
5602
+ }
5354
5603
  }
5355
5604
  updated = new Map();
5356
5605
  cEntities = new Map();
@@ -11002,7 +11251,7 @@ var EntitiesRenderManager;
11002
11251
  Manager.prototype.renderAsGeojson = function (entities, force) {
11003
11252
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
11004
11253
  return __awaiter(this, void 0, void 0, function () {
11005
- var zoomItem, lods, withLods_1, individuals, style, e_4, entityTypeId, entityType, e_5, pStyle, lStyle, polygonsClamped, bFillColor, cFillColor, bLineColor, cLineColor, lineWidthPx, geojson, notRendered, source, groups, applyStyle, toForceUpdate, register, sEntities, i, cEntity;
11254
+ var zoomItem, lods, withLods_1, individuals, style, e_4, entityTypeId, entityType, e_5, pStyle, lStyle, polygonsClamped, bFillColor, cFillColor, bLineColor, cLineColor, lineWidthPx, i, entity, geometry, optimized, geojson, notRendered, source, groups, applyStyle, toForceUpdate, register, sEntities, i, cEntity;
11006
11255
  var _this = this;
11007
11256
  return __generator(this, function (_o) {
11008
11257
  switch (_o.label) {
@@ -11120,6 +11369,39 @@ var EntitiesRenderManager;
11120
11369
  lineWidthPx = 0;
11121
11370
  }
11122
11371
  lineWidthPx = Math.round(lineWidthPx);
11372
+ // If we are flagged to optimize then we'll run through and simplify each entity's geometry.
11373
+ if (this.item.optimizeGeometry) {
11374
+ for (i = 0; i < entities.length; i++) {
11375
+ entity = entities[i];
11376
+ geometry = Entity$1.GetValue({
11377
+ entity: entity,
11378
+ path: ["Bruce", "VectorGeometry"]
11379
+ });
11380
+ if (geometry) {
11381
+ if (this.item.optimizeMinPoints == null) {
11382
+ this.item.optimizeMinPoints = 1000;
11383
+ }
11384
+ if (SimplifyGeometry.CountPoints(geometry) > this.item.optimizeMinPoints) {
11385
+ if (this.item.optimizeTolerance == null) {
11386
+ this.item.optimizeTolerance = 0.0005;
11387
+ }
11388
+ optimized = SimplifyGeometry.Simplify(geometry, this.item.optimizeTolerance);
11389
+ if (optimized) {
11390
+ // Dereference the Entity object now that we have done a destructive operation.
11391
+ entity = Object.assign({}, entity);
11392
+ entity.Bruce = Object.assign({}, entity.Bruce);
11393
+ entities[i] = entity;
11394
+ // Continue on with the rendering using the optimized geometry.
11395
+ geometry = optimized;
11396
+ }
11397
+ }
11398
+ }
11399
+ // We are using the new path.
11400
+ // This ensures we don't have a duplicate.
11401
+ entity.geometry = null;
11402
+ entity.Bruce.VectorGeometry = geometry;
11403
+ }
11404
+ }
11123
11405
  geojson = Entity$1.ToGeoJson({
11124
11406
  entities: entities,
11125
11407
  includeUserData: false,
@@ -11353,7 +11635,10 @@ var EntitiesRenderManager;
11353
11635
  visualRegister: this.visualsManager,
11354
11636
  zoomControl: this.item.CameraZoomSettings,
11355
11637
  entitiesHistoric: entitiesHistoric,
11356
- force: force
11638
+ force: force,
11639
+ optimizeGeometry: this.item.optimizeGeometry,
11640
+ optimizeMinPoints: this.item.optimizeMinPoints,
11641
+ optimizeTolerance: this.item.optimizeTolerance,
11357
11642
  })];
11358
11643
  case 3:
11359
11644
  _m = _o.sent(), updated = _m.updated, cEntities = _m.entities;
@@ -25324,7 +25609,7 @@ var ViewRenderEngine;
25324
25609
  ViewRenderEngine.Render = Render;
25325
25610
  })(ViewRenderEngine || (ViewRenderEngine = {}));
25326
25611
 
25327
- var VERSION = "4.1.7";
25612
+ var VERSION = "4.1.8";
25328
25613
 
25329
25614
  export { VERSION, CesiumViewMonitor, ViewerUtils, MenuItemManager, EntityRenderEngine, MenuItemCreator, VisualsRegister, RenderManager, EntitiesIdsRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, TilesetCadRenderManager, TilesetArbRenderManager, TilesetEntitiesRenderManager, TilesetOsmRenderManager, TilesetPointcloudRenderManager, TilesetGooglePhotosRenderManager, DataSourceStaticKmlManager, GoogleSearchRenderManager, RelationsRenderManager, SharedGetters, CesiumParabola, EntityLabel, ViewRenderEngine, TileRenderEngine, TilesetRenderEngine, CESIUM_INSPECTOR_KEY, CESIUM_TIMELINE_KEY, ViewUtils, DrawingUtils, MeasureUtils, EntityUtils, CesiumEntityStyler, CesiumAnimatedProperty, CesiumAnimatedInOut, Draw3dPolygon, Draw3dPolyline };
25330
25615
  //# sourceMappingURL=bruce-cesium.es5.js.map