bruce-cesium 2.7.4 → 2.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1764,7 +1764,7 @@
1764
1764
  }
1765
1765
  function getStyle(api, entity, styleId) {
1766
1766
  return __awaiter(this, void 0, void 0, function () {
1767
- var style, e_2, typeId, type, e_3;
1767
+ var style, e_2, typeId, type, e_3, hideError, error, code;
1768
1768
  return __generator(this, function (_a) {
1769
1769
  switch (_a.label) {
1770
1770
  case 0:
@@ -1807,7 +1807,18 @@
1807
1807
  return [3 /*break*/, 9];
1808
1808
  case 8:
1809
1809
  e_3 = _a.sent();
1810
- console.error(e_3);
1810
+ hideError = false;
1811
+ // TODO: we need a util for extracting code + message rather than writing all this every time.
1812
+ if (e_3 && typeof e_3 == "object" && e_3.ERROR) {
1813
+ error = e_3.ERROR;
1814
+ code = error && typeof error == "object" ? error.Code : "";
1815
+ // Avoiding logging a common error.
1816
+ // This happens when rendering entities that don't have records.
1817
+ hideError = String(code).toLowerCase() == "notfound";
1818
+ }
1819
+ if (!hideError) {
1820
+ console.error(e_3);
1821
+ }
1811
1822
  return [3 /*break*/, 9];
1812
1823
  case 9: return [2 /*return*/, style];
1813
1824
  }
@@ -5506,16 +5517,14 @@
5506
5517
  viewer: this.viewer,
5507
5518
  // Unfortunately this searches as an "AND" rather than "OR" which does not meet our needs here.
5508
5519
  // So for multiple tags we'll manually sort on UI end...
5509
- tagIds: tagsToRender.length == 1 ? tagsToRender : [],
5520
+ tagIds: (tagsToRender === null || tagsToRender === void 0 ? void 0 : tagsToRender.length) ? tagsToRender : [],
5510
5521
  debugShowBounds: Boolean(window === null || window === void 0 ? void 0 : window.ENTITIES_RENDER_MANAGER_SHOW_BOUNDS),
5511
5522
  cdn: this.item.cdnEnabled
5512
5523
  });
5513
5524
  var minMax = exports.RenderManager.GetZoomMinMax({
5514
5525
  zoomControl: this.item.CameraZoomSettings
5515
5526
  });
5516
- // Unfortunately this searches as an "AND" rather than "OR" which does not meet our needs here.
5517
- // So for multiple tags we'll manually sort on UI end...
5518
- this.getter.IncludeMenuItem(this.item.id, tagsToRender.length == 1 ? tagsToRender : [], minMax[0], minMax[1]);
5527
+ this.getter.IncludeMenuItem(this.item.id, (tagsToRender === null || tagsToRender === void 0 ? void 0 : tagsToRender.length) ? tagsToRender : [], minMax[0], minMax[1]);
5519
5528
  this.getterSub = this.getter.OnUpdate.Subscribe(function (entities) {
5520
5529
  if (isTagItem) {
5521
5530
  _this.distributeForRender(entities.filter(function (entity) {
@@ -8210,6 +8219,7 @@
8210
8219
  (function (TilesetEntitiesRenderManager) {
8211
8220
  var Manager = /** @class */ (function () {
8212
8221
  function Manager(params) {
8222
+ this.initCounter = 0;
8213
8223
  this.disposed = false;
8214
8224
  this.cTileset = null;
8215
8225
  var viewer = params.viewer, visualsManager = params.register, apiGetter = params.getters, item = params.item;
@@ -8232,23 +8242,32 @@
8232
8242
  enumerable: false,
8233
8243
  configurable: true
8234
8244
  });
8235
- Manager.prototype.Init = function () {
8245
+ Manager.prototype.Init = function (params) {
8236
8246
  var _a;
8237
8247
  return __awaiter(this, void 0, void 0, function () {
8238
- var tilesetId;
8248
+ var counter, tilesetId;
8239
8249
  var _this = this;
8240
8250
  return __generator(this, function (_b) {
8251
+ this.initCounter += 1;
8252
+ counter = this.initCounter;
8253
+ if (this.disposed) {
8254
+ return [2 /*return*/];
8255
+ }
8256
+ if (params === null || params === void 0 ? void 0 : params.item) {
8257
+ this.item = params.item;
8258
+ }
8241
8259
  tilesetId = (_a = this.item.tileset) === null || _a === void 0 ? void 0 : _a.TilesetID;
8242
8260
  if (!tilesetId) {
8243
8261
  return [2 /*return*/];
8244
8262
  }
8245
8263
  (function () { return __awaiter(_this, void 0, void 0, function () {
8246
- var canAccess, e_1, accountId, api, tileset, cTileset, _a;
8264
+ var canAccess, e_1, accountId, api, tileset, cTileset, _a, attenuation, attenuationMax;
8247
8265
  var _this = this;
8248
8266
  var _b, _c, _d;
8249
8267
  return __generator(this, function (_e) {
8250
8268
  switch (_e.label) {
8251
8269
  case 0:
8270
+ if (!!this.cTileset) return [3 /*break*/, 9];
8252
8271
  if (!tilesetId) return [3 /*break*/, 5];
8253
8272
  canAccess = false;
8254
8273
  _e.label = 1;
@@ -8277,6 +8296,9 @@
8277
8296
  console.warn("No tileset id found. Skipping access check.");
8278
8297
  _e.label = 6;
8279
8298
  case 6:
8299
+ if (this.disposed || counter !== this.initCounter) {
8300
+ return [2 /*return*/];
8301
+ }
8280
8302
  accountId = (_d = this.item.tileset) === null || _d === void 0 ? void 0 : _d.ClientAccountID;
8281
8303
  if (!accountId) {
8282
8304
  accountId = this.getters.GetAccountId();
@@ -8290,7 +8312,7 @@
8290
8312
  })];
8291
8313
  case 7:
8292
8314
  tileset = (_e.sent()).tileset;
8293
- if (!tileset || this.disposed) {
8315
+ if (!tileset || this.disposed || counter !== this.initCounter) {
8294
8316
  return [2 /*return*/];
8295
8317
  }
8296
8318
  this.typeId = tileset.settings.entityTypeId;
@@ -8324,6 +8346,25 @@
8324
8346
  cTileset.tileLoad.addEventListener(function (tile) {
8325
8347
  _this.mapCTile(tile);
8326
8348
  });
8349
+ _e.label = 9;
8350
+ case 9:
8351
+ attenuation = this.item.attenuation;
8352
+ if (!attenuation && attenuation != false) {
8353
+ attenuation = true;
8354
+ }
8355
+ attenuationMax = this.item.attenuationMax;
8356
+ if (isNaN(attenuationMax)) {
8357
+ attenuationMax = 20;
8358
+ }
8359
+ this.cTileset.readyPromise.then(function () {
8360
+ exports.TilesetRenderEngine.ApplySettings({
8361
+ cTileset: _this.cTileset,
8362
+ settings: {
8363
+ attenuation: attenuation,
8364
+ maximumAttenuation: attenuationMax
8365
+ }
8366
+ });
8367
+ });
8327
8368
  return [2 /*return*/];
8328
8369
  }
8329
8370
  });
@@ -9341,6 +9382,14 @@
9341
9382
  rItem.item = params.item;
9342
9383
  }
9343
9384
  }
9385
+ // This means we're updating a entities tileset menu item.
9386
+ // These have different point scaling settings based on bookmark settings.
9387
+ else if (rItem.type == bruceModels.MenuItem.EType.EntityTileset && params.item.Type == bruceModels.MenuItem.EType.EntityTileset) {
9388
+ rItem.renderManager.Init({
9389
+ item: params.item,
9390
+ });
9391
+ rItem.item = params.item;
9392
+ }
9344
9393
  }
9345
9394
  else {
9346
9395
  rItem = {
@@ -10008,7 +10057,7 @@
10008
10057
  renderedItemIds = [];
10009
10058
  if (!((menuItems === null || menuItems === void 0 ? void 0 : menuItems.length) && (enabledIds === null || enabledIds === void 0 ? void 0 : enabledIds.length))) return [3 /*break*/, 10];
10010
10059
  traverseItems_1 = function (item) { return __awaiter(_this, void 0, void 0, function () {
10011
- var eItem, eItemAlt, itemId, i;
10060
+ var eItem, eItemAlt, tItem, tItemAlt, itemId, i;
10012
10061
  var _a;
10013
10062
  return __generator(this, function (_b) {
10014
10063
  switch (_b.label) {
@@ -10023,6 +10072,12 @@
10023
10072
  eItem.BruceEntity = __assign(__assign({}, eItem.BruceEntity), { SelectedExpandLayers: (_a = eItemAlt.BruceEntity) === null || _a === void 0 ? void 0 : _a.SelectedExpandLayers });
10024
10073
  }
10025
10074
  }
10075
+ else if (item.Type == bruceModels.MenuItem.EType.EntityTileset) {
10076
+ tItem = item;
10077
+ tItemAlt = alternations[item.id];
10078
+ tItem.attenuation = tItemAlt.attenuation;
10079
+ tItem.attenuationMax = tItemAlt.attenuationMax;
10080
+ }
10026
10081
  }
10027
10082
  if (!enabledIds.includes(item.id)) return [3 /*break*/, 2];
10028
10083
  return [4 /*yield*/, manager.RenderItem({
@@ -12383,71 +12438,43 @@
12383
12438
  })(exports.ViewRenderEngine || (exports.ViewRenderEngine = {}));
12384
12439
 
12385
12440
  var DEFAULT_SMOOTH_MULTIPLIER = 0;
12386
- function avgDistanceFromPointPair(refPoint, pos1, pos2) {
12387
- var carto1 = Cesium.Cartographic.fromCartesian(refPoint);
12388
- var carto2 = Cesium.Cartographic.fromCartesian(pos1);
12389
- var carto3 = Cesium.Cartographic.fromCartesian(pos2);
12390
- var x1 = carto1.longitude;
12391
- var y1 = carto1.latitude;
12392
- var x2 = carto2.longitude;
12393
- var y2 = carto2.latitude;
12394
- var x3 = carto3.longitude;
12395
- var y3 = carto3.latitude;
12396
- var A = x1 - x2;
12397
- var B = y1 - y2;
12398
- var C = x3 - x2;
12399
- var D = y3 - y2;
12400
- var dot = A * C + B * D;
12401
- var lenSq = C * C + D * D;
12402
- var param = dot / lenSq;
12403
- var xx;
12404
- var yy;
12405
- if (param < 0 || x2 == x3 && y2 == y3) {
12406
- xx = x2;
12407
- yy = y2;
12408
- }
12409
- else if (param > 1) {
12410
- xx = x3;
12411
- yy = y3;
12441
+ function distanceToSegment$1(p, v, w) {
12442
+ var l2 = Cesium.Cartesian3.distanceSquared(v, w);
12443
+ if (l2 === 0) {
12444
+ return Cesium.Cartesian3.distance(p, v);
12412
12445
  }
12413
- else {
12414
- xx = x2 + param * C;
12415
- yy = y2 + param * D;
12446
+ var t = Cesium.Cartesian3.dot(Cesium.Cartesian3.subtract(p, v, new Cesium.Cartesian3()), Cesium.Cartesian3.subtract(w, v, new Cesium.Cartesian3())) / l2;
12447
+ if (t < 0) {
12448
+ return Cesium.Cartesian3.distance(p, v);
12449
+ }
12450
+ if (t > 1) {
12451
+ return Cesium.Cartesian3.distance(p, w);
12416
12452
  }
12417
- var dx = x1 - xx;
12418
- var dy = y1 - yy;
12419
- return Math.sqrt(dx * dx + dy * dy);
12453
+ var projection = Cesium.Cartesian3.add(v, Cesium.Cartesian3.multiplyByScalar(Cesium.Cartesian3.subtract(w, v, new Cesium.Cartesian3()), t, new Cesium.Cartesian3()), new Cesium.Cartesian3());
12454
+ return Cesium.Cartesian3.distance(p, projection);
12420
12455
  }
12456
+ /**
12457
+ * Returns splice index into a list of positions to insert a new position.
12458
+ * @param positions List of positions to insert into.
12459
+ * @param pos3d New position to insert.
12460
+ * @returns Index to insert at.
12461
+ */
12421
12462
  function getInsertIndex(positions, pos3d) {
12422
12463
  if (positions.length < 2) {
12423
12464
  return 0;
12424
12465
  }
12466
+ var minDistance = Infinity;
12425
12467
  var index = -1;
12426
- if (positions) {
12427
- var distance = void 0;
12428
- for (var j = 0; j < positions.length; j++) {
12429
- var pos1 = positions[j];
12430
- var pos2 = void 0;
12431
- var pos2Index = -1;
12432
- if (j >= positions.length - 1) {
12433
- pos2 = positions[0];
12434
- pos2Index = 0;
12435
- }
12436
- else {
12437
- pos2 = positions[j + 1];
12438
- pos2Index = j + 1;
12439
- }
12440
- if (bruceModels.Cartes.ValidateCartes3(pos1), bruceModels.Cartes.ValidateCartes3(pos2)) {
12441
- var length_1 = avgDistanceFromPointPair(pos3d, pos1, pos2);
12442
- if (index == -1 || length_1 < distance) {
12443
- var insertIndex = pos2Index == 0 ? 0 : j > pos2Index ? j : pos2Index;
12444
- index = insertIndex;
12445
- distance = length_1;
12446
- }
12447
- }
12468
+ for (var i = 0; i < positions.length; i++) {
12469
+ var pos1 = positions[i];
12470
+ var pos2 = i < positions.length - 1 ? positions[i + 1] : positions[0];
12471
+ var dist = distanceToSegment$1(pos3d, pos1, pos2);
12472
+ if (dist < minDistance) {
12473
+ minDistance = dist;
12474
+ index = i + 1;
12448
12475
  }
12449
12476
  }
12450
- return index == -1 ? 0 : index;
12477
+ return index;
12451
12478
  }
12452
12479
  var OUTLINE_COLOR = "rgba(51, 177, 255, 0.2)";
12453
12480
  var FILL_COLOR = "#33B1FF";
@@ -12850,71 +12877,61 @@
12850
12877
  }());
12851
12878
 
12852
12879
  var DEFAULT_SMOOTH_MULTIPLIER$1 = 0;
12853
- function avgDistanceFromPointPair$1(refPoint, pos1, pos2) {
12854
- var carto1 = Cesium.Cartographic.fromCartesian(refPoint);
12855
- var carto2 = Cesium.Cartographic.fromCartesian(pos1);
12856
- var carto3 = Cesium.Cartographic.fromCartesian(pos2);
12857
- var x1 = carto1.longitude;
12858
- var y1 = carto1.latitude;
12859
- var x2 = carto2.longitude;
12860
- var y2 = carto2.latitude;
12861
- var x3 = carto3.longitude;
12862
- var y3 = carto3.latitude;
12863
- var A = x1 - x2;
12864
- var B = y1 - y2;
12865
- var C = x3 - x2;
12866
- var D = y3 - y2;
12867
- var dot = A * C + B * D;
12868
- var lenSq = C * C + D * D;
12869
- var param = dot / lenSq;
12870
- var xx;
12871
- var yy;
12872
- if (param < 0 || x2 == x3 && y2 == y3) {
12873
- xx = x2;
12874
- yy = y2;
12875
- }
12876
- else if (param > 1) {
12877
- xx = x3;
12878
- yy = y3;
12880
+ function distanceToSegment$2(p, v, w) {
12881
+ var l2 = Cesium.Cartesian3.distanceSquared(v, w);
12882
+ if (l2 === 0) {
12883
+ return Cesium.Cartesian3.distance(p, v);
12879
12884
  }
12880
- else {
12881
- xx = x2 + param * C;
12882
- yy = y2 + param * D;
12885
+ var t = Cesium.Cartesian3.dot(Cesium.Cartesian3.subtract(p, v, new Cesium.Cartesian3()), Cesium.Cartesian3.subtract(w, v, new Cesium.Cartesian3())) / l2;
12886
+ if (t < 0) {
12887
+ return Cesium.Cartesian3.distance(p, v);
12883
12888
  }
12884
- var dx = x1 - xx;
12885
- var dy = y1 - yy;
12886
- return Math.sqrt(dx * dx + dy * dy);
12889
+ if (t > 1) {
12890
+ return Cesium.Cartesian3.distance(p, w);
12891
+ }
12892
+ var projection = Cesium.Cartesian3.add(v, Cesium.Cartesian3.multiplyByScalar(Cesium.Cartesian3.subtract(w, v, new Cesium.Cartesian3()), t, new Cesium.Cartesian3()), new Cesium.Cartesian3());
12893
+ return Cesium.Cartesian3.distance(p, projection);
12887
12894
  }
12895
+ /**
12896
+ * Returns splice index into a list of positions to insert a new position.
12897
+ * @param positions List of positions to insert into.
12898
+ * @param pos3d New position to insert.
12899
+ * @returns Index to insert at.
12900
+ */
12888
12901
  function getInsertIndex$1(positions, pos3d) {
12889
12902
  if (positions.length < 2) {
12890
12903
  return 0;
12891
12904
  }
12892
- var index = 0;
12893
- if (positions) {
12894
- var marginalShift = function (pos) {
12895
- var SHIFT = 0.001;
12896
- pos = pos.clone();
12897
- return new Cesium.Cartesian3(pos.x + SHIFT, pos.y + SHIFT, pos.z + SHIFT);
12898
- };
12899
- var distance = avgDistanceFromPointPair$1(pos3d, positions[0], marginalShift(positions[0]));
12900
- var endDistance = avgDistanceFromPointPair$1(pos3d, positions[positions.length - 1], marginalShift(positions[positions.length - 1]));
12901
- if (endDistance < distance) {
12902
- index = positions.length;
12903
- distance = endDistance;
12904
- }
12905
- for (var j = 0; j < positions.length; j++) {
12906
- var pos1 = positions[j];
12907
- var pos2 = positions[j + 1];
12908
- var pos2Index = j + 1;
12909
- if (bruceModels.Cartes.ValidateCartes3(pos1), bruceModels.Cartes.ValidateCartes3(pos2)) {
12910
- var length_1 = avgDistanceFromPointPair$1(pos3d, pos1, pos2);
12911
- if (length_1 < distance) {
12912
- var insertIndex = pos2Index == 0 ? 0 : j > pos2Index ? j : pos2Index;
12913
- index = insertIndex;
12914
- distance = length_1;
12915
- }
12916
- }
12917
- }
12905
+ var minDistance = Infinity;
12906
+ var index = -1;
12907
+ // Check against segments
12908
+ for (var i = 0; i < positions.length - 1; i++) {
12909
+ var pos1 = positions[i];
12910
+ var pos2 = positions[i + 1];
12911
+ var dist = distanceToSegment$2(pos3d, pos1, pos2);
12912
+ if (dist < minDistance) {
12913
+ minDistance = dist;
12914
+ index = i + 1;
12915
+ }
12916
+ }
12917
+ // Check against start point
12918
+ var startDist = Cesium.Cartesian3.distance(pos3d, positions[0]);
12919
+ if (startDist <= minDistance) {
12920
+ index = 0;
12921
+ minDistance = startDist;
12922
+ console.log("Insert at start");
12923
+ }
12924
+ else {
12925
+ console.log("Start distance was longer than cur distance. ".concat(startDist, " > ").concat(minDistance));
12926
+ }
12927
+ // Check against end point
12928
+ var endDist = Cesium.Cartesian3.distance(pos3d, positions[positions.length - 1]);
12929
+ if (endDist <= minDistance) {
12930
+ index = positions.length;
12931
+ console.log("Insert at end");
12932
+ }
12933
+ else {
12934
+ console.log("End distance was longer than cur distance. ".concat(endDist, " > ").concat(minDistance));
12918
12935
  }
12919
12936
  return index;
12920
12937
  }
@@ -15218,7 +15235,7 @@
15218
15235
  ViewerUtils.CreateWidgets = CreateWidgets;
15219
15236
  })(exports.ViewerUtils || (exports.ViewerUtils = {}));
15220
15237
 
15221
- var VERSION$1 = "2.7.4";
15238
+ var VERSION$1 = "2.7.6";
15222
15239
 
15223
15240
  exports.VERSION = VERSION$1;
15224
15241
  exports.CesiumViewMonitor = CesiumViewMonitor;