bruce-cesium 7.7.2 → 7.7.3

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, ColorMaterialProperty, Entity, Color, ConstantProperty, CallbackProperty, Primitive, Cesium3DTileFeature, ConstantPositionProperty, HeightReference, DistanceDisplayCondition, Math as Math$1, Cartesian3, JulianDate, Quaternion, Transforms, HeadingPitchRoll, Matrix4, ShaderSource, Ellipsoid, Geometry, GeometryAttribute, ComponentDatatype, PrimitiveType, BoundingSphere, GeometryPipeline, Cartesian2, Cartesian4, sampleTerrain, Texture, PixelFormat, Sampler, TextureWrap, TextureMinificationFilter, TextureMagnificationFilter, PixelDatatype, VertexArray, BufferUsage, ShaderProgram, RenderState, BlendingState, DrawCommand, Pass, ColorBlendMode, ShadowMode, ClassificationType, Model, ArcType, CornerType, HorizontalOrigin, VerticalOrigin, ImageMaterialProperty, PolygonHierarchy, PolylineGraphics, Rectangle, SceneMode, IntersectionTests, Ray, SceneTransforms, NearFarScalar, Matrix3, KmlDataSource, FeatureDetection, GeoJsonDataSource, Cesium3DTileStyle, HeadingPitchRange, Ion, Cesium3DTileColorBlendMode, IonResource, Cesium3DTileset, EllipsoidTerrainProvider, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, OrthographicFrustum, EasingFunction, Intersect, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, EllipsoidGeodesic, sampleTerrainMostDetailed, defined, PolygonPipeline, GeometryInstance, CesiumInspector, ClockRange, DynamicEnvironmentMapManager, CustomDataSource, ScreenSpaceEventHandler, ScreenSpaceEventType, Fullscreen, CzmlDataSource } from 'cesium';
3
- import { Cartes, LRUCache, Carto, ProjectViewTile, EntityHistoricData, BruceEvent, DelayQueue, Entity as Entity$1, EntityTag, ClientFile, ENVIRONMENT, EntityAttachmentType, EntityRelationType, EntityType, Tileset, Calculator, DataLab, Style, ObjectUtils, MenuItem, AccountConcept, RecordChangeFeed, EntityLod, UrlUtils, Geometry as Geometry$1, Api, Bounds, ClientFileValueMap, Color as Color$1, ProjectView, ProjectViewBookmark, ZoomControl, Assembly, EntityCoords, BruceApi, EntityRelation, EntitySource, ProgramKey, ProjectViewLegacyTile, Camera, Account, AccountLimits, Session, EntityAttachment, EntityAttribute, MathUtils, ProjectViewBookmarkGroup } from 'bruce-models';
2
+ import { Cartographic, ColorMaterialProperty, Entity, Color, ConstantProperty, CallbackProperty, Primitive, Cesium3DTileFeature, ShaderSource, Cartesian3, Math as Math$1, Ellipsoid, Transforms, Matrix4, Geometry, GeometryAttribute, ComponentDatatype, PrimitiveType, BoundingSphere, GeometryPipeline, Cartesian2, Cartesian4, sampleTerrain, Texture, PixelFormat, Sampler, TextureWrap, TextureMinificationFilter, TextureMagnificationFilter, PixelDatatype, VertexArray, BufferUsage, ShaderProgram, RenderState, BlendingState, DrawCommand, Pass, ConstantPositionProperty, HeightReference, DistanceDisplayCondition, JulianDate, Quaternion, HeadingPitchRoll, ColorBlendMode, ShadowMode, ClassificationType, Model, HorizontalOrigin, VerticalOrigin, ArcType, CornerType, ImageMaterialProperty, PolygonHierarchy, PolylineGraphics, Rectangle, SceneMode, IntersectionTests, Ray, SceneTransforms, FeatureDetection, Matrix3, NearFarScalar, KmlDataSource, GeoJsonDataSource, Cesium3DTileStyle, HeadingPitchRange, Cesium3DTileColorBlendMode, Ion, IonResource, 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, EllipsoidGeodesic, sampleTerrainMostDetailed, defined, CustomDataSource, GeometryInstance, PolygonPipeline, CesiumInspector, ClockRange, DynamicEnvironmentMapManager, ScreenSpaceEventHandler, ScreenSpaceEventType, Fullscreen, CzmlDataSource } from 'cesium';
3
+ import { Cartes, LRUCache, Carto, ProjectViewTile, EntityHistoricData, BruceEvent, DelayQueue, Entity as Entity$1, EntityTag, ClientFile, ENVIRONMENT, EntityAttachmentType, EntityRelationType, EntityType, Tileset, Calculator, DataLab, Style, ObjectUtils, MenuItem, AccountConcept, RecordChangeFeed, EntityLod, UrlUtils, Api, Geometry as Geometry$1, Bounds, ClientFileValueMap, Color as Color$1, ProjectView, ProjectViewBookmark, ZoomControl, Assembly, EntityCoords, BruceApi, EntityRelation, EntitySource, Camera, ProgramKey, ProjectViewLegacyTile, Account, AccountLimits, Session, EntityAttachment, EntityAttribute, MathUtils, ProjectViewBookmarkGroup } from 'bruce-models';
4
4
 
5
5
  /**
6
6
  * Ensures a number is returned from a given value.
@@ -45593,6 +45593,45 @@ function calcAssemblyRootFrame(entity, modelSpace) {
45593
45593
  const hpr = HeadingPitchRoll.fromDegrees(EnsureNumber(transform.heading), EnsureNumber(transform.pitch), EnsureNumber(transform.roll));
45594
45594
  return Matrix4.multiply(frame, Matrix4.fromRotation(Matrix3.fromHeadingPitchRoll(hpr)), frame);
45595
45595
  }
45596
+ // Assembly parts are always drawn at the heights their records hold.
45597
+ const ASSEMBLY_HEIGHT_REFS = {
45598
+ point: HeightReference.NONE,
45599
+ polyline: HeightReference.NONE,
45600
+ polygon: HeightReference.NONE
45601
+ };
45602
+ /*
45603
+ * Reads how an Entity Type's default Style draws its records, or null when the type cannot be read.
45604
+ */
45605
+ async function getStyledHeightRefs(api, entityTypeId) {
45606
+ var _a, _b;
45607
+ let styleId;
45608
+ try {
45609
+ const { entityType } = await EntityType.Get({ api, entityTypeId });
45610
+ if (!entityType) {
45611
+ return null;
45612
+ }
45613
+ styleId = entityType["DisplaySetting.ID"];
45614
+ }
45615
+ catch (e) {
45616
+ console.error(e);
45617
+ return null;
45618
+ }
45619
+ let settings = {};
45620
+ if (styleId && styleId > 0) {
45621
+ try {
45622
+ settings = ((_b = (_a = (await Style.Get({ api, styleId })).style) === null || _a === void 0 ? void 0 : _a.Settings) !== null && _b !== void 0 ? _b : {});
45623
+ }
45624
+ catch (e) {
45625
+ // A deleted Style leaves the records drawn with the defaults, as the render engines do.
45626
+ console.error(e);
45627
+ }
45628
+ }
45629
+ return {
45630
+ point: EntityRenderEngine.GetHeightRef(settings.pointStyle),
45631
+ polyline: EntityRenderEngine.GetHeightRefPolyline(EntityRenderEngine.GetHeightRef(settings.polylineStyle)),
45632
+ polygon: EntityRenderEngine.GetHeightRef(settings.polygonStyle)
45633
+ };
45634
+ }
45596
45635
  // Records created within about this long ago are the ones the oversized GeometryRadius bug could have written.
45597
45636
  const GEOMETRY_RADIUS_SUSPECT_AGE_MS = 1000 * 60 * 60 * 24 * 183;
45598
45637
  // Above this a recent record's radius is treated as that bug rather than a real size.
@@ -46029,6 +46068,44 @@ var EntityUtils;
46029
46068
  }
46030
46069
  return [];
46031
46070
  };
46071
+ // Entity Type ID -> how its default Style draws each kind of geometry, read once per call.
46072
+ const styledRefs = new Map();
46073
+ /*
46074
+ * How the scene would draw an undrawn record's geometry, or null to fall back to the sample's heightRef.
46075
+ */
46076
+ const getStyledRefs = (entity) => {
46077
+ var _a, _b, _c;
46078
+ // Assembly parts are drawn at absolute heights whatever their type's Style says, read with a root or not.
46079
+ if (((_a = entity === null || entity === void 0 ? void 0 : entity.Bruce) === null || _a === void 0 ? void 0 : _a.AssemblyPosition) || ((_b = entity === null || entity === void 0 ? void 0 : entity.Bruce) === null || _b === void 0 ? void 0 : _b.AssemblyRootLocation)) {
46080
+ return Promise.resolve(ASSEMBLY_HEIGHT_REFS);
46081
+ }
46082
+ const typeId = (_c = entity === null || entity === void 0 ? void 0 : entity.Bruce) === null || _c === void 0 ? void 0 : _c["EntityType.ID"];
46083
+ if (!api || !typeId) {
46084
+ return Promise.resolve(null);
46085
+ }
46086
+ if (!styledRefs.has(typeId)) {
46087
+ styledRefs.set(typeId, getStyledHeightRefs(api, typeId));
46088
+ }
46089
+ return styledRefs.get(typeId);
46090
+ };
46091
+ /*
46092
+ * Makes a record's positions absolute as a Style draws them, sampling terrain as none may be loaded there.
46093
+ */
46094
+ const placeStyled = async (posses, heightRef, sample) => {
46095
+ if (heightRef != HeightReference.NONE) {
46096
+ for (let i = 0; i < posses.length; i++) {
46097
+ const carto = Cartographic.fromCartesian(posses[i]);
46098
+ if (!carto) {
46099
+ continue;
46100
+ }
46101
+ const { height: terrainHeight } = await DrawingUtils.GetTerrainHeight({ pos3d: posses[i], viewer });
46102
+ const ground = EnsureNumber(terrainHeight, 0);
46103
+ carto.height = heightRef == HeightReference.CLAMP_TO_GROUND ? ground : carto.height + ground;
46104
+ posses[i] = Cartographic.toCartesian(carto);
46105
+ }
46106
+ }
46107
+ await ensureHeightRefs(posses, { ...sample, heightRef: HeightReference.NONE });
46108
+ };
46032
46109
  /**
46033
46110
  * Returns an array of positions for a given sampled entity.
46034
46111
  * This will include the location, and geometry positions.
@@ -46043,6 +46120,9 @@ var EntityUtils;
46043
46120
  */
46044
46121
  const evaluateRecord = async () => {
46045
46122
  let posses = [];
46123
+ const refs = await getStyledRefs(entity);
46124
+ // The record's own point, kept apart so a Style can say what its altitude means.
46125
+ const pointPosses = [];
46046
46126
  const location = Entity$1.GetValue({
46047
46127
  entity: entity,
46048
46128
  path: ["Bruce", "Location"]
@@ -46053,7 +46133,7 @@ var EntityUtils;
46053
46133
  // Disallowing 0.
46054
46134
  if (latitude && longitude) {
46055
46135
  const pos3d = Cartesian3.fromDegrees(longitude, latitude, EnsureNumber(location.altitude));
46056
- posses.push(pos3d);
46136
+ pointPosses.push(pos3d);
46057
46137
  }
46058
46138
  }
46059
46139
  const geometry = Entity$1.GetValue({
@@ -46069,7 +46149,7 @@ var EntityUtils;
46069
46149
  const point = points.length > 0 ? points[0] : null;
46070
46150
  if (point && Carto.ValidateCarto(point)) {
46071
46151
  const pos3d = Cartesian3.fromDegrees(EnsureNumber(point.longitude), EnsureNumber(point.latitude), EnsureNumber(point.altitude));
46072
- posses.push(pos3d);
46152
+ pointPosses.push(pos3d);
46073
46153
  }
46074
46154
  }
46075
46155
  const lineStr = geometry.LineString;
@@ -46077,7 +46157,12 @@ var EntityUtils;
46077
46157
  const points = Geometry$1.ParsePoints(lineStr);
46078
46158
  if (points.length > 0) {
46079
46159
  const pPosses = points.map(x => Cartesian3.fromDegrees(EnsureNumber(x.longitude), EnsureNumber(x.latitude), EnsureNumber(x.altitude)));
46080
- await ensureHeightRefs(pPosses, sample);
46160
+ if (refs) {
46161
+ await placeStyled(pPosses, refs.polyline, sample);
46162
+ }
46163
+ else {
46164
+ await ensureHeightRefs(pPosses, sample);
46165
+ }
46081
46166
  posses = posses.concat(pPosses);
46082
46167
  }
46083
46168
  }
@@ -46087,7 +46172,12 @@ var EntityUtils;
46087
46172
  if (boundary === null || boundary === void 0 ? void 0 : boundary.LinearRing) {
46088
46173
  const points = Geometry$1.ParsePoints(boundary.LinearRing);
46089
46174
  const pPosses = points.map(x => Cartesian3.fromDegrees(EnsureNumber(x.longitude), EnsureNumber(x.latitude), EnsureNumber(x.altitude)));
46090
- await ensureHeightRefs(pPosses, sample);
46175
+ if (refs) {
46176
+ await placeStyled(pPosses, refs.polygon, sample);
46177
+ }
46178
+ else {
46179
+ await ensureHeightRefs(pPosses, sample);
46180
+ }
46091
46181
  posses = posses.concat(pPosses);
46092
46182
  }
46093
46183
  }
@@ -46108,11 +46198,22 @@ var EntityUtils;
46108
46198
  Cartesian3.fromDegrees(EnsureNumber(boundaries.minLongitude), EnsureNumber(boundaries.minLatitude), EnsureNumber(boundaries.minAltitude)),
46109
46199
  Cartesian3.fromDegrees(EnsureNumber(boundaries.maxLongitude), EnsureNumber(boundaries.maxLatitude), EnsureNumber(boundaries.maxAltitude))
46110
46200
  ];
46111
- await ensureHeightRefs(bPosses, sample);
46201
+ if (refs) {
46202
+ // The bounds span the record's main geometry, so they are drawn the way it is.
46203
+ const boundsRef = (geometry === null || geometry === void 0 ? void 0 : geometry.Polygon) ? refs.polygon : (geometry === null || geometry === void 0 ? void 0 : geometry.LineString) ? refs.polyline : refs.point;
46204
+ await placeStyled(bPosses, boundsRef, sample);
46205
+ }
46206
+ else {
46207
+ await ensureHeightRefs(bPosses, sample);
46208
+ }
46112
46209
  posses = posses.concat(bPosses);
46113
46210
  }
46114
46211
  }
46115
- return posses;
46212
+ if (refs) {
46213
+ await placeStyled(pointPosses, refs.point, sample);
46214
+ }
46215
+ // Points first, since a lone record is placed by its first position.
46216
+ return pointPosses.concat(posses);
46116
46217
  };
46117
46218
  if (isAssemblyEntity) {
46118
46219
  // See if we have tileset coords to use.
@@ -46271,6 +46372,8 @@ var EntityUtils;
46271
46372
  sample.entity = (_e = simulation === null || simulation === void 0 ? void 0 : simulation.GetEntity(sample.entityId)) !== null && _e !== void 0 ? _e : sample.entity;
46272
46373
  }
46273
46374
  }
46375
+ // Read here at the scene's time with their location; records a caller supplied may be of another time.
46376
+ const readHere = new Set();
46274
46377
  // Bulk requesting Entity records.
46275
46378
  try {
46276
46379
  const toSearchIds = recordSamples.filter(x => !x.entity && x.entityId).map(x => x.entityId);
@@ -46292,6 +46395,9 @@ var EntityUtils;
46292
46395
  const sample = recordSamples[i];
46293
46396
  if (!sample.entity && sample.entityId) {
46294
46397
  const read = entitiesMap.get(sample.entityId);
46398
+ if (read) {
46399
+ readHere.add(sample.entityId);
46400
+ }
46295
46401
  sample.entity = read && simulation ? simulation.Overlay(read) : read;
46296
46402
  }
46297
46403
  }
@@ -46302,10 +46408,10 @@ var EntityUtils;
46302
46408
  catch (e) {
46303
46409
  console.error(e);
46304
46410
  }
46305
- // Some records may still not be expanded.
46306
- // We have to detect whatever is an Assembly Entity and expand it.
46411
+ // Assembly parts not read above with a location expand still need one, and the ones off the scene are dropped
46412
+ // when others are in it, since category nodes without geometry would otherwise pull the result elsewhere.
46307
46413
  try {
46308
- const needsExpansion = recordSamples.filter(x => {
46414
+ const assemblySamples = recordSamples.filter(x => {
46309
46415
  var _a;
46310
46416
  // Expanding reads the API's record, which would replace the stand-in or undo the patch.
46311
46417
  if (simulation === null || simulation === void 0 ? void 0 : simulation.HasBlob((_a = x.entity.Bruce) === null || _a === void 0 ? void 0 : _a.ID)) {
@@ -46315,36 +46421,30 @@ var EntityUtils;
46315
46421
  entity: x.entity,
46316
46422
  path: ["Bruce", "AssemblyPosition"]
46317
46423
  });
46318
- if (!assemblyPos) {
46319
- return false;
46320
- }
46321
- const rootPos = Entity$1.GetValue({
46322
- entity: x.entity,
46323
- path: ["Bruce", "AssemblyRootPosition"]
46324
- });
46325
- return !rootPos;
46424
+ return !!assemblyPos;
46326
46425
  });
46426
+ const isInScene = (sample) => {
46427
+ var _a;
46428
+ return !!(visualRegister && visualRegister.GetRego({
46429
+ entityId: (_a = sample.entityId) !== null && _a !== void 0 ? _a : sample.entity.Bruce.ID,
46430
+ menuItemId: sample.menuItemId
46431
+ }));
46432
+ };
46433
+ const sceneSamples = assemblySamples.filter(isInScene);
46434
+ const offSceneSamples = sceneSamples.length ? assemblySamples.filter(x => !isInScene(x)) : [];
46435
+ if (offSceneSamples.length) {
46436
+ const offSceneIds = new Set(offSceneSamples.map(x => x.entity.Bruce.ID));
46437
+ recordSamples = recordSamples.filter(x => !offSceneIds.has(x.entity.Bruce.ID));
46438
+ }
46439
+ const keptSamples = sceneSamples.length ? sceneSamples : assemblySamples;
46440
+ const needsExpansion = keptSamples.filter(x => !readHere.has(x.entity.Bruce.ID) || !Entity$1.GetValue({
46441
+ entity: x.entity,
46442
+ path: ["Bruce", "AssemblyRootLocation"]
46443
+ }));
46327
46444
  if (needsExpansion.length) {
46328
46445
  const EXPAND_BATCH_SIZE = 30;
46329
46446
  const EXPAND_MAX_IDS = 200;
46330
- // Figure out if any are in the scene.
46331
- // Helps us sort leaf-nodes away from category nodes thta don't have geometry.
46332
- const isInScene = (sample) => {
46333
- var _a;
46334
- return !!(visualRegister && visualRegister.GetRego({
46335
- entityId: (_a = sample.entityId) !== null && _a !== void 0 ? _a : sample.entity.Bruce.ID,
46336
- menuItemId: sample.menuItemId
46337
- }));
46338
- };
46339
- // Trim to max 200 with a preference to those in the scene.
46340
- const sceneSamples = needsExpansion.filter(isInScene);
46341
- const offSceneSamples = sceneSamples.length ? needsExpansion.filter(x => !isInScene(x)) : [];
46342
- if (offSceneSamples.length) {
46343
- const offSceneIds = new Set(offSceneSamples.map(x => x.entity.Bruce.ID));
46344
- recordSamples = recordSamples.filter(x => !offSceneIds.has(x.entity.Bruce.ID));
46345
- }
46346
- const effectiveSamples = sceneSamples.length ? sceneSamples : needsExpansion;
46347
- const uniqueIds = Array.from(new Set(effectiveSamples.map(x => x.entity.Bruce.ID)));
46447
+ const uniqueIds = Array.from(new Set(needsExpansion.map(x => x.entity.Bruce.ID)));
46348
46448
  const expandIds = uniqueIds.slice(0, EXPAND_MAX_IDS);
46349
46449
  // Anything we didn't expand will taint the overall result so we have to filter them out.
46350
46450
  const droppedIds = new Set(uniqueIds.slice(EXPAND_MAX_IDS));
@@ -46373,8 +46473,8 @@ var EntityUtils;
46373
46473
  expandedMap.set(entities[i].Bruce.ID, entities[i]);
46374
46474
  }
46375
46475
  }
46376
- for (let i = 0; i < effectiveSamples.length; i++) {
46377
- const sample = effectiveSamples[i];
46476
+ for (let i = 0; i < needsExpansion.length; i++) {
46477
+ const sample = needsExpansion[i];
46378
46478
  const expanded = expandedMap.get(sample.entity.Bruce.ID);
46379
46479
  if (expanded) {
46380
46480
  sample.entity = expanded;
@@ -57167,7 +57267,7 @@ var StyleUtils;
57167
57267
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
57168
57268
  })(StyleUtils || (StyleUtils = {}));
57169
57269
 
57170
- const VERSION = "7.7.2";
57270
+ const VERSION = "7.7.3";
57171
57271
  /**
57172
57272
  * Updates the environment instance used by bruce-cesium to one specified.
57173
57273
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.