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.
@@ -2473,6 +2473,129 @@ var Color;
2473
2473
  Color.ColorFromStr = ColorFromStr;
2474
2474
  })(Color || (Color = {}));
2475
2475
 
2476
+ /**
2477
+ * Describes vector geometry that Bruce uses.
2478
+ */
2479
+ var Geometry;
2480
+ (function (Geometry) {
2481
+ let EPolygonRingType;
2482
+ (function (EPolygonRingType) {
2483
+ EPolygonRingType["Boundaries"] = "out";
2484
+ EPolygonRingType["Hole"] = "in";
2485
+ })(EPolygonRingType = Geometry.EPolygonRingType || (Geometry.EPolygonRingType = {}));
2486
+ /**
2487
+ * Turns an array of points into string vector geometry that Bruce can use.
2488
+ * This is used for saving polyline and polygon data.
2489
+ * @param points
2490
+ * @returns
2491
+ */
2492
+ function LineStrFromPoints(points) {
2493
+ if (!points.length) {
2494
+ throw ("points is empty.");
2495
+ }
2496
+ let carto = points[0];
2497
+ let lineString = `${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
2498
+ for (let i = 1; i < points.length; i++) {
2499
+ carto = points[i];
2500
+ lineString += ` ${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
2501
+ }
2502
+ return lineString;
2503
+ }
2504
+ Geometry.LineStrFromPoints = LineStrFromPoints;
2505
+ /**
2506
+ * Removes same points that occur in a row.
2507
+ * This will not modify the original array.
2508
+ * @param positions
2509
+ * @returns
2510
+ */
2511
+ function RemoveRepeatPoints(positions) {
2512
+ const filteredList = [];
2513
+ for (let i = 0; i < positions.length; i++) {
2514
+ const pos = positions[i];
2515
+ const lastPos = filteredList.length > 0 ? filteredList[filteredList.length - 1] : null;
2516
+ if (!lastPos || (pos.latitude != lastPos.latitude || pos.longitude != lastPos.longitude || pos.altitude != lastPos.altitude)) {
2517
+ filteredList.push(pos);
2518
+ }
2519
+ }
2520
+ return filteredList;
2521
+ }
2522
+ Geometry.RemoveRepeatPoints = RemoveRepeatPoints;
2523
+ /**
2524
+ * Parses a string of points into an array of points.
2525
+ * @param pointsStr
2526
+ * @returns
2527
+ */
2528
+ function ParsePoints(pointsStr) {
2529
+ pointsStr = pointsStr.replace(/[^\d.,-\s]/g, "");
2530
+ let splitterCoordinates = " ";
2531
+ let splitterAxis = ",";
2532
+ const commaIndex = pointsStr.indexOf(",");
2533
+ const spaceIndex = pointsStr.indexOf(" ");
2534
+ if ((spaceIndex > -1 && commaIndex > spaceIndex) || commaIndex <= -1) {
2535
+ splitterCoordinates = ",";
2536
+ splitterAxis = " ";
2537
+ }
2538
+ let points = pointsStr.trim().split(splitterCoordinates);
2539
+ points = points.filter(a => a != "");
2540
+ const result = [];
2541
+ for (let i = 0; i < points.length; i++) {
2542
+ const pointData = points[i];
2543
+ const coords = pointData.trim().split(splitterAxis);
2544
+ if (coords.length == 2 || coords.length == 3) {
2545
+ const longitude = Number(coords[0]);
2546
+ const latitude = Number(coords[1]);
2547
+ const altitude = Number(coords.length >= 3 ? coords[2] : 0);
2548
+ if (longitude != null && latitude != null) {
2549
+ result.push({
2550
+ altitude: altitude,
2551
+ latitude: latitude,
2552
+ longitude: longitude
2553
+ });
2554
+ }
2555
+ else {
2556
+ console.warn("Invalid point data detected.", pointData);
2557
+ }
2558
+ }
2559
+ }
2560
+ return result;
2561
+ }
2562
+ Geometry.ParsePoints = ParsePoints;
2563
+ /**
2564
+ * Parses both string and object Bruce geometry.
2565
+ * String geometry is legacy Bruce data.
2566
+ * @param geometry
2567
+ * @returns
2568
+ */
2569
+ function ParseGeometry(geometry) {
2570
+ if (typeof geometry == "string") {
2571
+ let positions = [];
2572
+ const geometryParsed = (geometry || "").split(";");
2573
+ for (let i = 0; i < geometryParsed.length; i++) {
2574
+ const data = geometryParsed[i];
2575
+ const points = ParsePoints(data);
2576
+ if (points && points.length > 0) {
2577
+ positions = positions.concat(points);
2578
+ }
2579
+ }
2580
+ positions = RemoveRepeatPoints(positions);
2581
+ const newGeometry = {};
2582
+ if (positions.length > 0) {
2583
+ const topPoint = positions[0];
2584
+ newGeometry.Point = `${topPoint.latitude},${topPoint.longitude}` + (topPoint.altitude != null ? `,${topPoint.altitude}` : "");
2585
+ if (positions.length > 1) {
2586
+ newGeometry.Polygon = [{ Facing: EPolygonRingType.Boundaries, LinearRing: LineStrFromPoints(positions) }];
2587
+ }
2588
+ if (positions.length > 2) {
2589
+ newGeometry.LineString = LineStrFromPoints(positions);
2590
+ }
2591
+ }
2592
+ return newGeometry;
2593
+ }
2594
+ return geometry;
2595
+ }
2596
+ Geometry.ParseGeometry = ParseGeometry;
2597
+ })(Geometry || (Geometry = {}));
2598
+
2476
2599
  var ObjectUtils;
2477
2600
  (function (ObjectUtils) {
2478
2601
  const DEFAULT_LENGTH = 36;
@@ -3265,6 +3388,92 @@ var Entity;
3265
3388
  });
3266
3389
  }
3267
3390
  Entity.GetList = GetList;
3391
+ function ToGeoJson(params) {
3392
+ const { entities, excludeAltitude, altitude, includeUserData } = params;
3393
+ const features = [];
3394
+ const cloneObj = (obj) => {
3395
+ return JSON.parse(JSON.stringify(obj));
3396
+ };
3397
+ const populateProperties = (feature, entity) => {
3398
+ let properties = null;
3399
+ // All properties.
3400
+ if (includeUserData != false) {
3401
+ properties = cloneObj(entity);
3402
+ // We exclude geometry since the geojson is supposed to represent that attribute.
3403
+ delete properties.geometry;
3404
+ }
3405
+ // Only specific internal properties.
3406
+ else {
3407
+ properties = {
3408
+ Bruce: entity.Bruce ? cloneObj(entity.Bruce) : null,
3409
+ location: entity.location ? cloneObj(entity.location) : null,
3410
+ transform: entity.transform ? cloneObj(entity.transform) : null,
3411
+ boundaries: entity.boundaries ? cloneObj(entity.boundaries) : null,
3412
+ };
3413
+ }
3414
+ feature.properties = properties;
3415
+ };
3416
+ const processGeometry = (geometry, entity) => {
3417
+ const feature = {
3418
+ type: 'Feature',
3419
+ properties: {},
3420
+ geometry: null
3421
+ };
3422
+ populateProperties(feature, entity);
3423
+ if (geometry.Polygon) {
3424
+ const sortedPolygons = geometry.Polygon.sort((a, b) => a.Facing === Geometry.EPolygonRingType.Boundaries ? -1 : 1);
3425
+ const coordinates = sortedPolygons.map(polygonRing => polygonRing.LinearRing.split(' ').map(coord => {
3426
+ const [lon, lat, alt] = coord.split(',').map(Number);
3427
+ return excludeAltitude ? [lon, lat] : [lon, lat, altitude !== undefined ? altitude : (alt !== undefined ? alt : [])];
3428
+ }));
3429
+ feature.geometry = {
3430
+ type: 'Polygon',
3431
+ coordinates: coordinates,
3432
+ };
3433
+ }
3434
+ if (geometry.Point) {
3435
+ const [lon, lat, alt] = geometry.Point.split(',').map(Number);
3436
+ const coordinates = excludeAltitude ? [lon, lat] : [lon, lat, altitude !== undefined ? altitude : (alt !== undefined ? alt : [])];
3437
+ feature.geometry = {
3438
+ type: 'Point',
3439
+ coordinates,
3440
+ };
3441
+ }
3442
+ if (geometry.LineString) {
3443
+ const coordinates = geometry.LineString.split(' ').map(coord => {
3444
+ const [lon, lat, alt] = coord.split(',').map(Number);
3445
+ return excludeAltitude ? [lon, lat] : [lon, lat, altitude !== undefined ? altitude : (alt !== undefined ? alt : [])];
3446
+ });
3447
+ feature.geometry = {
3448
+ type: 'LineString',
3449
+ coordinates,
3450
+ };
3451
+ }
3452
+ if (geometry.MultiGeometry) {
3453
+ geometry.MultiGeometry.forEach(geo => processGeometry(geo, entity));
3454
+ return;
3455
+ }
3456
+ features.push(feature);
3457
+ };
3458
+ entities.forEach(entity => {
3459
+ var _a, _b, _c;
3460
+ if (!((_a = entity === null || entity === void 0 ? void 0 : entity.Bruce) === null || _a === void 0 ? void 0 : _a.ID)) {
3461
+ return;
3462
+ }
3463
+ let geometry = entity.geometry;
3464
+ if (!geometry && (((_b = entity.location) === null || _b === void 0 ? void 0 : _b.longitude) && ((_c = entity.location) === null || _c === void 0 ? void 0 : _c.latitude))) {
3465
+ geometry = {
3466
+ Point: `${entity.location.longitude},${entity.location.latitude}` + (entity.location.altitude != null ? `,${entity.location.altitude}` : ""),
3467
+ };
3468
+ }
3469
+ processGeometry(geometry, entity);
3470
+ });
3471
+ return {
3472
+ type: 'FeatureCollection',
3473
+ features,
3474
+ };
3475
+ }
3476
+ Entity.ToGeoJson = ToGeoJson;
3268
3477
  })(Entity || (Entity = {}));
3269
3478
 
3270
3479
  /**
@@ -3773,189 +3982,6 @@ var Calculator;
3773
3982
  Calculator.GetInputValue = GetInputValue;
3774
3983
  })(Calculator || (Calculator = {}));
3775
3984
 
3776
- /**
3777
- * Describes vector geometry that Bruce uses.
3778
- */
3779
- var Geometry;
3780
- (function (Geometry) {
3781
- let EPolygonRingType;
3782
- (function (EPolygonRingType) {
3783
- EPolygonRingType["Boundaries"] = "out";
3784
- EPolygonRingType["Hole"] = "in";
3785
- })(EPolygonRingType = Geometry.EPolygonRingType || (Geometry.EPolygonRingType = {}));
3786
- /**
3787
- * Turns an array of points into string vector geometry that Bruce can use.
3788
- * This is used for saving polyline and polygon data.
3789
- * @param points
3790
- * @returns
3791
- */
3792
- function LineStrFromPoints(points) {
3793
- if (!points.length) {
3794
- throw ("points is empty.");
3795
- }
3796
- let carto = points[0];
3797
- let lineString = `${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
3798
- for (let i = 1; i < points.length; i++) {
3799
- carto = points[i];
3800
- lineString += ` ${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
3801
- }
3802
- return lineString;
3803
- }
3804
- Geometry.LineStrFromPoints = LineStrFromPoints;
3805
- /**
3806
- * Removes same points that occur in a row.
3807
- * This will not modify the original array.
3808
- * @param positions
3809
- * @returns
3810
- */
3811
- function RemoveRepeatPoints(positions) {
3812
- const filteredList = [];
3813
- for (let i = 0; i < positions.length; i++) {
3814
- const pos = positions[i];
3815
- const lastPos = filteredList.length > 0 ? filteredList[filteredList.length - 1] : null;
3816
- if (!lastPos || (pos.latitude != lastPos.latitude || pos.longitude != lastPos.longitude || pos.altitude != lastPos.altitude)) {
3817
- filteredList.push(pos);
3818
- }
3819
- }
3820
- return filteredList;
3821
- }
3822
- Geometry.RemoveRepeatPoints = RemoveRepeatPoints;
3823
- /**
3824
- * Parses a string of points into an array of points.
3825
- * @param pointsStr
3826
- * @returns
3827
- */
3828
- function ParsePoints(pointsStr) {
3829
- pointsStr = pointsStr.replace(/[^\d.,-\s]/g, "");
3830
- let splitterCoordinates = " ";
3831
- let splitterAxis = ",";
3832
- const commaIndex = pointsStr.indexOf(",");
3833
- const spaceIndex = pointsStr.indexOf(" ");
3834
- if ((spaceIndex > -1 && commaIndex > spaceIndex) || commaIndex <= -1) {
3835
- splitterCoordinates = ",";
3836
- splitterAxis = " ";
3837
- }
3838
- let points = pointsStr.trim().split(splitterCoordinates);
3839
- points = points.filter(a => a != "");
3840
- const result = [];
3841
- for (let i = 0; i < points.length; i++) {
3842
- const pointData = points[i];
3843
- const coords = pointData.trim().split(splitterAxis);
3844
- if (coords.length == 2 || coords.length == 3) {
3845
- const longitude = Number(coords[0]);
3846
- const latitude = Number(coords[1]);
3847
- const altitude = Number(coords.length >= 3 ? coords[2] : 0);
3848
- if (longitude != null && latitude != null) {
3849
- result.push({
3850
- altitude: altitude,
3851
- latitude: latitude,
3852
- longitude: longitude
3853
- });
3854
- }
3855
- else {
3856
- console.warn("Invalid point data detected.", pointData);
3857
- }
3858
- }
3859
- }
3860
- return result;
3861
- }
3862
- Geometry.ParsePoints = ParsePoints;
3863
- /**
3864
- * Parses both string and object Bruce geometry.
3865
- * String geometry is legacy Bruce data.
3866
- * @param geometry
3867
- * @returns
3868
- */
3869
- function ParseGeometry(geometry) {
3870
- if (typeof geometry == "string") {
3871
- let positions = [];
3872
- const geometryParsed = (geometry || "").split(";");
3873
- for (let i = 0; i < geometryParsed.length; i++) {
3874
- const data = geometryParsed[i];
3875
- const points = ParsePoints(data);
3876
- if (points && points.length > 0) {
3877
- positions = positions.concat(points);
3878
- }
3879
- }
3880
- positions = RemoveRepeatPoints(positions);
3881
- const newGeometry = {};
3882
- if (positions.length > 0) {
3883
- const topPoint = positions[0];
3884
- newGeometry.Point = `${topPoint.latitude},${topPoint.longitude}` + (topPoint.altitude != null ? `,${topPoint.altitude}` : "");
3885
- if (positions.length > 1) {
3886
- newGeometry.Polygon = [{ Facing: EPolygonRingType.Boundaries, LinearRing: LineStrFromPoints(positions) }];
3887
- }
3888
- if (positions.length > 2) {
3889
- newGeometry.LineString = LineStrFromPoints(positions);
3890
- }
3891
- }
3892
- return newGeometry;
3893
- }
3894
- return geometry;
3895
- }
3896
- Geometry.ParseGeometry = ParseGeometry;
3897
- function ToGeoJson(params) {
3898
- const { entities, excludeAltitude } = params;
3899
- const features = [];
3900
- const processGeometry = (geometry, ID) => {
3901
- if (geometry.Polygon) {
3902
- const sortedPolygons = geometry.Polygon.sort((a, b) => a.Facing === EPolygonRingType.Boundaries ? -1 : 1);
3903
- const coordinates = sortedPolygons.map(polygonRing => polygonRing.LinearRing.split(' ').map(coord => {
3904
- const [lon, lat, alt] = coord.split(',').map(Number);
3905
- return excludeAltitude ? [lon, lat] : [lon, lat, ...(alt ? [alt] : [])];
3906
- }));
3907
- features.push({
3908
- type: 'Feature',
3909
- properties: { ID },
3910
- geometry: {
3911
- type: 'Polygon',
3912
- coordinates: coordinates,
3913
- }
3914
- });
3915
- }
3916
- if (geometry.Point) {
3917
- const [lon, lat, alt] = geometry.Point.split(',').map(Number);
3918
- const coordinates = excludeAltitude ? [lon, lat] : [lon, lat, ...(alt ? [alt] : [])];
3919
- features.push({
3920
- type: 'Feature',
3921
- properties: { ID },
3922
- geometry: {
3923
- type: 'Point',
3924
- coordinates,
3925
- }
3926
- });
3927
- }
3928
- if (geometry.LineString) {
3929
- const coordinates = geometry.LineString.split(' ').map(coord => {
3930
- const [lon, lat, alt] = coord.split(',').map(Number);
3931
- return excludeAltitude ? [lon, lat] : [lon, lat, ...(alt ? [alt] : [])];
3932
- });
3933
- features.push({
3934
- type: 'Feature',
3935
- properties: { ID },
3936
- geometry: {
3937
- type: 'LineString',
3938
- coordinates,
3939
- }
3940
- });
3941
- }
3942
- if (geometry.MultiGeometry) {
3943
- geometry.MultiGeometry.forEach(geo => processGeometry(geo, ID));
3944
- }
3945
- };
3946
- entities.forEach(entity => {
3947
- const { ID } = entity.Bruce;
3948
- const { geometry } = entity;
3949
- processGeometry(geometry, ID);
3950
- });
3951
- return {
3952
- type: 'FeatureCollection',
3953
- features,
3954
- };
3955
- }
3956
- Geometry.ToGeoJson = ToGeoJson;
3957
- })(Geometry || (Geometry = {}));
3958
-
3959
3985
  var Bounds;
3960
3986
  (function (Bounds) {
3961
3987
  /**
@@ -10770,7 +10796,7 @@ var DataSource;
10770
10796
  DataSource.GetList = GetList;
10771
10797
  })(DataSource || (DataSource = {}));
10772
10798
 
10773
- const VERSION = "3.4.2";
10799
+ const VERSION = "3.4.4";
10774
10800
 
10775
10801
  export { VERSION, AnnDocument, CustomForm, AbstractApi, Api, BruceApi, GlobalApi, GuardianApi, ApiGetters, Calculator, Bounds, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, BruceVariable, LRUCache, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityLodCategory, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityCoords, EntityTypeVisualSettings, EntityAttribute, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewLegacyTile, ProjectViewTile, ProjectViewLegacy, ProjectViewLegacyBookmark, PendingAction, MessageBroker, HostingLocation, Style, Tileset, Permission, Session, UserGroup, User, Account, AccountInvite, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, ImportCad, ImportCsv, ImportJson, ImportKml, ImportedFile, Markup, Uploader, Plugin, ENVIRONMENT, DataSource };
10776
10802
  //# sourceMappingURL=bruce-models.es5.js.map