bruce-models 1.1.5 → 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.
@@ -79,7 +79,8 @@
79
79
  EEnv["UAT"] = "UAT";
80
80
  EEnv["PROD"] = "PROD";
81
81
  })(EEnv = Api.EEnv || (Api.EEnv = {}));
82
- Api.DEFAULT_CACHE_STATE = true;
82
+ // False = cache is enabled by default for req-params.
83
+ Api.DEFAULT_NO_CACHE = false;
83
84
  /**
84
85
  * Prepares a string to be included in a url.
85
86
  * @param str
@@ -457,7 +458,7 @@
457
458
  GetCacheItem(key, reqParams) {
458
459
  let noCache = reqParams === null || reqParams === void 0 ? void 0 : reqParams.noCache;
459
460
  if (noCache == null) {
460
- noCache = exports.Api.DEFAULT_CACHE_STATE;
461
+ noCache = exports.Api.DEFAULT_NO_CACHE;
461
462
  }
462
463
  if (noCache) {
463
464
  return null;
@@ -1924,6 +1925,180 @@
1924
1925
  Calculator.GetInputValue = GetInputValue;
1925
1926
  })(exports.Calculator || (exports.Calculator = {}));
1926
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
+
1927
2102
  /**
1928
2103
  * Simple event utility.
1929
2104
  * Instantiate the model, then subscribe and trigger events.
@@ -2205,123 +2380,6 @@
2205
2380
  }
2206
2381
  }
2207
2382
 
2208
- /**
2209
- * Describes vector geometry that Bruce uses.
2210
- */
2211
- (function (Geometry) {
2212
- let EPolygonRingType;
2213
- (function (EPolygonRingType) {
2214
- EPolygonRingType["Boundaries"] = "out";
2215
- EPolygonRingType["Hole"] = "in";
2216
- })(EPolygonRingType = Geometry.EPolygonRingType || (Geometry.EPolygonRingType = {}));
2217
- /**
2218
- * Turns an array of points into string vector geometry that Bruce can use.
2219
- * This is used for saving polyline and polygon data.
2220
- * @param points
2221
- * @returns
2222
- */
2223
- function LineStrFromPoints(points) {
2224
- if (!points.length) {
2225
- throw ("points is empty.");
2226
- }
2227
- let carto = points[0];
2228
- let lineString = `${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
2229
- for (let i = 1; i < points.length; i++) {
2230
- carto = points[i];
2231
- lineString += ` ${carto.longitude},${carto.latitude}` + (carto.altitude != null ? `,${carto.altitude}` : "");
2232
- }
2233
- return lineString;
2234
- }
2235
- Geometry.LineStrFromPoints = LineStrFromPoints;
2236
- /**
2237
- * Removes same points that occur in a row.
2238
- * This will not modify the original array.
2239
- * @param positions
2240
- * @returns
2241
- */
2242
- function RemoveRepeatPoints(positions) {
2243
- const filteredList = [];
2244
- for (let i = 0; i < positions.length; i++) {
2245
- const pos = positions[i];
2246
- const lastPos = filteredList.length > 0 ? filteredList[filteredList.length - 1] : null;
2247
- if (!lastPos || (pos.latitude != lastPos.latitude || pos.longitude != lastPos.longitude || pos.altitude != lastPos.altitude)) {
2248
- filteredList.push(pos);
2249
- }
2250
- }
2251
- return filteredList;
2252
- }
2253
- Geometry.RemoveRepeatPoints = RemoveRepeatPoints;
2254
- function ParsePoints(data) {
2255
- data = data.replace(/[^\d.,-\s]/g, "");
2256
- let splitterCoordinates = " ";
2257
- let splitterAxis = ",";
2258
- const commaIndex = data.indexOf(",");
2259
- const spaceIndex = data.indexOf(" ");
2260
- if ((spaceIndex > -1 && commaIndex > spaceIndex) || commaIndex <= -1) {
2261
- splitterCoordinates = ",";
2262
- splitterAxis = " ";
2263
- }
2264
- let points = data.trim().split(splitterCoordinates);
2265
- points = points.filter(a => a != "");
2266
- const result = [];
2267
- for (let i = 0; i < points.length; i++) {
2268
- const pointData = points[i];
2269
- const coords = pointData.trim().split(splitterAxis);
2270
- if (coords.length == 2 || coords.length == 3) {
2271
- const longitude = Number(coords[0]);
2272
- const latitude = Number(coords[1]);
2273
- const altitude = Number(coords.length >= 3 ? coords[2] : 0);
2274
- if (longitude != null && latitude != null) {
2275
- result.push({
2276
- altitude: altitude,
2277
- latitude: latitude,
2278
- longitude: longitude
2279
- });
2280
- }
2281
- else {
2282
- console.warn("Invalid point data detected.", pointData);
2283
- }
2284
- }
2285
- }
2286
- return result;
2287
- }
2288
- Geometry.ParsePoints = ParsePoints;
2289
- /**
2290
- * Parses both string and object Bruce geometry.
2291
- * String geometry is legacy Bruce data.
2292
- * @param geometry
2293
- * @returns
2294
- */
2295
- function ParseGeometry(geometry) {
2296
- if (typeof geometry == "string") {
2297
- let positions = [];
2298
- const geometryParsed = (geometry || "").split(";");
2299
- for (let i = 0; i < geometryParsed.length; i++) {
2300
- const data = geometryParsed[i];
2301
- const points = ParsePoints(data);
2302
- if (points && points.length > 0) {
2303
- positions = positions.concat(points);
2304
- }
2305
- }
2306
- positions = RemoveRepeatPoints(positions);
2307
- const newGeometry = {};
2308
- if (positions.length > 0) {
2309
- const topPoint = positions[0];
2310
- newGeometry.Point = `${topPoint.latitude},${topPoint.longitude}` + (topPoint.altitude != null ? `,${topPoint.altitude}` : "");
2311
- if (positions.length > 1) {
2312
- newGeometry.Polygon = [{ Facing: EPolygonRingType.Boundaries, LinearRing: LineStrFromPoints(positions) }];
2313
- }
2314
- if (positions.length > 2) {
2315
- newGeometry.LineString = LineStrFromPoints(positions);
2316
- }
2317
- }
2318
- return newGeometry;
2319
- }
2320
- return geometry;
2321
- }
2322
- Geometry.ParseGeometry = ParseGeometry;
2323
- })(exports.Geometry || (exports.Geometry = {}));
2324
-
2325
2383
  /**
2326
2384
  * Describes a Bruce stored date.
2327
2385
  */