bruce-cesium 3.6.0 → 3.6.2

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, ProjectViewTile, DelayQueue, ZoomControl, Style, EntityTag, Calculator, EntityLod, EntityType, ClientFile, ObjectUtils, Bounds, Api, EntityRelationType, ENVIRONMENT, EntityCoords, EntitySource, MenuItem, EntityRelation, ProgramKey, AbstractApi, ProjectViewBookmark, EntityAttachment, EntityAttachmentType, EntityAttribute, ProjectView, ProjectViewLegacyTile, Camera } from 'bruce-models';
2
2
  import * as Cesium from 'cesium';
3
- import { Cartographic, Cartesian2, Math as Math$1, Cartesian3, CallbackProperty, Color, HeightReference, Rectangle, JulianDate, DistanceDisplayCondition, NearFarScalar, Model, Entity, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Primitive, Cesium3DTileFeature, SceneMode, GeoJsonDataSource, ColorMaterialProperty, Cesium3DTileColorBlendMode, HeadingPitchRange, Ion, Cesium3DTileStyle, KmlDataSource, SceneTransforms, OrthographicFrustum, EasingFunction, Cesium3DTileset, Matrix4, Matrix3, IonResource, EllipsoidTerrainProvider, CesiumInspector, defined, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, CesiumTerrainProvider, EllipsoidGeodesic, sampleTerrainMostDetailed, PolygonPipeline, BoundingSphere, GeometryInstance, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, ScreenSpaceEventHandler, ScreenSpaceEventType, Intersect } from 'cesium';
3
+ import { Cartographic, Cartesian2, Math as Math$1, Cartesian3, CallbackProperty, Color, HeightReference, Rectangle, JulianDate, DistanceDisplayCondition, NearFarScalar, Model, Entity, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Primitive, Cesium3DTileFeature, GeoJsonDataSource, ColorMaterialProperty, SceneMode, Cesium3DTileColorBlendMode, HeadingPitchRange, Ion, Cesium3DTileStyle, KmlDataSource, SceneTransforms, OrthographicFrustum, EasingFunction, EllipsoidTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, CesiumTerrainProvider, Cesium3DTileset, Matrix4, Matrix3, IonResource, CesiumInspector, defined, BoundingSphere, GeometryInstance, PolygonPipeline, ScreenSpaceEventHandler, ScreenSpaceEventType, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, EllipsoidGeodesic, sampleTerrainMostDetailed, CzmlDataSource, Quaternion, Intersect } from 'cesium';
4
4
 
5
5
  /*! *****************************************************************************
6
6
  Copyright (c) Microsoft Corporation. All rights reserved.
@@ -13908,6 +13908,13 @@ var DataSourceStaticKmlManager;
13908
13908
  enumerable: false,
13909
13909
  configurable: true
13910
13910
  });
13911
+ Object.defineProperty(Manager.prototype, "DataSources", {
13912
+ get: function () {
13913
+ return this.dataSources;
13914
+ },
13915
+ enumerable: false,
13916
+ configurable: true
13917
+ });
13911
13918
  Manager.prototype.Init = function () {
13912
13919
  var _this = this;
13913
13920
  var files = this.item.KML;
@@ -15246,6 +15253,414 @@ var LegacyRelationsRenderManager;
15246
15253
  LegacyRelationsRenderManager.Manager = Manager;
15247
15254
  })(LegacyRelationsRenderManager || (LegacyRelationsRenderManager = {}));
15248
15255
 
15256
+ /**
15257
+ * Made for a POC experiment.
15258
+ * Do not use without reviewing the purpose and settings of the Menu Item.
15259
+ */
15260
+ var DataSourceStaticCsvManager;
15261
+ (function (DataSourceStaticCsvManager) {
15262
+ var Manager = /** @class */ (function () {
15263
+ function Manager(params) {
15264
+ this.disposed = false;
15265
+ this.czmlDataInputs = [];
15266
+ // Array of callbacks to remove from the clock tick event.
15267
+ this.tickRemovals = [];
15268
+ var viewer = params.viewer, apiGetter = params.apiGetter, item = params.item;
15269
+ this.viewer = viewer;
15270
+ this.apiGetter = apiGetter;
15271
+ this.item = item;
15272
+ }
15273
+ Object.defineProperty(Manager.prototype, "Disposed", {
15274
+ get: function () {
15275
+ return this.disposed;
15276
+ },
15277
+ enumerable: false,
15278
+ configurable: true
15279
+ });
15280
+ Object.defineProperty(Manager.prototype, "DataSources", {
15281
+ get: function () {
15282
+ return this.dataSource ? [this.dataSource] : [];
15283
+ },
15284
+ enumerable: false,
15285
+ configurable: true
15286
+ });
15287
+ Object.defineProperty(Manager.prototype, "CzmlDataInputs", {
15288
+ get: function () {
15289
+ return this.czmlDataInputs;
15290
+ },
15291
+ enumerable: false,
15292
+ configurable: true
15293
+ });
15294
+ Manager.prototype.Init = function () {
15295
+ var _this = this;
15296
+ var files = this.item.CSV;
15297
+ if (!files) {
15298
+ return;
15299
+ }
15300
+ if (!Array.isArray(files)) {
15301
+ files = [files];
15302
+ }
15303
+ (function () { return __awaiter(_this, void 0, void 0, function () {
15304
+ var api, e_1;
15305
+ var _a;
15306
+ return __generator(this, function (_b) {
15307
+ switch (_b.label) {
15308
+ case 0:
15309
+ api = this.apiGetter.getApi();
15310
+ return [4 /*yield*/, api.Loading];
15311
+ case 1:
15312
+ _b.sent();
15313
+ if (this.disposed) {
15314
+ return [2 /*return*/];
15315
+ }
15316
+ _b.label = 2;
15317
+ case 2:
15318
+ _b.trys.push([2, 4, , 5]);
15319
+ return [4 /*yield*/, this.renderMovingItem()];
15320
+ case 3:
15321
+ _b.sent();
15322
+ if (this.disposed) {
15323
+ if (!((_a = this.viewer) === null || _a === void 0 ? void 0 : _a.isDestroyed()) && this.dataSource && this.viewer.dataSources.contains(this.dataSource)) {
15324
+ this.viewer.dataSources.remove(this.dataSource);
15325
+ this.dataSource = null;
15326
+ this.viewer.scene.requestRender();
15327
+ }
15328
+ if (this.tickRemovals.length) {
15329
+ this.tickRemovals.forEach(function (removal) { return removal(); });
15330
+ this.tickRemovals = [];
15331
+ }
15332
+ }
15333
+ return [3 /*break*/, 5];
15334
+ case 4:
15335
+ e_1 = _b.sent();
15336
+ console.error(e_1);
15337
+ return [3 /*break*/, 5];
15338
+ case 5: return [2 /*return*/];
15339
+ }
15340
+ });
15341
+ }); })();
15342
+ };
15343
+ /**
15344
+ * Takes a set of CSV files and renders the collection as a single moving item (truck, car, etc).
15345
+ * This will try to find which is the primary source of point data, and complimentary sources of attribute information.
15346
+ * @param files
15347
+ */
15348
+ Manager.prototype.renderMovingItem = function () {
15349
+ var _a;
15350
+ return __awaiter(this, void 0, void 0, function () {
15351
+ var api, vehicleFileUrl, lineColor, fileStrings, files, i, file, fileId, externalURL, fileUrl, fileStr, csvData, i, delimiter, fileStr, headers, rows, rowsArr, j, row, rowArr, primary, pHeaders, pLatIndex, pLonIndex, pDateTimeIndex, i, row, lat, lon, dateTime, vehicleId, czml, czmlAdjusted, curDateTime, source, errorsInARow_1, removal_1;
15352
+ var _this = this;
15353
+ return __generator(this, function (_b) {
15354
+ switch (_b.label) {
15355
+ case 0:
15356
+ api = this.apiGetter.getApi();
15357
+ return [4 /*yield*/, api.Loading];
15358
+ case 1:
15359
+ _b.sent();
15360
+ fileStrings = [];
15361
+ files = this.item.CSV;
15362
+ i = 0;
15363
+ _b.label = 2;
15364
+ case 2:
15365
+ if (!(i < files.length)) return [3 /*break*/, 6];
15366
+ file = files[i];
15367
+ fileId = (_a = file === null || file === void 0 ? void 0 : file.ClientFile) === null || _a === void 0 ? void 0 : _a.ID;
15368
+ externalURL = file === null || file === void 0 ? void 0 : file.fileUrl;
15369
+ if (!fileId && !externalURL) {
15370
+ return [3 /*break*/, 5];
15371
+ }
15372
+ fileUrl = void 0;
15373
+ if (fileId) {
15374
+ fileUrl = ClientFile.GetUrl({
15375
+ api: api,
15376
+ fileId: fileId,
15377
+ viaCdn: true
15378
+ });
15379
+ }
15380
+ else if (externalURL) {
15381
+ fileUrl = externalURL;
15382
+ }
15383
+ return [4 /*yield*/, fetch(fileUrl)];
15384
+ case 3: return [4 /*yield*/, (_b.sent()).text()];
15385
+ case 4:
15386
+ fileStr = _b.sent();
15387
+ fileStrings.push(fileStr);
15388
+ if (this.disposed) {
15389
+ return [2 /*return*/];
15390
+ }
15391
+ if (file.vehicleFileId) {
15392
+ vehicleFileUrl = ClientFile.GetUrl({
15393
+ api: api,
15394
+ fileId: file.vehicleFileId,
15395
+ viaCdn: true
15396
+ });
15397
+ }
15398
+ if (file.lineColor) {
15399
+ lineColor = file.lineColor;
15400
+ }
15401
+ _b.label = 5;
15402
+ case 5:
15403
+ i++;
15404
+ return [3 /*break*/, 2];
15405
+ case 6:
15406
+ csvData = [];
15407
+ for (i = 0; i < fileStrings.length; i++) {
15408
+ delimiter = ",";
15409
+ fileStr = fileStrings[i];
15410
+ headers = fileStr.slice(0, fileStr.indexOf("\n")).split(delimiter).map(function (header) { return header.trim(); });
15411
+ rows = fileStr.slice(fileStr.indexOf("\n") + 1).split("\n");
15412
+ rowsArr = [];
15413
+ for (j = 0; j < rows.length; j++) {
15414
+ row = rows[j];
15415
+ rowArr = row.split(delimiter).map(function (item) { return item.trim(); });
15416
+ if (rowArr.length === 1 && rowArr[0] === "") {
15417
+ continue;
15418
+ }
15419
+ rowsArr.push(rowArr);
15420
+ }
15421
+ csvData.push({
15422
+ headers: headers,
15423
+ rows: rowsArr
15424
+ });
15425
+ }
15426
+ primary = csvData[0];
15427
+ pHeaders = primary.headers;
15428
+ pLatIndex = pHeaders.findIndex(function (x) { return x.toLowerCase().includes("lat"); });
15429
+ pLonIndex = pHeaders.findIndex(function (x) { return x.toLowerCase().includes("lon"); });
15430
+ pDateTimeIndex = pHeaders.findIndex(function (x) { return x.toLowerCase().includes("date"); });
15431
+ // Ensure values are correct data types.
15432
+ for (i = 0; i < primary.rows.length; i++) {
15433
+ row = primary.rows[i];
15434
+ lat = row[pLatIndex];
15435
+ if (typeof lat == "string") {
15436
+ row[pLatIndex] = parseFloat(lat);
15437
+ }
15438
+ lon = row[pLonIndex];
15439
+ if (typeof lon == "string") {
15440
+ row[pLonIndex] = parseFloat(lon);
15441
+ }
15442
+ dateTime = new Date(row[pDateTimeIndex]);
15443
+ row[pDateTimeIndex] = dateTime.toISOString();
15444
+ }
15445
+ // Sort by date.
15446
+ primary.rows.sort(function (a, b) {
15447
+ var aDate = new Date(a[pDateTimeIndex]);
15448
+ var bDate = new Date(b[pDateTimeIndex]);
15449
+ return aDate.getTime() - bDate.getTime();
15450
+ });
15451
+ vehicleId = ObjectUtils.UId();
15452
+ czml = createJourneyCzml(vehicleId, vehicleFileUrl, lineColor, primary);
15453
+ this.czmlDataInputs.push(czml);
15454
+ czmlAdjusted = JSON.parse(JSON.stringify(czml));
15455
+ czmlAdjusted.forEach(function (item) {
15456
+ delete item.clock;
15457
+ });
15458
+ curDateTime = this.viewer.clock.currentTime;
15459
+ return [4 /*yield*/, this.viewer.dataSources.add(CzmlDataSource.load(czmlAdjusted))];
15460
+ case 7:
15461
+ source = _b.sent();
15462
+ this.dataSource = source;
15463
+ // Reset back to the previous dateTime.
15464
+ // Adding the czml data source will have changed the clock.
15465
+ this.viewer.clock.currentTime = curDateTime;
15466
+ // Listen to update ticks and ensure orientation of moving item is correct.
15467
+ if (this.viewer.clock) {
15468
+ errorsInARow_1 = 0;
15469
+ removal_1 = this.viewer.clock.onTick.addEventListener(function () {
15470
+ var vehicle = source.entities.getById(vehicleId);
15471
+ if (vehicle) {
15472
+ try {
15473
+ updateOrientation(_this.viewer, vehicle);
15474
+ errorsInARow_1 = 0;
15475
+ }
15476
+ catch (e) {
15477
+ console.error(e);
15478
+ errorsInARow_1 += 1;
15479
+ if (errorsInARow_1 >= 3) {
15480
+ removal_1();
15481
+ }
15482
+ }
15483
+ _this.viewer.scene.requestRender();
15484
+ }
15485
+ });
15486
+ this.tickRemovals.push(removal_1);
15487
+ }
15488
+ return [2 /*return*/];
15489
+ }
15490
+ });
15491
+ });
15492
+ };
15493
+ Manager.prototype.Dispose = function () {
15494
+ var _a;
15495
+ if (this.disposed) {
15496
+ return;
15497
+ }
15498
+ this.disposed = true;
15499
+ if (!((_a = this.viewer) === null || _a === void 0 ? void 0 : _a.isDestroyed())) {
15500
+ if (this.dataSource && this.viewer.dataSources.contains(this.dataSource)) {
15501
+ this.viewer.dataSources.remove(this.dataSource);
15502
+ this.dataSource = null;
15503
+ this.viewer.scene.requestRender();
15504
+ }
15505
+ }
15506
+ if (this.tickRemovals.length) {
15507
+ this.tickRemovals.forEach(function (removal) { return removal(); });
15508
+ this.tickRemovals = [];
15509
+ }
15510
+ };
15511
+ Manager.prototype.ReRender = function (params) {
15512
+ return __awaiter(this, void 0, void 0, function () {
15513
+ var entityIds, force;
15514
+ return __generator(this, function (_a) {
15515
+ entityIds = params.entityIds, force = params.force;
15516
+ return [2 /*return*/];
15517
+ });
15518
+ });
15519
+ };
15520
+ return Manager;
15521
+ }());
15522
+ DataSourceStaticCsvManager.Manager = Manager;
15523
+ })(DataSourceStaticCsvManager || (DataSourceStaticCsvManager = {}));
15524
+ /**
15525
+ * Creates a CZML object from the CSV data.
15526
+ * This shows a journey taken by a moving object and alarms detected along the way.
15527
+ * @param vehicleId
15528
+ * @param vehicleFileUrl
15529
+ * @param lineColor
15530
+ * @param data
15531
+ * @returns
15532
+ */
15533
+ function createJourneyCzml(vehicleId, vehicleFileUrl, lineColor, data) {
15534
+ var headers = data.headers;
15535
+ var rows = data.rows;
15536
+ var latIndex = headers.findIndex(function (x) { return x.toLowerCase().includes("lat"); });
15537
+ var lonIndex = headers.findIndex(function (x) { return x.toLowerCase().includes("lon"); });
15538
+ var dateTimeIndex = headers.findIndex(function (x) { return x.toLowerCase().includes("date"); });
15539
+ var alarmIndex = headers.findIndex(function (x) { return x.toLowerCase().includes("alarm"); });
15540
+ var czml = [
15541
+ {
15542
+ "id": "document",
15543
+ "name": "Journey",
15544
+ "version": "1.0",
15545
+ "clock": {
15546
+ "interval": rows[0][dateTimeIndex] + "/" + rows[rows.length - 1][dateTimeIndex],
15547
+ "currentTime": rows[0][dateTimeIndex],
15548
+ "multiplier": 10,
15549
+ "range": "LOOP_STOP",
15550
+ "step": "SYSTEM_CLOCK_MULTIPLIER"
15551
+ }
15552
+ },
15553
+ ];
15554
+ // Create a polyline for the full path.
15555
+ var roadPositions = rows.map(function (row) { return [
15556
+ Number(row[lonIndex]),
15557
+ Number(row[latIndex]),
15558
+ 0
15559
+ ]; }).flat();
15560
+ czml.push({
15561
+ "id": ObjectUtils.UId(),
15562
+ "name": "Path",
15563
+ "polyline": {
15564
+ "positions": {
15565
+ "cartographicDegrees": roadPositions
15566
+ },
15567
+ "material": {
15568
+ "solidColor": {
15569
+ "color": {
15570
+ "rgba": lineColor ? Color.fromCssColorString(lineColor).toBytes() : [0, 255, 0, 100]
15571
+ }
15572
+ }
15573
+ },
15574
+ "width": 5
15575
+ }
15576
+ });
15577
+ // Add points for the alarms.
15578
+ rows.filter(function (row) { return row[alarmIndex]; }).forEach(function (row, index) {
15579
+ czml.push({
15580
+ "id": ObjectUtils.UId(),
15581
+ "name": "Alarm",
15582
+ "position": {
15583
+ "cartographicDegrees": [
15584
+ Number(row[lonIndex]),
15585
+ Number(row[latIndex]),
15586
+ 0
15587
+ ]
15588
+ },
15589
+ "point": {
15590
+ "pixelSize": 10,
15591
+ "color": {
15592
+ "rgba": [255, 0, 0, 255]
15593
+ }
15594
+ },
15595
+ "label": {
15596
+ "text": row[alarmIndex],
15597
+ "show": true,
15598
+ "font": "11pt monospace",
15599
+ "style": "FILL",
15600
+ "outlineColor": {
15601
+ "rgba": [0, 0, 0, 255]
15602
+ },
15603
+ "outlineWidth": 2,
15604
+ "pixelOffset": {
15605
+ "cartesian2": [0, -16]
15606
+ }
15607
+ }
15608
+ });
15609
+ });
15610
+ // Add animated point for the moving item.
15611
+ czml.push({
15612
+ "id": vehicleId,
15613
+ "name": "Vehicle",
15614
+ "availability": rows[0][dateTimeIndex] + "/" + rows[rows.length - 1][dateTimeIndex],
15615
+ "model": vehicleFileUrl ? {
15616
+ "gltf": vehicleFileUrl,
15617
+ "scale": 5
15618
+ } : undefined,
15619
+ "point": !vehicleFileUrl ? {
15620
+ "pixelSize": 20,
15621
+ "color": {
15622
+ "rgba": [0, 0, 255, 255]
15623
+ }
15624
+ } : undefined,
15625
+ "orientation": {
15626
+ "velocityReference": "#vehicle#position"
15627
+ },
15628
+ "position": {
15629
+ "epoch": rows[0][dateTimeIndex],
15630
+ "cartographicDegrees": rows.map(function (row, index) { return [
15631
+ index,
15632
+ Number(row[lonIndex]),
15633
+ Number(row[latIndex]),
15634
+ 0
15635
+ ]; }).flat()
15636
+ }
15637
+ });
15638
+ return czml;
15639
+ }
15640
+ /**
15641
+ * Updates the orientation of the moving item.
15642
+ * This is done by calculating the direction of travel between the current and previous positions.
15643
+ * @param viewer
15644
+ * @param vehicleEntity
15645
+ * @returns
15646
+ */
15647
+ function updateOrientation(viewer, vehicleEntity) {
15648
+ if (!vehicleEntity || !vehicleEntity.position) {
15649
+ return;
15650
+ }
15651
+ var positionProperty = vehicleEntity.position;
15652
+ var currentTime = viewer.clock.currentTime;
15653
+ var previousTime = JulianDate.addSeconds(currentTime, -1, new JulianDate());
15654
+ var currentPosition = positionProperty.getValue(currentTime);
15655
+ var previousPosition = positionProperty.getValue(previousTime);
15656
+ if (currentPosition && previousPosition && !Cartesian3.equals(currentPosition, previousPosition)) {
15657
+ var direction = Cartesian3.subtract(currentPosition, previousPosition, new Cartesian3());
15658
+ Cartesian3.normalize(direction, direction);
15659
+ var rotationMatrix = Transforms.rotationMatrixFromPositionVelocity(previousPosition, direction);
15660
+ vehicleEntity.orientation = Quaternion.fromRotationMatrix(rotationMatrix);
15661
+ }
15662
+ }
15663
+
15249
15664
  /**
15250
15665
  * Utility to keep track of enabled menu items within a Cesium viewer.
15251
15666
  */
@@ -15484,6 +15899,13 @@ var MenuItemManager;
15484
15899
  item: params.item
15485
15900
  });
15486
15901
  break;
15902
+ case MenuItem.EType.Csv:
15903
+ rItem.renderManager = new DataSourceStaticCsvManager.Manager({
15904
+ viewer: this.viewer,
15905
+ apiGetter: params.apiGetter,
15906
+ item: params.item
15907
+ });
15908
+ break;
15487
15909
  case MenuItem.EType.IonTileset:
15488
15910
  case MenuItem.EType.ArbTileset:
15489
15911
  rItem.renderManager = new TilesetArbRenderManager.Manager({
@@ -21690,7 +22112,7 @@ var ViewRenderEngine;
21690
22112
  ViewRenderEngine.Render = Render;
21691
22113
  })(ViewRenderEngine || (ViewRenderEngine = {}));
21692
22114
 
21693
- var VERSION = "3.6.0";
22115
+ var VERSION = "3.6.2";
21694
22116
 
21695
22117
  export { VERSION, CesiumViewMonitor, ViewerUtils, MenuItemManager, EntityRenderEngine, MenuItemCreator, VisualsRegister, RenderManager, EntitiesIdsRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, TilesetCadRenderManager, TilesetArbRenderManager, TilesetEntitiesRenderManager, TilesetOsmRenderManager, TilesetPointcloudRenderManager, TilesetGooglePhotosRenderManager, DataSourceStaticKmlManager, RelationsRenderManager, SharedGetters, CesiumParabola, EntityLabel, ViewRenderEngine, TileRenderEngine, TilesetRenderEngine, CESIUM_INSPECTOR_KEY, ViewUtils, DrawingUtils, MeasureUtils, EntityUtils, CesiumEntityStyler, Draw3dPolygon, Draw3dPolyline };
21696
22118
  //# sourceMappingURL=bruce-cesium.es5.js.map