bruce-cesium 2.7.8 → 2.8.0

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.
@@ -3157,15 +3157,15 @@
3157
3157
  var siblings = [p1Entity, p2Entity];
3158
3158
  this.parabola = parabola;
3159
3159
  this.siblings = siblings;
3160
+ this.viewer.entities.add(this.parabola);
3161
+ this.viewer.entities.add(p1Entity);
3162
+ this.viewer.entities.add(p2Entity);
3160
3163
  };
3161
3164
  CesiumParabola.prototype.Animate = function () {
3162
3165
  var _this = this;
3163
3166
  if (this.disposed) {
3164
3167
  return null;
3165
3168
  }
3166
- if (this.parabola && !this.viewer.entities.contains(this.parabola)) {
3167
- this.viewer.entities.add(this.parabola);
3168
- }
3169
3169
  var retry = false;
3170
3170
  if (!this.curPos1 || !this.curPos2 || !bruceModels.Cartes.ValidateCartes3(this.curPos1) || !bruceModels.Cartes.ValidateCartes3(this.curPos2)) {
3171
3171
  retry = true;
@@ -3183,14 +3183,6 @@
3183
3183
  siblings: this.siblings
3184
3184
  };
3185
3185
  }
3186
- var cEntities = [
3187
- this.parabola
3188
- ].concat(this.siblings);
3189
- cEntities.forEach(function (e) {
3190
- if (e && !_this.viewer.entities.contains(e)) {
3191
- _this.viewer.entities.add(e);
3192
- }
3193
- });
3194
3186
  var RATE_PER_SECOND = 1000 / 40;
3195
3187
  var SEC_DURATION = this.duration;
3196
3188
  var HEIGHT_DISTANCE_RATIO = this.heightDistanceRatio;
@@ -3443,6 +3435,67 @@
3443
3435
  function colorToCColor$1(color) {
3444
3436
  return new Cesium.Color(color.red ? color.red / 255 : 0, color.green ? color.green / 255 : 0, color.blue ? color.blue / 255 : 0, color.alpha);
3445
3437
  }
3438
+ function getStyle$1(api, typeId, styleId) {
3439
+ return __awaiter(this, void 0, void 0, function () {
3440
+ var style, e_1, type, e_2, hideError, error, code;
3441
+ return __generator(this, function (_a) {
3442
+ switch (_a.label) {
3443
+ case 0:
3444
+ style = null;
3445
+ if (!styleId) return [3 /*break*/, 4];
3446
+ _a.label = 1;
3447
+ case 1:
3448
+ _a.trys.push([1, 3, , 4]);
3449
+ return [4 /*yield*/, bruceModels.Style.Get({
3450
+ api: api,
3451
+ styleId: styleId
3452
+ })];
3453
+ case 2:
3454
+ style = (_a.sent()).style;
3455
+ return [3 /*break*/, 4];
3456
+ case 3:
3457
+ e_1 = _a.sent();
3458
+ console.error(e_1);
3459
+ return [3 /*break*/, 4];
3460
+ case 4:
3461
+ if (!(!style && typeId)) return [3 /*break*/, 9];
3462
+ return [4 /*yield*/, bruceModels.EntityType.Get({
3463
+ api: api,
3464
+ entityTypeId: typeId
3465
+ })];
3466
+ case 5:
3467
+ type = (_a.sent()).entityType;
3468
+ if (!type["DisplaySetting.ID"]) return [3 /*break*/, 9];
3469
+ _a.label = 6;
3470
+ case 6:
3471
+ _a.trys.push([6, 8, , 9]);
3472
+ return [4 /*yield*/, bruceModels.Style.Get({
3473
+ api: api,
3474
+ styleId: type["DisplaySetting.ID"]
3475
+ })];
3476
+ case 7:
3477
+ style = (_a.sent()).style;
3478
+ return [3 /*break*/, 9];
3479
+ case 8:
3480
+ e_2 = _a.sent();
3481
+ hideError = false;
3482
+ // TODO: we need a util for extracting code + message rather than writing all this every time.
3483
+ if (e_2 && typeof e_2 == "object" && e_2.ERROR) {
3484
+ error = e_2.ERROR;
3485
+ code = error && typeof error == "object" ? error.Code : "";
3486
+ // Avoiding logging a common error.
3487
+ // This happens when rendering entities that don't have records.
3488
+ hideError = String(code).toLowerCase() == "notfound";
3489
+ }
3490
+ if (!hideError) {
3491
+ console.error(e_2);
3492
+ }
3493
+ return [3 /*break*/, 9];
3494
+ case 9: return [2 /*return*/, style];
3495
+ }
3496
+ });
3497
+ });
3498
+ }
3446
3499
  var RelationRenderEngine;
3447
3500
  (function (RelationRenderEngine) {
3448
3501
  function GetRenderGroupId(relation) {
@@ -3451,81 +3504,55 @@
3451
3504
  RelationRenderEngine.GetRenderGroupId = GetRenderGroupId;
3452
3505
  function Render(params) {
3453
3506
  return __awaiter(this, void 0, void 0, function () {
3454
- var apiGetter, viewer, visualRegister, menuItemId, relations, api, rendered, i, relation, fromEntity, toEntity, dataEntity, _a, relationType, styleId, typeId, entityType, _b, style, _c, cEntity;
3455
- return __generator(this, function (_d) {
3456
- switch (_d.label) {
3507
+ var apiGetter, viewer, visualRegister, menuItemId, relations, api, rendered, i, relation, fromEntity, toEntity, dataEntity, _a, relationType, style, cEntity, e_3;
3508
+ return __generator(this, function (_b) {
3509
+ switch (_b.label) {
3457
3510
  case 0:
3458
3511
  apiGetter = params.apiGetter, viewer = params.viewer, visualRegister = params.visualRegister, menuItemId = params.menuItemId, relations = params.relations;
3459
3512
  api = apiGetter.getApi(apiGetter.accountId);
3460
3513
  rendered = {};
3461
3514
  i = 0;
3462
- _d.label = 1;
3515
+ _b.label = 1;
3463
3516
  case 1:
3464
- if (!(i < relations.length)) return [3 /*break*/, 17];
3517
+ if (!(i < relations.length)) return [3 /*break*/, 13];
3518
+ _b.label = 2;
3519
+ case 2:
3520
+ _b.trys.push([2, 11, , 12]);
3465
3521
  relation = relations[i];
3466
3522
  return [4 /*yield*/, bruceModels.Entity.Get({
3467
3523
  api: api,
3468
3524
  entityId: relation["Principal.Entity.ID"],
3469
3525
  })];
3470
- case 2:
3471
- fromEntity = (_d.sent()).entity;
3526
+ case 3:
3527
+ fromEntity = (_b.sent()).entity;
3472
3528
  return [4 /*yield*/, bruceModels.Entity.Get({
3473
3529
  api: api,
3474
3530
  entityId: relation["Related.Entity.ID"],
3475
3531
  })];
3476
- case 3:
3477
- toEntity = (_d.sent()).entity;
3478
- if (!relation["Data.Entity.ID"]) return [3 /*break*/, 5];
3532
+ case 4:
3533
+ toEntity = (_b.sent()).entity;
3534
+ if (!relation["Data.Entity.ID"]) return [3 /*break*/, 6];
3479
3535
  return [4 /*yield*/, bruceModels.Entity.Get({
3480
3536
  api: api,
3481
3537
  entityId: relation["Data.Entity.ID"]
3482
3538
  })];
3483
- case 4:
3484
- _a = (_d.sent()).entity;
3485
- return [3 /*break*/, 6];
3486
3539
  case 5:
3487
- _a = null;
3488
- _d.label = 6;
3540
+ _a = (_b.sent()).entity;
3541
+ return [3 /*break*/, 7];
3489
3542
  case 6:
3543
+ _a = null;
3544
+ _b.label = 7;
3545
+ case 7:
3490
3546
  dataEntity = _a;
3491
3547
  return [4 /*yield*/, bruceModels.EntityRelationType.Get({
3492
3548
  api: api,
3493
3549
  relationTypeId: relation["Relation.Type.ID"]
3494
3550
  })];
3495
- case 7:
3496
- relationType = (_d.sent()).relationType;
3497
- styleId = Number(relationType === null || relationType === void 0 ? void 0 : relationType.EntityDisplaySettingID);
3498
- if (!!styleId) return [3 /*break*/, 11];
3499
- typeId = relationType === null || relationType === void 0 ? void 0 : relationType["Relation.EntityType.ID"];
3500
- if (!typeId) return [3 /*break*/, 9];
3501
- return [4 /*yield*/, bruceModels.EntityType.Get({
3502
- api: api,
3503
- entityTypeId: typeId
3504
- })];
3505
3551
  case 8:
3506
- _b = (_d.sent()).entityType;
3507
- return [3 /*break*/, 10];
3552
+ relationType = (_b.sent()).relationType;
3553
+ return [4 /*yield*/, getStyle$1(api, relationType === null || relationType === void 0 ? void 0 : relationType["Relation.EntityType.ID"], Number(relationType === null || relationType === void 0 ? void 0 : relationType.EntityDisplaySettingID))];
3508
3554
  case 9:
3509
- _b = null;
3510
- _d.label = 10;
3511
- case 10:
3512
- entityType = _b;
3513
- styleId = entityType === null || entityType === void 0 ? void 0 : entityType["DisplaySetting.ID"];
3514
- _d.label = 11;
3515
- case 11:
3516
- if (!styleId) return [3 /*break*/, 13];
3517
- return [4 /*yield*/, bruceModels.Style.Get({
3518
- api: api,
3519
- styleId: styleId
3520
- })];
3521
- case 12:
3522
- _c = (_d.sent()).style;
3523
- return [3 /*break*/, 14];
3524
- case 13:
3525
- _c = null;
3526
- _d.label = 14;
3527
- case 14:
3528
- style = _c;
3555
+ style = _b.sent();
3529
3556
  return [4 /*yield*/, Parabola.Render({
3530
3557
  dataEntity: dataEntity,
3531
3558
  fromEntity: fromEntity,
@@ -3536,15 +3563,19 @@
3536
3563
  visualRegister: visualRegister,
3537
3564
  apiGetter: apiGetter
3538
3565
  })];
3539
- case 15:
3540
- cEntity = _d.sent();
3566
+ case 10:
3567
+ cEntity = _b.sent();
3541
3568
  cEntity._renderGroup = GetRenderGroupId(relation);
3542
3569
  rendered[GetRenderGroupId(relation)] = cEntity;
3543
- _d.label = 16;
3544
- case 16:
3570
+ return [3 /*break*/, 12];
3571
+ case 11:
3572
+ e_3 = _b.sent();
3573
+ console.error(e_3);
3574
+ return [3 /*break*/, 12];
3575
+ case 12:
3545
3576
  i++;
3546
3577
  return [3 /*break*/, 1];
3547
- case 17: return [2 /*return*/, rendered];
3578
+ case 13: return [2 /*return*/, rendered];
3548
3579
  }
3549
3580
  });
3550
3581
  });
@@ -3572,7 +3603,7 @@
3572
3603
  toPos = null;
3573
3604
  updatingPosses = false;
3574
3605
  updatePosses = function () { return __awaiter(_this, void 0, void 0, function () {
3575
- var e_1;
3606
+ var e_4;
3576
3607
  return __generator(this, function (_a) {
3577
3608
  switch (_a.label) {
3578
3609
  case 0:
@@ -3609,8 +3640,8 @@
3609
3640
  toPos = _a.sent();
3610
3641
  return [3 /*break*/, 5];
3611
3642
  case 4:
3612
- e_1 = _a.sent();
3613
- console.error(e_1);
3643
+ e_4 = _a.sent();
3644
+ console.error(e_4);
3614
3645
  return [3 /*break*/, 5];
3615
3646
  case 5:
3616
3647
  updatingPosses = false;
@@ -8249,135 +8280,129 @@
8249
8280
  configurable: true
8250
8281
  });
8251
8282
  Manager.prototype.Init = function (params) {
8283
+ var _this = this;
8252
8284
  var _a;
8253
- return __awaiter(this, void 0, void 0, function () {
8254
- var counter, tilesetId;
8285
+ this.initCounter += 1;
8286
+ var counter = this.initCounter;
8287
+ if (this.disposed) {
8288
+ return;
8289
+ }
8290
+ if (params === null || params === void 0 ? void 0 : params.item) {
8291
+ this.item = params.item;
8292
+ }
8293
+ var tilesetId = (_a = this.item.tileset) === null || _a === void 0 ? void 0 : _a.TilesetID;
8294
+ if (!tilesetId) {
8295
+ return;
8296
+ }
8297
+ (function () { return __awaiter(_this, void 0, void 0, function () {
8298
+ var canAccess, e_1, accountId, api, tileset, cTileset, _a, attenuation, attenuationMax;
8255
8299
  var _this = this;
8256
- return __generator(this, function (_b) {
8257
- this.initCounter += 1;
8258
- counter = this.initCounter;
8259
- if (this.disposed) {
8260
- return [2 /*return*/];
8261
- }
8262
- if (params === null || params === void 0 ? void 0 : params.item) {
8263
- this.item = params.item;
8264
- }
8265
- tilesetId = (_a = this.item.tileset) === null || _a === void 0 ? void 0 : _a.TilesetID;
8266
- if (!tilesetId) {
8267
- return [2 /*return*/];
8268
- }
8269
- (function () { return __awaiter(_this, void 0, void 0, function () {
8270
- var canAccess, e_1, accountId, api, tileset, cTileset, _a, attenuation, attenuationMax;
8271
- var _this = this;
8272
- var _b, _c, _d;
8273
- return __generator(this, function (_e) {
8274
- switch (_e.label) {
8275
- case 0:
8276
- if (!!this.cTileset) return [3 /*break*/, 9];
8277
- if (!tilesetId) return [3 /*break*/, 5];
8278
- canAccess = false;
8279
- _e.label = 1;
8280
- case 1:
8281
- _e.trys.push([1, 3, , 4]);
8282
- return [4 /*yield*/, bruceModels.Tileset.Publish.IsAccessAllowed({
8283
- sourceAccountId: (_b = this.item.tileset) === null || _b === void 0 ? void 0 : _b.ClientAccountID,
8284
- tilesetId: tilesetId,
8285
- forAccountId: this.getters.GetAccountId(),
8286
- api: this.getters.GetGlobalApi()
8287
- })];
8288
- case 2:
8289
- canAccess = _e.sent();
8290
- return [3 /*break*/, 4];
8291
- case 3:
8292
- e_1 = _e.sent();
8293
- console.error(e_1);
8294
- return [3 /*break*/, 4];
8295
- case 4:
8296
- if (!canAccess) {
8297
- console.warn("Cannot access tileset: ".concat(tilesetId, ", from account: ").concat((_c = this.item.tileset) === null || _c === void 0 ? void 0 : _c.ClientAccountID, "."));
8298
- return [2 /*return*/];
8299
- }
8300
- return [3 /*break*/, 6];
8301
- case 5:
8302
- console.warn("No tileset id found. Skipping access check.");
8303
- _e.label = 6;
8304
- case 6:
8305
- if (this.disposed || counter !== this.initCounter) {
8306
- return [2 /*return*/];
8307
- }
8308
- accountId = (_d = this.item.tileset) === null || _d === void 0 ? void 0 : _d.ClientAccountID;
8309
- if (!accountId) {
8310
- accountId = this.getters.GetAccountId();
8311
- }
8312
- api = this.getters.GetBruceApi({
8313
- accountId: accountId
8314
- });
8315
- return [4 /*yield*/, bruceModels.Tileset.Get({
8316
- api: api,
8317
- tilesetId: tilesetId
8318
- })];
8319
- case 7:
8320
- tileset = (_e.sent()).tileset;
8321
- if (!tileset || this.disposed || counter !== this.initCounter) {
8322
- return [2 /*return*/];
8323
- }
8324
- this.typeId = tileset.settings.entityTypeId;
8325
- _a = this;
8326
- return [4 /*yield*/, exports.TilesetRenderEngine.Render({
8327
- apiGetter: this.getters.GetBruceGetter(),
8328
- tileset: tileset,
8329
- viewer: this.viewer,
8330
- accountId: accountId,
8331
- viaCdn: this.item.cdnEnabled
8332
- })];
8333
- case 8:
8334
- cTileset = _a.cTileset = _e.sent();
8335
- if (this.disposed) {
8336
- this.doDispose();
8337
- return [2 /*return*/];
8338
- }
8339
- this.viewer.scene.requestRender();
8340
- cTileset.readyPromise.then(function () {
8341
- try {
8342
- if (_this.disposed || _this.viewer.isDestroyed()) {
8343
- return;
8344
- }
8345
- _this.onCTilesetLoad();
8346
- _this.viewer.scene.requestRender();
8347
- }
8348
- catch (e) {
8349
- console.error(e);
8350
- }
8351
- });
8352
- cTileset.tileLoad.addEventListener(function (tile) {
8353
- _this.mapCTile(tile);
8354
- });
8355
- _e.label = 9;
8356
- case 9:
8357
- attenuation = this.item.attenuation;
8358
- if (!attenuation && attenuation != false) {
8359
- attenuation = true;
8360
- }
8361
- attenuationMax = this.item.attenuationMax;
8362
- if (isNaN(attenuationMax)) {
8363
- attenuationMax = 20;
8300
+ var _b, _c, _d;
8301
+ return __generator(this, function (_e) {
8302
+ switch (_e.label) {
8303
+ case 0:
8304
+ if (!!this.cTileset) return [3 /*break*/, 9];
8305
+ if (!tilesetId) return [3 /*break*/, 5];
8306
+ canAccess = false;
8307
+ _e.label = 1;
8308
+ case 1:
8309
+ _e.trys.push([1, 3, , 4]);
8310
+ return [4 /*yield*/, bruceModels.Tileset.Publish.IsAccessAllowed({
8311
+ sourceAccountId: (_b = this.item.tileset) === null || _b === void 0 ? void 0 : _b.ClientAccountID,
8312
+ tilesetId: tilesetId,
8313
+ forAccountId: this.getters.GetAccountId(),
8314
+ api: this.getters.GetGlobalApi()
8315
+ })];
8316
+ case 2:
8317
+ canAccess = _e.sent();
8318
+ return [3 /*break*/, 4];
8319
+ case 3:
8320
+ e_1 = _e.sent();
8321
+ console.error(e_1);
8322
+ return [3 /*break*/, 4];
8323
+ case 4:
8324
+ if (!canAccess) {
8325
+ console.warn("Cannot access tileset: ".concat(tilesetId, ", from account: ").concat((_c = this.item.tileset) === null || _c === void 0 ? void 0 : _c.ClientAccountID, "."));
8326
+ return [2 /*return*/];
8327
+ }
8328
+ return [3 /*break*/, 6];
8329
+ case 5:
8330
+ console.warn("No tileset id found. Skipping access check.");
8331
+ _e.label = 6;
8332
+ case 6:
8333
+ if (this.disposed || counter !== this.initCounter) {
8334
+ return [2 /*return*/];
8335
+ }
8336
+ accountId = (_d = this.item.tileset) === null || _d === void 0 ? void 0 : _d.ClientAccountID;
8337
+ if (!accountId) {
8338
+ accountId = this.getters.GetAccountId();
8339
+ }
8340
+ api = this.getters.GetBruceApi({
8341
+ accountId: accountId
8342
+ });
8343
+ return [4 /*yield*/, bruceModels.Tileset.Get({
8344
+ api: api,
8345
+ tilesetId: tilesetId
8346
+ })];
8347
+ case 7:
8348
+ tileset = (_e.sent()).tileset;
8349
+ if (!tileset || this.disposed || counter !== this.initCounter) {
8350
+ return [2 /*return*/];
8351
+ }
8352
+ this.typeId = tileset.settings.entityTypeId;
8353
+ _a = this;
8354
+ return [4 /*yield*/, exports.TilesetRenderEngine.Render({
8355
+ apiGetter: this.getters.GetBruceGetter(),
8356
+ tileset: tileset,
8357
+ viewer: this.viewer,
8358
+ accountId: accountId,
8359
+ viaCdn: this.item.cdnEnabled
8360
+ })];
8361
+ case 8:
8362
+ cTileset = _a.cTileset = _e.sent();
8363
+ if (this.disposed) {
8364
+ this.doDispose();
8365
+ return [2 /*return*/];
8366
+ }
8367
+ this.viewer.scene.requestRender();
8368
+ cTileset.readyPromise.then(function () {
8369
+ try {
8370
+ if (_this.disposed || _this.viewer.isDestroyed()) {
8371
+ return;
8364
8372
  }
8365
- this.cTileset.readyPromise.then(function () {
8366
- exports.TilesetRenderEngine.ApplySettings({
8367
- cTileset: _this.cTileset,
8368
- settings: {
8369
- attenuation: attenuation,
8370
- maximumAttenuation: attenuationMax
8371
- }
8372
- });
8373
- });
8374
- return [2 /*return*/];
8373
+ _this.onCTilesetLoad();
8374
+ _this.viewer.scene.requestRender();
8375
+ }
8376
+ catch (e) {
8377
+ console.error(e);
8378
+ }
8379
+ });
8380
+ cTileset.tileLoad.addEventListener(function (tile) {
8381
+ _this.mapCTile(tile);
8382
+ });
8383
+ _e.label = 9;
8384
+ case 9:
8385
+ attenuation = this.item.attenuation;
8386
+ if (!attenuation && attenuation != false) {
8387
+ attenuation = true;
8375
8388
  }
8376
- });
8377
- }); })();
8378
- return [2 /*return*/];
8389
+ attenuationMax = this.item.attenuationMax;
8390
+ if (isNaN(attenuationMax)) {
8391
+ attenuationMax = 20;
8392
+ }
8393
+ this.cTileset.readyPromise.then(function () {
8394
+ exports.TilesetRenderEngine.ApplySettings({
8395
+ cTileset: _this.cTileset,
8396
+ settings: {
8397
+ attenuation: attenuation,
8398
+ maximumAttenuation: attenuationMax
8399
+ }
8400
+ });
8401
+ });
8402
+ return [2 /*return*/];
8403
+ }
8379
8404
  });
8380
- });
8405
+ }); })();
8381
8406
  };
8382
8407
  Manager.prototype.Dispose = function () {
8383
8408
  if (this.disposed) {
@@ -9064,6 +9089,8 @@
9064
9089
  (function (RelationsRenderManager) {
9065
9090
  var Manager = /** @class */ (function () {
9066
9091
  function Manager(params) {
9092
+ // If true, this menu item is disposed and should not be used.
9093
+ // Any rendering will be ignored.
9067
9094
  this.disposed = false;
9068
9095
  var apiGetter = params.apiGetter, item = params.item, register = params.register, viewer = params.viewer;
9069
9096
  this.apiGetter = apiGetter;
@@ -9078,56 +9105,61 @@
9078
9105
  enumerable: false,
9079
9106
  configurable: true
9080
9107
  });
9081
- Manager.prototype.Init = function () {
9082
- var _this = this;
9083
- var drawn = [];
9084
- var api = this.apiGetter.getApi(this.apiGetter.accountId);
9085
- var BATCH_SIZE = 5;
9086
- var drawBatch = [];
9087
- var pending = this.item.BruceEntity.EntityIds.length;
9088
- var onResolve = function () {
9089
- pending -= 1;
9090
- if (pending <= 0) {
9091
- if (drawBatch === null || drawBatch === void 0 ? void 0 : drawBatch.length) {
9092
- _this.onGetterUpdate(drawBatch);
9108
+ /**
9109
+ * Starts rendering the menu item.
9110
+ * Re-call with an updated menu item to re-render. It will auto-cleanup old relations.
9111
+ * @param params
9112
+ * @returns
9113
+ */
9114
+ Manager.prototype.Init = function (params) {
9115
+ var _a;
9116
+ if (this.disposed) {
9117
+ return;
9118
+ }
9119
+ if (params === null || params === void 0 ? void 0 : params.item) {
9120
+ this.item = params.item;
9121
+ }
9122
+ // Remove relationships we no longer want to render.
9123
+ // We'll have to get regos by the menu item ID then run a check on the related rego relationship.
9124
+ var regos = this.register.GetRegos({
9125
+ menuItemId: this.item.id
9126
+ });
9127
+ var drawnIds = [];
9128
+ var toDrawIds = [];
9129
+ var entityIds = (_a = this.item.BruceEntity) === null || _a === void 0 ? void 0 : _a.EntityIds;
9130
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
9131
+ entityIds = [];
9132
+ }
9133
+ for (var i = 0; i < regos.length; i++) {
9134
+ var rego = regos[i];
9135
+ if (!this.shouldRenderRelation(rego.relation)) {
9136
+ this.register.RemoveRegos({
9137
+ relation: rego.relation,
9138
+ entityId: rego.entityId,
9139
+ menuItemId: this.item.id,
9140
+ requestRender: false
9141
+ });
9142
+ }
9143
+ else {
9144
+ drawnIds.push(rego.entityId);
9145
+ if (rego.relation) {
9146
+ drawnIds.push(rego.relation["Principal.Entity.ID"]);
9093
9147
  }
9094
9148
  }
9149
+ }
9150
+ this.viewer.scene.requestRender();
9151
+ var _loop_1 = function (i) {
9152
+ if (!drawnIds.find(function (x) { return x == entityIds[i]; })) {
9153
+ toDrawIds.push(entityIds[i]);
9154
+ }
9095
9155
  };
9096
- for (var i = 0; i < this.item.BruceEntity.EntityIds.length; i++) {
9097
- var entityId = this.item.BruceEntity.EntityIds[i];
9098
- bruceModels.EntityRelation.GetList({
9099
- api: api,
9100
- entityId: entityId,
9101
- filter: {
9102
- oneWayOnly: false,
9103
- loadEntityData: false
9104
- }
9105
- }).then(function (data) {
9106
- var _a;
9107
- var relations = data.relations;
9108
- var _loop_1 = function (j) {
9109
- var relation = relations[j];
9110
- if (((_a = _this.item.relationTypeIds) === null || _a === void 0 ? void 0 : _a.length) && !_this.item.relationTypeIds.includes(relation["Relation.Type.ID"])) {
9111
- return "continue";
9112
- }
9113
- var key = RelationRenderEngine.GetRenderGroupId(relation);
9114
- if (!drawn.find(function (x) { return x == key; })) {
9115
- drawn.push(key);
9116
- drawBatch.push(relation);
9117
- if (drawBatch.length >= BATCH_SIZE) {
9118
- _this.onGetterUpdate(drawBatch);
9119
- drawBatch = [];
9120
- }
9121
- }
9122
- };
9123
- for (var j = 0; j < relations.length; j++) {
9124
- _loop_1(j);
9125
- }
9126
- onResolve();
9127
- }).catch(function (e) {
9128
- onResolve();
9129
- });
9156
+ // We'll call a re-render on entity ids that are not drawn.
9157
+ for (var i = 0; i < entityIds.length; i++) {
9158
+ _loop_1(i);
9130
9159
  }
9160
+ this.renderEntityIds({
9161
+ entityIds: toDrawIds
9162
+ });
9131
9163
  };
9132
9164
  Manager.prototype.Dispose = function () {
9133
9165
  if (this.disposed) {
@@ -9138,19 +9170,154 @@
9138
9170
  menuItemId: this.item.id
9139
9171
  });
9140
9172
  };
9173
+ /**
9174
+ * Re-renders specific entity relationships.
9175
+ * @TODO: This should re-render all relationships when entityIds=null.
9176
+ * @param params
9177
+ */
9141
9178
  Manager.prototype.ReRender = function (params) {
9142
9179
  return __awaiter(this, void 0, void 0, function () {
9143
9180
  var entityIds, force;
9144
9181
  return __generator(this, function (_a) {
9145
9182
  entityIds = params.entityIds, force = params.force;
9183
+ if (entityIds == null) ;
9184
+ else {
9185
+ this.renderEntityIds({
9186
+ dataEntityIds: entityIds
9187
+ });
9188
+ }
9146
9189
  return [2 /*return*/];
9147
9190
  });
9148
9191
  });
9149
9192
  };
9193
+ /**
9194
+ * Gets relationship records corresponding to provided IDs and requests a render for them.
9195
+ */
9196
+ Manager.prototype.renderEntityIds = function (params) {
9197
+ return __awaiter(this, void 0, void 0, function () {
9198
+ var entityIds, dataEntityIds, drawn, api, BATCH_SIZE, drawBatch, pending, onResolve, i, entityId, i, entityId;
9199
+ var _this = this;
9200
+ return __generator(this, function (_a) {
9201
+ if (this.disposed || this.viewer.isDestroyed()) {
9202
+ return [2 /*return*/];
9203
+ }
9204
+ entityIds = params.entityIds, dataEntityIds = params.dataEntityIds;
9205
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
9206
+ entityIds = [];
9207
+ }
9208
+ if (!(dataEntityIds === null || dataEntityIds === void 0 ? void 0 : dataEntityIds.length)) {
9209
+ dataEntityIds = [];
9210
+ }
9211
+ drawn = [];
9212
+ api = this.apiGetter.getApi(this.apiGetter.accountId);
9213
+ BATCH_SIZE = 5;
9214
+ drawBatch = [];
9215
+ pending = entityIds.length + dataEntityIds.length;
9216
+ onResolve = function () {
9217
+ if (_this.disposed || _this.viewer.isDestroyed()) {
9218
+ return;
9219
+ }
9220
+ pending -= 1;
9221
+ if (pending <= 0) {
9222
+ if (drawBatch === null || drawBatch === void 0 ? void 0 : drawBatch.length) {
9223
+ _this.onGetterUpdate(drawBatch);
9224
+ }
9225
+ }
9226
+ };
9227
+ // Get relationships by their data entity ID.
9228
+ for (i = 0; i < dataEntityIds.length; i++) {
9229
+ entityId = dataEntityIds[i];
9230
+ bruceModels.EntityRelation.GetByDataEntityId({
9231
+ entityId: entityId,
9232
+ api: api
9233
+ }).then(function (data) {
9234
+ if (data.relation) {
9235
+ var relation = data.relation;
9236
+ var key_1 = RelationRenderEngine.GetRenderGroupId(relation);
9237
+ if (!drawn.find(function (x) { return x == key_1; })) {
9238
+ drawn.push(key_1);
9239
+ drawBatch.push(relation);
9240
+ if (drawBatch.length >= BATCH_SIZE) {
9241
+ _this.onGetterUpdate(drawBatch);
9242
+ drawBatch = [];
9243
+ }
9244
+ }
9245
+ }
9246
+ onResolve();
9247
+ }).catch(function (e) {
9248
+ onResolve();
9249
+ });
9250
+ }
9251
+ // Get relationships by either the parent or child ID.
9252
+ for (i = 0; i < entityIds.length; i++) {
9253
+ entityId = entityIds[i];
9254
+ bruceModels.EntityRelation.GetList({
9255
+ api: api,
9256
+ entityId: entityId,
9257
+ filter: {
9258
+ oneWayOnly: false,
9259
+ loadEntityData: false
9260
+ }
9261
+ }).then(function (data) {
9262
+ var relations = data.relations;
9263
+ var _loop_2 = function (j) {
9264
+ var relation = relations[j];
9265
+ var key = RelationRenderEngine.GetRenderGroupId(relation);
9266
+ if (!drawn.find(function (x) { return x == key; })) {
9267
+ drawn.push(key);
9268
+ drawBatch.push(relation);
9269
+ if (drawBatch.length >= BATCH_SIZE) {
9270
+ _this.onGetterUpdate(drawBatch);
9271
+ drawBatch = [];
9272
+ }
9273
+ }
9274
+ };
9275
+ for (var j = 0; j < relations.length; j++) {
9276
+ _loop_2(j);
9277
+ }
9278
+ onResolve();
9279
+ }).catch(function (e) {
9280
+ onResolve();
9281
+ });
9282
+ }
9283
+ return [2 /*return*/];
9284
+ });
9285
+ });
9286
+ };
9287
+ /**
9288
+ * Returns if a relation should be rendered.
9289
+ * This is in case the menu item was updated and the relation is no longer relevant.
9290
+ * @param relation
9291
+ */
9292
+ Manager.prototype.shouldRenderRelation = function (relation) {
9293
+ var _a, _b, _c;
9294
+ if (((_a = this.item.relationTypeIds) === null || _a === void 0 ? void 0 : _a.length) && !this.item.relationTypeIds.includes(relation["Relation.Type.ID"])) {
9295
+ return false;
9296
+ }
9297
+ var renderedIds = (_c = (_b = this.item) === null || _b === void 0 ? void 0 : _b.BruceEntity) === null || _c === void 0 ? void 0 : _c.EntityIds;
9298
+ if (!renderedIds) {
9299
+ return false;
9300
+ }
9301
+ var ids = [
9302
+ relation["Principal.Entity.ID"],
9303
+ relation["Related.Entity.ID"]
9304
+ ];
9305
+ if (relation["Data.Entity.ID"]) {
9306
+ ids.push(relation["Data.Entity.ID"]);
9307
+ }
9308
+ return ids.some(function (x) { return renderedIds.includes(x); });
9309
+ };
9310
+ /**
9311
+ * Renders batch of entity relationships.
9312
+ * This will check if a relationship SHOULD be rendered before rendering it.
9313
+ * It will also handle already rendered relations to avoid re-rendering them.
9314
+ * @param relations
9315
+ */
9150
9316
  Manager.prototype.onGetterUpdate = function (relations) {
9151
9317
  var _a, _b;
9152
9318
  return __awaiter(this, void 0, void 0, function () {
9153
- var cEntities, i, relation, key, cEntity, visual, e_1;
9319
+ var killCEntity, cEntities, key, i, relation, key, cEntity, visual, e_1;
9320
+ var _this = this;
9154
9321
  return __generator(this, function (_c) {
9155
9322
  switch (_c.label) {
9156
9323
  case 0:
@@ -9158,6 +9325,12 @@
9158
9325
  if (this.disposed || this.viewer.isDestroyed()) {
9159
9326
  return [2 /*return*/];
9160
9327
  }
9328
+ relations = relations.filter(function (x) { return _this.shouldRenderRelation(x); });
9329
+ killCEntity = function (cEntity) {
9330
+ if (cEntity && !_this.viewer.isDestroyed() && _this.viewer.entities.contains(cEntity)) {
9331
+ _this.viewer.entities.remove(cEntity);
9332
+ }
9333
+ };
9161
9334
  return [4 /*yield*/, RelationRenderEngine.Render({
9162
9335
  apiGetter: this.apiGetter,
9163
9336
  menuItemId: this.item.id,
@@ -9171,13 +9344,16 @@
9171
9344
  this.register.RemoveRegos({
9172
9345
  menuItemId: this.item.id
9173
9346
  });
9347
+ for (key in cEntities) {
9348
+ killCEntity(cEntities[key]);
9349
+ }
9174
9350
  return [2 /*return*/];
9175
9351
  }
9176
9352
  for (i = 0; i < relations.length; i++) {
9177
9353
  relation = relations[i];
9178
9354
  key = RelationRenderEngine.GetRenderGroupId(relation);
9179
9355
  cEntity = cEntities[key];
9180
- if (cEntity) {
9356
+ if (cEntity && this.shouldRenderRelation(relation)) {
9181
9357
  visual = (_a = this.register.GetRego({
9182
9358
  entityId: key,
9183
9359
  menuItemId: this.item.id
@@ -9203,6 +9379,7 @@
9203
9379
  menuItemId: this.item.id,
9204
9380
  requestRender: false
9205
9381
  });
9382
+ killCEntity(cEntity);
9206
9383
  }
9207
9384
  }
9208
9385
  this.viewer.scene.requestRender();
@@ -9397,6 +9574,14 @@
9397
9574
  });
9398
9575
  rItem.item = params.item;
9399
9576
  }
9577
+ // This means we're updating a rendered relationships menu item.
9578
+ // Eg: different entities need to be rendered, or one of the relationship data entities changed.
9579
+ else if (rItem.type == bruceModels.MenuItem.EType.Relations && params.item.Type == bruceModels.MenuItem.EType.Relations) {
9580
+ rItem.renderManager.Init({
9581
+ item: params.item,
9582
+ });
9583
+ rItem.item = params.item;
9584
+ }
9400
9585
  }
9401
9586
  else {
9402
9587
  rItem = {
@@ -12298,7 +12483,7 @@
12298
12483
  for (_i = 0, curEnabled_1 = curEnabled; _i < curEnabled_1.length; _i++) {
12299
12484
  id = curEnabled_1[_i];
12300
12485
  if (newItemIds.indexOf(id) === -1 ||
12301
- id == RELATION_MENU_ITEM_ID) {
12486
+ (id == RELATION_MENU_ITEM_ID && !renderedRelationEntityIds.length)) {
12302
12487
  params.manager.RemoveItemById({
12303
12488
  menuItemId: id
12304
12489
  });
@@ -12318,7 +12503,7 @@
12318
12503
  }
12319
12504
  _6.label = 4;
12320
12505
  case 4:
12321
- if (!(renderedRelationEntityIds.length > 0)) return [3 /*break*/, 6];
12506
+ if (!renderedRelationEntityIds.length) return [3 /*break*/, 6];
12322
12507
  menuItem = {
12323
12508
  id: RELATION_MENU_ITEM_ID,
12324
12509
  Caption: "Entity relations",
@@ -15242,7 +15427,7 @@
15242
15427
  ViewerUtils.CreateWidgets = CreateWidgets;
15243
15428
  })(exports.ViewerUtils || (exports.ViewerUtils = {}));
15244
15429
 
15245
- var VERSION$1 = "2.7.8";
15430
+ var VERSION$1 = "2.8.0";
15246
15431
 
15247
15432
  exports.VERSION = VERSION$1;
15248
15433
  exports.CesiumViewMonitor = CesiumViewMonitor;