bruce-cesium 2.6.4 → 2.6.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.
@@ -1713,7 +1713,7 @@
1713
1713
  }
1714
1714
  function getName(api, entity) {
1715
1715
  return __awaiter(this, void 0, void 0, function () {
1716
- var typeId, type, name_1, e_1;
1716
+ var typeId, type, name_1, e_1, hideError, error, code;
1717
1717
  return __generator(this, function (_a) {
1718
1718
  switch (_a.label) {
1719
1719
  case 0:
@@ -1740,7 +1740,18 @@
1740
1740
  return [3 /*break*/, 4];
1741
1741
  case 3:
1742
1742
  e_1 = _a.sent();
1743
- console.error(e_1);
1743
+ hideError = false;
1744
+ // TODO: we need a util for extracting code + message rather than writing all this every time.
1745
+ if (e_1 && typeof e_1 == "object" && e_1.ERROR) {
1746
+ error = e_1.ERROR;
1747
+ code = error && typeof error == "object" ? error.Code : "";
1748
+ // Avoiding logging a common error.
1749
+ // This happens when rendering entities that don't have records.
1750
+ hideError = String(code).toLowerCase() == "notfound";
1751
+ }
1752
+ if (!hideError) {
1753
+ console.error(e_1);
1754
+ }
1744
1755
  return [3 /*break*/, 4];
1745
1756
  case 4: return [2 /*return*/, "Unknown entity"];
1746
1757
  }
@@ -5738,17 +5749,20 @@
5738
5749
  (function (EntitiesLoadedRenderManager) {
5739
5750
  var Manager = /** @class */ (function () {
5740
5751
  function Manager(params) {
5752
+ var _a;
5741
5753
  this.getter = null;
5742
5754
  this.getterSub = null;
5743
5755
  this.disposed = false;
5744
5756
  this.renderedEntities = {};
5745
- this.updatedEntities = {};
5746
5757
  var viewer = params.viewer, apiGetter = params.apiGetter, monitor = params.monitor, item = params.item, visualsManager = params.register;
5747
5758
  this.viewer = viewer;
5748
5759
  this.apiGetter = apiGetter;
5749
5760
  this.monitor = monitor;
5750
5761
  this.item = item;
5751
5762
  this.visualsManager = visualsManager;
5763
+ if (!((_a = this.item.BruceEntity) === null || _a === void 0 ? void 0 : _a.Entities)) {
5764
+ this.item.BruceEntity = __assign(__assign({}, this.item.BruceEntity), { Entities: [] });
5765
+ }
5752
5766
  }
5753
5767
  Object.defineProperty(Manager.prototype, "Disposed", {
5754
5768
  get: function () {
@@ -5757,8 +5771,75 @@
5757
5771
  enumerable: false,
5758
5772
  configurable: true
5759
5773
  });
5760
- Manager.prototype.Init = function () {
5774
+ /**
5775
+ * Adds entities to menu item and queues the render for them.
5776
+ * If the entity already exists in the menu item, it will be removed and redrawn.
5777
+ * @param params
5778
+ */
5779
+ Manager.prototype.AddEntities = function (params) {
5780
+ var _this = this;
5781
+ if (this.disposed) {
5782
+ throw (new Error("This item is disposed."));
5783
+ }
5784
+ var entities = params.entities;
5785
+ entities.forEach(function (x) {
5786
+ var _a;
5787
+ // If already in the menu item we'll first remove it.
5788
+ // That way we're using the latest provided data.
5789
+ var entityId = (_a = x.Bruce) === null || _a === void 0 ? void 0 : _a.ID;
5790
+ var index = _this.item.BruceEntity.Entities.findIndex(function (y) { var _a; return ((_a = y === null || y === void 0 ? void 0 : y.Bruce) === null || _a === void 0 ? void 0 : _a.ID) == entityId; });
5791
+ if (index > -1) {
5792
+ _this.item.BruceEntity.Entities.splice(index, 1);
5793
+ }
5794
+ _this.item.BruceEntity.Entities.push(x);
5795
+ });
5796
+ this.ReRender({
5797
+ entities: entities,
5798
+ entityIds: entities.map(function (x) { var _a; return (_a = x.Bruce) === null || _a === void 0 ? void 0 : _a.ID; }),
5799
+ force: true
5800
+ });
5801
+ this.recreateGetter();
5802
+ };
5803
+ /**
5804
+ * Removes entities from the menu item that match provided IDs.
5805
+ * Any visuals will be removed as well.
5806
+ * @param params
5807
+ */
5808
+ Manager.prototype.RemoveEntities = function (params) {
5761
5809
  var _this = this;
5810
+ if (this.disposed) {
5811
+ throw (new Error("This item is disposed."));
5812
+ }
5813
+ var entityIds = params.entityIds;
5814
+ entityIds.forEach(function (x) {
5815
+ var index = _this.item.BruceEntity.Entities.findIndex(function (y) { var _a; return ((_a = y === null || y === void 0 ? void 0 : y.Bruce) === null || _a === void 0 ? void 0 : _a.ID) == x; });
5816
+ if (index > -1) {
5817
+ _this.item.BruceEntity.Entities.splice(index, 1);
5818
+ }
5819
+ _this.visualsManager.RemoveRegos({
5820
+ entityId: x,
5821
+ menuItemId: _this.item.id
5822
+ });
5823
+ _this.renderedEntities[x] = false;
5824
+ });
5825
+ this.recreateGetter();
5826
+ };
5827
+ /**
5828
+ * Clears all entities from the menu item.
5829
+ * Any visuals will be removed as well.
5830
+ */
5831
+ Manager.prototype.ClearEntities = function () {
5832
+ if (this.disposed) {
5833
+ throw (new Error("This item is disposed."));
5834
+ }
5835
+ this.item.BruceEntity.Entities = [];
5836
+ this.visualsManager.RemoveRegos({
5837
+ menuItemId: this.item.id
5838
+ });
5839
+ this.renderedEntities = {};
5840
+ this.recreateGetter();
5841
+ };
5842
+ Manager.prototype.Init = function () {
5762
5843
  var _a;
5763
5844
  if (this.disposed) {
5764
5845
  throw (new Error("This item is disposed."));
@@ -5775,6 +5856,17 @@
5775
5856
  }
5776
5857
  ];
5777
5858
  }
5859
+ this.recreateGetter();
5860
+ };
5861
+ /**
5862
+ * Recreates the getter for the entities.
5863
+ * This is used when the entities within the menu item are updated.
5864
+ * @todo: this causes a bad side-effect where all menu item entities are queued for a re-render.
5865
+ */
5866
+ Manager.prototype.recreateGetter = function () {
5867
+ var _this = this;
5868
+ var _a;
5869
+ (_a = this.getterSub) === null || _a === void 0 ? void 0 : _a.call(this);
5778
5870
  this.getter = new bruceModels.BatchedDataGetter.Getter(this.item.BruceEntity.Entities, this.monitor, BATCH_SIZE$1);
5779
5871
  this.getterSub = this.getter.OnUpdate.Subscribe(function (entities) {
5780
5872
  var _a;
@@ -5821,10 +5913,6 @@
5821
5913
  }
5822
5914
  if (entities === null || entities === void 0 ? void 0 : entities.length) {
5823
5915
  entities = [].concat(entities).filter(function (x) { var _a; return entityIds.includes((_a = x.Bruce) === null || _a === void 0 ? void 0 : _a.ID); });
5824
- entities.forEach(function (x) {
5825
- var _a;
5826
- _this.updatedEntities[(_a = x.Bruce) === null || _a === void 0 ? void 0 : _a.ID] = x;
5827
- });
5828
5916
  }
5829
5917
  this.visualsManager.MarkStale({
5830
5918
  entityIds: entityIds,
@@ -5875,7 +5963,6 @@
5875
5963
  if (!(ids.length > 0)) return [3 /*break*/, 4];
5876
5964
  checkBatch = function () { return __awaiter(_this, void 0, void 0, function () {
5877
5965
  var entityIds, entities;
5878
- var _this = this;
5879
5966
  return __generator(this, function (_a) {
5880
5967
  switch (_a.label) {
5881
5968
  case 0:
@@ -5889,10 +5976,6 @@
5889
5976
  if (this.disposed) {
5890
5977
  return [2 /*return*/];
5891
5978
  }
5892
- entities.forEach(function (x) {
5893
- var _a;
5894
- _this.updatedEntities[(_a = x.Bruce) === null || _a === void 0 ? void 0 : _a.ID] = x;
5895
- });
5896
5979
  this.onGetterUpdate(entities, force);
5897
5980
  return [2 /*return*/];
5898
5981
  }
@@ -5919,7 +6002,8 @@
5919
6002
  var _a;
5920
6003
  if (force === void 0) { force = false; }
5921
6004
  return __awaiter(this, void 0, void 0, function () {
5922
- var cEntities, i, entity, id, cEntity, visual, e_2;
6005
+ var isEntityInItem_1, cEntities, i, entity, id, cEntity, visual, e_2;
6006
+ var _this = this;
5923
6007
  return __generator(this, function (_b) {
5924
6008
  switch (_b.label) {
5925
6009
  case 0:
@@ -5927,6 +6011,16 @@
5927
6011
  if (this.disposed || this.viewer.isDestroyed()) {
5928
6012
  return [2 /*return*/];
5929
6013
  }
6014
+ isEntityInItem_1 = function (entityId) {
6015
+ var _a, _b;
6016
+ return (_b = (_a = _this.item.BruceEntity) === null || _a === void 0 ? void 0 : _a.Entities) === null || _b === void 0 ? void 0 : _b.find(function (y) { var _a; return ((_a = y === null || y === void 0 ? void 0 : y.Bruce) === null || _a === void 0 ? void 0 : _a.ID) == entityId; });
6017
+ };
6018
+ // Filter out entities that aren't in the menu item.
6019
+ // This can happen if the menu item is updated while the getter is running.
6020
+ entities = entities.filter(function (x) {
6021
+ var _a;
6022
+ return isEntityInItem_1((_a = x === null || x === void 0 ? void 0 : x.Bruce) === null || _a === void 0 ? void 0 : _a.ID);
6023
+ });
5930
6024
  return [4 /*yield*/, exports.EntityRenderEngine.Render({
5931
6025
  viewer: this.viewer,
5932
6026
  apiGetter: this.apiGetter,
@@ -5943,7 +6037,7 @@
5943
6037
  id = entity.Bruce.ID;
5944
6038
  cEntity = cEntities[id];
5945
6039
  this.renderedEntities[id] = !!cEntity;
5946
- if (cEntity) {
6040
+ if (cEntity && isEntityInItem_1(id)) {
5947
6041
  visual = (_a = this.visualsManager.GetRego({
5948
6042
  entityId: id,
5949
6043
  menuItemId: this.item.id
@@ -15022,7 +15116,7 @@
15022
15116
  ViewerUtils.CreateWidgets = CreateWidgets;
15023
15117
  })(exports.ViewerUtils || (exports.ViewerUtils = {}));
15024
15118
 
15025
- var VERSION$1 = "2.6.4";
15119
+ var VERSION$1 = "2.6.6";
15026
15120
 
15027
15121
  exports.VERSION = VERSION$1;
15028
15122
  exports.CesiumViewMonitor = CesiumViewMonitor;