bruce-models 1.1.6 → 1.1.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.
@@ -1925,6 +1925,180 @@
1925
1925
  Calculator.GetInputValue = GetInputValue;
1926
1926
  })(exports.Calculator || (exports.Calculator = {}));
1927
1927
 
1928
+ /**
1929
+ * Describes vector geometry that Bruce uses.
1930
+ */
1931
+ (function (Geometry) {
1932
+ let EPolygonRingType;
1933
+ (function (EPolygonRingType) {
1934
+ EPolygonRingType["Boundaries"] = "out";
1935
+ EPolygonRingType["Hole"] = "in";
1936
+ })(EPolygonRingType = Geometry.EPolygonRingType || (Geometry.EPolygonRingType = {}));
1937
+ /**
1938
+ * Turns an array of points into string vector geometry that Bruce can use.
1939
+ * This is used for saving polyline and polygon data.
1940
+ * @param points
1941
+ * @returns
1942
+ */
1943
+ function LineStrFromPoints(points) {
1944
+ if (!points.length) {
1945
+ throw ("points is empty.");
1946
+ }
1947
+ let carto = points[0];
1948
+ let lineString = `${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
1949
+ for (let i = 1; i < points.length; i++) {
1950
+ carto = points[i];
1951
+ lineString += ` ${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
1952
+ }
1953
+ return lineString;
1954
+ }
1955
+ Geometry.LineStrFromPoints = LineStrFromPoints;
1956
+ /**
1957
+ * Removes same points that occur in a row.
1958
+ * This will not modify the original array.
1959
+ * @param positions
1960
+ * @returns
1961
+ */
1962
+ function RemoveRepeatPoints(positions) {
1963
+ const filteredList = [];
1964
+ for (let i = 0; i < positions.length; i++) {
1965
+ const pos = positions[i];
1966
+ const lastPos = filteredList.length > 0 ? filteredList[filteredList.length - 1] : null;
1967
+ if (!lastPos || (pos.latitude != lastPos.latitude || pos.longitude != lastPos.longitude || pos.altitude != lastPos.altitude)) {
1968
+ filteredList.push(pos);
1969
+ }
1970
+ }
1971
+ return filteredList;
1972
+ }
1973
+ Geometry.RemoveRepeatPoints = RemoveRepeatPoints;
1974
+ function ParsePoints(data) {
1975
+ data = data.replace(/[^\d.,-\s]/g, "");
1976
+ let splitterCoordinates = " ";
1977
+ let splitterAxis = ",";
1978
+ const commaIndex = data.indexOf(",");
1979
+ const spaceIndex = data.indexOf(" ");
1980
+ if ((spaceIndex > -1 && commaIndex > spaceIndex) || commaIndex <= -1) {
1981
+ splitterCoordinates = ",";
1982
+ splitterAxis = " ";
1983
+ }
1984
+ let points = data.trim().split(splitterCoordinates);
1985
+ points = points.filter(a => a != "");
1986
+ const result = [];
1987
+ for (let i = 0; i < points.length; i++) {
1988
+ const pointData = points[i];
1989
+ const coords = pointData.trim().split(splitterAxis);
1990
+ if (coords.length == 2 || coords.length == 3) {
1991
+ const longitude = Number(coords[0]);
1992
+ const latitude = Number(coords[1]);
1993
+ const altitude = Number(coords.length >= 3 ? coords[2] : 0);
1994
+ if (longitude != null && latitude != null) {
1995
+ result.push({
1996
+ altitude: altitude,
1997
+ latitude: latitude,
1998
+ longitude: longitude
1999
+ });
2000
+ }
2001
+ else {
2002
+ console.warn("Invalid point data detected.", pointData);
2003
+ }
2004
+ }
2005
+ }
2006
+ return result;
2007
+ }
2008
+ Geometry.ParsePoints = ParsePoints;
2009
+ /**
2010
+ * Parses both string and object Bruce geometry.
2011
+ * String geometry is legacy Bruce data.
2012
+ * @param geometry
2013
+ * @returns
2014
+ */
2015
+ function ParseGeometry(geometry) {
2016
+ if (typeof geometry == "string") {
2017
+ let positions = [];
2018
+ const geometryParsed = (geometry || "").split(";");
2019
+ for (let i = 0; i < geometryParsed.length; i++) {
2020
+ const data = geometryParsed[i];
2021
+ const points = ParsePoints(data);
2022
+ if (points && points.length > 0) {
2023
+ positions = positions.concat(points);
2024
+ }
2025
+ }
2026
+ positions = RemoveRepeatPoints(positions);
2027
+ const newGeometry = {};
2028
+ if (positions.length > 0) {
2029
+ const topPoint = positions[0];
2030
+ newGeometry.Point = `${topPoint.latitude},${topPoint.longitude}` + (topPoint.altitude != null ? `,${topPoint.altitude}` : "");
2031
+ if (positions.length > 1) {
2032
+ newGeometry.Polygon = [{ Facing: EPolygonRingType.Boundaries, LinearRing: LineStrFromPoints(positions) }];
2033
+ }
2034
+ if (positions.length > 2) {
2035
+ newGeometry.LineString = LineStrFromPoints(positions);
2036
+ }
2037
+ }
2038
+ return newGeometry;
2039
+ }
2040
+ return geometry;
2041
+ }
2042
+ Geometry.ParseGeometry = ParseGeometry;
2043
+ })(exports.Geometry || (exports.Geometry = {}));
2044
+
2045
+ (function (Bounds) {
2046
+ /**
2047
+ * Calculates boundaries from entity.
2048
+ * This will not use the set entity boundaries and instead calculate from geometry and location.
2049
+ * @param entity
2050
+ */
2051
+ function FromEntity(entity) {
2052
+ const bounds = {
2053
+ maxAltitude: null,
2054
+ maxLatitude: null,
2055
+ maxLongitude: null,
2056
+ minAltitude: null,
2057
+ minLatitude: null,
2058
+ minLongitude: null
2059
+ };
2060
+ const points = [];
2061
+ if (entity.location) {
2062
+ points.push(entity.location);
2063
+ }
2064
+ if (entity.geometry) {
2065
+ if (entity.geometry.Point) {
2066
+ points.push(...exports.Geometry.ParsePoints(entity.geometry.Point));
2067
+ }
2068
+ if (entity.geometry.LineString) {
2069
+ points.push(...exports.Geometry.ParsePoints(entity.geometry.LineString));
2070
+ }
2071
+ if (entity.geometry.Polygon) {
2072
+ for (const ring of entity.geometry.Polygon) {
2073
+ points.push(...exports.Geometry.ParsePoints(ring.LinearRing));
2074
+ }
2075
+ }
2076
+ }
2077
+ for (const point of points) {
2078
+ if (bounds.maxLatitude == null || point.latitude > bounds.maxLatitude) {
2079
+ bounds.maxLatitude = point.latitude;
2080
+ }
2081
+ if (bounds.maxLongitude == null || point.longitude > bounds.maxLongitude) {
2082
+ bounds.maxLongitude = point.longitude;
2083
+ }
2084
+ if (bounds.maxAltitude == null || point.altitude > bounds.maxAltitude) {
2085
+ bounds.maxAltitude = point.altitude;
2086
+ }
2087
+ if (bounds.minLatitude == null || point.latitude < bounds.minLatitude) {
2088
+ bounds.minLatitude = point.latitude;
2089
+ }
2090
+ if (bounds.minLongitude == null || point.longitude < bounds.minLongitude) {
2091
+ bounds.minLongitude = point.longitude;
2092
+ }
2093
+ if (bounds.minAltitude == null || point.altitude < bounds.minAltitude) {
2094
+ bounds.minAltitude = point.altitude;
2095
+ }
2096
+ }
2097
+ return bounds;
2098
+ }
2099
+ Bounds.FromEntity = FromEntity;
2100
+ })(exports.Bounds || (exports.Bounds = {}));
2101
+
1928
2102
  /**
1929
2103
  * Simple event utility.
1930
2104
  * Instantiate the model, then subscribe and trigger events.
@@ -2206,123 +2380,6 @@
2206
2380
  }
2207
2381
  }
2208
2382
 
2209
- /**
2210
- * Describes vector geometry that Bruce uses.
2211
- */
2212
- (function (Geometry) {
2213
- let EPolygonRingType;
2214
- (function (EPolygonRingType) {
2215
- EPolygonRingType["Boundaries"] = "out";
2216
- EPolygonRingType["Hole"] = "in";
2217
- })(EPolygonRingType = Geometry.EPolygonRingType || (Geometry.EPolygonRingType = {}));
2218
- /**
2219
- * Turns an array of points into string vector geometry that Bruce can use.
2220
- * This is used for saving polyline and polygon data.
2221
- * @param points
2222
- * @returns
2223
- */
2224
- function LineStrFromPoints(points) {
2225
- if (!points.length) {
2226
- throw ("points is empty.");
2227
- }
2228
- let carto = points[0];
2229
- let lineString = `${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
2230
- for (let i = 1; i < points.length; i++) {
2231
- carto = points[i];
2232
- lineString += ` ${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
2233
- }
2234
- return lineString;
2235
- }
2236
- Geometry.LineStrFromPoints = LineStrFromPoints;
2237
- /**
2238
- * Removes same points that occur in a row.
2239
- * This will not modify the original array.
2240
- * @param positions
2241
- * @returns
2242
- */
2243
- function RemoveRepeatPoints(positions) {
2244
- const filteredList = [];
2245
- for (let i = 0; i < positions.length; i++) {
2246
- const pos = positions[i];
2247
- const lastPos = filteredList.length > 0 ? filteredList[filteredList.length - 1] : null;
2248
- if (!lastPos || (pos.latitude != lastPos.latitude || pos.longitude != lastPos.longitude || pos.altitude != lastPos.altitude)) {
2249
- filteredList.push(pos);
2250
- }
2251
- }
2252
- return filteredList;
2253
- }
2254
- Geometry.RemoveRepeatPoints = RemoveRepeatPoints;
2255
- function ParsePoints(data) {
2256
- data = data.replace(/[^\d.,-\s]/g, "");
2257
- let splitterCoordinates = " ";
2258
- let splitterAxis = ",";
2259
- const commaIndex = data.indexOf(",");
2260
- const spaceIndex = data.indexOf(" ");
2261
- if ((spaceIndex > -1 && commaIndex > spaceIndex) || commaIndex <= -1) {
2262
- splitterCoordinates = ",";
2263
- splitterAxis = " ";
2264
- }
2265
- let points = data.trim().split(splitterCoordinates);
2266
- points = points.filter(a => a != "");
2267
- const result = [];
2268
- for (let i = 0; i < points.length; i++) {
2269
- const pointData = points[i];
2270
- const coords = pointData.trim().split(splitterAxis);
2271
- if (coords.length == 2 || coords.length == 3) {
2272
- const longitude = Number(coords[0]);
2273
- const latitude = Number(coords[1]);
2274
- const altitude = Number(coords.length >= 3 ? coords[2] : 0);
2275
- if (longitude != null && latitude != null) {
2276
- result.push({
2277
- altitude: altitude,
2278
- latitude: latitude,
2279
- longitude: longitude
2280
- });
2281
- }
2282
- else {
2283
- console.warn("Invalid point data detected.", pointData);
2284
- }
2285
- }
2286
- }
2287
- return result;
2288
- }
2289
- Geometry.ParsePoints = ParsePoints;
2290
- /**
2291
- * Parses both string and object Bruce geometry.
2292
- * String geometry is legacy Bruce data.
2293
- * @param geometry
2294
- * @returns
2295
- */
2296
- function ParseGeometry(geometry) {
2297
- if (typeof geometry == "string") {
2298
- let positions = [];
2299
- const geometryParsed = (geometry || "").split(";");
2300
- for (let i = 0; i < geometryParsed.length; i++) {
2301
- const data = geometryParsed[i];
2302
- const points = ParsePoints(data);
2303
- if (points && points.length > 0) {
2304
- positions = positions.concat(points);
2305
- }
2306
- }
2307
- positions = RemoveRepeatPoints(positions);
2308
- const newGeometry = {};
2309
- if (positions.length > 0) {
2310
- const topPoint = positions[0];
2311
- newGeometry.Point = `${topPoint.latitude},${topPoint.longitude}` + (topPoint.altitude != null ? `,${topPoint.altitude}` : "");
2312
- if (positions.length > 1) {
2313
- newGeometry.Polygon = [{ Facing: EPolygonRingType.Boundaries, LinearRing: LineStrFromPoints(positions) }];
2314
- }
2315
- if (positions.length > 2) {
2316
- newGeometry.LineString = LineStrFromPoints(positions);
2317
- }
2318
- }
2319
- return newGeometry;
2320
- }
2321
- return geometry;
2322
- }
2323
- Geometry.ParseGeometry = ParseGeometry;
2324
- })(exports.Geometry || (exports.Geometry = {}));
2325
-
2326
2383
  /**
2327
2384
  * Describes a Bruce stored date.
2328
2385
  */