bruce-models 3.4.2 → 3.4.4

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.
@@ -2436,6 +2436,128 @@
2436
2436
  Color.ColorFromStr = ColorFromStr;
2437
2437
  })(exports.Color || (exports.Color = {}));
2438
2438
 
2439
+ /**
2440
+ * Describes vector geometry that Bruce uses.
2441
+ */
2442
+ (function (Geometry) {
2443
+ let EPolygonRingType;
2444
+ (function (EPolygonRingType) {
2445
+ EPolygonRingType["Boundaries"] = "out";
2446
+ EPolygonRingType["Hole"] = "in";
2447
+ })(EPolygonRingType = Geometry.EPolygonRingType || (Geometry.EPolygonRingType = {}));
2448
+ /**
2449
+ * Turns an array of points into string vector geometry that Bruce can use.
2450
+ * This is used for saving polyline and polygon data.
2451
+ * @param points
2452
+ * @returns
2453
+ */
2454
+ function LineStrFromPoints(points) {
2455
+ if (!points.length) {
2456
+ throw ("points is empty.");
2457
+ }
2458
+ let carto = points[0];
2459
+ let lineString = `${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
2460
+ for (let i = 1; i < points.length; i++) {
2461
+ carto = points[i];
2462
+ lineString += ` ${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
2463
+ }
2464
+ return lineString;
2465
+ }
2466
+ Geometry.LineStrFromPoints = LineStrFromPoints;
2467
+ /**
2468
+ * Removes same points that occur in a row.
2469
+ * This will not modify the original array.
2470
+ * @param positions
2471
+ * @returns
2472
+ */
2473
+ function RemoveRepeatPoints(positions) {
2474
+ const filteredList = [];
2475
+ for (let i = 0; i < positions.length; i++) {
2476
+ const pos = positions[i];
2477
+ const lastPos = filteredList.length > 0 ? filteredList[filteredList.length - 1] : null;
2478
+ if (!lastPos || (pos.latitude != lastPos.latitude || pos.longitude != lastPos.longitude || pos.altitude != lastPos.altitude)) {
2479
+ filteredList.push(pos);
2480
+ }
2481
+ }
2482
+ return filteredList;
2483
+ }
2484
+ Geometry.RemoveRepeatPoints = RemoveRepeatPoints;
2485
+ /**
2486
+ * Parses a string of points into an array of points.
2487
+ * @param pointsStr
2488
+ * @returns
2489
+ */
2490
+ function ParsePoints(pointsStr) {
2491
+ pointsStr = pointsStr.replace(/[^\d.,-\s]/g, "");
2492
+ let splitterCoordinates = " ";
2493
+ let splitterAxis = ",";
2494
+ const commaIndex = pointsStr.indexOf(",");
2495
+ const spaceIndex = pointsStr.indexOf(" ");
2496
+ if ((spaceIndex > -1 && commaIndex > spaceIndex) || commaIndex <= -1) {
2497
+ splitterCoordinates = ",";
2498
+ splitterAxis = " ";
2499
+ }
2500
+ let points = pointsStr.trim().split(splitterCoordinates);
2501
+ points = points.filter(a => a != "");
2502
+ const result = [];
2503
+ for (let i = 0; i < points.length; i++) {
2504
+ const pointData = points[i];
2505
+ const coords = pointData.trim().split(splitterAxis);
2506
+ if (coords.length == 2 || coords.length == 3) {
2507
+ const longitude = Number(coords[0]);
2508
+ const latitude = Number(coords[1]);
2509
+ const altitude = Number(coords.length >= 3 ? coords[2] : 0);
2510
+ if (longitude != null && latitude != null) {
2511
+ result.push({
2512
+ altitude: altitude,
2513
+ latitude: latitude,
2514
+ longitude: longitude
2515
+ });
2516
+ }
2517
+ else {
2518
+ console.warn("Invalid point data detected.", pointData);
2519
+ }
2520
+ }
2521
+ }
2522
+ return result;
2523
+ }
2524
+ Geometry.ParsePoints = ParsePoints;
2525
+ /**
2526
+ * Parses both string and object Bruce geometry.
2527
+ * String geometry is legacy Bruce data.
2528
+ * @param geometry
2529
+ * @returns
2530
+ */
2531
+ function ParseGeometry(geometry) {
2532
+ if (typeof geometry == "string") {
2533
+ let positions = [];
2534
+ const geometryParsed = (geometry || "").split(";");
2535
+ for (let i = 0; i < geometryParsed.length; i++) {
2536
+ const data = geometryParsed[i];
2537
+ const points = ParsePoints(data);
2538
+ if (points && points.length > 0) {
2539
+ positions = positions.concat(points);
2540
+ }
2541
+ }
2542
+ positions = RemoveRepeatPoints(positions);
2543
+ const newGeometry = {};
2544
+ if (positions.length > 0) {
2545
+ const topPoint = positions[0];
2546
+ newGeometry.Point = `${topPoint.latitude},${topPoint.longitude}` + (topPoint.altitude != null ? `,${topPoint.altitude}` : "");
2547
+ if (positions.length > 1) {
2548
+ newGeometry.Polygon = [{ Facing: EPolygonRingType.Boundaries, LinearRing: LineStrFromPoints(positions) }];
2549
+ }
2550
+ if (positions.length > 2) {
2551
+ newGeometry.LineString = LineStrFromPoints(positions);
2552
+ }
2553
+ }
2554
+ return newGeometry;
2555
+ }
2556
+ return geometry;
2557
+ }
2558
+ Geometry.ParseGeometry = ParseGeometry;
2559
+ })(exports.Geometry || (exports.Geometry = {}));
2560
+
2439
2561
  (function (ObjectUtils) {
2440
2562
  const DEFAULT_LENGTH = 36;
2441
2563
  /**
@@ -3214,6 +3336,92 @@
3214
3336
  });
3215
3337
  }
3216
3338
  Entity.GetList = GetList;
3339
+ function ToGeoJson(params) {
3340
+ const { entities, excludeAltitude, altitude, includeUserData } = params;
3341
+ const features = [];
3342
+ const cloneObj = (obj) => {
3343
+ return JSON.parse(JSON.stringify(obj));
3344
+ };
3345
+ const populateProperties = (feature, entity) => {
3346
+ let properties = null;
3347
+ // All properties.
3348
+ if (includeUserData != false) {
3349
+ properties = cloneObj(entity);
3350
+ // We exclude geometry since the geojson is supposed to represent that attribute.
3351
+ delete properties.geometry;
3352
+ }
3353
+ // Only specific internal properties.
3354
+ else {
3355
+ properties = {
3356
+ Bruce: entity.Bruce ? cloneObj(entity.Bruce) : null,
3357
+ location: entity.location ? cloneObj(entity.location) : null,
3358
+ transform: entity.transform ? cloneObj(entity.transform) : null,
3359
+ boundaries: entity.boundaries ? cloneObj(entity.boundaries) : null,
3360
+ };
3361
+ }
3362
+ feature.properties = properties;
3363
+ };
3364
+ const processGeometry = (geometry, entity) => {
3365
+ const feature = {
3366
+ type: 'Feature',
3367
+ properties: {},
3368
+ geometry: null
3369
+ };
3370
+ populateProperties(feature, entity);
3371
+ if (geometry.Polygon) {
3372
+ const sortedPolygons = geometry.Polygon.sort((a, b) => a.Facing === exports.Geometry.EPolygonRingType.Boundaries ? -1 : 1);
3373
+ const coordinates = sortedPolygons.map(polygonRing => polygonRing.LinearRing.split(' ').map(coord => {
3374
+ const [lon, lat, alt] = coord.split(',').map(Number);
3375
+ return excludeAltitude ? [lon, lat] : [lon, lat, altitude !== undefined ? altitude : (alt !== undefined ? alt : [])];
3376
+ }));
3377
+ feature.geometry = {
3378
+ type: 'Polygon',
3379
+ coordinates: coordinates,
3380
+ };
3381
+ }
3382
+ if (geometry.Point) {
3383
+ const [lon, lat, alt] = geometry.Point.split(',').map(Number);
3384
+ const coordinates = excludeAltitude ? [lon, lat] : [lon, lat, altitude !== undefined ? altitude : (alt !== undefined ? alt : [])];
3385
+ feature.geometry = {
3386
+ type: 'Point',
3387
+ coordinates,
3388
+ };
3389
+ }
3390
+ if (geometry.LineString) {
3391
+ const coordinates = geometry.LineString.split(' ').map(coord => {
3392
+ const [lon, lat, alt] = coord.split(',').map(Number);
3393
+ return excludeAltitude ? [lon, lat] : [lon, lat, altitude !== undefined ? altitude : (alt !== undefined ? alt : [])];
3394
+ });
3395
+ feature.geometry = {
3396
+ type: 'LineString',
3397
+ coordinates,
3398
+ };
3399
+ }
3400
+ if (geometry.MultiGeometry) {
3401
+ geometry.MultiGeometry.forEach(geo => processGeometry(geo, entity));
3402
+ return;
3403
+ }
3404
+ features.push(feature);
3405
+ };
3406
+ entities.forEach(entity => {
3407
+ var _a, _b, _c;
3408
+ if (!((_a = entity === null || entity === void 0 ? void 0 : entity.Bruce) === null || _a === void 0 ? void 0 : _a.ID)) {
3409
+ return;
3410
+ }
3411
+ let geometry = entity.geometry;
3412
+ if (!geometry && (((_b = entity.location) === null || _b === void 0 ? void 0 : _b.longitude) && ((_c = entity.location) === null || _c === void 0 ? void 0 : _c.latitude))) {
3413
+ geometry = {
3414
+ Point: `${entity.location.longitude},${entity.location.latitude}` + (entity.location.altitude != null ? `,${entity.location.altitude}` : ""),
3415
+ };
3416
+ }
3417
+ processGeometry(geometry, entity);
3418
+ });
3419
+ return {
3420
+ type: 'FeatureCollection',
3421
+ features,
3422
+ };
3423
+ }
3424
+ Entity.ToGeoJson = ToGeoJson;
3217
3425
  })(exports.Entity || (exports.Entity = {}));
3218
3426
 
3219
3427
  /**
@@ -3710,188 +3918,6 @@
3710
3918
  Calculator.GetInputValue = GetInputValue;
3711
3919
  })(exports.Calculator || (exports.Calculator = {}));
3712
3920
 
3713
- /**
3714
- * Describes vector geometry that Bruce uses.
3715
- */
3716
- (function (Geometry) {
3717
- let EPolygonRingType;
3718
- (function (EPolygonRingType) {
3719
- EPolygonRingType["Boundaries"] = "out";
3720
- EPolygonRingType["Hole"] = "in";
3721
- })(EPolygonRingType = Geometry.EPolygonRingType || (Geometry.EPolygonRingType = {}));
3722
- /**
3723
- * Turns an array of points into string vector geometry that Bruce can use.
3724
- * This is used for saving polyline and polygon data.
3725
- * @param points
3726
- * @returns
3727
- */
3728
- function LineStrFromPoints(points) {
3729
- if (!points.length) {
3730
- throw ("points is empty.");
3731
- }
3732
- let carto = points[0];
3733
- let lineString = `${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
3734
- for (let i = 1; i < points.length; i++) {
3735
- carto = points[i];
3736
- lineString += ` ${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
3737
- }
3738
- return lineString;
3739
- }
3740
- Geometry.LineStrFromPoints = LineStrFromPoints;
3741
- /**
3742
- * Removes same points that occur in a row.
3743
- * This will not modify the original array.
3744
- * @param positions
3745
- * @returns
3746
- */
3747
- function RemoveRepeatPoints(positions) {
3748
- const filteredList = [];
3749
- for (let i = 0; i < positions.length; i++) {
3750
- const pos = positions[i];
3751
- const lastPos = filteredList.length > 0 ? filteredList[filteredList.length - 1] : null;
3752
- if (!lastPos || (pos.latitude != lastPos.latitude || pos.longitude != lastPos.longitude || pos.altitude != lastPos.altitude)) {
3753
- filteredList.push(pos);
3754
- }
3755
- }
3756
- return filteredList;
3757
- }
3758
- Geometry.RemoveRepeatPoints = RemoveRepeatPoints;
3759
- /**
3760
- * Parses a string of points into an array of points.
3761
- * @param pointsStr
3762
- * @returns
3763
- */
3764
- function ParsePoints(pointsStr) {
3765
- pointsStr = pointsStr.replace(/[^\d.,-\s]/g, "");
3766
- let splitterCoordinates = " ";
3767
- let splitterAxis = ",";
3768
- const commaIndex = pointsStr.indexOf(",");
3769
- const spaceIndex = pointsStr.indexOf(" ");
3770
- if ((spaceIndex > -1 && commaIndex > spaceIndex) || commaIndex <= -1) {
3771
- splitterCoordinates = ",";
3772
- splitterAxis = " ";
3773
- }
3774
- let points = pointsStr.trim().split(splitterCoordinates);
3775
- points = points.filter(a => a != "");
3776
- const result = [];
3777
- for (let i = 0; i < points.length; i++) {
3778
- const pointData = points[i];
3779
- const coords = pointData.trim().split(splitterAxis);
3780
- if (coords.length == 2 || coords.length == 3) {
3781
- const longitude = Number(coords[0]);
3782
- const latitude = Number(coords[1]);
3783
- const altitude = Number(coords.length >= 3 ? coords[2] : 0);
3784
- if (longitude != null && latitude != null) {
3785
- result.push({
3786
- altitude: altitude,
3787
- latitude: latitude,
3788
- longitude: longitude
3789
- });
3790
- }
3791
- else {
3792
- console.warn("Invalid point data detected.", pointData);
3793
- }
3794
- }
3795
- }
3796
- return result;
3797
- }
3798
- Geometry.ParsePoints = ParsePoints;
3799
- /**
3800
- * Parses both string and object Bruce geometry.
3801
- * String geometry is legacy Bruce data.
3802
- * @param geometry
3803
- * @returns
3804
- */
3805
- function ParseGeometry(geometry) {
3806
- if (typeof geometry == "string") {
3807
- let positions = [];
3808
- const geometryParsed = (geometry || "").split(";");
3809
- for (let i = 0; i < geometryParsed.length; i++) {
3810
- const data = geometryParsed[i];
3811
- const points = ParsePoints(data);
3812
- if (points && points.length > 0) {
3813
- positions = positions.concat(points);
3814
- }
3815
- }
3816
- positions = RemoveRepeatPoints(positions);
3817
- const newGeometry = {};
3818
- if (positions.length > 0) {
3819
- const topPoint = positions[0];
3820
- newGeometry.Point = `${topPoint.latitude},${topPoint.longitude}` + (topPoint.altitude != null ? `,${topPoint.altitude}` : "");
3821
- if (positions.length > 1) {
3822
- newGeometry.Polygon = [{ Facing: EPolygonRingType.Boundaries, LinearRing: LineStrFromPoints(positions) }];
3823
- }
3824
- if (positions.length > 2) {
3825
- newGeometry.LineString = LineStrFromPoints(positions);
3826
- }
3827
- }
3828
- return newGeometry;
3829
- }
3830
- return geometry;
3831
- }
3832
- Geometry.ParseGeometry = ParseGeometry;
3833
- function ToGeoJson(params) {
3834
- const { entities, excludeAltitude } = params;
3835
- const features = [];
3836
- const processGeometry = (geometry, ID) => {
3837
- if (geometry.Polygon) {
3838
- const sortedPolygons = geometry.Polygon.sort((a, b) => a.Facing === EPolygonRingType.Boundaries ? -1 : 1);
3839
- const coordinates = sortedPolygons.map(polygonRing => polygonRing.LinearRing.split(' ').map(coord => {
3840
- const [lon, lat, alt] = coord.split(',').map(Number);
3841
- return excludeAltitude ? [lon, lat] : [lon, lat, ...(alt ? [alt] : [])];
3842
- }));
3843
- features.push({
3844
- type: 'Feature',
3845
- properties: { ID },
3846
- geometry: {
3847
- type: 'Polygon',
3848
- coordinates: coordinates,
3849
- }
3850
- });
3851
- }
3852
- if (geometry.Point) {
3853
- const [lon, lat, alt] = geometry.Point.split(',').map(Number);
3854
- const coordinates = excludeAltitude ? [lon, lat] : [lon, lat, ...(alt ? [alt] : [])];
3855
- features.push({
3856
- type: 'Feature',
3857
- properties: { ID },
3858
- geometry: {
3859
- type: 'Point',
3860
- coordinates,
3861
- }
3862
- });
3863
- }
3864
- if (geometry.LineString) {
3865
- const coordinates = geometry.LineString.split(' ').map(coord => {
3866
- const [lon, lat, alt] = coord.split(',').map(Number);
3867
- return excludeAltitude ? [lon, lat] : [lon, lat, ...(alt ? [alt] : [])];
3868
- });
3869
- features.push({
3870
- type: 'Feature',
3871
- properties: { ID },
3872
- geometry: {
3873
- type: 'LineString',
3874
- coordinates,
3875
- }
3876
- });
3877
- }
3878
- if (geometry.MultiGeometry) {
3879
- geometry.MultiGeometry.forEach(geo => processGeometry(geo, ID));
3880
- }
3881
- };
3882
- entities.forEach(entity => {
3883
- const { ID } = entity.Bruce;
3884
- const { geometry } = entity;
3885
- processGeometry(geometry, ID);
3886
- });
3887
- return {
3888
- type: 'FeatureCollection',
3889
- features,
3890
- };
3891
- }
3892
- Geometry.ToGeoJson = ToGeoJson;
3893
- })(exports.Geometry || (exports.Geometry = {}));
3894
-
3895
3921
  (function (Bounds) {
3896
3922
  /**
3897
3923
  * Calculates boundaries from entity.
@@ -10517,7 +10543,7 @@
10517
10543
  DataSource.GetList = GetList;
10518
10544
  })(exports.DataSource || (exports.DataSource = {}));
10519
10545
 
10520
- const VERSION = "3.4.2";
10546
+ const VERSION = "3.4.4";
10521
10547
 
10522
10548
  exports.VERSION = VERSION;
10523
10549
  exports.AbstractApi = AbstractApi;