bruce-models 4.6.5 → 4.6.7

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: {
@@ -4596,6 +4327,474 @@
4596
4327
  Calculator.GetInputValue = GetInputValue;
4597
4328
  })(exports.Calculator || (exports.Calculator = {}));
4598
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
+ const points = ParsePoints(polygon.LinearRing);
4524
+ return removeConsecutiveDuplicates(points.map(coord => {
4525
+ const { longitude: lon, latitude: lat, altitude: alt } = coord;
4526
+ return (altitude != null ? [lon, lat, altitude] : [lon, lat, alt !== undefined ? alt : 0]);
4527
+ }));
4528
+ }));
4529
+ if (coordinates.every(polygon => polygon.length >= 4)) {
4530
+ jGeometry = {
4531
+ coordinates: coordinates,
4532
+ type: exports.GeoJson.EType.Polygon
4533
+ };
4534
+ }
4535
+ }
4536
+ if (!jGeometry && geometry.LineString) {
4537
+ const points = ParsePoints(geometry.LineString);
4538
+ const coordinates = removeConsecutiveDuplicates(points.map(coord => {
4539
+ const { longitude: lon, latitude: lat, altitude: alt } = coord;
4540
+ return (altitude != null ? [lon, lat, altitude] : [lon, lat, alt !== undefined ? alt : 0]);
4541
+ }));
4542
+ if (coordinates.length >= 2) {
4543
+ jGeometry = {
4544
+ coordinates: coordinates,
4545
+ type: exports.GeoJson.EType.LineString
4546
+ };
4547
+ }
4548
+ }
4549
+ if (!jGeometry && geometry.Point) {
4550
+ const points = ParsePoints(geometry.Point);
4551
+ if (points.length) {
4552
+ const { longitude: lon, latitude: lat, altitude: alt } = points[0];
4553
+ const coordinates = altitude != null ? [lon, lat, altitude] : [lon, lat, alt !== undefined ? alt : 0];
4554
+ jGeometry = {
4555
+ coordinates: coordinates,
4556
+ type: exports.GeoJson.EType.Point
4557
+ };
4558
+ }
4559
+ }
4560
+ if (jGeometry) {
4561
+ collection.push(jGeometry);
4562
+ return true;
4563
+ }
4564
+ // Nothing :(
4565
+ return false;
4566
+ };
4567
+ // Add all geometries to the collection.
4568
+ processGeometry(geometry);
4569
+ // Nothing was produced.
4570
+ if (!collection.length) {
4571
+ return null;
4572
+ }
4573
+ // Just 1 item. We can have a single feature rather than geometry collection.
4574
+ if (collection.length === 1) {
4575
+ const geoJson = {
4576
+ type: exports.GeoJson.EType.Feature,
4577
+ geometry: collection[0],
4578
+ properties: properties || {}
4579
+ };
4580
+ return geoJson;
4581
+ }
4582
+ // Construct the base feature and append the collection.
4583
+ const geoJson = {
4584
+ type: exports.GeoJson.EType.Feature,
4585
+ geometry: {
4586
+ type: exports.GeoJson.EType.GeometryCollection,
4587
+ geometries: collection
4588
+ },
4589
+ properties: properties || {}
4590
+ };
4591
+ return geoJson;
4592
+ }
4593
+ Geometry.ToGeoJsonFeature = ToGeoJsonFeature;
4594
+ /**
4595
+ * Converts GeoJSON to Bruce geometry.
4596
+ * @param geoJson
4597
+ * @returns
4598
+ */
4599
+ function FromGeoJson(params) {
4600
+ var _a;
4601
+ const { geoJson } = params;
4602
+ // Don't process if there's no geometry.
4603
+ if (geoJson.type === exports.GeoJson.EType.FeatureCollection) {
4604
+ if (!geoJson.features.length) {
4605
+ return null;
4606
+ }
4607
+ }
4608
+ // We start by populating multi-geometry.
4609
+ // If we end up with only 1 level then we'll return the single geometry.
4610
+ const full = {
4611
+ MultiGeometry: []
4612
+ };
4613
+ // Merged properties added to as we go.
4614
+ const properties = {};
4615
+ // Traverse a geojson hierarchy and generate a Bruce multi-geometry from it.
4616
+ // This will append to the "full" object as it goes.
4617
+ const traverse = (feature) => {
4618
+ // Geometry collections don't have coords so we have to cast as any.
4619
+ const { type, coordinates, properties } = feature.geometry;
4620
+ // Unknown thing. Ignoring.
4621
+ if (!type) {
4622
+ return;
4623
+ }
4624
+ // No coordinates. Ignoring.
4625
+ if (!coordinates) {
4626
+ return;
4627
+ }
4628
+ // Simple properties merge.
4629
+ // Doesn't handle nested properties very well.
4630
+ if (properties) {
4631
+ Object.assign(properties, properties);
4632
+ }
4633
+ // We'll first match cases of nested collections and handle them early.
4634
+ // Then we'll be left with simple geometry cases.
4635
+ if (type === exports.GeoJson.EType.GeometryCollection) {
4636
+ const collection = feature;
4637
+ for (let i = 0; i < collection.geometries.length; i++) {
4638
+ const geo = collection.geometries[i];
4639
+ traverse({
4640
+ type: exports.GeoJson.EType.Feature,
4641
+ geometry: geo,
4642
+ properties: feature.properties
4643
+ });
4644
+ }
4645
+ return;
4646
+ }
4647
+ else if (type === exports.GeoJson.EType.FeatureCollection) {
4648
+ const collection = feature;
4649
+ for (let i = 0; i < collection.features.length; i++) {
4650
+ traverse(collection.features[i]);
4651
+ }
4652
+ return;
4653
+ }
4654
+ const geometry = {};
4655
+ switch (type) {
4656
+ case exports.GeoJson.EType.Polygon:
4657
+ if (!geometry.Polygon) {
4658
+ geometry.Polygon = [];
4659
+ }
4660
+ coordinates.forEach((polygon, index) => {
4661
+ const linearRing = polygon.map(coord => coord.join(',')).join(' ');
4662
+ geometry.Polygon.push({
4663
+ LinearRing: linearRing,
4664
+ Facing: index === 0 ? Geometry.EPolygonRingType.Boundaries : Geometry.EPolygonRingType.Hole
4665
+ });
4666
+ });
4667
+ break;
4668
+ case exports.GeoJson.EType.LineString:
4669
+ geometry.LineString = coordinates.map((coord) => coord.join(',')).join(' ');
4670
+ break;
4671
+ case exports.GeoJson.EType.Point:
4672
+ geometry.Point = coordinates.join(',');
4673
+ break;
4674
+ case exports.GeoJson.EType.MultiPolygon:
4675
+ if (!geometry.MultiGeometry) {
4676
+ geometry.MultiGeometry = [];
4677
+ }
4678
+ coordinates.forEach((multiPolygon) => {
4679
+ const multiPolygonGeometry = { Polygon: [] };
4680
+ multiPolygon.forEach((polygon, index) => {
4681
+ const linearRing = polygon.map(coord => coord.join(',')).join(' ');
4682
+ multiPolygonGeometry.Polygon.push({
4683
+ LinearRing: linearRing,
4684
+ Facing: index === 0 ? Geometry.EPolygonRingType.Boundaries : Geometry.EPolygonRingType.Hole
4685
+ });
4686
+ });
4687
+ geometry.MultiGeometry.push(multiPolygonGeometry);
4688
+ });
4689
+ break;
4690
+ case exports.GeoJson.EType.MultiLineString:
4691
+ if (!geometry.MultiGeometry) {
4692
+ geometry.MultiGeometry = [];
4693
+ }
4694
+ coordinates.forEach((multiLineString) => {
4695
+ geometry.MultiGeometry.push({
4696
+ LineString: multiLineString.map((coord) => coord.join(',')).join(' ')
4697
+ });
4698
+ });
4699
+ break;
4700
+ case exports.GeoJson.EType.MultiPoint:
4701
+ if (!geometry.MultiGeometry) {
4702
+ geometry.MultiGeometry = [];
4703
+ }
4704
+ coordinates.forEach((multiPoint) => {
4705
+ geometry.MultiGeometry.push({
4706
+ Point: multiPoint.join(',')
4707
+ });
4708
+ });
4709
+ break;
4710
+ default:
4711
+ return;
4712
+ }
4713
+ // Nothing to do. Nothing was made.
4714
+ if (Object.keys(geometry).length === 0) {
4715
+ return;
4716
+ }
4717
+ full.MultiGeometry.push(geometry);
4718
+ };
4719
+ // Traverse all features.
4720
+ if (geoJson.type === exports.GeoJson.EType.Feature) {
4721
+ traverse(geoJson);
4722
+ }
4723
+ else {
4724
+ (_a = geoJson.features) === null || _a === void 0 ? void 0 : _a.forEach(traverse);
4725
+ }
4726
+ // If we only have 1 geometry then we'll return it directly.
4727
+ if (full.MultiGeometry.length === 1) {
4728
+ return {
4729
+ geometry: full.MultiGeometry[0],
4730
+ properties: properties
4731
+ };
4732
+ }
4733
+ // If we have multiple but only 1 of each type then that's standard Bruce stuff.
4734
+ // Eg: 1 point, 1 line, 1 polygon is a very normal Bruce geometry.
4735
+ const countsPerType = {
4736
+ Point: 0,
4737
+ LineString: 0,
4738
+ Polygon: 0
4739
+ };
4740
+ full.MultiGeometry.forEach(geo => {
4741
+ if (geo.Point) {
4742
+ countsPerType.Point++;
4743
+ }
4744
+ else if (geo.LineString) {
4745
+ countsPerType.LineString++;
4746
+ }
4747
+ else if (geo.Polygon) {
4748
+ countsPerType.Polygon++;
4749
+ }
4750
+ });
4751
+ if (countsPerType.Point === 1 && countsPerType.LineString === 1 && countsPerType.Polygon === 1) {
4752
+ const merged = {};
4753
+ const addToMerged = (geo) => {
4754
+ if (geo.Point) {
4755
+ merged.Point = geo.Point;
4756
+ }
4757
+ else if (geo.LineString) {
4758
+ merged.LineString = geo.LineString;
4759
+ }
4760
+ else if (geo.Polygon) {
4761
+ merged.Polygon = geo.Polygon;
4762
+ }
4763
+ };
4764
+ full.MultiGeometry.forEach(addToMerged);
4765
+ return {
4766
+ geometry: merged,
4767
+ properties: properties
4768
+ };
4769
+ }
4770
+ // If there are many polygons but only 1 line and/or 1 point then we'll put those singles into the top-level.
4771
+ // Eg: 5 polygons, 1 point, 1 line. That should be a single geometry.
4772
+ if (countsPerType.Polygon > 1 && (countsPerType.LineString <= 1 && countsPerType.Point <= 1)) {
4773
+ const semiMerged = {};
4774
+ const addToSemiMerged = (geo) => {
4775
+ if (geo.Point) {
4776
+ semiMerged.Point = geo.Point;
4777
+ }
4778
+ else if (geo.LineString) {
4779
+ semiMerged.LineString = geo.LineString;
4780
+ }
4781
+ };
4782
+ semiMerged.MultiGeometry = full.MultiGeometry.filter(geo => geo.Polygon);
4783
+ full.MultiGeometry.forEach(addToSemiMerged);
4784
+ return {
4785
+ geometry: semiMerged,
4786
+ properties: properties
4787
+ };
4788
+ }
4789
+ // More than 1 of each, then return the full multi-geometry as-is.
4790
+ return {
4791
+ geometry: full,
4792
+ properties: properties
4793
+ };
4794
+ }
4795
+ Geometry.FromGeoJson = FromGeoJson;
4796
+ })(exports.Geometry || (exports.Geometry = {}));
4797
+
4599
4798
  (function (Bounds) {
4600
4799
  /**
4601
4800
  * Calculates boundaries from entity.
@@ -8580,6 +8779,27 @@
8580
8779
  ProgramKey.GetListCacheKey = GetListCacheKey;
8581
8780
  })(exports.ProgramKey || (exports.ProgramKey = {}));
8582
8781
 
8782
+ /**
8783
+ * Describes an expectation on what should be rendered for a menu item-
8784
+ * between a min-max distance of an entity to the camera.
8785
+ */
8786
+ (function (ZoomControl) {
8787
+ /**
8788
+ * Available display types for a menu item.
8789
+ */
8790
+ let EDisplayType;
8791
+ (function (EDisplayType) {
8792
+ // Hidden means it will not be rendered.
8793
+ EDisplayType["Hidden"] = "hidden";
8794
+ // Point will try render a point based on any available Entity data.
8795
+ EDisplayType["Point"] = "point";
8796
+ // Geometry means it will try render multi-geometry, polygon, polyline, or point in order of priority.
8797
+ EDisplayType["Geometry"] = "geometry";
8798
+ // 3D means it will try render 3D model, multi-geometry, polygon, polyline, or point in order of priority.
8799
+ EDisplayType["Model3D"] = "3d";
8800
+ })(EDisplayType = ZoomControl.EDisplayType || (ZoomControl.EDisplayType = {}));
8801
+ })(exports.ZoomControl || (exports.ZoomControl = {}));
8802
+
8583
8803
  /**
8584
8804
  * Converts legacy records into something easier to work with alongside the newer ones.
8585
8805
  * On save we'll convert back to the legacy format.
@@ -13531,7 +13751,7 @@
13531
13751
  })(exports.DataSource || (exports.DataSource = {}));
13532
13752
 
13533
13753
  // This is updated with the package.json version on build.
13534
- const VERSION = "4.6.5";
13754
+ const VERSION = "4.6.7";
13535
13755
 
13536
13756
  exports.VERSION = VERSION;
13537
13757
  exports.AbstractApi = AbstractApi;