bruce-cesium 7.3.4 → 7.3.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.
@@ -1,6 +1,6 @@
1
1
  import * as Cesium from 'cesium';
2
- import { Cartographic, ShaderSource, Cartesian3, Math as Math$1, Ellipsoid, Transforms, Matrix4, Geometry, GeometryAttribute, ComponentDatatype, PrimitiveType, BoundingSphere, GeometryPipeline, sampleTerrain, Texture, PixelFormat, Sampler, TextureWrap, TextureMinificationFilter, TextureMagnificationFilter, VertexArray, BufferUsage, ShaderProgram, RenderState, BlendingState, DrawCommand, Pass, Cartesian2, Cartesian4, ColorMaterialProperty, Color, JulianDate, Quaternion, HeadingPitchRoll, HeightReference, Entity, DistanceDisplayCondition, ColorBlendMode, CallbackProperty, ShadowMode, ConstantProperty, ClassificationType, Model, Primitive, Cesium3DTileFeature, ImageMaterialProperty, ArcType, CornerType, ConstantPositionProperty, HorizontalOrigin, VerticalOrigin, PolygonHierarchy, PolylineGraphics, Rectangle, SceneTransforms, NearFarScalar, Matrix3, KmlDataSource, GeoJsonDataSource, SceneMode, Cesium3DTileStyle, HeadingPitchRange, Ion, IonResource, Cesium3DTileColorBlendMode, Cesium3DTileset, OrthographicFrustum, EasingFunction, EllipsoidTerrainProvider, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, Intersect, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, PolygonPipeline, GeometryInstance, CustomDataSource, EllipsoidGeodesic, sampleTerrainMostDetailed, defined, ScreenSpaceEventHandler, ScreenSpaceEventType, CesiumInspector, ClockRange, DynamicEnvironmentMapManager, Fullscreen, CzmlDataSource } from 'cesium';
3
- import { Cartes, LRUCache, ProjectViewTile, ENVIRONMENT, Calculator, ClientFile, Entity as Entity$1, EntityLod, EntityTag, EntityType, ObjectUtils, Style, ClientFileValueMap, Color as Color$1, Carto, Geometry as Geometry$1, Api, Bounds, MenuItem, ProjectView, ProjectViewBookmark, Tileset, ZoomControl, BruceEvent, EntityCoords, DataLab, DelayQueue, AccountConcept, RecordChangeFeed, BruceApi, EntityRelation, EntitySource, Camera, ProgramKey, ProjectViewLegacyTile, Account, AccountLimits, Session, UrlUtils, EntityAttachment, EntityAttachmentType, EntityAttribute, MathUtils, ProjectViewBookmarkGroup, EntityRelationType, EntityHistoricData } from 'bruce-models';
2
+ import { Cartographic, ColorMaterialProperty, Entity, Color, ConstantProperty, CallbackProperty, Primitive, Cesium3DTileFeature, HeightReference, DistanceDisplayCondition, Math as Math$1, Cartesian3, JulianDate, Quaternion, Transforms, HeadingPitchRoll, Matrix4, ShaderSource, Ellipsoid, Geometry, GeometryAttribute, ComponentDatatype, PrimitiveType, BoundingSphere, GeometryPipeline, sampleTerrain, Texture, PixelFormat, Sampler, TextureWrap, TextureMinificationFilter, TextureMagnificationFilter, VertexArray, BufferUsage, ShaderProgram, RenderState, BlendingState, DrawCommand, Pass, Cartesian2, Cartesian4, ClassificationType, ArcType, CornerType, ShadowMode, ConstantPositionProperty, ColorBlendMode, Model, HorizontalOrigin, VerticalOrigin, ImageMaterialProperty, PolygonHierarchy, PolylineGraphics, Rectangle, SceneTransforms, NearFarScalar, Matrix3, KmlDataSource, GeoJsonDataSource, SceneMode, Ion, IonResource, Cesium3DTileStyle, HeadingPitchRange, Cesium3DTileset, Intersect, Cesium3DTileColorBlendMode, OrthographicFrustum, EasingFunction, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, PolygonPipeline, EllipsoidTerrainProvider, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, CustomDataSource, EllipsoidGeodesic, sampleTerrainMostDetailed, defined, CesiumInspector, ClockRange, DynamicEnvironmentMapManager, ScreenSpaceEventHandler, ScreenSpaceEventType, GeometryInstance, Fullscreen, CzmlDataSource } from 'cesium';
3
+ import { Cartes, LRUCache, ProjectViewTile, ENVIRONMENT, Calculator, Carto, Entity as Entity$1, EntityTag, EntityType, Geometry as Geometry$1, ObjectUtils, Style, ClientFile, EntityLod, Api, Bounds, ClientFileValueMap, Color as Color$1, MenuItem, ProjectView, ProjectViewBookmark, Tileset, ZoomControl, BruceEvent, EntityCoords, DataLab, DelayQueue, AccountConcept, BruceApi, RecordChangeFeed, EntityRelation, EntitySource, Camera, ProgramKey, ProjectViewLegacyTile, Account, AccountLimits, Session, UrlUtils, EntityAttachment, EntityAttachmentType, EntityAttribute, MathUtils, ProjectViewBookmarkGroup, EntityRelationType, EntityHistoricData } from 'bruce-models';
4
4
 
5
5
  /**
6
6
  * Ensures a number is returned from a given value.
@@ -182,6 +182,37 @@ var DrawingUtils;
182
182
  };
183
183
  }
184
184
  DrawingUtils.PointAcrossPolyline = PointAcrossPolyline;
185
+ const _sampledTerrain = new LRUCache(4000);
186
+ const _samplingTerrain = new Map();
187
+ // How precisely a sample is keyed. Roughly a metre, well under the resolution of any terrain we
188
+ // serve, so a camera that has not really moved asks the same question.
189
+ const SAMPLE_KEY_DECIMALS = 5;
190
+ // Identity for the provider a sample came from. Keyed on the object rather than on the tileset it
191
+ // was built from, so swapping terrain invalidates every height held against the old one.
192
+ const _providerIds = new WeakMap();
193
+ let _nextProviderId = 1;
194
+ /*
195
+ * Returns a stable id for a terrain provider, assigning one on first sight.
196
+ */
197
+ function terrainProviderId(provider) {
198
+ if (!provider) {
199
+ return 0;
200
+ }
201
+ let id = _providerIds.get(provider);
202
+ if (id == null) {
203
+ id = _nextProviderId++;
204
+ _providerIds.set(provider, id);
205
+ }
206
+ return id;
207
+ }
208
+ /**
209
+ * Empties the sampled terrain heights. For a terrain provider swap, or a test.
210
+ */
211
+ function ClearSampledTerrain() {
212
+ _sampledTerrain.Clear();
213
+ _samplingTerrain.clear();
214
+ }
215
+ DrawingUtils.ClearSampledTerrain = ClearSampledTerrain;
185
216
  /**
186
217
  * Returns terrain height from current viewer's provider.
187
218
  * On error or flat terrain, it will return 0.
@@ -205,17 +236,36 @@ var DrawingUtils;
205
236
  height: 0
206
237
  };
207
238
  }
208
- const sample = await sampleTerrainMostDetailed(viewer.scene.terrainProvider, [Cartographic.fromCartesian(pos3d)]);
209
- const height = (sample === null || sample === void 0 ? void 0 : sample.length) ? sample[0].height : null;
210
- if (isNaN(height)) {
211
- return {
212
- height: 0,
213
- error: "NaN"
214
- };
215
- }
216
- return {
217
- height: height
218
- };
239
+ const carto = Cartographic.fromCartesian(pos3d);
240
+ const key = `${terrainProviderId(viewer.scene.terrainProvider)}`
241
+ + `_${carto.longitude.toFixed(SAMPLE_KEY_DECIMALS)}`
242
+ + `_${carto.latitude.toFixed(SAMPLE_KEY_DECIMALS)}`;
243
+ const held = _sampledTerrain.Get(key);
244
+ if (held != null) {
245
+ return { height: held };
246
+ }
247
+ // Two callers on the same point wait on the one sample rather than each asking for it.
248
+ const sampling = _samplingTerrain.get(key);
249
+ if (sampling) {
250
+ return sampling;
251
+ }
252
+ const prom = sampleTerrainMostDetailed(viewer.scene.terrainProvider, [carto])
253
+ .then((sample) => {
254
+ const height = (sample === null || sample === void 0 ? void 0 : sample.length) ? sample[0].height : null;
255
+ if (height == null || isNaN(height)) {
256
+ return {
257
+ height: 0,
258
+ error: "NaN"
259
+ };
260
+ }
261
+ _sampledTerrain.Set(key, height);
262
+ return { height: height };
263
+ })
264
+ .finally(() => {
265
+ _samplingTerrain.delete(key);
266
+ });
267
+ _samplingTerrain.set(key, prom);
268
+ return prom;
219
269
  }
220
270
  catch (e) {
221
271
  return {
@@ -11014,6 +11064,22 @@ var HistoricFetchOrder;
11014
11064
  return Math.round(minMs + ((maxMs - minMs) * progress));
11015
11065
  }
11016
11066
  HistoricFetchOrder.IntervalFor = IntervalFor;
11067
+ /**
11068
+ * Returns the cadence for a set of this size on a clock running at this rate.
11069
+ * @param entityCount
11070
+ * @param multiplier the viewer clock's, ie. scene seconds per real second
11071
+ */
11072
+ function IntervalForClock(entityCount, multiplier) {
11073
+ const bySize = IntervalFor(entityCount);
11074
+ const rate = Math.abs(multiplier);
11075
+ if (!(rate > 0)) {
11076
+ return HistoricFetchOrder.MAX_INTERVAL_MS;
11077
+ }
11078
+ // How long one second of scene time takes to pass, which is how often a record can appear.
11079
+ const perRecord = 1000 / rate;
11080
+ return Math.min(HistoricFetchOrder.MAX_INTERVAL_MS, Math.max(bySize, perRecord));
11081
+ }
11082
+ HistoricFetchOrder.IntervalForClock = IntervalForClock;
11017
11083
  // Upper bounds in metres for the distance bands, nearest first.
11018
11084
  HistoricFetchOrder.DEFAULT_BANDS = [500, 2000, 10000, 50000];
11019
11085
  /**
@@ -11396,7 +11462,8 @@ class HistoricGatherer {
11396
11462
  * Returns how long to wait between refreshes for a set of this size.
11397
11463
  */
11398
11464
  IntervalFor(entityCount) {
11399
- return HistoricFetchOrder.IntervalFor(entityCount);
11465
+ var _a, _b, _c;
11466
+ return HistoricFetchOrder.IntervalForClock(entityCount, (_c = (_b = (_a = this.params.viewer) === null || _a === void 0 ? void 0 : _a.clock) === null || _b === void 0 ? void 0 : _b.multiplier) !== null && _c !== void 0 ? _c : 1);
11400
11467
  }
11401
11468
  /**
11402
11469
  * Fetches whatever the current clock range needs that is not already held.
@@ -13722,6 +13789,7 @@ var EntitiesIdsRenderManager;
13722
13789
  this.renderQueueForceFlags = [];
13723
13790
  this.reRenderState = new EntityReRenderMaintainState();
13724
13791
  const { viewer, apiGetter, monitor, item, register: visualsManager } = params;
13792
+ this.sharedHistoric = params.sharedHistoric;
13725
13793
  this.viewer = viewer;
13726
13794
  this.apiGetter = apiGetter;
13727
13795
  this.monitor = monitor;
@@ -13856,6 +13924,51 @@ var EntitiesIdsRenderManager;
13856
13924
  this.onGetterUpdate(entityIds);
13857
13925
  }
13858
13926
  }
13927
+ /*
13928
+ * The lane this item reads through, or null when it does not follow the clock.
13929
+ */
13930
+ getHistoricLane() {
13931
+ var _a, _b, _c;
13932
+ if (!this.sharedHistoric ||
13933
+ (!((_a = this.item.BruceEntity) === null || _a === void 0 ? void 0 : _a.historic) && !((_b = this.item.BruceEntity) === null || _b === void 0 ? void 0 : _b.historicAttrKey))) {
13934
+ return null;
13935
+ }
13936
+ if (!this.historicLane) {
13937
+ const historicKey = (_c = this.item.BruceEntity) === null || _c === void 0 ? void 0 : _c.historicAttrKey;
13938
+ this.historicLane = this.sharedHistoric.GetOrCreateLane({
13939
+ baseUrl: this.apiGetter.getApi().GetBaseUrl(),
13940
+ attrKey: historicKey,
13941
+ getMinIntervalMs: () => this.historicGatherer.IntervalFor(Object.keys(this.renderedEntities).length),
13942
+ subscribeToChanges: (onChanged) => {
13943
+ var _a;
13944
+ const feed = (_a = this.apiGetter.getApi()) === null || _a === void 0 ? void 0 : _a.RecordChangeFeed;
13945
+ if (!feed) {
13946
+ return null;
13947
+ }
13948
+ return feed.Subscribe({
13949
+ concepts: [AccountConcept.EConcept.ENTITY],
13950
+ actions: ["C", "U"]
13951
+ }, (event) => {
13952
+ if (typeof event.data === "string" && event.data) {
13953
+ onChanged(event.data);
13954
+ }
13955
+ });
13956
+ },
13957
+ isFeedConnected: () => { var _a, _b; return Boolean((_b = (_a = this.apiGetter.getApi()) === null || _a === void 0 ? void 0 : _a.RecordChangeFeed) === null || _b === void 0 ? void 0 : _b.IsConnected); },
13958
+ read: (entityIds, at) => Entity$1.GetListByIds({
13959
+ api: this.apiGetter.getApi(),
13960
+ entityIds: entityIds,
13961
+ historicPoint: new Date(at).toISOString(),
13962
+ historicKey: historicKey,
13963
+ expandSources: true,
13964
+ expandLocation: true,
13965
+ migrated: true,
13966
+ maxSearchTimeSec: 60 * 5,
13967
+ }).then(res => res.entities || [])
13968
+ });
13969
+ }
13970
+ return this.historicLane;
13971
+ }
13859
13972
  async onGetterUpdate(entityIds, force = false) {
13860
13973
  var _a, _b;
13861
13974
  if (this.disposed || this.viewer.isDestroyed() || !(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
@@ -13877,25 +13990,23 @@ var EntitiesIdsRenderManager;
13877
13990
  if (!apiIds.length) {
13878
13991
  return;
13879
13992
  }
13880
- const api = this.apiGetter.getApi();
13881
13993
  const revisions = this.reRenderState.captureApiRevisions(apiIds);
13882
- let newDateTime = null;
13883
- if (this.item.BruceEntity.historic || this.item.BruceEntity.historicAttrKey) {
13884
- newDateTime = JulianDate.toDate(this.viewer.clock.currentTime).toISOString();
13885
- }
13886
- const { entities } = await Entity$1.GetListByIds({
13887
- api,
13888
- entityIds: apiIds,
13889
- historicPoint: newDateTime,
13890
- historicKey: this.item.BruceEntity.historicAttrKey,
13891
- expandSources: true,
13892
- expandLocation: true,
13893
- migrated: true,
13894
- // If we're taking 5+ minutes to make a query, it's a dud.
13895
- // This is a timeout imposed on our DB and not external sources.
13896
- // Honestly could lower down to 30 seconds, but we'll keep it high for now.
13897
- maxSearchTimeSec: 60 * 5,
13898
- });
13994
+ const lane = this.getHistoricLane();
13995
+ const entities = lane
13996
+ ? await lane.Request({
13997
+ subscriberId: this.item.id,
13998
+ entityIds: apiIds,
13999
+ at: JulianDate.toDate(this.viewer.clock.currentTime).getTime(),
14000
+ force: force
14001
+ })
14002
+ : (await Entity$1.GetListByIds({
14003
+ api: this.apiGetter.getApi(),
14004
+ entityIds: apiIds,
14005
+ expandSources: true,
14006
+ expandLocation: true,
14007
+ migrated: true,
14008
+ maxSearchTimeSec: 60 * 5,
14009
+ })).entities;
13899
14010
  const resolved = this.reRenderState.filterCurrentApiEntities({
13900
14011
  entities,
13901
14012
  revisions
@@ -14111,6 +14222,7 @@ var EntitiesIdsRenderManager;
14111
14222
  return;
14112
14223
  }
14113
14224
  prevTick = currentTick;
14225
+ queue.delay = this.historicGatherer.IntervalFor(Object.keys(this.renderedEntities).length);
14114
14226
  queue.Call();
14115
14227
  });
14116
14228
  this.viewerDateTimeChangeRemoval = () => {
@@ -14123,9 +14235,11 @@ var EntitiesIdsRenderManager;
14123
14235
  };
14124
14236
  }
14125
14237
  viewerDateTimeDispose() {
14126
- var _a;
14238
+ var _a, _b;
14127
14239
  (_a = this.viewerDateTimeChangeRemoval) === null || _a === void 0 ? void 0 : _a.call(this);
14128
14240
  this.viewerDateTimeChangeRemoval = null;
14241
+ // Whatever this item was waiting on is nobody's answer now.
14242
+ (_b = this.historicLane) === null || _b === void 0 ? void 0 : _b.Drop(this.item.id);
14129
14243
  }
14130
14244
  }
14131
14245
  EntitiesIdsRenderManager.Manager = Manager;
@@ -19547,6 +19661,351 @@ var DataLabRenderManager;
19547
19661
  DataLabRenderManager.Manager = Manager;
19548
19662
  })(DataLabRenderManager || (DataLabRenderManager = {}));
19549
19663
 
19664
+ /**
19665
+ * The shared read path for Entities whose position comes from the clock.
19666
+ */
19667
+ var SharedHistoricGetters;
19668
+ (function (SharedHistoricGetters) {
19669
+ // The floor between two reads on a lane, so a fast server is not read from as fast as it answers.
19670
+ SharedHistoricGetters.DEFAULT_MIN_INTERVAL_MS = 250;
19671
+ // How far from a held answer's instant it still answers a new ask.
19672
+ SharedHistoricGetters.DEFAULT_FRESH_MS = 200;
19673
+ // How slow the idle backoff is allowed to make a lane.
19674
+ SharedHistoricGetters.DEFAULT_MAX_INTERVAL_MS = 3000;
19675
+ // How many unchanged reads it takes to reach that, doubling the wait each time.
19676
+ SharedHistoricGetters.IDLE_DOUBLINGS = 6;
19677
+ // The idle cap while a record change feed is connected.
19678
+ SharedHistoricGetters.FEED_MAX_INTERVAL_MS = 15000;
19679
+ /*
19680
+ * What an Entity looks like to the idle check: where it is, how it is turned, and when it was last written.
19681
+ */
19682
+ function SignatureOf(entity) {
19683
+ const bruce = entity === null || entity === void 0 ? void 0 : entity.Bruce;
19684
+ if (!bruce) {
19685
+ return "";
19686
+ }
19687
+ const location = bruce.Location;
19688
+ const transform = bruce.Transform;
19689
+ return [
19690
+ bruce.Updated || "",
19691
+ location ? `${location.latitude},${location.longitude},${location.altitude}` : "",
19692
+ transform ? `${transform.heading},${transform.pitch},${transform.roll}` : ""
19693
+ ].join("|");
19694
+ }
19695
+ SharedHistoricGetters.SignatureOf = SignatureOf;
19696
+ /**
19697
+ * One read path, shared by every manager reading the same Entities the same way.
19698
+ */
19699
+ class Lane {
19700
+ constructor(params) {
19701
+ this.params = params;
19702
+ // Subscriber to their one outstanding ask.
19703
+ this.pending = new Map();
19704
+ this.inFlight = false;
19705
+ this.lastSentAt = 0;
19706
+ this.pumpTimeout = null;
19707
+ // Set between an ask arriving and the pump running, so asks made in the same turn merge.
19708
+ this.pumpScheduled = false;
19709
+ this.disposed = false;
19710
+ // The last answer, kept so an ask that lands beside it is served rather than sent.
19711
+ this.held = null;
19712
+ // Entity id to what it looked like on the last read, for deciding whether anything moved.
19713
+ this.heldSignatures = {};
19714
+ // How many reads in a row have come back saying the same thing.
19715
+ this.idleReads = 0;
19716
+ // Entity internal id to its id, for matching what the feed reports against what is held.
19717
+ this.heldInternalIds = new Map();
19718
+ this.feedRemoval = null;
19719
+ this.feedWired = false;
19720
+ }
19721
+ /**
19722
+ * Asks for these Entities at this instant, resolving with them however the lane gets there:
19723
+ * from the held answer, from a read already about to happen, or from one this ask starts.
19724
+ */
19725
+ Request(ask) {
19726
+ if (this.disposed) {
19727
+ return Promise.resolve([]);
19728
+ }
19729
+ this.wireFeed();
19730
+ if (ask.force) {
19731
+ this.idleReads = 0;
19732
+ }
19733
+ const fresh = this.freshAnswerFor(ask);
19734
+ if (fresh) {
19735
+ return Promise.resolve(fresh);
19736
+ }
19737
+ return new Promise((resolve, reject) => {
19738
+ // Whoever was waiting on this subscriber's previous ask is answered by this one, so
19739
+ // they are handed the newer read rather than left hanging on a dropped request.
19740
+ const superseded = this.pending.get(ask.subscriberId);
19741
+ this.pending.set(ask.subscriberId, {
19742
+ ask,
19743
+ resolve: (entities) => {
19744
+ superseded === null || superseded === void 0 ? void 0 : superseded.resolve(entities);
19745
+ resolve(entities);
19746
+ },
19747
+ reject: (error) => {
19748
+ superseded === null || superseded === void 0 ? void 0 : superseded.reject(error);
19749
+ reject(error);
19750
+ }
19751
+ });
19752
+ this.schedulePump();
19753
+ });
19754
+ }
19755
+ /**
19756
+ * Forgets a subscriber, for a manager that has been disposed while it was waiting.
19757
+ */
19758
+ Drop(subscriberId) {
19759
+ const waiter = this.pending.get(subscriberId);
19760
+ if (waiter) {
19761
+ this.pending.delete(subscriberId);
19762
+ waiter.resolve([]);
19763
+ }
19764
+ }
19765
+ /**
19766
+ * Tells the lane that records it holds have changed, so its next read happens on the caller's
19767
+ * cadence rather than behind whatever backoff a quiet spell had earned.
19768
+ */
19769
+ NotifyChanged() {
19770
+ if (this.disposed) {
19771
+ return;
19772
+ }
19773
+ this.idleReads = 0;
19774
+ this.schedulePump();
19775
+ }
19776
+ /**
19777
+ * The same, for a feed event naming Entity internal ids as ranges.
19778
+ * @param rangeString as reported by the record change feed.
19779
+ */
19780
+ NotifyChangedRange(rangeString) {
19781
+ if (this.disposed || !rangeString || !this.heldInternalIds.size) {
19782
+ return;
19783
+ }
19784
+ for (const internalId of Array.from(this.heldInternalIds.keys())) {
19785
+ if (RecordChangeFeed.isEntityInternalIdInRangeString(rangeString, internalId)) {
19786
+ this.NotifyChanged();
19787
+ return;
19788
+ }
19789
+ }
19790
+ }
19791
+ Dispose() {
19792
+ var _a;
19793
+ this.disposed = true;
19794
+ (_a = this.feedRemoval) === null || _a === void 0 ? void 0 : _a.call(this);
19795
+ this.feedRemoval = null;
19796
+ if (this.pumpTimeout != null) {
19797
+ clearTimeout(this.pumpTimeout);
19798
+ this.pumpTimeout = null;
19799
+ }
19800
+ for (const waiter of Array.from(this.pending.values())) {
19801
+ waiter.resolve([]);
19802
+ }
19803
+ this.pending.clear();
19804
+ this.held = null;
19805
+ this.heldSignatures = {};
19806
+ this.heldInternalIds.clear();
19807
+ }
19808
+ /**
19809
+ * How many reads in a row have come back unchanged, which is what the wait is scaled by.
19810
+ */
19811
+ get IdleReads() {
19812
+ return this.idleReads;
19813
+ }
19814
+ /**
19815
+ * The wait the lane would apply before its next read,
19816
+ * ie. the caller's cadence after however far the idle backoff has widened it.
19817
+ */
19818
+ get IntervalMs() {
19819
+ return this.intervalNow();
19820
+ }
19821
+ /**
19822
+ * What the lane is currently holding, for a caller that wants it without asking for a read.
19823
+ */
19824
+ get Held() {
19825
+ return this.held;
19826
+ }
19827
+ /*
19828
+ * The wait before the next read: the caller's cadence, widened while nothing is changing.
19829
+ */
19830
+ intervalNow() {
19831
+ var _a, _b, _c;
19832
+ const base = this.params.getMinIntervalMs
19833
+ ? this.params.getMinIntervalMs() : SharedHistoricGetters.DEFAULT_MIN_INTERVAL_MS;
19834
+ if (!this.idleReads) {
19835
+ return base;
19836
+ }
19837
+ const maxInterval = (_a = this.params.maxIntervalMs) !== null && _a !== void 0 ? _a : (((_c = (_b = this.params).isFeedConnected) === null || _c === void 0 ? void 0 : _c.call(_b)) ? SharedHistoricGetters.FEED_MAX_INTERVAL_MS : SharedHistoricGetters.DEFAULT_MAX_INTERVAL_MS);
19838
+ const widened = base * Math.pow(2, Math.min(this.idleReads, SharedHistoricGetters.IDLE_DOUBLINGS));
19839
+ return Math.min(Math.max(base, maxInterval), widened);
19840
+ }
19841
+ /*
19842
+ * Returns the held answer when it covers this ask, or null when a read is needed.
19843
+ */
19844
+ freshAnswerFor(ask) {
19845
+ var _a;
19846
+ const freshMs = (_a = this.params.freshMs) !== null && _a !== void 0 ? _a : SharedHistoricGetters.DEFAULT_FRESH_MS;
19847
+ if (ask.force || !this.held || Math.abs(ask.at - this.held.at) > freshMs) {
19848
+ return null;
19849
+ }
19850
+ const entities = [];
19851
+ for (const entityId of ask.entityIds) {
19852
+ const entity = this.held.byId[entityId];
19853
+ // A partial answer is not an answer: the Entity may simply never have been asked for.
19854
+ if (!entity) {
19855
+ return null;
19856
+ }
19857
+ entities.push(entity);
19858
+ }
19859
+ return entities;
19860
+ }
19861
+ /*
19862
+ * Subscribes to the record change feed, on the first ask that finds one.
19863
+ */
19864
+ wireFeed() {
19865
+ if (this.feedWired || !this.params.subscribeToChanges) {
19866
+ return;
19867
+ }
19868
+ const removal = this.params.subscribeToChanges((rangeString) => this.NotifyChangedRange(rangeString));
19869
+ if (!removal) {
19870
+ return;
19871
+ }
19872
+ this.feedWired = true;
19873
+ this.feedRemoval = removal;
19874
+ }
19875
+ /*
19876
+ * Runs the pump at the end of this turn rather than during it.
19877
+ */
19878
+ schedulePump() {
19879
+ if (this.pumpScheduled || this.disposed) {
19880
+ return;
19881
+ }
19882
+ this.pumpScheduled = true;
19883
+ Promise.resolve().then(() => {
19884
+ this.pumpScheduled = false;
19885
+ this.pump();
19886
+ });
19887
+ }
19888
+ /*
19889
+ * Sends the next read when there is one to send and the lane is free to send it.
19890
+ */
19891
+ pump() {
19892
+ var _a;
19893
+ if (this.disposed || this.inFlight || !this.pending.size) {
19894
+ return;
19895
+ }
19896
+ const now = ((_a = this.params.now) !== null && _a !== void 0 ? _a : Date.now)();
19897
+ const waitFor = (this.lastSentAt + this.intervalNow()) - now;
19898
+ if (waitFor > 0) {
19899
+ // The pending map keeps absorbing asks meanwhile, so what eventually goes is the
19900
+ // union of everything wanted during the wait rather than the ask that started it.
19901
+ if (this.pumpTimeout == null) {
19902
+ this.pumpTimeout = setTimeout(() => {
19903
+ this.pumpTimeout = null;
19904
+ this.pump();
19905
+ }, waitFor);
19906
+ }
19907
+ return;
19908
+ }
19909
+ // Taken now rather than when each ask arrived, which is what makes an overtaken ask cost
19910
+ // nothing: it is simply part of this read instead of a read of its own.
19911
+ const waiters = Array.from(this.pending.values());
19912
+ this.pending.clear();
19913
+ const entityIds = [];
19914
+ const seen = {};
19915
+ let at = 0;
19916
+ for (const waiter of waiters) {
19917
+ at = Math.max(at, waiter.ask.at);
19918
+ for (const entityId of waiter.ask.entityIds) {
19919
+ if (entityId && !seen[entityId]) {
19920
+ seen[entityId] = true;
19921
+ entityIds.push(entityId);
19922
+ }
19923
+ }
19924
+ }
19925
+ if (!entityIds.length) {
19926
+ for (const waiter of waiters) {
19927
+ waiter.resolve([]);
19928
+ }
19929
+ return;
19930
+ }
19931
+ this.inFlight = true;
19932
+ this.lastSentAt = now;
19933
+ this.params.read(entityIds, at).then((entities) => {
19934
+ var _a, _b, _c;
19935
+ const signatureOf = (_a = this.params.signatureOf) !== null && _a !== void 0 ? _a : SignatureOf;
19936
+ const byId = {};
19937
+ let changed = false;
19938
+ for (const entity of entities || []) {
19939
+ const id = (_b = entity === null || entity === void 0 ? void 0 : entity.Bruce) === null || _b === void 0 ? void 0 : _b.ID;
19940
+ if (!id) {
19941
+ continue;
19942
+ }
19943
+ byId[id] = entity;
19944
+ const internalId = (_c = entity === null || entity === void 0 ? void 0 : entity.Bruce) === null || _c === void 0 ? void 0 : _c.InternalID;
19945
+ if (internalId != null) {
19946
+ this.heldInternalIds.set(internalId, id);
19947
+ }
19948
+ const signature = signatureOf(entity);
19949
+ // An Entity read for the first time is not a change: there is nothing it differs
19950
+ // from, and counting it as one would restart the backoff on every widened set.
19951
+ if (this.heldSignatures[id] != null && this.heldSignatures[id] !== signature) {
19952
+ changed = true;
19953
+ }
19954
+ this.heldSignatures[id] = signature;
19955
+ }
19956
+ this.idleReads = changed ? 0 : this.idleReads + 1;
19957
+ this.held = { at, byId };
19958
+ for (const waiter of waiters) {
19959
+ waiter.resolve(waiter.ask.entityIds.map(id => byId[id]).filter(x => !!x));
19960
+ }
19961
+ }).catch((error) => {
19962
+ for (const waiter of waiters) {
19963
+ waiter.reject(error);
19964
+ }
19965
+ }).finally(() => {
19966
+ this.inFlight = false;
19967
+ this.schedulePump();
19968
+ });
19969
+ }
19970
+ }
19971
+ SharedHistoricGetters.Lane = Lane;
19972
+ /**
19973
+ * The lanes in play, keyed so that two managers reading the same Entities the same way land on the same one.
19974
+ */
19975
+ class Cache {
19976
+ constructor() {
19977
+ this.lanes = {};
19978
+ }
19979
+ /**
19980
+ * Returns the lane for this endpoint and attribute key, creating it on first use.
19981
+ * @param params
19982
+ */
19983
+ GetOrCreateLane(params) {
19984
+ const key = `${params.baseUrl}|${params.attrKey || ""}`;
19985
+ let lane = this.lanes[key];
19986
+ if (!lane) {
19987
+ lane = new Lane({
19988
+ read: params.read,
19989
+ getMinIntervalMs: params.getMinIntervalMs,
19990
+ freshMs: params.freshMs,
19991
+ maxIntervalMs: params.maxIntervalMs,
19992
+ subscribeToChanges: params.subscribeToChanges,
19993
+ isFeedConnected: params.isFeedConnected
19994
+ });
19995
+ this.lanes[key] = lane;
19996
+ }
19997
+ return lane;
19998
+ }
19999
+ Dispose() {
20000
+ for (const key of Object.keys(this.lanes)) {
20001
+ this.lanes[key].Dispose();
20002
+ }
20003
+ this.lanes = {};
20004
+ }
20005
+ }
20006
+ SharedHistoricGetters.Cache = Cache;
20007
+ })(SharedHistoricGetters || (SharedHistoricGetters = {}));
20008
+
19550
20009
  const DEFAULT_GROUNDED_HEIGHT = 300;
19551
20010
  const MINIMUM_VIEW_AREA_SIZE_DEGREES = 0.01;
19552
20011
  const NET_STEP_PERCENT = 5;
@@ -24898,6 +25357,7 @@ var MenuItemManager;
24898
25357
  }
24899
25358
  this.visualsRegister = visualsRegister;
24900
25359
  this.sharedGetters = new SharedGetters.Cache();
25360
+ this.sharedHistoric = new SharedHistoricGetters.Cache();
24901
25361
  this.sharedMonitor = new CesiumViewMonitor.Monitor(this.viewer);
24902
25362
  this.tilesetInitQueue = new InitQueueTileset(this.getters);
24903
25363
  }
@@ -24906,7 +25366,7 @@ var MenuItemManager;
24906
25366
  * This will dispose all render managers and unregister all menu items.
24907
25367
  */
24908
25368
  Dispose(params) {
24909
- var _a, _b;
25369
+ var _a, _b, _c;
24910
25370
  const { disposeRegister } = params !== null && params !== void 0 ? params : {};
24911
25371
  for (let i = 0; i < this.items.length; i++) {
24912
25372
  const item = this.items[i];
@@ -24921,6 +25381,7 @@ var MenuItemManager;
24921
25381
  this.FlushPendingHandoffs();
24922
25382
  this.tilesetInitQueue.Dispose();
24923
25383
  (_b = this.sharedMonitor) === null || _b === void 0 ? void 0 : _b.Dispose();
25384
+ (_c = this.sharedHistoric) === null || _c === void 0 ? void 0 : _c.Dispose();
24924
25385
  if (this.visualsRegister && disposeRegister != false) {
24925
25386
  this.visualsRegister.Dispose();
24926
25387
  }
@@ -25128,7 +25589,8 @@ var MenuItemManager;
25128
25589
  register: this.visualsRegister,
25129
25590
  apiGetter: params.apiGetter,
25130
25591
  monitor: this.sharedMonitor,
25131
- item: params.item
25592
+ item: params.item,
25593
+ sharedHistoric: this.sharedHistoric
25132
25594
  });
25133
25595
  break;
25134
25596
  case MenuItem.EType.Entity:
@@ -47052,7 +47514,7 @@ var StyleUtils;
47052
47514
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
47053
47515
  })(StyleUtils || (StyleUtils = {}));
47054
47516
 
47055
- const VERSION = "7.3.4";
47517
+ const VERSION = "7.3.5";
47056
47518
  /**
47057
47519
  * Updates the environment instance used by bruce-cesium to one specified.
47058
47520
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.