bruce-cesium 2.7.8 → 2.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { BruceEvent, Cartes, Carto, Entity as Entity$1, Geometry, Tileset, MathUtils, LRUCache, ZoomControl, Style, EntityTag, Calculator, EntityLod, EntityType, ClientFile, ObjectUtils, Bounds, EntityRelationType, DelayQueue, BatchedDataGetter, EntityCoords, EntityFilterGetter, EntitySource, MenuItem, EntityRelation, ENVIRONMENT, ProjectView, ProjectViewBookmark, ProjectViewTile, ProjectViewLegacyTile, ProgramKey, Camera, AbstractApi, EntityAttachment, EntityAttachmentType, EntityAttribute } from 'bruce-models';
2
2
  import * as Cesium from 'cesium';
3
- import { Cartographic, Cartesian2, CallbackProperty, Cartesian3, Color, Rectangle, Math as Math$1, JulianDate, HeightReference, DistanceDisplayCondition, NearFarScalar, Entity, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, SceneMode, Primitive, Cesium3DTileFeature, Cesium3DTileColorBlendMode, HeadingPitchRange, createOsmBuildings, Cesium3DTileStyle, KmlDataSource, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, OrthographicFrustum, EasingFunction, CesiumInspector, defined, EllipsoidGeodesic, sampleTerrainMostDetailed, Cesium3DTileset, Model, Matrix4, Matrix3, IonResource, Ion, PolygonPipeline, ScreenSpaceEventHandler, ScreenSpaceEventType, ColorMaterialProperty, GeometryInstance, BoundingSphere } from 'cesium';
3
+ import { Cartographic, JulianDate, Cartesian2, CallbackProperty, Cartesian3, Color, Rectangle, Math as Math$1, HeightReference, DistanceDisplayCondition, NearFarScalar, Entity, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Primitive, Cesium3DTileFeature, SceneMode, HeadingPitchRange, Cesium3DTileColorBlendMode, createOsmBuildings, Cesium3DTileStyle, KmlDataSource, OrthographicFrustum, EasingFunction, Cesium3DTileset, Matrix4, Matrix3, IonResource, Ion, EllipsoidTerrainProvider, CesiumInspector, defined, EllipsoidGeodesic, sampleTerrainMostDetailed, Model, PolygonPipeline, ScreenSpaceEventHandler, ScreenSpaceEventType, createWorldTerrain, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, ColorMaterialProperty, GeometryInstance, BoundingSphere } from 'cesium';
4
4
 
5
5
  var TIME_LAG = 300;
6
6
  var POSITION_CHECK_TIMER = 950;
@@ -3160,15 +3160,15 @@ var CesiumParabola = /** @class */ (function () {
3160
3160
  var siblings = [p1Entity, p2Entity];
3161
3161
  this.parabola = parabola;
3162
3162
  this.siblings = siblings;
3163
+ this.viewer.entities.add(this.parabola);
3164
+ this.viewer.entities.add(p1Entity);
3165
+ this.viewer.entities.add(p2Entity);
3163
3166
  };
3164
3167
  CesiumParabola.prototype.Animate = function () {
3165
3168
  var _this = this;
3166
3169
  if (this.disposed) {
3167
3170
  return null;
3168
3171
  }
3169
- if (this.parabola && !this.viewer.entities.contains(this.parabola)) {
3170
- this.viewer.entities.add(this.parabola);
3171
- }
3172
3172
  var retry = false;
3173
3173
  if (!this.curPos1 || !this.curPos2 || !Cartes.ValidateCartes3(this.curPos1) || !Cartes.ValidateCartes3(this.curPos2)) {
3174
3174
  retry = true;
@@ -3186,14 +3186,6 @@ var CesiumParabola = /** @class */ (function () {
3186
3186
  siblings: this.siblings
3187
3187
  };
3188
3188
  }
3189
- var cEntities = [
3190
- this.parabola
3191
- ].concat(this.siblings);
3192
- cEntities.forEach(function (e) {
3193
- if (e && !_this.viewer.entities.contains(e)) {
3194
- _this.viewer.entities.add(e);
3195
- }
3196
- });
3197
3189
  var RATE_PER_SECOND = 1000 / 40;
3198
3190
  var SEC_DURATION = this.duration;
3199
3191
  var HEIGHT_DISTANCE_RATIO = this.heightDistanceRatio;
@@ -3446,6 +3438,67 @@ var CesiumParabola = /** @class */ (function () {
3446
3438
  function colorToCColor$1(color) {
3447
3439
  return new Color(color.red ? color.red / 255 : 0, color.green ? color.green / 255 : 0, color.blue ? color.blue / 255 : 0, color.alpha);
3448
3440
  }
3441
+ function getStyle$1(api, typeId, styleId) {
3442
+ return __awaiter(this, void 0, void 0, function () {
3443
+ var style, e_1, type, e_2, hideError, error, code;
3444
+ return __generator(this, function (_a) {
3445
+ switch (_a.label) {
3446
+ case 0:
3447
+ style = null;
3448
+ if (!styleId) return [3 /*break*/, 4];
3449
+ _a.label = 1;
3450
+ case 1:
3451
+ _a.trys.push([1, 3, , 4]);
3452
+ return [4 /*yield*/, Style.Get({
3453
+ api: api,
3454
+ styleId: styleId
3455
+ })];
3456
+ case 2:
3457
+ style = (_a.sent()).style;
3458
+ return [3 /*break*/, 4];
3459
+ case 3:
3460
+ e_1 = _a.sent();
3461
+ console.error(e_1);
3462
+ return [3 /*break*/, 4];
3463
+ case 4:
3464
+ if (!(!style && typeId)) return [3 /*break*/, 9];
3465
+ return [4 /*yield*/, EntityType.Get({
3466
+ api: api,
3467
+ entityTypeId: typeId
3468
+ })];
3469
+ case 5:
3470
+ type = (_a.sent()).entityType;
3471
+ if (!type["DisplaySetting.ID"]) return [3 /*break*/, 9];
3472
+ _a.label = 6;
3473
+ case 6:
3474
+ _a.trys.push([6, 8, , 9]);
3475
+ return [4 /*yield*/, Style.Get({
3476
+ api: api,
3477
+ styleId: type["DisplaySetting.ID"]
3478
+ })];
3479
+ case 7:
3480
+ style = (_a.sent()).style;
3481
+ return [3 /*break*/, 9];
3482
+ case 8:
3483
+ e_2 = _a.sent();
3484
+ hideError = false;
3485
+ // TODO: we need a util for extracting code + message rather than writing all this every time.
3486
+ if (e_2 && typeof e_2 == "object" && e_2.ERROR) {
3487
+ error = e_2.ERROR;
3488
+ code = error && typeof error == "object" ? error.Code : "";
3489
+ // Avoiding logging a common error.
3490
+ // This happens when rendering entities that don't have records.
3491
+ hideError = String(code).toLowerCase() == "notfound";
3492
+ }
3493
+ if (!hideError) {
3494
+ console.error(e_2);
3495
+ }
3496
+ return [3 /*break*/, 9];
3497
+ case 9: return [2 /*return*/, style];
3498
+ }
3499
+ });
3500
+ });
3501
+ }
3449
3502
  var RelationRenderEngine;
3450
3503
  (function (RelationRenderEngine) {
3451
3504
  function GetRenderGroupId(relation) {
@@ -3454,81 +3507,55 @@ var RelationRenderEngine;
3454
3507
  RelationRenderEngine.GetRenderGroupId = GetRenderGroupId;
3455
3508
  function Render(params) {
3456
3509
  return __awaiter(this, void 0, void 0, function () {
3457
- var apiGetter, viewer, visualRegister, menuItemId, relations, api, rendered, i, relation, fromEntity, toEntity, dataEntity, _a, relationType, styleId, typeId, entityType, _b, style, _c, cEntity;
3458
- return __generator(this, function (_d) {
3459
- switch (_d.label) {
3510
+ var apiGetter, viewer, visualRegister, menuItemId, relations, api, rendered, i, relation, fromEntity, toEntity, dataEntity, _a, relationType, style, cEntity, e_3;
3511
+ return __generator(this, function (_b) {
3512
+ switch (_b.label) {
3460
3513
  case 0:
3461
3514
  apiGetter = params.apiGetter, viewer = params.viewer, visualRegister = params.visualRegister, menuItemId = params.menuItemId, relations = params.relations;
3462
3515
  api = apiGetter.getApi(apiGetter.accountId);
3463
3516
  rendered = {};
3464
3517
  i = 0;
3465
- _d.label = 1;
3518
+ _b.label = 1;
3466
3519
  case 1:
3467
- if (!(i < relations.length)) return [3 /*break*/, 17];
3520
+ if (!(i < relations.length)) return [3 /*break*/, 13];
3521
+ _b.label = 2;
3522
+ case 2:
3523
+ _b.trys.push([2, 11, , 12]);
3468
3524
  relation = relations[i];
3469
3525
  return [4 /*yield*/, Entity$1.Get({
3470
3526
  api: api,
3471
3527
  entityId: relation["Principal.Entity.ID"],
3472
3528
  })];
3473
- case 2:
3474
- fromEntity = (_d.sent()).entity;
3529
+ case 3:
3530
+ fromEntity = (_b.sent()).entity;
3475
3531
  return [4 /*yield*/, Entity$1.Get({
3476
3532
  api: api,
3477
3533
  entityId: relation["Related.Entity.ID"],
3478
3534
  })];
3479
- case 3:
3480
- toEntity = (_d.sent()).entity;
3481
- if (!relation["Data.Entity.ID"]) return [3 /*break*/, 5];
3535
+ case 4:
3536
+ toEntity = (_b.sent()).entity;
3537
+ if (!relation["Data.Entity.ID"]) return [3 /*break*/, 6];
3482
3538
  return [4 /*yield*/, Entity$1.Get({
3483
3539
  api: api,
3484
3540
  entityId: relation["Data.Entity.ID"]
3485
3541
  })];
3486
- case 4:
3487
- _a = (_d.sent()).entity;
3488
- return [3 /*break*/, 6];
3489
3542
  case 5:
3490
- _a = null;
3491
- _d.label = 6;
3543
+ _a = (_b.sent()).entity;
3544
+ return [3 /*break*/, 7];
3492
3545
  case 6:
3546
+ _a = null;
3547
+ _b.label = 7;
3548
+ case 7:
3493
3549
  dataEntity = _a;
3494
3550
  return [4 /*yield*/, EntityRelationType.Get({
3495
3551
  api: api,
3496
3552
  relationTypeId: relation["Relation.Type.ID"]
3497
3553
  })];
3498
- case 7:
3499
- relationType = (_d.sent()).relationType;
3500
- styleId = Number(relationType === null || relationType === void 0 ? void 0 : relationType.EntityDisplaySettingID);
3501
- if (!!styleId) return [3 /*break*/, 11];
3502
- typeId = relationType === null || relationType === void 0 ? void 0 : relationType["Relation.EntityType.ID"];
3503
- if (!typeId) return [3 /*break*/, 9];
3504
- return [4 /*yield*/, EntityType.Get({
3505
- api: api,
3506
- entityTypeId: typeId
3507
- })];
3508
3554
  case 8:
3509
- _b = (_d.sent()).entityType;
3510
- return [3 /*break*/, 10];
3555
+ relationType = (_b.sent()).relationType;
3556
+ 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))];
3511
3557
  case 9:
3512
- _b = null;
3513
- _d.label = 10;
3514
- case 10:
3515
- entityType = _b;
3516
- styleId = entityType === null || entityType === void 0 ? void 0 : entityType["DisplaySetting.ID"];
3517
- _d.label = 11;
3518
- case 11:
3519
- if (!styleId) return [3 /*break*/, 13];
3520
- return [4 /*yield*/, Style.Get({
3521
- api: api,
3522
- styleId: styleId
3523
- })];
3524
- case 12:
3525
- _c = (_d.sent()).style;
3526
- return [3 /*break*/, 14];
3527
- case 13:
3528
- _c = null;
3529
- _d.label = 14;
3530
- case 14:
3531
- style = _c;
3558
+ style = _b.sent();
3532
3559
  return [4 /*yield*/, Parabola.Render({
3533
3560
  dataEntity: dataEntity,
3534
3561
  fromEntity: fromEntity,
@@ -3539,15 +3566,19 @@ var RelationRenderEngine;
3539
3566
  visualRegister: visualRegister,
3540
3567
  apiGetter: apiGetter
3541
3568
  })];
3542
- case 15:
3543
- cEntity = _d.sent();
3569
+ case 10:
3570
+ cEntity = _b.sent();
3544
3571
  cEntity._renderGroup = GetRenderGroupId(relation);
3545
3572
  rendered[GetRenderGroupId(relation)] = cEntity;
3546
- _d.label = 16;
3547
- case 16:
3573
+ return [3 /*break*/, 12];
3574
+ case 11:
3575
+ e_3 = _b.sent();
3576
+ console.error(e_3);
3577
+ return [3 /*break*/, 12];
3578
+ case 12:
3548
3579
  i++;
3549
3580
  return [3 /*break*/, 1];
3550
- case 17: return [2 /*return*/, rendered];
3581
+ case 13: return [2 /*return*/, rendered];
3551
3582
  }
3552
3583
  });
3553
3584
  });
@@ -3575,7 +3606,7 @@ var RelationRenderEngine;
3575
3606
  toPos = null;
3576
3607
  updatingPosses = false;
3577
3608
  updatePosses = function () { return __awaiter(_this, void 0, void 0, function () {
3578
- var e_1;
3609
+ var e_4;
3579
3610
  return __generator(this, function (_a) {
3580
3611
  switch (_a.label) {
3581
3612
  case 0:
@@ -3612,8 +3643,8 @@ var RelationRenderEngine;
3612
3643
  toPos = _a.sent();
3613
3644
  return [3 /*break*/, 5];
3614
3645
  case 4:
3615
- e_1 = _a.sent();
3616
- console.error(e_1);
3646
+ e_4 = _a.sent();
3647
+ console.error(e_4);
3617
3648
  return [3 /*break*/, 5];
3618
3649
  case 5:
3619
3650
  updatingPosses = false;
@@ -8286,135 +8317,129 @@ var TilesetEntitiesRenderManager;
8286
8317
  configurable: true
8287
8318
  });
8288
8319
  Manager.prototype.Init = function (params) {
8320
+ var _this = this;
8289
8321
  var _a;
8290
- return __awaiter(this, void 0, void 0, function () {
8291
- var counter, tilesetId;
8322
+ this.initCounter += 1;
8323
+ var counter = this.initCounter;
8324
+ if (this.disposed) {
8325
+ return;
8326
+ }
8327
+ if (params === null || params === void 0 ? void 0 : params.item) {
8328
+ this.item = params.item;
8329
+ }
8330
+ var tilesetId = (_a = this.item.tileset) === null || _a === void 0 ? void 0 : _a.TilesetID;
8331
+ if (!tilesetId) {
8332
+ return;
8333
+ }
8334
+ (function () { return __awaiter(_this, void 0, void 0, function () {
8335
+ var canAccess, e_1, accountId, api, tileset, cTileset, _a, attenuation, attenuationMax;
8292
8336
  var _this = this;
8293
- return __generator(this, function (_b) {
8294
- this.initCounter += 1;
8295
- counter = this.initCounter;
8296
- if (this.disposed) {
8297
- return [2 /*return*/];
8298
- }
8299
- if (params === null || params === void 0 ? void 0 : params.item) {
8300
- this.item = params.item;
8301
- }
8302
- tilesetId = (_a = this.item.tileset) === null || _a === void 0 ? void 0 : _a.TilesetID;
8303
- if (!tilesetId) {
8304
- return [2 /*return*/];
8305
- }
8306
- (function () { return __awaiter(_this, void 0, void 0, function () {
8307
- var canAccess, e_1, accountId, api, tileset, cTileset, _a, attenuation, attenuationMax;
8308
- var _this = this;
8309
- var _b, _c, _d;
8310
- return __generator(this, function (_e) {
8311
- switch (_e.label) {
8312
- case 0:
8313
- if (!!this.cTileset) return [3 /*break*/, 9];
8314
- if (!tilesetId) return [3 /*break*/, 5];
8315
- canAccess = false;
8316
- _e.label = 1;
8317
- case 1:
8318
- _e.trys.push([1, 3, , 4]);
8319
- return [4 /*yield*/, Tileset.Publish.IsAccessAllowed({
8320
- sourceAccountId: (_b = this.item.tileset) === null || _b === void 0 ? void 0 : _b.ClientAccountID,
8321
- tilesetId: tilesetId,
8322
- forAccountId: this.getters.GetAccountId(),
8323
- api: this.getters.GetGlobalApi()
8324
- })];
8325
- case 2:
8326
- canAccess = _e.sent();
8327
- return [3 /*break*/, 4];
8328
- case 3:
8329
- e_1 = _e.sent();
8330
- console.error(e_1);
8331
- return [3 /*break*/, 4];
8332
- case 4:
8333
- if (!canAccess) {
8334
- console.warn("Cannot access tileset: ".concat(tilesetId, ", from account: ").concat((_c = this.item.tileset) === null || _c === void 0 ? void 0 : _c.ClientAccountID, "."));
8335
- return [2 /*return*/];
8336
- }
8337
- return [3 /*break*/, 6];
8338
- case 5:
8339
- console.warn("No tileset id found. Skipping access check.");
8340
- _e.label = 6;
8341
- case 6:
8342
- if (this.disposed || counter !== this.initCounter) {
8343
- return [2 /*return*/];
8344
- }
8345
- accountId = (_d = this.item.tileset) === null || _d === void 0 ? void 0 : _d.ClientAccountID;
8346
- if (!accountId) {
8347
- accountId = this.getters.GetAccountId();
8348
- }
8349
- api = this.getters.GetBruceApi({
8350
- accountId: accountId
8351
- });
8352
- return [4 /*yield*/, Tileset.Get({
8353
- api: api,
8354
- tilesetId: tilesetId
8355
- })];
8356
- case 7:
8357
- tileset = (_e.sent()).tileset;
8358
- if (!tileset || this.disposed || counter !== this.initCounter) {
8359
- return [2 /*return*/];
8360
- }
8361
- this.typeId = tileset.settings.entityTypeId;
8362
- _a = this;
8363
- return [4 /*yield*/, TilesetRenderEngine.Render({
8364
- apiGetter: this.getters.GetBruceGetter(),
8365
- tileset: tileset,
8366
- viewer: this.viewer,
8367
- accountId: accountId,
8368
- viaCdn: this.item.cdnEnabled
8369
- })];
8370
- case 8:
8371
- cTileset = _a.cTileset = _e.sent();
8372
- if (this.disposed) {
8373
- this.doDispose();
8374
- return [2 /*return*/];
8375
- }
8376
- this.viewer.scene.requestRender();
8377
- cTileset.readyPromise.then(function () {
8378
- try {
8379
- if (_this.disposed || _this.viewer.isDestroyed()) {
8380
- return;
8381
- }
8382
- _this.onCTilesetLoad();
8383
- _this.viewer.scene.requestRender();
8384
- }
8385
- catch (e) {
8386
- console.error(e);
8387
- }
8388
- });
8389
- cTileset.tileLoad.addEventListener(function (tile) {
8390
- _this.mapCTile(tile);
8391
- });
8392
- _e.label = 9;
8393
- case 9:
8394
- attenuation = this.item.attenuation;
8395
- if (!attenuation && attenuation != false) {
8396
- attenuation = true;
8397
- }
8398
- attenuationMax = this.item.attenuationMax;
8399
- if (isNaN(attenuationMax)) {
8400
- attenuationMax = 20;
8337
+ var _b, _c, _d;
8338
+ return __generator(this, function (_e) {
8339
+ switch (_e.label) {
8340
+ case 0:
8341
+ if (!!this.cTileset) return [3 /*break*/, 9];
8342
+ if (!tilesetId) return [3 /*break*/, 5];
8343
+ canAccess = false;
8344
+ _e.label = 1;
8345
+ case 1:
8346
+ _e.trys.push([1, 3, , 4]);
8347
+ return [4 /*yield*/, Tileset.Publish.IsAccessAllowed({
8348
+ sourceAccountId: (_b = this.item.tileset) === null || _b === void 0 ? void 0 : _b.ClientAccountID,
8349
+ tilesetId: tilesetId,
8350
+ forAccountId: this.getters.GetAccountId(),
8351
+ api: this.getters.GetGlobalApi()
8352
+ })];
8353
+ case 2:
8354
+ canAccess = _e.sent();
8355
+ return [3 /*break*/, 4];
8356
+ case 3:
8357
+ e_1 = _e.sent();
8358
+ console.error(e_1);
8359
+ return [3 /*break*/, 4];
8360
+ case 4:
8361
+ if (!canAccess) {
8362
+ console.warn("Cannot access tileset: ".concat(tilesetId, ", from account: ").concat((_c = this.item.tileset) === null || _c === void 0 ? void 0 : _c.ClientAccountID, "."));
8363
+ return [2 /*return*/];
8364
+ }
8365
+ return [3 /*break*/, 6];
8366
+ case 5:
8367
+ console.warn("No tileset id found. Skipping access check.");
8368
+ _e.label = 6;
8369
+ case 6:
8370
+ if (this.disposed || counter !== this.initCounter) {
8371
+ return [2 /*return*/];
8372
+ }
8373
+ accountId = (_d = this.item.tileset) === null || _d === void 0 ? void 0 : _d.ClientAccountID;
8374
+ if (!accountId) {
8375
+ accountId = this.getters.GetAccountId();
8376
+ }
8377
+ api = this.getters.GetBruceApi({
8378
+ accountId: accountId
8379
+ });
8380
+ return [4 /*yield*/, Tileset.Get({
8381
+ api: api,
8382
+ tilesetId: tilesetId
8383
+ })];
8384
+ case 7:
8385
+ tileset = (_e.sent()).tileset;
8386
+ if (!tileset || this.disposed || counter !== this.initCounter) {
8387
+ return [2 /*return*/];
8388
+ }
8389
+ this.typeId = tileset.settings.entityTypeId;
8390
+ _a = this;
8391
+ return [4 /*yield*/, TilesetRenderEngine.Render({
8392
+ apiGetter: this.getters.GetBruceGetter(),
8393
+ tileset: tileset,
8394
+ viewer: this.viewer,
8395
+ accountId: accountId,
8396
+ viaCdn: this.item.cdnEnabled
8397
+ })];
8398
+ case 8:
8399
+ cTileset = _a.cTileset = _e.sent();
8400
+ if (this.disposed) {
8401
+ this.doDispose();
8402
+ return [2 /*return*/];
8403
+ }
8404
+ this.viewer.scene.requestRender();
8405
+ cTileset.readyPromise.then(function () {
8406
+ try {
8407
+ if (_this.disposed || _this.viewer.isDestroyed()) {
8408
+ return;
8401
8409
  }
8402
- this.cTileset.readyPromise.then(function () {
8403
- TilesetRenderEngine.ApplySettings({
8404
- cTileset: _this.cTileset,
8405
- settings: {
8406
- attenuation: attenuation,
8407
- maximumAttenuation: attenuationMax
8408
- }
8409
- });
8410
- });
8411
- return [2 /*return*/];
8410
+ _this.onCTilesetLoad();
8411
+ _this.viewer.scene.requestRender();
8412
+ }
8413
+ catch (e) {
8414
+ console.error(e);
8415
+ }
8416
+ });
8417
+ cTileset.tileLoad.addEventListener(function (tile) {
8418
+ _this.mapCTile(tile);
8419
+ });
8420
+ _e.label = 9;
8421
+ case 9:
8422
+ attenuation = this.item.attenuation;
8423
+ if (!attenuation && attenuation != false) {
8424
+ attenuation = true;
8412
8425
  }
8413
- });
8414
- }); })();
8415
- return [2 /*return*/];
8426
+ attenuationMax = this.item.attenuationMax;
8427
+ if (isNaN(attenuationMax)) {
8428
+ attenuationMax = 20;
8429
+ }
8430
+ this.cTileset.readyPromise.then(function () {
8431
+ TilesetRenderEngine.ApplySettings({
8432
+ cTileset: _this.cTileset,
8433
+ settings: {
8434
+ attenuation: attenuation,
8435
+ maximumAttenuation: attenuationMax
8436
+ }
8437
+ });
8438
+ });
8439
+ return [2 /*return*/];
8440
+ }
8416
8441
  });
8417
- });
8442
+ }); })();
8418
8443
  };
8419
8444
  Manager.prototype.Dispose = function () {
8420
8445
  if (this.disposed) {
@@ -9105,6 +9130,8 @@ var RelationsRenderManager;
9105
9130
  (function (RelationsRenderManager) {
9106
9131
  var Manager = /** @class */ (function () {
9107
9132
  function Manager(params) {
9133
+ // If true, this menu item is disposed and should not be used.
9134
+ // Any rendering will be ignored.
9108
9135
  this.disposed = false;
9109
9136
  var apiGetter = params.apiGetter, item = params.item, register = params.register, viewer = params.viewer;
9110
9137
  this.apiGetter = apiGetter;
@@ -9119,56 +9146,62 @@ var RelationsRenderManager;
9119
9146
  enumerable: false,
9120
9147
  configurable: true
9121
9148
  });
9122
- Manager.prototype.Init = function () {
9123
- var _this = this;
9124
- var drawn = [];
9125
- var api = this.apiGetter.getApi(this.apiGetter.accountId);
9126
- var BATCH_SIZE = 5;
9127
- var drawBatch = [];
9128
- var pending = this.item.BruceEntity.EntityIds.length;
9129
- var onResolve = function () {
9130
- pending -= 1;
9131
- if (pending <= 0) {
9132
- if (drawBatch === null || drawBatch === void 0 ? void 0 : drawBatch.length) {
9133
- _this.onGetterUpdate(drawBatch);
9149
+ /**
9150
+ * Starts rendering the menu item.
9151
+ * Re-call with an updated menu item to re-render. It will auto-cleanup old relations.
9152
+ * @param params
9153
+ * @returns
9154
+ */
9155
+ Manager.prototype.Init = function (params) {
9156
+ var _a;
9157
+ if (this.disposed) {
9158
+ return;
9159
+ }
9160
+ if (params === null || params === void 0 ? void 0 : params.item) {
9161
+ this.item = params.item;
9162
+ }
9163
+ // Remove relationships we no longer want to render.
9164
+ // We'll have to get regos by the menu item ID then run a check on the related rego relationship.
9165
+ var regos = this.register.GetRegos({
9166
+ menuItemId: this.item.id
9167
+ });
9168
+ var drawnIds = [];
9169
+ var toDrawIds = [];
9170
+ var entityIds = (_a = this.item.BruceEntity) === null || _a === void 0 ? void 0 : _a.EntityIds;
9171
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
9172
+ entityIds = [];
9173
+ }
9174
+ for (var i = 0; i < regos.length; i++) {
9175
+ var rego = regos[i];
9176
+ if (!this.shouldRenderRelation(rego.relation)) {
9177
+ this.register.RemoveRegos({
9178
+ relation: rego.relation,
9179
+ entityId: rego.entityId,
9180
+ menuItemId: this.item.id,
9181
+ requestRender: false
9182
+ });
9183
+ }
9184
+ else {
9185
+ drawnIds.push(rego.entityId);
9186
+ if (rego.relation) {
9187
+ drawnIds.push(rego.relation["Principal.Entity.ID"]);
9188
+ drawnIds.push(rego.relation["Related.Entity.ID"]);
9134
9189
  }
9135
9190
  }
9191
+ }
9192
+ this.viewer.scene.requestRender();
9193
+ var _loop_1 = function (i) {
9194
+ if (!drawnIds.find(function (x) { return x == entityIds[i]; })) {
9195
+ toDrawIds.push(entityIds[i]);
9196
+ }
9136
9197
  };
9137
- for (var i = 0; i < this.item.BruceEntity.EntityIds.length; i++) {
9138
- var entityId = this.item.BruceEntity.EntityIds[i];
9139
- EntityRelation.GetList({
9140
- api: api,
9141
- entityId: entityId,
9142
- filter: {
9143
- oneWayOnly: false,
9144
- loadEntityData: false
9145
- }
9146
- }).then(function (data) {
9147
- var _a;
9148
- var relations = data.relations;
9149
- var _loop_1 = function (j) {
9150
- var relation = relations[j];
9151
- if (((_a = _this.item.relationTypeIds) === null || _a === void 0 ? void 0 : _a.length) && !_this.item.relationTypeIds.includes(relation["Relation.Type.ID"])) {
9152
- return "continue";
9153
- }
9154
- var key = RelationRenderEngine.GetRenderGroupId(relation);
9155
- if (!drawn.find(function (x) { return x == key; })) {
9156
- drawn.push(key);
9157
- drawBatch.push(relation);
9158
- if (drawBatch.length >= BATCH_SIZE) {
9159
- _this.onGetterUpdate(drawBatch);
9160
- drawBatch = [];
9161
- }
9162
- }
9163
- };
9164
- for (var j = 0; j < relations.length; j++) {
9165
- _loop_1(j);
9166
- }
9167
- onResolve();
9168
- }).catch(function (e) {
9169
- onResolve();
9170
- });
9198
+ // We'll call a re-render on entity ids that are not drawn.
9199
+ for (var i = 0; i < entityIds.length; i++) {
9200
+ _loop_1(i);
9171
9201
  }
9202
+ this.renderEntityIds({
9203
+ entityIds: toDrawIds
9204
+ });
9172
9205
  };
9173
9206
  Manager.prototype.Dispose = function () {
9174
9207
  if (this.disposed) {
@@ -9179,19 +9212,154 @@ var RelationsRenderManager;
9179
9212
  menuItemId: this.item.id
9180
9213
  });
9181
9214
  };
9215
+ /**
9216
+ * Re-renders specific entity relationships.
9217
+ * @TODO: This should re-render all relationships when entityIds=null.
9218
+ * @param params
9219
+ */
9182
9220
  Manager.prototype.ReRender = function (params) {
9183
9221
  return __awaiter(this, void 0, void 0, function () {
9184
9222
  var entityIds, force;
9185
9223
  return __generator(this, function (_a) {
9186
9224
  entityIds = params.entityIds, force = params.force;
9225
+ if (entityIds == null) ;
9226
+ else {
9227
+ this.renderEntityIds({
9228
+ dataEntityIds: entityIds
9229
+ });
9230
+ }
9187
9231
  return [2 /*return*/];
9188
9232
  });
9189
9233
  });
9190
9234
  };
9235
+ /**
9236
+ * Gets relationship records corresponding to provided IDs and requests a render for them.
9237
+ */
9238
+ Manager.prototype.renderEntityIds = function (params) {
9239
+ return __awaiter(this, void 0, void 0, function () {
9240
+ var entityIds, dataEntityIds, drawn, api, BATCH_SIZE, drawBatch, pending, onResolve, i, entityId, i, entityId;
9241
+ var _this = this;
9242
+ return __generator(this, function (_a) {
9243
+ if (this.disposed || this.viewer.isDestroyed()) {
9244
+ return [2 /*return*/];
9245
+ }
9246
+ entityIds = params.entityIds, dataEntityIds = params.dataEntityIds;
9247
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
9248
+ entityIds = [];
9249
+ }
9250
+ if (!(dataEntityIds === null || dataEntityIds === void 0 ? void 0 : dataEntityIds.length)) {
9251
+ dataEntityIds = [];
9252
+ }
9253
+ drawn = [];
9254
+ api = this.apiGetter.getApi(this.apiGetter.accountId);
9255
+ BATCH_SIZE = 5;
9256
+ drawBatch = [];
9257
+ pending = entityIds.length + dataEntityIds.length;
9258
+ onResolve = function () {
9259
+ if (_this.disposed || _this.viewer.isDestroyed()) {
9260
+ return;
9261
+ }
9262
+ pending -= 1;
9263
+ if (pending <= 0) {
9264
+ if (drawBatch === null || drawBatch === void 0 ? void 0 : drawBatch.length) {
9265
+ _this.onGetterUpdate(drawBatch);
9266
+ }
9267
+ }
9268
+ };
9269
+ // Get relationships by their data entity ID.
9270
+ for (i = 0; i < dataEntityIds.length; i++) {
9271
+ entityId = dataEntityIds[i];
9272
+ EntityRelation.GetByDataEntityId({
9273
+ entityId: entityId,
9274
+ api: api
9275
+ }).then(function (data) {
9276
+ if (data.relation) {
9277
+ var relation = data.relation;
9278
+ var key_1 = RelationRenderEngine.GetRenderGroupId(relation);
9279
+ if (!drawn.find(function (x) { return x == key_1; })) {
9280
+ drawn.push(key_1);
9281
+ drawBatch.push(relation);
9282
+ if (drawBatch.length >= BATCH_SIZE) {
9283
+ _this.onGetterUpdate(drawBatch);
9284
+ drawBatch = [];
9285
+ }
9286
+ }
9287
+ }
9288
+ onResolve();
9289
+ }).catch(function (e) {
9290
+ onResolve();
9291
+ });
9292
+ }
9293
+ // Get relationships by either the parent or child ID.
9294
+ for (i = 0; i < entityIds.length; i++) {
9295
+ entityId = entityIds[i];
9296
+ EntityRelation.GetList({
9297
+ api: api,
9298
+ entityId: entityId,
9299
+ filter: {
9300
+ oneWayOnly: false,
9301
+ loadEntityData: false
9302
+ }
9303
+ }).then(function (data) {
9304
+ var relations = data.relations;
9305
+ var _loop_2 = function (j) {
9306
+ var relation = relations[j];
9307
+ var key = RelationRenderEngine.GetRenderGroupId(relation);
9308
+ if (!drawn.find(function (x) { return x == key; })) {
9309
+ drawn.push(key);
9310
+ drawBatch.push(relation);
9311
+ if (drawBatch.length >= BATCH_SIZE) {
9312
+ _this.onGetterUpdate(drawBatch);
9313
+ drawBatch = [];
9314
+ }
9315
+ }
9316
+ };
9317
+ for (var j = 0; j < relations.length; j++) {
9318
+ _loop_2(j);
9319
+ }
9320
+ onResolve();
9321
+ }).catch(function (e) {
9322
+ onResolve();
9323
+ });
9324
+ }
9325
+ return [2 /*return*/];
9326
+ });
9327
+ });
9328
+ };
9329
+ /**
9330
+ * Returns if a relation should be rendered.
9331
+ * This is in case the menu item was updated and the relation is no longer relevant.
9332
+ * @param relation
9333
+ */
9334
+ Manager.prototype.shouldRenderRelation = function (relation) {
9335
+ var _a, _b, _c;
9336
+ if (((_a = this.item.relationTypeIds) === null || _a === void 0 ? void 0 : _a.length) && !this.item.relationTypeIds.includes(relation["Relation.Type.ID"])) {
9337
+ return false;
9338
+ }
9339
+ var renderedIds = (_c = (_b = this.item) === null || _b === void 0 ? void 0 : _b.BruceEntity) === null || _c === void 0 ? void 0 : _c.EntityIds;
9340
+ if (!renderedIds) {
9341
+ return false;
9342
+ }
9343
+ var ids = [
9344
+ relation["Principal.Entity.ID"],
9345
+ relation["Related.Entity.ID"]
9346
+ ];
9347
+ if (relation["Data.Entity.ID"]) {
9348
+ ids.push(relation["Data.Entity.ID"]);
9349
+ }
9350
+ return ids.some(function (x) { return renderedIds.includes(x); });
9351
+ };
9352
+ /**
9353
+ * Renders batch of entity relationships.
9354
+ * This will check if a relationship SHOULD be rendered before rendering it.
9355
+ * It will also handle already rendered relations to avoid re-rendering them.
9356
+ * @param relations
9357
+ */
9191
9358
  Manager.prototype.onGetterUpdate = function (relations) {
9192
9359
  var _a, _b;
9193
9360
  return __awaiter(this, void 0, void 0, function () {
9194
- var cEntities, i, relation, key, cEntity, visual, e_1;
9361
+ var killCEntity, cEntities, key, i, relation, key, cEntity, visual, e_1;
9362
+ var _this = this;
9195
9363
  return __generator(this, function (_c) {
9196
9364
  switch (_c.label) {
9197
9365
  case 0:
@@ -9199,6 +9367,12 @@ var RelationsRenderManager;
9199
9367
  if (this.disposed || this.viewer.isDestroyed()) {
9200
9368
  return [2 /*return*/];
9201
9369
  }
9370
+ relations = relations.filter(function (x) { return _this.shouldRenderRelation(x); });
9371
+ killCEntity = function (cEntity) {
9372
+ if (cEntity && !_this.viewer.isDestroyed() && _this.viewer.entities.contains(cEntity)) {
9373
+ _this.viewer.entities.remove(cEntity);
9374
+ }
9375
+ };
9202
9376
  return [4 /*yield*/, RelationRenderEngine.Render({
9203
9377
  apiGetter: this.apiGetter,
9204
9378
  menuItemId: this.item.id,
@@ -9212,13 +9386,16 @@ var RelationsRenderManager;
9212
9386
  this.register.RemoveRegos({
9213
9387
  menuItemId: this.item.id
9214
9388
  });
9389
+ for (key in cEntities) {
9390
+ killCEntity(cEntities[key]);
9391
+ }
9215
9392
  return [2 /*return*/];
9216
9393
  }
9217
9394
  for (i = 0; i < relations.length; i++) {
9218
9395
  relation = relations[i];
9219
9396
  key = RelationRenderEngine.GetRenderGroupId(relation);
9220
9397
  cEntity = cEntities[key];
9221
- if (cEntity) {
9398
+ if (cEntity && this.shouldRenderRelation(relation)) {
9222
9399
  visual = (_a = this.register.GetRego({
9223
9400
  entityId: key,
9224
9401
  menuItemId: this.item.id
@@ -9244,6 +9421,7 @@ var RelationsRenderManager;
9244
9421
  menuItemId: this.item.id,
9245
9422
  requestRender: false
9246
9423
  });
9424
+ killCEntity(cEntity);
9247
9425
  }
9248
9426
  }
9249
9427
  this.viewer.scene.requestRender();
@@ -9443,6 +9621,14 @@ var MenuItemManager;
9443
9621
  });
9444
9622
  rItem.item = params.item;
9445
9623
  }
9624
+ // This means we're updating a rendered relationships menu item.
9625
+ // Eg: different entities need to be rendered, or one of the relationship data entities changed.
9626
+ else if (rItem.type == MenuItem.EType.Relations && params.item.Type == MenuItem.EType.Relations) {
9627
+ rItem.renderManager.Init({
9628
+ item: params.item,
9629
+ });
9630
+ rItem.item = params.item;
9631
+ }
9446
9632
  }
9447
9633
  else {
9448
9634
  rItem = {
@@ -12350,7 +12536,7 @@ function renderNavigator(iteration, params, bookmark, view) {
12350
12536
  for (_i = 0, curEnabled_1 = curEnabled; _i < curEnabled_1.length; _i++) {
12351
12537
  id = curEnabled_1[_i];
12352
12538
  if (newItemIds.indexOf(id) === -1 ||
12353
- id == RELATION_MENU_ITEM_ID) {
12539
+ (id == RELATION_MENU_ITEM_ID && !renderedRelationEntityIds.length)) {
12354
12540
  params.manager.RemoveItemById({
12355
12541
  menuItemId: id
12356
12542
  });
@@ -12370,7 +12556,7 @@ function renderNavigator(iteration, params, bookmark, view) {
12370
12556
  }
12371
12557
  _6.label = 4;
12372
12558
  case 4:
12373
- if (!(renderedRelationEntityIds.length > 0)) return [3 /*break*/, 6];
12559
+ if (!renderedRelationEntityIds.length) return [3 /*break*/, 6];
12374
12560
  menuItem = {
12375
12561
  id: RELATION_MENU_ITEM_ID,
12376
12562
  Caption: "Entity relations",
@@ -15296,7 +15482,7 @@ var ViewerUtils;
15296
15482
  ViewerUtils.CreateWidgets = CreateWidgets;
15297
15483
  })(ViewerUtils || (ViewerUtils = {}));
15298
15484
 
15299
- var VERSION$1 = "2.7.8";
15485
+ var VERSION$1 = "2.7.9";
15300
15486
 
15301
15487
  export { VERSION$1 as VERSION, CesiumViewMonitor, ViewerUtils, MenuItemManager, EntityRenderEngine, MenuItemCreator, VisualsRegister, RenderManager, EntitiesIdsRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, TilesetCadRenderManager, TilesetArbRenderManager, TilesetEntitiesRenderManager, TilesetOsmRenderManager, TilesetPointcloudRenderManager, TilesetGooglePhotosRenderManager, DataSourceStaticKmlManager, RelationsRenderManager, SharedGetters, CesiumParabola, ViewRenderEngine, TileRenderEngine, TilesetRenderEngine, CESIUM_INSPECTOR_KEY, ViewUtils, DrawingUtils, MeasureUtils, EntityUtils, Draw3dPolygon, Draw3dPolyline };
15302
15488
  //# sourceMappingURL=bruce-cesium.es5.js.map