bruce-cesium 1.0.3 → 1.0.4

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, ObjectUtils, Tileset, EntityCoords, EntityFilterGetter, EntitySource, MenuItem, ProjectView, ProjectViewBookmark, ProjectViewTile, ProjectViewLegacyTile, ProgramKey, Camera } from 'bruce-models';
2
- import { Cartesian2, Cartographic, Math as Math$1, Entity, Primitive, Cesium3DTileFeature, Color, Cartesian3, HeightReference, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, PolygonHierarchy, ShadowMode, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Cesium3DTileColorBlendMode, HeadingPitchRange, OrthographicFrustum, JulianDate, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, PolygonPipeline, Matrix4, Cesium3DTileStyle, Cesium3DTileset, IonResource, ColorMaterialProperty, Rectangle, Matrix3, EasingFunction, GeometryInstance, EllipsoidGeodesic, createOsmBuildings, KmlDataSource } from 'cesium';
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, ColorMaterialProperty, Rectangle, Matrix3, EasingFunction, GeometryInstance, CallbackProperty, createOsmBuildings, KmlDataSource } from 'cesium';
3
3
 
4
4
  var TIME_LAG = 300;
5
5
  var POSITION_CHECK_TIMER = 950;
@@ -401,6 +401,54 @@ var DrawingUtils;
401
401
  };
402
402
  }
403
403
  DrawingUtils.PointAcrossPolyline = PointAcrossPolyline;
404
+ /**
405
+ * Returns terrain height from current viewer's provider.
406
+ * On error or flat terrain, it will return 0.
407
+ * If an error occurred it will be attached to the result.
408
+ * @param pos3d
409
+ * @param viewer
410
+ * @returns
411
+ */
412
+ function GetTerrainHeight(params) {
413
+ return __awaiter(this, void 0, void 0, function () {
414
+ var pos3d, viewer, sample, height, e_1;
415
+ return __generator(this, function (_a) {
416
+ switch (_a.label) {
417
+ case 0:
418
+ pos3d = params.pos3d, viewer = params.viewer;
419
+ _a.label = 1;
420
+ case 1:
421
+ _a.trys.push([1, 3, , 4]);
422
+ if (viewer.scene.terrainProvider instanceof EllipsoidTerrainProvider) {
423
+ return [2 /*return*/, {
424
+ height: 0
425
+ }];
426
+ }
427
+ return [4 /*yield*/, sampleTerrainMostDetailed(viewer.scene.terrainProvider, [Cartographic.fromCartesian(pos3d)])];
428
+ case 2:
429
+ sample = _a.sent();
430
+ height = (sample === null || sample === void 0 ? void 0 : sample.length) ? sample[0].height : null;
431
+ if (isNaN(height)) {
432
+ return [2 /*return*/, {
433
+ height: 0,
434
+ error: "NaN"
435
+ }];
436
+ }
437
+ return [2 /*return*/, {
438
+ height: height
439
+ }];
440
+ case 3:
441
+ e_1 = _a.sent();
442
+ return [2 /*return*/, {
443
+ height: 0,
444
+ error: e_1
445
+ }];
446
+ case 4: return [2 /*return*/];
447
+ }
448
+ });
449
+ });
450
+ }
451
+ DrawingUtils.GetTerrainHeight = GetTerrainHeight;
404
452
  })(DrawingUtils || (DrawingUtils = {}));
405
453
 
406
454
  var MeasureUtils;
@@ -7094,5 +7142,284 @@ var ViewUtils;
7094
7142
  ViewUtils.GatherTerrainTile = GatherTerrainTile;
7095
7143
  })(ViewUtils || (ViewUtils = {}));
7096
7144
 
7097
- export { CesiumViewMonitor, ViewerUtils, MenuItemManager, EntityRenderEngine, MenuItemCreator, VisualsRegister, RenderManager, EntitiesIdsRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, TilesetCadRenderManager, ViewRenderEngine, TileRenderEngine, TilesetRenderEngine, SharedGetters, ViewUtils, DrawingUtils, MeasureUtils, EntityUtils };
7145
+ /**
7146
+ * Utility for rendering parabolas between two points on the map.
7147
+ */
7148
+ var CesiumParabola = /** @class */ (function () {
7149
+ function CesiumParabola(params) {
7150
+ this.color = "white";
7151
+ this.width = 2;
7152
+ this.duration = 10;
7153
+ this.heightDistanceRatio = 0.25;
7154
+ this.viewer = params.viewer;
7155
+ this.pos1 = params.pos1;
7156
+ this.pos2 = params.pos2;
7157
+ if (params.color) {
7158
+ this.color = params.color;
7159
+ }
7160
+ if (!isNaN(params.width)) {
7161
+ this.width = params.width;
7162
+ }
7163
+ if (!isNaN(params.duration)) {
7164
+ this.duration = params.duration;
7165
+ }
7166
+ if (!isNaN(params.heightDistanceRatio)) {
7167
+ this.heightDistanceRatio = params.heightDistanceRatio;
7168
+ }
7169
+ }
7170
+ Object.defineProperty(CesiumParabola.prototype, "curPos1", {
7171
+ get: function () {
7172
+ return this.pos1 instanceof Function ? this.pos1() : this.pos1;
7173
+ },
7174
+ enumerable: false,
7175
+ configurable: true
7176
+ });
7177
+ Object.defineProperty(CesiumParabola.prototype, "curPos2", {
7178
+ get: function () {
7179
+ return this.pos2 instanceof Function ? this.pos2() : this.pos2;
7180
+ },
7181
+ enumerable: false,
7182
+ configurable: true
7183
+ });
7184
+ CesiumParabola.prototype.Animate = function () {
7185
+ var _this = this;
7186
+ this.Dispose();
7187
+ var p1 = this.curPos1;
7188
+ var p2 = this.curPos2;
7189
+ var retry = false;
7190
+ if (!p1 || !p2 || !Cartes.ValidateCartes3(p1) || !Cartes.ValidateCartes3(p2)) {
7191
+ retry = true;
7192
+ }
7193
+ var TOTAL_LENGTH = retry ? 0 : Cartesian3.distance(p1, p2);
7194
+ if (TOTAL_LENGTH <= 0) {
7195
+ retry = true;
7196
+ }
7197
+ if (retry) {
7198
+ var retryTimeout_1 = setTimeout(function () {
7199
+ _this.Animate();
7200
+ }, 2000);
7201
+ this.dispose = function () {
7202
+ clearTimeout(retryTimeout_1);
7203
+ };
7204
+ return;
7205
+ }
7206
+ var TOTAL_POINTS = Math.max(50, Math.min(1000, TOTAL_LENGTH * 0.1));
7207
+ var POINT_LENGTH = TOTAL_LENGTH / TOTAL_POINTS;
7208
+ var RATE_PER_SECOND = 1000 / 40;
7209
+ var SEC_DURATION = this.duration;
7210
+ var HEIGHT_DISTANCE_RATIO = this.heightDistanceRatio;
7211
+ var TICK_LENGTH_INC = TOTAL_POINTS / (RATE_PER_SECOND * SEC_DURATION);
7212
+ var curPoints = [];
7213
+ var curPoint = 0;
7214
+ var parabola = new Entity({
7215
+ polyline: {
7216
+ positions: new CallbackProperty(function () {
7217
+ return curPoints;
7218
+ }, false),
7219
+ width: this.width,
7220
+ material: Color.fromCssColorString(this.color)
7221
+ }
7222
+ });
7223
+ this.viewer.entities.add(parabola);
7224
+ var p1Entity = new Entity({
7225
+ position: new CallbackProperty(function () {
7226
+ return curPoints.length ? curPoints[0] : new Cartesian3();
7227
+ }, false),
7228
+ point: {
7229
+ heightReference: HeightReference.NONE,
7230
+ pixelSize: this.width * 1.3,
7231
+ color: Color.fromCssColorString(this.color),
7232
+ outlineColor: Color.WHITE,
7233
+ outlineWidth: 2
7234
+ }
7235
+ });
7236
+ var p2Entity = new Entity({
7237
+ position: new CallbackProperty(function () {
7238
+ return curPoints.length ? curPoints[curPoints.length - 1] : new Cartesian3();
7239
+ }, false),
7240
+ point: {
7241
+ heightReference: HeightReference.NONE,
7242
+ pixelSize: this.width * 1.3,
7243
+ color: Color.fromCssColorString(this.color),
7244
+ outlineColor: Color.WHITE,
7245
+ outlineWidth: 2
7246
+ }
7247
+ });
7248
+ this.viewer.entities.add(p1Entity);
7249
+ this.viewer.entities.add(p2Entity);
7250
+ p1Entity.parent = parabola;
7251
+ p2Entity.parent = parabola;
7252
+ var quadraticKey = null;
7253
+ var quadratic = null;
7254
+ var prepareQuadratic = function () {
7255
+ var p1 = _this.curPos1;
7256
+ var p2 = _this.curPos2;
7257
+ if (!p1 || !p2 || !Cartes.ValidateCartes3(p1) || !Cartes.ValidateCartes3(p2)) {
7258
+ return;
7259
+ }
7260
+ var height1 = Cartographic.fromCartesian(p1).height;
7261
+ var height2 = Cartographic.fromCartesian(p2).height;
7262
+ if (isNaN(height1) || isNaN(height2)) {
7263
+ return;
7264
+ }
7265
+ var totalHeight = height2 + height1;
7266
+ var curQuadraticKey = height1 + "-" + height2;
7267
+ if (quadraticKey == curQuadraticKey) {
7268
+ return;
7269
+ }
7270
+ var points2d = [
7271
+ new Cartesian2(0, height1),
7272
+ new Cartesian2(TOTAL_LENGTH, height2)
7273
+ ];
7274
+ var vertexHeight = 0;
7275
+ // Flat line.
7276
+ if (HEIGHT_DISTANCE_RATIO == 0) {
7277
+ vertexHeight = totalHeight * 0.5;
7278
+ }
7279
+ else {
7280
+ var largestHeight = Math.max(height1, height2);
7281
+ vertexHeight = largestHeight + (TOTAL_LENGTH * HEIGHT_DISTANCE_RATIO);
7282
+ }
7283
+ points2d.push(new Cartesian2(TOTAL_LENGTH * 0.5, vertexHeight));
7284
+ var calcQuadratic = function (points) {
7285
+ // Swaps position of two rows in matrix.
7286
+ function swapRows(matrix, rowAIndex, rowBIndex) {
7287
+ var rowAVal = matrix[rowAIndex];
7288
+ matrix[rowAIndex] = matrix[rowBIndex];
7289
+ matrix[rowBIndex] = rowAVal;
7290
+ return matrix;
7291
+ }
7292
+ // Zeros rowA at colIndex by subtracting a multiplied rowB from it.
7293
+ function reduceMatrixRowByRow(matrix, zeroingIndex, parentIndex, colIndex) {
7294
+ var zeroRow = matrix[zeroingIndex];
7295
+ var parentRow = matrix[parentIndex];
7296
+ if (zeroRow[colIndex] == 0) {
7297
+ return matrix;
7298
+ }
7299
+ else if (parentRow[colIndex] == 0) {
7300
+ matrix = swapRows(matrix, parentIndex, zeroingIndex);
7301
+ return divideMatrixRow(matrix, parentIndex, colIndex);
7302
+ }
7303
+ // rowAIndex colIndex / rowBIndex colIndex = factor;
7304
+ var factor = zeroRow[colIndex] / parentRow[colIndex];
7305
+ for (var i = 0; i < zeroRow.length; i++) {
7306
+ if (i >= colIndex) {
7307
+ zeroRow[i] -= parentRow[i] * factor;
7308
+ }
7309
+ }
7310
+ return matrix;
7311
+ }
7312
+ // Makes a given row column equal 1 by diving while row by that column.
7313
+ function divideMatrixRow(matrix, rowIndex, colIndex) {
7314
+ var row = matrix[rowIndex];
7315
+ var colValue = row[colIndex];
7316
+ for (var i = 0; i < row.length; i++) {
7317
+ if (i >= colIndex) {
7318
+ row[i] /= colValue;
7319
+ }
7320
+ }
7321
+ return matrix;
7322
+ }
7323
+ // Returns initial matrix for calculating a, b and c for quadratic formula from given points.
7324
+ function matrixFromPoints(points) {
7325
+ var rows = [];
7326
+ var constructRow = function (point) {
7327
+ rows.push([
7328
+ -Math.pow(point.x, 2),
7329
+ point.x,
7330
+ 1,
7331
+ point.y
7332
+ ]);
7333
+ };
7334
+ for (var i = 0; i < points.length; i++) {
7335
+ constructRow(points[i]);
7336
+ }
7337
+ return rows;
7338
+ }
7339
+ var initialMatrix = matrixFromPoints(points);
7340
+ var step1Matrix = reduceMatrixRowByRow(initialMatrix, 1, 0, 0);
7341
+ var step2Matrix = reduceMatrixRowByRow(step1Matrix, 2, 0, 0);
7342
+ var step3Matrix = reduceMatrixRowByRow(step2Matrix, 2, 1, 1);
7343
+ var step4Matrix = reduceMatrixRowByRow(step3Matrix, 0, 1, 1);
7344
+ var step5Matrix = reduceMatrixRowByRow(step4Matrix, 0, 2, 2);
7345
+ var step6Matrix = reduceMatrixRowByRow(step5Matrix, 1, 2, 2);
7346
+ var a = step6Matrix[0][3];
7347
+ var b = step6Matrix[1][3];
7348
+ var c = step6Matrix[2][3];
7349
+ return { a: a, b: b, c: c };
7350
+ };
7351
+ quadratic = calcQuadratic(points2d);
7352
+ };
7353
+ var getPosition = function (increment) {
7354
+ if (!quadratic) {
7355
+ return null;
7356
+ }
7357
+ var lengthAcross = POINT_LENGTH * increment;
7358
+ if (lengthAcross > TOTAL_LENGTH) {
7359
+ lengthAcross = TOTAL_LENGTH;
7360
+ }
7361
+ var getParabolaYFromX = function (x, quadLetters) {
7362
+ var a = quadLetters.a;
7363
+ var b = quadLetters.b;
7364
+ var c = quadLetters.c;
7365
+ return (-a * Math.pow(x, 2)) + (b * x) + c;
7366
+ };
7367
+ var pos3d = DrawingUtils.PointAcrossPolyline({
7368
+ viewer: _this.viewer,
7369
+ distance: lengthAcross,
7370
+ posses: [p1, p2]
7371
+ }).point;
7372
+ var point = Cartographic.fromCartesian(pos3d);
7373
+ var posHeight = getParabolaYFromX(lengthAcross, quadratic);
7374
+ return Cartesian3.fromRadians(point.longitude, point.latitude, posHeight);
7375
+ };
7376
+ var updatePoints = function () {
7377
+ var increment = Math.floor(curPoint);
7378
+ var chips = curPoint - Math.floor(curPoint);
7379
+ var posses = [];
7380
+ posses.push(getPosition(0));
7381
+ var addLast = increment >= TOTAL_POINTS;
7382
+ var totalCycles = addLast ? increment + 1 : increment;
7383
+ for (var i = 0; i < totalCycles; i++) {
7384
+ posses.push(getPosition(i));
7385
+ }
7386
+ posses.push(getPosition(increment + chips));
7387
+ if (posses.find(function (x) { return !x || !Cartes.ValidateCartes3(x); })) {
7388
+ return;
7389
+ }
7390
+ curPoints = posses;
7391
+ };
7392
+ var doTick = function () {
7393
+ if (curPoint >= TOTAL_POINTS) {
7394
+ clearInterval(animateInterval);
7395
+ return;
7396
+ }
7397
+ curPoint += TICK_LENGTH_INC;
7398
+ prepareQuadratic();
7399
+ updatePoints();
7400
+ };
7401
+ var animateInterval = setInterval(doTick, RATE_PER_SECOND);
7402
+ this.dispose = function () {
7403
+ clearInterval(animateInterval);
7404
+ if (parabola && _this.viewer.entities.contains(parabola)) {
7405
+ _this.viewer.entities.remove(parabola);
7406
+ }
7407
+ if (p1Entity && _this.viewer.entities.contains(p1Entity)) {
7408
+ _this.viewer.entities.remove(p1Entity);
7409
+ }
7410
+ if (p2Entity && _this.viewer.entities.contains(p2Entity)) {
7411
+ _this.viewer.entities.remove(p2Entity);
7412
+ }
7413
+ };
7414
+ return parabola;
7415
+ };
7416
+ CesiumParabola.prototype.Dispose = function () {
7417
+ var _a;
7418
+ (_a = this.dispose) === null || _a === void 0 ? void 0 : _a.call(this);
7419
+ this.dispose = null;
7420
+ };
7421
+ return CesiumParabola;
7422
+ }());
7423
+
7424
+ export { CesiumViewMonitor, ViewerUtils, MenuItemManager, EntityRenderEngine, MenuItemCreator, VisualsRegister, RenderManager, EntitiesIdsRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, TilesetCadRenderManager, ViewRenderEngine, TileRenderEngine, TilesetRenderEngine, SharedGetters, ViewUtils, DrawingUtils, MeasureUtils, EntityUtils, CesiumParabola };
7098
7425
  //# sourceMappingURL=bruce-cesium.es5.js.map