bruce-cesium 6.9.7 → 6.9.8

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 +469 -38
  2. package/dist/bruce-cesium.es5.js.map +1 -1
  3. package/dist/bruce-cesium.umd.js +467 -36
  4. package/dist/bruce-cesium.umd.js.map +1 -1
  5. package/dist/lib/bruce-cesium.js +1 -1
  6. package/dist/lib/internal/image-utils.js +35 -0
  7. package/dist/lib/internal/image-utils.js.map +1 -0
  8. package/dist/lib/internal/series-segment.js +3 -0
  9. package/dist/lib/internal/series-segment.js.map +1 -0
  10. package/dist/lib/rendering/entity-render-engine-polygon.js +114 -34
  11. package/dist/lib/rendering/entity-render-engine-polygon.js.map +1 -1
  12. package/dist/lib/rendering/entity-render-engine.js +1 -0
  13. package/dist/lib/rendering/entity-render-engine.js.map +1 -1
  14. package/dist/lib/rendering/menu-item-manager.js +46 -1
  15. package/dist/lib/rendering/menu-item-manager.js.map +1 -1
  16. package/dist/lib/rendering/render-managers/entities/entities-render-manager.js +3 -1
  17. package/dist/lib/rendering/render-managers/entities/entities-render-manager.js.map +1 -1
  18. package/dist/lib/rendering/texture-frame-series-animator.js +281 -0
  19. package/dist/lib/rendering/texture-frame-series-animator.js.map +1 -0
  20. package/dist/types/bruce-cesium.d.ts +1 -1
  21. package/dist/types/internal/image-utils.d.ts +10 -0
  22. package/dist/types/internal/series-segment.d.ts +10 -0
  23. package/dist/types/rendering/entity-render-engine-polygon.d.ts +4 -0
  24. package/dist/types/rendering/entity-render-engine.d.ts +2 -0
  25. package/dist/types/rendering/menu-item-manager.d.ts +19 -0
  26. package/dist/types/rendering/render-managers/entities/entities-render-manager.d.ts +3 -0
  27. package/dist/types/rendering/texture-frame-series-animator.d.ts +93 -0
  28. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import * as Cesium from 'cesium';
2
- import { Cartographic, ColorMaterialProperty, Entity, Color, ConstantProperty, CallbackProperty, Primitive, Cesium3DTileFeature, DistanceDisplayCondition, HeightReference, HorizontalOrigin, VerticalOrigin, Cartesian3, ClassificationType, ConstantPositionProperty, ArcType, CornerType, ShadowMode, Math as Math$1, JulianDate, Quaternion, Transforms, HeadingPitchRoll, Matrix4, ColorBlendMode, Model, ImageMaterialProperty, PolygonHierarchy, PolylineGraphics, Cartesian2, SceneTransforms, NearFarScalar, Matrix3, Rectangle, KmlDataSource, GeoJsonDataSource, SceneMode, Cesium3DTileStyle, HeadingPitchRange, Ion, IonResource, Cesium3DTileColorBlendMode, Cesium3DTileset, EllipsoidTerrainProvider, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, OrthographicFrustum, EasingFunction, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, EllipsoidGeodesic, sampleTerrainMostDetailed, defined, PolygonPipeline, CesiumInspector, ClockRange, ScreenSpaceEventHandler, ScreenSpaceEventType, BoundingSphere, GeometryInstance, Fullscreen, Intersect, CzmlDataSource } from 'cesium';
3
- import { Cartes, Entity as Entity$1, ENVIRONMENT, Api, Calculator, ClientFile, EntityTag, EntityType, LRUCache, ObjectUtils, Style, Carto, Geometry, EntityLod, MenuItem, ProjectView, ProjectViewBookmark, Tileset, ZoomControl, BruceEvent, EntityCoords, Bounds, Color as Color$1, DataLab, DelayQueue, EntityHistoricData, BruceApi, EntityRelation, AccountConcept, RecordChangeFeed, ProgramKey, EntitySource, ProjectViewLegacyTile, ProjectViewTile, Camera, Session, EntityAttachment, EntityAttachmentType, EntityAttribute, MathUtils, EntityRelationType } from 'bruce-models';
2
+ import { Cartographic, ColorMaterialProperty, Entity, Color, ConstantProperty, CallbackProperty, Primitive, Cesium3DTileFeature, DistanceDisplayCondition, HeightReference, ColorBlendMode, HeadingPitchRoll, Math as Math$1, Transforms, ShadowMode, Cartesian3, ClassificationType, Model, HorizontalOrigin, VerticalOrigin, ConstantPositionProperty, JulianDate, Quaternion, Matrix4, ArcType, CornerType, ImageMaterialProperty, PolygonHierarchy, PolylineGraphics, Cartesian2, SceneTransforms, NearFarScalar, Matrix3, Rectangle, KmlDataSource, GeoJsonDataSource, SceneMode, Cesium3DTileStyle, HeadingPitchRange, Ion, IonResource, Cesium3DTileColorBlendMode, EllipsoidTerrainProvider, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, Cesium3DTileset, OrthographicFrustum, EasingFunction, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, EllipsoidGeodesic, sampleTerrainMostDetailed, defined, PolygonPipeline, CesiumInspector, ClockRange, BoundingSphere, GeometryInstance, ScreenSpaceEventHandler, ScreenSpaceEventType, Fullscreen, Intersect, CzmlDataSource } from 'cesium';
3
+ import { Cartes, Entity as Entity$1, ENVIRONMENT, Calculator, ClientFile, EntityLod, EntityTag, EntityType, LRUCache, ObjectUtils, Style, Api, Carto, Geometry, MenuItem, ProjectView, ProjectViewBookmark, Tileset, ZoomControl, Bounds, Color as Color$1, BruceEvent, EntityCoords, DelayQueue, EntityHistoricData, DataLab, BruceApi, EntityRelation, AccountConcept, RecordChangeFeed, ProgramKey, ProjectViewLegacyTile, ProjectViewTile, EntitySource, Camera, EntityAttachment, EntityAttachmentType, EntityAttribute, MathUtils, Session, EntityRelationType } from 'bruce-models';
4
4
 
5
5
  /**
6
6
  * Ensures a number is returned from a given value.
@@ -9686,13 +9686,14 @@ var EntitiesRenderManager;
9686
9686
  // Type IDs that we'll allow to be rendered when receiving Entities.
9687
9687
  // This might be exactly the Menu Item Type ID because of local data sources.
9688
9688
  this.allowedTypeIDs = [];
9689
- const { viewer, apiGetter, monitor, item, register: visualsManager, sharedGetters } = params;
9689
+ const { viewer, apiGetter, monitor, item, register: visualsManager, sharedGetters, onSeriesDiscovered } = params;
9690
9690
  this.viewer = viewer;
9691
9691
  this.sharedGetters = sharedGetters;
9692
9692
  this.monitor = monitor;
9693
9693
  this.apiGetter = apiGetter;
9694
9694
  this.item = item;
9695
9695
  this.visualsManager = visualsManager;
9696
+ this.onSeriesDiscovered = onSeriesDiscovered;
9696
9697
  this.useGeojson = item.renderAsGeojson == true;
9697
9698
  if (item.enableClustering) {
9698
9699
  this.clustering = new PointClustering(this.visualsManager, this.item.id);
@@ -10661,6 +10662,7 @@ var EntitiesRenderManager;
10661
10662
  apiGetter: this.apiGetter,
10662
10663
  entities: entities,
10663
10664
  menuItemId: this.item.id,
10665
+ onSeriesDiscovered: this.onSeriesDiscovered,
10664
10666
  visualRegister: this.visualsManager,
10665
10667
  zoomControl: this.zoomControl,
10666
10668
  entitiesHistoric: entitiesHistoric,
@@ -22270,6 +22272,46 @@ var MenuItemManager;
22270
22272
  }
22271
22273
  return this.onUpdate;
22272
22274
  }
22275
+ get OnSeriesUpdated() {
22276
+ if (!this.onSeriesUpdated) {
22277
+ this.onSeriesUpdated = new BruceEvent();
22278
+ }
22279
+ return this.onSeriesUpdated;
22280
+ }
22281
+ /**
22282
+ * Currently known series segments for a menu item (empty array if none discovered yet).
22283
+ */
22284
+ GetSeriesSegments(itemId) {
22285
+ return this.seriesSegments.get(itemId) || [];
22286
+ }
22287
+ /**
22288
+ * @param itemId
22289
+ * @param segment
22290
+ */
22291
+ RecordSeriesSegment(itemId, segment) {
22292
+ const existing = this.seriesSegments.get(itemId) || [];
22293
+ const idx = existing.findIndex((s) => s.key === segment.key);
22294
+ if (idx !== -1) {
22295
+ const current = existing[idx];
22296
+ if (current.min.getTime() === segment.min.getTime() && current.max.getTime() === segment.max.getTime() && current.label === segment.label) {
22297
+ return; // No-op.
22298
+ }
22299
+ existing[idx] = segment;
22300
+ }
22301
+ else {
22302
+ existing.push(segment);
22303
+ }
22304
+ this.seriesSegments.set(itemId, existing);
22305
+ this.OnSeriesUpdated.Trigger({ itemId, segments: existing });
22306
+ }
22307
+ /**
22308
+ * Clears any series segments recorded for a menu item, eg when it's disabled/removed.
22309
+ */
22310
+ ClearSeriesSegments(itemId) {
22311
+ if (this.seriesSegments.delete(itemId)) {
22312
+ this.OnSeriesUpdated.Trigger({ itemId, segments: [] });
22313
+ }
22314
+ }
22273
22315
  get Monitor() {
22274
22316
  return this.sharedMonitor;
22275
22317
  }
@@ -22277,6 +22319,9 @@ var MenuItemManager;
22277
22319
  this.items = [];
22278
22320
  this.pendingHandoffPool = [];
22279
22321
  this.onUpdate = null;
22322
+ // Segments discovered so far per menu item ID.
22323
+ this.seriesSegments = new Map();
22324
+ this.onSeriesUpdated = null;
22280
22325
  let { viewer, visualsRegister, getters } = params;
22281
22326
  this.viewer = viewer;
22282
22327
  if (!getters) {
@@ -22502,7 +22547,8 @@ var MenuItemManager;
22502
22547
  apiGetter: params.apiGetter,
22503
22548
  monitor: this.sharedMonitor,
22504
22549
  item: params.item,
22505
- sharedGetters: this.sharedGetters
22550
+ sharedGetters: this.sharedGetters,
22551
+ onSeriesDiscovered: (segment) => this.RecordSeriesSegment(rItem.id, segment)
22506
22552
  });
22507
22553
  break;
22508
22554
  case MenuItem.EType.EntitiesLoaded:
@@ -22728,6 +22774,7 @@ var MenuItemManager;
22728
22774
  }
22729
22775
  }
22730
22776
  this.items = this.items.filter(x => x.id !== id);
22777
+ this.ClearSeriesSegments(item.id);
22731
22778
  (_b = this.onUpdate) === null || _b === void 0 ? void 0 : _b.Trigger({ isEnabling: false, itemId: item.id });
22732
22779
  }
22733
22780
  }
@@ -36724,6 +36771,312 @@ function getHeightRef$2(style, defaultStyle) {
36724
36771
  return heightRef;
36725
36772
  }
36726
36773
 
36774
+ /**
36775
+ * Remaps a (assumed grayscale, server-rendered black-to-white) image's pixels into a gradient between minColor/maxColor,
36776
+ * preserving source alpha blended with the mask's own alpha.
36777
+ * @param imageData
36778
+ * @param minColor
36779
+ * @param maxColor
36780
+ */
36781
+ function ApplyGrayscaleColorMask(imageData, minColor, maxColor) {
36782
+ const data = imageData.data;
36783
+ for (let i = 0; i < data.length; i += 4) {
36784
+ // The texture is rendered black-to-white server-side, so any channel carries the value.
36785
+ const t = data[i] / 255;
36786
+ data[i] = Math.round(minColor.red + (maxColor.red - minColor.red) * t);
36787
+ data[i + 1] = Math.round(minColor.green + (maxColor.green - minColor.green) * t);
36788
+ data[i + 2] = Math.round(minColor.blue + (maxColor.blue - minColor.blue) * t);
36789
+ // Preserve source transparency (eg unrasterized pixels) blended with the mask's own alpha.
36790
+ const srcAlpha = data[i + 3] / 255;
36791
+ const maskAlpha = minColor.alpha + (maxColor.alpha - minColor.alpha) * t;
36792
+ data[i + 3] = Math.round(srcAlpha * maskAlpha * 255);
36793
+ }
36794
+ }
36795
+ function loadImage(src) {
36796
+ return new Promise((res, rej) => {
36797
+ const image = new Image();
36798
+ image.onload = () => res(image);
36799
+ image.onerror = (e) => rej(e);
36800
+ image.src = src;
36801
+ });
36802
+ }
36803
+
36804
+ var TextureFrameSeriesAnimator;
36805
+ (function (TextureFrameSeriesAnimator) {
36806
+ /**
36807
+ * Detects whether a ClientFile's `Data.generation` metadata describes a frame archive rather than a single static image,
36808
+ * so a caller can decide whether to construct an Animator or fall back to the existing static-texture path.
36809
+ * @param data ClientFile.Data (the `IFile.Data` field), as returned by ClientFile.Get().
36810
+ */
36811
+ function IsFrameArchiveMetadata(data) {
36812
+ return Boolean(data && data.generation && Array.isArray(data.generation.Frames) && data.generation.Frames.length > 0);
36813
+ }
36814
+ TextureFrameSeriesAnimator.IsFrameArchiveMetadata = IsFrameArchiveMetadata;
36815
+ const DEFAULT_CROSSFADE_MS = 900;
36816
+ const DEFAULT_LOW_COLOR = { red: 255, green: 255, blue: 255, alpha: 0.12 };
36817
+ const DEFAULT_HIGH_COLOR = { red: 21, green: 96, blue: 196, alpha: 0.92 };
36818
+ class Animator {
36819
+ constructor(options) {
36820
+ var _a;
36821
+ this.removeOnTick = null;
36822
+ this.removeCrossfadeTick = null;
36823
+ this.disposed = false;
36824
+ this.currentFrameIndex = -1;
36825
+ // Single-in-flight fetch queue: only one Range GET outstanding at a time, and the NEXT one
36826
+ // is chosen right before sending, this is what makes reprioritizing mid-scrub take effect
36827
+ // immediately instead of draining a backlog of stale requests first.
36828
+ this.inFlightIndex = -1;
36829
+ this.pendingIndex = -1;
36830
+ this.displayedPixels = null;
36831
+ this.fadeFromPixels = null;
36832
+ this.fadeToIndex = -1;
36833
+ this.fadeToDims = null;
36834
+ this.fadeStartMs = null;
36835
+ // Two-canvas pool: Cesium compares image references each frame, so alternating between
36836
+ // pool[0]/pool[1] gives a new object reference whenever we actually present a new frame,
36837
+ // forcing Cesium to re-upload the texture only when something changed.
36838
+ this.pool = [document.createElement("canvas"), document.createElement("canvas")];
36839
+ this.poolIdx = 0;
36840
+ if (!options.entity.polygon) {
36841
+ throw new Error("TextureFrameSeriesAnimator requires an entity with polygon graphics.");
36842
+ }
36843
+ if (!options.frames || options.frames.length === 0) {
36844
+ throw new Error("TextureFrameSeriesAnimator requires at least one frame.");
36845
+ }
36846
+ this.viewer = options.viewer;
36847
+ this.entity = options.entity;
36848
+ this.archiveUrl = options.archiveUrl;
36849
+ this.frames = options.frames;
36850
+ this.crossfadeMs = (_a = options.crossfadeMs) !== null && _a !== void 0 ? _a : DEFAULT_CROSSFADE_MS;
36851
+ const mask = options.textureColorMask;
36852
+ this.lowColor = (mask && Color$1.ColorFromStr(mask.minColor)) || DEFAULT_LOW_COLOR;
36853
+ this.highColor = (mask && Color$1.ColorFromStr(mask.maxColor)) || DEFAULT_HIGH_COLOR;
36854
+ this.frameDates = this.frames.map((f) => JulianDate.fromIso8601(f.Timestamp));
36855
+ this.frameCache = new Array(this.frames.length).fill(null);
36856
+ this.frameDims = new Array(this.frames.length).fill(null);
36857
+ this.originalMaterial = options.entity.polygon.material;
36858
+ this.imageProperty = new CallbackProperty(() => this.pool[this.poolIdx], false);
36859
+ options.entity.polygon.material = new ImageMaterialProperty({ image: this.imageProperty, transparent: true });
36860
+ this.removeCrossfadeTick = this.viewer.scene.postUpdate.addEventListener(() => this.tickCrossfade());
36861
+ this.removeOnTick = this.viewer.clock.onTick.addEventListener((clock) => this.onClockTick(clock.currentTime));
36862
+ this.onClockTick(this.viewer.clock.currentTime);
36863
+ }
36864
+ /**
36865
+ * Explicit teardown: stops driving the entity's material, abandons any in-flight/pending fetch (results are simply ignored when they land),
36866
+ * and restores whatever material the entity had before construction. Never called automatically.
36867
+ */
36868
+ Dispose() {
36869
+ if (this.disposed) {
36870
+ return;
36871
+ }
36872
+ this.disposed = true;
36873
+ if (this.removeOnTick) {
36874
+ this.removeOnTick();
36875
+ this.removeOnTick = null;
36876
+ }
36877
+ if (this.removeCrossfadeTick) {
36878
+ this.removeCrossfadeTick();
36879
+ this.removeCrossfadeTick = null;
36880
+ }
36881
+ if (this.entity && this.entity.polygon) {
36882
+ this.entity.polygon.material = this.originalMaterial;
36883
+ }
36884
+ }
36885
+ IsDisposed() {
36886
+ return this.disposed;
36887
+ }
36888
+ /**
36889
+ * The archive URL this instance was constructed with,
36890
+ * lets a caller re-rendering the same entity tell whether an existing instance is already correct, without reaching into private state.
36891
+ */
36892
+ GetArchiveUrl() {
36893
+ return this.archiveUrl;
36894
+ }
36895
+ onClockTick(currentTime) {
36896
+ if (this.disposed) {
36897
+ return;
36898
+ }
36899
+ this.swapToFrame(this.findFrameIndex(currentTime));
36900
+ }
36901
+ // Binary-search the frame whose timestamp is <= currentTime.
36902
+ findFrameIndex(currentTime) {
36903
+ const dates = this.frameDates;
36904
+ let lo = 0;
36905
+ let hi = dates.length - 1;
36906
+ if (JulianDate.lessThanOrEquals(currentTime, dates[0])) {
36907
+ return 0;
36908
+ }
36909
+ if (JulianDate.greaterThanOrEquals(currentTime, dates[hi])) {
36910
+ return hi;
36911
+ }
36912
+ while (lo < hi) {
36913
+ const mid = (lo + hi + 1) >> 1;
36914
+ if (JulianDate.lessThanOrEquals(dates[mid], currentTime)) {
36915
+ lo = mid;
36916
+ }
36917
+ else {
36918
+ hi = mid - 1;
36919
+ }
36920
+ }
36921
+ return lo;
36922
+ }
36923
+ // Called with the discrete target frame (never a fractional/interpolated index).
36924
+ // Scrubbing rapidly just retargets what's fetched next.
36925
+ swapToFrame(idx) {
36926
+ if (idx === this.currentFrameIndex) {
36927
+ return;
36928
+ }
36929
+ this.currentFrameIndex = idx;
36930
+ if (this.frameCache[idx]) {
36931
+ this.beginCrossfadeTo(idx);
36932
+ return;
36933
+ }
36934
+ this.ensureFrame(idx);
36935
+ }
36936
+ ensureFrame(idx) {
36937
+ if (this.frameCache[idx]) {
36938
+ return;
36939
+ }
36940
+ if (this.inFlightIndex === idx) {
36941
+ return;
36942
+ }
36943
+ this.pendingIndex = idx;
36944
+ this.pumpFetchQueue();
36945
+ }
36946
+ // Nearest still-uncached frame to wherever the viewer CURRENTLY is.
36947
+ nearestUncachedFrame() {
36948
+ const n = this.frameCache.length;
36949
+ if (this.currentFrameIndex < 0) {
36950
+ return this.frameCache[0] ? -1 : 0;
36951
+ }
36952
+ for (let d = 0; d < n; d++) {
36953
+ const forward = this.currentFrameIndex + d;
36954
+ if (forward < n && !this.frameCache[forward]) {
36955
+ return forward;
36956
+ }
36957
+ const backward = this.currentFrameIndex - d;
36958
+ if (backward >= 0 && !this.frameCache[backward]) {
36959
+ return backward;
36960
+ }
36961
+ }
36962
+ return -1;
36963
+ }
36964
+ pumpFetchQueue() {
36965
+ if (this.disposed || this.inFlightIndex !== -1) {
36966
+ return;
36967
+ }
36968
+ let next = -1;
36969
+ if (this.pendingIndex !== -1) {
36970
+ next = this.pendingIndex;
36971
+ this.pendingIndex = -1;
36972
+ }
36973
+ else {
36974
+ next = this.nearestUncachedFrame();
36975
+ }
36976
+ if (next === -1) {
36977
+ return;
36978
+ }
36979
+ this.inFlightIndex = next;
36980
+ this.fetchAndTint(next)
36981
+ .catch(() => {
36982
+ // Eating it.
36983
+ })
36984
+ .finally(() => {
36985
+ this.inFlightIndex = -1;
36986
+ if (!this.disposed) {
36987
+ this.pumpFetchQueue();
36988
+ }
36989
+ });
36990
+ }
36991
+ async fetchAndTint(idx) {
36992
+ const entry = this.frames[idx];
36993
+ const start = entry.ByteOffset;
36994
+ const end = entry.ByteOffset + entry.ByteLength - 1;
36995
+ const response = await fetch(this.archiveUrl, { headers: { Range: `bytes=${start}-${end}` } });
36996
+ const buffer = await response.arrayBuffer();
36997
+ if (this.disposed) {
36998
+ return;
36999
+ }
37000
+ const decoded = await this.decodeAndTint(buffer);
37001
+ if (this.disposed) {
37002
+ return;
37003
+ }
37004
+ this.frameCache[idx] = decoded.pixels;
37005
+ this.frameDims[idx] = { width: decoded.width, height: decoded.height };
37006
+ if (idx === this.currentFrameIndex) {
37007
+ this.beginCrossfadeTo(idx);
37008
+ }
37009
+ }
37010
+ /**
37011
+ * Decodes one frame's raw PNG bytes (as returned by a Range GET) and applies the grayscale color mask.
37012
+ */
37013
+ async decodeAndTint(buffer) {
37014
+ const blob = new Blob([buffer], { type: "image/png" });
37015
+ const objectUrl = URL.createObjectURL(blob);
37016
+ let image;
37017
+ try {
37018
+ image = await loadImage(objectUrl);
37019
+ }
37020
+ finally {
37021
+ URL.revokeObjectURL(objectUrl);
37022
+ }
37023
+ const canvas = document.createElement("canvas");
37024
+ canvas.width = image.width;
37025
+ canvas.height = image.height;
37026
+ const ctx = canvas.getContext("2d");
37027
+ ctx.drawImage(image, 0, 0);
37028
+ const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
37029
+ ApplyGrayscaleColorMask(imageData, this.lowColor, this.highColor);
37030
+ return { pixels: imageData.data, width: canvas.width, height: canvas.height };
37031
+ }
37032
+ beginCrossfadeTo(idx) {
37033
+ const to = this.frameCache[idx];
37034
+ this.fadeFromPixels = this.displayedPixels === null ? new Uint8ClampedArray(to.length) : this.displayedPixels;
37035
+ this.fadeToIndex = idx;
37036
+ this.fadeToDims = this.frameDims[idx];
37037
+ this.fadeStartMs = Now();
37038
+ }
37039
+ tickCrossfade() {
37040
+ if (this.disposed || this.fadeStartMs === null) {
37041
+ return;
37042
+ }
37043
+ const t = Math.min(1, (Now() - this.fadeStartMs) / this.crossfadeMs);
37044
+ const eased = easeInOutQuad(t);
37045
+ const from = this.fadeFromPixels;
37046
+ const to = this.frameCache[this.fadeToIndex];
37047
+ const n = Math.min(from.length, to.length);
37048
+ const blended = new Uint8ClampedArray(to.length);
37049
+ for (let i = 0; i < n; i++) {
37050
+ blended[i] = from[i] + (to[i] - from[i]) * eased;
37051
+ }
37052
+ this.presentPixels(blended, this.fadeToDims);
37053
+ if (t >= 1) {
37054
+ this.fadeStartMs = null;
37055
+ this.fadeFromPixels = null;
37056
+ }
37057
+ }
37058
+ presentPixels(pixels, dims) {
37059
+ this.poolIdx = 1 - this.poolIdx;
37060
+ const target = this.pool[this.poolIdx];
37061
+ target.width = dims.width;
37062
+ target.height = dims.height;
37063
+ const ctx = target.getContext("2d");
37064
+ const imgData = ctx.createImageData(dims.width, dims.height);
37065
+ imgData.data.set(pixels);
37066
+ ctx.putImageData(imgData, 0, 0);
37067
+ this.displayedPixels = pixels;
37068
+ }
37069
+ }
37070
+ TextureFrameSeriesAnimator.Animator = Animator;
37071
+ function easeInOutQuad(t) {
37072
+ return t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2;
37073
+ }
37074
+ function Now() {
37075
+ return typeof performance !== "undefined" ? performance.now() : Date.now();
37076
+ }
37077
+ })(TextureFrameSeriesAnimator || (TextureFrameSeriesAnimator = {}));
37078
+
37079
+ const TEXTURE_FRAME_SERIES_ANIMATOR_KEY = "TextureFrameSeriesAnimator.Animator";
36727
37080
  var EntityRenderEnginePolygon;
36728
37081
  (function (EntityRenderEnginePolygon) {
36729
37082
  async function Render(params) {
@@ -36743,6 +37096,7 @@ var EntityRenderEnginePolygon;
36743
37096
  const cFillColor = bFillColor ? ColorToCColor(bFillColor) : Color.fromCssColorString("rgba(139, 195, 74, 0.8)");
36744
37097
  let textureDataUri = null;
36745
37098
  let textureTraceEffective = null;
37099
+ let frameArchive = null;
36746
37100
  if (fillType === Style.EPolygonFillType.Texture) {
36747
37101
  const resolved = await resolveTexturedFill({
36748
37102
  api: params.api,
@@ -36752,11 +37106,14 @@ var EntityRenderEnginePolygon;
36752
37106
  });
36753
37107
  textureDataUri = resolved.dataUri;
36754
37108
  textureTraceEffective = resolved.effective;
37109
+ frameArchive = resolved.frameArchive || null;
36755
37110
  }
36756
- const hasFill = fillType === Style.EPolygonFillType.Texture ? Boolean(textureDataUri) : cFillColor.alpha > 0;
37111
+ const hasFill = fillType === Style.EPolygonFillType.Texture ? Boolean(textureDataUri || frameArchive) : cFillColor.alpha > 0;
36757
37112
  const fillMaterial = textureDataUri
36758
37113
  ? new ImageMaterialProperty({ image: textureDataUri, transparent: true })
36759
- : cFillColor;
37114
+ : frameArchive
37115
+ ? Color.WHITE.withAlpha(0)
37116
+ : cFillColor;
36760
37117
  const lineColorTrace = style.lineColor ? Calculator.TraceGetColor(style.lineColor, entity, params.tags) : { value: null, effective: null };
36761
37118
  const bLineColor = lineColorTrace.value;
36762
37119
  const cLineColor = bLineColor ? ColorToCColor(bLineColor) : Color.fromCssColorString("rgba(80, 80, 80, 0.8)");
@@ -36926,6 +37283,13 @@ var EntityRenderEnginePolygon;
36926
37283
  }
36927
37284
  cEntity.show = true;
36928
37285
  }
37286
+ syncTextureFrameArchive(cEntity, frameArchive, params.viewer, style.textureColorMask);
37287
+ if (frameArchive && params.onSeriesDiscovered) {
37288
+ const segment = frameArchiveToSeriesSegment(frameArchive, params.entity);
37289
+ if (segment) {
37290
+ params.onSeriesDiscovered(segment);
37291
+ }
37292
+ }
36929
37293
  if (hasOutline) {
36930
37294
  let borderHeight = undefined;
36931
37295
  if (heightRef != HeightReference.CLAMP_TO_GROUND) {
@@ -37134,7 +37498,9 @@ var EntityRenderEnginePolygon;
37134
37498
  // Temporarily disabling re-using graphics for polygons as they have some bugs, and
37135
37499
  // they don't support any animation yet.
37136
37500
  // rendered: null
37137
- rendered: (_c = params.rendered) === null || _c === void 0 ? void 0 : _c.get(entity.Bruce.ID)
37501
+ rendered: (_c = params.rendered) === null || _c === void 0 ? void 0 : _c.get(entity.Bruce.ID),
37502
+ menuItemId: params.menuItemId,
37503
+ onSeriesDiscovered: params.onSeriesDiscovered
37138
37504
  });
37139
37505
  if (cEntity) {
37140
37506
  const name = await getName$3(api, entity);
@@ -37250,11 +37616,86 @@ async function getStyle$4(api, entity, styleId) {
37250
37616
  // same polygon (or multiple polygons sharing a texture) don't refetch/reprocess the same image.
37251
37617
  const _textureCache = new LRUCache(50);
37252
37618
  /**
37253
- * Returns if a resolved texture value looks like a URL rather than a client file ID.
37619
+ * Reconciles cEntity's TextureFrameSeriesAnimator.Animator (if any) against this render's resolved texture.
37620
+ * Called once cEntity is fully created/updated and definitely has a `polygon` graphics.
37621
+ * @param cEntity
37622
+ * @param frameArchive
37623
+ * @param viewer
37624
+ * @param textureColorMask
37625
+ */
37626
+ function syncTextureFrameArchive(cEntity, frameArchive, viewer, textureColorMask) {
37627
+ const existing = cEntity[TEXTURE_FRAME_SERIES_ANIMATOR_KEY];
37628
+ if (frameArchive && existing && !existing.IsDisposed() && existing.GetArchiveUrl() === frameArchive.url) {
37629
+ return;
37630
+ }
37631
+ if (existing && !existing.IsDisposed()) {
37632
+ existing.Dispose();
37633
+ cEntity[TEXTURE_FRAME_SERIES_ANIMATOR_KEY] = null;
37634
+ }
37635
+ if (frameArchive) {
37636
+ const animator = new TextureFrameSeriesAnimator.Animator({
37637
+ viewer,
37638
+ entity: cEntity,
37639
+ archiveUrl: frameArchive.url,
37640
+ frames: frameArchive.metadata.Frames,
37641
+ textureColorMask
37642
+ });
37643
+ cEntity[TEXTURE_FRAME_SERIES_ANIMATOR_KEY] = animator;
37644
+ }
37645
+ }
37646
+ /**
37647
+ * Derives a min/max/label time-range segment from a resolved frame archive's Frames metadata,
37648
+ * for reporting up to whoever owns the menu item this entity belongs to (see IParams.onSeriesDiscovered).
37649
+ * @param frameArchive
37650
+ * @param entity
37651
+ */
37652
+ function frameArchiveToSeriesSegment(frameArchive, entity) {
37653
+ var _a;
37654
+ const timestamps = frameArchive.metadata.Frames
37655
+ .map((f) => new Date(f.Timestamp))
37656
+ .filter((d) => !isNaN(d.getTime()));
37657
+ if (!timestamps.length) {
37658
+ return null;
37659
+ }
37660
+ return {
37661
+ key: frameArchive.url,
37662
+ min: new Date(Math.min(...timestamps.map((d) => d.getTime()))),
37663
+ max: new Date(Math.max(...timestamps.map((d) => d.getTime()))),
37664
+ label: ((_a = entity === null || entity === void 0 ? void 0 : entity.Bruce) === null || _a === void 0 ? void 0 : _a.Name) || undefined
37665
+ };
37666
+ }
37667
+ /**
37668
+ * Returns if a value looks like a URL rather than a bare client file ID.
37254
37669
  * @param value
37255
37670
  */
37256
- function looksLikeTextureUrl(value) {
37257
- return /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(value) || value.startsWith("//") || value.startsWith("data:");
37671
+ function looksLikeUrl(value) {
37672
+ return /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(value) || value.startsWith("//");
37673
+ }
37674
+ /**
37675
+ * Extracts a client file ID from a resolved polygon "texture" value, which is either a bare
37676
+ * file ID or a URL. Follows the "/file/<id>" route path regardless of domain,
37677
+ * eg: "https://host/file/AGPWMAQR6F5ZVDJXZVRODGLCJE.png" or "https://host/RV:1/file/AGPWMAQR6F5ZVDJXZVRODGLCJE?cc=1".
37678
+ * @param raw
37679
+ */
37680
+ function extractClientFileIdFromTextureValue(raw) {
37681
+ if (!raw || typeof raw !== "string") {
37682
+ return null;
37683
+ }
37684
+ if (!looksLikeUrl(raw)) {
37685
+ return raw;
37686
+ }
37687
+ try {
37688
+ const withoutQuery = raw.split("?")[0];
37689
+ const match = withoutQuery.match(/\/file\/([^\/]+)/);
37690
+ if (!match) {
37691
+ return null;
37692
+ }
37693
+ return match[1].split(".")[0];
37694
+ }
37695
+ catch (e) {
37696
+ console.warn("Failed to parse client file ID from texture URL:", e, raw);
37697
+ return null;
37698
+ }
37258
37699
  }
37259
37700
  /**
37260
37701
  * Resolves a polygon style's texture field and if a color ask is needed it tints the resulting image.
@@ -37274,13 +37715,21 @@ async function resolveTexturedFill(params) {
37274
37715
  return { dataUri: null, effective: textureTrace.effective };
37275
37716
  }
37276
37717
  let url = raw;
37277
- if (!looksLikeTextureUrl(raw)) {
37278
- await api.Loading;
37279
- url = ClientFile.GetUrl({
37280
- api,
37281
- fileId: raw,
37282
- viaCdn: true
37283
- });
37718
+ if (!raw.startsWith("data:")) {
37719
+ const clientFileId = extractClientFileIdFromTextureValue(raw);
37720
+ if (clientFileId) {
37721
+ await api.Loading;
37722
+ const { clientFile } = await ClientFile.Get({ api, fileId: clientFileId });
37723
+ url = clientFile.URL;
37724
+ const clientFileData = clientFile.Data;
37725
+ if (TextureFrameSeriesAnimator.IsFrameArchiveMetadata(clientFileData)) {
37726
+ return {
37727
+ dataUri: null,
37728
+ effective: textureTrace.effective,
37729
+ frameArchive: { url, metadata: clientFileData.generation }
37730
+ };
37731
+ }
37732
+ }
37284
37733
  }
37285
37734
  const mask = style.textureColorMask;
37286
37735
  const cacheKey = "texture-" + url + "-" + (mask ? mask.type + "-" + mask.minColor + "-" + mask.maxColor : "none");
@@ -37317,30 +37766,11 @@ async function buildTintedTextureDataUri(url, mask) {
37317
37766
  const minColor = Color$1.ColorFromStr(mask.minColor) || { red: 0, green: 0, blue: 0, alpha: 1 };
37318
37767
  const maxColor = Color$1.ColorFromStr(mask.maxColor) || { red: 255, green: 255, blue: 255, alpha: 1 };
37319
37768
  const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
37320
- const data = imageData.data;
37321
- for (let i = 0; i < data.length; i += 4) {
37322
- // The texture is rendered black-to-white server-side, so any channel carries the value.
37323
- const t = data[i] / 255;
37324
- data[i] = Math.round(minColor.red + (maxColor.red - minColor.red) * t);
37325
- data[i + 1] = Math.round(minColor.green + (maxColor.green - minColor.green) * t);
37326
- data[i + 2] = Math.round(minColor.blue + (maxColor.blue - minColor.blue) * t);
37327
- // Preserve source transparency (eg unrasterized pixels) blended with the mask's own alpha.
37328
- const srcAlpha = data[i + 3] / 255;
37329
- const maskAlpha = minColor.alpha + (maxColor.alpha - minColor.alpha) * t;
37330
- data[i + 3] = Math.round(srcAlpha * maskAlpha * 255);
37331
- }
37769
+ ApplyGrayscaleColorMask(imageData, minColor, maxColor);
37332
37770
  context.putImageData(imageData, 0, 0);
37333
37771
  }
37334
37772
  return canvas.toDataURL("image/png");
37335
37773
  }
37336
- function loadImage(src) {
37337
- return new Promise((res, rej) => {
37338
- const image = new Image();
37339
- image.onload = () => res(image);
37340
- image.onerror = (e) => rej(e);
37341
- image.src = src;
37342
- });
37343
- }
37344
37774
  /**
37345
37775
  * Compares two color materials.
37346
37776
  * Returns if they are equal.
@@ -37685,6 +38115,7 @@ var EntityRenderEngine;
37685
38115
  entities: [],
37686
38116
  zoomItems: {},
37687
38117
  menuItemId: params.menuItemId,
38118
+ onSeriesDiscovered: params.onSeriesDiscovered,
37688
38119
  visualRegister: params.visualRegister
37689
38120
  };
37690
38121
  const updated = new Map();
@@ -38650,7 +39081,7 @@ var StyleUtils;
38650
39081
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
38651
39082
  })(StyleUtils || (StyleUtils = {}));
38652
39083
 
38653
- const VERSION = "6.9.7";
39084
+ const VERSION = "6.9.8";
38654
39085
  /**
38655
39086
  * Updates the environment instance used by bruce-cesium to one specified.
38656
39087
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.