bruce-models 4.6.4 → 4.6.6

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.
@@ -2181,128 +2181,6 @@
2181
2181
  Color.ColorFromStr = ColorFromStr;
2182
2182
  })(exports.Color || (exports.Color = {}));
2183
2183
 
2184
- /**
2185
- * Describes vector geometry that Bruce uses.
2186
- */
2187
- (function (Geometry) {
2188
- let EPolygonRingType;
2189
- (function (EPolygonRingType) {
2190
- EPolygonRingType["Boundaries"] = "out";
2191
- EPolygonRingType["Hole"] = "in";
2192
- })(EPolygonRingType = Geometry.EPolygonRingType || (Geometry.EPolygonRingType = {}));
2193
- /**
2194
- * Turns an array of points into string vector geometry that Bruce can use.
2195
- * This is used for saving polyline and polygon data.
2196
- * @param points
2197
- * @returns
2198
- */
2199
- function LineStrFromPoints(points) {
2200
- if (!points.length) {
2201
- throw ("points is empty.");
2202
- }
2203
- let carto = points[0];
2204
- let lineString = `${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
2205
- for (let i = 1; i < points.length; i++) {
2206
- carto = points[i];
2207
- lineString += ` ${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
2208
- }
2209
- return lineString;
2210
- }
2211
- Geometry.LineStrFromPoints = LineStrFromPoints;
2212
- /**
2213
- * Removes same points that occur in a row.
2214
- * This will not modify the original array.
2215
- * @param positions
2216
- * @returns
2217
- */
2218
- function RemoveRepeatPoints(positions) {
2219
- const filteredList = [];
2220
- for (let i = 0; i < positions.length; i++) {
2221
- const pos = positions[i];
2222
- const lastPos = filteredList.length > 0 ? filteredList[filteredList.length - 1] : null;
2223
- if (!lastPos || (pos.latitude != lastPos.latitude || pos.longitude != lastPos.longitude || pos.altitude != lastPos.altitude)) {
2224
- filteredList.push(pos);
2225
- }
2226
- }
2227
- return filteredList;
2228
- }
2229
- Geometry.RemoveRepeatPoints = RemoveRepeatPoints;
2230
- /**
2231
- * Parses a string of points into an array of points.
2232
- * @param pointsStr
2233
- * @returns
2234
- */
2235
- function ParsePoints(pointsStr) {
2236
- pointsStr = pointsStr.replace(/[^\d.,-\s]/g, "");
2237
- let splitterCoordinates = " ";
2238
- let splitterAxis = ",";
2239
- const commaIndex = pointsStr.indexOf(",");
2240
- const spaceIndex = pointsStr.indexOf(" ");
2241
- if ((spaceIndex > -1 && commaIndex > spaceIndex) || commaIndex <= -1) {
2242
- splitterCoordinates = ",";
2243
- splitterAxis = " ";
2244
- }
2245
- let points = pointsStr.trim().split(splitterCoordinates);
2246
- points = points.filter(a => a != "");
2247
- const result = [];
2248
- for (let i = 0; i < points.length; i++) {
2249
- const pointData = points[i];
2250
- const coords = pointData.trim().split(splitterAxis);
2251
- if (coords.length == 2 || coords.length == 3) {
2252
- const longitude = Number(coords[0]);
2253
- const latitude = Number(coords[1]);
2254
- const altitude = Number(coords.length >= 3 ? coords[2] : 0);
2255
- if (longitude != null && latitude != null) {
2256
- result.push({
2257
- altitude: altitude,
2258
- latitude: latitude,
2259
- longitude: longitude
2260
- });
2261
- }
2262
- else {
2263
- console.warn("Invalid point data detected.", pointData);
2264
- }
2265
- }
2266
- }
2267
- return result;
2268
- }
2269
- Geometry.ParsePoints = ParsePoints;
2270
- /**
2271
- * Parses both string and object Bruce geometry.
2272
- * String geometry is legacy Bruce data.
2273
- * @param geometry
2274
- * @returns
2275
- */
2276
- function ParseGeometry(geometry) {
2277
- if (typeof geometry == "string") {
2278
- let positions = [];
2279
- const geometryParsed = (geometry || "").split(";");
2280
- for (let i = 0; i < geometryParsed.length; i++) {
2281
- const data = geometryParsed[i];
2282
- const points = ParsePoints(data);
2283
- if (points && points.length > 0) {
2284
- positions = positions.concat(points);
2285
- }
2286
- }
2287
- positions = RemoveRepeatPoints(positions);
2288
- const newGeometry = {};
2289
- if (positions.length > 0) {
2290
- const topPoint = positions[0];
2291
- newGeometry.Point = `${topPoint.latitude},${topPoint.longitude}` + (topPoint.altitude != null ? `,${topPoint.altitude}` : "");
2292
- if (positions.length > 1) {
2293
- newGeometry.Polygon = [{ Facing: EPolygonRingType.Boundaries, LinearRing: LineStrFromPoints(positions) }];
2294
- }
2295
- if (positions.length > 2) {
2296
- newGeometry.LineString = LineStrFromPoints(positions);
2297
- }
2298
- }
2299
- return newGeometry;
2300
- }
2301
- return geometry;
2302
- }
2303
- Geometry.ParseGeometry = ParseGeometry;
2304
- })(exports.Geometry || (exports.Geometry = {}));
2305
-
2306
2184
  (function (ObjectUtils) {
2307
2185
  const DEFAULT_LENGTH = 36;
2308
2186
  /**
@@ -2929,27 +2807,6 @@
2929
2807
  PathUtils.ParseLegacy = ParseLegacy;
2930
2808
  })(exports.PathUtils || (exports.PathUtils = {}));
2931
2809
 
2932
- /**
2933
- * Describes an expectation on what should be rendered for a menu item-
2934
- * between a min-max distance of an entity to the camera.
2935
- */
2936
- (function (ZoomControl) {
2937
- /**
2938
- * Available display types for a menu item.
2939
- */
2940
- let EDisplayType;
2941
- (function (EDisplayType) {
2942
- // Hidden means it will not be rendered.
2943
- EDisplayType["Hidden"] = "hidden";
2944
- // Point will try render a point based on any available Entity data.
2945
- EDisplayType["Point"] = "point";
2946
- // Geometry means it will try render multi-geometry, polygon, polyline, or point in order of priority.
2947
- EDisplayType["Geometry"] = "geometry";
2948
- // 3D means it will try render 3D model, multi-geometry, polygon, polyline, or point in order of priority.
2949
- EDisplayType["Model3D"] = "3d";
2950
- })(EDisplayType = ZoomControl.EDisplayType || (ZoomControl.EDisplayType = {}));
2951
- })(exports.ZoomControl || (exports.ZoomControl = {}));
2952
-
2953
2810
  (function (EntityHistoricData) {
2954
2811
  /**
2955
2812
  * Returns historic data for an array of Entity IDs.
@@ -3901,132 +3758,6 @@
3901
3758
  return Object.assign(Object.assign({}, baseEntity), { "Bruce": bruce });
3902
3759
  }
3903
3760
  Entity.Assert = Assert;
3904
- /**
3905
- * Helper method that returns a geojson object for a given set of Entities.
3906
- * @param params
3907
- * @returns
3908
- */
3909
- function ToGeoJson(params) {
3910
- const { entities, excludeAltitude, altitude, includeUserData, allowedDisplayTypes } = params;
3911
- const features = [];
3912
- const allowPoint = allowedDisplayTypes == null || allowedDisplayTypes.includes(exports.ZoomControl.EDisplayType.Point);
3913
- const allowGeometry = allowedDisplayTypes == null || allowedDisplayTypes.includes(exports.ZoomControl.EDisplayType.Geometry);
3914
- const cloneObj = (obj) => {
3915
- return JSON.parse(JSON.stringify(obj));
3916
- };
3917
- const areCoordinatesEqual = (coord1, coord2) => {
3918
- return coord1[0] === coord2[0] && coord1[1] === coord2[1] && (coord1[2] === coord2[2] || (coord1.length < 3 && coord2.length < 3));
3919
- };
3920
- const removeConsecutiveDuplicates = (coordinates) => {
3921
- return coordinates.filter((coord, index, array) => {
3922
- return index === 0 || !areCoordinatesEqual(coord, array[index - 1]);
3923
- });
3924
- };
3925
- const closePolygonCoordinates = (coordinates) => {
3926
- if (coordinates.length > 0 && !areCoordinatesEqual(coordinates[0], coordinates[coordinates.length - 1])) {
3927
- const firstPointCopy = [...coordinates[0]];
3928
- coordinates.push(firstPointCopy);
3929
- }
3930
- return coordinates;
3931
- };
3932
- const populateProperties = (feature, entity) => {
3933
- let properties = null;
3934
- // All properties.
3935
- if (includeUserData != false) {
3936
- properties = cloneObj(entity);
3937
- // The GeoJSON is supposed to represent the geometry attribute.
3938
- delete properties.Bruce.VectorGeometry;
3939
- delete properties.Bruce.Boundaries;
3940
- }
3941
- // Only specific internal properties.
3942
- else {
3943
- const bClone = cloneObj(entity.Bruce);
3944
- // The GeoJSON is supposed to represent the geometry attribute.
3945
- delete bClone.VectorGeometry;
3946
- delete bClone.Boundaries;
3947
- properties = {
3948
- Bruce: bClone
3949
- };
3950
- }
3951
- feature.properties = properties;
3952
- };
3953
- const processGeometry = (geometry, entity) => {
3954
- var _a, _b;
3955
- const feature = {
3956
- type: "Feature",
3957
- properties: {},
3958
- geometry: null
3959
- };
3960
- populateProperties(feature, entity);
3961
- if (((_a = geometry.MultiGeometry) === null || _a === void 0 ? void 0 : _a.length) && allowGeometry) {
3962
- geometry.MultiGeometry.forEach(geo => processGeometry(geo, entity));
3963
- return;
3964
- }
3965
- else if (((_b = geometry.Polygon) === null || _b === void 0 ? void 0 : _b.length) && allowGeometry) {
3966
- const sortedPolygons = geometry.Polygon.sort((a, b) => a.Facing === exports.Geometry.EPolygonRingType.Boundaries ? -1 : 1);
3967
- const coordinates = sortedPolygons.map(polygonRing => closePolygonCoordinates(removeConsecutiveDuplicates(polygonRing.LinearRing.split(' ').map(coord => {
3968
- const [lon, lat, alt] = coord.split(',').map(Number);
3969
- return excludeAltitude ? [lon, lat] : [lon, lat, altitude !== undefined ? altitude : (alt !== undefined ? alt : [])];
3970
- }))));
3971
- // Check if the polygon has at least 4 points.
3972
- const isValidPolygon = coordinates.every(polygon => polygon.length >= 4);
3973
- if (!isValidPolygon) {
3974
- // Perhaps try other geometry instead of returning?
3975
- return;
3976
- }
3977
- feature.geometry = {
3978
- type: "Polygon",
3979
- coordinates: coordinates,
3980
- };
3981
- }
3982
- else if (geometry.LineString && (allowedDisplayTypes == null || allowedDisplayTypes.includes(exports.ZoomControl.EDisplayType.Geometry))) {
3983
- const coordinates = removeConsecutiveDuplicates(geometry.LineString.split(' ').map(coord => {
3984
- const [lon, lat, alt] = coord.split(',').map(Number);
3985
- return excludeAltitude ? [lon, lat] : [lon, lat, altitude !== undefined ? altitude : (alt !== undefined ? alt : [])];
3986
- }));
3987
- // Check if the polyline has at least 2 points.
3988
- if (coordinates.length < 2) {
3989
- // Perhaps try other geometry instead of returning?
3990
- return;
3991
- }
3992
- feature.geometry = {
3993
- type: "LineString",
3994
- coordinates,
3995
- };
3996
- }
3997
- else if (geometry.Point && allowPoint) {
3998
- const [lon, lat, alt] = geometry.Point.split(',').map(Number);
3999
- const coordinates = excludeAltitude ? [lon, lat] : [lon, lat, altitude !== undefined ? altitude : (alt !== undefined ? alt : [])];
4000
- feature.geometry = {
4001
- type: "Point",
4002
- coordinates,
4003
- };
4004
- }
4005
- if (feature.geometry) {
4006
- features.push(feature);
4007
- }
4008
- };
4009
- entities.forEach(entity => {
4010
- var _a, _b, _c;
4011
- if (!((_a = entity === null || entity === void 0 ? void 0 : entity.Bruce) === null || _a === void 0 ? void 0 : _a.ID)) {
4012
- return;
4013
- }
4014
- let geometry = entity.Bruce.VectorGeometry;
4015
- if (!geometry && (((_b = entity.Bruce.Location) === null || _b === void 0 ? void 0 : _b.longitude) && ((_c = entity.Bruce.Location) === null || _c === void 0 ? void 0 : _c.latitude))) {
4016
- geometry = {
4017
- Point: `${entity.Bruce.Location.longitude},${entity.Bruce.Location.latitude}` + (entity.Bruce.Location.altitude != null ? `,${entity.Bruce.Location.altitude}` : ""),
4018
- };
4019
- }
4020
- if (geometry) {
4021
- processGeometry(geometry, entity);
4022
- }
4023
- });
4024
- return {
4025
- type: "FeatureCollection",
4026
- features,
4027
- };
4028
- }
4029
- Entity.ToGeoJson = ToGeoJson;
4030
3761
  /**
4031
3762
  * Returns cache identifier for an entity record.
4032
3763
  * Example: {
@@ -4161,12 +3892,12 @@
4161
3892
  path = path.replace("${", "");
4162
3893
  path = path.replace("}", "");
4163
3894
  }
3895
+ // Split by backslashes.
3896
+ paths.push(exports.PathUtils.Parse(path));
4164
3897
  // Split by dots.
4165
3898
  paths.push(exports.PathUtils.ParseLegacy(path));
4166
3899
  // Take string as is.
4167
3900
  paths.push([path]);
4168
- // Split by backslashes.
4169
- paths.push(exports.PathUtils.Parse(path));
4170
3901
  // Remove duplicates.
4171
3902
  const tmpPaths = [];
4172
3903
  for (let i = 0; i < paths.length; i++) {
@@ -4455,11 +4186,17 @@
4455
4186
  entity: entity,
4456
4187
  path: attrPath
4457
4188
  });
4458
- const isValueNum = !isNaN(+eValue);
4189
+ let isValueNum = !isNaN(+eValue);
4190
+ if (eValue == null) {
4191
+ isValueNum = false;
4192
+ }
4459
4193
  for (let i = 0; i < value.values.length; i++) {
4460
4194
  const option = value.values[i];
4461
4195
  const mapValue = option.fieldValue;
4462
- const isMapValueNum = !isNaN(+mapValue);
4196
+ let isMapValueNum = !isNaN(+mapValue);
4197
+ if (isMapValueNum == null) {
4198
+ isMapValueNum = false;
4199
+ }
4463
4200
  if (isValueNum && (isMapValueNum || mapValue.includes("-"))) {
4464
4201
  if (+mapValue == +eValue) {
4465
4202
  return option.appliedValue;
@@ -4590,6 +4327,469 @@
4590
4327
  Calculator.GetInputValue = GetInputValue;
4591
4328
  })(exports.Calculator || (exports.Calculator = {}));
4592
4329
 
4330
+ /**
4331
+ * GeoJSON data structures.
4332
+ */
4333
+ (function (GeoJson) {
4334
+ let EType;
4335
+ (function (EType) {
4336
+ EType["Point"] = "Point";
4337
+ EType["MultiPoint"] = "MultiPoint";
4338
+ EType["LineString"] = "LineString";
4339
+ EType["MultiLineString"] = "MultiLineString";
4340
+ EType["Polygon"] = "Polygon";
4341
+ EType["MultiPolygon"] = "MultiPolygon";
4342
+ EType["GeometryCollection"] = "GeometryCollection";
4343
+ EType["Feature"] = "Feature";
4344
+ EType["FeatureCollection"] = "FeatureCollection";
4345
+ })(EType = GeoJson.EType || (GeoJson.EType = {}));
4346
+ })(exports.GeoJson || (exports.GeoJson = {}));
4347
+
4348
+ (function (Geometry) {
4349
+ let EPolygonRingType;
4350
+ (function (EPolygonRingType) {
4351
+ EPolygonRingType["Boundaries"] = "out";
4352
+ EPolygonRingType["Hole"] = "in";
4353
+ })(EPolygonRingType = Geometry.EPolygonRingType || (Geometry.EPolygonRingType = {}));
4354
+ /**
4355
+ * Turns an array of points into string vector geometry that Bruce can use.
4356
+ * This is used for saving polyline and polygon data.
4357
+ * @param points
4358
+ * @returns
4359
+ */
4360
+ function LineStrFromPoints(points) {
4361
+ if (!points.length) {
4362
+ throw ("points is empty.");
4363
+ }
4364
+ let carto = points[0];
4365
+ let lineString = `${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
4366
+ for (let i = 1; i < points.length; i++) {
4367
+ carto = points[i];
4368
+ lineString += ` ${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
4369
+ }
4370
+ return lineString;
4371
+ }
4372
+ Geometry.LineStrFromPoints = LineStrFromPoints;
4373
+ /**
4374
+ * Removes same points that occur in a row.
4375
+ * This will not modify the original array.
4376
+ * @param positions
4377
+ * @returns
4378
+ */
4379
+ function RemoveRepeatPoints(positions) {
4380
+ const filteredList = [];
4381
+ for (let i = 0; i < positions.length; i++) {
4382
+ const pos = positions[i];
4383
+ const lastPos = filteredList.length > 0 ? filteredList[filteredList.length - 1] : null;
4384
+ if (!lastPos || (pos.latitude != lastPos.latitude || pos.longitude != lastPos.longitude || pos.altitude != lastPos.altitude)) {
4385
+ filteredList.push(pos);
4386
+ }
4387
+ }
4388
+ return filteredList;
4389
+ }
4390
+ Geometry.RemoveRepeatPoints = RemoveRepeatPoints;
4391
+ /**
4392
+ * Parses a string of points into an array of points.
4393
+ * @param pointsStr
4394
+ * @returns
4395
+ */
4396
+ function ParsePoints(pointsStr) {
4397
+ pointsStr = pointsStr.replace(/[^\d.,-\s]/g, "");
4398
+ let splitterCoordinates = " ";
4399
+ let splitterAxis = ",";
4400
+ const commaIndex = pointsStr.indexOf(",");
4401
+ const spaceIndex = pointsStr.indexOf(" ");
4402
+ if ((spaceIndex > -1 && commaIndex > spaceIndex) || commaIndex <= -1) {
4403
+ splitterCoordinates = ",";
4404
+ splitterAxis = " ";
4405
+ }
4406
+ let points = pointsStr.trim().split(splitterCoordinates);
4407
+ points = points.filter(a => a != "");
4408
+ const result = [];
4409
+ for (let i = 0; i < points.length; i++) {
4410
+ const pointData = points[i];
4411
+ const coords = pointData.trim().split(splitterAxis);
4412
+ if (coords.length == 2 || coords.length == 3) {
4413
+ const longitude = Number(coords[0]);
4414
+ const latitude = Number(coords[1]);
4415
+ const altitude = Number(coords.length >= 3 ? coords[2] : 0);
4416
+ if (longitude != null && latitude != null) {
4417
+ result.push({
4418
+ altitude: altitude,
4419
+ latitude: latitude,
4420
+ longitude: longitude
4421
+ });
4422
+ }
4423
+ else {
4424
+ console.warn("Invalid point data detected.", pointData);
4425
+ }
4426
+ }
4427
+ }
4428
+ return result;
4429
+ }
4430
+ Geometry.ParsePoints = ParsePoints;
4431
+ /**
4432
+ * Parses both string and object Bruce geometry.
4433
+ * String geometry is legacy Bruce data.
4434
+ * @param geometry
4435
+ * @returns
4436
+ */
4437
+ function ParseGeometry(geometry) {
4438
+ if (typeof geometry == "string") {
4439
+ let positions = [];
4440
+ const geometryParsed = (geometry || "").split(";");
4441
+ for (let i = 0; i < geometryParsed.length; i++) {
4442
+ const data = geometryParsed[i];
4443
+ const points = ParsePoints(data);
4444
+ if (points && points.length > 0) {
4445
+ positions = positions.concat(points);
4446
+ }
4447
+ }
4448
+ positions = RemoveRepeatPoints(positions);
4449
+ const newGeometry = {};
4450
+ if (positions.length > 0) {
4451
+ const topPoint = positions[0];
4452
+ newGeometry.Point = `${topPoint.latitude},${topPoint.longitude}` + (topPoint.altitude != null ? `,${topPoint.altitude}` : "");
4453
+ if (positions.length > 1) {
4454
+ newGeometry.Polygon = [{ Facing: EPolygonRingType.Boundaries, LinearRing: LineStrFromPoints(positions) }];
4455
+ }
4456
+ if (positions.length > 2) {
4457
+ newGeometry.LineString = LineStrFromPoints(positions);
4458
+ }
4459
+ }
4460
+ return newGeometry;
4461
+ }
4462
+ return geometry;
4463
+ }
4464
+ Geometry.ParseGeometry = ParseGeometry;
4465
+ /**
4466
+ * Converts Bruce geometry to GeoJSON.
4467
+ * @param geometry
4468
+ * @returns returns GeoJSON or null if conversion failed or resulted in an empty object.
4469
+ */
4470
+ function ToGeoJsonFeature(params) {
4471
+ const { geometry, properties, altitude } = params;
4472
+ // Primary collection of geometries.
4473
+ // We will return a single feature that contains many geometries.
4474
+ // That way we can attach properties to the top-level.
4475
+ const collection = [];
4476
+ // Returns if two coordinates are equal.
4477
+ const areCoordinatesEqual = (coord1, coord2) => {
4478
+ return coord1[0] === coord2[0] && coord1[1] === coord2[1] && coord1[2] === coord2[2];
4479
+ };
4480
+ // Removes consecutive duplicate coordinates.
4481
+ const removeConsecutiveDuplicates = (coordinates) => {
4482
+ return coordinates.filter((coord, index) => {
4483
+ return index === 0 || !areCoordinatesEqual(coord, coordinates[index - 1]);
4484
+ });
4485
+ };
4486
+ // Ensures that the polygon is closed.
4487
+ const closePolygonCoordinates = (coordinates) => {
4488
+ return coordinates.map(ring => {
4489
+ if (!areCoordinatesEqual(ring[0], ring[ring.length - 1])) {
4490
+ ring.push(ring[0]);
4491
+ }
4492
+ return ring;
4493
+ });
4494
+ };
4495
+ /**
4496
+ * Processes Bruce geometry.
4497
+ * Called recursively for MultiGeometry.
4498
+ * @param geometry
4499
+ * @returns if a geometry was processed and added.
4500
+ */
4501
+ const processGeometry = (geometry) => {
4502
+ var _a, _b;
4503
+ let jGeometry = null;
4504
+ // We add in order of priority while ignoring anything lower priority.
4505
+ // This mimics how we render Bruce geometry.
4506
+ if ((_a = geometry.MultiGeometry) === null || _a === void 0 ? void 0 : _a.length) {
4507
+ let passed = false;
4508
+ geometry.MultiGeometry.forEach(geo => {
4509
+ if (processGeometry(geo)) {
4510
+ passed = true;
4511
+ }
4512
+ });
4513
+ if (passed) {
4514
+ return true;
4515
+ }
4516
+ }
4517
+ if (!jGeometry && ((_b = geometry.Polygon) === null || _b === void 0 ? void 0 : _b.length)) {
4518
+ // Sorts polygons so that boundaries come first.
4519
+ const sortedPolygons = geometry.Polygon.sort((a, b) => a.Facing === Geometry.EPolygonRingType.Boundaries ? -1 : 1);
4520
+ // Converts polygons to GeoJSON coordinates.
4521
+ // This will close the polygon if it's not already closed and remove consecutive duplicates.
4522
+ const coordinates = closePolygonCoordinates(sortedPolygons.map(polygon => {
4523
+ return removeConsecutiveDuplicates(polygon.LinearRing.split(' ').map(coord => {
4524
+ const [lon, lat, alt] = coord.split(',').map(Number);
4525
+ return (altitude != null ? [lon, lat, altitude] : [lon, lat, alt !== undefined ? alt : 0]);
4526
+ }));
4527
+ }));
4528
+ if (coordinates.every(polygon => polygon.length >= 4)) {
4529
+ jGeometry = {
4530
+ coordinates: coordinates,
4531
+ type: exports.GeoJson.EType.Polygon
4532
+ };
4533
+ }
4534
+ }
4535
+ if (!jGeometry && geometry.LineString) {
4536
+ const coordinates = removeConsecutiveDuplicates(geometry.LineString.split(' ').map(coord => {
4537
+ const [lon, lat, alt] = coord.split(',').map(Number);
4538
+ return (altitude != null ? [lon, lat, altitude] : [lon, lat, alt !== undefined ? alt : 0]);
4539
+ }));
4540
+ if (coordinates.length >= 2) {
4541
+ jGeometry = {
4542
+ coordinates: coordinates,
4543
+ type: exports.GeoJson.EType.LineString
4544
+ };
4545
+ }
4546
+ }
4547
+ if (!jGeometry && geometry.Point) {
4548
+ const [lon, lat, alt] = geometry.Point.split(',').map(Number);
4549
+ const coordinates = altitude != null ? [lon, lat, altitude] : [lon, lat, alt !== undefined ? alt : 0];
4550
+ jGeometry = {
4551
+ coordinates: coordinates,
4552
+ type: exports.GeoJson.EType.Point
4553
+ };
4554
+ }
4555
+ if (jGeometry) {
4556
+ collection.push(jGeometry);
4557
+ return true;
4558
+ }
4559
+ // Nothing :(
4560
+ return false;
4561
+ };
4562
+ // Add all geometries to the collection.
4563
+ processGeometry(geometry);
4564
+ // Nothing was produced.
4565
+ if (!collection.length) {
4566
+ return null;
4567
+ }
4568
+ // Just 1 item. We can have a single feature rather than geometry collection.
4569
+ if (collection.length === 1) {
4570
+ const geoJson = {
4571
+ type: exports.GeoJson.EType.Feature,
4572
+ geometry: collection[0],
4573
+ properties: properties || {}
4574
+ };
4575
+ return geoJson;
4576
+ }
4577
+ // Construct the base feature and append the collection.
4578
+ const geoJson = {
4579
+ type: exports.GeoJson.EType.Feature,
4580
+ geometry: {
4581
+ type: exports.GeoJson.EType.GeometryCollection,
4582
+ geometries: collection
4583
+ },
4584
+ properties: properties || {}
4585
+ };
4586
+ return geoJson;
4587
+ }
4588
+ Geometry.ToGeoJsonFeature = ToGeoJsonFeature;
4589
+ /**
4590
+ * Converts GeoJSON to Bruce geometry.
4591
+ * @param geoJson
4592
+ * @returns
4593
+ */
4594
+ function FromGeoJson(params) {
4595
+ var _a;
4596
+ const { geoJson } = params;
4597
+ // Don't process if there's no geometry.
4598
+ if (geoJson.type === exports.GeoJson.EType.FeatureCollection) {
4599
+ if (!geoJson.features.length) {
4600
+ return null;
4601
+ }
4602
+ }
4603
+ // We start by populating multi-geometry.
4604
+ // If we end up with only 1 level then we'll return the single geometry.
4605
+ const full = {
4606
+ MultiGeometry: []
4607
+ };
4608
+ // Merged properties added to as we go.
4609
+ const properties = {};
4610
+ // Traverse a geojson hierarchy and generate a Bruce multi-geometry from it.
4611
+ // This will append to the "full" object as it goes.
4612
+ const traverse = (feature) => {
4613
+ // Geometry collections don't have coords so we have to cast as any.
4614
+ const { type, coordinates, properties } = feature.geometry;
4615
+ // Unknown thing. Ignoring.
4616
+ if (!type) {
4617
+ return;
4618
+ }
4619
+ // No coordinates. Ignoring.
4620
+ if (!coordinates) {
4621
+ return;
4622
+ }
4623
+ // Simple properties merge.
4624
+ // Doesn't handle nested properties very well.
4625
+ if (properties) {
4626
+ Object.assign(properties, properties);
4627
+ }
4628
+ // We'll first match cases of nested collections and handle them early.
4629
+ // Then we'll be left with simple geometry cases.
4630
+ if (type === exports.GeoJson.EType.GeometryCollection) {
4631
+ const collection = feature;
4632
+ for (let i = 0; i < collection.geometries.length; i++) {
4633
+ const geo = collection.geometries[i];
4634
+ traverse({
4635
+ type: exports.GeoJson.EType.Feature,
4636
+ geometry: geo,
4637
+ properties: feature.properties
4638
+ });
4639
+ }
4640
+ return;
4641
+ }
4642
+ else if (type === exports.GeoJson.EType.FeatureCollection) {
4643
+ const collection = feature;
4644
+ for (let i = 0; i < collection.features.length; i++) {
4645
+ traverse(collection.features[i]);
4646
+ }
4647
+ return;
4648
+ }
4649
+ const geometry = {};
4650
+ switch (type) {
4651
+ case exports.GeoJson.EType.Polygon:
4652
+ if (!geometry.Polygon) {
4653
+ geometry.Polygon = [];
4654
+ }
4655
+ coordinates.forEach((polygon, index) => {
4656
+ const linearRing = polygon.map(coord => coord.join(',')).join(' ');
4657
+ geometry.Polygon.push({
4658
+ LinearRing: linearRing,
4659
+ Facing: index === 0 ? Geometry.EPolygonRingType.Boundaries : Geometry.EPolygonRingType.Hole
4660
+ });
4661
+ });
4662
+ break;
4663
+ case exports.GeoJson.EType.LineString:
4664
+ geometry.LineString = coordinates.map((coord) => coord.join(',')).join(' ');
4665
+ break;
4666
+ case exports.GeoJson.EType.Point:
4667
+ geometry.Point = coordinates.join(',');
4668
+ break;
4669
+ case exports.GeoJson.EType.MultiPolygon:
4670
+ if (!geometry.MultiGeometry) {
4671
+ geometry.MultiGeometry = [];
4672
+ }
4673
+ coordinates.forEach((multiPolygon) => {
4674
+ const multiPolygonGeometry = { Polygon: [] };
4675
+ multiPolygon.forEach((polygon, index) => {
4676
+ const linearRing = polygon.map(coord => coord.join(',')).join(' ');
4677
+ multiPolygonGeometry.Polygon.push({
4678
+ LinearRing: linearRing,
4679
+ Facing: index === 0 ? Geometry.EPolygonRingType.Boundaries : Geometry.EPolygonRingType.Hole
4680
+ });
4681
+ });
4682
+ geometry.MultiGeometry.push(multiPolygonGeometry);
4683
+ });
4684
+ break;
4685
+ case exports.GeoJson.EType.MultiLineString:
4686
+ if (!geometry.MultiGeometry) {
4687
+ geometry.MultiGeometry = [];
4688
+ }
4689
+ coordinates.forEach((multiLineString) => {
4690
+ geometry.MultiGeometry.push({
4691
+ LineString: multiLineString.map((coord) => coord.join(',')).join(' ')
4692
+ });
4693
+ });
4694
+ break;
4695
+ case exports.GeoJson.EType.MultiPoint:
4696
+ if (!geometry.MultiGeometry) {
4697
+ geometry.MultiGeometry = [];
4698
+ }
4699
+ coordinates.forEach((multiPoint) => {
4700
+ geometry.MultiGeometry.push({
4701
+ Point: multiPoint.join(',')
4702
+ });
4703
+ });
4704
+ break;
4705
+ default:
4706
+ return;
4707
+ }
4708
+ // Nothing to do. Nothing was made.
4709
+ if (Object.keys(geometry).length === 0) {
4710
+ return;
4711
+ }
4712
+ full.MultiGeometry.push(geometry);
4713
+ };
4714
+ // Traverse all features.
4715
+ if (geoJson.type === exports.GeoJson.EType.Feature) {
4716
+ traverse(geoJson);
4717
+ }
4718
+ else {
4719
+ (_a = geoJson.features) === null || _a === void 0 ? void 0 : _a.forEach(traverse);
4720
+ }
4721
+ // If we only have 1 geometry then we'll return it directly.
4722
+ if (full.MultiGeometry.length === 1) {
4723
+ return {
4724
+ geometry: full.MultiGeometry[0],
4725
+ properties: properties
4726
+ };
4727
+ }
4728
+ // If we have multiple but only 1 of each type then that's standard Bruce stuff.
4729
+ // Eg: 1 point, 1 line, 1 polygon is a very normal Bruce geometry.
4730
+ const countsPerType = {
4731
+ Point: 0,
4732
+ LineString: 0,
4733
+ Polygon: 0
4734
+ };
4735
+ full.MultiGeometry.forEach(geo => {
4736
+ if (geo.Point) {
4737
+ countsPerType.Point++;
4738
+ }
4739
+ else if (geo.LineString) {
4740
+ countsPerType.LineString++;
4741
+ }
4742
+ else if (geo.Polygon) {
4743
+ countsPerType.Polygon++;
4744
+ }
4745
+ });
4746
+ if (countsPerType.Point === 1 && countsPerType.LineString === 1 && countsPerType.Polygon === 1) {
4747
+ const merged = {};
4748
+ const addToMerged = (geo) => {
4749
+ if (geo.Point) {
4750
+ merged.Point = geo.Point;
4751
+ }
4752
+ else if (geo.LineString) {
4753
+ merged.LineString = geo.LineString;
4754
+ }
4755
+ else if (geo.Polygon) {
4756
+ merged.Polygon = geo.Polygon;
4757
+ }
4758
+ };
4759
+ full.MultiGeometry.forEach(addToMerged);
4760
+ return {
4761
+ geometry: merged,
4762
+ properties: properties
4763
+ };
4764
+ }
4765
+ // If there are many polygons but only 1 line and/or 1 point then we'll put those singles into the top-level.
4766
+ // Eg: 5 polygons, 1 point, 1 line. That should be a single geometry.
4767
+ if (countsPerType.Polygon > 1 && (countsPerType.LineString <= 1 && countsPerType.Point <= 1)) {
4768
+ const semiMerged = {};
4769
+ const addToSemiMerged = (geo) => {
4770
+ if (geo.Point) {
4771
+ semiMerged.Point = geo.Point;
4772
+ }
4773
+ else if (geo.LineString) {
4774
+ semiMerged.LineString = geo.LineString;
4775
+ }
4776
+ };
4777
+ semiMerged.MultiGeometry = full.MultiGeometry.filter(geo => geo.Polygon);
4778
+ full.MultiGeometry.forEach(addToSemiMerged);
4779
+ return {
4780
+ geometry: semiMerged,
4781
+ properties: properties
4782
+ };
4783
+ }
4784
+ // More than 1 of each, then return the full multi-geometry as-is.
4785
+ return {
4786
+ geometry: full,
4787
+ properties: properties
4788
+ };
4789
+ }
4790
+ Geometry.FromGeoJson = FromGeoJson;
4791
+ })(exports.Geometry || (exports.Geometry = {}));
4792
+
4593
4793
  (function (Bounds) {
4594
4794
  /**
4595
4795
  * Calculates boundaries from entity.
@@ -8574,6 +8774,27 @@
8574
8774
  ProgramKey.GetListCacheKey = GetListCacheKey;
8575
8775
  })(exports.ProgramKey || (exports.ProgramKey = {}));
8576
8776
 
8777
+ /**
8778
+ * Describes an expectation on what should be rendered for a menu item-
8779
+ * between a min-max distance of an entity to the camera.
8780
+ */
8781
+ (function (ZoomControl) {
8782
+ /**
8783
+ * Available display types for a menu item.
8784
+ */
8785
+ let EDisplayType;
8786
+ (function (EDisplayType) {
8787
+ // Hidden means it will not be rendered.
8788
+ EDisplayType["Hidden"] = "hidden";
8789
+ // Point will try render a point based on any available Entity data.
8790
+ EDisplayType["Point"] = "point";
8791
+ // Geometry means it will try render multi-geometry, polygon, polyline, or point in order of priority.
8792
+ EDisplayType["Geometry"] = "geometry";
8793
+ // 3D means it will try render 3D model, multi-geometry, polygon, polyline, or point in order of priority.
8794
+ EDisplayType["Model3D"] = "3d";
8795
+ })(EDisplayType = ZoomControl.EDisplayType || (ZoomControl.EDisplayType = {}));
8796
+ })(exports.ZoomControl || (exports.ZoomControl = {}));
8797
+
8577
8798
  /**
8578
8799
  * Converts legacy records into something easier to work with alongside the newer ones.
8579
8800
  * On save we'll convert back to the legacy format.
@@ -13525,7 +13746,7 @@
13525
13746
  })(exports.DataSource || (exports.DataSource = {}));
13526
13747
 
13527
13748
  // This is updated with the package.json version on build.
13528
- const VERSION = "4.6.4";
13749
+ const VERSION = "4.6.6";
13529
13750
 
13530
13751
  exports.VERSION = VERSION;
13531
13752
  exports.AbstractApi = AbstractApi;