bruce-cesium 3.3.9 → 3.4.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.
@@ -8461,12 +8461,12 @@
8461
8461
  * @param force TODO: This should re-render entities that are already rendered.
8462
8462
  */
8463
8463
  Manager.prototype.renderAsGeojson = function (entities, force) {
8464
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
8464
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
8465
8465
  return __awaiter(this, void 0, void 0, function () {
8466
- var zoomItem, style, e_4, entityType, e_5, pStyle, lStyle, polygonsClamped, bFillColor, cFillColor, bLineColor, cLineColor, lineWidthPx, geojson, source, groups, applyStyle, register, sEntities, i, cEntity;
8466
+ var zoomItem, style, e_4, entityTypeId, entityType, e_5, pStyle, lStyle, polygonsClamped, bFillColor, cFillColor, bLineColor, cLineColor, lineWidthPx, geojson, source, groups, applyStyle, register, sEntities, i, cEntity;
8467
8467
  var _this = this;
8468
- return __generator(this, function (_k) {
8469
- switch (_k.label) {
8468
+ return __generator(this, function (_m) {
8469
+ switch (_m.label) {
8470
8470
  case 0:
8471
8471
  entities = entities.filter(function (entity) {
8472
8472
  var _a;
@@ -8479,47 +8479,54 @@
8479
8479
  });
8480
8480
  zoomItem = this.item.CameraZoomSettings[0];
8481
8481
  style = null;
8482
- if (!(zoomItem === null || zoomItem === void 0 ? void 0 : zoomItem.StyleID)) return [3 /*break*/, 4];
8483
- _k.label = 1;
8482
+ if (!((zoomItem === null || zoomItem === void 0 ? void 0 : zoomItem.StyleID) && (zoomItem === null || zoomItem === void 0 ? void 0 : zoomItem.StyleID) > -1)) return [3 /*break*/, 4];
8483
+ _m.label = 1;
8484
8484
  case 1:
8485
- _k.trys.push([1, 3, , 4]);
8485
+ _m.trys.push([1, 3, , 4]);
8486
8486
  return [4 /*yield*/, bruceModels.Style.Get({
8487
8487
  api: this.apiGetter.getApi(),
8488
8488
  styleId: zoomItem === null || zoomItem === void 0 ? void 0 : zoomItem.StyleID
8489
8489
  })];
8490
8490
  case 2:
8491
- style = (_a = (_k.sent()).style) === null || _a === void 0 ? void 0 : _a.Settings;
8491
+ style = (_a = (_m.sent()).style) === null || _a === void 0 ? void 0 : _a.Settings;
8492
8492
  return [3 /*break*/, 4];
8493
8493
  case 3:
8494
- e_4 = _k.sent();
8494
+ e_4 = _m.sent();
8495
8495
  console.error(e_4);
8496
8496
  return [3 /*break*/, 4];
8497
8497
  case 4:
8498
- _k.trys.push([4, 8, , 9]);
8498
+ entityTypeId = (_b = this.item.BruceEntity) === null || _b === void 0 ? void 0 : _b["EntityType.ID"];
8499
+ if (!entityTypeId) {
8500
+ entityTypeId = (_d = (_c = entities.find(function (x) { var _a; return !!((_a = x.Bruce) === null || _a === void 0 ? void 0 : _a["EntityType.ID"]); })) === null || _c === void 0 ? void 0 : _c.Bruce) === null || _d === void 0 ? void 0 : _d["EntityType.ID"];
8501
+ }
8502
+ if (!entityTypeId) return [3 /*break*/, 10];
8503
+ _m.label = 5;
8504
+ case 5:
8505
+ _m.trys.push([5, 9, , 10]);
8499
8506
  return [4 /*yield*/, bruceModels.EntityType.Get({
8500
- entityTypeId: this.item.BruceEntity["EntityType.ID"],
8507
+ entityTypeId: entityTypeId,
8501
8508
  api: this.apiGetter.getApi()
8502
8509
  })];
8503
- case 5:
8504
- entityType = (_b = (_k.sent())) === null || _b === void 0 ? void 0 : _b.entityType;
8505
- if (!(!style && ((_c = this.item.BruceEntity) === null || _c === void 0 ? void 0 : _c["EntityType.ID"]))) return [3 /*break*/, 7];
8506
- if (!entityType["DisplaySetting.ID"]) return [3 /*break*/, 7];
8510
+ case 6:
8511
+ entityType = (_e = (_m.sent())) === null || _e === void 0 ? void 0 : _e.entityType;
8512
+ if (!(!style && entityType)) return [3 /*break*/, 8];
8513
+ if (!(entityType["DisplaySetting.ID"] && entityType["DisplaySetting.ID"] > 0)) return [3 /*break*/, 8];
8507
8514
  return [4 /*yield*/, bruceModels.Style.Get({
8508
8515
  api: this.apiGetter.getApi(),
8509
8516
  styleId: entityType["DisplaySetting.ID"]
8510
8517
  })];
8511
- case 6:
8512
- style = (_d = (_k.sent()).style) === null || _d === void 0 ? void 0 : _d.Settings;
8513
- _k.label = 7;
8514
- case 7: return [3 /*break*/, 9];
8515
- case 8:
8516
- e_5 = _k.sent();
8517
- console.error(e_5);
8518
- return [3 /*break*/, 9];
8518
+ case 7:
8519
+ style = (_f = (_m.sent()).style) === null || _f === void 0 ? void 0 : _f.Settings;
8520
+ _m.label = 8;
8521
+ case 8: return [3 /*break*/, 10];
8519
8522
  case 9:
8520
- pStyle = (_e = style === null || style === void 0 ? void 0 : style.polygonStyle) !== null && _e !== void 0 ? _e : {};
8521
- lStyle = (_f = style === null || style === void 0 ? void 0 : style.polylineStyle) !== null && _f !== void 0 ? _f : {};
8522
- polygonsClamped = ((_g = pStyle === null || pStyle === void 0 ? void 0 : pStyle.altitudeOption) === null || _g === void 0 ? void 0 : _g.id) == null ? true : ((_h = pStyle === null || pStyle === void 0 ? void 0 : pStyle.altitudeOption) === null || _h === void 0 ? void 0 : _h.id) == 0;
8523
+ e_5 = _m.sent();
8524
+ console.error(e_5);
8525
+ return [3 /*break*/, 10];
8526
+ case 10:
8527
+ pStyle = (_g = style === null || style === void 0 ? void 0 : style.polygonStyle) !== null && _g !== void 0 ? _g : {};
8528
+ lStyle = (_h = style === null || style === void 0 ? void 0 : style.polylineStyle) !== null && _h !== void 0 ? _h : {};
8529
+ polygonsClamped = ((_j = pStyle === null || pStyle === void 0 ? void 0 : pStyle.altitudeOption) === null || _j === void 0 ? void 0 : _j.id) == null ? true : ((_k = pStyle === null || pStyle === void 0 ? void 0 : pStyle.altitudeOption) === null || _k === void 0 ? void 0 : _k.id) == 0;
8523
8530
  bFillColor = bruceModels.Calculator.GetColor(pStyle.fillColor, {}, []);
8524
8531
  cFillColor = bFillColor ? colorToCColor$2(bFillColor) : Cesium.Color.fromCssColorString("rgba(139, 195, 74, 0.8)");
8525
8532
  bLineColor = bruceModels.Calculator.GetColor(pStyle.lineColor, {}, []);
@@ -8541,7 +8548,7 @@
8541
8548
  // No points.
8542
8549
  allowedDisplayTypes: [bruceModels.ZoomControl.EDisplayType.Geometry]
8543
8550
  });
8544
- if (!((_j = geojson === null || geojson === void 0 ? void 0 : geojson.features) === null || _j === void 0 ? void 0 : _j.length)) {
8551
+ if (!((_l = geojson === null || geojson === void 0 ? void 0 : geojson.features) === null || _l === void 0 ? void 0 : _l.length)) {
8545
8552
  return [2 /*return*/];
8546
8553
  }
8547
8554
  return [4 /*yield*/, Cesium.GeoJsonDataSource.load(geojson, {
@@ -8550,8 +8557,8 @@
8550
8557
  strokeWidth: lineWidthPx,
8551
8558
  clampToGround: lineWidthPx <= 0 && polygonsClamped
8552
8559
  })];
8553
- case 10:
8554
- source = _k.sent();
8560
+ case 11:
8561
+ source = _m.sent();
8555
8562
  this.viewer.dataSources.add(source);
8556
8563
  this.sources.push(source);
8557
8564
  if (this.disposed) {
@@ -8627,6 +8634,7 @@
8627
8634
  if (!entityId) {
8628
8635
  return;
8629
8636
  }
8637
+ var needsUpdate = false;
8630
8638
  // Find group for the nextspace entity ID.
8631
8639
  group = groups.find(function (x) { return x.entityId == entityId; });
8632
8640
  // No group yet. We can designate this as the primary entity and create a new group for it.
@@ -8649,11 +8657,11 @@
8649
8657
  entityTypeId: group.entityTypeId,
8650
8658
  accountId: _this.apiGetter.accountId,
8651
8659
  tagIds: group.tagIds ? [].concat(group.tagIds) : [],
8652
- name: (_d = bruceModels.Entity.CalculateName({
8660
+ name: entityType ? (_d = bruceModels.Entity.CalculateName({
8653
8661
  entity: group.data,
8654
8662
  type: entityType,
8655
8663
  defaultToId: false
8656
- })) !== null && _d !== void 0 ? _d : "Unnamed Entity",
8664
+ })) !== null && _d !== void 0 ? _d : "Unnamed Entity" : "Unnamed Entity",
8657
8665
  cdn: _this.item.cdnEnabled,
8658
8666
  collection: source.entities
8659
8667
  };
@@ -8672,9 +8680,15 @@
8672
8680
  _this.visualsManager.RefreshMark({
8673
8681
  rego: group.rego
8674
8682
  });
8683
+ needsUpdate = true;
8675
8684
  }
8676
8685
  }
8677
8686
  applyStyle(thing, entityId, group.data);
8687
+ if (needsUpdate) {
8688
+ _this.visualsManager.ForceUpdate({
8689
+ entityIds: [entityId],
8690
+ });
8691
+ }
8678
8692
  };
8679
8693
  sEntities = source.entities.values;
8680
8694
  for (i = 0; i < sEntities.length; i++) {
@@ -8860,6 +8874,15 @@
8860
8874
 
8861
8875
  var BATCH_SIZE$1 = 500;
8862
8876
  var CHECK_BATCH_SIZE$1 = 250;
8877
+ function getValue$4(viewer, obj) {
8878
+ if (obj === null || obj === void 0 ? void 0 : obj.getValue) {
8879
+ return obj.getValue(viewer.scene.lastRenderTime);
8880
+ }
8881
+ return obj;
8882
+ }
8883
+ function colorToCColor$3(color) {
8884
+ return new Cesium.Color(color.red ? color.red / 255 : 0, color.green ? color.green / 255 : 0, color.blue ? color.blue / 255 : 0, color.alpha);
8885
+ }
8863
8886
  (function (EntitiesLoadedRenderManager) {
8864
8887
  var Manager = /** @class */ (function () {
8865
8888
  function Manager(params) {
@@ -8868,12 +8891,17 @@
8868
8891
  this.getterSub = null;
8869
8892
  this.disposed = false;
8870
8893
  this.renderedEntities = {};
8894
+ this.sources = [];
8895
+ // Highly experimental flag to try improve rendering large sets of polygons and polylines.
8896
+ // Many things are not supported when this is enabled.
8897
+ this.useGeojson = false;
8871
8898
  var viewer = params.viewer, apiGetter = params.apiGetter, monitor = params.monitor, item = params.item, visualsManager = params.register;
8872
8899
  this.viewer = viewer;
8873
8900
  this.apiGetter = apiGetter;
8874
8901
  this.monitor = monitor;
8875
8902
  this.item = item;
8876
8903
  this.visualsManager = visualsManager;
8904
+ this.useGeojson = item.renderAsGeojson == true;
8877
8905
  if (!((_a = this.item.BruceEntity) === null || _a === void 0 ? void 0 : _a.Entities)) {
8878
8906
  this.item.BruceEntity = __assign(__assign({}, this.item.BruceEntity), { Entities: [] });
8879
8907
  }
@@ -8995,16 +9023,24 @@
8995
9023
  this.getter.Start();
8996
9024
  };
8997
9025
  Manager.prototype.Dispose = function () {
8998
- var _a;
8999
9026
  if (this.disposed) {
9000
9027
  return;
9001
9028
  }
9029
+ this.doDispose();
9030
+ };
9031
+ Manager.prototype.doDispose = function () {
9032
+ var _a;
9002
9033
  (_a = this.getterSub) === null || _a === void 0 ? void 0 : _a.call(this);
9003
9034
  this.getterSub = null;
9004
9035
  this.disposed = true;
9005
9036
  this.visualsManager.RemoveRegos({
9006
9037
  menuItemId: this.item.id
9007
9038
  });
9039
+ for (var i = 0; i < this.sources.length; i++) {
9040
+ var source = this.sources[i];
9041
+ this.viewer.dataSources.remove(source);
9042
+ }
9043
+ this.sources = [];
9008
9044
  };
9009
9045
  Manager.prototype.ReRender = function (params) {
9010
9046
  return __awaiter(this, void 0, void 0, function () {
@@ -9113,15 +9149,14 @@
9113
9149
  });
9114
9150
  };
9115
9151
  Manager.prototype.onGetterUpdate = function (entities, force) {
9116
- var _a;
9117
9152
  if (force === void 0) { force = false; }
9118
9153
  return __awaiter(this, void 0, void 0, function () {
9119
- var isEntityInItem_1, cEntities, i, entity, id, cEntity, visual, e_2;
9154
+ var isEntityInItem_1, e_2;
9120
9155
  var _this = this;
9121
- return __generator(this, function (_b) {
9122
- switch (_b.label) {
9156
+ return __generator(this, function (_a) {
9157
+ switch (_a.label) {
9123
9158
  case 0:
9124
- _b.trys.push([0, 2, , 3]);
9159
+ _a.trys.push([0, 5, , 6]);
9125
9160
  if (this.disposed || this.viewer.isDestroyed()) {
9126
9161
  return [2 /*return*/];
9127
9162
  }
@@ -9135,196 +9170,499 @@
9135
9170
  var _a;
9136
9171
  return isEntityInItem_1((_a = x === null || x === void 0 ? void 0 : x.Bruce) === null || _a === void 0 ? void 0 : _a.ID);
9137
9172
  });
9138
- return [4 /*yield*/, exports.EntityRenderEngine.Render({
9139
- viewer: this.viewer,
9140
- apiGetter: this.apiGetter,
9141
- entities: entities,
9142
- menuItemId: this.item.id,
9143
- visualRegister: this.visualsManager,
9144
- zoomControl: this.item.CameraZoomSettings,
9145
- force: force
9146
- })];
9173
+ if (!this.useGeojson) return [3 /*break*/, 2];
9174
+ return [4 /*yield*/, this.renderAsGeojson(entities, force)];
9147
9175
  case 1:
9148
- cEntities = _b.sent();
9149
- if (this.disposed) {
9150
- this.visualsManager.RemoveRegos({
9151
- menuItemId: this.item.id
9152
- });
9153
- return [2 /*return*/];
9154
- }
9155
- for (i = 0; i < entities.length; i++) {
9156
- entity = entities[i];
9157
- id = entity.Bruce.ID;
9158
- cEntity = cEntities[id];
9159
- this.renderedEntities[id] = !!cEntity;
9160
- if (cEntity && isEntityInItem_1(id)) {
9161
- visual = (_a = this.visualsManager.GetRego({
9162
- entityId: id,
9163
- menuItemId: this.item.id
9164
- })) === null || _a === void 0 ? void 0 : _a.visual;
9165
- if (!visual || visual != cEntity) {
9166
- this.visualsManager.AddRego({
9167
- rego: {
9168
- entityId: id,
9169
- menuItemId: this.item.id,
9170
- visual: cEntity,
9171
- priority: 0,
9172
- entityTypeId: entity.Bruce["EntityType.ID"],
9173
- accountId: this.apiGetter.accountId,
9174
- name: cEntity.name
9175
- },
9176
- requestRender: false
9177
- });
9178
- }
9179
- }
9180
- else {
9181
- this.visualsManager.RemoveRegos({
9182
- entityId: id,
9183
- menuItemId: this.item.id,
9184
- requestRender: false
9185
- });
9186
- }
9187
- }
9188
- this.viewer.scene.requestRender();
9189
- return [3 /*break*/, 3];
9190
- case 2:
9191
- e_2 = _b.sent();
9176
+ _a.sent();
9177
+ return [3 /*break*/, 4];
9178
+ case 2: return [4 /*yield*/, this.renderAsIndividuals(entities, force)];
9179
+ case 3:
9180
+ _a.sent();
9181
+ _a.label = 4;
9182
+ case 4: return [3 /*break*/, 6];
9183
+ case 5:
9184
+ e_2 = _a.sent();
9192
9185
  console.error(e_2);
9193
- return [3 /*break*/, 3];
9194
- case 3: return [2 /*return*/];
9186
+ return [3 /*break*/, 6];
9187
+ case 6: return [2 /*return*/];
9195
9188
  }
9196
9189
  });
9197
9190
  });
9198
9191
  };
9199
- return Manager;
9200
- }());
9201
- EntitiesLoadedRenderManager.Manager = Manager;
9202
- })(exports.EntitiesLoadedRenderManager || (exports.EntitiesLoadedRenderManager = {}));
9203
-
9204
- var BATCH_SIZE$2 = 500;
9205
- (function (EntitiesIdsRenderManager) {
9206
- var Manager = /** @class */ (function () {
9207
- function Manager(params) {
9208
- var _a;
9209
- this.getter = null;
9210
- this.getterSub = null;
9211
- this.disposed = false;
9212
- this.renderedEntities = {};
9213
- var viewer = params.viewer, apiGetter = params.apiGetter, monitor = params.monitor, item = params.item, visualsManager = params.register;
9214
- this.viewer = viewer;
9215
- this.apiGetter = apiGetter;
9216
- this.monitor = monitor;
9217
- this.item = item;
9218
- this.visualsManager = visualsManager;
9219
- if (this.item.enableClustering) {
9220
- this.clustering = new PointClustering(visualsManager, this.item.id, (_a = this.item) === null || _a === void 0 ? void 0 : _a.clustering);
9221
- }
9222
- }
9223
- Object.defineProperty(Manager.prototype, "Disposed", {
9224
- get: function () {
9225
- return this.disposed;
9226
- },
9227
- enumerable: false,
9228
- configurable: true
9229
- });
9230
- Manager.prototype.Init = function () {
9231
- var _this = this;
9232
- var _a;
9233
- if (this.disposed) {
9234
- throw (new Error("This item is disposed."));
9235
- }
9236
- if (!((_a = this.item.CameraZoomSettings) === null || _a === void 0 ? void 0 : _a.length)) {
9237
- this.item.CameraZoomSettings = [
9238
- {
9239
- MinZoom: 0,
9240
- MaxZoom: 100000,
9241
- DisplayType: bruceModels.ZoomControl.EDisplayType.Model3D,
9242
- LODCategoryID: "glb",
9243
- LODLevel: 0,
9244
- StyleID: 0
9245
- }
9246
- ];
9247
- }
9248
- this.getter = new BatchedDataGetter.Getter(this.item.BruceEntity.EntityIds, this.monitor, BATCH_SIZE$2);
9249
- this.getterSub = this.getter.OnUpdate.Subscribe(function (ids) {
9250
- _this.onGetterUpdate(ids);
9251
- });
9252
- this.getter.Start();
9253
- };
9254
- Manager.prototype.Dispose = function () {
9255
- var _a, _b;
9256
- if (this.disposed) {
9257
- return;
9258
- }
9259
- (_a = this.getterSub) === null || _a === void 0 ? void 0 : _a.call(this);
9260
- this.getterSub = null;
9261
- this.disposed = true;
9262
- this.visualsManager.RemoveRegos({
9263
- menuItemId: this.item.id
9264
- });
9265
- (_b = this.clustering) === null || _b === void 0 ? void 0 : _b.Dispose();
9266
- };
9267
- Manager.prototype.ReRender = function (params) {
9192
+ /**
9193
+ * Our optimized and more stable path.
9194
+ * We construct a geojson that we draw in one go.
9195
+ * @param entities
9196
+ * @param force TODO: This should re-render entities that are already rendered.
9197
+ */
9198
+ Manager.prototype.renderAsGeojson = function (entities, force) {
9199
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
9268
9200
  return __awaiter(this, void 0, void 0, function () {
9269
- var entityIds, force, entities;
9201
+ var zoomItem, style, e_3, entityTypeId, entityType, e_4, pStyle, lStyle, polygonsClamped, bFillColor, cFillColor, bLineColor, cLineColor, lineWidthPx, geojson, source, groups, applyStyle, register, sEntities, i, cEntity;
9270
9202
  var _this = this;
9271
- return __generator(this, function (_a) {
9272
- entityIds = params.entityIds, force = params.force, entities = params.entities;
9273
- if (entities && !entityIds) {
9274
- entityIds = entities.map(function (x) { var _a; return (_a = x.Bruce) === null || _a === void 0 ? void 0 : _a.ID; });
9275
- }
9276
- if (entityIds == null) {
9277
- entityIds = Object.keys(this.renderedEntities);
9278
- }
9279
- else {
9280
- // ensure entity ids are part of menu item.
9281
- entityIds = entityIds.filter(function (x) {
9282
- var _a;
9283
- return (_a = _this.item.BruceEntity) === null || _a === void 0 ? void 0 : _a.EntityIds.includes(x);
9284
- });
9285
- }
9286
- this.visualsManager.MarkStale({
9287
- entityIds: entityIds,
9288
- menuItemIds: [this.item.id]
9289
- });
9290
- if (entities === null || entities === void 0 ? void 0 : entities.length) {
9291
- this.renderEntities([].concat(entities).filter(function (x) { var _a; return entityIds.includes((_a = x.Bruce) === null || _a === void 0 ? void 0 : _a.ID); }), force);
9292
- }
9293
- else {
9294
- this.onGetterUpdate(entityIds, force);
9295
- }
9296
- return [2 /*return*/];
9297
- });
9298
- });
9299
- };
9300
- Manager.prototype.UpdateSettings = function (params) {
9301
- var CameraZoomSettings = params.zoomControl, queueRerender = params.queueRerender;
9302
- if (this.disposed) {
9303
- return;
9304
- }
9305
- if (CameraZoomSettings === null || CameraZoomSettings === void 0 ? void 0 : CameraZoomSettings.length) {
9306
- this.item.CameraZoomSettings = CameraZoomSettings;
9307
- }
9308
- if (queueRerender != false) {
9309
- var entityIds = Object.keys(this.renderedEntities);
9310
- this.visualsManager.MarkStale({
9311
- entityIds: entityIds,
9312
- menuItemIds: [this.item.id]
9313
- });
9314
- this.onGetterUpdate(entityIds);
9315
- }
9316
- };
9317
- Manager.prototype.onGetterUpdate = function (entityIds, force) {
9318
- if (force === void 0) { force = false; }
9319
- return __awaiter(this, void 0, void 0, function () {
9320
- var api, entities, e_1;
9321
- return __generator(this, function (_a) {
9322
- switch (_a.label) {
9203
+ return __generator(this, function (_m) {
9204
+ switch (_m.label) {
9323
9205
  case 0:
9324
- if (this.disposed || this.viewer.isDestroyed()) {
9325
- return [2 /*return*/];
9326
- }
9327
- _a.label = 1;
9206
+ entities = entities.filter(function (entity) {
9207
+ var _a;
9208
+ return !_this.renderedEntities[(_a = entity.Bruce) === null || _a === void 0 ? void 0 : _a.ID];
9209
+ });
9210
+ // Mark these as rendered.
9211
+ entities.forEach(function (entity) {
9212
+ var _a;
9213
+ _this.renderedEntities[(_a = entity.Bruce) === null || _a === void 0 ? void 0 : _a.ID] = true;
9214
+ });
9215
+ zoomItem = this.item.CameraZoomSettings[0];
9216
+ style = null;
9217
+ if (!((zoomItem === null || zoomItem === void 0 ? void 0 : zoomItem.StyleID) && (zoomItem === null || zoomItem === void 0 ? void 0 : zoomItem.StyleID) > -1)) return [3 /*break*/, 4];
9218
+ _m.label = 1;
9219
+ case 1:
9220
+ _m.trys.push([1, 3, , 4]);
9221
+ return [4 /*yield*/, bruceModels.Style.Get({
9222
+ api: this.apiGetter.getApi(),
9223
+ styleId: zoomItem === null || zoomItem === void 0 ? void 0 : zoomItem.StyleID
9224
+ })];
9225
+ case 2:
9226
+ style = (_a = (_m.sent()).style) === null || _a === void 0 ? void 0 : _a.Settings;
9227
+ return [3 /*break*/, 4];
9228
+ case 3:
9229
+ e_3 = _m.sent();
9230
+ console.error(e_3);
9231
+ return [3 /*break*/, 4];
9232
+ case 4:
9233
+ entityTypeId = (_b = this.item.BruceEntity) === null || _b === void 0 ? void 0 : _b["EntityType.ID"];
9234
+ if (!entityTypeId) {
9235
+ entityTypeId = (_d = (_c = entities.find(function (x) { var _a; return !!((_a = x.Bruce) === null || _a === void 0 ? void 0 : _a["EntityType.ID"]); })) === null || _c === void 0 ? void 0 : _c.Bruce) === null || _d === void 0 ? void 0 : _d["EntityType.ID"];
9236
+ }
9237
+ if (!entityTypeId) return [3 /*break*/, 10];
9238
+ _m.label = 5;
9239
+ case 5:
9240
+ _m.trys.push([5, 9, , 10]);
9241
+ return [4 /*yield*/, bruceModels.EntityType.Get({
9242
+ entityTypeId: entityTypeId,
9243
+ api: this.apiGetter.getApi()
9244
+ })];
9245
+ case 6:
9246
+ entityType = (_e = (_m.sent())) === null || _e === void 0 ? void 0 : _e.entityType;
9247
+ if (!(!style && entityType)) return [3 /*break*/, 8];
9248
+ if (!(entityType["DisplaySetting.ID"] && entityType["DisplaySetting.ID"] > 0)) return [3 /*break*/, 8];
9249
+ return [4 /*yield*/, bruceModels.Style.Get({
9250
+ api: this.apiGetter.getApi(),
9251
+ styleId: entityType["DisplaySetting.ID"]
9252
+ })];
9253
+ case 7:
9254
+ style = (_f = (_m.sent()).style) === null || _f === void 0 ? void 0 : _f.Settings;
9255
+ _m.label = 8;
9256
+ case 8: return [3 /*break*/, 10];
9257
+ case 9:
9258
+ e_4 = _m.sent();
9259
+ console.error(e_4);
9260
+ return [3 /*break*/, 10];
9261
+ case 10:
9262
+ pStyle = (_g = style === null || style === void 0 ? void 0 : style.polygonStyle) !== null && _g !== void 0 ? _g : {};
9263
+ lStyle = (_h = style === null || style === void 0 ? void 0 : style.polylineStyle) !== null && _h !== void 0 ? _h : {};
9264
+ polygonsClamped = ((_j = pStyle === null || pStyle === void 0 ? void 0 : pStyle.altitudeOption) === null || _j === void 0 ? void 0 : _j.id) == null ? true : ((_k = pStyle === null || pStyle === void 0 ? void 0 : pStyle.altitudeOption) === null || _k === void 0 ? void 0 : _k.id) == 0;
9265
+ bFillColor = bruceModels.Calculator.GetColor(pStyle.fillColor, {}, []);
9266
+ cFillColor = bFillColor ? colorToCColor$3(bFillColor) : Cesium.Color.fromCssColorString("rgba(139, 195, 74, 0.8)");
9267
+ bLineColor = bruceModels.Calculator.GetColor(pStyle.lineColor, {}, []);
9268
+ cLineColor = bLineColor ? colorToCColor$3(bLineColor) : Cesium.Color.fromCssColorString("rgba(80, 80, 80, 0.8)");
9269
+ lineWidthPx = pStyle.lineWidth ? bruceModels.Calculator.GetNumber(pStyle.lineWidth, {}, []) : null;
9270
+ if (lineWidthPx == null) {
9271
+ lineWidthPx = 1;
9272
+ }
9273
+ lineWidthPx = EnsureNumber(lineWidthPx);
9274
+ if (lineWidthPx < 0.01) {
9275
+ lineWidthPx = 0;
9276
+ }
9277
+ lineWidthPx = Math.round(lineWidthPx);
9278
+ geojson = bruceModels.Entity.ToGeoJson({
9279
+ entities: entities,
9280
+ includeUserData: false,
9281
+ excludeAltitude: polygonsClamped && lineWidthPx <= 0,
9282
+ altitude: lineWidthPx > 0 && polygonsClamped ? 1 : null,
9283
+ // No points.
9284
+ allowedDisplayTypes: [bruceModels.ZoomControl.EDisplayType.Geometry]
9285
+ });
9286
+ if (!((_l = geojson === null || geojson === void 0 ? void 0 : geojson.features) === null || _l === void 0 ? void 0 : _l.length)) {
9287
+ return [2 /*return*/];
9288
+ }
9289
+ return [4 /*yield*/, Cesium.GeoJsonDataSource.load(geojson, {
9290
+ stroke: cLineColor,
9291
+ fill: cFillColor,
9292
+ strokeWidth: lineWidthPx,
9293
+ clampToGround: lineWidthPx <= 0 && polygonsClamped
9294
+ })];
9295
+ case 11:
9296
+ source = _m.sent();
9297
+ this.viewer.dataSources.add(source);
9298
+ this.sources.push(source);
9299
+ if (this.disposed) {
9300
+ this.doDispose();
9301
+ return [2 /*return*/];
9302
+ }
9303
+ groups = [];
9304
+ applyStyle = function (thing, entityId, data) {
9305
+ if (thing.polygon) {
9306
+ var bFillColor_1 = bruceModels.Calculator.GetColor(pStyle.fillColor, data, []);
9307
+ var cFillColor_1 = bFillColor_1 ? colorToCColor$3(bFillColor_1) : Cesium.Color.fromCssColorString("rgba(139, 195, 74, 0.8)");
9308
+ var bLineColor_1 = bruceModels.Calculator.GetColor(pStyle.lineColor, data, []);
9309
+ var cLineColor_1 = bLineColor_1 ? colorToCColor$3(bLineColor_1) : Cesium.Color.fromCssColorString("rgba(80, 80, 80, 0.8)");
9310
+ var width = pStyle.lineWidth ? bruceModels.Calculator.GetNumber(pStyle.lineWidth, data, []) : null;
9311
+ if (width == null) {
9312
+ width = 1;
9313
+ }
9314
+ width = EnsureNumber(width);
9315
+ if (width < 0.01) {
9316
+ width = 0;
9317
+ }
9318
+ var curFillColor = getValue$4(_this.viewer, thing.polygon.material);
9319
+ if (curFillColor && curFillColor instanceof Cesium.ColorMaterialProperty) {
9320
+ curFillColor = curFillColor.color;
9321
+ }
9322
+ var curLineColor = getValue$4(_this.viewer, thing.polygon.outlineColor);
9323
+ if (curLineColor && curLineColor instanceof Cesium.ColorMaterialProperty) {
9324
+ curLineColor = curLineColor.color;
9325
+ }
9326
+ var curWidth = getValue$4(_this.viewer, thing.polygon.outlineWidth);
9327
+ if ((curFillColor instanceof Cesium.Color && curFillColor.equals(cFillColor_1)) &&
9328
+ (curLineColor instanceof Cesium.Color && curLineColor.equals(cLineColor_1)) &&
9329
+ curWidth == width) {
9330
+ return;
9331
+ }
9332
+ thing.polygon.material = cFillColor_1;
9333
+ thing.polygon.outlineColor = cLineColor_1;
9334
+ thing.polygon.outlineWidth = width;
9335
+ }
9336
+ else if (thing.polyline) {
9337
+ var bColor = lStyle.lineColor ? bruceModels.Calculator.GetColor(lStyle.lineColor, data, []) : null;
9338
+ var cColor = bColor ? colorToCColor$3(bColor) : Cesium.Color.fromCssColorString("rgba(255, 193, 7, 0.8)");
9339
+ var width = lStyle.lineWidth ? bruceModels.Calculator.GetNumber(lStyle.lineWidth, data, []) : null;
9340
+ if (width == null) {
9341
+ width = 2;
9342
+ }
9343
+ width = EnsureNumber(width);
9344
+ if (width < 0.01) {
9345
+ width = 0;
9346
+ }
9347
+ var curColor = getValue$4(_this.viewer, thing.polyline.material);
9348
+ if (curColor && curColor instanceof Cesium.ColorMaterialProperty) {
9349
+ curColor = curColor.color;
9350
+ }
9351
+ var curWidth = getValue$4(_this.viewer, thing.polyline.width);
9352
+ if ((curColor instanceof Cesium.Color && curColor.equals(cColor)) &&
9353
+ curWidth == width) {
9354
+ return;
9355
+ }
9356
+ thing.polyline.material = cColor;
9357
+ thing.polyline.width = width;
9358
+ }
9359
+ };
9360
+ register = function (thing) {
9361
+ var _a, _b, _c, _d;
9362
+ // See if the cesium entity already exists in a group.
9363
+ var group = groups.find(function (x) { var _a; return ((_a = x.visual) === null || _a === void 0 ? void 0 : _a.id) == thing.id || x.siblings.find(function (x) { return (x === null || x === void 0 ? void 0 : x.id) == thing.id; }); });
9364
+ if (group) {
9365
+ return;
9366
+ }
9367
+ var metadata = getValue$4(_this.viewer, thing === null || thing === void 0 ? void 0 : thing.properties);
9368
+ var entityId = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.Bruce) === null || _a === void 0 ? void 0 : _a.ID;
9369
+ if (!entityId) {
9370
+ return;
9371
+ }
9372
+ var needsUpdate = false;
9373
+ // Find group for the nextspace entity ID.
9374
+ group = groups.find(function (x) { return x.entityId == entityId; });
9375
+ // No group yet. We can designate this as the primary entity and create a new group for it.
9376
+ if (!group) {
9377
+ group = {
9378
+ entityId: entityId,
9379
+ visual: thing,
9380
+ tagIds: (_b = metadata === null || metadata === void 0 ? void 0 : metadata.Bruce) === null || _b === void 0 ? void 0 : _b["Layer.ID"],
9381
+ entityTypeId: (_c = metadata === null || metadata === void 0 ? void 0 : metadata.Bruce) === null || _c === void 0 ? void 0 : _c["EntityType.ID"],
9382
+ siblings: [],
9383
+ data: entities.find(function (x) { var _a; return ((_a = x.Bruce) === null || _a === void 0 ? void 0 : _a.ID) == entityId; }),
9384
+ rego: null
9385
+ };
9386
+ groups.push(group);
9387
+ var rego = {
9388
+ entityId: entityId,
9389
+ menuItemId: _this.item.id,
9390
+ visual: thing,
9391
+ priority: 0,
9392
+ entityTypeId: group.entityTypeId,
9393
+ accountId: _this.apiGetter.accountId,
9394
+ tagIds: group.tagIds ? [].concat(group.tagIds) : [],
9395
+ name: entityType ? (_d = bruceModels.Entity.CalculateName({
9396
+ entity: group.data,
9397
+ type: entityType,
9398
+ defaultToId: false
9399
+ })) !== null && _d !== void 0 ? _d : "Unnamed Entity" : "Unnamed Entity",
9400
+ cdn: _this.item.cdnEnabled,
9401
+ collection: source.entities
9402
+ };
9403
+ group.rego = rego;
9404
+ _this.visualsManager.AddRego({
9405
+ rego: rego,
9406
+ requestRender: false
9407
+ });
9408
+ }
9409
+ // Found a group. We flag this as a sibling entity of the primary.
9410
+ else {
9411
+ group.siblings.push(thing);
9412
+ group.visual._siblingGraphics = group.siblings;
9413
+ thing._parentEntity = group.visual;
9414
+ if (group.rego) {
9415
+ _this.visualsManager.RefreshMark({
9416
+ rego: group.rego
9417
+ });
9418
+ needsUpdate = true;
9419
+ }
9420
+ }
9421
+ applyStyle(thing, entityId, group.data);
9422
+ if (needsUpdate) {
9423
+ _this.visualsManager.ForceUpdate({
9424
+ entityIds: [entityId],
9425
+ });
9426
+ }
9427
+ };
9428
+ sEntities = source.entities.values;
9429
+ for (i = 0; i < sEntities.length; i++) {
9430
+ cEntity = sEntities[i];
9431
+ register(cEntity);
9432
+ }
9433
+ this.viewer.scene.requestRender();
9434
+ return [2 /*return*/];
9435
+ }
9436
+ });
9437
+ });
9438
+ };
9439
+ /**
9440
+ * Our default path.
9441
+ * We render each entity individually.
9442
+ * @param entities
9443
+ * @param force
9444
+ * @returns
9445
+ */
9446
+ Manager.prototype.renderAsIndividuals = function (entities, force) {
9447
+ var _a;
9448
+ if (force === void 0) { force = false; }
9449
+ return __awaiter(this, void 0, void 0, function () {
9450
+ var cEntities, isEntityInItem, i, entity, id, cEntity, visual;
9451
+ var _this = this;
9452
+ return __generator(this, function (_b) {
9453
+ switch (_b.label) {
9454
+ case 0: return [4 /*yield*/, exports.EntityRenderEngine.Render({
9455
+ viewer: this.viewer,
9456
+ apiGetter: this.apiGetter,
9457
+ entities: entities,
9458
+ menuItemId: this.item.id,
9459
+ visualRegister: this.visualsManager,
9460
+ zoomControl: this.item.CameraZoomSettings,
9461
+ force: force
9462
+ })];
9463
+ case 1:
9464
+ cEntities = _b.sent();
9465
+ if (this.disposed) {
9466
+ this.visualsManager.RemoveRegos({
9467
+ menuItemId: this.item.id
9468
+ });
9469
+ return [2 /*return*/];
9470
+ }
9471
+ isEntityInItem = function (entityId) {
9472
+ var _a, _b;
9473
+ 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; });
9474
+ };
9475
+ for (i = 0; i < entities.length; i++) {
9476
+ entity = entities[i];
9477
+ id = entity.Bruce.ID;
9478
+ cEntity = cEntities[id];
9479
+ this.renderedEntities[id] = !!cEntity;
9480
+ if (cEntity && isEntityInItem(id)) {
9481
+ visual = (_a = this.visualsManager.GetRego({
9482
+ entityId: id,
9483
+ menuItemId: this.item.id
9484
+ })) === null || _a === void 0 ? void 0 : _a.visual;
9485
+ if (!visual || visual != cEntity) {
9486
+ this.visualsManager.AddRego({
9487
+ rego: {
9488
+ entityId: id,
9489
+ menuItemId: this.item.id,
9490
+ visual: cEntity,
9491
+ priority: 0,
9492
+ entityTypeId: entity.Bruce["EntityType.ID"],
9493
+ accountId: this.apiGetter.accountId,
9494
+ name: cEntity.name
9495
+ },
9496
+ requestRender: false
9497
+ });
9498
+ }
9499
+ }
9500
+ else {
9501
+ this.visualsManager.RemoveRegos({
9502
+ entityId: id,
9503
+ menuItemId: this.item.id,
9504
+ requestRender: false
9505
+ });
9506
+ }
9507
+ }
9508
+ this.viewer.scene.requestRender();
9509
+ return [2 /*return*/];
9510
+ }
9511
+ });
9512
+ });
9513
+ };
9514
+ return Manager;
9515
+ }());
9516
+ EntitiesLoadedRenderManager.Manager = Manager;
9517
+ })(exports.EntitiesLoadedRenderManager || (exports.EntitiesLoadedRenderManager = {}));
9518
+
9519
+ var BATCH_SIZE$2 = 500;
9520
+ function getValue$5(viewer, obj) {
9521
+ if (obj === null || obj === void 0 ? void 0 : obj.getValue) {
9522
+ return obj.getValue(viewer.scene.lastRenderTime);
9523
+ }
9524
+ return obj;
9525
+ }
9526
+ function colorToCColor$4(color) {
9527
+ return new Cesium.Color(color.red ? color.red / 255 : 0, color.green ? color.green / 255 : 0, color.blue ? color.blue / 255 : 0, color.alpha);
9528
+ }
9529
+ (function (EntitiesIdsRenderManager) {
9530
+ var Manager = /** @class */ (function () {
9531
+ function Manager(params) {
9532
+ var _a;
9533
+ this.getter = null;
9534
+ this.getterSub = null;
9535
+ this.disposed = false;
9536
+ this.renderedEntities = {};
9537
+ this.sources = [];
9538
+ // Highly experimental flag to try improve rendering large sets of polygons and polylines.
9539
+ // Many things are not supported when this is enabled.
9540
+ this.useGeojson = false;
9541
+ var viewer = params.viewer, apiGetter = params.apiGetter, monitor = params.monitor, item = params.item, visualsManager = params.register;
9542
+ this.viewer = viewer;
9543
+ this.apiGetter = apiGetter;
9544
+ this.monitor = monitor;
9545
+ this.item = item;
9546
+ this.visualsManager = visualsManager;
9547
+ this.useGeojson = item.renderAsGeojson == true;
9548
+ if (this.item.enableClustering) {
9549
+ this.clustering = new PointClustering(visualsManager, this.item.id, (_a = this.item) === null || _a === void 0 ? void 0 : _a.clustering);
9550
+ }
9551
+ }
9552
+ Object.defineProperty(Manager.prototype, "Disposed", {
9553
+ get: function () {
9554
+ return this.disposed;
9555
+ },
9556
+ enumerable: false,
9557
+ configurable: true
9558
+ });
9559
+ Manager.prototype.Init = function () {
9560
+ var _this = this;
9561
+ var _a;
9562
+ if (this.disposed) {
9563
+ throw (new Error("This item is disposed."));
9564
+ }
9565
+ if (!((_a = this.item.CameraZoomSettings) === null || _a === void 0 ? void 0 : _a.length)) {
9566
+ this.item.CameraZoomSettings = [
9567
+ {
9568
+ MinZoom: 0,
9569
+ MaxZoom: 100000,
9570
+ DisplayType: bruceModels.ZoomControl.EDisplayType.Model3D,
9571
+ LODCategoryID: "glb",
9572
+ LODLevel: 0,
9573
+ StyleID: 0
9574
+ }
9575
+ ];
9576
+ }
9577
+ this.getter = new BatchedDataGetter.Getter(this.item.BruceEntity.EntityIds, this.monitor, BATCH_SIZE$2);
9578
+ this.getterSub = this.getter.OnUpdate.Subscribe(function (ids) {
9579
+ _this.onGetterUpdate(ids);
9580
+ });
9581
+ this.getter.Start();
9582
+ };
9583
+ Manager.prototype.Dispose = function () {
9584
+ if (this.disposed) {
9585
+ return;
9586
+ }
9587
+ this.doDispose();
9588
+ };
9589
+ Manager.prototype.doDispose = function () {
9590
+ var _a, _b;
9591
+ (_a = this.getterSub) === null || _a === void 0 ? void 0 : _a.call(this);
9592
+ this.getterSub = null;
9593
+ this.disposed = true;
9594
+ this.visualsManager.RemoveRegos({
9595
+ menuItemId: this.item.id
9596
+ });
9597
+ (_b = this.clustering) === null || _b === void 0 ? void 0 : _b.Dispose();
9598
+ this.clustering = null;
9599
+ for (var i = 0; i < this.sources.length; i++) {
9600
+ var source = this.sources[i];
9601
+ this.viewer.dataSources.remove(source);
9602
+ }
9603
+ this.sources = [];
9604
+ };
9605
+ Manager.prototype.ReRender = function (params) {
9606
+ return __awaiter(this, void 0, void 0, function () {
9607
+ var entityIds, force, entities;
9608
+ var _this = this;
9609
+ return __generator(this, function (_a) {
9610
+ entityIds = params.entityIds, force = params.force, entities = params.entities;
9611
+ if (entities && !entityIds) {
9612
+ entityIds = entities.map(function (x) { var _a; return (_a = x.Bruce) === null || _a === void 0 ? void 0 : _a.ID; });
9613
+ }
9614
+ if (entityIds == null) {
9615
+ entityIds = Object.keys(this.renderedEntities);
9616
+ }
9617
+ else {
9618
+ // ensure entity ids are part of menu item.
9619
+ entityIds = entityIds.filter(function (x) {
9620
+ var _a;
9621
+ return (_a = _this.item.BruceEntity) === null || _a === void 0 ? void 0 : _a.EntityIds.includes(x);
9622
+ });
9623
+ }
9624
+ this.visualsManager.MarkStale({
9625
+ entityIds: entityIds,
9626
+ menuItemIds: [this.item.id]
9627
+ });
9628
+ if (entities === null || entities === void 0 ? void 0 : entities.length) {
9629
+ this.renderEntities([].concat(entities).filter(function (x) { var _a; return entityIds.includes((_a = x.Bruce) === null || _a === void 0 ? void 0 : _a.ID); }), force);
9630
+ }
9631
+ else {
9632
+ this.onGetterUpdate(entityIds, force);
9633
+ }
9634
+ return [2 /*return*/];
9635
+ });
9636
+ });
9637
+ };
9638
+ Manager.prototype.UpdateSettings = function (params) {
9639
+ var CameraZoomSettings = params.zoomControl, queueRerender = params.queueRerender;
9640
+ if (this.disposed) {
9641
+ return;
9642
+ }
9643
+ if (CameraZoomSettings === null || CameraZoomSettings === void 0 ? void 0 : CameraZoomSettings.length) {
9644
+ this.item.CameraZoomSettings = CameraZoomSettings;
9645
+ }
9646
+ if (queueRerender != false) {
9647
+ var entityIds = Object.keys(this.renderedEntities);
9648
+ this.visualsManager.MarkStale({
9649
+ entityIds: entityIds,
9650
+ menuItemIds: [this.item.id]
9651
+ });
9652
+ this.onGetterUpdate(entityIds);
9653
+ }
9654
+ };
9655
+ Manager.prototype.onGetterUpdate = function (entityIds, force) {
9656
+ if (force === void 0) { force = false; }
9657
+ return __awaiter(this, void 0, void 0, function () {
9658
+ var api, entities, e_1;
9659
+ return __generator(this, function (_a) {
9660
+ switch (_a.label) {
9661
+ case 0:
9662
+ if (this.disposed || this.viewer.isDestroyed()) {
9663
+ return [2 /*return*/];
9664
+ }
9665
+ _a.label = 1;
9328
9666
  case 1:
9329
9667
  _a.trys.push([1, 4, , 5]);
9330
9668
  api = this.apiGetter.getApi();
@@ -9333,44 +9671,323 @@
9333
9671
  entityIds: entityIds
9334
9672
  })];
9335
9673
  case 2:
9336
- entities = (_a.sent()).entities;
9337
- return [4 /*yield*/, this.renderEntities(entities, force)];
9338
- case 3:
9674
+ entities = (_a.sent()).entities;
9675
+ return [4 /*yield*/, this.renderEntities(entities, force)];
9676
+ case 3:
9677
+ _a.sent();
9678
+ return [3 /*break*/, 5];
9679
+ case 4:
9680
+ e_1 = _a.sent();
9681
+ console.error(e_1);
9682
+ return [3 /*break*/, 5];
9683
+ case 5: return [2 /*return*/];
9684
+ }
9685
+ });
9686
+ });
9687
+ };
9688
+ Manager.prototype.renderEntities = function (entities, force) {
9689
+ if (force === void 0) { force = false; }
9690
+ return __awaiter(this, void 0, void 0, function () {
9691
+ var e_2;
9692
+ return __generator(this, function (_a) {
9693
+ switch (_a.label) {
9694
+ case 0:
9695
+ if (this.disposed || this.viewer.isDestroyed()) {
9696
+ return [2 /*return*/];
9697
+ }
9698
+ _a.label = 1;
9699
+ case 1:
9700
+ _a.trys.push([1, 6, , 7]);
9701
+ if (!this.useGeojson) return [3 /*break*/, 3];
9702
+ return [4 /*yield*/, this.renderAsGeojson(entities, force)];
9703
+ case 2:
9339
9704
  _a.sent();
9340
9705
  return [3 /*break*/, 5];
9706
+ case 3: return [4 /*yield*/, this.renderAsIndividuals(entities, force)];
9341
9707
  case 4:
9342
- e_1 = _a.sent();
9343
- console.error(e_1);
9344
- return [3 /*break*/, 5];
9345
- case 5: return [2 /*return*/];
9708
+ _a.sent();
9709
+ _a.label = 5;
9710
+ case 5: return [3 /*break*/, 7];
9711
+ case 6:
9712
+ e_2 = _a.sent();
9713
+ console.error(e_2);
9714
+ return [3 /*break*/, 7];
9715
+ case 7: return [2 /*return*/];
9346
9716
  }
9347
9717
  });
9348
9718
  });
9349
9719
  };
9350
- Manager.prototype.renderEntities = function (entities, force) {
9720
+ /**
9721
+ * Our optimized and more stable path.
9722
+ * We construct a geojson that we draw in one go.
9723
+ * @param entities
9724
+ * @param force TODO: This should re-render entities that are already rendered.
9725
+ */
9726
+ Manager.prototype.renderAsGeojson = function (entities, force) {
9727
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
9728
+ return __awaiter(this, void 0, void 0, function () {
9729
+ var zoomItem, style, e_3, entityTypeId, entityType, e_4, pStyle, lStyle, polygonsClamped, bFillColor, cFillColor, bLineColor, cLineColor, lineWidthPx, geojson, source, groups, applyStyle, register, sEntities, i, cEntity;
9730
+ var _this = this;
9731
+ return __generator(this, function (_m) {
9732
+ switch (_m.label) {
9733
+ case 0:
9734
+ entities = entities.filter(function (entity) {
9735
+ var _a;
9736
+ return !_this.renderedEntities[(_a = entity.Bruce) === null || _a === void 0 ? void 0 : _a.ID];
9737
+ });
9738
+ // Mark these as rendered.
9739
+ entities.forEach(function (entity) {
9740
+ var _a;
9741
+ _this.renderedEntities[(_a = entity.Bruce) === null || _a === void 0 ? void 0 : _a.ID] = true;
9742
+ });
9743
+ zoomItem = this.item.CameraZoomSettings[0];
9744
+ style = null;
9745
+ if (!((zoomItem === null || zoomItem === void 0 ? void 0 : zoomItem.StyleID) && (zoomItem === null || zoomItem === void 0 ? void 0 : zoomItem.StyleID) > -1)) return [3 /*break*/, 4];
9746
+ _m.label = 1;
9747
+ case 1:
9748
+ _m.trys.push([1, 3, , 4]);
9749
+ return [4 /*yield*/, bruceModels.Style.Get({
9750
+ api: this.apiGetter.getApi(),
9751
+ styleId: zoomItem === null || zoomItem === void 0 ? void 0 : zoomItem.StyleID
9752
+ })];
9753
+ case 2:
9754
+ style = (_a = (_m.sent()).style) === null || _a === void 0 ? void 0 : _a.Settings;
9755
+ return [3 /*break*/, 4];
9756
+ case 3:
9757
+ e_3 = _m.sent();
9758
+ console.error(e_3);
9759
+ return [3 /*break*/, 4];
9760
+ case 4:
9761
+ entityTypeId = (_b = this.item.BruceEntity) === null || _b === void 0 ? void 0 : _b["EntityType.ID"];
9762
+ if (!entityTypeId) {
9763
+ entityTypeId = (_d = (_c = entities.find(function (x) { var _a; return !!((_a = x.Bruce) === null || _a === void 0 ? void 0 : _a["EntityType.ID"]); })) === null || _c === void 0 ? void 0 : _c.Bruce) === null || _d === void 0 ? void 0 : _d["EntityType.ID"];
9764
+ }
9765
+ if (!entityTypeId) return [3 /*break*/, 10];
9766
+ _m.label = 5;
9767
+ case 5:
9768
+ _m.trys.push([5, 9, , 10]);
9769
+ return [4 /*yield*/, bruceModels.EntityType.Get({
9770
+ entityTypeId: entityTypeId,
9771
+ api: this.apiGetter.getApi()
9772
+ })];
9773
+ case 6:
9774
+ entityType = (_e = (_m.sent())) === null || _e === void 0 ? void 0 : _e.entityType;
9775
+ if (!(!style && entityType)) return [3 /*break*/, 8];
9776
+ if (!(entityType["DisplaySetting.ID"] && entityType["DisplaySetting.ID"] > 0)) return [3 /*break*/, 8];
9777
+ return [4 /*yield*/, bruceModels.Style.Get({
9778
+ api: this.apiGetter.getApi(),
9779
+ styleId: entityType["DisplaySetting.ID"]
9780
+ })];
9781
+ case 7:
9782
+ style = (_f = (_m.sent()).style) === null || _f === void 0 ? void 0 : _f.Settings;
9783
+ _m.label = 8;
9784
+ case 8: return [3 /*break*/, 10];
9785
+ case 9:
9786
+ e_4 = _m.sent();
9787
+ console.error(e_4);
9788
+ return [3 /*break*/, 10];
9789
+ case 10:
9790
+ pStyle = (_g = style === null || style === void 0 ? void 0 : style.polygonStyle) !== null && _g !== void 0 ? _g : {};
9791
+ lStyle = (_h = style === null || style === void 0 ? void 0 : style.polylineStyle) !== null && _h !== void 0 ? _h : {};
9792
+ polygonsClamped = ((_j = pStyle === null || pStyle === void 0 ? void 0 : pStyle.altitudeOption) === null || _j === void 0 ? void 0 : _j.id) == null ? true : ((_k = pStyle === null || pStyle === void 0 ? void 0 : pStyle.altitudeOption) === null || _k === void 0 ? void 0 : _k.id) == 0;
9793
+ bFillColor = bruceModels.Calculator.GetColor(pStyle.fillColor, {}, []);
9794
+ cFillColor = bFillColor ? colorToCColor$4(bFillColor) : Cesium.Color.fromCssColorString("rgba(139, 195, 74, 0.8)");
9795
+ bLineColor = bruceModels.Calculator.GetColor(pStyle.lineColor, {}, []);
9796
+ cLineColor = bLineColor ? colorToCColor$4(bLineColor) : Cesium.Color.fromCssColorString("rgba(80, 80, 80, 0.8)");
9797
+ lineWidthPx = pStyle.lineWidth ? bruceModels.Calculator.GetNumber(pStyle.lineWidth, {}, []) : null;
9798
+ if (lineWidthPx == null) {
9799
+ lineWidthPx = 1;
9800
+ }
9801
+ lineWidthPx = EnsureNumber(lineWidthPx);
9802
+ if (lineWidthPx < 0.01) {
9803
+ lineWidthPx = 0;
9804
+ }
9805
+ lineWidthPx = Math.round(lineWidthPx);
9806
+ geojson = bruceModels.Entity.ToGeoJson({
9807
+ entities: entities,
9808
+ includeUserData: false,
9809
+ excludeAltitude: polygonsClamped && lineWidthPx <= 0,
9810
+ altitude: lineWidthPx > 0 && polygonsClamped ? 1 : null,
9811
+ // No points.
9812
+ allowedDisplayTypes: [bruceModels.ZoomControl.EDisplayType.Geometry]
9813
+ });
9814
+ if (!((_l = geojson === null || geojson === void 0 ? void 0 : geojson.features) === null || _l === void 0 ? void 0 : _l.length)) {
9815
+ return [2 /*return*/];
9816
+ }
9817
+ return [4 /*yield*/, Cesium.GeoJsonDataSource.load(geojson, {
9818
+ stroke: cLineColor,
9819
+ fill: cFillColor,
9820
+ strokeWidth: lineWidthPx,
9821
+ clampToGround: lineWidthPx <= 0 && polygonsClamped
9822
+ })];
9823
+ case 11:
9824
+ source = _m.sent();
9825
+ this.viewer.dataSources.add(source);
9826
+ this.sources.push(source);
9827
+ if (this.disposed) {
9828
+ this.doDispose();
9829
+ return [2 /*return*/];
9830
+ }
9831
+ groups = [];
9832
+ applyStyle = function (thing, entityId, data) {
9833
+ if (thing.polygon) {
9834
+ var bFillColor_1 = bruceModels.Calculator.GetColor(pStyle.fillColor, data, []);
9835
+ var cFillColor_1 = bFillColor_1 ? colorToCColor$4(bFillColor_1) : Cesium.Color.fromCssColorString("rgba(139, 195, 74, 0.8)");
9836
+ var bLineColor_1 = bruceModels.Calculator.GetColor(pStyle.lineColor, data, []);
9837
+ var cLineColor_1 = bLineColor_1 ? colorToCColor$4(bLineColor_1) : Cesium.Color.fromCssColorString("rgba(80, 80, 80, 0.8)");
9838
+ var width = pStyle.lineWidth ? bruceModels.Calculator.GetNumber(pStyle.lineWidth, data, []) : null;
9839
+ if (width == null) {
9840
+ width = 1;
9841
+ }
9842
+ width = EnsureNumber(width);
9843
+ if (width < 0.01) {
9844
+ width = 0;
9845
+ }
9846
+ var curFillColor = getValue$5(_this.viewer, thing.polygon.material);
9847
+ if (curFillColor && curFillColor instanceof Cesium.ColorMaterialProperty) {
9848
+ curFillColor = curFillColor.color;
9849
+ }
9850
+ var curLineColor = getValue$5(_this.viewer, thing.polygon.outlineColor);
9851
+ if (curLineColor && curLineColor instanceof Cesium.ColorMaterialProperty) {
9852
+ curLineColor = curLineColor.color;
9853
+ }
9854
+ var curWidth = getValue$5(_this.viewer, thing.polygon.outlineWidth);
9855
+ if ((curFillColor instanceof Cesium.Color && curFillColor.equals(cFillColor_1)) &&
9856
+ (curLineColor instanceof Cesium.Color && curLineColor.equals(cLineColor_1)) &&
9857
+ curWidth == width) {
9858
+ return;
9859
+ }
9860
+ thing.polygon.material = cFillColor_1;
9861
+ thing.polygon.outlineColor = cLineColor_1;
9862
+ thing.polygon.outlineWidth = width;
9863
+ }
9864
+ else if (thing.polyline) {
9865
+ var bColor = lStyle.lineColor ? bruceModels.Calculator.GetColor(lStyle.lineColor, data, []) : null;
9866
+ var cColor = bColor ? colorToCColor$4(bColor) : Cesium.Color.fromCssColorString("rgba(255, 193, 7, 0.8)");
9867
+ var width = lStyle.lineWidth ? bruceModels.Calculator.GetNumber(lStyle.lineWidth, data, []) : null;
9868
+ if (width == null) {
9869
+ width = 2;
9870
+ }
9871
+ width = EnsureNumber(width);
9872
+ if (width < 0.01) {
9873
+ width = 0;
9874
+ }
9875
+ var curColor = getValue$5(_this.viewer, thing.polyline.material);
9876
+ if (curColor && curColor instanceof Cesium.ColorMaterialProperty) {
9877
+ curColor = curColor.color;
9878
+ }
9879
+ var curWidth = getValue$5(_this.viewer, thing.polyline.width);
9880
+ if ((curColor instanceof Cesium.Color && curColor.equals(cColor)) &&
9881
+ curWidth == width) {
9882
+ return;
9883
+ }
9884
+ thing.polyline.material = cColor;
9885
+ thing.polyline.width = width;
9886
+ }
9887
+ };
9888
+ register = function (thing) {
9889
+ var _a, _b, _c, _d;
9890
+ // See if the cesium entity already exists in a group.
9891
+ var group = groups.find(function (x) { var _a; return ((_a = x.visual) === null || _a === void 0 ? void 0 : _a.id) == thing.id || x.siblings.find(function (x) { return (x === null || x === void 0 ? void 0 : x.id) == thing.id; }); });
9892
+ if (group) {
9893
+ return;
9894
+ }
9895
+ var metadata = getValue$5(_this.viewer, thing === null || thing === void 0 ? void 0 : thing.properties);
9896
+ var entityId = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.Bruce) === null || _a === void 0 ? void 0 : _a.ID;
9897
+ if (!entityId) {
9898
+ return;
9899
+ }
9900
+ var needsUpdate = false;
9901
+ // Find group for the nextspace entity ID.
9902
+ group = groups.find(function (x) { return x.entityId == entityId; });
9903
+ // No group yet. We can designate this as the primary entity and create a new group for it.
9904
+ if (!group) {
9905
+ group = {
9906
+ entityId: entityId,
9907
+ visual: thing,
9908
+ tagIds: (_b = metadata === null || metadata === void 0 ? void 0 : metadata.Bruce) === null || _b === void 0 ? void 0 : _b["Layer.ID"],
9909
+ entityTypeId: (_c = metadata === null || metadata === void 0 ? void 0 : metadata.Bruce) === null || _c === void 0 ? void 0 : _c["EntityType.ID"],
9910
+ siblings: [],
9911
+ data: entities.find(function (x) { var _a; return ((_a = x.Bruce) === null || _a === void 0 ? void 0 : _a.ID) == entityId; }),
9912
+ rego: null
9913
+ };
9914
+ groups.push(group);
9915
+ var rego = {
9916
+ entityId: entityId,
9917
+ menuItemId: _this.item.id,
9918
+ visual: thing,
9919
+ priority: 0,
9920
+ entityTypeId: group.entityTypeId,
9921
+ accountId: _this.apiGetter.accountId,
9922
+ tagIds: group.tagIds ? [].concat(group.tagIds) : [],
9923
+ name: entityType ? (_d = bruceModels.Entity.CalculateName({
9924
+ entity: group.data,
9925
+ type: entityType,
9926
+ defaultToId: false
9927
+ })) !== null && _d !== void 0 ? _d : "Unnamed Entity" : "Unnamed Entity",
9928
+ cdn: _this.item.cdnEnabled,
9929
+ collection: source.entities
9930
+ };
9931
+ group.rego = rego;
9932
+ _this.visualsManager.AddRego({
9933
+ rego: rego,
9934
+ requestRender: false
9935
+ });
9936
+ }
9937
+ // Found a group. We flag this as a sibling entity of the primary.
9938
+ else {
9939
+ group.siblings.push(thing);
9940
+ group.visual._siblingGraphics = group.siblings;
9941
+ thing._parentEntity = group.visual;
9942
+ if (group.rego) {
9943
+ _this.visualsManager.RefreshMark({
9944
+ rego: group.rego
9945
+ });
9946
+ needsUpdate = true;
9947
+ }
9948
+ }
9949
+ applyStyle(thing, entityId, group.data);
9950
+ if (needsUpdate) {
9951
+ _this.visualsManager.ForceUpdate({
9952
+ entityIds: [entityId],
9953
+ });
9954
+ }
9955
+ };
9956
+ sEntities = source.entities.values;
9957
+ for (i = 0; i < sEntities.length; i++) {
9958
+ cEntity = sEntities[i];
9959
+ register(cEntity);
9960
+ }
9961
+ this.viewer.scene.requestRender();
9962
+ return [2 /*return*/];
9963
+ }
9964
+ });
9965
+ });
9966
+ };
9967
+ /**
9968
+ * Our default path.
9969
+ * We render each entity individually.
9970
+ * @param entities
9971
+ * @param force
9972
+ * @returns
9973
+ */
9974
+ Manager.prototype.renderAsIndividuals = function (entities, force) {
9351
9975
  var _a, _b;
9352
9976
  if (force === void 0) { force = false; }
9353
9977
  return __awaiter(this, void 0, void 0, function () {
9354
- var cEntities, i, entity, id, cEntity, visual, clustered, e_2;
9978
+ var cEntities, i, entity, id, cEntity, visual, clustered;
9355
9979
  return __generator(this, function (_c) {
9356
9980
  switch (_c.label) {
9357
- case 0:
9358
- if (this.disposed || this.viewer.isDestroyed()) {
9359
- return [2 /*return*/];
9360
- }
9361
- _c.label = 1;
9981
+ case 0: return [4 /*yield*/, exports.EntityRenderEngine.Render({
9982
+ viewer: this.viewer,
9983
+ apiGetter: this.apiGetter,
9984
+ entities: entities,
9985
+ menuItemId: this.item.id,
9986
+ visualRegister: this.visualsManager,
9987
+ zoomControl: this.item.CameraZoomSettings,
9988
+ force: force
9989
+ })];
9362
9990
  case 1:
9363
- _c.trys.push([1, 3, , 4]);
9364
- return [4 /*yield*/, exports.EntityRenderEngine.Render({
9365
- viewer: this.viewer,
9366
- apiGetter: this.apiGetter,
9367
- entities: entities,
9368
- menuItemId: this.item.id,
9369
- visualRegister: this.visualsManager,
9370
- zoomControl: this.item.CameraZoomSettings,
9371
- force: force
9372
- })];
9373
- case 2:
9374
9991
  cEntities = _c.sent();
9375
9992
  for (i = 0; i < entities.length; i++) {
9376
9993
  entity = entities[i];
@@ -9412,12 +10029,7 @@
9412
10029
  if (this.clustering && entities.length) {
9413
10030
  this.clustering.Update();
9414
10031
  }
9415
- return [3 /*break*/, 4];
9416
- case 3:
9417
- e_2 = _c.sent();
9418
- console.error(e_2);
9419
- return [3 /*break*/, 4];
9420
- case 4: return [2 /*return*/];
10032
+ return [2 /*return*/];
9421
10033
  }
9422
10034
  });
9423
10035
  });
@@ -9629,7 +10241,7 @@
9629
10241
  EntityRenderManager.Manager = Manager;
9630
10242
  })(exports.EntityRenderManager || (exports.EntityRenderManager = {}));
9631
10243
 
9632
- function colorToCColor$3(color) {
10244
+ function colorToCColor$5(color) {
9633
10245
  return new Cesium.Color(color.red ? color.red / 255 : 0, color.green ? color.green / 255 : 0, color.blue ? color.blue / 255 : 0, color.alpha);
9634
10246
  }
9635
10247
  /**
@@ -10248,7 +10860,7 @@
10248
10860
  Styler.prototype.loadStyles = function () {
10249
10861
  var _a, _b;
10250
10862
  return __awaiter(this, void 0, void 0, function () {
10251
- var counter, fallbackStyleId, data, e_1, styleMapping, modelTree, entityTypeIds, _loop_2, i, i, styleMap, styleId, entityType, e_2, data, e_3;
10863
+ var counter, fallbackStyleId, data, e_1, styleMapping, modelTree, entityTypeIds, _loop_2, this_2, i, i, styleMap, styleId, entityType, e_2, data, e_3;
10252
10864
  return __generator(this, function (_c) {
10253
10865
  switch (_c.label) {
10254
10866
  case 0:
@@ -10293,11 +10905,12 @@
10293
10905
  if (styleMapping.findIndex(function (x) { return x.EntityTypeID == entityTypeId; }) <= -1) {
10294
10906
  styleMapping.push({
10295
10907
  EntityTypeID: entityTypeId,
10296
- StyleID: null,
10297
- style: null
10908
+ StyleID: this_2.fallbackStyle ? fallbackStyleId : 0,
10909
+ style: this_2.fallbackStyle
10298
10910
  });
10299
10911
  }
10300
10912
  };
10913
+ this_2 = this;
10301
10914
  for (i = 0; i < entityTypeIds.length; i++) {
10302
10915
  _loop_2(i);
10303
10916
  }
@@ -10505,7 +11118,7 @@
10505
11118
  cColor = Cesium.Color.WHITE;
10506
11119
  }
10507
11120
  else {
10508
- cColor = colorToCColor$3(bColor);
11121
+ cColor = colorToCColor$5(bColor);
10509
11122
  }
10510
11123
  CesiumEntityStyler.SetDefaultColor({
10511
11124
  color: cColor,
@@ -20487,7 +21100,7 @@
20487
21100
  CesiumViewMonitor.Monitor = Monitor;
20488
21101
  })(exports.CesiumViewMonitor || (exports.CesiumViewMonitor = {}));
20489
21102
 
20490
- var VERSION$1 = "3.3.9";
21103
+ var VERSION$1 = "3.4.1";
20491
21104
 
20492
21105
  exports.VERSION = VERSION$1;
20493
21106
  exports.CesiumParabola = CesiumParabola;