bruce-cesium 4.2.0 → 4.2.1

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.
@@ -4636,11 +4636,6 @@
4636
4636
  }
4637
4637
  }
4638
4638
 
4639
- // Hash of input geometry to the simplified geometry.
4640
- var _cache = new bruceModels.LRUCache(1000);
4641
- function getHash(entityId, geometry) {
4642
- return bruceModels.EncryptUtils.Cyrb53Hash(entityId + JSON.stringify(geometry));
4643
- }
4644
4639
  /**
4645
4640
  * Util for simplifying geometry on the fly.
4646
4641
  */
@@ -4691,11 +4686,6 @@
4691
4686
  if (!geometry || !turf || !turf.simplify) {
4692
4687
  return geometry;
4693
4688
  }
4694
- // Generate unique hash for the geometry.
4695
- var hash = getHash(entityId, geometry);
4696
- if (_cache.Get(hash)) {
4697
- return _cache.Get(hash);
4698
- }
4699
4689
  // Convert to geojson so that we can interact with turf.
4700
4690
  var gFeature = bruceModels.Geometry.ToGeoJsonFeature({
4701
4691
  geometry: geometry
@@ -4719,9 +4709,6 @@
4719
4709
  geometry = (_a = bruceModels.Geometry.FromGeoJson({
4720
4710
  geoJson: gFeature
4721
4711
  })) === null || _a === void 0 ? void 0 : _a.geometry;
4722
- // Store cached result to avoid recalculating.
4723
- // Hashing a large geometry string is slow, but all these operations are slower.
4724
- _cache.Set(hash, geometry);
4725
4712
  return geometry;
4726
4713
  }
4727
4714
  SimplifyGeometry.Simplify = Simplify;
@@ -4742,22 +4729,49 @@
4742
4729
  try {
4743
4730
  // Dedupe the coordinates to avoid issues with unkink.
4744
4731
  coords = dedupeCoordinates(coords);
4745
- var tmpFeature = turf.polygon(coords);
4746
- var untangled = turf.unkinkPolygon(tmpFeature);
4747
- if (untangled.features.length) {
4748
- if (untangled.type == "FeatureCollection") {
4749
- for (var i = 0; i < untangled.features.length; i++) {
4750
- collection.geometries.push(untangled.features[i].geometry);
4732
+ var outer = [];
4733
+ var inner = [];
4734
+ // We'll unkink each ring separately as this is killing the holes when it is done as a whole.
4735
+ // So we'll do it separate then recombine.
4736
+ for (var i = 0; i < coords.length; i++) {
4737
+ var ring = coords[i];
4738
+ var unkink = turf.unkinkPolygon({
4739
+ type: "Polygon",
4740
+ coordinates: [ring]
4741
+ });
4742
+ if (unkink.type == "FeatureCollection") {
4743
+ var target = i == 0 ? outer : inner;
4744
+ for (var j = 0; j < unkink.features.length; j++) {
4745
+ var unkinked = unkink.features[j].geometry.coordinates;
4746
+ if (unkinked.length > 0) {
4747
+ target.push(unkinked[0]);
4748
+ }
4751
4749
  }
4752
- return true;
4753
4750
  }
4754
4751
  else {
4755
- console.error("Unexpected unkink result.", untangled);
4752
+ console.error("Unexpected unkink result.", unkink);
4753
+ }
4754
+ }
4755
+ // Recreate the rings and reapply to the collection.
4756
+ if (outer.length > 0) {
4757
+ var combinedCoords = [outer[0]];
4758
+ for (var i = 0; i < inner.length; i++) {
4759
+ combinedCoords.push(inner[i]);
4756
4760
  }
4761
+ // Add the combined coordinates to the collection
4762
+ var polygon = {
4763
+ type: "Polygon",
4764
+ coordinates: combinedCoords
4765
+ };
4766
+ // Ensure right-hand rule is followed.
4767
+ ensureRightHandRule(polygon);
4768
+ // Add to the collection.
4769
+ collection.geometries.push(polygon);
4770
+ return true;
4757
4771
  }
4758
4772
  }
4759
4773
  catch (e) {
4760
- console.error("Failed to unkink polygon.", e);
4774
+ // console.error("Failed to unkink polygon.", e);
4761
4775
  }
4762
4776
  return false;
4763
4777
  };
@@ -4879,7 +4893,7 @@
4879
4893
  }
4880
4894
  }
4881
4895
  catch (e) {
4882
- console.error("Failed to union polygons.", e);
4896
+ // console.error("Failed to union polygons.", e);
4883
4897
  return;
4884
4898
  }
4885
4899
  // Re-assign the geometry.
@@ -4915,6 +4929,31 @@
4915
4929
  return dedupeCoords;
4916
4930
  });
4917
4931
  }
4932
+ function ensureRightHandRule(polygon) {
4933
+ // Ensure the outer ring follows the right-hand rule
4934
+ if (polygon.coordinates.length > 0) {
4935
+ var outerRing = polygon.coordinates[0];
4936
+ if (isClockwise(outerRing)) {
4937
+ polygon.coordinates[0] = outerRing.reverse();
4938
+ }
4939
+ }
4940
+ // Ensure any inner rings (holes) follow the right-hand rule
4941
+ for (var i = 1; i < polygon.coordinates.length; i++) {
4942
+ var innerRing = polygon.coordinates[i];
4943
+ if (!isClockwise(innerRing)) {
4944
+ polygon.coordinates[i] = innerRing.reverse();
4945
+ }
4946
+ }
4947
+ }
4948
+ function isClockwise(ring) {
4949
+ var sum = 0;
4950
+ for (var i = 0; i < ring.length - 1; i++) {
4951
+ var p1 = ring[i];
4952
+ var p2 = ring[i + 1];
4953
+ sum += (p2[0] - p1[0]) * (p2[1] + p1[1]);
4954
+ }
4955
+ return sum > 0;
4956
+ }
4918
4957
 
4919
4958
  function colorToCColor(color) {
4920
4959
  return new Cesium.Color(color.red ? color.red / 255 : 0, color.green ? color.green / 255 : 0, color.blue ? color.blue / 255 : 0, color.alpha);
@@ -5588,11 +5627,11 @@
5588
5627
  }
5589
5628
  (function (EntityRenderEngine) {
5590
5629
  function Render(params) {
5591
- var _a, _b, _c, _d, _e, _f, _g;
5630
+ var _a, _b, _c, _d, _e, _f;
5592
5631
  return __awaiter(this, void 0, void 0, function () {
5593
- 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;
5594
- return __generator(this, function (_h) {
5595
- switch (_h.label) {
5632
+ var groupRenderParams, updated, cEntities, models, multiGeometry, polygons, polylines, points, prepareGeometry, 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;
5633
+ return __generator(this, function (_g) {
5634
+ switch (_g.label) {
5596
5635
  case 0:
5597
5636
  groupRenderParams = {
5598
5637
  apiGetter: params.apiGetter,
@@ -5602,10 +5641,16 @@
5602
5641
  menuItemId: params.menuItemId,
5603
5642
  visualRegister: params.visualRegister
5604
5643
  };
5605
- // Flatten multi-geometry if it's only got 1 piece.
5606
- for (i = 0; i < params.entities.length; i++) {
5607
- entity = params.entities[i];
5608
- geometry = bruceModels.Entity.GetValue({
5644
+ updated = new Map();
5645
+ cEntities = new Map();
5646
+ models = [];
5647
+ multiGeometry = [];
5648
+ polygons = [];
5649
+ polylines = [];
5650
+ points = [];
5651
+ prepareGeometry = function (entity) {
5652
+ var _a;
5653
+ var geometry = bruceModels.Entity.GetValue({
5609
5654
  entity: entity,
5610
5655
  path: ["Bruce", "VectorGeometry"]
5611
5656
  });
@@ -5620,14 +5665,13 @@
5620
5665
  if (params.optimizeTolerance == null) {
5621
5666
  params.optimizeTolerance = 0.00001;
5622
5667
  }
5623
- optimized = SimplifyGeometry.Simplify(entity.Bruce.ID, geometry, params.optimizeTolerance);
5668
+ var optimized = SimplifyGeometry.Simplify(entity.Bruce.ID, geometry, params.optimizeTolerance);
5624
5669
  if (optimized) {
5625
5670
  // Continue on with the rendering using the optimized geometry.
5626
5671
  geometry = optimized;
5627
5672
  // Dereference the Entity object now that we have done a destructive operation.
5628
5673
  entity = Object.assign({}, entity);
5629
5674
  entity.Bruce = Object.assign({}, entity.Bruce);
5630
- params.entities[i] = entity;
5631
5675
  }
5632
5676
  }
5633
5677
  }
@@ -5640,14 +5684,8 @@
5640
5684
  else {
5641
5685
  entity.Bruce.VectorGeometry = geometry;
5642
5686
  }
5643
- }
5644
- updated = new Map();
5645
- cEntities = new Map();
5646
- models = [];
5647
- multiGeometry = [];
5648
- polygons = [];
5649
- polylines = [];
5650
- points = [];
5687
+ return entity;
5688
+ };
5651
5689
  // Initial sorting.
5652
5690
  for (i = 0; i < params.entities.length; i++) {
5653
5691
  entity = params.entities[i];
@@ -5671,12 +5709,12 @@
5671
5709
  menuItemId: params.menuItemId
5672
5710
  });
5673
5711
  newRenderId = getRenderGroupId(zoomItem);
5674
- oldRenderId = (_b = existingRego === null || existingRego === void 0 ? void 0 : existingRego.visual) === null || _b === void 0 ? void 0 : _b._renderGroup;
5712
+ oldRenderId = (_a = existingRego === null || existingRego === void 0 ? void 0 : existingRego.visual) === null || _a === void 0 ? void 0 : _a._renderGroup;
5675
5713
  if (!params.force &&
5676
5714
  newRenderId == oldRenderId &&
5677
5715
  !(existingRego === null || existingRego === void 0 ? void 0 : existingRego.stale) &&
5678
5716
  // If historic metadata is different then it's also stale.
5679
- ((existingRego === null || existingRego === void 0 ? void 0 : existingRego.historicDateTime) == ((_c = entity.Bruce) === null || _c === void 0 ? void 0 : _c.HistoricDateTime))) {
5717
+ ((existingRego === null || existingRego === void 0 ? void 0 : existingRego.historicDateTime) == ((_b = entity.Bruce) === null || _b === void 0 ? void 0 : _b.HistoricDateTime))) {
5680
5718
  // No sorting category needed. Already rendered the way we want.
5681
5719
  cEntities.set(id, existingRego.visual);
5682
5720
  }
@@ -5687,20 +5725,22 @@
5687
5725
  // Flag as no longer stale as we're unlikely to recreate the rego if we're reusing the graphic.
5688
5726
  existingRego.stale = false;
5689
5727
  // Update metadata for the same reason.
5690
- existingRego.historicDateTime = (_d = entity.Bruce) === null || _d === void 0 ? void 0 : _d.HistoricDateTime;
5691
- existingRego.historicAttrKey = (_e = entity.Bruce) === null || _e === void 0 ? void 0 : _e.HistoricAttrKey;
5728
+ existingRego.historicDateTime = (_c = entity.Bruce) === null || _c === void 0 ? void 0 : _c.HistoricDateTime;
5729
+ existingRego.historicAttrKey = (_d = entity.Bruce) === null || _d === void 0 ? void 0 : _d.HistoricAttrKey;
5692
5730
  existingRego.entityTypeId = entity.Bruce["EntityType.ID"];
5693
5731
  updated.set(id, true);
5694
5732
  }
5695
5733
  if (displayType == bruceModels.ZoomControl.EDisplayType.Model3D) {
5734
+ entity = params.entities[i] = prepareGeometry(entity);
5696
5735
  models.push(entity);
5697
5736
  }
5698
5737
  else if (displayType == bruceModels.ZoomControl.EDisplayType.Geometry) {
5738
+ entity = params.entities[i] = prepareGeometry(entity);
5699
5739
  geometry = bruceModels.Entity.GetValue({
5700
5740
  entity: entity,
5701
5741
  path: ["Bruce", "VectorGeometry"]
5702
5742
  });
5703
- if ((_f = geometry === null || geometry === void 0 ? void 0 : geometry.MultiGeometry) === null || _f === void 0 ? void 0 : _f.length) {
5743
+ if ((_e = geometry === null || geometry === void 0 ? void 0 : geometry.MultiGeometry) === null || _e === void 0 ? void 0 : _e.length) {
5704
5744
  multiGeometry.push(entity);
5705
5745
  }
5706
5746
  else {
@@ -5718,7 +5758,7 @@
5718
5758
  mParams = __assign(__assign({}, groupRenderParams), { rendered: cEntities, entities: models, entitiesHistoric: params.entitiesHistoric });
5719
5759
  return [4 /*yield*/, Model3d.RenderGroup(mParams)];
5720
5760
  case 1:
5721
- mEntities = _h.sent();
5761
+ mEntities = _g.sent();
5722
5762
  for (i = 0; i < mParams.entities.length; i++) {
5723
5763
  entity = mParams.entities[i];
5724
5764
  id = entity.Bruce.ID;
@@ -5730,20 +5770,20 @@
5730
5770
  multiGeometry.push(entity);
5731
5771
  }
5732
5772
  }
5733
- _h.label = 2;
5773
+ _g.label = 2;
5734
5774
  case 2:
5735
5775
  if (!(multiGeometry.length > 0)) return [3 /*break*/, 6];
5736
5776
  _loop_1 = function (i) {
5737
5777
  var entity, geometry, pParams, zoomItem, j, subEntity, cPoly, rendered, cLines, cPoints, rootEntity_1, firstEntity;
5738
- return __generator(this, function (_j) {
5739
- switch (_j.label) {
5778
+ return __generator(this, function (_h) {
5779
+ switch (_h.label) {
5740
5780
  case 0:
5741
5781
  entity = multiGeometry[i];
5742
5782
  geometry = bruceModels.Entity.GetValue({
5743
5783
  entity: entity,
5744
5784
  path: ["Bruce", "VectorGeometry"]
5745
5785
  });
5746
- if (!((_g = geometry === null || geometry === void 0 ? void 0 : geometry.MultiGeometry) === null || _g === void 0 ? void 0 : _g.length)) {
5786
+ if (!((_f = geometry === null || geometry === void 0 ? void 0 : geometry.MultiGeometry) === null || _f === void 0 ? void 0 : _f.length)) {
5747
5787
  polygons.push(entity);
5748
5788
  return [2 /*return*/, "continue"];
5749
5789
  }
@@ -5757,7 +5797,7 @@
5757
5797
  }
5758
5798
  return [4 /*yield*/, Polygon.RenderGroup(pParams)];
5759
5799
  case 1:
5760
- cPoly = _j.sent();
5800
+ cPoly = _h.sent();
5761
5801
  Array.from(cPoly.keys()).forEach(function (key) {
5762
5802
  if (cPoly.get(key)) {
5763
5803
  pParams.entities = pParams.entities.filter(function (e) { return e.Bruce.ID != key; });
@@ -5766,7 +5806,7 @@
5766
5806
  rendered = Array.from(cPoly.values());
5767
5807
  return [4 /*yield*/, Polyline.RenderGroup(pParams)];
5768
5808
  case 2:
5769
- cLines = _j.sent();
5809
+ cLines = _h.sent();
5770
5810
  Array.from(cLines.keys()).forEach(function (key) {
5771
5811
  if (cLines.get(key)) {
5772
5812
  pParams.entities = pParams.entities.filter(function (e) { return e.Bruce.ID != key; });
@@ -5776,9 +5816,9 @@
5776
5816
  if (!!rendered.length) return [3 /*break*/, 4];
5777
5817
  return [4 /*yield*/, Point.RenderGroup(pParams)];
5778
5818
  case 3:
5779
- cPoints = _j.sent();
5819
+ cPoints = _h.sent();
5780
5820
  rendered = rendered.concat(Array.from(cPoints.values()));
5781
- _j.label = 4;
5821
+ _h.label = 4;
5782
5822
  case 4:
5783
5823
  rendered = rendered.filter(function (x) { return x != null; });
5784
5824
  if (rendered.length) {
@@ -5805,13 +5845,13 @@
5805
5845
  });
5806
5846
  };
5807
5847
  i = 0;
5808
- _h.label = 3;
5848
+ _g.label = 3;
5809
5849
  case 3:
5810
5850
  if (!(i < multiGeometry.length)) return [3 /*break*/, 6];
5811
5851
  return [5 /*yield**/, _loop_1(i)];
5812
5852
  case 4:
5813
- _h.sent();
5814
- _h.label = 5;
5853
+ _g.sent();
5854
+ _g.label = 5;
5815
5855
  case 5:
5816
5856
  i++;
5817
5857
  return [3 /*break*/, 3];
@@ -5820,7 +5860,7 @@
5820
5860
  pParams = __assign(__assign({}, groupRenderParams), { entities: polygons, rendered: cEntities });
5821
5861
  return [4 /*yield*/, Polygon.RenderGroup(pParams)];
5822
5862
  case 7:
5823
- pEntities = _h.sent();
5863
+ pEntities = _g.sent();
5824
5864
  for (i = 0; i < pParams.entities.length; i++) {
5825
5865
  entity = pParams.entities[i];
5826
5866
  cEntity = pEntities.get(entity.Bruce.ID);
@@ -5831,13 +5871,13 @@
5831
5871
  polylines.push(entity);
5832
5872
  }
5833
5873
  }
5834
- _h.label = 8;
5874
+ _g.label = 8;
5835
5875
  case 8:
5836
5876
  if (!(polylines.length > 0)) return [3 /*break*/, 10];
5837
5877
  pParams = __assign(__assign({}, groupRenderParams), { entities: polylines, rendered: cEntities });
5838
5878
  return [4 /*yield*/, Polyline.RenderGroup(pParams)];
5839
5879
  case 9:
5840
- pEntities = _h.sent();
5880
+ pEntities = _g.sent();
5841
5881
  for (i = 0; i < pParams.entities.length; i++) {
5842
5882
  entity = pParams.entities[i];
5843
5883
  cEntity = pEntities.get(entity.Bruce.ID);
@@ -5848,13 +5888,13 @@
5848
5888
  points.push(entity);
5849
5889
  }
5850
5890
  }
5851
- _h.label = 10;
5891
+ _g.label = 10;
5852
5892
  case 10:
5853
5893
  if (!(points.length > 0)) return [3 /*break*/, 12];
5854
5894
  pParams = __assign(__assign({}, groupRenderParams), { entities: points, rendered: cEntities, entitiesHistoric: params.entitiesHistoric });
5855
5895
  return [4 /*yield*/, Point.RenderGroup(pParams)];
5856
5896
  case 11:
5857
- pEntities = _h.sent();
5897
+ pEntities = _g.sent();
5858
5898
  for (i = 0; i < pParams.entities.length; i++) {
5859
5899
  entity = pParams.entities[i];
5860
5900
  cEntity = pEntities.get(entity.Bruce.ID);
@@ -5862,7 +5902,7 @@
5862
5902
  cEntities.set(entity.Bruce.ID, cEntity);
5863
5903
  }
5864
5904
  }
5865
- _h.label = 12;
5905
+ _g.label = 12;
5866
5906
  case 12: return [2 /*return*/, {
5867
5907
  entities: cEntities,
5868
5908
  updated: updated
@@ -6776,6 +6816,7 @@
6776
6816
  var points = bruceModels.Geometry.ParsePoints(x.LinearRing);
6777
6817
  var holePosses = points.map(function (x) { return Cesium.Cartesian3.fromDegrees(EnsureNumber(x.longitude), EnsureNumber(x.latitude), EnsureNumber(x.altitude)); });
6778
6818
  holePosses = cullDuplicatePoints(holePosses);
6819
+ bruceModels.Cartes.CloseRing3(holePosses);
6779
6820
  return holePosses;
6780
6821
  }).filter(function (x) { return x.length >= 4; });
6781
6822
  var zIndex = getZIndex(style, entity, params.tags);
@@ -25644,7 +25685,7 @@
25644
25685
  ViewRenderEngine.Render = Render;
25645
25686
  })(exports.ViewRenderEngine || (exports.ViewRenderEngine = {}));
25646
25687
 
25647
- var VERSION = "4.2.0";
25688
+ var VERSION = "4.2.1";
25648
25689
 
25649
25690
  exports.VERSION = VERSION;
25650
25691
  exports.CesiumParabola = CesiumParabola;