bruce-cesium 2.7.3 → 2.7.5

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
  }
@@ -3063,6 +3074,7 @@
3063
3074
  */
3064
3075
  var CesiumParabola = /** @class */ (function () {
3065
3076
  function CesiumParabola(params) {
3077
+ this.disposed = false;
3066
3078
  this.color = "white";
3067
3079
  this.width = 2;
3068
3080
  this.duration = 10;
@@ -3144,6 +3156,9 @@
3144
3156
  };
3145
3157
  CesiumParabola.prototype.Animate = function () {
3146
3158
  var _this = this;
3159
+ if (this.disposed) {
3160
+ return null;
3161
+ }
3147
3162
  if (this.parabola && !this.viewer.entities.contains(this.parabola)) {
3148
3163
  this.viewer.entities.add(this.parabola);
3149
3164
  }
@@ -3175,9 +3190,34 @@
3175
3190
  var RATE_PER_SECOND = 1000 / 40;
3176
3191
  var SEC_DURATION = this.duration;
3177
3192
  var HEIGHT_DISTANCE_RATIO = this.heightDistanceRatio;
3178
- var TOTAL_POINTS = Math.max(50, Math.min(1000, TOTAL_LENGTH * 0.1));
3179
- var POINT_LENGTH = TOTAL_LENGTH / TOTAL_POINTS;
3180
- var TICK_LENGTH_INC = SEC_DURATION == 0 ? TOTAL_LENGTH : TOTAL_POINTS / (RATE_PER_SECOND * SEC_DURATION);
3193
+ var TOTAL_POINTS = null;
3194
+ var POINT_LENGTH = null;
3195
+ var TICK_LENGTH_INC = null;
3196
+ // Updates TOTAL_POINTS, POINT_LENGTH, and TICK_LENGTH_INC based on current TOTAL_LENGTH and camera position.
3197
+ // We want less points the further away the camera is.
3198
+ var updateParams = function () {
3199
+ var _a, _b;
3200
+ // TODO: Do distance to parabola line instead.
3201
+ var MIN_POINTS = 30;
3202
+ var totalPoints = 80;
3203
+ var cameraHeight = (_b = (_a = _this.viewer.camera) === null || _a === void 0 ? void 0 : _a.positionCartographic) === null || _b === void 0 ? void 0 : _b.height;
3204
+ if (isNaN(cameraHeight) || cameraHeight >= 100000) {
3205
+ totalPoints = MIN_POINTS;
3206
+ }
3207
+ else if (cameraHeight >= 10000) {
3208
+ totalPoints = 50;
3209
+ }
3210
+ else if (cameraHeight >= 1000) {
3211
+ totalPoints = 80;
3212
+ }
3213
+ else if (cameraHeight >= 100) {
3214
+ totalPoints = 100;
3215
+ }
3216
+ TOTAL_POINTS = Math.max(MIN_POINTS, Math.min(totalPoints, TOTAL_LENGTH * 0.1));
3217
+ POINT_LENGTH = TOTAL_LENGTH / TOTAL_POINTS;
3218
+ TICK_LENGTH_INC = SEC_DURATION == 0 ? TOTAL_LENGTH : TOTAL_POINTS / (RATE_PER_SECOND * SEC_DURATION);
3219
+ };
3220
+ updateParams();
3181
3221
  var curPoint = 0;
3182
3222
  var quadraticKey = null;
3183
3223
  var quadratic = null;
@@ -3333,30 +3373,45 @@
3333
3373
  for (var i = 0; i < totalCycles; i++) {
3334
3374
  posses.push(getPosition(i));
3335
3375
  }
3336
- posses.push(getPosition(increment + chips));
3376
+ if (chips) {
3377
+ posses.push(getPosition(increment + chips));
3378
+ }
3337
3379
  if (posses.find(function (x) { return !x || !bruceModels.Cartes.ValidateCartes3(x); })) {
3338
3380
  return;
3339
3381
  }
3340
3382
  _this.curPoints = posses;
3341
3383
  };
3384
+ var lastTickDate = new Date();
3385
+ var finished = false;
3342
3386
  var doTick = function () {
3343
- var p1 = _this.curPos1;
3344
- var p2 = _this.curPos2;
3345
- var newLength = p1 && p2 ? Cesium.Cartesian3.distance(p1, p2) : -1;
3346
- if (newLength > 0 && newLength != TOTAL_LENGTH) {
3347
- TOTAL_LENGTH = newLength;
3348
- TOTAL_POINTS = Math.max(50, Math.min(1000, TOTAL_LENGTH * 0.1));
3349
- POINT_LENGTH = TOTAL_LENGTH / TOTAL_POINTS;
3350
- TICK_LENGTH_INC = SEC_DURATION == 0 ? TOTAL_LENGTH : TOTAL_POINTS / (RATE_PER_SECOND * SEC_DURATION);
3351
- }
3352
- prepareQuadratic();
3353
- if (quadratic) {
3354
- if (curPoint < TOTAL_POINTS) {
3355
- curPoint += TICK_LENGTH_INC;
3387
+ var curDate = new Date();
3388
+ var seconds = (curDate.getTime() - lastTickDate.getTime()) / 1000;
3389
+ var ticks = seconds * RATE_PER_SECOND;
3390
+ if (!isNaN(ticks) && ticks >= 1) {
3391
+ lastTickDate = curDate;
3392
+ var p1 = _this.curPos1;
3393
+ var p2 = _this.curPos2;
3394
+ var newLength = p1 && p2 ? Cesium.Cartesian3.distance(p1, p2) : -1;
3395
+ if (newLength > 0 && newLength != TOTAL_LENGTH) {
3396
+ TOTAL_LENGTH = newLength;
3397
+ updateParams();
3398
+ }
3399
+ prepareQuadratic();
3400
+ if (quadratic) {
3401
+ if (curPoint < TOTAL_POINTS) {
3402
+ curPoint += (TICK_LENGTH_INC * ticks);
3403
+ }
3404
+ updatePoints();
3405
+ }
3406
+ _this.viewer.scene.requestRender();
3407
+ if (curPoint >= TOTAL_POINTS && !finished) {
3408
+ finished = true;
3409
+ // We can make the interval update super slow now.
3410
+ // We keep it updating in case the positions move.
3411
+ clearInterval(_this.animateInterval);
3412
+ _this.animateInterval = setInterval(doTick, 3000);
3356
3413
  }
3357
- updatePoints();
3358
3414
  }
3359
- _this.viewer.scene.requestRender();
3360
3415
  };
3361
3416
  this.animateInterval = setInterval(doTick, RATE_PER_SECOND);
3362
3417
  return {
@@ -3366,6 +3421,7 @@
3366
3421
  };
3367
3422
  CesiumParabola.prototype.Dispose = function () {
3368
3423
  var _this = this;
3424
+ this.disposed = true;
3369
3425
  clearTimeout(this.retryTimeout);
3370
3426
  clearInterval(this.animateInterval);
3371
3427
  var cEntities = [
@@ -5461,16 +5517,14 @@
5461
5517
  viewer: this.viewer,
5462
5518
  // Unfortunately this searches as an "AND" rather than "OR" which does not meet our needs here.
5463
5519
  // So for multiple tags we'll manually sort on UI end...
5464
- tagIds: tagsToRender.length == 1 ? tagsToRender : [],
5520
+ tagIds: (tagsToRender === null || tagsToRender === void 0 ? void 0 : tagsToRender.length) ? tagsToRender : [],
5465
5521
  debugShowBounds: Boolean(window === null || window === void 0 ? void 0 : window.ENTITIES_RENDER_MANAGER_SHOW_BOUNDS),
5466
5522
  cdn: this.item.cdnEnabled
5467
5523
  });
5468
5524
  var minMax = exports.RenderManager.GetZoomMinMax({
5469
5525
  zoomControl: this.item.CameraZoomSettings
5470
5526
  });
5471
- // Unfortunately this searches as an "AND" rather than "OR" which does not meet our needs here.
5472
- // So for multiple tags we'll manually sort on UI end...
5473
- 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]);
5474
5528
  this.getterSub = this.getter.OnUpdate.Subscribe(function (entities) {
5475
5529
  if (isTagItem) {
5476
5530
  _this.distributeForRender(entities.filter(function (entity) {
@@ -9074,6 +9128,12 @@
9074
9128
  })];
9075
9129
  case 1:
9076
9130
  cEntities = _c.sent();
9131
+ if (this.disposed) {
9132
+ this.register.RemoveRegos({
9133
+ menuItemId: this.item.id
9134
+ });
9135
+ return [2 /*return*/];
9136
+ }
9077
9137
  for (i = 0; i < relations.length; i++) {
9078
9138
  relation = relations[i];
9079
9139
  key = RelationRenderEngine.GetRenderGroupId(relation);
@@ -12332,71 +12392,43 @@
12332
12392
  })(exports.ViewRenderEngine || (exports.ViewRenderEngine = {}));
12333
12393
 
12334
12394
  var DEFAULT_SMOOTH_MULTIPLIER = 0;
12335
- function avgDistanceFromPointPair(refPoint, pos1, pos2) {
12336
- var carto1 = Cesium.Cartographic.fromCartesian(refPoint);
12337
- var carto2 = Cesium.Cartographic.fromCartesian(pos1);
12338
- var carto3 = Cesium.Cartographic.fromCartesian(pos2);
12339
- var x1 = carto1.longitude;
12340
- var y1 = carto1.latitude;
12341
- var x2 = carto2.longitude;
12342
- var y2 = carto2.latitude;
12343
- var x3 = carto3.longitude;
12344
- var y3 = carto3.latitude;
12345
- var A = x1 - x2;
12346
- var B = y1 - y2;
12347
- var C = x3 - x2;
12348
- var D = y3 - y2;
12349
- var dot = A * C + B * D;
12350
- var lenSq = C * C + D * D;
12351
- var param = dot / lenSq;
12352
- var xx;
12353
- var yy;
12354
- if (param < 0 || x2 == x3 && y2 == y3) {
12355
- xx = x2;
12356
- yy = y2;
12357
- }
12358
- else if (param > 1) {
12359
- xx = x3;
12360
- yy = y3;
12395
+ function distanceToSegment$1(p, v, w) {
12396
+ var l2 = Cesium.Cartesian3.distanceSquared(v, w);
12397
+ if (l2 === 0) {
12398
+ return Cesium.Cartesian3.distance(p, v);
12361
12399
  }
12362
- else {
12363
- xx = x2 + param * C;
12364
- yy = y2 + param * D;
12400
+ var t = Cesium.Cartesian3.dot(Cesium.Cartesian3.subtract(p, v, new Cesium.Cartesian3()), Cesium.Cartesian3.subtract(w, v, new Cesium.Cartesian3())) / l2;
12401
+ if (t < 0) {
12402
+ return Cesium.Cartesian3.distance(p, v);
12403
+ }
12404
+ if (t > 1) {
12405
+ return Cesium.Cartesian3.distance(p, w);
12365
12406
  }
12366
- var dx = x1 - xx;
12367
- var dy = y1 - yy;
12368
- return Math.sqrt(dx * dx + dy * dy);
12407
+ var projection = Cesium.Cartesian3.add(v, Cesium.Cartesian3.multiplyByScalar(Cesium.Cartesian3.subtract(w, v, new Cesium.Cartesian3()), t, new Cesium.Cartesian3()), new Cesium.Cartesian3());
12408
+ return Cesium.Cartesian3.distance(p, projection);
12369
12409
  }
12410
+ /**
12411
+ * Returns splice index into a list of positions to insert a new position.
12412
+ * @param positions List of positions to insert into.
12413
+ * @param pos3d New position to insert.
12414
+ * @returns Index to insert at.
12415
+ */
12370
12416
  function getInsertIndex(positions, pos3d) {
12371
12417
  if (positions.length < 2) {
12372
12418
  return 0;
12373
12419
  }
12420
+ var minDistance = Infinity;
12374
12421
  var index = -1;
12375
- if (positions) {
12376
- var distance = void 0;
12377
- for (var j = 0; j < positions.length; j++) {
12378
- var pos1 = positions[j];
12379
- var pos2 = void 0;
12380
- var pos2Index = -1;
12381
- if (j >= positions.length - 1) {
12382
- pos2 = positions[0];
12383
- pos2Index = 0;
12384
- }
12385
- else {
12386
- pos2 = positions[j + 1];
12387
- pos2Index = j + 1;
12388
- }
12389
- if (bruceModels.Cartes.ValidateCartes3(pos1), bruceModels.Cartes.ValidateCartes3(pos2)) {
12390
- var length_1 = avgDistanceFromPointPair(pos3d, pos1, pos2);
12391
- if (index == -1 || length_1 < distance) {
12392
- var insertIndex = pos2Index == 0 ? 0 : j > pos2Index ? j : pos2Index;
12393
- index = insertIndex;
12394
- distance = length_1;
12395
- }
12396
- }
12422
+ for (var i = 0; i < positions.length; i++) {
12423
+ var pos1 = positions[i];
12424
+ var pos2 = i < positions.length - 1 ? positions[i + 1] : positions[0];
12425
+ var dist = distanceToSegment$1(pos3d, pos1, pos2);
12426
+ if (dist < minDistance) {
12427
+ minDistance = dist;
12428
+ index = i + 1;
12397
12429
  }
12398
12430
  }
12399
- return index == -1 ? 0 : index;
12431
+ return index;
12400
12432
  }
12401
12433
  var OUTLINE_COLOR = "rgba(51, 177, 255, 0.2)";
12402
12434
  var FILL_COLOR = "#33B1FF";
@@ -12799,71 +12831,61 @@
12799
12831
  }());
12800
12832
 
12801
12833
  var DEFAULT_SMOOTH_MULTIPLIER$1 = 0;
12802
- function avgDistanceFromPointPair$1(refPoint, pos1, pos2) {
12803
- var carto1 = Cesium.Cartographic.fromCartesian(refPoint);
12804
- var carto2 = Cesium.Cartographic.fromCartesian(pos1);
12805
- var carto3 = Cesium.Cartographic.fromCartesian(pos2);
12806
- var x1 = carto1.longitude;
12807
- var y1 = carto1.latitude;
12808
- var x2 = carto2.longitude;
12809
- var y2 = carto2.latitude;
12810
- var x3 = carto3.longitude;
12811
- var y3 = carto3.latitude;
12812
- var A = x1 - x2;
12813
- var B = y1 - y2;
12814
- var C = x3 - x2;
12815
- var D = y3 - y2;
12816
- var dot = A * C + B * D;
12817
- var lenSq = C * C + D * D;
12818
- var param = dot / lenSq;
12819
- var xx;
12820
- var yy;
12821
- if (param < 0 || x2 == x3 && y2 == y3) {
12822
- xx = x2;
12823
- yy = y2;
12824
- }
12825
- else if (param > 1) {
12826
- xx = x3;
12827
- yy = y3;
12834
+ function distanceToSegment$2(p, v, w) {
12835
+ var l2 = Cesium.Cartesian3.distanceSquared(v, w);
12836
+ if (l2 === 0) {
12837
+ return Cesium.Cartesian3.distance(p, v);
12828
12838
  }
12829
- else {
12830
- xx = x2 + param * C;
12831
- yy = y2 + param * D;
12839
+ var t = Cesium.Cartesian3.dot(Cesium.Cartesian3.subtract(p, v, new Cesium.Cartesian3()), Cesium.Cartesian3.subtract(w, v, new Cesium.Cartesian3())) / l2;
12840
+ if (t < 0) {
12841
+ return Cesium.Cartesian3.distance(p, v);
12842
+ }
12843
+ if (t > 1) {
12844
+ return Cesium.Cartesian3.distance(p, w);
12832
12845
  }
12833
- var dx = x1 - xx;
12834
- var dy = y1 - yy;
12835
- return Math.sqrt(dx * dx + dy * dy);
12846
+ var projection = Cesium.Cartesian3.add(v, Cesium.Cartesian3.multiplyByScalar(Cesium.Cartesian3.subtract(w, v, new Cesium.Cartesian3()), t, new Cesium.Cartesian3()), new Cesium.Cartesian3());
12847
+ return Cesium.Cartesian3.distance(p, projection);
12836
12848
  }
12849
+ /**
12850
+ * Returns splice index into a list of positions to insert a new position.
12851
+ * @param positions List of positions to insert into.
12852
+ * @param pos3d New position to insert.
12853
+ * @returns Index to insert at.
12854
+ */
12837
12855
  function getInsertIndex$1(positions, pos3d) {
12838
12856
  if (positions.length < 2) {
12839
12857
  return 0;
12840
12858
  }
12841
- var index = 0;
12842
- if (positions) {
12843
- var marginalShift = function (pos) {
12844
- var SHIFT = 0.001;
12845
- pos = pos.clone();
12846
- return new Cesium.Cartesian3(pos.x + SHIFT, pos.y + SHIFT, pos.z + SHIFT);
12847
- };
12848
- var distance = avgDistanceFromPointPair$1(pos3d, positions[0], marginalShift(positions[0]));
12849
- var endDistance = avgDistanceFromPointPair$1(pos3d, positions[positions.length - 1], marginalShift(positions[positions.length - 1]));
12850
- if (endDistance < distance) {
12851
- index = positions.length;
12852
- distance = endDistance;
12853
- }
12854
- for (var j = 0; j < positions.length; j++) {
12855
- var pos1 = positions[j];
12856
- var pos2 = positions[j + 1];
12857
- var pos2Index = j + 1;
12858
- if (bruceModels.Cartes.ValidateCartes3(pos1), bruceModels.Cartes.ValidateCartes3(pos2)) {
12859
- var length_1 = avgDistanceFromPointPair$1(pos3d, pos1, pos2);
12860
- if (length_1 < distance) {
12861
- var insertIndex = pos2Index == 0 ? 0 : j > pos2Index ? j : pos2Index;
12862
- index = insertIndex;
12863
- distance = length_1;
12864
- }
12865
- }
12866
- }
12859
+ var minDistance = Infinity;
12860
+ var index = -1;
12861
+ // Check against segments
12862
+ for (var i = 0; i < positions.length - 1; i++) {
12863
+ var pos1 = positions[i];
12864
+ var pos2 = positions[i + 1];
12865
+ var dist = distanceToSegment$2(pos3d, pos1, pos2);
12866
+ if (dist < minDistance) {
12867
+ minDistance = dist;
12868
+ index = i + 1;
12869
+ }
12870
+ }
12871
+ // Check against start point
12872
+ var startDist = Cesium.Cartesian3.distance(pos3d, positions[0]);
12873
+ if (startDist <= minDistance) {
12874
+ index = 0;
12875
+ minDistance = startDist;
12876
+ console.log("Insert at start");
12877
+ }
12878
+ else {
12879
+ console.log("Start distance was longer than cur distance. ".concat(startDist, " > ").concat(minDistance));
12880
+ }
12881
+ // Check against end point
12882
+ var endDist = Cesium.Cartesian3.distance(pos3d, positions[positions.length - 1]);
12883
+ if (endDist <= minDistance) {
12884
+ index = positions.length;
12885
+ console.log("Insert at end");
12886
+ }
12887
+ else {
12888
+ console.log("End distance was longer than cur distance. ".concat(endDist, " > ").concat(minDistance));
12867
12889
  }
12868
12890
  return index;
12869
12891
  }
@@ -15167,7 +15189,7 @@
15167
15189
  ViewerUtils.CreateWidgets = CreateWidgets;
15168
15190
  })(exports.ViewerUtils || (exports.ViewerUtils = {}));
15169
15191
 
15170
- var VERSION$1 = "2.7.3";
15192
+ var VERSION$1 = "2.7.5";
15171
15193
 
15172
15194
  exports.VERSION = VERSION$1;
15173
15195
  exports.CesiumViewMonitor = CesiumViewMonitor;