bruce-cesium 3.7.3 → 3.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.
Files changed (28) hide show
  1. package/dist/bruce-cesium.es5.js +1171 -312
  2. package/dist/bruce-cesium.es5.js.map +1 -1
  3. package/dist/bruce-cesium.umd.js +1169 -310
  4. package/dist/bruce-cesium.umd.js.map +1 -1
  5. package/dist/lib/bruce-cesium.js +1 -1
  6. package/dist/lib/rendering/cesium-animated-property.js +280 -0
  7. package/dist/lib/rendering/cesium-animated-property.js.map +1 -0
  8. package/dist/lib/rendering/entity-render-engine.js +660 -278
  9. package/dist/lib/rendering/entity-render-engine.js.map +1 -1
  10. package/dist/lib/rendering/getters/entity-filter-getter.js +69 -2
  11. package/dist/lib/rendering/getters/entity-filter-getter.js.map +1 -1
  12. package/dist/lib/rendering/render-managers/common/shared-getters.js +2 -1
  13. package/dist/lib/rendering/render-managers/common/shared-getters.js.map +1 -1
  14. package/dist/lib/rendering/render-managers/entities/entities-render-manager.js +37 -20
  15. package/dist/lib/rendering/render-managers/entities/entities-render-manager.js.map +1 -1
  16. package/dist/lib/rendering/tileset-render-engine.js +10 -0
  17. package/dist/lib/rendering/tileset-render-engine.js.map +1 -1
  18. package/dist/lib/rendering/visuals-register.js.map +1 -1
  19. package/dist/lib/utils/cesium-entity-styler.js +115 -5
  20. package/dist/lib/utils/cesium-entity-styler.js.map +1 -1
  21. package/dist/types/bruce-cesium.d.ts +1 -1
  22. package/dist/types/rendering/cesium-animated-property.d.ts +88 -0
  23. package/dist/types/rendering/entity-render-engine.d.ts +10 -1
  24. package/dist/types/rendering/getters/entity-filter-getter.d.ts +15 -1
  25. package/dist/types/rendering/render-managers/common/shared-getters.d.ts +1 -0
  26. package/dist/types/rendering/visuals-register.d.ts +2 -0
  27. package/dist/types/utils/cesium-entity-styler.d.ts +5 -0
  28. package/package.json +2 -2
@@ -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, SceneMode, Entity, Primitive, Cesium3DTileFeature, GeoJsonDataSource, ColorMaterialProperty, ConstantProperty, DistanceDisplayCondition, NearFarScalar, Model, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, 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, ClockRange, EllipsoidGeodesic, sampleTerrainMostDetailed, PolygonPipeline, BoundingSphere, GeometryInstance, ScreenSpaceEventHandler, ScreenSpaceEventType, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, CzmlDataSource, Quaternion, ConstantPositionProperty, Intersect } from 'cesium';
3
+ import { Cartographic, Cartesian2, Math as Math$1, Cartesian3, CallbackProperty, Color, HeightReference, Rectangle, JulianDate, DistanceDisplayCondition, NearFarScalar, Model, Entity, HorizontalOrigin, VerticalOrigin, ConstantProperty, ConstantPositionProperty, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, ColorMaterialProperty, HeadingPitchRoll, Transforms, ColorBlendMode, SceneMode, Primitive, Cesium3DTileFeature, GeoJsonDataSource, Cesium3DTileColorBlendMode, HeadingPitchRange, Ion, Cesium3DTileStyle, KmlDataSource, SceneTransforms, OrthographicFrustum, EasingFunction, Cesium3DTileset, Matrix4, Matrix3, IonResource, EllipsoidTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, CesiumTerrainProvider, CesiumInspector, defined, ClockRange, EllipsoidGeodesic, sampleTerrainMostDetailed, PolygonPipeline, BoundingSphere, GeometryInstance, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, ScreenSpaceEventHandler, ScreenSpaceEventType, CzmlDataSource, Quaternion, Intersect } from 'cesium';
4
4
 
5
5
  /*! *****************************************************************************
6
6
  Copyright (c) Microsoft Corporation. All rights reserved.
@@ -900,6 +900,282 @@ var DrawingUtils;
900
900
  DrawingUtils.RaisePos3d = RaisePos3d;
901
901
  })(DrawingUtils || (DrawingUtils = {}));
902
902
 
903
+ function getColor(viewer, obj) {
904
+ var value = null;
905
+ if (obj === null || obj === void 0 ? void 0 : obj.getValue) {
906
+ var date = viewer.scene.lastRenderTime;
907
+ if (!date) {
908
+ date = viewer.clock.currentTime;
909
+ }
910
+ value = obj.getValue(date);
911
+ }
912
+ else {
913
+ value = obj;
914
+ }
915
+ if (value && value instanceof ColorMaterialProperty) {
916
+ value = value.color;
917
+ }
918
+ return value;
919
+ }
920
+ function getNumber(viewer, obj) {
921
+ var value = null;
922
+ if (obj === null || obj === void 0 ? void 0 : obj.getValue) {
923
+ var date = viewer.scene.lastRenderTime;
924
+ if (!date) {
925
+ date = viewer.clock.currentTime;
926
+ }
927
+ value = obj.getValue(date);
928
+ }
929
+ else {
930
+ value = obj;
931
+ }
932
+ return value;
933
+ }
934
+ /**
935
+ * Returns if a given visual is alive and in the scene.
936
+ * @param viewer
937
+ * @param visual
938
+ * @returns
939
+ */
940
+ function isFeatureAlive(viewer, feature) {
941
+ if (!(viewer === null || viewer === void 0 ? void 0 : viewer.scene) || viewer.isDestroyed()) {
942
+ return false;
943
+ }
944
+ var cTileset = feature === null || feature === void 0 ? void 0 : feature.tileset;
945
+ if (!cTileset) {
946
+ return false;
947
+ }
948
+ if (cTileset.isDestroyed() || !viewer.scene.primitives.contains(cTileset)) {
949
+ return false;
950
+ }
951
+ return true;
952
+ }
953
+ var _lastMark = 0;
954
+ var generateMark = function () {
955
+ _lastMark += 1;
956
+ return _lastMark;
957
+ };
958
+ function setMark(color, mark) {
959
+ color["NEXTSPACE_PROPERTY_MARK"] = mark;
960
+ }
961
+ function assertColorMark(mark, color) {
962
+ return color["NEXTSPACE_PROPERTY_MARK"] == mark;
963
+ }
964
+ var CesiumAnimatedProperty;
965
+ (function (CesiumAnimatedProperty) {
966
+ /**
967
+ * Example:
968
+ * ```
969
+ * const myEntity = null; // Get an Entity from somewhere.
970
+ *
971
+ * const animateColor = new AnimateColor({
972
+ * viewer: viewer,
973
+ * color: Cesium.Color.RED,
974
+ * startColor: myEntity.model.color,
975
+ * type: "LINEAR",
976
+ * durationMs: 1000
977
+ * });
978
+ *
979
+ * myEntity.model.color = new Cesium.CallbackProperty(() => {
980
+ * return animateColor.GetValue();
981
+ * }, false);
982
+ * ```
983
+ */
984
+ var AnimateColor = /** @class */ (function () {
985
+ function AnimateColor(params) {
986
+ var _a;
987
+ this.viewer = params.viewer;
988
+ this.color = params.color;
989
+ this.durationMs = params.durationMs;
990
+ this.startColor = getColor(this.viewer, params.startColor);
991
+ if ((_a = this.startColor) === null || _a === void 0 ? void 0 : _a.clone) {
992
+ this.startColor = this.startColor.clone();
993
+ }
994
+ if (!this.startColor) {
995
+ this.startColor = Color.WHITE.clone();
996
+ console.warn("No start color provided. Using WHITE as start color. Animation may not work as expected.");
997
+ }
998
+ this.startTime = new Date();
999
+ }
1000
+ /**
1001
+ * Returns the calculated color at the provided time.
1002
+ * @returns
1003
+ */
1004
+ AnimateColor.prototype.GetColor = function () {
1005
+ var now = new Date();
1006
+ var elapsedMs = now.getTime() - this.startTime.getTime();
1007
+ // Animation over.
1008
+ if (elapsedMs >= this.durationMs) {
1009
+ return this.color;
1010
+ }
1011
+ try {
1012
+ var progress = elapsedMs / this.durationMs;
1013
+ return Color.lerp(this.startColor, this.color, progress, new Color());
1014
+ }
1015
+ catch (e) {
1016
+ console.error(e);
1017
+ }
1018
+ // Failed to calculate color.
1019
+ // We'll just return the target color.
1020
+ return this.color;
1021
+ };
1022
+ /**
1023
+ * Returns the calculated color as a material property.
1024
+ * @returns
1025
+ */
1026
+ AnimateColor.prototype.GetMaterial = function () {
1027
+ var color = this.GetColor();
1028
+ return new ColorMaterialProperty(color);
1029
+ };
1030
+ return AnimateColor;
1031
+ }());
1032
+ CesiumAnimatedProperty.AnimateColor = AnimateColor;
1033
+ var AnimateNumber = /** @class */ (function () {
1034
+ function AnimateNumber(params) {
1035
+ this.paused = false;
1036
+ this.paused = Boolean(params.startPaused);
1037
+ this.viewer = params.viewer;
1038
+ this.value = params.value;
1039
+ this.durationMs = params.durationMs;
1040
+ this.startValue = getNumber(this.viewer, params.startValue);
1041
+ if (!this.startValue) {
1042
+ this.startValue = 0;
1043
+ }
1044
+ if (!this.paused) {
1045
+ this.startTime = new Date();
1046
+ }
1047
+ }
1048
+ AnimateNumber.prototype.Play = function () {
1049
+ if (this.paused) {
1050
+ this.paused = false;
1051
+ this.startTime = new Date();
1052
+ }
1053
+ };
1054
+ AnimateNumber.prototype.GetValue = function () {
1055
+ if (this.paused) {
1056
+ return this.startValue;
1057
+ }
1058
+ var now = new Date();
1059
+ var elapsedMs = now.getTime() - this.startTime.getTime();
1060
+ // Animation over.
1061
+ if (elapsedMs >= this.durationMs) {
1062
+ return this.value;
1063
+ }
1064
+ try {
1065
+ var progress = elapsedMs / this.durationMs;
1066
+ return Math$1.lerp(this.startValue, this.value, progress);
1067
+ }
1068
+ catch (e) {
1069
+ console.error(e);
1070
+ }
1071
+ // Failed to calculate value.
1072
+ // We'll just return the target value.
1073
+ return this.value;
1074
+ };
1075
+ return AnimateNumber;
1076
+ }());
1077
+ CesiumAnimatedProperty.AnimateNumber = AnimateNumber;
1078
+ /**
1079
+ * Animates the color of a feature.
1080
+ * This is handled separately from the AnimateColor class as Tileset features do not support Cesium callback properties.
1081
+ *
1082
+ * Example:
1083
+ * ```
1084
+ * const animateColor = AnimateTFeatureColor({
1085
+ * viewer: viewer,
1086
+ * feature: feature,
1087
+ * color: Cesium.Color.RED,
1088
+ * startColor: feature.color,
1089
+ * durationMs: 1000
1090
+ * });
1091
+ * ```
1092
+ * @param params
1093
+ * @returns
1094
+ */
1095
+ function AnimateTFeatureColor(params) {
1096
+ var viewer = params.viewer, feature = params.feature, color = params.color, startColor = params.startColor, durationMs = params.durationMs;
1097
+ ClearTFeatureColorAnimation(feature);
1098
+ if (!startColor) {
1099
+ if (feature.color) {
1100
+ startColor = feature.color;
1101
+ if (startColor.clone) {
1102
+ startColor = startColor.clone();
1103
+ }
1104
+ }
1105
+ else {
1106
+ startColor = Color.WHITE.clone();
1107
+ }
1108
+ }
1109
+ // Don't animate if the colour is the same.
1110
+ var curColor = getColor(viewer, feature.color);
1111
+ if (curColor && Color.WHITE.equals(curColor)) {
1112
+ curColor = null;
1113
+ }
1114
+ var colorTmp = color == null || Color.WHITE.equals(color) ? null : color;
1115
+ if (!curColor && !colorTmp) {
1116
+ return function () { };
1117
+ }
1118
+ else if (curColor && colorTmp && curColor.equals(colorTmp)) {
1119
+ return function () { };
1120
+ }
1121
+ // Marks are used to detect external changes to the feature's color.
1122
+ // If an external change is detected, the animation will stop.
1123
+ var mark = generateMark();
1124
+ setMark(feature.color, mark);
1125
+ setMark(startColor, mark);
1126
+ setMark(color, mark);
1127
+ var startTime = new Date();
1128
+ var removal = viewer.scene.postUpdate.addEventListener(function () {
1129
+ if (!isFeatureAlive(viewer, feature)) {
1130
+ removal === null || removal === void 0 ? void 0 : removal();
1131
+ removal = null;
1132
+ return;
1133
+ }
1134
+ if (!assertColorMark(mark, feature.color)) {
1135
+ removal === null || removal === void 0 ? void 0 : removal();
1136
+ removal = null;
1137
+ return;
1138
+ }
1139
+ var now = new Date();
1140
+ var elapsedMs = now.getTime() - startTime.getTime();
1141
+ // Animation over.
1142
+ if (elapsedMs >= durationMs) {
1143
+ feature.color = color;
1144
+ removal === null || removal === void 0 ? void 0 : removal();
1145
+ removal = null;
1146
+ return;
1147
+ }
1148
+ try {
1149
+ var progress = elapsedMs / durationMs;
1150
+ var newColor = Color.lerp(startColor, color, progress, new Color());
1151
+ setMark(newColor, mark);
1152
+ feature.color = newColor;
1153
+ return;
1154
+ }
1155
+ catch (e) {
1156
+ console.error(e);
1157
+ }
1158
+ // Failed to calculate color.
1159
+ // We'll just set the target color and stop the animation.
1160
+ feature.color = color;
1161
+ });
1162
+ // Return a function to stop the animation.
1163
+ feature["ANIMATED_COLOR_REMOVAL"] = removal;
1164
+ return function () {
1165
+ removal === null || removal === void 0 ? void 0 : removal();
1166
+ removal = null;
1167
+ };
1168
+ }
1169
+ CesiumAnimatedProperty.AnimateTFeatureColor = AnimateTFeatureColor;
1170
+ function ClearTFeatureColorAnimation(feature) {
1171
+ if (feature && feature["ANIMATED_COLOR_REMOVAL"]) {
1172
+ feature["ANIMATED_COLOR_REMOVAL"]();
1173
+ feature["ANIMATED_COLOR_REMOVAL"] = null;
1174
+ }
1175
+ }
1176
+ CesiumAnimatedProperty.ClearTFeatureColorAnimation = ClearTFeatureColorAnimation;
1177
+ })(CesiumAnimatedProperty || (CesiumAnimatedProperty = {}));
1178
+
903
1179
  /**
904
1180
  * Returns if a given visual can be styled by this utility.
905
1181
  * @param viewer
@@ -1020,7 +1296,7 @@ function storeColor(viewer, key, color, graphic) {
1020
1296
  * @param graphic
1021
1297
  * @returns
1022
1298
  */
1023
- function getColor(viewer, key, graphic) {
1299
+ function getColor$1(viewer, key, graphic) {
1024
1300
  var color = graphic[getStoreKey(key)];
1025
1301
  // If no color is stored for the default color, we'll calculate and store it.
1026
1302
  if (!color) {
@@ -1050,6 +1326,8 @@ function getColor(viewer, key, graphic) {
1050
1326
  function applyOpacity(viewer, opacity, graphic) {
1051
1327
  refreshColor(viewer, graphic, opacity);
1052
1328
  }
1329
+ var ANIMATE_COLOR_MS = 200;
1330
+ var ANIMATE_COLOR_HIGHLIGHT_MS = 200;
1053
1331
  /**
1054
1332
  * Applies a color to a graphic based on the current key states.
1055
1333
  * Eg: if the graphic is selected, it will apply the selected color.
@@ -1058,7 +1336,7 @@ function applyOpacity(viewer, opacity, graphic) {
1058
1336
  * @param opacity
1059
1337
  */
1060
1338
  function refreshColor(viewer, graphic, opacity) {
1061
- var _a;
1339
+ var _a, _b;
1062
1340
  // Calculate what color key we should apply.
1063
1341
  var key = "default";
1064
1342
  if (getKeyState(graphic, "select")) {
@@ -1069,11 +1347,12 @@ function refreshColor(viewer, graphic, opacity) {
1069
1347
  }
1070
1348
  // This ensures that the default color is always stored prior to applying a new color.
1071
1349
  if (key != "default") {
1072
- getColor(viewer, "default", graphic);
1350
+ getColor$1(viewer, "default", graphic);
1073
1351
  }
1074
- var color = (_a = getColor(viewer, key, graphic)) !== null && _a !== void 0 ? _a : Color.WHITE;
1352
+ var color = (_a = getColor$1(viewer, key, graphic)) !== null && _a !== void 0 ? _a : Color.WHITE;
1075
1353
  // If we're highlighting and it's selected, don't change the color.
1076
1354
  if (key != "highlight" || getKeyState(graphic, "select") == false) {
1355
+ var animateMs = key == "highlight" ? ANIMATE_COLOR_HIGHLIGHT_MS : ANIMATE_COLOR_MS;
1077
1356
  color = color.clone();
1078
1357
  // Multiply opacity if one is set.
1079
1358
  if (opacity != null) {
@@ -1089,10 +1368,34 @@ function refreshColor(viewer, graphic, opacity) {
1089
1368
  }
1090
1369
  }
1091
1370
  if (graphic instanceof Cesium3DTileFeature) {
1092
- graphic.color = color;
1371
+ CesiumAnimatedProperty.ClearTFeatureColorAnimation(graphic);
1372
+ if (key == "default") {
1373
+ graphic.color = color;
1374
+ }
1375
+ else {
1376
+ CesiumAnimatedProperty.AnimateTFeatureColor({
1377
+ color: color.clone(),
1378
+ durationMs: animateMs,
1379
+ feature: graphic,
1380
+ viewer: viewer,
1381
+ startColor: ((_b = graphic.color) === null || _b === void 0 ? void 0 : _b.clone) ? graphic.color.clone() : graphic.color
1382
+ });
1383
+ }
1093
1384
  }
1094
1385
  else if (graphic instanceof ModelGraphics) {
1095
- graphic.color = new ConstantProperty(color);
1386
+ // graphic.color = new Cesium.ConstantProperty(color);
1387
+ var animateColor_1 = new CesiumAnimatedProperty.AnimateColor({
1388
+ color: color,
1389
+ durationMs: animateMs,
1390
+ viewer: viewer,
1391
+ startColor: graphic.color
1392
+ });
1393
+ if (graphic.color instanceof CallbackProperty) {
1394
+ graphic.color.setCallback(function () { return animateColor_1.GetColor(); }, false);
1395
+ }
1396
+ else {
1397
+ graphic.color = new CallbackProperty(function () { return animateColor_1.GetColor(); }, false);
1398
+ }
1096
1399
  }
1097
1400
  else if (graphic instanceof PolygonGraphics) {
1098
1401
  graphic.material = new ColorMaterialProperty(color);
@@ -1104,10 +1407,34 @@ function refreshColor(viewer, graphic, opacity) {
1104
1407
  graphic.material = new ColorMaterialProperty(color);
1105
1408
  }
1106
1409
  else if (graphic instanceof PointGraphics) {
1107
- graphic.color = new ConstantProperty(color);
1410
+ // graphic.color = new Cesium.ConstantProperty(color);
1411
+ var animateColor_2 = new CesiumAnimatedProperty.AnimateColor({
1412
+ color: color,
1413
+ durationMs: animateMs,
1414
+ viewer: viewer,
1415
+ startColor: graphic.color
1416
+ });
1417
+ if (graphic.color instanceof CallbackProperty) {
1418
+ graphic.color.setCallback(function () { return animateColor_2.GetColor(); }, false);
1419
+ }
1420
+ else {
1421
+ graphic.color = new CallbackProperty(function () { return animateColor_2.GetColor(); }, false);
1422
+ }
1108
1423
  }
1109
1424
  else if (graphic instanceof BillboardGraphics) {
1110
- graphic.color = new ConstantProperty(color);
1425
+ // graphic.color = new Cesium.ConstantProperty(color);
1426
+ var animateColor_3 = new CesiumAnimatedProperty.AnimateColor({
1427
+ color: color,
1428
+ durationMs: animateMs,
1429
+ viewer: viewer,
1430
+ startColor: graphic.color
1431
+ });
1432
+ if (graphic.color instanceof CallbackProperty) {
1433
+ graphic.color.setCallback(function () { return animateColor_3.GetColor(); }, false);
1434
+ }
1435
+ else {
1436
+ graphic.color = new CallbackProperty(function () { return animateColor_3.GetColor(); }, false);
1437
+ }
1111
1438
  }
1112
1439
  else if (graphic instanceof EllipseGraphics) {
1113
1440
  graphic.material = new ColorMaterialProperty(color);
@@ -1208,6 +1535,64 @@ var CesiumEntityStyler;
1208
1535
  }
1209
1536
  }
1210
1537
  CesiumEntityStyler.Refresh = Refresh;
1538
+ function BakeDefaultColor(params) {
1539
+ var viewer = params.viewer, entity = params.entity, override = params.override;
1540
+ if (!entity) {
1541
+ return;
1542
+ }
1543
+ var parts = EntityUtils.GatherEntity({
1544
+ entity: entity
1545
+ });
1546
+ for (var i = 0; i < parts.length; i++) {
1547
+ var part = parts[i];
1548
+ if (!isAlive(viewer, part)) {
1549
+ continue;
1550
+ }
1551
+ // If we're not overriding then we check to ensure a colour is not already set.
1552
+ if (override == false) {
1553
+ var stored = part[getStoreKey("default")];
1554
+ if (stored) {
1555
+ continue;
1556
+ }
1557
+ }
1558
+ if (part instanceof Cesium3DTileFeature) {
1559
+ var opacity = getAppliedOpacity(part);
1560
+ storeColor(viewer, "default", calculateCurColor(viewer, part), part);
1561
+ refreshColor(viewer, part, opacity);
1562
+ }
1563
+ else if (part instanceof Entity) {
1564
+ if (part.billboard) {
1565
+ storeColor(viewer, "default", calculateCurColor(viewer, part.billboard), part.billboard);
1566
+ refreshColor(viewer, part.billboard, getAppliedOpacity(part.billboard));
1567
+ }
1568
+ if (part.model) {
1569
+ storeColor(viewer, "default", calculateCurColor(viewer, part.model), part.model);
1570
+ refreshColor(viewer, part.model, getAppliedOpacity(part.model));
1571
+ }
1572
+ if (part.polyline) {
1573
+ storeColor(viewer, "default", calculateCurColor(viewer, part.polyline), part.polyline);
1574
+ refreshColor(viewer, part.polyline, getAppliedOpacity(part.polyline));
1575
+ }
1576
+ if (part.polygon) {
1577
+ storeColor(viewer, "default", calculateCurColor(viewer, part.polygon), part.polygon);
1578
+ refreshColor(viewer, part.polygon, getAppliedOpacity(part.polygon));
1579
+ }
1580
+ if (part.corridor) {
1581
+ storeColor(viewer, "default", calculateCurColor(viewer, part.corridor), part.corridor);
1582
+ refreshColor(viewer, part.corridor, getAppliedOpacity(part.corridor));
1583
+ }
1584
+ if (part.point) {
1585
+ storeColor(viewer, "default", calculateCurColor(viewer, part.point), part.point);
1586
+ refreshColor(viewer, part.point, getAppliedOpacity(part.point));
1587
+ }
1588
+ if (part.ellipse) {
1589
+ storeColor(viewer, "default", calculateCurColor(viewer, part.ellipse), part.ellipse);
1590
+ refreshColor(viewer, part.ellipse, getAppliedOpacity(part.ellipse));
1591
+ }
1592
+ }
1593
+ }
1594
+ }
1595
+ CesiumEntityStyler.BakeDefaultColor = BakeDefaultColor;
1211
1596
  /**
1212
1597
  * Updates the default colour of a graphic.
1213
1598
  * This will not change the graphic's state to use it if the entity is selected/highlighted.
@@ -4257,7 +4642,7 @@ var POINT_BILLBOARD_PADDING = 1;
4257
4642
  var createCircleBillboard = function (size, colorCss) {
4258
4643
  var key = size + "-" + colorCss;
4259
4644
  var cacheData = _billboardCache.Get(key);
4260
- if ((cacheData === null || cacheData === void 0 ? void 0 : cacheData.canvas) instanceof HTMLCanvasElement) {
4645
+ if ((cacheData === null || cacheData === void 0 ? void 0 : cacheData.canvasDataUri) && typeof (cacheData === null || cacheData === void 0 ? void 0 : cacheData.canvasDataUri) == "string") {
4261
4646
  return cacheData;
4262
4647
  }
4263
4648
  // Slight padding to avoid corners clipping.
@@ -4271,7 +4656,7 @@ var createCircleBillboard = function (size, colorCss) {
4271
4656
  context.fillStyle = colorCss;
4272
4657
  context.fill();
4273
4658
  var data = {
4274
- canvas: canvas,
4659
+ canvasDataUri: canvas.toDataURL("image/png"),
4275
4660
  colorCss: colorCss,
4276
4661
  size: size,
4277
4662
  height: canvasSize,
@@ -4306,7 +4691,7 @@ var createImageBillboard = function (url) {
4306
4691
  var context = canvas_1.getContext("2d");
4307
4692
  context.drawImage(image_1, 0, 0);
4308
4693
  var data = {
4309
- canvas: canvas_1,
4694
+ canvasDataUri: canvas_1.toDataURL("image/png"),
4310
4695
  height: image_1.height
4311
4696
  };
4312
4697
  res(data);
@@ -4422,11 +4807,11 @@ function extractMetadataFromFileUrl(url) {
4422
4807
  var EntityRenderEngine;
4423
4808
  (function (EntityRenderEngine) {
4424
4809
  function Render(params) {
4425
- var _a, _b, _c, _d, _e, _f, _g, _h;
4810
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
4426
4811
  return __awaiter(this, void 0, void 0, function () {
4427
- var groupRenderParams, i, entity, geometry, cEntities, models, multiGeometry, polygons, polylines, points, i, entity, id, zoomItem, displayType, newRenderId, existingRego, oldRenderId, mParams, mEntities, i, entity, id, cEntity, _loop_1, i, pParams, pEntities, i, entity, cEntity, pParams, pEntities, i, entity, cEntity, pParams, pEntities, i, entity, cEntity;
4428
- return __generator(this, function (_j) {
4429
- switch (_j.label) {
4812
+ var groupRenderParams, i, entity, geometry, cEntities, models, multiGeometry, polygons, polylines, points, i, entity, id, zoomItem, displayType, existingRego, newRenderId, oldRenderId, mParams, mEntities, i, entity, id, cEntity, _loop_1, i, pParams, pEntities, i, entity, cEntity, pParams, pEntities, i, entity, cEntity, pParams, pEntities, i, entity, cEntity;
4813
+ return __generator(this, function (_m) {
4814
+ switch (_m.label) {
4430
4815
  case 0:
4431
4816
  groupRenderParams = {
4432
4817
  apiGetter: params.apiGetter,
@@ -4468,21 +4853,36 @@ var EntityRenderEngine;
4468
4853
  displayType = ZoomControl.EDisplayType.Geometry;
4469
4854
  }
4470
4855
  if (displayType != ZoomControl.EDisplayType.Hidden) {
4471
- newRenderId = getRenderGroupId(zoomItem, (_b = params.viewer) === null || _b === void 0 ? void 0 : _b.terrainProvider);
4472
4856
  existingRego = params.visualRegister.GetRego({
4473
4857
  entityId: id,
4474
4858
  menuItemId: params.menuItemId
4475
4859
  });
4860
+ newRenderId = getRenderGroupId(zoomItem, (_b = params.viewer) === null || _b === void 0 ? void 0 : _b.terrainProvider);
4476
4861
  oldRenderId = (_c = existingRego === null || existingRego === void 0 ? void 0 : existingRego.visual) === null || _c === void 0 ? void 0 : _c._renderGroup;
4477
- if (!params.force && newRenderId == oldRenderId && !(existingRego === null || existingRego === void 0 ? void 0 : existingRego.stale)) {
4862
+ if (!params.force &&
4863
+ newRenderId == oldRenderId &&
4864
+ !(existingRego === null || existingRego === void 0 ? void 0 : existingRego.stale) &&
4865
+ // If historic metadata is different then it's also stale.
4866
+ ((existingRego === null || existingRego === void 0 ? void 0 : existingRego.historicDateTime) == ((_d = entity.Bruce) === null || _d === void 0 ? void 0 : _d.historicDateTime))) {
4867
+ // No sorting category needed. Already rendered the way we want.
4478
4868
  cEntities[id] = existingRego.visual;
4479
4869
  }
4480
4870
  else {
4871
+ // Add so we can re-use the graphic and update it.
4872
+ if (existingRego && newRenderId == oldRenderId) {
4873
+ cEntities[id] = existingRego.visual;
4874
+ // Flag as no longer stale as we're unlikely to recreate the rego if we're reusing the graphic.
4875
+ existingRego.stale = false;
4876
+ // Update metadata for the same reason.
4877
+ existingRego.historicDateTime = (_e = entity.Bruce) === null || _e === void 0 ? void 0 : _e.historicDateTime;
4878
+ existingRego.historicAttrKey = (_f = entity.Bruce) === null || _f === void 0 ? void 0 : _f.historicAttrKey;
4879
+ existingRego.entityTypeId = entity.Bruce["EntityType.ID"];
4880
+ }
4481
4881
  if (displayType == ZoomControl.EDisplayType.Model3D) {
4482
4882
  models.push(entity);
4483
4883
  }
4484
4884
  else if (displayType == ZoomControl.EDisplayType.Geometry) {
4485
- if ((_e = (_d = entity.geometry) === null || _d === void 0 ? void 0 : _d.MultiGeometry) === null || _e === void 0 ? void 0 : _e.length) {
4885
+ if ((_h = (_g = entity.geometry) === null || _g === void 0 ? void 0 : _g.MultiGeometry) === null || _h === void 0 ? void 0 : _h.length) {
4486
4886
  multiGeometry.push(entity);
4487
4887
  }
4488
4888
  else {
@@ -4497,10 +4897,10 @@ var EntityRenderEngine;
4497
4897
  }
4498
4898
  }
4499
4899
  if (!(models.length > 0)) return [3 /*break*/, 2];
4500
- mParams = __assign(__assign({}, groupRenderParams), { entities: models });
4900
+ mParams = __assign(__assign({}, groupRenderParams), { rendered: cEntities, entities: models });
4501
4901
  return [4 /*yield*/, Model3d.RenderGroup(mParams)];
4502
4902
  case 1:
4503
- mEntities = _j.sent();
4903
+ mEntities = _m.sent();
4504
4904
  for (i = 0; i < mParams.entities.length; i++) {
4505
4905
  entity = mParams.entities[i];
4506
4906
  id = entity.Bruce.ID;
@@ -4512,20 +4912,20 @@ var EntityRenderEngine;
4512
4912
  multiGeometry.push(entity);
4513
4913
  }
4514
4914
  }
4515
- _j.label = 2;
4915
+ _m.label = 2;
4516
4916
  case 2:
4517
4917
  if (!(multiGeometry.length > 0)) return [3 /*break*/, 6];
4518
4918
  _loop_1 = function (i) {
4519
4919
  var entity, pParams, zoomItem, j, subEntity, cPoly, rendered, cLines, cPoints, rootEntity_1, firstEntity;
4520
- return __generator(this, function (_k) {
4521
- switch (_k.label) {
4920
+ return __generator(this, function (_o) {
4921
+ switch (_o.label) {
4522
4922
  case 0:
4523
4923
  entity = multiGeometry[i];
4524
- if (!((_g = (_f = entity.geometry) === null || _f === void 0 ? void 0 : _f.MultiGeometry) === null || _g === void 0 ? void 0 : _g.length)) {
4924
+ if (!((_k = (_j = entity.geometry) === null || _j === void 0 ? void 0 : _j.MultiGeometry) === null || _k === void 0 ? void 0 : _k.length)) {
4525
4925
  polygons.push(entity);
4526
4926
  return [2 /*return*/, "continue"];
4527
4927
  }
4528
- pParams = __assign(__assign({}, groupRenderParams), { entities: [] });
4928
+ pParams = __assign(__assign({}, groupRenderParams), { entities: [], rendered: cEntities });
4529
4929
  zoomItem = pParams.zoomItems[entity.Bruce.ID];
4530
4930
  for (j = 0; j < entity.geometry.MultiGeometry.length; j++) {
4531
4931
  subEntity = __assign(__assign({}, entity), { geometry: entity.geometry.MultiGeometry[j], Bruce: __assign(__assign({}, entity.Bruce), { ID: ObjectUtils.UId() }) });
@@ -4534,7 +4934,7 @@ var EntityRenderEngine;
4534
4934
  }
4535
4935
  return [4 /*yield*/, Polygon.RenderGroup(pParams)];
4536
4936
  case 1:
4537
- cPoly = _k.sent();
4937
+ cPoly = _o.sent();
4538
4938
  Object.keys(cPoly).forEach(function (key) {
4539
4939
  if (cPoly[key]) {
4540
4940
  pParams.entities = pParams.entities.filter(function (e) { return e.Bruce.ID != key; });
@@ -4543,7 +4943,7 @@ var EntityRenderEngine;
4543
4943
  rendered = Object.values(cPoly);
4544
4944
  return [4 /*yield*/, Polyline.RenderGroup(pParams)];
4545
4945
  case 2:
4546
- cLines = _k.sent();
4946
+ cLines = _o.sent();
4547
4947
  Object.keys(cLines).forEach(function (key) {
4548
4948
  if (cLines[key]) {
4549
4949
  pParams.entities = pParams.entities.filter(function (e) { return e.Bruce.ID != key; });
@@ -4553,9 +4953,9 @@ var EntityRenderEngine;
4553
4953
  if (!!rendered.length) return [3 /*break*/, 4];
4554
4954
  return [4 /*yield*/, Point.RenderGroup(pParams)];
4555
4955
  case 3:
4556
- cPoints = _k.sent();
4956
+ cPoints = _o.sent();
4557
4957
  rendered = rendered.concat(Object.values(cPoints));
4558
- _k.label = 4;
4958
+ _o.label = 4;
4559
4959
  case 4:
4560
4960
  rendered = rendered.filter(function (x) { return x != null; });
4561
4961
  if (rendered.length) {
@@ -4563,7 +4963,7 @@ var EntityRenderEngine;
4563
4963
  id: ObjectUtils.UId(10)
4564
4964
  });
4565
4965
  rootEntity_1._siblingGraphics = [];
4566
- rootEntity_1._renderGroup = getRenderGroupId(zoomItem, (_h = params.viewer) === null || _h === void 0 ? void 0 : _h.terrainProvider);
4966
+ rootEntity_1._renderGroup = getRenderGroupId(zoomItem, (_l = params.viewer) === null || _l === void 0 ? void 0 : _l.terrainProvider);
4567
4967
  rootEntity_1._siblingGraphics = rootEntity_1._siblingGraphics.concat(rendered);
4568
4968
  cEntities[entity.Bruce.ID] = rootEntity_1;
4569
4969
  firstEntity = rendered[0];
@@ -4582,22 +4982,22 @@ var EntityRenderEngine;
4582
4982
  });
4583
4983
  };
4584
4984
  i = 0;
4585
- _j.label = 3;
4985
+ _m.label = 3;
4586
4986
  case 3:
4587
4987
  if (!(i < multiGeometry.length)) return [3 /*break*/, 6];
4588
4988
  return [5 /*yield**/, _loop_1(i)];
4589
4989
  case 4:
4590
- _j.sent();
4591
- _j.label = 5;
4990
+ _m.sent();
4991
+ _m.label = 5;
4592
4992
  case 5:
4593
4993
  i++;
4594
4994
  return [3 /*break*/, 3];
4595
4995
  case 6:
4596
4996
  if (!(polygons.length > 0)) return [3 /*break*/, 8];
4597
- pParams = __assign(__assign({}, groupRenderParams), { entities: polygons });
4997
+ pParams = __assign(__assign({}, groupRenderParams), { entities: polygons, rendered: cEntities });
4598
4998
  return [4 /*yield*/, Polygon.RenderGroup(pParams)];
4599
4999
  case 7:
4600
- pEntities = _j.sent();
5000
+ pEntities = _m.sent();
4601
5001
  for (i = 0; i < pParams.entities.length; i++) {
4602
5002
  entity = pParams.entities[i];
4603
5003
  cEntity = pEntities[entity.Bruce.ID];
@@ -4608,13 +5008,13 @@ var EntityRenderEngine;
4608
5008
  polylines.push(entity);
4609
5009
  }
4610
5010
  }
4611
- _j.label = 8;
5011
+ _m.label = 8;
4612
5012
  case 8:
4613
5013
  if (!(polylines.length > 0)) return [3 /*break*/, 10];
4614
- pParams = __assign(__assign({}, groupRenderParams), { entities: polylines });
5014
+ pParams = __assign(__assign({}, groupRenderParams), { entities: polylines, rendered: cEntities });
4615
5015
  return [4 /*yield*/, Polyline.RenderGroup(pParams)];
4616
5016
  case 9:
4617
- pEntities = _j.sent();
5017
+ pEntities = _m.sent();
4618
5018
  for (i = 0; i < pParams.entities.length; i++) {
4619
5019
  entity = pParams.entities[i];
4620
5020
  cEntity = pEntities[entity.Bruce.ID];
@@ -4625,13 +5025,13 @@ var EntityRenderEngine;
4625
5025
  points.push(entity);
4626
5026
  }
4627
5027
  }
4628
- _j.label = 10;
5028
+ _m.label = 10;
4629
5029
  case 10:
4630
5030
  if (!(points.length > 0)) return [3 /*break*/, 12];
4631
- pParams = __assign(__assign({}, groupRenderParams), { entities: points });
5031
+ pParams = __assign(__assign({}, groupRenderParams), { entities: points, rendered: cEntities });
4632
5032
  return [4 /*yield*/, Point.RenderGroup(pParams)];
4633
5033
  case 11:
4634
- pEntities = _j.sent();
5034
+ pEntities = _m.sent();
4635
5035
  for (i = 0; i < pParams.entities.length; i++) {
4636
5036
  entity = pParams.entities[i];
4637
5037
  cEntity = pEntities[entity.Bruce.ID];
@@ -4639,7 +5039,7 @@ var EntityRenderEngine;
4639
5039
  cEntities[entity.Bruce.ID] = cEntity;
4640
5040
  }
4641
5041
  }
4642
- _j.label = 12;
5042
+ _m.label = 12;
4643
5043
  case 12: return [2 /*return*/, cEntities];
4644
5044
  }
4645
5045
  });
@@ -4692,11 +5092,11 @@ var EntityRenderEngine;
4692
5092
  }
4693
5093
  Point.CreateCircleBillboard = CreateCircleBillboard;
4694
5094
  function Render(params) {
4695
- var _a, _b;
5095
+ var _a, _b, _c, _d;
4696
5096
  return __awaiter(this, void 0, void 0, function () {
4697
- var entity, style, type, cEntity, siblings, iconUrlRows, icon, iconUrl, metadata, api, image, e_5, iconScale, disableDepthTest, bColor, cColor, heightRef, radius, bFill, cFill, outline, cOutline, outlineWidth, bOutline, heightRef, pos3d, extrusion, outlineExtrusion, bColor, cColor, size, heightRef, circleBillboard, disableDepthTest;
4698
- return __generator(this, function (_c) {
4699
- switch (_c.label) {
5097
+ var entity, style, type, cEntity, siblings, prepareExistingGraphic, iconUrlRows, icon, iconUrl, metadata, api, image, e_5, iconScale, disableDepthTest, bColor, cColor_1, heightRef, currentImgKey, radius, bFill, cFill, outline, cOutline, outlineWidth, bOutline, heightRef, pos3d, extrusion, hasOutline, outlineExtrusion, outlineEntity, bColor, cColor, size, heightRef, circleBillboard, disableDepthTest, imgKey, currentImgKey;
5098
+ return __generator(this, function (_e) {
5099
+ switch (_e.label) {
4700
5100
  case 0:
4701
5101
  entity = params.entity;
4702
5102
  style = params.style;
@@ -4709,6 +5109,27 @@ var EntityRenderEngine;
4709
5109
  }
4710
5110
  cEntity = null;
4711
5111
  siblings = [];
5112
+ prepareExistingGraphic = function (cEntity, siblings) {
5113
+ if (siblings === void 0) { siblings = 0; }
5114
+ // Gather entity in case previous version had sibling graphics we no longer need.
5115
+ var parts = EntityUtils.GatherEntity({
5116
+ entity: cEntity,
5117
+ });
5118
+ if (parts.length > 1) {
5119
+ // We'll cull all except the allowed number of siblings.
5120
+ cEntity._siblingGraphics = cEntity._siblingGraphics.slice(0, siblings);
5121
+ // We'll remove all that aren't in the allowed (direct) list.
5122
+ for (var i = 0; i < parts.length - 1; i++) {
5123
+ var part = parts[i];
5124
+ if (part && part instanceof Entity && params.viewer.entities.contains(part) && !cEntity._siblingGraphics.includes(part)) {
5125
+ params.viewer.entities.remove(part);
5126
+ }
5127
+ }
5128
+ if (cEntity._parentEntity) {
5129
+ console.warn("Point.Render: Parent entity was not null. This should not happen.");
5130
+ }
5131
+ }
5132
+ };
4712
5133
  if (!(type == Style.EPointType.Icon)) return [3 /*break*/, 9];
4713
5134
  iconUrlRows = style.iconUrl == null ? [] : style.iconUrl;
4714
5135
  iconUrlRows.forEach(function (row) {
@@ -4725,36 +5146,36 @@ var EntityRenderEngine;
4725
5146
  api = params.apiGetter.getApi(metadata.accountId);
4726
5147
  return [4 /*yield*/, api.Loading];
4727
5148
  case 1:
4728
- _c.sent();
5149
+ _e.sent();
4729
5150
  iconUrl = ClientFile.GetUrl({
4730
5151
  api: api,
4731
5152
  fileId: metadata.fileId,
4732
5153
  viaCdn: true
4733
5154
  });
4734
- _c.label = 2;
5155
+ _e.label = 2;
4735
5156
  case 2:
4736
5157
  if (!(!iconUrl && style.iconId)) return [3 /*break*/, 4];
4737
5158
  return [4 /*yield*/, params.api.Loading];
4738
5159
  case 3:
4739
- _c.sent();
5160
+ _e.sent();
4740
5161
  iconUrl = ClientFile.GetUrl({
4741
5162
  api: params.api,
4742
5163
  fileId: style.iconId,
4743
5164
  viaCdn: true
4744
5165
  });
4745
- _c.label = 4;
5166
+ _e.label = 4;
4746
5167
  case 4:
4747
5168
  image = null;
4748
5169
  if (!iconUrl) return [3 /*break*/, 8];
4749
- _c.label = 5;
5170
+ _e.label = 5;
4750
5171
  case 5:
4751
- _c.trys.push([5, 7, , 8]);
5172
+ _e.trys.push([5, 7, , 8]);
4752
5173
  return [4 /*yield*/, createImageBillboard(iconUrl)];
4753
5174
  case 6:
4754
- image = _c.sent();
5175
+ image = _e.sent();
4755
5176
  return [3 /*break*/, 8];
4756
5177
  case 7:
4757
- e_5 = _c.sent();
5178
+ e_5 = _e.sent();
4758
5179
  // Expanding the logging here so we can figure out why this is happening.
4759
5180
  // Most of the time the file is missing but we're getting some strange errors so I am including logging on the API settings as well.
4760
5181
  OneTimeError("ENTITY_RENDER_ENGINE_ICON_URL_ERROR_" + iconUrl, {
@@ -4773,34 +5194,64 @@ var EntityRenderEngine;
4773
5194
  disableDepthTest = Boolean(style.renderOnTop);
4774
5195
  if (iconScale > 0) {
4775
5196
  bColor = style.iconTintColor ? Calculator.GetColor(style.iconTintColor, entity, params.tags) : null;
4776
- cColor = bColor ? colorToCColor(bColor) : undefined;
5197
+ cColor_1 = bColor ? colorToCColor(bColor) : undefined;
4777
5198
  heightRef = getHeightRef(style);
4778
- cEntity = new Entity({
4779
- id: ObjectUtils.UId(10),
4780
- billboard: {
4781
- horizontalOrigin: HorizontalOrigin.CENTER,
4782
- verticalOrigin: VerticalOrigin.BOTTOM,
4783
- image: image.canvas,
4784
- heightReference: getHeightRef(style),
4785
- scale: iconScale,
4786
- disableDepthTestDistance: disableDepthTest ? Number.POSITIVE_INFINITY : undefined,
4787
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance),
4788
- color: cColor
4789
- // Would be great once we have a setting for this.
4790
- // translucencyByDistance: getTranslucencyByDistance(params.minDistance, params.maxDistance),
4791
- },
4792
- position: EntityUtils.GetPos({
5199
+ if (!params.rendered || !params.rendered.billboard) {
5200
+ cEntity = new Entity({
5201
+ id: ObjectUtils.UId(10),
5202
+ billboard: {
5203
+ horizontalOrigin: HorizontalOrigin.CENTER,
5204
+ verticalOrigin: VerticalOrigin.BOTTOM,
5205
+ image: image.canvasDataUri,
5206
+ heightReference: getHeightRef(style),
5207
+ scale: iconScale,
5208
+ disableDepthTestDistance: disableDepthTest ? Number.POSITIVE_INFINITY : undefined,
5209
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance),
5210
+ color: new CallbackProperty(function () { return cColor_1; }, true),
5211
+ // Would be great once we have a setting for this.
5212
+ // translucencyByDistance: getTranslucencyByDistance(params.minDistance, params.maxDistance),
5213
+ },
5214
+ position: EntityUtils.GetPos({
5215
+ viewer: params.viewer,
5216
+ entity: entity,
5217
+ recordHeightRef: heightRef,
5218
+ returnHeightRef: heightRef
5219
+ }),
5220
+ show: true
5221
+ });
5222
+ }
5223
+ else {
5224
+ prepareExistingGraphic(params.rendered);
5225
+ cEntity = params.rendered;
5226
+ currentImgKey = cEntity.billboard._billboardImgKey;
5227
+ if (currentImgKey != iconUrl) {
5228
+ cEntity.billboard.image = new ConstantProperty(image.canvasDataUri);
5229
+ }
5230
+ cEntity.billboard.scale = new ConstantProperty(iconScale);
5231
+ cEntity.billboard.heightReference = new ConstantProperty(getHeightRef(style));
5232
+ cEntity.billboard.disableDepthTestDistance = new ConstantProperty(disableDepthTest ? Number.POSITIVE_INFINITY : undefined);
5233
+ cEntity.billboard.distanceDisplayCondition = new ConstantProperty(getDisplayCondition(params.minDistance, params.maxDistance));
5234
+ cEntity.position = new ConstantPositionProperty(EntityUtils.GetPos({
4793
5235
  viewer: params.viewer,
4794
5236
  entity: entity,
4795
5237
  recordHeightRef: heightRef,
4796
5238
  returnHeightRef: heightRef
4797
- }),
4798
- show: true
4799
- });
5239
+ }));
5240
+ // We'll use "SetDefaultColor" to updating the internal reference and to allow for an animation.
5241
+ CesiumEntityStyler.SetDefaultColor({
5242
+ color: cColor_1,
5243
+ entity: cEntity,
5244
+ viewer: params.viewer,
5245
+ override: true,
5246
+ requestRender: false
5247
+ });
5248
+ cEntity.show = true;
5249
+ }
4800
5250
  cEntity.billboard._billboardSize = image.height;
5251
+ cEntity.billboard._billboardImgKey = iconUrl;
4801
5252
  }
4802
5253
  }
4803
- _c.label = 9;
5254
+ _e.label = 9;
4804
5255
  case 9:
4805
5256
  if (type == Style.EPointType.Cylinder) {
4806
5257
  radius = EnsureNumber(Calculator.GetNumber(style.CylinderRadius, entity, params.tags));
@@ -4825,46 +5276,97 @@ var EntityRenderEngine;
4825
5276
  returnHeightRef: heightRef
4826
5277
  });
4827
5278
  extrusion = getCylinderExtrusion(entity, params.tags, heightRef, style.CylinderFillExtrusion);
4828
- cEntity = new Entity({
4829
- id: ObjectUtils.UId(10),
4830
- ellipse: {
4831
- semiMajorAxis: radius,
4832
- semiMinorAxis: radius,
4833
- material: cFill,
4834
- outlineWidth: null,
4835
- extrudedHeight: extrusion.value,
4836
- heightReference: heightRef,
4837
- extrudedHeightReference: extrusion.exHeightRef,
4838
- height: Cartographic.fromCartesian(pos3d).height,
4839
- zIndex: 1,
4840
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
4841
- },
4842
- position: pos3d === null || pos3d === void 0 ? void 0 : pos3d.clone(),
4843
- show: true
4844
- });
4845
- if (outline && outlineWidth > 0) {
4846
- outlineExtrusion = getCylinderExtrusion(entity, params.tags, heightRef, style.CylinderBorderExtrusion);
4847
- // If this doesn't have its own extrusion, we must make it match the sibling.
4848
- // This way they render in a uniform way.
4849
- if (!outlineExtrusion.value && extrusion.value) {
4850
- outlineExtrusion.exHeightRef = extrusion.exHeightRef;
4851
- }
4852
- siblings.push(new Entity({
5279
+ hasOutline = outline && outlineWidth > 0;
5280
+ if (!params.rendered || !params.rendered.ellipse) {
5281
+ cEntity = new Entity({
4853
5282
  id: ObjectUtils.UId(10),
4854
5283
  ellipse: {
4855
- semiMajorAxis: radius + outlineWidth,
4856
- semiMinorAxis: radius + outlineWidth,
4857
- material: cOutline,
4858
- outlineWidth: undefined,
4859
- extrudedHeight: outlineExtrusion.value,
5284
+ semiMajorAxis: radius,
5285
+ semiMinorAxis: radius,
5286
+ material: cFill,
5287
+ outlineWidth: null,
5288
+ extrudedHeight: extrusion.value,
4860
5289
  heightReference: heightRef,
4861
- extrudedHeightReference: outlineExtrusion.exHeightRef,
5290
+ extrudedHeightReference: extrusion.exHeightRef,
4862
5291
  height: Cartographic.fromCartesian(pos3d).height,
4863
- zIndex: 2,
5292
+ zIndex: 1,
4864
5293
  distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
4865
5294
  },
4866
- position: pos3d === null || pos3d === void 0 ? void 0 : pos3d.clone()
4867
- }));
5295
+ position: pos3d === null || pos3d === void 0 ? void 0 : pos3d.clone(),
5296
+ show: true
5297
+ });
5298
+ }
5299
+ else {
5300
+ prepareExistingGraphic(params.rendered, hasOutline ? 1 : 0);
5301
+ cEntity = params.rendered;
5302
+ cEntity.ellipse.semiMajorAxis = new ConstantProperty(radius);
5303
+ cEntity.ellipse.semiMinorAxis = new ConstantProperty(radius);
5304
+ cEntity.ellipse.outlineWidth = undefined;
5305
+ cEntity.ellipse.extrudedHeight = new ConstantProperty(extrusion.value);
5306
+ cEntity.ellipse.heightReference = new ConstantProperty(heightRef);
5307
+ cEntity.ellipse.extrudedHeightReference = new ConstantProperty(extrusion.exHeightRef);
5308
+ cEntity.ellipse.height = new ConstantProperty(Cartographic.fromCartesian(pos3d).height);
5309
+ cEntity.ellipse.zIndex = new ConstantProperty(1);
5310
+ cEntity.ellipse.distanceDisplayCondition = new ConstantProperty(getDisplayCondition(params.minDistance, params.maxDistance));
5311
+ cEntity.position = new ConstantPositionProperty(pos3d === null || pos3d === void 0 ? void 0 : pos3d.clone());
5312
+ // We'll use "SetDefaultColor" to updating the internal reference and to allow for an animation.
5313
+ // WARNING: ellipse does not support animation (yet?).
5314
+ CesiumEntityStyler.SetDefaultColor({
5315
+ color: cFill,
5316
+ entity: cEntity,
5317
+ viewer: params.viewer,
5318
+ override: true,
5319
+ requestRender: false
5320
+ });
5321
+ cEntity.show = true;
5322
+ }
5323
+ if (hasOutline) {
5324
+ outlineExtrusion = getCylinderExtrusion(entity, params.tags, heightRef, style.CylinderBorderExtrusion);
5325
+ // If this doesn't have its own extrusion, we must make it match the sibling.
5326
+ // This way they render in a uniform way.
5327
+ if (!outlineExtrusion.value && extrusion.value) {
5328
+ outlineExtrusion.exHeightRef = extrusion.exHeightRef;
5329
+ }
5330
+ outlineEntity = (_d = (_c = params.rendered) === null || _c === void 0 ? void 0 : _c._siblingGraphics) === null || _d === void 0 ? void 0 : _d[0];
5331
+ if (outlineEntity && outlineEntity.ellipse) {
5332
+ outlineEntity.ellipse.semiMajorAxis = new ConstantProperty(radius + outlineWidth);
5333
+ outlineEntity.ellipse.semiMinorAxis = new ConstantProperty(radius + outlineWidth);
5334
+ outlineEntity.ellipse.extrudedHeight = new ConstantProperty(outlineExtrusion.value);
5335
+ outlineEntity.ellipse.heightReference = new ConstantProperty(heightRef);
5336
+ outlineEntity.ellipse.extrudedHeightReference = new ConstantProperty(outlineExtrusion.exHeightRef);
5337
+ outlineEntity.ellipse.height = new ConstantProperty(Cartographic.fromCartesian(pos3d).height);
5338
+ outlineEntity.ellipse.zIndex = new ConstantProperty(2);
5339
+ outlineEntity.ellipse.distanceDisplayCondition = new ConstantProperty(getDisplayCondition(params.minDistance, params.maxDistance));
5340
+ // We'll use "SetDefaultColor" to updating the internal reference and to allow for an animation.
5341
+ // WARNING: ellipse does not support animation (yet?).
5342
+ CesiumEntityStyler.SetDefaultColor({
5343
+ color: cOutline,
5344
+ entity: outlineEntity,
5345
+ viewer: params.viewer,
5346
+ override: true,
5347
+ requestRender: false
5348
+ });
5349
+ outlineEntity.show = true;
5350
+ }
5351
+ else {
5352
+ outlineEntity = new Entity({
5353
+ id: ObjectUtils.UId(10),
5354
+ ellipse: {
5355
+ semiMajorAxis: radius + outlineWidth,
5356
+ semiMinorAxis: radius + outlineWidth,
5357
+ material: cOutline,
5358
+ outlineWidth: undefined,
5359
+ extrudedHeight: outlineExtrusion.value,
5360
+ heightReference: heightRef,
5361
+ extrudedHeightReference: outlineExtrusion.exHeightRef,
5362
+ height: Cartographic.fromCartesian(pos3d).height,
5363
+ zIndex: 2,
5364
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
5365
+ },
5366
+ position: pos3d === null || pos3d === void 0 ? void 0 : pos3d.clone()
5367
+ });
5368
+ }
5369
+ siblings.push(outlineEntity);
4868
5370
  }
4869
5371
  }
4870
5372
  if (!cEntity) {
@@ -4881,33 +5383,66 @@ var EntityRenderEngine;
4881
5383
  heightRef = getHeightRef(style);
4882
5384
  circleBillboard = createCircleBillboard(size, cColor.toCssColorString());
4883
5385
  disableDepthTest = Boolean(style.renderOnTop);
4884
- cEntity = new Entity({
4885
- id: ObjectUtils.UId(10),
4886
- // point: {
4887
- // pixelSize: size,
4888
- // color: cColor,
4889
- // heightReference: getHeightRef(style),
4890
- // distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
4891
- // },
4892
- // We are generating a billboard instead of using the point.
4893
- // This is because points were behaving strangely where they would appear oblong shapes.
4894
- // This occurred consistently when rendering many icons and points at the same time.
4895
- billboard: {
4896
- height: circleBillboard.height,
4897
- width: circleBillboard.width,
4898
- image: circleBillboard.canvas,
4899
- heightReference: heightRef,
4900
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance),
4901
- disableDepthTestDistance: disableDepthTest ? Number.POSITIVE_INFINITY : undefined
4902
- },
4903
- position: EntityUtils.GetPos({
5386
+ if (!params.rendered || !params.rendered.billboard) {
5387
+ cEntity = new Entity({
5388
+ id: ObjectUtils.UId(10),
5389
+ // point: {
5390
+ // pixelSize: size,
5391
+ // color: cColor,
5392
+ // heightReference: getHeightRef(style),
5393
+ // distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
5394
+ // },
5395
+ // We are generating a billboard instead of using the point.
5396
+ // This is because points were behaving strangely where they would appear oblong shapes.
5397
+ // This occurred consistently when rendering many icons and points at the same time.
5398
+ billboard: {
5399
+ height: circleBillboard.height,
5400
+ width: circleBillboard.width,
5401
+ image: circleBillboard.canvasDataUri,
5402
+ color: new CallbackProperty(function () { return undefined; }, true),
5403
+ heightReference: heightRef,
5404
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance),
5405
+ disableDepthTestDistance: disableDepthTest ? Number.POSITIVE_INFINITY : undefined
5406
+ },
5407
+ position: EntityUtils.GetPos({
5408
+ viewer: params.viewer,
5409
+ entity: entity,
5410
+ recordHeightRef: heightRef,
5411
+ returnHeightRef: heightRef
5412
+ }),
5413
+ show: true
5414
+ });
5415
+ }
5416
+ else {
5417
+ prepareExistingGraphic(params.rendered);
5418
+ cEntity = params.rendered;
5419
+ imgKey = "".concat(size, "-").concat(cColor.toCssColorString());
5420
+ currentImgKey = cEntity.billboard._billboardImgKey;
5421
+ if (currentImgKey != imgKey) {
5422
+ cEntity.billboard.image = new ConstantProperty(circleBillboard.canvasDataUri);
5423
+ }
5424
+ cEntity.billboard.height = new ConstantProperty(circleBillboard.height);
5425
+ cEntity.billboard.width = new ConstantProperty(circleBillboard.width);
5426
+ cEntity.billboard.heightReference = new ConstantProperty(heightRef);
5427
+ cEntity.billboard.distanceDisplayCondition = new ConstantProperty(getDisplayCondition(params.minDistance, params.maxDistance));
5428
+ cEntity.billboard.disableDepthTestDistance = new ConstantProperty(disableDepthTest ? Number.POSITIVE_INFINITY : undefined);
5429
+ cEntity.position = new ConstantPositionProperty(EntityUtils.GetPos({
4904
5430
  viewer: params.viewer,
4905
5431
  entity: entity,
4906
5432
  recordHeightRef: heightRef,
4907
5433
  returnHeightRef: heightRef
4908
- }),
4909
- show: true
4910
- });
5434
+ }));
5435
+ // We'll use "SetDefaultColor" to updating the internal reference and to allow for an animation.
5436
+ CesiumEntityStyler.SetDefaultColor({
5437
+ color: cColor,
5438
+ entity: cEntity,
5439
+ viewer: params.viewer,
5440
+ override: true,
5441
+ requestRender: false
5442
+ });
5443
+ cEntity.show = true;
5444
+ cEntity.billboard._billboardImgKey = imgKey;
5445
+ }
4911
5446
  cEntity.billboard._billboardSize = Math.ceil(circleBillboard.height / 2);
4912
5447
  }
4913
5448
  if (cEntity) {
@@ -4920,16 +5455,16 @@ var EntityRenderEngine;
4920
5455
  }
4921
5456
  Point.Render = Render;
4922
5457
  function RenderGroup(params) {
4923
- var _a, _b, _c;
5458
+ var _a, _b, _c, _d;
4924
5459
  return __awaiter(this, void 0, void 0, function () {
4925
- var api, cEntities, i, entity, zoomItem, style, _d, tagIds, tags, pStyle, cEntity, name_2;
4926
- return __generator(this, function (_e) {
4927
- switch (_e.label) {
5460
+ var api, cEntities, i, entity, zoomItem, style, _e, tagIds, tags, pStyle, cEntity, name_2;
5461
+ return __generator(this, function (_f) {
5462
+ switch (_f.label) {
4928
5463
  case 0:
4929
5464
  api = params.apiGetter.getApi();
4930
5465
  cEntities = {};
4931
5466
  i = 0;
4932
- _e.label = 1;
5467
+ _f.label = 1;
4933
5468
  case 1:
4934
5469
  if (!(i < params.entities.length)) return [3 /*break*/, 11];
4935
5470
  entity = params.entities[i];
@@ -4937,13 +5472,13 @@ var EntityRenderEngine;
4937
5472
  if (!(zoomItem.StyleID != -1)) return [3 /*break*/, 3];
4938
5473
  return [4 /*yield*/, getStyle(api, entity, zoomItem.StyleID)];
4939
5474
  case 2:
4940
- _d = (_a = (_e.sent())) === null || _a === void 0 ? void 0 : _a.Settings;
5475
+ _e = (_a = (_f.sent())) === null || _a === void 0 ? void 0 : _a.Settings;
4941
5476
  return [3 /*break*/, 4];
4942
5477
  case 3:
4943
- _d = zoomItem.Style;
4944
- _e.label = 4;
5478
+ _e = zoomItem.Style;
5479
+ _f.label = 4;
4945
5480
  case 4:
4946
- style = _d;
5481
+ style = _e;
4947
5482
  tagIds = entity.Bruce["Layer.ID"];
4948
5483
  tags = [];
4949
5484
  if (!(tagIds && tagIds.length > 0)) return [3 /*break*/, 6];
@@ -4952,8 +5487,8 @@ var EntityRenderEngine;
4952
5487
  tagIds: tagIds
4953
5488
  })];
4954
5489
  case 5:
4955
- tags = (_e.sent()).tags;
4956
- _e.label = 6;
5490
+ tags = (_f.sent()).tags;
5491
+ _f.label = 6;
4957
5492
  case 6:
4958
5493
  pStyle = (_b = style === null || style === void 0 ? void 0 : style.pointStyle) !== null && _b !== void 0 ? _b : {};
4959
5494
  return [4 /*yield*/, Render({
@@ -4964,20 +5499,21 @@ var EntityRenderEngine;
4964
5499
  api: api,
4965
5500
  apiGetter: params.apiGetter,
4966
5501
  maxDistance: zoomItem.MaxZoom,
4967
- minDistance: zoomItem.MinZoom
5502
+ minDistance: zoomItem.MinZoom,
5503
+ rendered: (_c = params.rendered) === null || _c === void 0 ? void 0 : _c[entity.Bruce.ID]
4968
5504
  })];
4969
5505
  case 7:
4970
- cEntity = _e.sent();
5506
+ cEntity = _f.sent();
4971
5507
  if (!cEntity) return [3 /*break*/, 9];
4972
5508
  return [4 /*yield*/, getName(api, entity)];
4973
5509
  case 8:
4974
- name_2 = _e.sent();
5510
+ name_2 = _f.sent();
4975
5511
  cEntity.name = name_2;
4976
- cEntity._renderGroup = getRenderGroupId(zoomItem, (_c = params.viewer) === null || _c === void 0 ? void 0 : _c.terrainProvider);
4977
- _e.label = 9;
5512
+ cEntity._renderGroup = getRenderGroupId(zoomItem, (_d = params.viewer) === null || _d === void 0 ? void 0 : _d.terrainProvider);
5513
+ _f.label = 9;
4978
5514
  case 9:
4979
5515
  cEntities[entity.Bruce.ID] = cEntity;
4980
- _e.label = 10;
5516
+ _f.label = 10;
4981
5517
  case 10:
4982
5518
  i++;
4983
5519
  return [3 /*break*/, 1];
@@ -5062,52 +5598,110 @@ var EntityRenderEngine;
5062
5598
  if (style.drapeOver == "ALL") {
5063
5599
  classification = ClassificationType.BOTH;
5064
5600
  }
5065
- var cEntity = new Entity({
5066
- id: ObjectUtils.UId(10),
5067
- polyline: units == "px" ? {
5068
- positions: posses,
5069
- material: cColor,
5070
- width: width,
5071
- classificationType: classification,
5072
- arcType: ArcType.GEODESIC,
5073
- zIndex: getZIndex(style, entity, params.tags),
5074
- clampToGround: heightRef == HeightReference.CLAMP_TO_GROUND,
5075
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
5076
- } : null,
5077
- corridor: units == "m" ? {
5078
- positions: posses,
5079
- material: cColor,
5080
- width: width,
5081
- classificationType: classification,
5082
- heightReference: heightRef,
5083
- zIndex: getZIndex(style, entity, params.tags),
5084
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance, width),
5085
- cornerType: CornerType.MITERED,
5086
- shadows: ShadowMode.ENABLED,
5087
- fill: true
5088
- } : null,
5089
- position: EntityUtils.GetPos({
5601
+ var cEntity = null;
5602
+ if (!params.rendered || ((!params.rendered.polyline && units == "px") ||
5603
+ (!params.rendered.corridor && units == "m"))) {
5604
+ cEntity = new Entity({
5605
+ id: ObjectUtils.UId(10),
5606
+ polyline: units == "px" ? {
5607
+ positions: posses,
5608
+ material: cColor,
5609
+ width: width,
5610
+ classificationType: classification,
5611
+ arcType: ArcType.GEODESIC,
5612
+ zIndex: getZIndex(style, entity, params.tags),
5613
+ clampToGround: heightRef == HeightReference.CLAMP_TO_GROUND,
5614
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
5615
+ } : null,
5616
+ corridor: units == "m" ? {
5617
+ positions: posses,
5618
+ material: cColor,
5619
+ width: width,
5620
+ classificationType: classification,
5621
+ heightReference: heightRef,
5622
+ zIndex: getZIndex(style, entity, params.tags),
5623
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance, width),
5624
+ cornerType: CornerType.MITERED,
5625
+ shadows: ShadowMode.ENABLED,
5626
+ fill: true
5627
+ } : null,
5628
+ position: EntityUtils.GetPos({
5629
+ viewer: params.viewer,
5630
+ entity: entity,
5631
+ recordHeightRef: heightRef,
5632
+ returnHeightRef: heightRef
5633
+ }),
5634
+ show: true
5635
+ });
5636
+ }
5637
+ else {
5638
+ // Gather entity in case previous version had sibling graphics we no longer need.
5639
+ var parts = EntityUtils.GatherEntity({
5640
+ entity: cEntity,
5641
+ });
5642
+ if (parts.length > 1) {
5643
+ // Kill all expect last part. Last one is the primary entity.
5644
+ for (var i = 0; i < parts.length - 1; i++) {
5645
+ var part = parts[i];
5646
+ if (part && part instanceof Entity && params.viewer.entities.contains(part)) {
5647
+ params.viewer.entities.remove(part);
5648
+ }
5649
+ }
5650
+ cEntity._siblingGraphics = [];
5651
+ if (cEntity._parentEntity) {
5652
+ console.warn("Polyline.Render: Parent entity was not null. This should not happen.");
5653
+ }
5654
+ }
5655
+ cEntity = params.rendered;
5656
+ if (units == "px") {
5657
+ cEntity.polyline.positions = new ConstantProperty(posses);
5658
+ cEntity.polyline.width = new ConstantProperty(width);
5659
+ cEntity.polyline.classificationType = new ConstantProperty(classification);
5660
+ cEntity.polyline.zIndex = new ConstantProperty(getZIndex(style, entity, params.tags));
5661
+ cEntity.polyline.clampToGround = new ConstantProperty(heightRef == HeightReference.CLAMP_TO_GROUND);
5662
+ cEntity.polyline.distanceDisplayCondition = new ConstantProperty(getDisplayCondition(params.minDistance, params.maxDistance));
5663
+ cEntity.corridor = undefined;
5664
+ }
5665
+ else {
5666
+ cEntity.corridor.positions = new ConstantProperty(posses);
5667
+ cEntity.corridor.width = new ConstantProperty(width);
5668
+ cEntity.corridor.classificationType = new ConstantProperty(classification);
5669
+ cEntity.corridor.heightReference = new ConstantProperty(heightRef);
5670
+ cEntity.corridor.zIndex = new ConstantProperty(getZIndex(style, entity, params.tags));
5671
+ cEntity.corridor.distanceDisplayCondition = new ConstantProperty(getDisplayCondition(params.minDistance, params.maxDistance, width));
5672
+ cEntity.polyline = undefined;
5673
+ }
5674
+ // We'll use "SetDefaultColor" to updating the internal reference and to allow for an animation.
5675
+ // WARNING: polyline does not support animation (yet?).
5676
+ CesiumEntityStyler.SetDefaultColor({
5677
+ color: cColor,
5678
+ entity: cEntity,
5679
+ viewer: params.viewer,
5680
+ override: true,
5681
+ requestRender: false
5682
+ });
5683
+ cEntity.position = new ConstantPositionProperty(EntityUtils.GetPos({
5090
5684
  viewer: params.viewer,
5091
5685
  entity: entity,
5092
5686
  recordHeightRef: heightRef,
5093
5687
  returnHeightRef: heightRef
5094
- }),
5095
- show: true
5096
- });
5688
+ }));
5689
+ cEntity.show = true;
5690
+ }
5097
5691
  return cEntity;
5098
5692
  }
5099
5693
  Polyline.Render = Render;
5100
5694
  function RenderGroup(params) {
5101
- var _a, _b, _c;
5695
+ var _a, _b, _c, _d;
5102
5696
  return __awaiter(this, void 0, void 0, function () {
5103
- var api, cEntities, i, entity, zoomItem, style, _d, tagIds, tags, lStyle, cEntity, name_3;
5104
- return __generator(this, function (_e) {
5105
- switch (_e.label) {
5697
+ var api, cEntities, i, entity, zoomItem, style, _e, tagIds, tags, lStyle, cEntity, name_3;
5698
+ return __generator(this, function (_f) {
5699
+ switch (_f.label) {
5106
5700
  case 0:
5107
5701
  api = params.apiGetter.getApi();
5108
5702
  cEntities = {};
5109
5703
  i = 0;
5110
- _e.label = 1;
5704
+ _f.label = 1;
5111
5705
  case 1:
5112
5706
  if (!(i < params.entities.length)) return [3 /*break*/, 9];
5113
5707
  entity = params.entities[i];
@@ -5115,13 +5709,13 @@ var EntityRenderEngine;
5115
5709
  if (!(zoomItem.StyleID != -1)) return [3 /*break*/, 3];
5116
5710
  return [4 /*yield*/, getStyle(api, entity, zoomItem.StyleID)];
5117
5711
  case 2:
5118
- _d = (_a = (_e.sent())) === null || _a === void 0 ? void 0 : _a.Settings;
5712
+ _e = (_a = (_f.sent())) === null || _a === void 0 ? void 0 : _a.Settings;
5119
5713
  return [3 /*break*/, 4];
5120
5714
  case 3:
5121
- _d = zoomItem.Style;
5122
- _e.label = 4;
5715
+ _e = zoomItem.Style;
5716
+ _f.label = 4;
5123
5717
  case 4:
5124
- style = _d;
5718
+ style = _e;
5125
5719
  tagIds = entity.Bruce["Layer.ID"];
5126
5720
  tags = [];
5127
5721
  if (!(tagIds && tagIds.length > 0)) return [3 /*break*/, 6];
@@ -5130,8 +5724,8 @@ var EntityRenderEngine;
5130
5724
  tagIds: tagIds
5131
5725
  })];
5132
5726
  case 5:
5133
- tags = (_e.sent()).tags;
5134
- _e.label = 6;
5727
+ tags = (_f.sent()).tags;
5728
+ _f.label = 6;
5135
5729
  case 6:
5136
5730
  lStyle = (_b = style === null || style === void 0 ? void 0 : style.polylineStyle) !== null && _b !== void 0 ? _b : {};
5137
5731
  cEntity = Render({
@@ -5140,16 +5734,17 @@ var EntityRenderEngine;
5140
5734
  tags: tags,
5141
5735
  viewer: params.viewer,
5142
5736
  maxDistance: zoomItem.MaxZoom,
5143
- minDistance: zoomItem.MinZoom
5737
+ minDistance: zoomItem.MinZoom,
5738
+ rendered: (_c = params.rendered) === null || _c === void 0 ? void 0 : _c[entity.Bruce.ID]
5144
5739
  });
5145
5740
  if (!cEntity) return [3 /*break*/, 8];
5146
5741
  return [4 /*yield*/, getName(api, entity)];
5147
5742
  case 7:
5148
- name_3 = _e.sent();
5743
+ name_3 = _f.sent();
5149
5744
  cEntity.name = name_3;
5150
- cEntity._renderGroup = getRenderGroupId(zoomItem, (_c = params.viewer) === null || _c === void 0 ? void 0 : _c.terrainProvider);
5745
+ cEntity._renderGroup = getRenderGroupId(zoomItem, (_d = params.viewer) === null || _d === void 0 ? void 0 : _d.terrainProvider);
5151
5746
  cEntities[entity.Bruce.ID] = cEntity;
5152
- _e.label = 8;
5747
+ _f.label = 8;
5153
5748
  case 8:
5154
5749
  i++;
5155
5750
  return [3 /*break*/, 1];
@@ -5163,7 +5758,7 @@ var EntityRenderEngine;
5163
5758
  var Polygon;
5164
5759
  (function (Polygon) {
5165
5760
  function Render(params) {
5166
- var _a, _b;
5761
+ var _a, _b, _c, _d;
5167
5762
  var entity = params.entity;
5168
5763
  var pRings = (_a = entity.geometry) === null || _a === void 0 ? void 0 : _a.Polygon;
5169
5764
  if (pRings == null || pRings.length <= 0) {
@@ -5220,30 +5815,85 @@ var EntityRenderEngine;
5220
5815
  if (style.drapeOver == "ALL") {
5221
5816
  classification = ClassificationType.BOTH;
5222
5817
  }
5223
- var cEntity = new Entity({
5224
- id: ObjectUtils.UId(10),
5225
- polygon: {
5226
- hierarchy: new PolygonHierarchy(posses, holePosses.map(function (x) { return new PolygonHierarchy(x); })),
5227
- material: cFillColor,
5228
- extrudedHeight: extrusion.value,
5229
- extrudedHeightReference: extrusion.exHeightRef,
5230
- shadows: ShadowMode.ENABLED,
5231
- heightReference: heightRef,
5232
- classificationType: classification,
5233
- perPositionHeight: heightRef == HeightReference.CLAMP_TO_GROUND ? false : true,
5234
- zIndex: zIndex,
5235
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance, width <= 0 || !cLineColor || units == "m" ? size : null, true)
5236
- },
5237
- position: EntityUtils.GetPos({
5818
+ var prepareExistingGraphic = function (cEntity, siblings) {
5819
+ if (siblings === void 0) { siblings = 0; }
5820
+ // Gather entity in case previous version had sibling graphics we no longer need.
5821
+ var parts = EntityUtils.GatherEntity({
5822
+ entity: cEntity,
5823
+ });
5824
+ if (parts.length > 1) {
5825
+ // We'll cull all except the allowed number of siblings.
5826
+ cEntity._siblingGraphics = cEntity._siblingGraphics.slice(0, siblings);
5827
+ // We'll remove all that aren't in the allowed (direct) list.
5828
+ for (var i = 0; i < parts.length - 1; i++) {
5829
+ var part = parts[i];
5830
+ if (part && part instanceof Entity && params.viewer.entities.contains(part) && !cEntity._siblingGraphics.includes(part)) {
5831
+ params.viewer.entities.remove(part);
5832
+ }
5833
+ }
5834
+ if (cEntity._parentEntity) {
5835
+ console.warn("Point.Render: Parent entity was not null. This should not happen.");
5836
+ }
5837
+ }
5838
+ };
5839
+ var hasOutline = width > 0 && cLineColor;
5840
+ var cEntity = null;
5841
+ if (!params.rendered || !params.rendered.polygon) {
5842
+ cEntity = new Entity({
5843
+ id: ObjectUtils.UId(10),
5844
+ polygon: {
5845
+ hierarchy: new PolygonHierarchy(posses, holePosses.map(function (x) { return new PolygonHierarchy(x); })),
5846
+ material: cFillColor,
5847
+ extrudedHeight: extrusion.value,
5848
+ extrudedHeightReference: extrusion.exHeightRef,
5849
+ shadows: ShadowMode.ENABLED,
5850
+ heightReference: heightRef,
5851
+ classificationType: classification,
5852
+ perPositionHeight: heightRef == HeightReference.CLAMP_TO_GROUND ? false : true,
5853
+ zIndex: zIndex,
5854
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance, width <= 0 || !cLineColor || units == "m" ? size : null, true)
5855
+ },
5856
+ position: EntityUtils.GetPos({
5857
+ viewer: params.viewer,
5858
+ entity: entity,
5859
+ recordHeightRef: heightRef,
5860
+ returnHeightRef: heightRef
5861
+ }),
5862
+ show: true
5863
+ });
5864
+ }
5865
+ else {
5866
+ // Polygons can have more siblings for the related hole graphics.
5867
+ // So this is a "good enough" way rather than perfect as it only preserves the outline.
5868
+ prepareExistingGraphic(params.rendered, hasOutline ? 1 : 0);
5869
+ cEntity = params.rendered;
5870
+ cEntity.polygon.hierarchy = new ConstantProperty(new PolygonHierarchy(posses, holePosses.map(function (x) { return new PolygonHierarchy(x); })));
5871
+ cEntity.polygon.extrudedHeight = new ConstantProperty(extrusion.value);
5872
+ cEntity.polygon.extrudedHeightReference = new ConstantProperty(extrusion.exHeightRef);
5873
+ cEntity.polygon.shadows = new ConstantProperty(ShadowMode.ENABLED);
5874
+ cEntity.polygon.heightReference = new ConstantProperty(heightRef);
5875
+ cEntity.polygon.classificationType = new ConstantProperty(classification);
5876
+ cEntity.polygon.perPositionHeight = new ConstantProperty(heightRef == HeightReference.CLAMP_TO_GROUND ? false : true);
5877
+ cEntity.polygon.zIndex = new ConstantProperty(zIndex);
5878
+ cEntity.polygon.distanceDisplayCondition = new ConstantProperty(getDisplayCondition(params.minDistance, params.maxDistance, width <= 0 || !cLineColor || units == "m" ? size : null, true));
5879
+ cEntity.position = new ConstantPositionProperty(EntityUtils.GetPos({
5238
5880
  viewer: params.viewer,
5239
5881
  entity: entity,
5240
5882
  recordHeightRef: heightRef,
5241
5883
  returnHeightRef: heightRef
5242
- }),
5243
- show: true
5244
- });
5245
- cEntity._siblingGraphics = [];
5246
- if (width > 0 && cLineColor) {
5884
+ }));
5885
+ // We'll use "SetDefaultColor" to updating the internal reference and to allow for an animation.
5886
+ // WARNING: polygon does not support animation (yet?).
5887
+ CesiumEntityStyler.SetDefaultColor({
5888
+ color: cFillColor,
5889
+ entity: cEntity,
5890
+ viewer: params.viewer,
5891
+ override: true,
5892
+ requestRender: false
5893
+ });
5894
+ cEntity.show = true;
5895
+ }
5896
+ if (hasOutline) {
5247
5897
  var borderHeight = undefined;
5248
5898
  if (heightRef != HeightReference.CLAMP_TO_GROUND) {
5249
5899
  if (flattenPoints) {
@@ -5267,33 +5917,62 @@ var EntityRenderEngine;
5267
5917
  else {
5268
5918
  borderPosses = posses.map(function (x) { return x.clone ? x.clone() : __assign({}, x); });
5269
5919
  }
5270
- var cEntityBorder = new Entity({
5271
- id: ObjectUtils.UId(10),
5272
- polyline: units == "px" ? new PolylineGraphics({
5273
- positions: borderPosses,
5274
- material: cLineColor,
5275
- width: width,
5276
- clampToGround: heightRef == HeightReference.CLAMP_TO_GROUND,
5277
- classificationType: ClassificationType.TERRAIN,
5278
- arcType: ArcType.GEODESIC,
5279
- zIndex: zIndex,
5280
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
5281
- }) : null,
5282
- corridor: units == "m" ? {
5283
- positions: borderPosses,
5284
- material: cLineColor,
5285
- heightReference: heightRef,
5286
- height: borderHeight,
5287
- width: width,
5288
- fill: true,
5289
- zIndex: zIndex + 1,
5290
- cornerType: CornerType.MITERED,
5291
- classificationType: classification,
5292
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance, width),
5293
- shadows: ShadowMode.ENABLED
5294
- } : null,
5295
- show: true
5296
- });
5920
+ var cEntityBorder = (_d = (_c = params.rendered) === null || _c === void 0 ? void 0 : _c._siblingGraphics) === null || _d === void 0 ? void 0 : _d[0];
5921
+ cEntity._siblingGraphics = [];
5922
+ if (!cEntityBorder || ((!cEntityBorder.polyline && units == "px") ||
5923
+ (!cEntityBorder.corridor && units == "m"))) {
5924
+ cEntityBorder = new Entity({
5925
+ id: ObjectUtils.UId(10),
5926
+ polyline: units == "px" ? new PolylineGraphics({
5927
+ positions: borderPosses,
5928
+ material: cLineColor,
5929
+ width: width,
5930
+ clampToGround: heightRef == HeightReference.CLAMP_TO_GROUND,
5931
+ classificationType: ClassificationType.TERRAIN,
5932
+ arcType: ArcType.GEODESIC,
5933
+ zIndex: zIndex,
5934
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
5935
+ }) : null,
5936
+ corridor: units == "m" ? {
5937
+ positions: borderPosses,
5938
+ material: cLineColor,
5939
+ heightReference: heightRef,
5940
+ height: borderHeight,
5941
+ width: width,
5942
+ fill: true,
5943
+ zIndex: zIndex + 1,
5944
+ cornerType: CornerType.MITERED,
5945
+ classificationType: classification,
5946
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance, width),
5947
+ shadows: ShadowMode.ENABLED
5948
+ } : null,
5949
+ show: true
5950
+ });
5951
+ }
5952
+ else {
5953
+ if (units == "px") {
5954
+ cEntityBorder.polyline.positions = new ConstantProperty(borderPosses);
5955
+ cEntityBorder.polyline.width = new ConstantProperty(width);
5956
+ cEntityBorder.polyline.clampToGround = new ConstantProperty(heightRef == HeightReference.CLAMP_TO_GROUND);
5957
+ cEntityBorder.polyline.classificationType = new ConstantProperty(ClassificationType.TERRAIN);
5958
+ cEntityBorder.polyline.zIndex = new ConstantProperty(zIndex);
5959
+ cEntityBorder.polyline.distanceDisplayCondition = new ConstantProperty(getDisplayCondition(params.minDistance, params.maxDistance));
5960
+ cEntityBorder.polyline.material = new ColorMaterialProperty(cLineColor);
5961
+ cEntityBorder.corridor = undefined;
5962
+ }
5963
+ else {
5964
+ cEntityBorder.corridor.positions = new ConstantProperty(borderPosses);
5965
+ cEntityBorder.corridor.heightReference = new ConstantProperty(heightRef);
5966
+ cEntityBorder.corridor.height = new ConstantProperty(borderHeight);
5967
+ cEntityBorder.corridor.width = new ConstantProperty(width);
5968
+ cEntityBorder.corridor.fill = new ConstantProperty(true);
5969
+ cEntityBorder.corridor.zIndex = new ConstantProperty(zIndex + 1);
5970
+ cEntityBorder.corridor.distanceDisplayCondition = new ConstantProperty(getDisplayCondition(params.minDistance, params.maxDistance, width));
5971
+ cEntityBorder.corridor.material = new ColorMaterialProperty(cLineColor);
5972
+ cEntityBorder.polyline = undefined;
5973
+ }
5974
+ cEntityBorder.show = true;
5975
+ }
5297
5976
  cEntityBorder._parentEntity = cEntity;
5298
5977
  cEntity._siblingGraphics.push(cEntityBorder);
5299
5978
  for (var i = 0; i < holePosses.length; i++) {
@@ -5330,20 +6009,23 @@ var EntityRenderEngine;
5330
6009
  cEntityHole._parentEntity = cEntity;
5331
6010
  }
5332
6011
  }
6012
+ else {
6013
+ cEntity._siblingGraphics = [];
6014
+ }
5333
6015
  return cEntity;
5334
6016
  }
5335
6017
  Polygon.Render = Render;
5336
6018
  function RenderGroup(params) {
5337
- var _a, _b, _c;
6019
+ var _a, _b, _c, _d;
5338
6020
  return __awaiter(this, void 0, void 0, function () {
5339
- var api, cEntities, i, entity, zoomItem, style, _d, tagIds, tags, pStyle, cEntity, name_4;
5340
- return __generator(this, function (_e) {
5341
- switch (_e.label) {
6021
+ var api, cEntities, i, entity, zoomItem, style, _e, tagIds, tags, pStyle, cEntity, name_4;
6022
+ return __generator(this, function (_f) {
6023
+ switch (_f.label) {
5342
6024
  case 0:
5343
6025
  api = params.apiGetter.getApi();
5344
6026
  cEntities = {};
5345
6027
  i = 0;
5346
- _e.label = 1;
6028
+ _f.label = 1;
5347
6029
  case 1:
5348
6030
  if (!(i < params.entities.length)) return [3 /*break*/, 9];
5349
6031
  entity = params.entities[i];
@@ -5351,13 +6033,13 @@ var EntityRenderEngine;
5351
6033
  if (!(zoomItem.StyleID != -1)) return [3 /*break*/, 3];
5352
6034
  return [4 /*yield*/, getStyle(api, entity, zoomItem.StyleID)];
5353
6035
  case 2:
5354
- _d = (_a = (_e.sent())) === null || _a === void 0 ? void 0 : _a.Settings;
6036
+ _e = (_a = (_f.sent())) === null || _a === void 0 ? void 0 : _a.Settings;
5355
6037
  return [3 /*break*/, 4];
5356
6038
  case 3:
5357
- _d = zoomItem.Style;
5358
- _e.label = 4;
6039
+ _e = zoomItem.Style;
6040
+ _f.label = 4;
5359
6041
  case 4:
5360
- style = _d;
6042
+ style = _e;
5361
6043
  tagIds = entity.Bruce["Layer.ID"];
5362
6044
  tags = [];
5363
6045
  if (!(tagIds && tagIds.length > 0)) return [3 /*break*/, 6];
@@ -5366,8 +6048,8 @@ var EntityRenderEngine;
5366
6048
  tagIds: tagIds
5367
6049
  })];
5368
6050
  case 5:
5369
- tags = (_e.sent()).tags;
5370
- _e.label = 6;
6051
+ tags = (_f.sent()).tags;
6052
+ _f.label = 6;
5371
6053
  case 6:
5372
6054
  pStyle = (_b = style === null || style === void 0 ? void 0 : style.polygonStyle) !== null && _b !== void 0 ? _b : {};
5373
6055
  cEntity = Render({
@@ -5376,16 +6058,17 @@ var EntityRenderEngine;
5376
6058
  tags: tags,
5377
6059
  viewer: params.viewer,
5378
6060
  maxDistance: zoomItem.MaxZoom,
5379
- minDistance: zoomItem.MinZoom
6061
+ minDistance: zoomItem.MinZoom,
6062
+ rendered: (_c = params.rendered) === null || _c === void 0 ? void 0 : _c[entity.Bruce.ID]
5380
6063
  });
5381
6064
  if (!cEntity) return [3 /*break*/, 8];
5382
6065
  return [4 /*yield*/, getName(api, entity)];
5383
6066
  case 7:
5384
- name_4 = _e.sent();
6067
+ name_4 = _f.sent();
5385
6068
  cEntity.name = name_4;
5386
- cEntity._renderGroup = getRenderGroupId(zoomItem, (_c = params.viewer) === null || _c === void 0 ? void 0 : _c.terrainProvider);
6069
+ cEntity._renderGroup = getRenderGroupId(zoomItem, (_d = params.viewer) === null || _d === void 0 ? void 0 : _d.terrainProvider);
5387
6070
  cEntities[entity.Bruce.ID] = cEntity;
5388
- _e.label = 8;
6071
+ _f.label = 8;
5389
6072
  case 8:
5390
6073
  i++;
5391
6074
  return [3 /*break*/, 1];
@@ -5449,22 +6132,99 @@ var EntityRenderEngine;
5449
6132
  color = colorToCColor(bColor);
5450
6133
  }
5451
6134
  }
5452
- var cEntity = new Entity({
6135
+ /*
6136
+ const cEntity: ICesiumEntityExt = new Cesium.Entity({
5453
6137
  id: ObjectUtils.UId(10),
5454
6138
  model: {
5455
6139
  uri: params.lodUrl,
5456
6140
  heightReference: heightRef,
5457
6141
  scale: scale * styleScale,
5458
- shadows: ShadowMode.ENABLED,
6142
+ shadows: Cesium.ShadowMode.ENABLED,
5459
6143
  colorBlendAmount: blendAmount,
5460
6144
  colorBlendMode: blendMode,
5461
- color: color,
6145
+ color: new Cesium.CallbackProperty(() => color, true),
5462
6146
  distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
5463
6147
  },
5464
- orientation: new ConstantProperty(orientation),
6148
+ orientation: new Cesium.ConstantProperty(orientation),
5465
6149
  position: pos,
5466
6150
  show: true
5467
6151
  });
6152
+ */
6153
+ var animateScale = null;
6154
+ var cEntity = params.rendered;
6155
+ if (!cEntity || !cEntity.model) {
6156
+ cEntity = new Entity({
6157
+ id: ObjectUtils.UId(10),
6158
+ model: {
6159
+ uri: params.lodUrl,
6160
+ heightReference: heightRef,
6161
+ scale: new CallbackProperty(function () { return scale * styleScale; }, true),
6162
+ shadows: ShadowMode.ENABLED,
6163
+ colorBlendAmount: blendAmount,
6164
+ colorBlendMode: blendMode,
6165
+ color: new CallbackProperty(function () { return color; }, true),
6166
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
6167
+ },
6168
+ orientation: new ConstantProperty(orientation),
6169
+ position: pos,
6170
+ show: true
6171
+ });
6172
+ }
6173
+ else {
6174
+ // Gather entity in case previous version had sibling graphics we no longer need.
6175
+ var parts = EntityUtils.GatherEntity({
6176
+ entity: cEntity,
6177
+ });
6178
+ if (parts.length > 1) {
6179
+ // Kill all expect last part. Last one is the primary entity.
6180
+ for (var i = 0; i < parts.length - 1; i++) {
6181
+ var part = parts[i];
6182
+ if (part && part instanceof Entity && params.viewer.entities.contains(part)) {
6183
+ params.viewer.entities.remove(part);
6184
+ }
6185
+ }
6186
+ cEntity._siblingGraphics = [];
6187
+ if (cEntity._parentEntity) {
6188
+ console.warn("Model3d.Render: Parent entity was not null. This should not happen.");
6189
+ }
6190
+ }
6191
+ var currentUri = getValue$1(params.viewer, cEntity.model.uri);
6192
+ if (currentUri != params.lodUrl) {
6193
+ cEntity.model.uri = new ConstantProperty(params.lodUrl);
6194
+ }
6195
+ cEntity.model.heightReference = new ConstantProperty(heightRef);
6196
+ cEntity.model.shadows = new ConstantProperty(ShadowMode.ENABLED);
6197
+ cEntity.model.colorBlendAmount = new ConstantProperty(blendAmount);
6198
+ cEntity.model.colorBlendMode = new ConstantProperty(blendMode);
6199
+ cEntity.model.distanceDisplayCondition = new ConstantProperty(getDisplayCondition(params.minDistance, params.maxDistance));
6200
+ cEntity.orientation = new ConstantProperty(orientation);
6201
+ cEntity.position = new ConstantPositionProperty(pos);
6202
+ // Same file but different scale. We'll animate the scale.
6203
+ var prevClientFileId = cEntity.model._clientFileId;
6204
+ if (prevClientFileId == params.lodClientFileId) {
6205
+ animateScale = new CesiumAnimatedProperty.AnimateNumber({
6206
+ durationMs: 200,
6207
+ value: scale * styleScale,
6208
+ viewer: params.viewer,
6209
+ startValue: cEntity.model.scale,
6210
+ startPaused: true
6211
+ });
6212
+ cEntity.model.scale = new CallbackProperty(function () { return animateScale.GetValue(); }, false);
6213
+ }
6214
+ else {
6215
+ cEntity.model.scale = new CallbackProperty(function () { return scale * styleScale; }, true);
6216
+ }
6217
+ // We'll use "SetDefaultColor" to updating the internal reference and to allow for an animation.
6218
+ // cEntity.model.color = new Cesium.CallbackProperty(() => color, true);
6219
+ CesiumEntityStyler.SetDefaultColor({
6220
+ color: color,
6221
+ entity: cEntity,
6222
+ viewer: params.viewer,
6223
+ override: true,
6224
+ requestRender: false
6225
+ });
6226
+ cEntity.show = true;
6227
+ }
5468
6228
  var fileRadiusKey = "model3d_".concat(params.lodUrl, "_").concat(scale * styleScale, "_radius");
5469
6229
  var heightProm = _fileRadiusCache.Get(fileRadiusKey);
5470
6230
  if (!heightProm) {
@@ -5543,6 +6303,10 @@ var EntityRenderEngine;
5543
6303
  VisualRegisterCuller.MarkShouldRecheck(params.viewer);
5544
6304
  }
5545
6305
  }
6306
+ // Rough estimate on when the model is ready in the scene.
6307
+ if (animateScale) {
6308
+ animateScale.Play();
6309
+ }
5546
6310
  });
5547
6311
  var model = cEntity.model;
5548
6312
  model._radiusLoaded = false;
@@ -5555,16 +6319,16 @@ var EntityRenderEngine;
5555
6319
  }
5556
6320
  Model3d.Render = Render;
5557
6321
  function RenderGroup(params) {
5558
- var _a, _b, _c, _d, _e;
6322
+ var _a, _b, _c, _d, _e, _f;
5559
6323
  return __awaiter(this, void 0, void 0, function () {
5560
- var api, cEntities, reqBody, i, entity, zoomItem, style, _f, tagIds, tags, mStyle, group, level, catId, lodData, _loop_2, i;
5561
- return __generator(this, function (_g) {
5562
- switch (_g.label) {
6324
+ var api, cEntities, reqBody, i, entity, zoomItem, style, _g, tagIds, tags, mStyle, group, level, catId, lodData, _loop_2, i;
6325
+ return __generator(this, function (_h) {
6326
+ switch (_h.label) {
5563
6327
  case 0:
5564
6328
  api = params.apiGetter.getApi();
5565
6329
  return [4 /*yield*/, api.Loading];
5566
6330
  case 1:
5567
- _g.sent();
6331
+ _h.sent();
5568
6332
  cEntities = {};
5569
6333
  reqBody = {
5570
6334
  "strict": false,
@@ -5572,7 +6336,7 @@ var EntityRenderEngine;
5572
6336
  "Items": []
5573
6337
  };
5574
6338
  i = 0;
5575
- _g.label = 2;
6339
+ _h.label = 2;
5576
6340
  case 2:
5577
6341
  if (!(i < params.entities.length)) return [3 /*break*/, 9];
5578
6342
  entity = params.entities[i];
@@ -5580,13 +6344,13 @@ var EntityRenderEngine;
5580
6344
  if (!(zoomItem.StyleID != -1)) return [3 /*break*/, 4];
5581
6345
  return [4 /*yield*/, getStyle(api, entity, zoomItem.StyleID)];
5582
6346
  case 3:
5583
- _f = (_a = (_g.sent())) === null || _a === void 0 ? void 0 : _a.Settings;
6347
+ _g = (_a = (_h.sent())) === null || _a === void 0 ? void 0 : _a.Settings;
5584
6348
  return [3 /*break*/, 5];
5585
6349
  case 4:
5586
- _f = zoomItem.Style;
5587
- _g.label = 5;
6350
+ _g = zoomItem.Style;
6351
+ _h.label = 5;
5588
6352
  case 5:
5589
- style = _f;
6353
+ style = _g;
5590
6354
  tagIds = entity.Bruce["Layer.ID"];
5591
6355
  tags = [];
5592
6356
  if (!(tagIds && tagIds.length > 0)) return [3 /*break*/, 7];
@@ -5595,8 +6359,8 @@ var EntityRenderEngine;
5595
6359
  tagIds: tagIds
5596
6360
  })];
5597
6361
  case 6:
5598
- tags = (_g.sent()).tags;
5599
- _g.label = 7;
6362
+ tags = (_h.sent()).tags;
6363
+ _h.label = 7;
5600
6364
  case 7:
5601
6365
  mStyle = (_b = style === null || style === void 0 ? void 0 : style.modelStyle) !== null && _b !== void 0 ? _b : {};
5602
6366
  group = mStyle.lodGroup ? Calculator.GetString(mStyle.lodGroup, entity, tags) : null;
@@ -5617,7 +6381,7 @@ var EntityRenderEngine;
5617
6381
  "group": group,
5618
6382
  "level": level
5619
6383
  });
5620
- _g.label = 8;
6384
+ _h.label = 8;
5621
6385
  case 8:
5622
6386
  i++;
5623
6387
  return [3 /*break*/, 2];
@@ -5626,24 +6390,24 @@ var EntityRenderEngine;
5626
6390
  filter: reqBody
5627
6391
  })];
5628
6392
  case 10:
5629
- lodData = (_g.sent()).lods;
6393
+ lodData = (_h.sent()).lods;
5630
6394
  _loop_2 = function (i) {
5631
- var entity, zoomItem, style, _h, tagIds, tags, lod, mStyle, cEntity, name_5;
5632
- return __generator(this, function (_j) {
5633
- switch (_j.label) {
6395
+ var entity, zoomItem, style, _j, tagIds, tags, lod, mStyle, cEntity, name_5;
6396
+ return __generator(this, function (_k) {
6397
+ switch (_k.label) {
5634
6398
  case 0:
5635
6399
  entity = params.entities[i];
5636
6400
  zoomItem = params.zoomItems[entity.Bruce.ID];
5637
6401
  if (!(zoomItem.StyleID != -1)) return [3 /*break*/, 2];
5638
6402
  return [4 /*yield*/, getStyle(api, entity, zoomItem.StyleID)];
5639
6403
  case 1:
5640
- _h = (_c = (_j.sent())) === null || _c === void 0 ? void 0 : _c.Settings;
6404
+ _j = (_c = (_k.sent())) === null || _c === void 0 ? void 0 : _c.Settings;
5641
6405
  return [3 /*break*/, 3];
5642
6406
  case 2:
5643
- _h = zoomItem.Style;
5644
- _j.label = 3;
6407
+ _j = zoomItem.Style;
6408
+ _k.label = 3;
5645
6409
  case 3:
5646
- style = _h;
6410
+ style = _j;
5647
6411
  tagIds = entity.Bruce["Layer.ID"];
5648
6412
  tags = [];
5649
6413
  if (!(tagIds && tagIds.length > 0)) return [3 /*break*/, 5];
@@ -5652,8 +6416,8 @@ var EntityRenderEngine;
5652
6416
  tagIds: tagIds
5653
6417
  })];
5654
6418
  case 4:
5655
- tags = (_j.sent()).tags;
5656
- _j.label = 5;
6419
+ tags = (_k.sent()).tags;
6420
+ _k.label = 5;
5657
6421
  case 5:
5658
6422
  lod = lodData.find(function (x) { return x.entityId == entity.Bruce.ID; });
5659
6423
  if (!(lod === null || lod === void 0 ? void 0 : lod.clientFileId)) {
@@ -5661,6 +6425,7 @@ var EntityRenderEngine;
5661
6425
  }
5662
6426
  mStyle = (_d = style === null || style === void 0 ? void 0 : style.modelStyle) !== null && _d !== void 0 ? _d : {};
5663
6427
  cEntity = Render({
6428
+ rendered: (_e = params.rendered) === null || _e === void 0 ? void 0 : _e[entity.Bruce.ID],
5664
6429
  entity: entity,
5665
6430
  style: mStyle,
5666
6431
  tags: tags,
@@ -5677,23 +6442,23 @@ var EntityRenderEngine;
5677
6442
  if (!cEntity) return [3 /*break*/, 7];
5678
6443
  return [4 /*yield*/, getName(api, entity)];
5679
6444
  case 6:
5680
- name_5 = _j.sent();
6445
+ name_5 = _k.sent();
5681
6446
  cEntity.name = name_5;
5682
- cEntity._renderGroup = getRenderGroupId(zoomItem, (_e = params.viewer) === null || _e === void 0 ? void 0 : _e.terrainProvider);
6447
+ cEntity._renderGroup = getRenderGroupId(zoomItem, (_f = params.viewer) === null || _f === void 0 ? void 0 : _f.terrainProvider);
5683
6448
  cEntities[entity.Bruce.ID] = cEntity;
5684
- _j.label = 7;
6449
+ _k.label = 7;
5685
6450
  case 7: return [2 /*return*/];
5686
6451
  }
5687
6452
  });
5688
6453
  };
5689
6454
  i = 0;
5690
- _g.label = 11;
6455
+ _h.label = 11;
5691
6456
  case 11:
5692
6457
  if (!(i < params.entities.length)) return [3 /*break*/, 14];
5693
6458
  return [5 /*yield**/, _loop_2(i)];
5694
6459
  case 12:
5695
- _g.sent();
5696
- _g.label = 13;
6460
+ _h.sent();
6461
+ _h.label = 13;
5697
6462
  case 13:
5698
6463
  i++;
5699
6464
  return [3 /*break*/, 11];
@@ -8997,7 +9762,8 @@ var EntitiesRenderManager;
8997
9762
  // So for multiple tags we'll manually sort on UI end...
8998
9763
  tagIds: (tagsToRender === null || tagsToRender === void 0 ? void 0 : tagsToRender.length) ? tagsToRender : [],
8999
9764
  debugShowBounds: Boolean(window === null || window === void 0 ? void 0 : window.ENTITIES_RENDER_MANAGER_SHOW_BOUNDS),
9000
- cdn: this.item.cdnEnabled
9765
+ cdn: this.item.cdnEnabled,
9766
+ historicAttrKey: this.item.BruceEntity.historicAttrKey
9001
9767
  });
9002
9768
  var minMax = RenderManager.GetZoomMinMax({
9003
9769
  zoomControl: this.item.CameraZoomSettings
@@ -9559,23 +10325,37 @@ var EntitiesRenderManager;
9559
10325
  * @returns
9560
10326
  */
9561
10327
  Manager.prototype.renderAsIndividuals = function (entities, force) {
9562
- var _a, _b, _c;
10328
+ var _a, _b, _c, _d, _e, _f, _g;
9563
10329
  if (force === void 0) { force = false; }
9564
10330
  return __awaiter(this, void 0, void 0, function () {
9565
- var cEntities, i, entity, id, cEntity, visual, wasClustered, tagIds, rego;
9566
- return __generator(this, function (_d) {
9567
- switch (_d.label) {
9568
- case 0: return [4 /*yield*/, EntityRenderEngine.Render({
9569
- viewer: this.viewer,
9570
- apiGetter: this.apiGetter,
9571
- entities: entities,
9572
- menuItemId: this.item.id,
9573
- visualRegister: this.visualsManager,
9574
- zoomControl: this.item.CameraZoomSettings,
9575
- force: force
9576
- })];
10331
+ var toRemove, i, entity, cEntities, i, entity, id, cEntity, visual, wasClustered, tagIds, rego;
10332
+ return __generator(this, function (_h) {
10333
+ switch (_h.label) {
10334
+ case 0:
10335
+ if ((_a = this.item.BruceEntity) === null || _a === void 0 ? void 0 : _a.historicAttrKey) {
10336
+ toRemove = entities.filter(function (x) { var _a; return !((_a = x.Bruce) === null || _a === void 0 ? void 0 : _a.historicAttrKey); });
10337
+ for (i = 0; i < toRemove.length; i++) {
10338
+ entity = toRemove[i];
10339
+ this.visualsManager.RemoveRegos({
10340
+ entityId: entity.Bruce.ID,
10341
+ menuItemId: this.item.id,
10342
+ requestRender: false
10343
+ });
10344
+ (_b = this.clustering) === null || _b === void 0 ? void 0 : _b.RemoveEntity(entity.Bruce.ID, false);
10345
+ }
10346
+ entities = entities.filter(function (x) { var _a; return !!((_a = x.Bruce) === null || _a === void 0 ? void 0 : _a.historicAttrKey); });
10347
+ }
10348
+ return [4 /*yield*/, EntityRenderEngine.Render({
10349
+ viewer: this.viewer,
10350
+ apiGetter: this.apiGetter,
10351
+ entities: entities,
10352
+ menuItemId: this.item.id,
10353
+ visualRegister: this.visualsManager,
10354
+ zoomControl: this.item.CameraZoomSettings,
10355
+ force: force
10356
+ })];
9577
10357
  case 1:
9578
- cEntities = _d.sent();
10358
+ cEntities = _h.sent();
9579
10359
  if (this.disposed) {
9580
10360
  this.doDispose();
9581
10361
  return [2 /*return*/];
@@ -9586,13 +10366,13 @@ var EntitiesRenderManager;
9586
10366
  cEntity = cEntities[id];
9587
10367
  this.renderedEntities[id] = !!cEntity;
9588
10368
  if (cEntity) {
9589
- visual = (_a = this.visualsManager.GetRego({
10369
+ visual = (_c = this.visualsManager.GetRego({
9590
10370
  entityId: id,
9591
10371
  menuItemId: this.item.id
9592
- })) === null || _a === void 0 ? void 0 : _a.visual;
10372
+ })) === null || _c === void 0 ? void 0 : _c.visual;
9593
10373
  if (!visual || visual != cEntity) {
9594
10374
  wasClustered = this.clustering ? this.clustering.AddEntity(id, cEntity, false) : false;
9595
- tagIds = (_b = entity.Bruce) === null || _b === void 0 ? void 0 : _b["Layer.ID"];
10375
+ tagIds = (_d = entity.Bruce) === null || _d === void 0 ? void 0 : _d["Layer.ID"];
9596
10376
  rego = {
9597
10377
  entityId: id,
9598
10378
  menuItemId: this.item.id,
@@ -9603,7 +10383,9 @@ var EntitiesRenderManager;
9603
10383
  tagIds: tagIds ? [].concat(tagIds) : [],
9604
10384
  overrideShow: wasClustered ? false : null,
9605
10385
  name: cEntity.name,
9606
- cdn: this.item.cdnEnabled
10386
+ cdn: this.item.cdnEnabled,
10387
+ historicDateTime: (_e = entity.Bruce) === null || _e === void 0 ? void 0 : _e.historicDateTime,
10388
+ historicAttrKey: (_f = entity.Bruce) === null || _f === void 0 ? void 0 : _f.historicAttrKey
9607
10389
  };
9608
10390
  this.visualsManager.AddRego({
9609
10391
  rego: rego,
@@ -9617,7 +10399,7 @@ var EntitiesRenderManager;
9617
10399
  menuItemId: this.item.id,
9618
10400
  requestRender: false
9619
10401
  });
9620
- (_c = this.clustering) === null || _c === void 0 ? void 0 : _c.RemoveEntity(id, false);
10402
+ (_g = this.clustering) === null || _g === void 0 ? void 0 : _g.RemoveEntity(id, false);
9621
10403
  }
9622
10404
  }
9623
10405
  this.viewer.scene.requestRender();
@@ -11798,6 +12580,16 @@ var TilesetRenderEngine;
11798
12580
  };
11799
12581
  Styler.prototype.QueueEntities = function (entities, highPriority) {
11800
12582
  if (highPriority === void 0) { highPriority = false; }
12583
+ // We set a default colour right away to avoid race conditions at later times.
12584
+ for (var i = 0; i < entities.length; i++) {
12585
+ var entity = entities[i];
12586
+ this.styledEntityIds[entity.entityId] = true;
12587
+ CesiumEntityStyler.BakeDefaultColor({
12588
+ entity: entity.visual,
12589
+ viewer: this.viewer,
12590
+ override: false
12591
+ });
12592
+ }
11801
12593
  for (var i = 0; i < entities.length; i++) {
11802
12594
  var entity = entities[i];
11803
12595
  this.queueTilesetFeatureStyle(entity, highPriority);
@@ -12829,12 +13621,13 @@ var EntityFilterGetter;
12829
13621
  EStatus["Loading"] = "LOADING";
12830
13622
  })(EStatus = EntityFilterGetter.EStatus || (EntityFilterGetter.EStatus = {}));
12831
13623
  var Getter = /** @class */ (function () {
12832
- function Getter(api, viewPort, typeId, batchSize, attrFilter, viaCdn) {
13624
+ function Getter(api, viewer, viewPort, typeId, batchSize, attrFilter, historicAttrKey, viaCdn) {
12833
13625
  this.onUpdate = null;
12834
13626
  this.LastStateUpdates = {};
12835
13627
  this.onStateUpdate = null;
12836
13628
  this.onScanUpdate = null;
12837
13629
  this.viewPortChangeRemoval = null;
13630
+ this.viewerDateTimeChangeRemoval = null;
12838
13631
  this.cells = null;
12839
13632
  this.registeredItems = {};
12840
13633
  this.getterLoopId = 0;
@@ -12845,10 +13638,12 @@ var EntityFilterGetter;
12845
13638
  this.viewCenter = null;
12846
13639
  this.api = api;
12847
13640
  this.typeId = typeId;
13641
+ this.historicAttrKey = historicAttrKey;
12848
13642
  this.viaCdn = Boolean(viaCdn);
12849
13643
  this.batchSize = isNaN(batchSize) ? 300 : batchSize;
12850
13644
  this.viewPort = viewPort;
12851
13645
  this.attrFilter = attrFilter;
13646
+ this.viewer = viewer;
12852
13647
  this.updateBounds();
12853
13648
  }
12854
13649
  Object.defineProperty(Getter.prototype, "OnUpdate", {
@@ -12887,7 +13682,14 @@ var EntityFilterGetter;
12887
13682
  * @returns
12888
13683
  */
12889
13684
  Getter.prototype.getIntegrityId = function () {
12890
- return this.tagIds == null ? "" : this.tagIds.join();
13685
+ var integrity = this.tagIds == null ? "" : this.tagIds.join();
13686
+ if (this.historicAttrKey) {
13687
+ integrity += this.historicAttrKey;
13688
+ if (this.historicAttrDateTime) {
13689
+ integrity += this.historicAttrDateTime;
13690
+ }
13691
+ }
13692
+ return integrity;
12891
13693
  };
12892
13694
  Getter.prototype.viewAreaSub = function () {
12893
13695
  var _this = this;
@@ -12900,6 +13702,57 @@ var EntityFilterGetter;
12900
13702
  Getter.prototype.viewAreaDispose = function () {
12901
13703
  var _a;
12902
13704
  (_a = this.viewPortChangeRemoval) === null || _a === void 0 ? void 0 : _a.call(this);
13705
+ this.viewPortChangeRemoval = null;
13706
+ };
13707
+ /**
13708
+ * Monitors the Cesium viewer and updates the historic data filter values.
13709
+ * If there is no historic attr set, this will do nothing.
13710
+ */
13711
+ Getter.prototype.viewerDateTimeSub = function () {
13712
+ var _this = this;
13713
+ this.viewerDateTimeDispose();
13714
+ if (!this.historicAttrKey) {
13715
+ return;
13716
+ }
13717
+ var delayQueue = new DelayQueue(function () {
13718
+ var current = _this.getIntegrityId();
13719
+ _this.updateHistoricDateTime();
13720
+ if (current != _this.getIntegrityId()) {
13721
+ _this.updateState();
13722
+ }
13723
+ }, 250);
13724
+ var postUpdateRemoval = this.viewer.scene.postUpdate.addEventListener(function () {
13725
+ if (delayQueue) {
13726
+ delayQueue.Call();
13727
+ }
13728
+ });
13729
+ this.viewerDateTimeChangeRemoval = function () {
13730
+ delayQueue === null || delayQueue === void 0 ? void 0 : delayQueue.Dispose();
13731
+ postUpdateRemoval === null || postUpdateRemoval === void 0 ? void 0 : postUpdateRemoval();
13732
+ delayQueue = null;
13733
+ postUpdateRemoval = null;
13734
+ };
13735
+ };
13736
+ Getter.prototype.updateHistoricDateTime = function () {
13737
+ var newDateTime = JulianDate.toDate(this.viewer.clock.currentTime);
13738
+ // Has previous value. Let's compare.
13739
+ if (this.historicAttrDateTime) {
13740
+ var oldDateTime = new Date(this.historicAttrDateTime);
13741
+ // Change must be at least 0.1 seconds.
13742
+ // TODO: This is just a random value I picked. We may need to make a setting or refine this.
13743
+ if (Math.abs(newDateTime.getTime() - oldDateTime.getTime()) < 100) {
13744
+ return;
13745
+ }
13746
+ }
13747
+ this.historicAttrDateTime = newDateTime.toISOString();
13748
+ // Set min/max to be the value increased/decreased by 1 minute.
13749
+ this.historicAttrDateTimeMin = new Date(newDateTime.getTime() - 60000).toISOString();
13750
+ this.historicAttrDateTimeMax = new Date(newDateTime.getTime() + 60000).toISOString();
13751
+ };
13752
+ Getter.prototype.viewerDateTimeDispose = function () {
13753
+ var _a;
13754
+ (_a = this.viewerDateTimeChangeRemoval) === null || _a === void 0 ? void 0 : _a.call(this);
13755
+ this.viewerDateTimeChangeRemoval = null;
12903
13756
  };
12904
13757
  Getter.prototype.GetMenuItems = function () {
12905
13758
  return Object.keys(this.registeredItems);
@@ -12959,8 +13812,10 @@ var EntityFilterGetter;
12959
13812
  this.minHeight = minHeight;
12960
13813
  this.maxHeight = maxHeight;
12961
13814
  this.updateBounds();
13815
+ this.updateHistoricDateTime();
12962
13816
  this.startGetterLoop();
12963
13817
  this.viewAreaSub();
13818
+ this.viewerDateTimeSub();
12964
13819
  }
12965
13820
  else {
12966
13821
  this.getterLoopId += 1;
@@ -13056,6 +13911,9 @@ var EntityFilterGetter;
13056
13911
  _j.trys.push([8, 10, , 11]);
13057
13912
  return [4 /*yield*/, Entity$1.GetList({
13058
13913
  api: this.api,
13914
+ historicKey: this.historicAttrKey,
13915
+ historicFrom: this.historicAttrKey ? this.historicAttrDateTimeMin : null,
13916
+ historicTo: this.historicAttrKey ? this.historicAttrDateTimeMax : null,
13059
13917
  filter: {
13060
13918
  pageSize: PAGE_SIZE,
13061
13919
  pageIndex: curCell.FetchPageIndex,
@@ -13153,6 +14011,7 @@ function createFilterGetterCacheKey(params) {
13153
14011
  cacheKey += params.batchSize;
13154
14012
  cacheKey += String(params.cdn);
13155
14013
  cacheKey += JSON.stringify(params.tagIds ? params.tagIds : []);
14014
+ cacheKey += params.historicAttrKey ? params.historicAttrKey : "";
13156
14015
  // This could potentially crash, but if it crashes here then it would crash during API request anyways.
13157
14016
  cacheKey += JSON.stringify(params.attrFilter ? params.attrFilter : {});
13158
14017
  return cacheKey;
@@ -13168,7 +14027,7 @@ var SharedGetters;
13168
14027
  var cacheKey = createFilterGetterCacheKey(params);
13169
14028
  var getter = this.data[cacheKey];
13170
14029
  if (!getter) {
13171
- getter = new EntityFilterGetter.Getter(params.api, params.monitor, params.typeId, params.batchSize, params.attrFilter, params.cdn);
14030
+ getter = new EntityFilterGetter.Getter(params.api, params.viewer, params.monitor, params.typeId, params.batchSize, params.attrFilter, params.historicAttrKey, params.cdn);
13172
14031
  this.data[cacheKey] = getter;
13173
14032
  /**
13174
14033
  * Debug option.
@@ -22578,7 +23437,7 @@ var ViewRenderEngine;
22578
23437
  ViewRenderEngine.Render = Render;
22579
23438
  })(ViewRenderEngine || (ViewRenderEngine = {}));
22580
23439
 
22581
- var VERSION = "3.7.3";
23440
+ var VERSION = "3.7.5";
22582
23441
 
22583
23442
  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, CESIUM_TIMELINE_KEY, ViewUtils, DrawingUtils, MeasureUtils, EntityUtils, CesiumEntityStyler, Draw3dPolygon, Draw3dPolyline };
22584
23443
  //# sourceMappingURL=bruce-cesium.es5.js.map