bruce-cesium 5.9.5 → 5.9.7

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
- import { BruceEvent, Cartes, Entity as Entity$1, ProjectViewTile, Carto, Geometry, MathUtils, LRUCache, Api, Calculator, ClientFile, EntityTag, EntityType, ObjectUtils, Style, DelayQueue, EntityLod, Bounds, ZoomControl, EntityRelationType, ENVIRONMENT, EntityHistoricData, Tileset, EntityCoords, DataLab, EntitySource, MenuItem, EntityRelation, ProgramKey, ProjectView, ProjectViewBookmark, ProjectViewLegacyTile, Camera, EntityAttachment, EntityAttachmentType, EntityAttribute, Session, AbstractApi } from 'bruce-models';
1
+ import { BruceEvent, Cartes, Entity as Entity$1, ProjectViewTile, Carto, Geometry, MathUtils, LRUCache, Api, Calculator, ClientFile, EntityTag, EntityType, ObjectUtils, Style, DelayQueue, EntityLod, Bounds, ZoomControl, EntityRelationType, ENVIRONMENT, EntityHistoricData, Tileset, EntityCoords, DataLab, EntitySource, MenuItem, EntityRelation, ProgramKey, ProjectView, ProjectViewBookmark, Camera, ProjectViewLegacyTile, EntityAttachment, EntityAttachmentType, EntityAttribute, AbstractApi, Session } from 'bruce-models';
2
2
  import * as Cesium from 'cesium';
3
- import { Cartographic, Cartesian2, Math as Math$1, Cartesian3, CallbackProperty, Color, HeightReference, Rectangle, JulianDate, Entity, DistanceDisplayCondition, ClassificationType, ArcType, CornerType, ShadowMode, ConstantProperty, ConstantPositionProperty, PolygonHierarchy, PolylineGraphics, ColorMaterialProperty, HorizontalOrigin, VerticalOrigin, ColorBlendMode, HeadingPitchRoll, Transforms, Model, SceneMode, Primitive, Cesium3DTileFeature, GeoJsonDataSource, Cesium3DTileStyle, HeadingPitchRange, Cesium3DTileColorBlendMode, Ion, KmlDataSource, SceneTransforms, Quaternion, Matrix3, Matrix4, Cesium3DTileset, IonResource, EllipsoidTerrainProvider, CesiumInspector, OrthographicFrustum, defined, ClockRange, PolygonPipeline, EllipsoidGeodesic, sampleTerrainMostDetailed, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, EasingFunction, NearFarScalar, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, ScreenSpaceEventHandler, ScreenSpaceEventType, BoundingSphere, GeometryInstance, CzmlDataSource, Intersect, Fullscreen } from 'cesium';
3
+ import { Cartographic, Cartesian2, Math as Math$1, Cartesian3, CallbackProperty, Color, HeightReference, Rectangle, JulianDate, Entity, DistanceDisplayCondition, ClassificationType, ArcType, CornerType, ShadowMode, ConstantProperty, ConstantPositionProperty, HorizontalOrigin, VerticalOrigin, ColorBlendMode, HeadingPitchRoll, Transforms, Model, PolygonHierarchy, PolylineGraphics, ColorMaterialProperty, Primitive, Cesium3DTileFeature, SceneMode, GeoJsonDataSource, Cesium3DTileStyle, HeadingPitchRange, Cesium3DTileColorBlendMode, Ion, KmlDataSource, Quaternion, Matrix3, Matrix4, OrthographicFrustum, EasingFunction, NearFarScalar, SceneTransforms, Cesium3DTileset, IonResource, EllipsoidTerrainProvider, CesiumInspector, defined, ClockRange, EllipsoidGeodesic, sampleTerrainMostDetailed, PolygonPipeline, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, ScreenSpaceEventHandler, ScreenSpaceEventType, BoundingSphere, GeometryInstance, CzmlDataSource, Intersect, Fullscreen } from 'cesium';
4
4
 
5
5
  const TIME_LAG = 300;
6
6
  const POSITION_CHECK_TIMER = 950;
@@ -1144,48 +1144,70 @@ var CesiumAnimatedProperty;
1144
1144
  */
1145
1145
  class AnimatePositionSeries {
1146
1146
  constructor(params) {
1147
- // Current position state.
1148
- this.lastCalcPos3d = null;
1149
- this.lastCalcPosIndexLast = -1;
1150
- this.lastCalcPosIndexNext = -1;
1151
- // Series data for rendering path.
1147
+ // Animation state.
1148
+ this.currentAnimatedPos = null;
1149
+ this.actualTargetPos = null;
1150
+ this.animationStartPos = null;
1151
+ this.animationStartTime = null;
1152
+ this.animationDuration = 350;
1153
+ // Cached data for performance.
1154
+ this.lastDesiredPosIndex = -1;
1155
+ this.lastDesiredNextIndex = -1;
1156
+ // Series data for rendering path
1152
1157
  this.lastCalcSeriesPos3d = [];
1153
1158
  this.lastCalcSeriesTime = null;
1154
- // Orientation.
1159
+ // Orientation cache.
1155
1160
  this.lastCalcOrient = null;
1156
1161
  this.lastCalcOrientTime = null;
1157
- // Starting animation state.
1158
- this.animateFromPos3d = null;
1159
- this.animateFromPos3dTimeStart = null;
1160
- this.animationDuration = 200; // milliseconds
1161
1162
  this.viewer = params.viewer;
1162
1163
  this.positions = params.posses || [];
1163
1164
  this.pitch = params.pitch || 0;
1164
1165
  this.roll = params.roll || 0;
1165
- // Animation from a starting position.
1166
+ this.processHeadings();
1167
+ this.sortPositions();
1168
+ // Initialize animation from starting position if provided.
1166
1169
  if (params.animateFromPos3d) {
1167
- this.animateFromPos3d = params.animateFromPos3d;
1170
+ this.animationStartPos = params.animateFromPos3d;
1168
1171
  const currentTime = Date.now();
1169
1172
  const providedTime = params.animateFromPos3dTimeStart || 0;
1170
- // Check if the provided timestamp is stale (animation would have already completed)
1171
- // If so, use current time to restart the animation.
1173
+ // Check if the provided timestamp is stale.
1172
1174
  if (!providedTime || (currentTime - providedTime) >= this.animationDuration) {
1173
- this.animateFromPos3dTimeStart = currentTime;
1175
+ this.animationStartTime = currentTime;
1174
1176
  }
1175
1177
  else {
1176
- this.animateFromPos3dTimeStart = providedTime;
1178
+ this.animationStartTime = providedTime;
1177
1179
  }
1178
1180
  }
1181
+ }
1182
+ AddPosition(pos) {
1183
+ if (!pos || !pos.pos3d || !pos.dateTime) {
1184
+ console.warn("Invalid position provided to AnimatePositionSeries.");
1185
+ return;
1186
+ }
1187
+ this.positions.push(pos);
1179
1188
  this.processHeadings();
1180
- // Order positions by date.
1189
+ this.sortPositions();
1190
+ this.invalidateCache();
1191
+ }
1192
+ UpdatePitchRoll(pitch, roll) {
1193
+ this.pitch = pitch;
1194
+ this.roll = roll;
1195
+ this.invalidateCache();
1196
+ }
1197
+ GetAnimateFromDateTime() {
1198
+ return this.animationStartTime;
1199
+ }
1200
+ GetPositions() {
1201
+ return this.positions;
1202
+ }
1203
+ sortPositions() {
1181
1204
  if (this.positions.length > 0) {
1182
- this.positions.sort((a, b) => {
1183
- return a.dateTime.getTime() - b.dateTime.getTime();
1184
- });
1205
+ this.positions.sort((a, b) => a.dateTime.getTime() - b.dateTime.getTime());
1185
1206
  }
1186
1207
  }
1187
- GetAnimateFromDateTime() {
1188
- return this.animateFromPos3dTimeStart;
1208
+ invalidateCache() {
1209
+ this.lastCalcSeriesTime = null;
1210
+ this.lastCalcOrientTime = null;
1189
1211
  }
1190
1212
  /**
1191
1213
  * Pre-process headings in the series.
@@ -1209,130 +1231,178 @@ var CesiumAnimatedProperty;
1209
1231
  }
1210
1232
  }
1211
1233
  }
1212
- GetPositions() {
1213
- return this.positions;
1214
- }
1215
1234
  easeInOutQuad(t) {
1216
1235
  return t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2;
1217
1236
  }
1218
1237
  /**
1219
- * Interpolates between the starting position and target position.
1238
+ * Calculate the desired position based on current time without any animation smoothing.
1220
1239
  */
1221
- interpolateToTargetPosition(startPos, targetPos, startTimeMs, currentTimeMs) {
1222
- if (!startPos || !targetPos) {
1223
- return startPos || targetPos || new Cartesian3();
1240
+ calculateDesiredPosition(timeMs) {
1241
+ // No positions available.
1242
+ if (!this.positions || this.positions.length === 0) {
1243
+ return { position: null, lastIndex: -1, nextIndex: -1 };
1224
1244
  }
1225
- const elapsedTime = currentTimeMs - startTimeMs;
1226
- let progress = Math.min(elapsedTime / this.animationDuration, 1.0);
1227
- // Apply easing for more natural motion.
1228
- progress = this.easeInOutQuad(progress);
1229
- try {
1230
- return Cartesian3.lerp(startPos, targetPos, progress, new Cartesian3());
1245
+ // Only one position..
1246
+ if (this.positions.length === 1) {
1247
+ return {
1248
+ position: this.positions[0].pos3d || null,
1249
+ lastIndex: 0,
1250
+ nextIndex: 0
1251
+ };
1231
1252
  }
1232
- catch (e) {
1233
- console.error("Error in position interpolation: ", e);
1234
- return targetPos;
1253
+ // Before first position - use first two positions for orientation.
1254
+ if (timeMs <= this.positions[0].dateTime.getTime()) {
1255
+ return {
1256
+ position: this.positions[0].pos3d || null,
1257
+ lastIndex: 0,
1258
+ nextIndex: Math.min(1, this.positions.length - 1)
1259
+ };
1235
1260
  }
1261
+ // After last position - use last two positions for orientation.
1262
+ const lastIdx = this.positions.length - 1;
1263
+ if (timeMs >= this.positions[lastIdx].dateTime.getTime()) {
1264
+ return {
1265
+ position: this.positions[lastIdx].pos3d || null,
1266
+ lastIndex: Math.max(0, lastIdx - 1),
1267
+ nextIndex: lastIdx
1268
+ };
1269
+ }
1270
+ // Find positions to interpolate between.
1271
+ for (let i = 0; i < this.positions.length - 1; i++) {
1272
+ const current = this.positions[i];
1273
+ const next = this.positions[i + 1];
1274
+ if (timeMs >= current.dateTime.getTime() && timeMs < next.dateTime.getTime()) {
1275
+ // Exact match on current position - still use current and next for orientation.
1276
+ if (timeMs === current.dateTime.getTime()) {
1277
+ return {
1278
+ position: current.pos3d || null,
1279
+ lastIndex: i,
1280
+ nextIndex: i + 1
1281
+ };
1282
+ }
1283
+ // Interpolate between current and next.
1284
+ if (!current.pos3d || !next.pos3d) {
1285
+ return {
1286
+ position: current.pos3d || next.pos3d || null,
1287
+ lastIndex: i,
1288
+ nextIndex: i + 1
1289
+ };
1290
+ }
1291
+ try {
1292
+ const progress = (timeMs - current.dateTime.getTime()) / (next.dateTime.getTime() - current.dateTime.getTime());
1293
+ const interpolatedPos = Cartesian3.lerp(current.pos3d, next.pos3d, progress, new Cartesian3());
1294
+ return {
1295
+ position: interpolatedPos,
1296
+ lastIndex: i,
1297
+ nextIndex: i + 1
1298
+ };
1299
+ }
1300
+ catch (e) {
1301
+ console.error("Error in position interpolation: ", e);
1302
+ return {
1303
+ position: current.pos3d,
1304
+ lastIndex: i,
1305
+ nextIndex: i + 1
1306
+ };
1307
+ }
1308
+ }
1309
+ }
1310
+ // Fallback to last position with previous position for orientation.
1311
+ return {
1312
+ position: this.positions[lastIdx].pos3d || null,
1313
+ lastIndex: Math.max(0, lastIdx - 1),
1314
+ nextIndex: lastIdx
1315
+ };
1236
1316
  }
1237
1317
  /**
1238
- * Main method to get the current position based on time
1318
+ * Main method to get the current position based on time.
1239
1319
  */
1240
1320
  GetValue() {
1241
- let now = this.viewer.scene.lastRenderTime;
1242
- if (!now) {
1243
- now = this.viewer.clock.currentTime;
1321
+ let viewerTime = this.viewer.scene.lastRenderTime;
1322
+ if (!viewerTime) {
1323
+ viewerTime = this.viewer.clock.currentTime;
1244
1324
  }
1245
- const nowTimeMs = JulianDate.toDate(now).getTime();
1325
+ const viewerTimeMs = JulianDate.toDate(viewerTime).getTime();
1246
1326
  const currentRealTimeMs = Date.now();
1247
- // Calculate the ideal position based on time.
1248
- const idealPosition = this.calculateIdealPosition(nowTimeMs);
1249
- // First run initialization.
1250
- if (!this.lastCalcPos3d) {
1251
- this.lastCalcPos3d = idealPosition;
1252
- // If we have a starting position, animate from it.
1253
- if (this.animateFromPos3d) {
1254
- return this.interpolateToTargetPosition(this.animateFromPos3d, idealPosition, this.animateFromPos3dTimeStart, currentRealTimeMs);
1255
- }
1256
- return idealPosition;
1257
- }
1258
- // If we're animating from a start position.
1259
- if (this.animateFromPos3d) {
1260
- const elapsedTime = currentRealTimeMs - this.animateFromPos3dTimeStart;
1261
- // If animation is complete, just return ideal position and clear animation state.
1262
- if (elapsedTime >= this.animationDuration) {
1263
- this.animateFromPos3d = null;
1264
- this.lastCalcPos3d = idealPosition;
1265
- return idealPosition;
1266
- }
1267
- // Otherwise continue interpolation.
1268
- const interpolatedPos = this.interpolateToTargetPosition(this.animateFromPos3d, idealPosition, this.animateFromPos3dTimeStart, currentRealTimeMs);
1269
- this.lastCalcPos3d = interpolatedPos;
1270
- return interpolatedPos;
1271
- }
1272
- // If we're not animating, directly use the ideal position.
1273
- // This ensures we're exactly where we should be based on time.
1274
- this.lastCalcPos3d = idealPosition;
1275
- return idealPosition;
1276
- }
1277
- /**
1278
- * Calculate the ideal position based on current time without any smoothing.
1279
- */
1280
- calculateIdealPosition(timeMs) {
1281
- if (!this.positions || this.positions.length === 0) {
1327
+ // Calculate the desired position based on time.
1328
+ const desired = this.calculateDesiredPosition(viewerTimeMs);
1329
+ if (!desired.position) {
1330
+ this.currentAnimatedPos = null;
1331
+ this.actualTargetPos = null;
1282
1332
  return new Cartesian3();
1283
1333
  }
1284
- // Before first position.
1285
- if (timeMs <= this.positions[0].dateTime.getTime()) {
1286
- this.lastCalcPosIndexLast = 0;
1287
- this.lastCalcPosIndexNext = 0;
1288
- return this.positions[0].pos3d || new Cartesian3();
1289
- }
1290
- // After last position.
1291
- if (timeMs >= this.positions[this.positions.length - 1].dateTime.getTime()) {
1292
- const lastIndex = this.positions.length - 1;
1293
- this.lastCalcPosIndexLast = lastIndex;
1294
- this.lastCalcPosIndexNext = lastIndex;
1295
- return this.positions[lastIndex].pos3d || new Cartesian3();
1296
- }
1297
- // Find the position before and after the current time.
1298
- let lastIndex = 0;
1299
- for (let i = 0; i < this.positions.length - 1; i++) {
1300
- if (timeMs >= this.positions[i].dateTime.getTime() &&
1301
- timeMs < this.positions[i + 1].dateTime.getTime()) {
1302
- lastIndex = i;
1303
- break;
1304
- }
1305
- }
1306
- const last = this.positions[lastIndex];
1307
- this.lastCalcPosIndexLast = lastIndex;
1308
- // If we're exactly at this position's time.
1309
- if (timeMs === last.dateTime.getTime()) {
1310
- this.lastCalcPosIndexNext = lastIndex;
1311
- return last.pos3d || new Cartesian3();
1334
+ this.lastDesiredPosIndex = desired.lastIndex;
1335
+ this.lastDesiredNextIndex = desired.nextIndex;
1336
+ // Determine the desired position without interpolation.
1337
+ let discreteTarget;
1338
+ if (desired.lastIndex === desired.nextIndex) {
1339
+ discreteTarget = this.positions[desired.lastIndex].pos3d;
1312
1340
  }
1313
- // Interpolate between surrounding positions.
1314
- const next = this.positions[lastIndex + 1];
1315
- if (!next) {
1316
- this.lastCalcPosIndexNext = lastIndex;
1317
- return last.pos3d || new Cartesian3();
1318
- }
1319
- this.lastCalcPosIndexNext = lastIndex + 1;
1320
- try {
1321
- // Ensure both position vectors are valid.
1322
- if (!last.pos3d || !next.pos3d) {
1323
- return last.pos3d || next.pos3d || new Cartesian3();
1341
+ // Use the next position as the target.
1342
+ else {
1343
+ discreteTarget = this.positions[desired.nextIndex].pos3d;
1344
+ }
1345
+ // Check if we have a new actual target
1346
+ const actualTargetChanged = !this.actualTargetPos || !Cartesian3.equals(this.actualTargetPos, discreteTarget);
1347
+ // First time or no previous position - start here.
1348
+ if (!this.currentAnimatedPos) {
1349
+ if (this.animationStartPos) {
1350
+ this.actualTargetPos = discreteTarget;
1351
+ const progress = this.getAnimationProgress(currentRealTimeMs, this.animationStartTime);
1352
+ // Animation from start position complete.
1353
+ if (progress >= 1.0) {
1354
+ this.currentAnimatedPos = desired.position;
1355
+ this.animationStartPos = null;
1356
+ this.animationStartTime = null;
1357
+ return desired.position;
1358
+ }
1359
+ // Still animating from initial position.
1360
+ else {
1361
+ const easedProgress = this.easeInOutQuad(progress);
1362
+ this.currentAnimatedPos = Cartesian3.lerp(this.animationStartPos, desired.position, easedProgress, new Cartesian3());
1363
+ return this.currentAnimatedPos;
1364
+ }
1365
+ }
1366
+ // No initial animation needed.
1367
+ else {
1368
+ this.currentAnimatedPos = desired.position;
1369
+ this.actualTargetPos = discreteTarget;
1370
+ return desired.position;
1371
+ }
1372
+ }
1373
+ // Target changed.
1374
+ if (actualTargetChanged) {
1375
+ this.animationStartPos = this.currentAnimatedPos;
1376
+ this.animationStartTime = currentRealTimeMs;
1377
+ this.actualTargetPos = discreteTarget;
1378
+ }
1379
+ // Continue or start animation to target if we have an active animation.
1380
+ if (this.animationStartPos && this.animationStartTime) {
1381
+ const progress = this.getAnimationProgress(currentRealTimeMs, this.animationStartTime);
1382
+ // Animation complete.
1383
+ if (progress >= 1.0) {
1384
+ this.currentAnimatedPos = desired.position;
1385
+ this.animationStartPos = null;
1386
+ this.animationStartTime = null;
1387
+ return desired.position;
1388
+ }
1389
+ // Continue animation to interpolated position.
1390
+ else {
1391
+ const easedProgress = this.easeInOutQuad(progress);
1392
+ this.currentAnimatedPos = Cartesian3.lerp(this.animationStartPos, desired.position, easedProgress, new Cartesian3());
1393
+ return this.currentAnimatedPos;
1324
1394
  }
1325
- const progress = (timeMs - last.dateTime.getTime()) /
1326
- (next.dateTime.getTime() - last.dateTime.getTime());
1327
- return Cartesian3.lerp(last.pos3d, next.pos3d, progress, new Cartesian3());
1328
- }
1329
- catch (e) {
1330
- console.error("Error in ideal position calculation: ", e);
1331
- return last.pos3d || new Cartesian3();
1332
1395
  }
1396
+ // No active animation - follow interpolated path directly.
1397
+ this.currentAnimatedPos = desired.position;
1398
+ return desired.position;
1399
+ }
1400
+ getAnimationProgress(currentTime, startTime) {
1401
+ const elapsed = currentTime - startTime;
1402
+ return Math.min(elapsed / this.animationDuration, 1.0);
1333
1403
  }
1334
1404
  /**
1335
- * Returns a series of positions to use for rendering the path..
1405
+ * Returns a series of positions to use for rendering the path.
1336
1406
  */
1337
1407
  GetSeries() {
1338
1408
  // Update at 30 fps.
@@ -1356,8 +1426,7 @@ var CesiumAnimatedProperty;
1356
1426
  this.lastCalcSeriesPos3d = [];
1357
1427
  return [];
1358
1428
  }
1359
- const totalDuration = this.positions[this.positions.length - 1].dateTime.getTime() -
1360
- this.positions[0].dateTime.getTime();
1429
+ const totalDuration = this.positions[this.positions.length - 1].dateTime.getTime() - this.positions[0].dateTime.getTime();
1361
1430
  // Percentage of the polyline to be visible before and after each point.
1362
1431
  const visibilityPercentage = 0.05; // 5%
1363
1432
  const visibilityDuration = totalDuration * visibilityPercentage;
@@ -1365,13 +1434,14 @@ var CesiumAnimatedProperty;
1365
1434
  const newPosses = [];
1366
1435
  for (let i = 0; i < this.positions.length; i++) {
1367
1436
  const pos = this.positions[i];
1368
- if (!pos.pos3d)
1437
+ if (!pos.pos3d) {
1369
1438
  continue;
1439
+ }
1370
1440
  let add = nowDate >= new Date(pos.dateTime.getTime() - visibilityDuration / 2) &&
1371
1441
  nowDate <= new Date(pos.dateTime.getTime() + visibilityDuration / 2);
1372
1442
  // Also include the segment we're currently traversing.
1373
- if (!add && this.lastCalcPosIndexLast > -1 && this.lastCalcPosIndexNext > -1) {
1374
- add = i >= this.lastCalcPosIndexLast && i <= this.lastCalcPosIndexNext;
1443
+ if (!add && this.lastDesiredPosIndex > -1 && this.lastDesiredNextIndex > -1) {
1444
+ add = i >= this.lastDesiredPosIndex && i <= this.lastDesiredNextIndex;
1375
1445
  }
1376
1446
  if (add) {
1377
1447
  newPosses.push(pos.pos3d);
@@ -1409,10 +1479,10 @@ var CesiumAnimatedProperty;
1409
1479
  }
1410
1480
  const nowTime = JulianDate.toDate(now).getTime();
1411
1481
  try {
1412
- // Get last and next position indices.
1413
- const lastIndex = this.lastCalcPosIndexLast;
1414
- const nextIndex = this.lastCalcPosIndexNext;
1415
- // Validate indices.
1482
+ // Get current position indices.
1483
+ const lastIndex = this.lastDesiredPosIndex;
1484
+ const nextIndex = this.lastDesiredNextIndex;
1485
+ // Invalid indices.
1416
1486
  if (lastIndex < 0 || nextIndex < 0 ||
1417
1487
  lastIndex >= this.positions.length || nextIndex >= this.positions.length) {
1418
1488
  return this.lastCalcOrient || defaultQuaternion;
@@ -1422,6 +1492,17 @@ var CesiumAnimatedProperty;
1422
1492
  if (!lastPos || !nextPos) {
1423
1493
  return this.lastCalcOrient || defaultQuaternion;
1424
1494
  }
1495
+ // Single position case - use its heading if available.
1496
+ if (lastIndex === nextIndex) {
1497
+ if (lastPos.heading !== null) {
1498
+ this.lastCalcOrient = Transforms.headingPitchRollQuaternion(currentPosition, new HeadingPitchRoll(Math$1.toRadians(lastPos.heading), Math$1.toRadians(this.pitch), Math$1.toRadians(this.roll)));
1499
+ this.lastCalcOrientTime = Date.now();
1500
+ return this.lastCalcOrient;
1501
+ }
1502
+ // No heading data and single position, return previous or default.
1503
+ return this.lastCalcOrient || defaultQuaternion;
1504
+ }
1505
+ // Two different positions - we can calculate orientation.
1425
1506
  // Use explicit heading values if available.
1426
1507
  if (lastPos.heading !== null && nextPos.heading !== null) {
1427
1508
  // Calculate interpolated heading.
@@ -1435,8 +1516,7 @@ var CesiumAnimatedProperty;
1435
1516
  }
1436
1517
  // Calculate interpolation factor.
1437
1518
  let factor = 0;
1438
- if (lastIndex !== nextIndex &&
1439
- lastPos.dateTime.getTime() !== nextPos.dateTime.getTime()) {
1519
+ if (lastPos.dateTime.getTime() !== nextPos.dateTime.getTime()) {
1440
1520
  factor = (nowTime - lastPos.dateTime.getTime()) /
1441
1521
  (nextPos.dateTime.getTime() - lastPos.dateTime.getTime());
1442
1522
  factor = Math.max(0, Math.min(1, factor));
@@ -1449,7 +1529,7 @@ var CesiumAnimatedProperty;
1449
1529
  // Create quaternion from heading, pitch, roll.
1450
1530
  this.lastCalcOrient = Transforms.headingPitchRollQuaternion(currentPosition, new HeadingPitchRoll(Math$1.toRadians(interpolatedHeading), Math$1.toRadians(this.pitch), Math$1.toRadians(this.roll)));
1451
1531
  }
1452
- // Calculate heading from position changes if not available.
1532
+ // Calculate heading from position changes if heading data not available.
1453
1533
  else {
1454
1534
  if (!lastPos.pos3d || !nextPos.pos3d) {
1455
1535
  return this.lastCalcOrient || defaultQuaternion;
@@ -6842,7 +6922,9 @@ function removeEntities(viewer, entities) {
6842
6922
  continue;
6843
6923
  }
6844
6924
  entityRemoveAddState.delete(entity.id);
6845
- viewer.entities.remove(entity);
6925
+ if (viewer.entities.contains(entity)) {
6926
+ viewer.entities.remove(entity);
6927
+ }
6846
6928
  }
6847
6929
  });
6848
6930
  }
@@ -6864,7 +6946,9 @@ function addEntities(viewer, entities) {
6864
6946
  continue;
6865
6947
  }
6866
6948
  entityRemoveAddState.delete(entity.id);
6867
- viewer.entities.add(entity);
6949
+ if (!viewer.entities.contains(entity)) {
6950
+ viewer.entities.add(entity);
6951
+ }
6868
6952
  }
6869
6953
  });
6870
6954
  }
@@ -6971,7 +7055,7 @@ var EntityRenderEngineModel3d;
6971
7055
  * @returns
6972
7056
  */
6973
7057
  function Render(params) {
6974
- var _a, _b;
7058
+ var _a, _b, _c, _d;
6975
7059
  const entity = params.entity;
6976
7060
  if (!params.entityHistoric) {
6977
7061
  params.entityHistoric = [];
@@ -7073,6 +7157,7 @@ var EntityRenderEngineModel3d;
7073
7157
  }
7074
7158
  };
7075
7159
  let cEntity = params.rendered;
7160
+ let prevPos3d = cEntity ? GetCValue(params.viewer, cEntity.position) : null;
7076
7161
  if (!cEntity || !cEntity.model) {
7077
7162
  updateShouldShowTrack();
7078
7163
  if (!color) {
@@ -7162,12 +7247,11 @@ var EntityRenderEngineModel3d;
7162
7247
  cEntity.model.colorBlendAmount = new ConstantProperty(blendAmount);
7163
7248
  cEntity.model.colorBlendMode = new ConstantProperty(blendMode);
7164
7249
  cEntity.model.distanceDisplayCondition = new ConstantProperty(EntityRenderEngine.GetDisplayCondition(params.minDistance, params.maxDistance));
7165
- const prevPos3d = GetCValue(params.viewer, cEntity.position);
7166
7250
  let prevStartTime = null;
7167
7251
  if (cEntity.position && cEntity.position["CesiumAnimatedProperty.AnimatePositionSeries"]) {
7168
7252
  prevStartTime = cEntity.position["CesiumAnimatedProperty.AnimatePositionSeries"].GetAnimateFromDateTime();
7169
7253
  }
7170
- // If we have a series of time-based positions then we'll animate as time changes.
7254
+ // If we've loaded a set of series positions then we'll animate through them.
7171
7255
  const series = CesiumAnimatedProperty.GetSeriesPossesForHistoricEntity(params.viewer, heightRef, heightRef, params.entityHistoric);
7172
7256
  if (series.length > 1) {
7173
7257
  animatePosition = new CesiumAnimatedProperty.AnimatePositionSeries({
@@ -7182,17 +7266,50 @@ var EntityRenderEngineModel3d;
7182
7266
  cEntity.position["CesiumAnimatedProperty.AnimatePositionSeries"] = animatePosition;
7183
7267
  }
7184
7268
  else {
7269
+ const dateTimeStr = (_b = (_a = entity.Bruce.Outline) === null || _a === void 0 ? void 0 : _a.find(x => !!x.DateTime)) === null || _b === void 0 ? void 0 : _b.DateTime;
7270
+ const dateTime = dateTimeStr ? new Date(dateTimeStr) : null;
7185
7271
  const posChanged = !prevPos3d || !Cartesian3.equals(prevPos3d, pos3d);
7186
7272
  if (posChanged) {
7187
- animatePosition = new CesiumAnimatedProperty.AnimatePosition({
7188
- durationMs: 200,
7189
- targetPos3d: pos3d,
7190
- viewer: params.viewer,
7191
- startPos3d: prevPos3d
7192
- });
7193
- cEntity.position = new CallbackProperty(() => animatePosition.GetValue(), false);
7273
+ if (cEntity.position["CesiumAnimatedProperty.AnimatePositionSeries"]) {
7274
+ const prevAnimatePosition = cEntity.position["CesiumAnimatedProperty.AnimatePositionSeries"];
7275
+ animatePosition = prevAnimatePosition;
7276
+ animatePosition.AddPosition({
7277
+ pos3d: pos3d,
7278
+ dateTime: dateTime,
7279
+ heading: !EnsureNumber(transform === null || transform === void 0 ? void 0 : transform.heading) ? null : heading
7280
+ });
7281
+ animatePosition.UpdatePitchRoll(pitch, roll);
7282
+ }
7283
+ else {
7284
+ let posses = [];
7285
+ const isLive = ViewUtils.GetTimeDetails({ viewer: params.viewer }).isLive;
7286
+ if (prevPos3d && isLive) {
7287
+ posses.push({
7288
+ pos3d: prevPos3d,
7289
+ // Guess so that we can determine a direction of movement right away :)
7290
+ dateTime: new Date(dateTime.getTime() - 1000),
7291
+ heading: !EnsureNumber(transform === null || transform === void 0 ? void 0 : transform.heading) ? null : heading
7292
+ });
7293
+ }
7294
+ posses.push({
7295
+ pos3d: pos3d,
7296
+ dateTime: dateTime,
7297
+ heading: !EnsureNumber(transform === null || transform === void 0 ? void 0 : transform.heading) ? null : heading
7298
+ });
7299
+ animatePosition = new CesiumAnimatedProperty.AnimatePositionSeries({
7300
+ posses: posses,
7301
+ viewer: params.viewer,
7302
+ pitch: pitch,
7303
+ roll: roll,
7304
+ animateFromPos3d: prevPos3d && !isLive ? prevPos3d : null,
7305
+ animateFromPos3dTimeStart: null
7306
+ });
7307
+ cEntity.position = new CallbackProperty(() => animatePosition.GetValue(), false);
7308
+ cEntity.position["CesiumAnimatedProperty.AnimatePositionSeries"] = animatePosition;
7309
+ }
7194
7310
  }
7195
7311
  }
7312
+ // If we're animating position then we can animate orientation too based on the interpolated position.
7196
7313
  if (animatePosition && animatePosition instanceof CesiumAnimatedProperty.AnimatePositionSeries && animatePosition.GetOrient) {
7197
7314
  cEntity.orientation = new CallbackProperty(() => {
7198
7315
  return animatePosition.GetOrient();
@@ -7200,15 +7317,16 @@ var EntityRenderEngineModel3d;
7200
7317
  }
7201
7318
  else {
7202
7319
  const prevHeading = cEntity.model._heading;
7320
+ // Not worth animating.
7203
7321
  if (prevHeading == null || prevHeading == heading || isNaN(prevHeading)) {
7204
7322
  const hpr = new HeadingPitchRoll(Math$1.toRadians(heading), Math$1.toRadians(pitch), Math$1.toRadians(roll));
7205
7323
  const orient = Transforms.headingPitchRollQuaternion(pos3d, hpr);
7206
7324
  cEntity.orientation = new CallbackProperty(() => orient, true);
7207
7325
  }
7208
- // Animate orientation. We'll calculate the heading based on movement.
7326
+ // Animate the change.
7209
7327
  else {
7210
7328
  const animateHeading = new CesiumAnimatedProperty.AnimateHeading({
7211
- durationMs: 200,
7329
+ durationMs: 500,
7212
7330
  targetHeading: heading,
7213
7331
  viewer: params.viewer,
7214
7332
  startHeading: prevHeading
@@ -7240,7 +7358,7 @@ var EntityRenderEngineModel3d;
7240
7358
  else {
7241
7359
  cEntity.model.scale = new CallbackProperty(() => scale * styleScale, true);
7242
7360
  }
7243
- // We'll use "SetDefaultColor" to updating the internal reference and to allow for an animation.
7361
+ // We'll use "SetDefaultColor" to update the internal reference and to allow for an animation.
7244
7362
  // cEntity.model.color = new Cesium.CallbackProperty(() => color, true);
7245
7363
  CesiumEntityStyler.SetDefaultColor({
7246
7364
  color: color ? color : new Color(),
@@ -7337,7 +7455,7 @@ var EntityRenderEngineModel3d;
7337
7455
  // Generate a polyline 'track' for the historic data.
7338
7456
  // We do this for historic data that exists and is moving.
7339
7457
  if (shouldShowTrack && animatePosition && animatePosition instanceof CesiumAnimatedProperty.AnimatePositionSeries && animatePosition.GetSeries) {
7340
- const lStyle = (_b = (_a = params.fullStyle) === null || _a === void 0 ? void 0 : _a.polylineStyle) !== null && _b !== void 0 ? _b : {};
7458
+ const lStyle = (_d = (_c = params.fullStyle) === null || _c === void 0 ? void 0 : _c.polylineStyle) !== null && _d !== void 0 ? _d : {};
7341
7459
  const bColor = lStyle.lineColor ? Calculator.GetColor(lStyle.lineColor, entity, params.tags) : null;
7342
7460
  const cColor = bColor ? ColorToCColor(bColor) : Color.fromCssColorString("rgba(255, 193, 7, 0.8)");
7343
7461
  let width = lStyle.lineWidth ? EnsureNumber(Calculator.GetNumber(lStyle.lineWidth, entity, params.tags)) : 2;
@@ -33131,7 +33249,7 @@ class WidgetViewBar extends Widget.AWidget {
33131
33249
  }
33132
33250
  }
33133
33251
 
33134
- const VERSION = "5.9.5";
33252
+ const VERSION = "5.9.7";
33135
33253
 
33136
33254
  export { VERSION, CesiumViewMonitor, ViewerUtils, ViewerEventTracker, MenuItemManager, isOutlineChanged, EntityRenderEngine, EntityRenderEnginePoint, EntityRenderEnginePolyline, EntityRenderEnginePolygon, EntityRenderEngineModel3d, MenuItemCreator, VisualsRegister, RenderManager, EntitiesIdsRenderManager, DataLabRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, TilesetCadRenderManager, TilesetArbRenderManager, TilesetEntitiesRenderManager, TilesetOsmRenderManager, TilesetPointcloudRenderManager, TilesetGooglePhotosRenderManager, DataSourceStaticKmlManager, GoogleSearchRenderManager, AssemblyRenderManager, RelationsRenderManager, SharedGetters, CesiumParabola, EntityLabel, ViewRenderEngine, TileRenderEngine, TilesetRenderEngine, CESIUM_INSPECTOR_KEY, CESIUM_TIMELINE_KEY, CESIUM_TIMELINE_LIVE_KEY, CESIUM_TIMELINE_LIVE_PADDING_KEY, CESIUM_TIMELINE_INTERVAL_KEY, DEFAULT_LIVE_PADDING_SECONDS, ViewUtils, DrawingUtils, MeasureUtils, EntityUtils, CesiumEntityStyler, CesiumAnimatedProperty, CesiumAnimatedInOut, Draw3dPolygon, Draw3dPolyline, MeasureCreator, Walkthrough, Widget, VIEWER_BOOKMARKS_WIDGET_KEY, WidgetBookmarks, WidgetBranding, WidgetCursorBar, WidgetEmbeddedInfoView, WidgetInfoView, WidgetNavCompass$$1 as WidgetNavCompass, VIEWER_VIEW_BAR_WIDGET_KEY, WidgetViewBar, WidgetControlViewBar, WidgetControlViewBarSearch, VIEWER_LEFT_PANEL_WIDGET_KEY, VIEWER_LEFT_PANEL_CSS_VAR_LEFT, WidgetLeftPanel, WidgetLeftPanelTab, WidgetLeftPanelTabBookmarks };
33137
33255
  //# sourceMappingURL=bruce-cesium.es5.js.map