@twinmatrix/spatialverse-sdk-web 0.0.2 → 0.0.3

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.
Files changed (125) hide show
  1. package/lib/cjs/index.js +9 -9
  2. package/lib/cjs/index.js.map +1 -1
  3. package/lib/cjs/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/CustomThreeJsWrapper.js +213 -294
  4. package/lib/cjs/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/CustomThreeJsWrapper.js.map +1 -1
  5. package/lib/cjs/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/utils.js +43 -45
  6. package/lib/cjs/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/utils.js.map +1 -1
  7. package/lib/cjs/meta-atlas-sdk/3DMap/MainMap.js +241 -271
  8. package/lib/cjs/meta-atlas-sdk/3DMap/MainMap.js.map +1 -1
  9. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/fetch-published-json.js +167 -215
  10. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/fetch-published-json.js.map +1 -1
  11. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/fetchMapObjectsData.js +28 -30
  12. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/fetchMapObjectsData.js.map +1 -1
  13. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/meta-atlas-sdk-core.js +876 -1188
  14. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/meta-atlas-sdk-core.js.map +1 -1
  15. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/index.js +173 -163
  16. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/index.js.map +1 -1
  17. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/interfaces.js +6 -6
  18. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/interfaces.js.map +1 -1
  19. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/mapObjectsHelper.js +6 -6
  20. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/mapObjectsHelper.js.map +1 -1
  21. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/routeLayers.js +3 -3
  22. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/routeLayers.js.map +1 -1
  23. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/routing-helpers.js +546 -620
  24. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/routing-helpers.js.map +1 -1
  25. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/utils.js +155 -160
  26. package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/utils.js.map +1 -1
  27. package/lib/cjs/meta-atlas-sdk/customStyles.js +2 -2
  28. package/lib/cjs/meta-atlas-sdk/customStyles.js.map +1 -1
  29. package/lib/cjs/meta-atlas-sdk/customerLayer.js +15 -29
  30. package/lib/cjs/meta-atlas-sdk/customerLayer.js.map +1 -1
  31. package/lib/cjs/meta-atlas-sdk/customerLayerVariant.js +5 -5
  32. package/lib/cjs/meta-atlas-sdk/customerLayerVariant.js.map +1 -1
  33. package/lib/cjs/meta-atlas-sdk/meta-atlas-sdk.js +832 -1060
  34. package/lib/cjs/meta-atlas-sdk/meta-atlas-sdk.js.map +1 -1
  35. package/lib/cjs/meta-atlas-sdk/utils/helpers.js +33 -50
  36. package/lib/cjs/meta-atlas-sdk/utils/helpers.js.map +1 -1
  37. package/lib/cjs/meta-atlas-sdk/utils/local-storage.js +18 -36
  38. package/lib/cjs/meta-atlas-sdk/utils/local-storage.js.map +1 -1
  39. package/lib/cjs/meta-atlas-sdk/utils/mapobjects-store.js +6 -6
  40. package/lib/cjs/meta-atlas-sdk/utils/mapobjects-store.js.map +1 -1
  41. package/lib/cjs/meta-atlas-sdk/utils/routing-store.js +6 -6
  42. package/lib/cjs/meta-atlas-sdk/utils/routing-store.js.map +1 -1
  43. package/lib/cjs/meta-atlas-sdk/utils/routing-visualizer/index.js +428 -556
  44. package/lib/cjs/meta-atlas-sdk/utils/routing-visualizer/index.js.map +1 -1
  45. package/lib/cjs/react/MetaAtlasMap.js +127 -0
  46. package/lib/cjs/react/MetaAtlasMap.js.map +1 -0
  47. package/lib/cjs/react/hooks/useDrawing/index.js +17 -18
  48. package/lib/cjs/react/hooks/useDrawing/index.js.map +1 -1
  49. package/lib/cjs/react/hooks/useFocus/index.js +48 -55
  50. package/lib/cjs/react/hooks/useFocus/index.js.map +1 -1
  51. package/lib/cjs/react/hooks/useMapEvents/index.js +40 -50
  52. package/lib/cjs/react/hooks/useMapEvents/index.js.map +1 -1
  53. package/lib/cjs/react/hooks/useMapOverlays/index.js +20 -21
  54. package/lib/cjs/react/hooks/useMapOverlays/index.js.map +1 -1
  55. package/lib/cjs/react/hooks/useMetaAtlas/index.js +77 -95
  56. package/lib/cjs/react/hooks/useMetaAtlas/index.js.map +1 -1
  57. package/lib/cjs/react/hooks/useMetaAtlas.js +78 -96
  58. package/lib/cjs/react/hooks/useMetaAtlas.js.map +1 -1
  59. package/lib/cjs/react/hooks/useRouting/index.js +21 -20
  60. package/lib/cjs/react/hooks/useRouting/index.js.map +1 -1
  61. package/lib/cjs/react/hooks/useSearch/index.js +35 -34
  62. package/lib/cjs/react/hooks/useSearch/index.js.map +1 -1
  63. package/lib/cjs/react/hooks/useStampRally/index.js +30 -29
  64. package/lib/cjs/react/hooks/useStampRally/index.js.map +1 -1
  65. package/lib/cjs/react/hooks/useStampRally/utils.js +2 -2
  66. package/lib/cjs/react/hooks/useStampRally/utils.js.map +1 -1
  67. package/lib/cjs/react/index.js +31 -31
  68. package/lib/cjs/react/index.js.map +1 -1
  69. package/lib/cjs/react/stores/useMapDataStore.js +53 -64
  70. package/lib/cjs/react/stores/useMapDataStore.js.map +1 -1
  71. package/lib/cjs/react/stores/useMetaAtlasStore.js +27 -40
  72. package/lib/cjs/react/stores/useMetaAtlasStore.js.map +1 -1
  73. package/lib/esm/index.js +3 -7
  74. package/lib/esm/index.js.map +1 -1
  75. package/lib/esm/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/CustomThreeJsWrapper.js +2 -1
  76. package/lib/esm/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/CustomThreeJsWrapper.js.map +1 -1
  77. package/lib/esm/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/utils.js +10 -9
  78. package/lib/esm/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/utils.js.map +1 -1
  79. package/lib/esm/meta-atlas-sdk/3DMap/MainMap.js +2 -2
  80. package/lib/esm/meta-atlas-sdk/3DMap/MainMap.js.map +1 -1
  81. package/lib/esm/meta-atlas-sdk/MetaAtlasCore/fetch-published-json.js +3 -3
  82. package/lib/esm/meta-atlas-sdk/MetaAtlasCore/fetch-published-json.js.map +1 -1
  83. package/lib/esm/meta-atlas-sdk/MetaAtlasCore/fetchMapObjectsData.js +4 -3
  84. package/lib/esm/meta-atlas-sdk/MetaAtlasCore/fetchMapObjectsData.js.map +1 -1
  85. package/lib/esm/meta-atlas-sdk/MetaAtlasCore/meta-atlas-sdk-core.js +22 -14
  86. package/lib/esm/meta-atlas-sdk/MetaAtlasCore/meta-atlas-sdk-core.js.map +1 -1
  87. package/lib/esm/meta-atlas-sdk/MetaAtlasCore/routing-core/index.js +8 -8
  88. package/lib/esm/meta-atlas-sdk/MetaAtlasCore/routing-core/index.js.map +1 -1
  89. package/lib/esm/meta-atlas-sdk/MetaAtlasCore/routing-core/mapObjectsHelper.js +3 -3
  90. package/lib/esm/meta-atlas-sdk/MetaAtlasCore/routing-core/mapObjectsHelper.js.map +1 -1
  91. package/lib/esm/meta-atlas-sdk/MetaAtlasCore/routing-core/routing-helpers.js +18 -11
  92. package/lib/esm/meta-atlas-sdk/MetaAtlasCore/routing-core/routing-helpers.js.map +1 -1
  93. package/lib/esm/meta-atlas-sdk/MetaAtlasCore/routing-core/utils.js +4 -3
  94. package/lib/esm/meta-atlas-sdk/MetaAtlasCore/routing-core/utils.js.map +1 -1
  95. package/lib/esm/meta-atlas-sdk/customerLayer.js +4 -1
  96. package/lib/esm/meta-atlas-sdk/customerLayer.js.map +1 -1
  97. package/lib/esm/meta-atlas-sdk/meta-atlas-sdk.js +80 -61
  98. package/lib/esm/meta-atlas-sdk/meta-atlas-sdk.js.map +1 -1
  99. package/lib/esm/meta-atlas-sdk/utils/helpers.js +3 -1
  100. package/lib/esm/meta-atlas-sdk/utils/helpers.js.map +1 -1
  101. package/lib/esm/meta-atlas-sdk/utils/routing-visualizer/index.js +19 -15
  102. package/lib/esm/meta-atlas-sdk/utils/routing-visualizer/index.js.map +1 -1
  103. package/lib/esm/react/MetaAtlasMap.js +120 -0
  104. package/lib/esm/react/MetaAtlasMap.js.map +1 -0
  105. package/lib/esm/react/hooks/useDrawing/index.js +2 -2
  106. package/lib/esm/react/hooks/useDrawing/index.js.map +1 -1
  107. package/lib/esm/react/hooks/useFocus/index.js +4 -3
  108. package/lib/esm/react/hooks/useFocus/index.js.map +1 -1
  109. package/lib/esm/react/hooks/useMapEvents/index.js +3 -3
  110. package/lib/esm/react/hooks/useMapEvents/index.js.map +1 -1
  111. package/lib/esm/react/hooks/useMapOverlays/index.js +2 -2
  112. package/lib/esm/react/hooks/useMapOverlays/index.js.map +1 -1
  113. package/lib/esm/react/hooks/useMetaAtlas/index.js +162 -60
  114. package/lib/esm/react/hooks/useMetaAtlas/index.js.map +1 -1
  115. package/lib/esm/react/hooks/useMetaAtlas.js +162 -60
  116. package/lib/esm/react/hooks/useMetaAtlas.js.map +1 -1
  117. package/lib/esm/react/hooks/useRouting/index.js +2 -2
  118. package/lib/esm/react/hooks/useRouting/index.js.map +1 -1
  119. package/lib/esm/react/hooks/useSearch/index.js +2 -2
  120. package/lib/esm/react/hooks/useSearch/index.js.map +1 -1
  121. package/lib/esm/react/hooks/useStampRally/index.js +8 -7
  122. package/lib/esm/react/hooks/useStampRally/index.js.map +1 -1
  123. package/lib/esm/react/index.js +11 -15
  124. package/lib/esm/react/index.js.map +1 -1
  125. package/package.json +9 -6
@@ -20,24 +20,11 @@ var _helpers = require("@turf/helpers");
20
20
  var _length = _interopRequireDefault(require("@turf/length"));
21
21
  var _turf = require("@turf/turf");
22
22
  var _lodash = require("lodash");
23
- var _interfaces = require("./interfaces");
24
- var _ = _interopRequireDefault(require("."));
25
- var _mapObjectsHelper = require("./mapObjectsHelper");
26
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
27
- function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
28
- function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
29
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
30
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
31
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
32
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
33
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
34
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
35
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
36
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
37
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
38
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
39
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
40
- var ManeuverType = exports.ManeuverType = /*#__PURE__*/function (ManeuverType) {
23
+ var _interfaces = require("./interfaces.js");
24
+ var _index = _interopRequireDefault(require("./index.js"));
25
+ var _mapObjectsHelper = require("./mapObjectsHelper.js");
26
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
27
+ let ManeuverType = exports.ManeuverType = /*#__PURE__*/function (ManeuverType) {
41
28
  ManeuverType["RouteOverview"] = "Route Overview";
42
29
  ManeuverType["SectionOverview"] = "Section Overview";
43
30
  ManeuverType["LeftHairPinTurn"] = "Left hairpin turn";
@@ -54,9 +41,9 @@ var ManeuverType = exports.ManeuverType = /*#__PURE__*/function (ManeuverType) {
54
41
  return ManeuverType;
55
42
  }({});
56
43
  function createDefaultSegment(pathSegment) {
57
- var startMapObj = (0, _mapObjectsHelper.getEdge)(pathSegment.edges[0]);
58
- var endMapObj = (0, _mapObjectsHelper.getEdge)(pathSegment.edges[1]);
59
- var segment = {
44
+ const startMapObj = (0, _mapObjectsHelper.getEdge)(pathSegment.edges[0]);
45
+ const endMapObj = (0, _mapObjectsHelper.getEdge)(pathSegment.edges[1]);
46
+ const segment = {
60
47
  maneuverType: ManeuverType.Static,
61
48
  coordinates: [],
62
49
  distance: 0,
@@ -88,8 +75,8 @@ function isOverviewSegment(segment) {
88
75
  return segment.maneuverType === ManeuverType.RouteOverview || segment.maneuverType === ManeuverType.SectionOverview;
89
76
  }
90
77
  function updateFeatureHighlightState(features, isHighlighted) {
91
- for (var index = 0; index < features.length; index += 1) {
92
- var feature = features[index];
78
+ for (let index = 0; index < features.length; index += 1) {
79
+ const feature = features[index];
93
80
  if (isHighlighted) {
94
81
  feature.properties.highlight = true;
95
82
  } else {
@@ -99,9 +86,9 @@ function updateFeatureHighlightState(features, isHighlighted) {
99
86
  return features;
100
87
  }
101
88
  function highlightRouteSegment(pathFeatures, segmentToHighlight) {
102
- var highlightNodeOnly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
103
- for (var index = 0; index < pathFeatures.length; index += 1) {
104
- var segment = pathFeatures[index];
89
+ let highlightNodeOnly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
90
+ for (let index = 0; index < pathFeatures.length; index += 1) {
91
+ const segment = pathFeatures[index];
105
92
  if (segment.properties.segmentNumber === segmentToHighlight) {
106
93
  if (highlightNodeOnly) {
107
94
  if (segment.properties.startPoint === true) {
@@ -117,53 +104,56 @@ function highlightRouteSegment(pathFeatures, segmentToHighlight) {
117
104
  return pathFeatures;
118
105
  }
119
106
  function getRouteNode(coordinates, segmentNumber, isHighlighted, patchNumber) {
120
- var whereDimension = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '';
107
+ let whereDimension = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '';
121
108
  if (coordinates.length === 0) {
122
109
  return [];
123
110
  }
124
- var properties = {
125
- segmentNumber: segmentNumber,
111
+ const properties = {
112
+ segmentNumber,
126
113
  dimension_where: whereDimension,
127
- patchNumber: patchNumber,
114
+ patchNumber,
128
115
  isNode: true
129
116
  };
130
- var node = (0, _helpers.point)(coordinates, properties);
131
- var features = [node];
117
+ const node = (0, _helpers.point)(coordinates, properties);
118
+ const features = [node];
132
119
  updateFeatureHighlightState(features, isHighlighted);
133
120
  return features;
134
121
  }
135
122
  function getRouteLine(coordinates, segmentNumber, isHighlighted, patchNumber, zone) {
136
- var whereDimension = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : '';
123
+ let whereDimension = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : '';
137
124
  if (coordinates.length === 0) {
138
125
  return [];
139
126
  }
140
- var properties = {
141
- segmentNumber: segmentNumber,
127
+ const properties = {
128
+ segmentNumber,
142
129
  dimension_where: whereDimension,
143
- patchNumber: patchNumber,
130
+ patchNumber,
144
131
  isNode: false,
145
- zone: zone
132
+ zone
146
133
  };
147
134
  // const curved = smooth(coordinates, {iteration: 1});
148
- var line = (0, _helpers.lineString)(coordinates, _objectSpread(_objectSpread({}, properties), {}, {
135
+ const line = (0, _helpers.lineString)(coordinates, {
136
+ ...properties,
149
137
  featureBelongsToLineString: true
150
- }));
151
- var startPoint = (0, _helpers.point)(coordinates[0], _objectSpread(_objectSpread({}, properties), {}, {
138
+ });
139
+ const startPoint = (0, _helpers.point)(coordinates[0], {
140
+ ...properties,
152
141
  featureBelongsToLineString: false
153
- }));
154
- var endPoint = (0, _helpers.point)(coordinates[coordinates.length - 1], _objectSpread(_objectSpread({}, properties), {}, {
142
+ });
143
+ const endPoint = (0, _helpers.point)(coordinates[coordinates.length - 1], {
144
+ ...properties,
155
145
  featureBelongsToLineString: false
156
- }));
157
- var features = [];
146
+ });
147
+ const features = [];
158
148
  features.push(startPoint, line, endPoint);
159
149
  updateFeatureHighlightState(features, isHighlighted);
160
150
  return features;
161
151
  }
162
152
  function getLineStringFeaturesOfRouteSegment(routeSegment) {
163
- var whereDimension = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
164
- var lineFeatures = [];
165
- for (var index = 0; index < routeSegment.features.length; index += 1) {
166
- var feature = routeSegment.features[index];
153
+ let whereDimension = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
154
+ const lineFeatures = [];
155
+ for (let index = 0; index < routeSegment.features.length; index += 1) {
156
+ const feature = routeSegment.features[index];
167
157
  if (feature.properties.featureBelongsToLineString) {
168
158
  if (whereDimension !== '') {
169
159
  if (feature.properties.dimension_where && feature.properties.dimension_where === whereDimension) {
@@ -177,9 +167,9 @@ function getLineStringFeaturesOfRouteSegment(routeSegment) {
177
167
  return lineFeatures;
178
168
  }
179
169
  function generateOverviewSegment(route) {
180
- var indexOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
181
- var overviewSegment = (0, _lodash.cloneDeep)(route.segments[1]);
182
- var initialWhereDimension = route.segments.length > 1 ? route.segments[1].startEdge.whereDimension : '';
170
+ let indexOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
171
+ const overviewSegment = (0, _lodash.cloneDeep)(route.segments[1]);
172
+ const initialWhereDimension = route.segments.length > 1 ? route.segments[1].startEdge.whereDimension : '';
183
173
  overviewSegment.coordinates = [];
184
174
  overviewSegment.features = [];
185
175
  overviewSegment.time = 0;
@@ -188,14 +178,14 @@ function generateOverviewSegment(route) {
188
178
  overviewSegment.maneuverType = ManeuverType.RouteOverview;
189
179
  overviewSegment.patchNumber = indexOffset;
190
180
  overviewSegment.instructions = ['Overview'];
191
- for (var index = 1; index < route.segments.length; index += 1) {
181
+ for (let index = 1; index < route.segments.length; index += 1) {
192
182
  if (route.segments[index].maneuverType !== ManeuverType.SectionOverview) {
193
- for (var j = 0; j < route.segments[index].coordinates.length; j += 1) {
194
- var coord = route.segments[index].coordinates[j];
183
+ for (let j = 0; j < route.segments[index].coordinates.length; j += 1) {
184
+ const coord = route.segments[index].coordinates[j];
195
185
  overviewSegment.coordinates.push(coord);
196
186
  }
197
- for (var _j = 0; _j < route.segments[index].features.length; _j += 1) {
198
- var feature = (0, _lodash.cloneDeep)(route.segments[index].features[_j]);
187
+ for (let j = 0; j < route.segments[index].features.length; j += 1) {
188
+ const feature = (0, _lodash.cloneDeep)(route.segments[index].features[j]);
199
189
  if (feature.properties && !feature.properties.isNode) {
200
190
  // isNonHighlightedOverview is used in layer styling to decide the color of lines
201
191
  // features which are not on initialWhereDimension should be colored accordingly
@@ -213,551 +203,488 @@ function generateOverviewSegment(route) {
213
203
  overviewSegment.distance = route.walkingDistance + route.transportDistance;
214
204
  return overviewSegment;
215
205
  }
216
- function createRoute(_x, _x2, _x3) {
217
- return _createRoute.apply(this, arguments);
218
- }
219
- function _createRoute() {
220
- _createRoute = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(startMapObjectId, endMapObjectId, wheelChairAccessibleRouteOnly) {
221
- var shouldAddOverviewSegment,
222
- indexOffset,
223
- path,
224
- pathSegments,
225
- optimizedPath,
226
- endSegment,
227
- segmentIndex,
228
- pathSegment,
229
- currentZone,
230
- _path,
231
- lastManeuverType,
232
- firstSegment,
233
- prevPathSegment,
234
- prevZone,
235
- prevPath,
236
- pathPoint,
237
- index,
238
- startPoint,
239
- midPoint,
240
- endPoint,
241
- currentManeuverType,
242
- _pathPoint,
243
- _pathPoint2,
244
- removeExtraChangeZoneSegment,
245
- lastSegmentAdded,
246
- immigrationPolygonFeatures,
247
- line,
248
- _index,
249
- immigrationPolygonFeature,
250
- intersects,
251
- lineBeforeImmigration,
252
- lengthOfLineBeforeImmigration,
253
- segmentBeforeImmigration,
254
- coordsOfLastSegment,
255
- secondLastSegmentAdded,
256
- immigrationLine,
257
- immigrationSegment,
258
- lineCoords,
259
- lineAfterImmigration,
260
- segmentAfterImmigration,
261
- startPointWithinPolygon,
262
- _immigrationLine,
263
- _immigrationSegment,
264
- changeZoneSegment,
265
- _secondLastSegmentAdded,
266
- _lineCoords,
267
- _lineAfterImmigration,
268
- _segmentAfterImmigration,
269
- previousLine,
270
- _lineCoords2,
271
- _lineAfterImmigration2,
272
- _segmentAfterImmigration2,
273
- enterPortalSegment,
274
- exitPortalSegment,
275
- _lastSegmentAdded2,
276
- travelPortalSegment,
277
- route,
278
- addOverviewSegment,
279
- initialIndex,
280
- dummySegment,
281
- patchNumber,
282
- whereDimension,
283
- _index2,
284
- highlight,
285
- segment,
286
- segmentNumber,
287
- routeSegmentCoords,
288
- segmentDistance,
289
- startEdgeFeatures,
290
- features,
291
- _iterator,
292
- _step,
293
- feature,
294
- _nextRouteSegment,
295
- portalCost,
296
- _portalCost,
297
- _segmentDistance,
298
- nextRouteSegment,
299
- overviewSegment,
300
- _args = arguments;
301
- return _regenerator().w(function (_context) {
302
- while (1) switch (_context.n) {
303
- case 0:
304
- shouldAddOverviewSegment = _args.length > 3 && _args[3] !== undefined ? _args[3] : true;
305
- indexOffset = _args.length > 4 && _args[4] !== undefined ? _args[4] : 0;
306
- path = _["default"].getRoute(startMapObjectId, endMapObjectId, wheelChairAccessibleRouteOnly);
307
- pathSegments = path.routes; // Find optimized path (i.e. combine straight segments) & maneuvers list
308
- optimizedPath = [];
309
- for (segmentIndex = 0; pathSegments && segmentIndex < pathSegments.length; segmentIndex += 1) {
310
- pathSegment = pathSegments[segmentIndex];
311
- currentZone = pathSegment.geojson.properties.zone;
312
- if (!pathSegment.isPortal) {
313
- _path = pathSegment.geojson.geometry.coordinates; // Reset state for each segment of the path
314
- lastManeuverType = ManeuverType.Static; // Only add the starting static node for the very first node of route
315
- if (optimizedPath.length === 0) {
316
- firstSegment = _objectSpread(_objectSpread({}, createDefaultSegment(pathSegment)), {}, {
317
- maneuverType: ManeuverType.Static,
318
- coordinates: [_path[0]]
319
- });
320
- optimizedPath.push(firstSegment);
321
- }
322
- if (segmentIndex > 0 && optimizedPath.length > 0) {
323
- prevPathSegment = pathSegments[segmentIndex - 1];
324
- prevZone = prevPathSegment.geojson.properties.zone;
325
- if (currentZone !== prevZone) {
326
- prevPath = prevPathSegment.geojson.geometry.coordinates;
327
- pathPoint = _objectSpread(_objectSpread({}, createDefaultSegment(prevPathSegment)), {}, {
328
- maneuverType: ManeuverType.ChangeZone,
329
- zone: currentZone,
330
- coordinates: [prevPath[prevPath.length - 1]]
331
- });
332
- optimizedPath.push(pathPoint);
333
- lastManeuverType = ManeuverType.ChangeZone;
334
- }
335
- }
336
- if (_path.length > 2) {
337
- for (index = 0; index < _path.length - 2; index += 1) {
338
- startPoint = _path[index];
339
- midPoint = _path[index + 1];
340
- endPoint = _path[index + 2]; // Keep updating endSegment on each iteration
341
- endSegment = _objectSpread(_objectSpread({}, createDefaultSegment(pathSegment)), {}, {
342
- maneuverType: ManeuverType.Static,
343
- coordinates: [endPoint],
344
- zone: currentZone
345
- });
206
+ async function createRoute(startMapObjectId, endMapObjectId, wheelChairAccessibleRouteOnly) {
207
+ let shouldAddOverviewSegment = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
208
+ let indexOffset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
209
+ const path = _index.default.getRoute(startMapObjectId, endMapObjectId, wheelChairAccessibleRouteOnly);
210
+ const pathSegments = path.routes;
346
211
 
347
- // const line = lineString([startPoint, midPoint]);
348
- // const segmentDistance = length(line, { units: DISTANCE_UNIT });
212
+ // Find optimized path (i.e. combine straight segments) & maneuvers list
213
+ const optimizedPath = [];
214
+ let endSegment;
215
+ for (let segmentIndex = 0; pathSegments && segmentIndex < pathSegments.length; segmentIndex += 1) {
216
+ const pathSegment = pathSegments[segmentIndex];
217
+ const currentZone = pathSegment.geojson.properties.zone;
218
+ if (!pathSegment.isPortal) {
219
+ const path = pathSegment.geojson.geometry.coordinates;
349
220
 
350
- // Determine the maneuver type based on the angle of the turn
351
- currentManeuverType = void 0;
352
- currentManeuverType = ManeuverType.ContinueStraight;
353
- // if ((index === 0 || index === path.length - 3) && segmentDistance < 3) {
354
- // currentManeuverType = ManeuverType.ContinueStraight;
355
- // }
356
- // else {
357
- // // Calculate the bearings between the points
358
- // const bearing1 = bearing(startPoint, midPoint);
359
- // const bearing2 = bearing(midPoint, endPoint);
221
+ // Reset state for each segment of the path
222
+ let lastManeuverType = ManeuverType.Static;
360
223
 
361
- // // Calculate the angle between the bearings
362
- // let angle = bearing2 - bearing1;
363
- // if (angle < -180) {
364
- // angle += 360;
365
- // } else if (angle > 180) {
366
- // angle -= 360;
367
- // }
224
+ // Only add the starting static node for the very first node of route
225
+ if (optimizedPath.length === 0) {
226
+ const firstSegment = {
227
+ ...createDefaultSegment(pathSegment),
228
+ maneuverType: ManeuverType.Static,
229
+ coordinates: [path[0]]
230
+ };
231
+ optimizedPath.push(firstSegment);
232
+ }
233
+ if (segmentIndex > 0 && optimizedPath.length > 0) {
234
+ const prevPathSegment = pathSegments[segmentIndex - 1];
235
+ const prevZone = prevPathSegment.geojson.properties.zone;
236
+ if (currentZone !== prevZone) {
237
+ const prevPath = prevPathSegment.geojson.geometry.coordinates;
238
+ const pathPoint = {
239
+ ...createDefaultSegment(prevPathSegment),
240
+ maneuverType: ManeuverType.ChangeZone,
241
+ zone: currentZone,
242
+ coordinates: [prevPath[prevPath.length - 1]]
243
+ };
244
+ optimizedPath.push(pathPoint);
245
+ lastManeuverType = ManeuverType.ChangeZone;
246
+ }
247
+ }
248
+ if (path.length > 2) {
249
+ for (let index = 0; index < path.length - 2; index += 1) {
250
+ const startPoint = path[index];
251
+ const midPoint = path[index + 1];
252
+ const endPoint = path[index + 2];
368
253
 
369
- // if (angle < -140) {
370
- // currentManeuverType = ManeuverType.LeftHairPinTurn;
371
- // } else if (angle > 140) {
372
- // currentManeuverType = ManeuverType.RightHairPinTurn;
373
- // } else if (angle < -50) {
374
- // currentManeuverType = ManeuverType.LeftTurn;
375
- // } else if (angle > 50) {
376
- // currentManeuverType = ManeuverType.RightTurn;
377
- // // } else if (angle < -10) {
378
- // // currentManeuverType = 'Veer left';
379
- // // } else if (angle > 10) {
380
- // // currentManeuverType = 'Veer right';
381
- // } else {
382
- // currentManeuverType = ManeuverType.ContinueStraight;
383
- // }
384
- // }
385
- _pathPoint = _objectSpread(_objectSpread({}, createDefaultSegment(pathSegment)), {}, {
386
- maneuverType: currentManeuverType,
387
- zone: currentZone
388
- });
389
- if (lastManeuverType === ManeuverType.ContinueStraight) {
390
- // If last iteration of loop then use the end point as segment end else use mid point
391
- // Use index + 3 because last two points are skipped by loop
392
- if (index + 3 === _path.length) {
393
- optimizedPath[optimizedPath.length - 1].coordinates.push(midPoint, endPoint);
394
- } else {
395
- optimizedPath[optimizedPath.length - 1].coordinates.push(midPoint);
396
- }
397
- optimizedPath[optimizedPath.length - 1].maneuverType = currentManeuverType;
398
- } else {
399
- _pathPoint.coordinates.push(startPoint, midPoint);
400
- optimizedPath.push(_pathPoint);
254
+ // Keep updating endSegment on each iteration
255
+ endSegment = {
256
+ ...createDefaultSegment(pathSegment),
257
+ maneuverType: ManeuverType.Static,
258
+ coordinates: [endPoint],
259
+ zone: currentZone
260
+ };
401
261
 
402
- // If reached end of path then add a ContinueStraight segment at end of path
403
- // Use index + 3 because last two points are skipped by loop
404
- if (index + 3 === _path.length) {
405
- // if a ContinueStraight segment was just added then extend that, else add a new ContinueStraight segment at end
406
- if (currentManeuverType === ManeuverType.ContinueStraight) {
407
- optimizedPath[optimizedPath.length - 1].coordinates.push(endPoint);
408
- } else {
409
- optimizedPath.push(_objectSpread(_objectSpread({}, createDefaultSegment(pathSegment)), {}, {
410
- maneuverType: ManeuverType.ContinueStraight,
411
- coordinates: [midPoint, endPoint],
412
- zone: currentZone
413
- }));
414
- }
415
- }
416
- }
417
- lastManeuverType = currentManeuverType;
418
- }
262
+ // const line = lineString([startPoint, midPoint]);
263
+ // const segmentDistance = length(line, { units: DISTANCE_UNIT });
264
+
265
+ // Determine the maneuver type based on the angle of the turn
266
+ let currentManeuverType;
267
+ currentManeuverType = ManeuverType.ContinueStraight;
268
+ // if ((index === 0 || index === path.length - 3) && segmentDistance < 3) {
269
+ // currentManeuverType = ManeuverType.ContinueStraight;
270
+ // }
271
+ // else {
272
+ // // Calculate the bearings between the points
273
+ // const bearing1 = bearing(startPoint, midPoint);
274
+ // const bearing2 = bearing(midPoint, endPoint);
275
+
276
+ // // Calculate the angle between the bearings
277
+ // let angle = bearing2 - bearing1;
278
+ // if (angle < -180) {
279
+ // angle += 360;
280
+ // } else if (angle > 180) {
281
+ // angle -= 360;
282
+ // }
283
+
284
+ // if (angle < -140) {
285
+ // currentManeuverType = ManeuverType.LeftHairPinTurn;
286
+ // } else if (angle > 140) {
287
+ // currentManeuverType = ManeuverType.RightHairPinTurn;
288
+ // } else if (angle < -50) {
289
+ // currentManeuverType = ManeuverType.LeftTurn;
290
+ // } else if (angle > 50) {
291
+ // currentManeuverType = ManeuverType.RightTurn;
292
+ // // } else if (angle < -10) {
293
+ // // currentManeuverType = 'Veer left';
294
+ // // } else if (angle > 10) {
295
+ // // currentManeuverType = 'Veer right';
296
+ // } else {
297
+ // currentManeuverType = ManeuverType.ContinueStraight;
298
+ // }
299
+ // }
300
+
301
+ const pathPoint = {
302
+ ...createDefaultSegment(pathSegment),
303
+ maneuverType: currentManeuverType,
304
+ zone: currentZone
305
+ };
306
+ if (lastManeuverType === ManeuverType.ContinueStraight) {
307
+ // If last iteration of loop then use the end point as segment end else use mid point
308
+ // Use index + 3 because last two points are skipped by loop
309
+ if (index + 3 === path.length) {
310
+ optimizedPath[optimizedPath.length - 1].coordinates.push(midPoint, endPoint);
311
+ } else {
312
+ optimizedPath[optimizedPath.length - 1].coordinates.push(midPoint);
313
+ }
314
+ optimizedPath[optimizedPath.length - 1].maneuverType = currentManeuverType;
315
+ } else {
316
+ pathPoint.coordinates.push(startPoint, midPoint);
317
+ optimizedPath.push(pathPoint);
318
+
319
+ // If reached end of path then add a ContinueStraight segment at end of path
320
+ // Use index + 3 because last two points are skipped by loop
321
+ if (index + 3 === path.length) {
322
+ // if a ContinueStraight segment was just added then extend that, else add a new ContinueStraight segment at end
323
+ if (currentManeuverType === ManeuverType.ContinueStraight) {
324
+ optimizedPath[optimizedPath.length - 1].coordinates.push(endPoint);
419
325
  } else {
420
- _pathPoint2 = _objectSpread(_objectSpread({}, createDefaultSegment(pathSegment)), {}, {
326
+ optimizedPath.push({
327
+ ...createDefaultSegment(pathSegment),
421
328
  maneuverType: ManeuverType.ContinueStraight,
422
- coordinates: _path,
329
+ coordinates: [midPoint, endPoint],
423
330
  zone: currentZone
424
331
  });
425
- optimizedPath.push(_pathPoint2);
426
332
  }
427
- removeExtraChangeZoneSegment = function removeExtraChangeZoneSegment() {
428
- // When going from public to transit, hide the ChangeZone instruction, if the next step is PassThroughImmigration.
429
- if (optimizedPath.length > 0) {
430
- var _lastSegmentAdded = optimizedPath[optimizedPath.length - 1];
431
- if (_lastSegmentAdded.maneuverType === ManeuverType.ChangeZone) {
432
- if (_lastSegmentAdded.zone === _interfaces.Zone.Transit) optimizedPath.pop();
333
+ }
334
+ }
335
+ lastManeuverType = currentManeuverType;
336
+ }
337
+ } else {
338
+ const pathPoint = {
339
+ ...createDefaultSegment(pathSegment),
340
+ maneuverType: ManeuverType.ContinueStraight,
341
+ coordinates: path,
342
+ zone: currentZone
343
+ };
344
+ optimizedPath.push(pathPoint);
345
+ }
346
+ const removeExtraChangeZoneSegment = () => {
347
+ // When going from public to transit, hide the ChangeZone instruction, if the next step is PassThroughImmigration.
348
+ if (optimizedPath.length > 0) {
349
+ const lastSegmentAdded = optimizedPath[optimizedPath.length - 1];
350
+ if (lastSegmentAdded.maneuverType === ManeuverType.ChangeZone) {
351
+ if (lastSegmentAdded.zone === _interfaces.Zone.Transit) optimizedPath.pop();
352
+ }
353
+ }
354
+ };
355
+ // Check if there are immigration crossings
356
+ let lastSegmentAdded = optimizedPath.length > 0 ? optimizedPath[optimizedPath.length - 1] : undefined;
357
+ if (lastSegmentAdded && lastSegmentAdded.maneuverType === ManeuverType.ContinueStraight) {
358
+ // Will add new segment, search for immigration crossings on the current non-vertical segment
359
+ const immigrationPolygonFeatures = (0, _mapObjectsHelper.getImmigrationPolygonFeaturesForWhereTaxonomy)(lastSegmentAdded.startEdge.whereDimension);
360
+ const line = (0, _helpers.lineString)(lastSegmentAdded.coordinates);
361
+ for (let index = 0; index < immigrationPolygonFeatures.length; index += 1) {
362
+ const immigrationPolygonFeature = immigrationPolygonFeatures[index];
363
+ if (!(0, _turf.booleanDisjoint)(line, immigrationPolygonFeature)) {
364
+ const intersects = (0, _turf.lineIntersect)(line, immigrationPolygonFeature);
365
+ if (intersects.features.length > 1) {
366
+ optimizedPath.pop();
367
+ const lineBeforeImmigration = (0, _turf.lineSlice)((0, _turf.getCoords)(line)[0], (0, _turf.getCoord)(intersects.features[0]), line);
368
+ const lengthOfLineBeforeImmigration = (0, _length.default)(lineBeforeImmigration, {
369
+ units: 'meters'
370
+ });
371
+ // Only add if length greater then min limit
372
+ if (lengthOfLineBeforeImmigration >= 10) {
373
+ const segmentBeforeImmigration = {
374
+ ...createDefaultSegment(pathSegment),
375
+ maneuverType: ManeuverType.ContinueStraight,
376
+ zone: currentZone,
377
+ coordinates: (0, _turf.getCoords)(lineBeforeImmigration)
378
+ };
379
+ optimizedPath.push(segmentBeforeImmigration);
380
+ } else if (optimizedPath.length > 0) {
381
+ lastSegmentAdded = optimizedPath[optimizedPath.length - 1];
382
+ // If lastSegmentAdded is a change zone segment then move both lastSegmentAdded and also the second last segment
383
+ if (lastSegmentAdded.maneuverType === ManeuverType.ChangeZone) {
384
+ const coordsOfLastSegment = (0, _turf.getCoords)(lineBeforeImmigration);
385
+ lastSegmentAdded.coordinates = [coordsOfLastSegment[coordsOfLastSegment.length - 1]];
386
+ if (optimizedPath.length > 1) {
387
+ const secondLastSegmentAdded = optimizedPath[optimizedPath.length - 2];
388
+ secondLastSegmentAdded.coordinates = secondLastSegmentAdded.coordinates.concat((0, _turf.getCoords)(lineBeforeImmigration));
433
389
  }
390
+ } else {
391
+ lastSegmentAdded.coordinates.concat((0, _turf.getCoords)(lineBeforeImmigration));
434
392
  }
435
- }; // Check if there are immigration crossings
436
- lastSegmentAdded = optimizedPath.length > 0 ? optimizedPath[optimizedPath.length - 1] : undefined;
437
- if (lastSegmentAdded && lastSegmentAdded.maneuverType === ManeuverType.ContinueStraight) {
438
- // Will add new segment, search for immigration crossings on the current non-vertical segment
439
- immigrationPolygonFeatures = (0, _mapObjectsHelper.getImmigrationPolygonFeaturesForWhereTaxonomy)(lastSegmentAdded.startEdge.whereDimension);
440
- line = (0, _helpers.lineString)(lastSegmentAdded.coordinates);
441
- for (_index = 0; _index < immigrationPolygonFeatures.length; _index += 1) {
442
- immigrationPolygonFeature = immigrationPolygonFeatures[_index];
443
- if (!(0, _turf.booleanDisjoint)(line, immigrationPolygonFeature)) {
444
- intersects = (0, _turf.lineIntersect)(line, immigrationPolygonFeature);
445
- if (intersects.features.length > 1) {
446
- optimizedPath.pop();
447
- lineBeforeImmigration = (0, _turf.lineSlice)((0, _turf.getCoords)(line)[0], (0, _turf.getCoord)(intersects.features[0]), line);
448
- lengthOfLineBeforeImmigration = (0, _length["default"])(lineBeforeImmigration, {
449
- units: 'meters'
450
- }); // Only add if length greater then min limit
451
- if (lengthOfLineBeforeImmigration >= 10) {
452
- segmentBeforeImmigration = _objectSpread(_objectSpread({}, createDefaultSegment(pathSegment)), {}, {
453
- maneuverType: ManeuverType.ContinueStraight,
454
- zone: currentZone,
455
- coordinates: (0, _turf.getCoords)(lineBeforeImmigration)
456
- });
457
- optimizedPath.push(segmentBeforeImmigration);
458
- } else if (optimizedPath.length > 0) {
459
- lastSegmentAdded = optimizedPath[optimizedPath.length - 1];
460
- // If lastSegmentAdded is a change zone segment then move both lastSegmentAdded and also the second last segment
461
- if (lastSegmentAdded.maneuverType === ManeuverType.ChangeZone) {
462
- coordsOfLastSegment = (0, _turf.getCoords)(lineBeforeImmigration);
463
- lastSegmentAdded.coordinates = [coordsOfLastSegment[coordsOfLastSegment.length - 1]];
464
- if (optimizedPath.length > 1) {
465
- secondLastSegmentAdded = optimizedPath[optimizedPath.length - 2];
466
- secondLastSegmentAdded.coordinates = secondLastSegmentAdded.coordinates.concat((0, _turf.getCoords)(lineBeforeImmigration));
467
- }
468
- } else {
469
- lastSegmentAdded.coordinates.concat((0, _turf.getCoords)(lineBeforeImmigration));
470
- }
471
- }
472
- immigrationLine = (0, _turf.lineSlice)((0, _turf.getCoord)(intersects.features[0]), (0, _turf.getCoord)(intersects.features[1]), line);
473
- immigrationSegment = _objectSpread(_objectSpread({}, createDefaultSegment(pathSegment)), {}, {
474
- maneuverType: ManeuverType.PassThroughImmigration,
475
- zone: currentZone,
476
- coordinates: (0, _turf.getCoords)(immigrationLine)
477
- }); // The lineBeforeImmigration might not have been added due to length limit
478
- // And if lineBeforeImmigration was supposed to be the the first segment then prepend this segment with coordinates of lineBeforeImmigration
479
- if (optimizedPath.length === 0) {
480
- immigrationSegment.coordinates = lineBeforeImmigration.geometry.coordinates.concat(immigrationSegment.coordinates);
481
- }
393
+ }
394
+ const immigrationLine = (0, _turf.lineSlice)((0, _turf.getCoord)(intersects.features[0]), (0, _turf.getCoord)(intersects.features[1]), line);
395
+ const immigrationSegment = {
396
+ ...createDefaultSegment(pathSegment),
397
+ maneuverType: ManeuverType.PassThroughImmigration,
398
+ zone: currentZone,
399
+ coordinates: (0, _turf.getCoords)(immigrationLine)
400
+ };
401
+ // The lineBeforeImmigration might not have been added due to length limit
402
+ // And if lineBeforeImmigration was supposed to be the the first segment then prepend this segment with coordinates of lineBeforeImmigration
403
+ if (optimizedPath.length === 0) {
404
+ immigrationSegment.coordinates = lineBeforeImmigration.geometry.coordinates.concat(immigrationSegment.coordinates);
405
+ }
482
406
 
483
- // When going from public to transit, hide the ChangeZone instruction, if the next step is PassThroughImmigration.
484
- removeExtraChangeZoneSegment();
485
- optimizedPath.push(immigrationSegment);
486
- lineCoords = (0, _turf.getCoords)(line);
487
- lineAfterImmigration = (0, _turf.lineSlice)((0, _turf.getCoord)(intersects.features[1]), lineCoords[lineCoords.length - 1], line);
488
- segmentAfterImmigration = _objectSpread(_objectSpread({}, createDefaultSegment(pathSegment)), {}, {
489
- maneuverType: ManeuverType.ContinueStraight,
490
- zone: currentZone,
491
- coordinates: (0, _turf.getCoords)(lineAfterImmigration)
492
- });
493
- optimizedPath.push(segmentAfterImmigration);
494
- // line = segmentAfterImmigration;
495
- } else if (intersects.features.length > 0) {
496
- // check if start point outside polygon then end inside polygon - valid
497
- startPointWithinPolygon = (0, _turf.booleanPointInPolygon)((0, _turf.getCoords)(line)[0], immigrationPolygonFeature);
498
- if (startPointWithinPolygon) {
499
- optimizedPath.pop();
407
+ // When going from public to transit, hide the ChangeZone instruction, if the next step is PassThroughImmigration.
408
+ removeExtraChangeZoneSegment();
409
+ optimizedPath.push(immigrationSegment);
410
+ const lineCoords = (0, _turf.getCoords)(line);
411
+ const lineAfterImmigration = (0, _turf.lineSlice)((0, _turf.getCoord)(intersects.features[1]), lineCoords[lineCoords.length - 1], line);
412
+ const segmentAfterImmigration = {
413
+ ...createDefaultSegment(pathSegment),
414
+ maneuverType: ManeuverType.ContinueStraight,
415
+ zone: currentZone,
416
+ coordinates: (0, _turf.getCoords)(lineAfterImmigration)
417
+ };
418
+ optimizedPath.push(segmentAfterImmigration);
419
+ // line = segmentAfterImmigration;
420
+ } else if (intersects.features.length > 0) {
421
+ // check if start point outside polygon then end inside polygon - valid
422
+ const startPointWithinPolygon = (0, _turf.booleanPointInPolygon)((0, _turf.getCoords)(line)[0], immigrationPolygonFeature);
423
+ if (startPointWithinPolygon) {
424
+ optimizedPath.pop();
500
425
 
501
- // One intersection point and start point is within polygon
502
- // Means line start inside and exits the polygon
503
- _immigrationLine = (0, _turf.lineSlice)((0, _turf.getCoords)(line)[0], (0, _turf.getCoord)(intersects.features[0]), line);
504
- _immigrationSegment = _objectSpread(_objectSpread({}, createDefaultSegment(pathSegment)), {}, {
505
- maneuverType: ManeuverType.PassThroughImmigration,
506
- zone: currentZone,
507
- coordinates: (0, _turf.getCoords)(_immigrationLine)
508
- });
509
- lastSegmentAdded = optimizedPath.length > 0 ? optimizedPath[optimizedPath.length - 1] : undefined;
510
- if (lastSegmentAdded && lastSegmentAdded.maneuverType === ManeuverType.ChangeZone) {
511
- // Remove change zone segment
512
- changeZoneSegment = optimizedPath.pop();
513
- if (optimizedPath.length > 1) {
514
- _secondLastSegmentAdded = optimizedPath[optimizedPath.length - 1];
515
- if (_secondLastSegmentAdded.maneuverType === ManeuverType.PassThroughImmigration) {
516
- optimizedPath.pop();
426
+ // One intersection point and start point is within polygon
427
+ // Means line start inside and exits the polygon
428
+ const immigrationLine = (0, _turf.lineSlice)((0, _turf.getCoords)(line)[0], (0, _turf.getCoord)(intersects.features[0]), line);
429
+ const immigrationSegment = {
430
+ ...createDefaultSegment(pathSegment),
431
+ maneuverType: ManeuverType.PassThroughImmigration,
432
+ zone: currentZone,
433
+ coordinates: (0, _turf.getCoords)(immigrationLine)
434
+ };
435
+ lastSegmentAdded = optimizedPath.length > 0 ? optimizedPath[optimizedPath.length - 1] : undefined;
436
+ if (lastSegmentAdded && lastSegmentAdded.maneuverType === ManeuverType.ChangeZone) {
437
+ // Remove change zone segment
438
+ const changeZoneSegment = optimizedPath.pop();
439
+ if (optimizedPath.length > 1) {
440
+ const secondLastSegmentAdded = optimizedPath[optimizedPath.length - 1];
441
+ if (secondLastSegmentAdded.maneuverType === ManeuverType.PassThroughImmigration) {
442
+ optimizedPath.pop();
517
443
 
518
- // Re add the change zone segment with updated coordinates
519
- changeZoneSegment.coordinates = [_secondLastSegmentAdded.coordinates[0]];
520
- optimizedPath.push(changeZoneSegment);
521
- _immigrationSegment.coordinates = _secondLastSegmentAdded.coordinates.concat(_immigrationSegment.coordinates);
522
- }
523
- }
524
- }
525
- // When going from public to transit, hide the ChangeZone instruction, if the next step is PassThroughImmigration.
526
- removeExtraChangeZoneSegment();
527
- optimizedPath.push(_immigrationSegment);
528
- _lineCoords = (0, _turf.getCoords)(line);
529
- _lineAfterImmigration = (0, _turf.lineSlice)((0, _turf.getCoord)(intersects.features[0]), _lineCoords[_lineCoords.length - 1], line);
530
- _segmentAfterImmigration = _objectSpread(_objectSpread({}, createDefaultSegment(pathSegment)), {}, {
531
- maneuverType: ManeuverType.ContinueStraight,
532
- zone: currentZone,
533
- coordinates: (0, _turf.getCoords)(_lineAfterImmigration)
534
- });
535
- optimizedPath.push(_segmentAfterImmigration);
536
- } else {
537
- // line starts outside immigration and ends inside immigration
538
- // this is not a valid case but lines are still divided into segments as the segments are used
539
- // by the logic under case 2(startPointWithinPolygon)
540
- previousLine = (0, _turf.lineSlice)((0, _turf.getCoords)(line)[0], (0, _turf.getCoord)(intersects.features[0]), line);
541
- lastSegmentAdded.coordinates = (0, _turf.getCoords)(previousLine);
542
- _lineCoords2 = (0, _turf.getCoords)(line);
543
- _lineAfterImmigration2 = (0, _turf.lineSlice)((0, _turf.getCoord)(intersects.features[0]), _lineCoords2[_lineCoords2.length - 1], line);
544
- _segmentAfterImmigration2 = _objectSpread(_objectSpread({}, createDefaultSegment(pathSegment)), {}, {
545
- maneuverType: ManeuverType.PassThroughImmigration,
546
- zone: currentZone,
547
- coordinates: (0, _turf.getCoords)(_lineAfterImmigration2)
548
- });
549
- optimizedPath.push(_segmentAfterImmigration2);
550
- // line = segmentAfterImmigration;
551
- }
444
+ // Re add the change zone segment with updated coordinates
445
+ changeZoneSegment.coordinates = [secondLastSegmentAdded.coordinates[0]];
446
+ optimizedPath.push(changeZoneSegment);
447
+ immigrationSegment.coordinates = secondLastSegmentAdded.coordinates.concat(immigrationSegment.coordinates);
552
448
  }
553
449
  }
554
450
  }
555
- }
556
- } else {
557
- // Keep updating endSegment on each iteration
558
- endSegment = _objectSpread(_objectSpread({}, createDefaultSegment(pathSegment)), {}, {
559
- maneuverType: ManeuverType.Static,
560
- coordinates: [pathSegment.geojson.geometry.coordinates[1]],
561
- zone: currentZone,
562
- isPortal: false
563
- });
564
- enterPortalSegment = _objectSpread(_objectSpread({}, createDefaultSegment(pathSegment)), {}, {
565
- maneuverType: ManeuverType.EnterPortal,
566
- coordinates: [pathSegment.geojson.geometry.coordinates[0]]
567
- }); // // Only add this EnterPortal segment if previously same what dimension portal is not being continued
568
- // // This is done to ensure Take Lift at A, Exit Lift at B, Take lift at B, Exit Lift at C is generated only as Take lift at A, Exit lift at C
569
- // let lastSegmentAdded = (optimizedPath.length > 0) ? optimizedPath[optimizedPath.length - 1] : undefined;
570
- // if (!lastSegmentAdded
571
- // || (lastSegmentAdded && lastSegmentAdded.maneuverType !== ManeuverType.ExitPortal)
572
- // || (lastSegmentAdded && lastSegmentAdded.maneuverType === ManeuverType.ExitPortal && lastSegmentAdded.startEdge.whatDimension !== enterPortalSegment.startEdge.whatDimension)) {
573
- // optimizedPath.push(enterPortalSegment);
574
- // lastSegmentAdded = enterPortalSegment;
575
- // }
576
- optimizedPath.push(enterPortalSegment);
577
- exitPortalSegment = _objectSpread(_objectSpread({}, createDefaultSegment(pathSegment)), {}, {
578
- maneuverType: ManeuverType.ExitPortal,
579
- coordinates: [pathSegment.geojson.geometry.coordinates[1]]
580
- }); // // This logic is tied to the above similar logic for EnterPortal
581
- // // Only add this ExitPortal segment if previously same what dimension portal is not being continued
582
- // // This is done to ensure Take Lift at A, Exit Lift at B, Take lift at B, Exit Lift at C is generated only as Take lift at A, Exit lift at C
583
- // if (lastSegmentAdded && lastSegmentAdded.maneuverType !== ManeuverType.ExitPortal) {
584
- // if (pathSegment.portalPath) {
585
- // const travelPortalSegment: RouteSegment = {
586
- // ...createDefaultSegment(pathSegment),
587
- // maneuverType: ManeuverType.TravelPortal,
588
- // coordinates: pathSegment.portalPath.geometry.coordinates,
589
- // zone: currentZone,
590
- // };
591
- // optimizedPath.push(travelPortalSegment);
592
- // }
593
- // optimizedPath.push(exitPortalSegment);
594
- // } else
595
- optimizedPath.push(exitPortalSegment);
596
- _lastSegmentAdded2 = optimizedPath.length > 0 ? optimizedPath[optimizedPath.length - 1] : undefined;
597
- if (_lastSegmentAdded2 && _lastSegmentAdded2.maneuverType === ManeuverType.ExitPortal) {
598
- optimizedPath.pop();
599
- if (pathSegment.portalPath) {
600
- travelPortalSegment = _objectSpread(_objectSpread({}, createDefaultSegment(pathSegment)), {}, {
601
- maneuverType: ManeuverType.TravelPortal,
602
- coordinates: pathSegment.portalPath.geometry.coordinates,
603
- zone: currentZone
604
- });
605
- optimizedPath.push(travelPortalSegment);
606
- }
607
- optimizedPath.push(exitPortalSegment);
451
+ // When going from public to transit, hide the ChangeZone instruction, if the next step is PassThroughImmigration.
452
+ removeExtraChangeZoneSegment();
453
+ optimizedPath.push(immigrationSegment);
454
+ const lineCoords = (0, _turf.getCoords)(line);
455
+ const lineAfterImmigration = (0, _turf.lineSlice)((0, _turf.getCoord)(intersects.features[0]), lineCoords[lineCoords.length - 1], line);
456
+ const segmentAfterImmigration = {
457
+ ...createDefaultSegment(pathSegment),
458
+ maneuverType: ManeuverType.ContinueStraight,
459
+ zone: currentZone,
460
+ coordinates: (0, _turf.getCoords)(lineAfterImmigration)
461
+ };
462
+ optimizedPath.push(segmentAfterImmigration);
463
+ } else {
464
+ // line starts outside immigration and ends inside immigration
465
+ // this is not a valid case but lines are still divided into segments as the segments are used
466
+ // by the logic under case 2(startPointWithinPolygon)
467
+ const previousLine = (0, _turf.lineSlice)((0, _turf.getCoords)(line)[0], (0, _turf.getCoord)(intersects.features[0]), line);
468
+ lastSegmentAdded.coordinates = (0, _turf.getCoords)(previousLine);
469
+ const lineCoords = (0, _turf.getCoords)(line);
470
+ const lineAfterImmigration = (0, _turf.lineSlice)((0, _turf.getCoord)(intersects.features[0]), lineCoords[lineCoords.length - 1], line);
471
+ const segmentAfterImmigration = {
472
+ ...createDefaultSegment(pathSegment),
473
+ maneuverType: ManeuverType.PassThroughImmigration,
474
+ zone: currentZone,
475
+ coordinates: (0, _turf.getCoords)(lineAfterImmigration)
476
+ };
477
+ optimizedPath.push(segmentAfterImmigration);
478
+ // line = segmentAfterImmigration;
608
479
  }
609
480
  }
610
481
  }
611
- if (endSegment) optimizedPath.push(endSegment);
612
- route = {
613
- segments: optimizedPath,
614
- walkingDistance: 0,
615
- transportDistance: 0,
616
- walkingTime: 0,
617
- transportTime: 0,
618
- distanceUnit: _interfaces.DISTANCE_UNIT,
619
- speed: _interfaces.WALK_SPEED
620
- }; // A patch denotes the segments which are directly connected to each other i.e. no portal in between, portal enter/exit can be part of the patch
621
- if (route.segments.length > 0) {
622
- addOverviewSegment = shouldAddOverviewSegment;
623
- initialIndex = 0;
624
- if (addOverviewSegment) {
625
- // Dummy overview segment at start of route
626
- dummySegment = (0, _lodash.cloneDeep)(route.segments[0]);
627
- dummySegment.maneuverType = ManeuverType.RouteOverview;
628
- route.segments.unshift(dummySegment);
629
- initialIndex = 1; // Because overview segment will be at 0th index of route
630
- }
482
+ }
483
+ }
484
+ } else {
485
+ // Keep updating endSegment on each iteration
486
+ endSegment = {
487
+ ...createDefaultSegment(pathSegment),
488
+ maneuverType: ManeuverType.Static,
489
+ coordinates: [pathSegment.geojson.geometry.coordinates[1]],
490
+ zone: currentZone,
491
+ isPortal: false
492
+ };
493
+ const enterPortalSegment = {
494
+ ...createDefaultSegment(pathSegment),
495
+ maneuverType: ManeuverType.EnterPortal,
496
+ coordinates: [pathSegment.geojson.geometry.coordinates[0]]
497
+ };
498
+ // // Only add this EnterPortal segment if previously same what dimension portal is not being continued
499
+ // // This is done to ensure Take Lift at A, Exit Lift at B, Take lift at B, Exit Lift at C is generated only as Take lift at A, Exit lift at C
500
+ // let lastSegmentAdded = (optimizedPath.length > 0) ? optimizedPath[optimizedPath.length - 1] : undefined;
501
+ // if (!lastSegmentAdded
502
+ // || (lastSegmentAdded && lastSegmentAdded.maneuverType !== ManeuverType.ExitPortal)
503
+ // || (lastSegmentAdded && lastSegmentAdded.maneuverType === ManeuverType.ExitPortal && lastSegmentAdded.startEdge.whatDimension !== enterPortalSegment.startEdge.whatDimension)) {
504
+ // optimizedPath.push(enterPortalSegment);
505
+ // lastSegmentAdded = enterPortalSegment;
506
+ // }
631
507
 
632
- // A patch denotes the segments which are directly connected to each other i.e. no portal in between, portal enter/exit can be part of the patch
633
- patchNumber = indexOffset + initialIndex;
634
- whereDimension = route.segments.length > initialIndex ? route.segments[initialIndex].startEdge.whereDimension : '';
635
- for (_index2 = initialIndex; _index2 < route.segments.length; _index2 += 1) {
636
- highlight = false;
637
- segment = route.segments[_index2];
638
- segmentNumber = indexOffset + _index2;
639
- if (!segment.isPortal) {
640
- // point feature if ManeuverType.Static else line feature
641
- if (segment.maneuverType === ManeuverType.Static || segment.maneuverType === ManeuverType.ChangeZone) {
642
- segment.features = getRouteNode(segment.coordinates[0], segmentNumber, highlight, patchNumber, segment.endEdge.whereDimension);
643
- segment.patchNumber = patchNumber;
644
- segment.whereDimension = whereDimension;
645
- } else {
646
- segment.features = getRouteLine(segment.coordinates, segmentNumber, highlight, patchNumber, segment.zone, segment.startEdge.whereDimension);
647
- segment.patchNumber = patchNumber;
648
- segment.whereDimension = whereDimension;
649
- }
650
- routeSegmentCoords = segment.coordinates;
651
- segmentDistance = void 0;
652
- if (routeSegmentCoords.length > 1) {
653
- segmentDistance = (0, _length["default"])((0, _helpers.lineString)(routeSegmentCoords), {
654
- units: route.distanceUnit
655
- });
656
- } else {
657
- segmentDistance = 0;
658
- }
659
- segment.distance = segmentDistance;
660
- if (segment.maneuverType !== ManeuverType.PassThroughImmigration) {
661
- segment.time = segment.distance / route.speed;
662
- } else {
663
- segment.time = 0;
664
- }
665
- } else {
666
- // if (
667
- // segment.maneuverType !== ManeuverType.EnterPortal
668
- // && segment.maneuverType !== ManeuverType.ExitPortal
669
- // ) {
670
- // console.warn('unexpected state in createRoute');
671
- // }
508
+ optimizedPath.push(enterPortalSegment);
509
+ const exitPortalSegment = {
510
+ ...createDefaultSegment(pathSegment),
511
+ maneuverType: ManeuverType.ExitPortal,
512
+ coordinates: [pathSegment.geojson.geometry.coordinates[1]]
513
+ };
514
+ // // This logic is tied to the above similar logic for EnterPortal
515
+ // // Only add this ExitPortal segment if previously same what dimension portal is not being continued
516
+ // // This is done to ensure Take Lift at A, Exit Lift at B, Take lift at B, Exit Lift at C is generated only as Take lift at A, Exit lift at C
517
+ // if (lastSegmentAdded && lastSegmentAdded.maneuverType !== ManeuverType.ExitPortal) {
518
+ // if (pathSegment.portalPath) {
519
+ // const travelPortalSegment: RouteSegment = {
520
+ // ...createDefaultSegment(pathSegment),
521
+ // maneuverType: ManeuverType.TravelPortal,
522
+ // coordinates: pathSegment.portalPath.geometry.coordinates,
523
+ // zone: currentZone,
524
+ // };
525
+ // optimizedPath.push(travelPortalSegment);
526
+ // }
672
527
 
673
- if (segment.maneuverType === ManeuverType.EnterPortal) {
674
- startEdgeFeatures = getRouteNode(segment.coordinates[0], segmentNumber, highlight, patchNumber, segment.startEdge.whereDimension);
675
- features = []; // eslint-disable-next-line no-restricted-syntax
676
- _iterator = _createForOfIteratorHelper(startEdgeFeatures);
677
- try {
678
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
679
- feature = _step.value;
680
- features.push(feature);
681
- }
682
- } catch (err) {
683
- _iterator.e(err);
684
- } finally {
685
- _iterator.f();
686
- }
687
- segment.features = features;
688
- segment.patchNumber = patchNumber;
689
- segment.whereDimension = whereDimension;
528
+ // optimizedPath.push(exitPortalSegment);
529
+ // } else
530
+ optimizedPath.push(exitPortalSegment);
531
+ const lastSegmentAdded = optimizedPath.length > 0 ? optimizedPath[optimizedPath.length - 1] : undefined;
532
+ if (lastSegmentAdded && lastSegmentAdded.maneuverType === ManeuverType.ExitPortal) {
533
+ optimizedPath.pop();
534
+ if (pathSegment.portalPath) {
535
+ const travelPortalSegment = {
536
+ ...createDefaultSegment(pathSegment),
537
+ maneuverType: ManeuverType.TravelPortal,
538
+ coordinates: pathSegment.portalPath.geometry.coordinates,
539
+ zone: currentZone
540
+ };
541
+ optimizedPath.push(travelPortalSegment);
542
+ }
543
+ optimizedPath.push(exitPortalSegment);
544
+ }
545
+ }
546
+ }
547
+ if (endSegment) optimizedPath.push(endSegment);
548
+ const route = {
549
+ segments: optimizedPath,
550
+ walkingDistance: 0,
551
+ transportDistance: 0,
552
+ walkingTime: 0,
553
+ transportTime: 0,
554
+ distanceUnit: _interfaces.DISTANCE_UNIT,
555
+ speed: _interfaces.WALK_SPEED
556
+ };
690
557
 
691
- // read next segment, if next segment is TravelPortal then do not include time of this enter portal segment
692
- _nextRouteSegment = route.segments.length >= _index2 + 2 ? route.segments[_index2 + 1] : undefined;
693
- if (_nextRouteSegment && _nextRouteSegment.maneuverType !== ManeuverType.TravelPortal) {
694
- portalCost = segment.cost;
695
- segment.time = portalCost || 0;
696
- } else {
697
- segment.time = 0;
698
- }
699
- segment.distance = 0;
700
- }
701
- if (segment.maneuverType === ManeuverType.TravelPortal) {
702
- segment.features = getRouteLine(segment.coordinates, segmentNumber, highlight, patchNumber, segment.zone, segment.startEdge.whereDimension);
703
- segment.patchNumber = patchNumber;
704
- segment.whereDimension = whereDimension;
705
- _portalCost = segment.cost;
706
- segment.time = _portalCost || 0;
707
- _segmentDistance = void 0;
708
- if (segment.coordinates.length > 1) {
709
- _segmentDistance = (0, _length["default"])((0, _helpers.lineString)(segment.coordinates), {
710
- units: route.distanceUnit
711
- });
712
- } else {
713
- _segmentDistance = 0;
714
- }
715
- segment.distance = _segmentDistance;
558
+ // A patch denotes the segments which are directly connected to each other i.e. no portal in between, portal enter/exit can be part of the patch
559
+ if (route.segments.length > 0) {
560
+ const addOverviewSegment = shouldAddOverviewSegment;
561
+ let initialIndex = 0;
562
+ if (addOverviewSegment) {
563
+ // Dummy overview segment at start of route
564
+ const dummySegment = (0, _lodash.cloneDeep)(route.segments[0]);
565
+ dummySegment.maneuverType = ManeuverType.RouteOverview;
566
+ route.segments.unshift(dummySegment);
567
+ initialIndex = 1; // Because overview segment will be at 0th index of route
568
+ }
716
569
 
717
- // Set time of previous enter portal instruction to zero, so that time in not shown in UI
718
- if (_index2 > 0) route.segments[_index2 - 1].time = 0;
719
- }
720
- if (segment.maneuverType === ManeuverType.ExitPortal) {
721
- // increment patch number to next value
722
- patchNumber += 1;
723
- whereDimension = segment.endEdge.whereDimension;
570
+ // A patch denotes the segments which are directly connected to each other i.e. no portal in between, portal enter/exit can be part of the patch
571
+ let patchNumber = indexOffset + initialIndex;
572
+ let whereDimension = route.segments.length > initialIndex ? route.segments[initialIndex].startEdge.whereDimension : '';
573
+ for (let index = initialIndex; index < route.segments.length; index += 1) {
574
+ const highlight = false;
575
+ const segment = route.segments[index];
576
+ const segmentNumber = indexOffset + index;
577
+ if (!segment.isPortal) {
578
+ // point feature if ManeuverType.Static else line feature
579
+ if (segment.maneuverType === ManeuverType.Static || segment.maneuverType === ManeuverType.ChangeZone) {
580
+ segment.features = getRouteNode(segment.coordinates[0], segmentNumber, highlight, patchNumber, segment.endEdge.whereDimension);
581
+ segment.patchNumber = patchNumber;
582
+ segment.whereDimension = whereDimension;
583
+ } else {
584
+ segment.features = getRouteLine(segment.coordinates, segmentNumber, highlight, patchNumber, segment.zone, segment.startEdge.whereDimension);
585
+ segment.patchNumber = patchNumber;
586
+ segment.whereDimension = whereDimension;
587
+ }
588
+ const routeSegmentCoords = segment.coordinates;
589
+ let segmentDistance;
590
+ if (routeSegmentCoords.length > 1) {
591
+ segmentDistance = (0, _length.default)((0, _helpers.lineString)(routeSegmentCoords), {
592
+ units: route.distanceUnit
593
+ });
594
+ } else {
595
+ segmentDistance = 0;
596
+ }
597
+ segment.distance = segmentDistance;
598
+ if (segment.maneuverType !== ManeuverType.PassThroughImmigration) {
599
+ segment.time = segment.distance / route.speed;
600
+ } else {
601
+ segment.time = 0;
602
+ }
603
+ } else {
604
+ // if (
605
+ // segment.maneuverType !== ManeuverType.EnterPortal
606
+ // && segment.maneuverType !== ManeuverType.ExitPortal
607
+ // ) {
608
+ // console.warn('unexpected state in createRoute');
609
+ // }
724
610
 
725
- // Remove ExitPortal segment from route, because its only used to calculate patch information since ATOMS-207
726
- route.segments.splice(_index2, 1);
727
- _index2 -= 1;
728
- }
611
+ if (segment.maneuverType === ManeuverType.EnterPortal) {
612
+ const startEdgeFeatures = getRouteNode(segment.coordinates[0], segmentNumber, highlight, patchNumber, segment.startEdge.whereDimension);
613
+ const features = [];
614
+ // eslint-disable-next-line no-restricted-syntax
615
+ for (const feature of startEdgeFeatures) {
616
+ features.push(feature);
617
+ }
618
+ segment.features = features;
619
+ segment.patchNumber = patchNumber;
620
+ segment.whereDimension = whereDimension;
729
621
 
730
- // read next segment
731
- nextRouteSegment = route.segments.length >= _index2 + 2 ? route.segments[_index2 + 1] : undefined;
732
- if (nextRouteSegment && nextRouteSegment.maneuverType === ManeuverType.TravelPortal) {
733
- patchNumber += 1;
734
- }
735
- }
736
- if (segment.maneuverType === ManeuverType.TravelPortal) {
737
- route.transportDistance += segment.distance;
738
- route.transportTime += segment.time;
739
- } else {
740
- route.walkingDistance += segment.distance;
741
- route.walkingTime += segment.time;
742
- }
743
- }
744
- if (addOverviewSegment) {
745
- // Generate and add actual overview segment
746
- overviewSegment = generateOverviewSegment(route, indexOffset);
747
- route.segments[0] = overviewSegment;
748
- }
622
+ // read next segment, if next segment is TravelPortal then do not include time of this enter portal segment
623
+ const nextRouteSegment = route.segments.length >= index + 2 ? route.segments[index + 1] : undefined;
624
+ if (nextRouteSegment && nextRouteSegment.maneuverType !== ManeuverType.TravelPortal) {
625
+ const portalCost = segment.cost;
626
+ segment.time = portalCost || 0;
627
+ } else {
628
+ segment.time = 0;
629
+ }
630
+ segment.distance = 0;
631
+ }
632
+ if (segment.maneuverType === ManeuverType.TravelPortal) {
633
+ segment.features = getRouteLine(segment.coordinates, segmentNumber, highlight, patchNumber, segment.zone, segment.startEdge.whereDimension);
634
+ segment.patchNumber = patchNumber;
635
+ segment.whereDimension = whereDimension;
636
+ const portalCost = segment.cost;
637
+ segment.time = portalCost || 0;
638
+ let segmentDistance;
639
+ if (segment.coordinates.length > 1) {
640
+ segmentDistance = (0, _length.default)((0, _helpers.lineString)(segment.coordinates), {
641
+ units: route.distanceUnit
642
+ });
643
+ } else {
644
+ segmentDistance = 0;
749
645
  }
750
- return _context.a(2, route);
646
+ segment.distance = segmentDistance;
647
+
648
+ // Set time of previous enter portal instruction to zero, so that time in not shown in UI
649
+ if (index > 0) route.segments[index - 1].time = 0;
650
+ }
651
+ if (segment.maneuverType === ManeuverType.ExitPortal) {
652
+ // increment patch number to next value
653
+ patchNumber += 1;
654
+ whereDimension = segment.endEdge.whereDimension;
655
+
656
+ // Remove ExitPortal segment from route, because its only used to calculate patch information since ATOMS-207
657
+ route.segments.splice(index, 1);
658
+ index -= 1;
659
+ }
660
+
661
+ // read next segment
662
+ const nextRouteSegment = route.segments.length >= index + 2 ? route.segments[index + 1] : undefined;
663
+ if (nextRouteSegment && nextRouteSegment.maneuverType === ManeuverType.TravelPortal) {
664
+ patchNumber += 1;
665
+ }
666
+ }
667
+ if (segment.maneuverType === ManeuverType.TravelPortal) {
668
+ route.transportDistance += segment.distance;
669
+ route.transportTime += segment.time;
670
+ } else {
671
+ route.walkingDistance += segment.distance;
672
+ route.walkingTime += segment.time;
751
673
  }
752
- }, _callee);
753
- }));
754
- return _createRoute.apply(this, arguments);
674
+ }
675
+ if (addOverviewSegment) {
676
+ // Generate and add actual overview segment
677
+ const overviewSegment = generateOverviewSegment(route, indexOffset);
678
+ route.segments[0] = overviewSegment;
679
+ }
680
+ }
681
+ return route;
755
682
  }
756
683
  function getPatch(route) {
757
- var patchNumber = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
758
- var routefeatures = [];
759
- for (var index = 0; index < route.segments.length; index += 1) {
760
- var routeSegment = route.segments[index];
684
+ let patchNumber = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
685
+ let routefeatures = [];
686
+ for (let index = 0; index < route.segments.length; index += 1) {
687
+ const routeSegment = route.segments[index];
761
688
  if (routeSegment.patchNumber === patchNumber) {
762
689
  routefeatures = routefeatures.concat(routeSegment.features);
763
690
  }
@@ -765,18 +692,17 @@ function getPatch(route) {
765
692
  return routefeatures;
766
693
  }
767
694
  function getFeaturesForPatch(route, patchNumber, overviewSegmentInfo) {
768
- var routefeatures = [];
769
- for (var index = 0; index < route.segments.length; index += 1) {
770
- var routeSegment = route.segments[index];
695
+ let routefeatures = [];
696
+ for (let index = 0; index < route.segments.length; index += 1) {
697
+ const routeSegment = route.segments[index];
771
698
  if (overviewSegmentInfo.includeOverviewFeatures) {
772
699
  // Return all features in default case
773
700
  if (isOverviewSegment(routeSegment)) {
774
- var nonHighlightedOverviewFeatures = [];
775
- var highlightedOverviewFeatures = [];
776
- for (var j = 0; j < routeSegment.features.length; j++) {
777
- var _feature$properties;
778
- var feature = routeSegment.features[j];
779
- if (((_feature$properties = feature.properties) === null || _feature$properties === void 0 ? void 0 : _feature$properties.patchNumber) !== undefined && feature.properties.patchNumber === overviewSegmentInfo.patchNumberForOverviewFeatures) {
701
+ const nonHighlightedOverviewFeatures = [];
702
+ const highlightedOverviewFeatures = [];
703
+ for (let j = 0; j < routeSegment.features.length; j++) {
704
+ const feature = routeSegment.features[j];
705
+ if (feature.properties?.patchNumber !== undefined && feature.properties.patchNumber === overviewSegmentInfo.patchNumberForOverviewFeatures) {
780
706
  if (feature.properties.isNonHighlightedOverview !== undefined) {
781
707
  if (feature.properties.isNonHighlightedOverview === '1') {
782
708
  nonHighlightedOverviewFeatures.push(feature);
@@ -788,7 +714,7 @@ function getFeaturesForPatch(route, patchNumber, overviewSegmentInfo) {
788
714
  }
789
715
  // Sort the features such that non hihglighted features come first in the array
790
716
  // because on map they should be sorted below highlighted features in z dimension
791
- var overviewSegmentFeatures = nonHighlightedOverviewFeatures.concat(highlightedOverviewFeatures);
717
+ const overviewSegmentFeatures = nonHighlightedOverviewFeatures.concat(highlightedOverviewFeatures);
792
718
  routefeatures = routefeatures.concat(overviewSegmentFeatures);
793
719
  }
794
720
  } else if (routeSegment.patchNumber === patchNumber) {
@@ -845,12 +771,12 @@ function getPortalName(whatDimension) {
845
771
  }
846
772
  }
847
773
  function getTerminalAndLevelName(whereDimension) {
848
- var regex = /^(T\d+|JEWEL)([A-Za-z]\d+[A-Za-z]?)$/;
849
- var subDimension = whereDimension.split('.').slice(-2).join('').toUpperCase();
850
- var match = subDimension.match(regex);
774
+ const regex = /^(T\d+|JEWEL)([A-Za-z]\d+[A-Za-z]?)$/;
775
+ const subDimension = whereDimension.split('.').slice(-2).join('').toUpperCase();
776
+ const match = subDimension.match(regex);
851
777
  if (match) {
852
- var terminalIndicator = match[1][0];
853
- var terminalName;
778
+ const terminalIndicator = match[1][0];
779
+ let terminalName;
854
780
  switch (terminalIndicator) {
855
781
  case 'T':
856
782
  terminalName = 'Terminal';
@@ -862,9 +788,9 @@ function getTerminalAndLevelName(whereDimension) {
862
788
  terminalName = 'Level';
863
789
  break;
864
790
  }
865
- var terminal = terminalName === 'Terminal' ? "".concat(terminalName, " ").concat(match[1][1]) : "".concat(terminalName);
866
- var levelIdentifier = match[2][0];
867
- var levelName;
791
+ const terminal = terminalName === 'Terminal' ? `${terminalName} ${match[1][1]}` : `${terminalName}`;
792
+ const levelIdentifier = match[2][0];
793
+ let levelName;
868
794
  switch (levelIdentifier) {
869
795
  case 'L':
870
796
  levelName = 'Level';
@@ -876,7 +802,7 @@ function getTerminalAndLevelName(whereDimension) {
876
802
  levelName = 'Level';
877
803
  break;
878
804
  }
879
- var level = "".concat(levelName, " ").concat(match[2].substring(1));
805
+ const level = `${levelName} ${match[2].substring(1)}`;
880
806
  return {
881
807
  Terminal: terminal,
882
808
  Level: level
@@ -885,7 +811,7 @@ function getTerminalAndLevelName(whereDimension) {
885
811
  return null; // Return null if the input doesn't match the expected format
886
812
  }
887
813
  function getWhereDimensionNameForPortal(portalDimension, whereDimension) {
888
- var terminalAndLevelName = getTerminalAndLevelName(whereDimension);
814
+ const terminalAndLevelName = getTerminalAndLevelName(whereDimension);
889
815
  if (terminalAndLevelName) {
890
816
  if (isCrossTerminalPortal(portalDimension)) {
891
817
  return terminalAndLevelName.Terminal;
@@ -901,10 +827,10 @@ function getWhereDimensionNameForPortal(portalDimension, whereDimension) {
901
827
  }
902
828
  function convertSecondsToMinutes(timeInSeconds) {
903
829
  // Calculate minutes
904
- var minutes = Math.floor(timeInSeconds / 60);
830
+ let minutes = Math.floor(timeInSeconds / 60);
905
831
 
906
832
  // Check for remaining seconds
907
- var remainingSeconds = timeInSeconds % 60;
833
+ const remainingSeconds = timeInSeconds % 60;
908
834
 
909
835
  // If there are remaining seconds and they are greater than 30, increment minutes
910
836
  if (remainingSeconds > 30) {
@@ -914,37 +840,37 @@ function convertSecondsToMinutes(timeInSeconds) {
914
840
  }
915
841
  function formatTime(value) {
916
842
  if (value < 60) return '<1 minute';
917
- return "~".concat(convertSecondsToMinutes(value), " ").concat(convertSecondsToMinutes(value) > 1 ? 'minutes' : 'minute');
843
+ return `~${convertSecondsToMinutes(value)} ${convertSecondsToMinutes(value) > 1 ? 'minutes' : 'minute'}`;
918
844
  }
919
845
  function generateInstructions(route) {
920
- var isFirstSegment = function isFirstSegment(index) {
846
+ const isFirstSegment = index => {
921
847
  if (index === 0 || index === 1 && route.segments[index - 1].maneuverType === ManeuverType.RouteOverview) return true;
922
848
  return false;
923
849
  };
924
- var getImmigrationInstruction = function getImmigrationInstruction(segment) {
850
+ const getImmigrationInstruction = segment => {
925
851
  if (segment.startEdge.whereDimension.toLowerCase().includes('l1')) {
926
852
  return 'Clear Arrival Immigration';
927
853
  }
928
854
  return 'Clear Departure Immigration';
929
855
  };
930
- for (var index = 0; index < route.segments.length; index += 1) {
931
- var rotueSegment = route.segments[index];
856
+ for (let index = 0; index < route.segments.length; index += 1) {
857
+ const rotueSegment = route.segments[index];
932
858
  rotueSegment.instructions = []; // clear instructions array
933
859
 
934
860
  if (rotueSegment.maneuverType === ManeuverType.RouteOverview) {
935
- var instruction = 'Overview';
861
+ const instruction = 'Overview';
936
862
  rotueSegment.instructions.push(instruction);
937
863
  }
938
864
  if (index > 0 && rotueSegment.maneuverType === ManeuverType.ChangeZone) {
939
- var _instruction = '';
865
+ let instruction = '';
940
866
  if (route.segments[index - 1].zone === _interfaces.Zone.Public && rotueSegment.zone === _interfaces.Zone.Transit) {
941
- _instruction = getImmigrationInstruction(rotueSegment);
867
+ instruction = getImmigrationInstruction(rotueSegment);
942
868
  } else if (route.segments[index - 1].zone === _interfaces.Zone.Transit && rotueSegment.zone === _interfaces.Zone.Public) {
943
- _instruction = 'Exit Baggage Claim Hall';
869
+ instruction = 'Exit Baggage Claim Hall';
944
870
  }
945
- rotueSegment.instructions.push(_instruction);
871
+ rotueSegment.instructions.push(instruction);
946
872
  } else if (rotueSegment.maneuverType === ManeuverType.ContinueStraight || rotueSegment.maneuverType === ManeuverType.PassThroughImmigration) {
947
- var postfix = rotueSegment.maneuverType === ManeuverType.ContinueStraight ? "Walk for ".concat(Math.ceil(rotueSegment.distance), " ").concat(route.distanceUnit) : getImmigrationInstruction(rotueSegment);
873
+ const postfix = rotueSegment.maneuverType === ManeuverType.ContinueStraight ? `Walk for ${Math.ceil(rotueSegment.distance)} ${route.distanceUnit}` : getImmigrationInstruction(rotueSegment);
948
874
 
949
875
  // 0th index if overview segment was not included, else 1st index
950
876
  // if (index === 0
@@ -957,9 +883,9 @@ function generateInstructions(route) {
957
883
  // } \n& ${postfix}`,
958
884
  // );
959
885
  // } else {
960
- var _instruction2 = void 0;
886
+ let instruction;
961
887
  if (route.segments[index - 1].maneuverType === ManeuverType.ChangeZone || route.segments[index - 1].maneuverType === ManeuverType.PassThroughImmigration) {
962
- _instruction2 = postfix;
888
+ instruction = postfix;
963
889
  // eslint-disable-next-line brace-style
964
890
  }
965
891
  // else if (route.segments[index - 1].maneuverType === ManeuverType.EnterPortal || route.segments[index - 1].maneuverType === ManeuverType.TravelPortal) {
@@ -994,36 +920,36 @@ function generateInstructions(route) {
994
920
  // // }
995
921
  // }
996
922
  else {
997
- _instruction2 = postfix;
923
+ instruction = postfix;
998
924
  }
999
- rotueSegment.instructions.push(_instruction2);
925
+ rotueSegment.instructions.push(instruction);
1000
926
  // }
1001
927
  } else if (rotueSegment.maneuverType === ManeuverType.Static) {
1002
928
  if (isFirstSegment(index)) {
1003
- rotueSegment.instructions.push("Start at ".concat(rotueSegment.startEdge.name));
929
+ rotueSegment.instructions.push(`Start at ${rotueSegment.startEdge.name}`);
1004
930
  }
1005
931
  if (index === route.segments.length - 1) {
1006
- rotueSegment.instructions.push("Arrive at ".concat(rotueSegment.endEdge.name));
932
+ rotueSegment.instructions.push(`Arrive at ${rotueSegment.endEdge.name}`);
1007
933
  }
1008
934
  } else if (rotueSegment.maneuverType === ManeuverType.EnterPortal) {
1009
- var _instruction3 = "Enter ".concat(rotueSegment.startEdge.name, " at ").concat(rotueSegment.startEdge.whereDimension.split('.').slice(-2).join(' ').toUpperCase());
935
+ let instruction = `Enter ${rotueSegment.startEdge.name} at ${rotueSegment.startEdge.whereDimension.split('.').slice(-2).join(' ').toUpperCase()}`;
1010
936
  if (isNonMovingPortalTaxonomy(rotueSegment.startEdge.whatDimension)) {
1011
- _instruction3 = "Continue to ".concat(getWhereDimensionNameForPortal(rotueSegment.startEdge.whatDimension, rotueSegment.endEdge.whereDimension));
1012
- rotueSegment.instructions.push(_instruction3);
937
+ instruction = `Continue to ${getWhereDimensionNameForPortal(rotueSegment.startEdge.whatDimension, rotueSegment.endEdge.whereDimension)}`;
938
+ rotueSegment.instructions.push(instruction);
1013
939
  } else if (isMovingPortalTaxonomy(rotueSegment.startEdge.whatDimension)) {
1014
- var nextRouteSegment = index + 1 <= route.segments.length - 1 ? route.segments[index + 1] : undefined;
940
+ const nextRouteSegment = index + 1 <= route.segments.length - 1 ? route.segments[index + 1] : undefined;
1015
941
  if (nextRouteSegment && nextRouteSegment.maneuverType === ManeuverType.TravelPortal) {
1016
942
  // push the current enter portal instruction and increment index, since we want to skip the iteration on TravelPortal segment
1017
- rotueSegment.instructions.push(_instruction3);
943
+ rotueSegment.instructions.push(instruction);
1018
944
  index += 1;
1019
- var name = getPortalName(nextRouteSegment.startEdge.whatDimension);
1020
- _instruction3 = "Take ".concat(name, " to ").concat(getWhereDimensionNameForPortal(rotueSegment.startEdge.whatDimension, rotueSegment.endEdge.whereDimension));
1021
- nextRouteSegment.instructions.push(_instruction3);
945
+ const name = getPortalName(nextRouteSegment.startEdge.whatDimension);
946
+ instruction = `Take ${name} to ${getWhereDimensionNameForPortal(rotueSegment.startEdge.whatDimension, rotueSegment.endEdge.whereDimension)}`;
947
+ nextRouteSegment.instructions.push(instruction);
1022
948
  if (rotueSegment.description) nextRouteSegment.instructions.push(rotueSegment.description);
1023
949
  } else {
1024
- var _name = getPortalName(rotueSegment.startEdge.whatDimension);
1025
- _instruction3 = "Take ".concat(_name, " to ").concat(getWhereDimensionNameForPortal(rotueSegment.startEdge.whatDimension, rotueSegment.endEdge.whereDimension));
1026
- rotueSegment.instructions.push(_instruction3);
950
+ const name = getPortalName(rotueSegment.startEdge.whatDimension);
951
+ instruction = `Take ${name} to ${getWhereDimensionNameForPortal(rotueSegment.startEdge.whatDimension, rotueSegment.endEdge.whereDimension)}`;
952
+ rotueSegment.instructions.push(instruction);
1027
953
  }
1028
954
  }
1029
955
  }