bruce-cesium 1.0.8 → 1.1.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.
@@ -1,5 +1,5 @@
1
1
  import { BruceEvent, Cartes, Carto, Geometry, ZoomControl, Style, EntityTag, Calculator, EntityLod, EntityType, ClientFile, DelayQueue, Entity as Entity$1, BatchedDataGetter, EntityRelationType, ObjectUtils, Tileset, EntityCoords, EntityFilterGetter, EntitySource, EntityRelation, MenuItem, ProjectView, ProjectViewBookmark, ProjectViewTile, ProjectViewLegacyTile, ProgramKey, Camera } from 'bruce-models';
2
- import { Cartesian2, Cartographic, Math as Math$1, Color, HeightReference, Cartesian3, Entity, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, PolygonHierarchy, ShadowMode, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Primitive, Cesium3DTileFeature, Cesium3DTileColorBlendMode, HeadingPitchRange, OrthographicFrustum, JulianDate, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, Matrix4, Cesium3DTileStyle, Cesium3DTileset, IonResource, EllipsoidGeodesic, sampleTerrainMostDetailed, PolygonPipeline, CallbackProperty, ColorMaterialProperty, Rectangle, Matrix3, EasingFunction, GeometryInstance, createOsmBuildings, KmlDataSource } from 'cesium';
2
+ import { Cartesian2, Cartographic, Math as Math$1, Entity, Primitive, Cesium3DTileFeature, Color, Cartesian3, OrthographicFrustum, JulianDate, Cesium3DTileColorBlendMode, HeadingPitchRange, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, HeightReference, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, PolygonHierarchy, ShadowMode, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Matrix4, Cesium3DTileStyle, Cesium3DTileset, IonResource, EllipsoidGeodesic, sampleTerrainMostDetailed, PolygonPipeline, CallbackProperty, ColorMaterialProperty, Rectangle, Matrix3, EasingFunction, GeometryInstance, createOsmBuildings, KmlDataSource } from 'cesium';
3
3
 
4
4
  var TIME_LAG = 300;
5
5
  var POSITION_CHECK_TIMER = 950;
@@ -2353,6 +2353,9 @@ var CesiumParabola = /** @class */ (function () {
2353
2353
  this.width = 2;
2354
2354
  this.duration = 10;
2355
2355
  this.heightDistanceRatio = 0.25;
2356
+ this.curPoints = [];
2357
+ this.animateInterval = null;
2358
+ this.retryTimeout = null;
2356
2359
  this.viewer = params.viewer;
2357
2360
  this.pos1 = params.pos1;
2358
2361
  this.pos2 = params.pos2;
@@ -2368,6 +2371,7 @@ var CesiumParabola = /** @class */ (function () {
2368
2371
  if (!isNaN(params.heightDistanceRatio)) {
2369
2372
  this.heightDistanceRatio = params.heightDistanceRatio;
2370
2373
  }
2374
+ this.prepareEntities();
2371
2375
  }
2372
2376
  Object.defineProperty(CesiumParabola.prototype, "curPos1", {
2373
2377
  get: function () {
@@ -2383,47 +2387,20 @@ var CesiumParabola = /** @class */ (function () {
2383
2387
  enumerable: false,
2384
2388
  configurable: true
2385
2389
  });
2386
- CesiumParabola.prototype.Animate = function () {
2390
+ CesiumParabola.prototype.prepareEntities = function () {
2387
2391
  var _this = this;
2388
- this.Dispose();
2389
- var retry = false;
2390
- if (!this.curPos1 || !this.curPos2 || !Cartes.ValidateCartes3(this.curPos1) || !Cartes.ValidateCartes3(this.curPos2)) {
2391
- retry = true;
2392
- }
2393
- var TOTAL_LENGTH = retry ? 0 : Cartesian3.distance(this.curPos1, this.curPos2);
2394
- if (TOTAL_LENGTH <= 0) {
2395
- retry = true;
2396
- }
2397
- if (retry) {
2398
- var retryTimeout_1 = setTimeout(function () {
2399
- _this.Animate();
2400
- }, 2000);
2401
- this.dispose = function () {
2402
- clearTimeout(retryTimeout_1);
2403
- };
2404
- return;
2405
- }
2406
- var RATE_PER_SECOND = 1000 / 40;
2407
- var SEC_DURATION = this.duration;
2408
- var HEIGHT_DISTANCE_RATIO = this.heightDistanceRatio;
2409
- var TOTAL_POINTS = Math.max(50, Math.min(1000, TOTAL_LENGTH * 0.1));
2410
- var POINT_LENGTH = TOTAL_LENGTH / TOTAL_POINTS;
2411
- var TICK_LENGTH_INC = SEC_DURATION == 0 ? TOTAL_LENGTH : TOTAL_POINTS / (RATE_PER_SECOND * SEC_DURATION);
2412
- var curPoints = [];
2413
- var curPoint = 0;
2414
2392
  var parabola = new Entity({
2415
2393
  polyline: {
2416
2394
  positions: new CallbackProperty(function () {
2417
- return curPoints;
2395
+ return _this.curPoints;
2418
2396
  }, false),
2419
2397
  width: this.width,
2420
2398
  material: Color.fromCssColorString(this.color)
2421
2399
  }
2422
2400
  });
2423
- this.viewer.entities.add(parabola);
2424
2401
  var p1Entity = new Entity({
2425
2402
  position: new CallbackProperty(function () {
2426
- return curPoints.length ? curPoints[0] : new Cartesian3();
2403
+ return _this.curPoints.length ? _this.curPoints[0] : new Cartesian3();
2427
2404
  }, false),
2428
2405
  point: {
2429
2406
  heightReference: HeightReference.NONE,
@@ -2435,7 +2412,7 @@ var CesiumParabola = /** @class */ (function () {
2435
2412
  });
2436
2413
  var p2Entity = new Entity({
2437
2414
  position: new CallbackProperty(function () {
2438
- return curPoints.length ? curPoints[curPoints.length - 1] : new Cartesian3();
2415
+ return _this.curPoints.length ? _this.curPoints[_this.curPoints.length - 1] : new Cartesian3();
2439
2416
  }, false),
2440
2417
  point: {
2441
2418
  heightReference: HeightReference.NONE,
@@ -2445,11 +2422,49 @@ var CesiumParabola = /** @class */ (function () {
2445
2422
  outlineWidth: 2
2446
2423
  }
2447
2424
  });
2448
- this.viewer.entities.add(p1Entity);
2449
- this.viewer.entities.add(p2Entity);
2450
2425
  p1Entity.parent = parabola;
2451
2426
  p2Entity.parent = parabola;
2452
2427
  var siblings = [p1Entity, p2Entity];
2428
+ this.parabola = parabola;
2429
+ this.siblings = siblings;
2430
+ };
2431
+ CesiumParabola.prototype.Animate = function () {
2432
+ var _this = this;
2433
+ if (this.parabola && !this.viewer.entities.contains(this.parabola)) {
2434
+ this.viewer.entities.add(this.parabola);
2435
+ }
2436
+ var retry = false;
2437
+ if (!this.curPos1 || !this.curPos2 || !Cartes.ValidateCartes3(this.curPos1) || !Cartes.ValidateCartes3(this.curPos2)) {
2438
+ retry = true;
2439
+ }
2440
+ var TOTAL_LENGTH = retry ? 0 : Cartesian3.distance(this.curPos1, this.curPos2);
2441
+ if (TOTAL_LENGTH <= 0) {
2442
+ retry = true;
2443
+ }
2444
+ if (retry) {
2445
+ this.retryTimeout = setTimeout(function () {
2446
+ _this.Animate();
2447
+ }, 2000);
2448
+ return {
2449
+ parabola: this.parabola,
2450
+ siblings: this.siblings
2451
+ };
2452
+ }
2453
+ var cEntities = [
2454
+ this.parabola
2455
+ ].concat(this.siblings);
2456
+ cEntities.forEach(function (e) {
2457
+ if (e && !_this.viewer.entities.contains(e)) {
2458
+ _this.viewer.entities.add(e);
2459
+ }
2460
+ });
2461
+ var RATE_PER_SECOND = 1000 / 40;
2462
+ var SEC_DURATION = this.duration;
2463
+ var HEIGHT_DISTANCE_RATIO = this.heightDistanceRatio;
2464
+ var TOTAL_POINTS = Math.max(50, Math.min(1000, TOTAL_LENGTH * 0.1));
2465
+ var POINT_LENGTH = TOTAL_LENGTH / TOTAL_POINTS;
2466
+ var TICK_LENGTH_INC = SEC_DURATION == 0 ? TOTAL_LENGTH : TOTAL_POINTS / (RATE_PER_SECOND * SEC_DURATION);
2467
+ var curPoint = 0;
2453
2468
  var quadraticKey = null;
2454
2469
  var quadratic = null;
2455
2470
  var quadraticPreparing = false;
@@ -2608,7 +2623,7 @@ var CesiumParabola = /** @class */ (function () {
2608
2623
  if (posses.find(function (x) { return !x || !Cartes.ValidateCartes3(x); })) {
2609
2624
  return;
2610
2625
  }
2611
- curPoints = posses;
2626
+ _this.curPoints = posses;
2612
2627
  };
2613
2628
  var doTick = function () {
2614
2629
  var p1 = _this.curPos1;
@@ -2628,28 +2643,24 @@ var CesiumParabola = /** @class */ (function () {
2628
2643
  updatePoints();
2629
2644
  }
2630
2645
  };
2631
- var animateInterval = setInterval(doTick, RATE_PER_SECOND);
2632
- this.dispose = function () {
2633
- clearInterval(animateInterval);
2634
- if (parabola && _this.viewer.entities.contains(parabola)) {
2635
- _this.viewer.entities.remove(parabola);
2636
- }
2637
- if (p1Entity && _this.viewer.entities.contains(p1Entity)) {
2638
- _this.viewer.entities.remove(p1Entity);
2639
- }
2640
- if (p2Entity && _this.viewer.entities.contains(p2Entity)) {
2641
- _this.viewer.entities.remove(p2Entity);
2642
- }
2643
- };
2646
+ this.animateInterval = setInterval(doTick, RATE_PER_SECOND);
2644
2647
  return {
2645
- parabola: parabola,
2646
- siblings: siblings
2648
+ parabola: this.parabola,
2649
+ siblings: this.siblings
2647
2650
  };
2648
2651
  };
2649
2652
  CesiumParabola.prototype.Dispose = function () {
2650
- var _a;
2651
- (_a = this.dispose) === null || _a === void 0 ? void 0 : _a.call(this);
2652
- this.dispose = null;
2653
+ var _this = this;
2654
+ clearTimeout(this.retryTimeout);
2655
+ clearInterval(this.animateInterval);
2656
+ var cEntities = [
2657
+ this.parabola
2658
+ ].concat(this.siblings);
2659
+ cEntities.forEach(function (e) {
2660
+ if (e && _this.viewer.entities.contains(e)) {
2661
+ _this.viewer.entities.remove(e);
2662
+ }
2663
+ });
2653
2664
  };
2654
2665
  return CesiumParabola;
2655
2666
  }());