mobility-toolbox-js 2.0.0-beta.34 → 2.0.0-beta.37

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 (195) hide show
  1. package/README.md +14 -8
  2. package/api/RealtimeAPI.d.ts +6 -6
  3. package/api/RealtimeAPI.d.ts.map +1 -1
  4. package/api/RealtimeAPI.js +170 -197
  5. package/api/RealtimeAPI.test.d.ts +2 -0
  6. package/api/RealtimeAPI.test.d.ts.map +1 -0
  7. package/api/RealtimeAPI.test.js +67 -0
  8. package/api/RoutingAPI.d.ts +6 -2
  9. package/api/RoutingAPI.d.ts.map +1 -1
  10. package/api/RoutingAPI.js +8 -38
  11. package/api/RoutingAPI.test.d.ts +2 -0
  12. package/api/RoutingAPI.test.d.ts.map +1 -0
  13. package/api/RoutingAPI.test.js +29 -0
  14. package/api/StopsAPI.d.ts +1 -1
  15. package/api/StopsAPI.d.ts.map +1 -1
  16. package/api/StopsAPI.js +8 -40
  17. package/api/StopsAPI.test.d.ts +2 -0
  18. package/api/StopsAPI.test.d.ts.map +1 -0
  19. package/api/StopsAPI.test.js +26 -0
  20. package/api/index.d.ts +3 -4
  21. package/api/index.d.ts.map +1 -1
  22. package/api/index.js +3 -10
  23. package/api/typedefs.js +1 -0
  24. package/common/api/HttpAPI.d.ts +2 -2
  25. package/common/api/HttpAPI.d.ts.map +1 -1
  26. package/common/api/HttpAPI.js +21 -48
  27. package/common/api/HttpAPI.test.d.ts +2 -0
  28. package/common/api/HttpAPI.test.d.ts.map +1 -0
  29. package/common/api/HttpAPI.test.js +54 -0
  30. package/common/api/WebSocketAPI.d.ts +8 -4
  31. package/common/api/WebSocketAPI.d.ts.map +1 -1
  32. package/common/api/WebSocketAPI.js +125 -129
  33. package/common/api/WebSocketAPI.test.d.ts +2 -0
  34. package/common/api/WebSocketAPI.test.d.ts.map +1 -0
  35. package/common/api/WebSocketAPI.test.js +380 -0
  36. package/common/controls/Control.d.ts +5 -5
  37. package/common/controls/Control.d.ts.map +1 -1
  38. package/common/controls/Control.js +44 -77
  39. package/common/controls/Control.test.d.ts +2 -0
  40. package/common/controls/Control.test.d.ts.map +1 -0
  41. package/common/controls/Control.test.js +89 -0
  42. package/common/index.js +2 -18
  43. package/common/layers/Layer.d.ts +11 -11
  44. package/common/layers/Layer.d.ts.map +1 -1
  45. package/common/layers/Layer.js +70 -104
  46. package/common/layers/Layer.test.d.ts +2 -0
  47. package/common/layers/Layer.test.d.ts.map +1 -0
  48. package/common/layers/Layer.test.js +137 -0
  49. package/common/mixins/CopyrightMixin.js +23 -52
  50. package/common/mixins/MapboxLayerMixin.js +162 -204
  51. package/common/mixins/RealtimeLayerMixin.js +580 -635
  52. package/common/mixins/StopFinderMixin.d.ts +3 -3
  53. package/common/mixins/StopFinderMixin.d.ts.map +1 -1
  54. package/common/mixins/StopFinderMixin.js +115 -157
  55. package/common/mixins/UserInteractionsLayerMixin.js +142 -175
  56. package/common/mixins/UserInteractionsLayerMixin.test.d.ts +2 -0
  57. package/common/mixins/UserInteractionsLayerMixin.test.d.ts.map +1 -0
  58. package/common/mixins/UserInteractionsLayerMixin.test.js +214 -0
  59. package/common/styles/index.js +4 -24
  60. package/common/styles/realtimeDefaultStyle.d.ts.map +1 -1
  61. package/common/styles/realtimeDefaultStyle.js +67 -78
  62. package/common/styles/realtimeDelayStyle.js +4 -17
  63. package/common/styles/realtimeSimpleStyle.js +5 -7
  64. package/common/typedefs.js +1 -0
  65. package/common/utils/cleanStopTime.js +3 -5
  66. package/common/utils/compareDepartures.d.ts +1 -1
  67. package/common/utils/compareDepartures.d.ts.map +1 -1
  68. package/common/utils/compareDepartures.js +8 -11
  69. package/common/utils/createCanvas.js +3 -5
  70. package/common/utils/createTrackerFilters.d.ts +1 -1
  71. package/common/utils/createTrackerFilters.d.ts.map +1 -1
  72. package/common/utils/createTrackerFilters.js +22 -32
  73. package/common/utils/createTrackerFilters.test.d.ts +2 -0
  74. package/common/utils/createTrackerFilters.test.d.ts.map +1 -0
  75. package/common/utils/createTrackerFilters.test.js +79 -0
  76. package/common/utils/getLayersAsFlatArray.js +6 -8
  77. package/common/utils/getMapboxMapCopyrights.js +9 -11
  78. package/common/utils/getMapboxMapCopyrights.test.d.ts +2 -0
  79. package/common/utils/getMapboxMapCopyrights.test.d.ts.map +1 -0
  80. package/common/utils/getMapboxMapCopyrights.test.js +40 -0
  81. package/common/utils/getMapboxRender.js +12 -15
  82. package/common/utils/getMaplibreRender.js +10 -13
  83. package/common/utils/getRealtimeModeSuffix.js +2 -6
  84. package/common/utils/getUrlWithParams.js +5 -8
  85. package/common/utils/getVehiclePosition.js +20 -23
  86. package/common/utils/index.js +12 -37
  87. package/common/utils/removeDuplicate.d.ts +1 -1
  88. package/common/utils/removeDuplicate.d.ts.map +1 -1
  89. package/common/utils/removeDuplicate.js +6 -21
  90. package/common/utils/removeDuplicate.test.d.ts +2 -0
  91. package/common/utils/removeDuplicate.test.d.ts.map +1 -0
  92. package/common/utils/removeDuplicate.test.js +19 -0
  93. package/common/utils/renderTrajectories.js +31 -43
  94. package/common/utils/sortByDelay.js +4 -6
  95. package/common/utils/timeUtils.js +14 -24
  96. package/common/utils/timeUtils.test.d.ts +2 -0
  97. package/common/utils/timeUtils.test.d.ts.map +1 -0
  98. package/common/utils/timeUtils.test.js +10 -0
  99. package/common/utils/trackerConfig.js +27 -39
  100. package/common/utils/trackerConfig.test.d.ts +2 -0
  101. package/common/utils/trackerConfig.test.d.ts.map +1 -0
  102. package/common/utils/trackerConfig.test.js +23 -0
  103. package/iife.js +3 -5
  104. package/index.d.ts +4 -0
  105. package/index.js +9 -10
  106. package/mapbox/controls/CopyrightControl.d.ts +0 -1
  107. package/mapbox/controls/CopyrightControl.d.ts.map +1 -1
  108. package/mapbox/controls/CopyrightControl.js +18 -38
  109. package/mapbox/controls/index.js +1 -5
  110. package/mapbox/index.js +4 -20
  111. package/mapbox/layers/Layer.d.ts +1 -1
  112. package/mapbox/layers/Layer.d.ts.map +1 -1
  113. package/mapbox/layers/Layer.js +29 -71
  114. package/mapbox/layers/Layer.test.d.ts +2 -0
  115. package/mapbox/layers/Layer.test.d.ts.map +1 -0
  116. package/mapbox/layers/Layer.test.js +204 -0
  117. package/mapbox/layers/RealtimeLayer.d.ts +4 -4
  118. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -1
  119. package/mapbox/layers/RealtimeLayer.js +83 -125
  120. package/mapbox/layers/RealtimeLayer.test.d.ts +2 -0
  121. package/mapbox/layers/RealtimeLayer.test.d.ts.map +1 -0
  122. package/mapbox/layers/RealtimeLayer.test.js +10 -0
  123. package/mapbox/layers/index.js +2 -7
  124. package/mapbox/utils.js +19 -33
  125. package/mbt.js +59 -37
  126. package/mbt.js.map +2 -2
  127. package/mbt.min.js +10 -10
  128. package/mbt.min.js.map +2 -2
  129. package/ol/controls/CopyrightControl.js +26 -47
  130. package/ol/controls/CopyrightControl.test.d.ts +2 -0
  131. package/ol/controls/CopyrightControl.test.d.ts.map +1 -0
  132. package/ol/controls/CopyrightControl.test.js +177 -0
  133. package/ol/controls/RoutingControl.d.ts +6 -5
  134. package/ol/controls/RoutingControl.d.ts.map +1 -1
  135. package/ol/controls/RoutingControl.js +209 -270
  136. package/ol/controls/RoutingControl.test.d.ts +2 -0
  137. package/ol/controls/RoutingControl.test.d.ts.map +1 -0
  138. package/ol/controls/RoutingControl.test.js +150 -0
  139. package/ol/controls/StopFinderControl.js +9 -32
  140. package/ol/controls/StopFinderControl.test.d.ts +2 -0
  141. package/ol/controls/StopFinderControl.test.d.ts.map +1 -0
  142. package/ol/controls/StopFinderControl.test.js +49 -0
  143. package/ol/controls/index.js +3 -9
  144. package/ol/index.js +5 -21
  145. package/ol/layers/Layer.d.ts +1 -1
  146. package/ol/layers/Layer.d.ts.map +1 -1
  147. package/ol/layers/Layer.js +40 -72
  148. package/ol/layers/Layer.test.d.ts +2 -0
  149. package/ol/layers/Layer.test.d.ts.map +1 -0
  150. package/ol/layers/Layer.test.js +196 -0
  151. package/ol/layers/MapboxLayer.d.ts +7 -7
  152. package/ol/layers/MapboxLayer.d.ts.map +1 -1
  153. package/ol/layers/MapboxLayer.js +30 -66
  154. package/ol/layers/MapboxLayer.test.d.ts +2 -0
  155. package/ol/layers/MapboxLayer.test.d.ts.map +1 -0
  156. package/ol/layers/MapboxLayer.test.js +164 -0
  157. package/ol/layers/MapboxStyleLayer.d.ts +3 -3
  158. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -1
  159. package/ol/layers/MapboxStyleLayer.js +92 -135
  160. package/ol/layers/MapboxStyleLayer.test.d.ts +2 -0
  161. package/ol/layers/MapboxStyleLayer.test.d.ts.map +1 -0
  162. package/ol/layers/MapboxStyleLayer.test.js +232 -0
  163. package/ol/layers/MaplibreLayer.d.ts +1 -1
  164. package/ol/layers/MaplibreLayer.d.ts.map +1 -1
  165. package/ol/layers/MaplibreLayer.js +14 -48
  166. package/ol/layers/RealtimeLayer.d.ts +2 -2
  167. package/ol/layers/RealtimeLayer.d.ts.map +1 -1
  168. package/ol/layers/RealtimeLayer.js +111 -147
  169. package/ol/layers/RealtimeLayer.test.d.ts +2 -0
  170. package/ol/layers/RealtimeLayer.test.d.ts.map +1 -0
  171. package/ol/layers/RealtimeLayer.test.js +71 -0
  172. package/ol/layers/RoutingLayer.d.ts +2 -2
  173. package/ol/layers/RoutingLayer.d.ts.map +1 -1
  174. package/ol/layers/RoutingLayer.js +29 -61
  175. package/ol/layers/RoutingLayer.test.d.ts +2 -0
  176. package/ol/layers/RoutingLayer.test.d.ts.map +1 -0
  177. package/ol/layers/RoutingLayer.test.js +39 -0
  178. package/ol/layers/VectorLayer.d.ts +1 -1
  179. package/ol/layers/VectorLayer.d.ts.map +1 -1
  180. package/ol/layers/VectorLayer.js +14 -48
  181. package/ol/layers/VectorLayer.test.d.ts +2 -0
  182. package/ol/layers/VectorLayer.test.d.ts.map +1 -0
  183. package/ol/layers/VectorLayer.test.js +87 -0
  184. package/ol/layers/WMSLayer.d.ts +1 -1
  185. package/ol/layers/WMSLayer.d.ts.map +1 -1
  186. package/ol/layers/WMSLayer.js +34 -68
  187. package/ol/layers/WMSLayer.test.d.ts +2 -0
  188. package/ol/layers/WMSLayer.test.d.ts.map +1 -0
  189. package/ol/layers/WMSLayer.test.js +66 -0
  190. package/ol/layers/index.js +8 -19
  191. package/ol/styles/fullTrajectoryDelayStyle.js +11 -13
  192. package/ol/styles/fullTrajectoryStyle.js +16 -18
  193. package/ol/styles/index.js +2 -7
  194. package/package.json +5 -2
  195. package/setupTests.js +12 -14
@@ -1,52 +1,15 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
29
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
- if (ar || !(i in from)) {
31
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
- ar[i] = from[i];
33
- }
34
- }
35
- return to.concat(ar || Array.prototype.slice.call(from));
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- var ol_1 = require("ol");
39
- var geom_1 = require("ol/geom");
40
- var interaction_1 = require("ol/interaction");
41
- var Observable_1 = require("ol/Observable");
42
- var condition_1 = require("ol/events/condition");
43
- var format_1 = require("ol/format");
44
- var extent_1 = require("ol/extent");
45
- var proj_1 = require("ol/proj");
46
- var GeometryType_1 = require("ol/geom/GeometryType");
47
- var api_1 = require("../../api");
48
- var Control_1 = require("../../common/controls/Control");
49
- var RoutingLayer_1 = require("../layers/RoutingLayer");
1
+ import { Feature } from 'ol';
2
+ import { LineString, Point } from 'ol/geom';
3
+ import { Modify } from 'ol/interaction';
4
+ import { unByKey } from 'ol/Observable';
5
+ import { click } from 'ol/events/condition';
6
+ import { GeoJSON } from 'ol/format';
7
+ import { buffer } from 'ol/extent';
8
+ import { fromLonLat, toLonLat } from 'ol/proj';
9
+ import GeomType from 'ol/geom/GeometryType';
10
+ import { RoutingAPI } from '../../api';
11
+ import Control from '../../common/controls/Control';
12
+ import RoutingLayer from '../layers/RoutingLayer';
50
13
  // Examples for a single hop:
51
14
  // basel sbb a station named "basel sbb"
52
15
  // ZUE, station "Zürich HB" by its common abbreviation
@@ -55,25 +18,25 @@ var RoutingLayer_1 = require("../layers/RoutingLayer");
55
18
  // @47.37811,8.53935$4 track 4 in a station at position 47.37811, 8.53935
56
19
  // zürich hb@47.37811,8.53935$8 track 8 in station "Zürich HB" at position 47.37811, 8.53935
57
20
  /** @private */
58
- var REGEX_VIA_POINT = /^([^@$!\n]*)(@?([\d.]+),([\d.]+))?(\$?([a-zA-Z0-9]{0,2}))$/;
21
+ const REGEX_VIA_POINT = /^([^@$!\n]*)(@?([\d.]+),([\d.]+))?(\$?([a-zA-Z0-9]{0,2}))$/;
59
22
  // Examples for a single hop:
60
23
  //
61
24
  // 47.37811,8.53935 a position 47.37811, 8.53935
62
25
  /** @private */
63
- var REGEX_VIA_POINT_COORD = /^([\d.]+),([\d.]+)$/;
26
+ const REGEX_VIA_POINT_COORD = /^([\d.]+),([\d.]+)$/;
64
27
  // Examples for a single hop:
65
28
  //
66
29
  // !8596126 a station with id 8596126
67
30
  // !8596126$4 a station with id 8596126
68
31
  /** @private */
69
- var REGEX_VIA_POINT_STATION_ID = /^!([^$]*)(\$?([a-zA-Z0-9]{0,2}))$/;
32
+ const REGEX_VIA_POINT_STATION_ID = /^!([^$]*)(\$?([a-zA-Z0-9]{0,2}))$/;
70
33
  /** @private */
71
- var STOP_FETCH_ABORT_CONTROLLER_KEY = 'stop-fetch';
34
+ const STOP_FETCH_ABORT_CONTROLLER_KEY = 'stop-fetch';
72
35
  /** @private */
73
- var getFlatCoordinatesFromSegments = function (segmentArray) {
74
- var coords = [];
75
- segmentArray.forEach(function (seg) {
76
- coords.push.apply(coords, seg.getGeometry().getCoordinates());
36
+ const getFlatCoordinatesFromSegments = (segmentArray) => {
37
+ const coords = [];
38
+ segmentArray.forEach((seg) => {
39
+ coords.push(...seg.getGeometry().getCoordinates());
77
40
  });
78
41
  return coords;
79
42
  };
@@ -108,112 +71,106 @@ var getFlatCoordinatesFromSegments = function (segmentArray) {
108
71
  * @extends {Control}
109
72
  * @implements {RoutingInterface}
110
73
  */
111
- var RoutingControl = /** @class */ (function (_super) {
112
- __extends(RoutingControl, _super);
113
- function RoutingControl(options) {
114
- if (options === void 0) { options = {}; }
115
- var _this = _super.call(this, options) || this;
116
- Object.defineProperties(_this, {
74
+ class RoutingControl extends Control {
75
+ constructor(options = {}) {
76
+ super(options);
77
+ Object.defineProperties(this, {
117
78
  mot: {
118
- get: function () { return _this.get('mot'); },
119
- set: function (newMot) {
79
+ get: () => this.get('mot'),
80
+ set: (newMot) => {
120
81
  if (newMot) {
121
- _this.set('mot', newMot);
122
- if (_this.viaPoints) {
123
- _this.drawRoute();
82
+ this.set('mot', newMot);
83
+ if (this.viaPoints) {
84
+ this.drawRoute();
124
85
  }
125
86
  }
126
87
  },
127
88
  },
128
89
  loading: {
129
- get: function () { return _this.get('loading'); },
130
- set: function (newLoading) {
131
- _this.set('loading', newLoading);
90
+ get: () => this.get('loading'),
91
+ set: (newLoading) => {
92
+ this.set('loading', newLoading);
132
93
  },
133
94
  },
134
95
  modify: {
135
- get: function () { return _this.get('modify'); },
136
- set: function (modify) {
137
- _this.set('modify', modify);
96
+ get: () => this.get('modify'),
97
+ set: (modify) => {
98
+ this.set('modify', modify);
138
99
  },
139
100
  },
140
101
  });
141
102
  /** True if the control is requesting the backend. */
142
- _this.loading = false;
103
+ this.loading = false;
143
104
  /** @ignore */
144
- _this.graphs = options.graphs || [['osm', 0, 99]];
105
+ this.graphs = options.graphs || [['osm', 0, 99]];
145
106
  /** @ignore */
146
- _this.mot = options.mot || 'bus';
107
+ this.mot = options.mot || 'bus';
147
108
  /** @ignore */
148
- _this.modify = options.modify !== false;
109
+ this.modify = options.modify !== false;
149
110
  /** @ignore */
150
- _this.routingApiParams = options.routingApiParams || {};
111
+ this.routingApiParams = options.routingApiParams || {};
151
112
  /** @ignore */
152
- _this.useRawViaPoints = options.useRawViaPoints || false;
113
+ this.useRawViaPoints = options.useRawViaPoints || false;
153
114
  /** @ignore */
154
- _this.snapToClosestStation = options.snapToClosestStation || false;
115
+ this.snapToClosestStation = options.snapToClosestStation || false;
155
116
  /** @ignore */
156
- _this.cacheStationData = {};
117
+ this.cacheStationData = {};
157
118
  /** @ignore */
158
- _this.abortControllers = [];
119
+ this.abortControllers = [];
159
120
  /** @ignore */
160
- _this.apiKey = options.apiKey;
121
+ this.apiKey = options.apiKey;
161
122
  /** @ignore */
162
- _this.stopsApiKey = options.stopsApiKey || _this.apiKey;
123
+ this.stopsApiKey = options.stopsApiKey || this.apiKey;
163
124
  /** @ignore */
164
- _this.segments = [];
125
+ this.segments = [];
165
126
  /** @ignore */
166
- _this.stopsApiUrl = options.stopsApiUrl || 'https://api.geops.io/stops/v1/';
127
+ this.stopsApiUrl = options.stopsApiUrl || 'https://api.geops.io/stops/v1/';
167
128
  /** @ignore */
168
- _this.api = new api_1.RoutingAPI(__assign({}, options));
129
+ this.api = new RoutingAPI(Object.assign({}, options));
169
130
  /** @ignore */
170
- _this.routingLayer =
131
+ this.routingLayer =
171
132
  options.routingLayer ||
172
- new RoutingLayer_1.default({
133
+ new RoutingLayer({
173
134
  name: 'routing-layer',
174
135
  style: options.style,
175
136
  });
176
137
  /** @ignore */
177
- _this.onRouteError =
138
+ this.onRouteError =
178
139
  options.onRouteError ||
179
- (function (error) {
180
- _this.dispatchEvent({
140
+ ((error) => {
141
+ this.dispatchEvent({
181
142
  type: 'change:route',
182
- target: _this,
143
+ target: this,
183
144
  });
184
- _this.reset();
145
+ this.reset();
185
146
  // eslint-disable-next-line no-console
186
147
  console.error(error);
187
148
  });
188
149
  /** @ignore */
189
- _this.viaPoints = [];
150
+ this.viaPoints = [];
190
151
  /** @ignore */
191
- _this.onMapClick = _this.onMapClick.bind(_this);
152
+ this.onMapClick = this.onMapClick.bind(this);
192
153
  /** @ignore */
193
- _this.onModifyEnd = _this.onModifyEnd.bind(_this);
154
+ this.onModifyEnd = this.onModifyEnd.bind(this);
194
155
  /** @ignore */
195
- _this.onModifyStart = _this.onModifyStart.bind(_this);
156
+ this.onModifyStart = this.onModifyStart.bind(this);
196
157
  /** @ignore */
197
- _this.apiChangeListener = function () { return _this.drawRoute(); };
158
+ this.apiChangeListener = () => this.drawRoute();
198
159
  /** @ignore */
199
- _this.createModifyInteraction();
200
- return _this;
160
+ this.createModifyInteraction();
201
161
  }
202
162
  /**
203
163
  * Calculate at which resolutions corresponds each generalizations.
204
164
  *
205
165
  * @private
206
166
  */
207
- RoutingControl.getGraphsResolutions = function (graphs, map) {
208
- var view = map.getView();
209
- return graphs.map(function (_a) {
210
- var minZoom = _a[1], maxZoom = _a[2];
211
- return [
212
- view.getResolutionForZoom(minZoom),
213
- view.getResolutionForZoom(maxZoom || minZoom + 1),
214
- ];
215
- });
216
- };
167
+ static getGraphsResolutions(graphs, map) {
168
+ const view = map.getView();
169
+ return graphs.map(([, minZoom, maxZoom]) => [
170
+ view.getResolutionForZoom(minZoom),
171
+ view.getResolutionForZoom(maxZoom || minZoom + 1),
172
+ ]);
173
+ }
217
174
  /**
218
175
  * Adds/Replaces a viaPoint to the viaPoints array and redraws route:
219
176
  * Adds a viaPoint at end of array by default.
@@ -224,9 +181,7 @@ var RoutingControl = /** @class */ (function (_super) {
224
181
  * @param {number} [index=-1] Integer representing the index of the added viaPoint. If not specified, the viaPoint is added at the end of the array.
225
182
  * @param {number} [overwrite=0] Marks the number of viaPoints that are removed at the specified index on add.
226
183
  */
227
- RoutingControl.prototype.addViaPoint = function (coordinatesOrString, index, overwrite) {
228
- if (index === void 0) { index = -1; }
229
- if (overwrite === void 0) { overwrite = 0; }
184
+ addViaPoint(coordinatesOrString, index = -1, overwrite = 0) {
230
185
  /* Add/Insert/Overwrite viapoint and redraw route */
231
186
  this.viaPoints.splice(index === -1 ? this.viaPoints.length : index, overwrite, coordinatesOrString);
232
187
  this.drawRoute();
@@ -234,14 +189,13 @@ var RoutingControl = /** @class */ (function (_super) {
234
189
  type: 'change:route',
235
190
  target: this,
236
191
  });
237
- };
192
+ }
238
193
  /**
239
194
  * Removes a viaPoint at the passed array index and redraws route
240
195
  * By default the last viaPoint is removed.
241
196
  * @param {number} index Integer representing the index of the viaPoint to delete.
242
197
  */
243
- RoutingControl.prototype.removeViaPoint = function (index) {
244
- if (index === void 0) { index = this.viaPoints.length - 1; }
198
+ removeViaPoint(index = this.viaPoints.length - 1) {
245
199
  /* Remove viapoint and redraw route */
246
200
  if (this.viaPoints.length && this.viaPoints[index]) {
247
201
  this.viaPoints.splice(index, 1);
@@ -251,23 +205,23 @@ var RoutingControl = /** @class */ (function (_super) {
251
205
  type: 'change:route',
252
206
  target: this,
253
207
  });
254
- };
208
+ }
255
209
  /**
256
210
  * Replaces the current viaPoints with a new coordinate array.
257
211
  * @param {Array<Array<number>>} coordinateArray Array of nested coordinates
258
212
  */
259
- RoutingControl.prototype.setViaPoints = function (coordinateArray) {
260
- this.viaPoints = __spreadArray([], coordinateArray, true);
213
+ setViaPoints(coordinateArray) {
214
+ this.viaPoints = [...coordinateArray];
261
215
  this.drawRoute();
262
216
  this.dispatchEvent({
263
217
  type: 'change:route',
264
218
  target: this,
265
219
  });
266
- };
220
+ }
267
221
  /**
268
222
  * Removes all viaPoints, clears the source and triggers a change event
269
223
  */
270
- RoutingControl.prototype.reset = function () {
224
+ reset() {
271
225
  // Clear viaPoints and source
272
226
  this.abortRequests();
273
227
  this.viaPoints = [];
@@ -276,28 +230,26 @@ var RoutingControl = /** @class */ (function (_super) {
276
230
  type: 'change:route',
277
231
  target: this,
278
232
  });
279
- };
233
+ }
280
234
  /**
281
235
  * Aborts viapoint and route requests
282
236
  * @private
283
237
  */
284
- RoutingControl.prototype.abortRequests = function () {
285
- var _this = this;
238
+ abortRequests() {
286
239
  var _a;
287
240
  // Abort Routing API requests
288
- this.graphs.forEach(function (_a) {
289
- var graph = _a[0];
290
- if (_this.abortControllers[graph]) {
291
- _this.abortControllers[graph].abort();
241
+ this.graphs.forEach(([graph]) => {
242
+ if (this.abortControllers[graph]) {
243
+ this.abortControllers[graph].abort();
292
244
  }
293
- _this.abortControllers[graph] = new AbortController();
245
+ this.abortControllers[graph] = new AbortController();
294
246
  });
295
247
  // Abort Stops API requests
296
248
  (_a = this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]) === null || _a === void 0 ? void 0 : _a.abort();
297
249
  this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY] =
298
250
  new AbortController();
299
251
  this.loading = false;
300
- };
252
+ }
301
253
  /**
302
254
  * Draws route on map using an array of coordinates:
303
255
  * If a single coordinate is passed a single point feature is added to map.
@@ -305,8 +257,7 @@ var RoutingControl = /** @class */ (function (_super) {
305
257
  * the route using the passed coordinates and the current mot.
306
258
  * @private
307
259
  */
308
- RoutingControl.prototype.drawRoute = function () {
309
- var _this = this;
260
+ drawRoute() {
310
261
  /* Calls RoutingAPI to draw a route using the viaPoints array */
311
262
  this.abortRequests();
312
263
  this.routingLayer.olLayer.getSource().clear();
@@ -317,92 +268,87 @@ var RoutingControl = /** @class */ (function (_super) {
317
268
  // Add point for first node
318
269
  return this.drawViaPoint(this.viaPoints[0], 0, this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]);
319
270
  }
320
- var formattedViaPoints = this.viaPoints.map(function (viaPoint) {
271
+ const formattedViaPoints = this.viaPoints.map((viaPoint) => {
321
272
  if (Array.isArray(viaPoint)) {
322
- var projection = _this.map.getView().getProjection();
273
+ const projection = this.map.getView().getProjection();
323
274
  // viaPoint is a coordinate
324
275
  // Coordinates need to be reversed as required by the backend RoutingAPI
325
- var _a = (0, proj_1.toLonLat)(viaPoint, projection), lon = _a[0], lat = _a[1];
326
- return _this.snapToClosestStation ? ["@".concat(lat), lon] : [lat, lon];
276
+ const [lon, lat] = toLonLat(viaPoint, projection);
277
+ return this.snapToClosestStation ? [`@${lat}`, lon] : [lat, lon];
327
278
  }
328
279
  // viaPoint is a string to use as it is
329
- return _this.useRawViaPoints ? viaPoint : "!".concat(viaPoint);
280
+ return this.useRawViaPoints ? viaPoint : `!${viaPoint}`;
330
281
  });
331
282
  this.loading = true;
332
283
  // Clear source
333
284
  this.routingLayer.olLayer.getSource().clear();
334
285
  // Create point features for the viaPoints
335
- this.viaPoints.forEach(function (viaPoint, idx) {
336
- return _this.drawViaPoint(viaPoint, idx, _this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]);
337
- });
338
- return Promise.all(this.graphs.map(function (_a, index) {
339
- var graph = _a[0];
340
- var signal = _this.abortControllers[graph].signal;
341
- return _this.api
342
- .route(__assign({ graph: graph, via: "".concat(formattedViaPoints.join('|')), mot: "".concat(_this.mot), 'resolve-hops': false, elevation: false, 'coord-radius': 100.0, 'coord-punish': 1000.0 }, _this.routingApiParams), { signal: signal })
343
- .then(function (featureCollection) {
344
- _this.segments = _this.format.readFeatures(featureCollection);
345
- if (_this.mot === 'foot') {
286
+ this.viaPoints.forEach((viaPoint, idx) => this.drawViaPoint(viaPoint, idx, this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]));
287
+ return Promise.all(this.graphs.map(([graph], index) => {
288
+ const { signal } = this.abortControllers[graph];
289
+ return this.api
290
+ .route(Object.assign({ graph, via: `${formattedViaPoints.join('|')}`, mot: `${this.mot}`, 'resolve-hops': false, elevation: false, 'coord-radius': 100.0, 'coord-punish': 1000.0 }, this.routingApiParams), { signal })
291
+ .then((featureCollection) => {
292
+ this.segments = this.format.readFeatures(featureCollection);
293
+ if (this.mot === 'foot') {
346
294
  // Extract unique values from viaPoint target value
347
- var uniqueVias = _this.segments.reduce(function (resultVias, currentFeat) {
348
- var segTrg = currentFeat.get('trg');
349
- return resultVias.find(function (via) { return via[0] === segTrg[0] && via[1] === segTrg[1]; })
295
+ const uniqueVias = this.segments.reduce((resultVias, currentFeat) => {
296
+ const segTrg = currentFeat.get('trg');
297
+ return resultVias.find((via) => via[0] === segTrg[0] && via[1] === segTrg[1])
350
298
  ? resultVias
351
- : __spreadArray(__spreadArray([], resultVias, true), [segTrg], false);
299
+ : [...resultVias, segTrg];
352
300
  }, []);
353
301
  // Create LineString features from segments with same unique value
354
- _this.segments = uniqueVias.map(function (via) {
355
- var viaSegments = _this.segments.filter(function (seg) {
356
- var segTrg = seg.get('trg');
302
+ this.segments = uniqueVias.map((via) => {
303
+ const viaSegments = this.segments.filter((seg) => {
304
+ const segTrg = seg.get('trg');
357
305
  return segTrg[0] === via[0] && segTrg[1] === via[1];
358
306
  });
359
- var coords = getFlatCoordinatesFromSegments(viaSegments);
360
- return new ol_1.Feature({
361
- geometry: new geom_1.LineString(coords),
307
+ const coords = getFlatCoordinatesFromSegments(viaSegments);
308
+ return new Feature({
309
+ geometry: new LineString(coords),
362
310
  });
363
311
  });
364
312
  }
365
313
  // Create the new route. This route will be modifiable by the Modifiy interaction.
366
- var coords = getFlatCoordinatesFromSegments(_this.segments);
367
- var routeFeature = new ol_1.Feature({
368
- geometry: new geom_1.LineString(coords),
314
+ const coords = getFlatCoordinatesFromSegments(this.segments);
315
+ const routeFeature = new Feature({
316
+ geometry: new LineString(coords),
369
317
  });
370
318
  routeFeature.set('graph', graph);
371
- routeFeature.set('mot', _this.mot);
372
- routeFeature.set('minResolution', _this.graphsResolutions[index][0]);
373
- routeFeature.set('maxResolution', _this.graphsResolutions[index][1]);
374
- _this.routingLayer.olLayer.getSource().addFeature(routeFeature);
375
- _this.loading = false;
319
+ routeFeature.set('mot', this.mot);
320
+ routeFeature.set('minResolution', this.graphsResolutions[index][0]);
321
+ routeFeature.set('maxResolution', this.graphsResolutions[index][1]);
322
+ this.routingLayer.olLayer.getSource().addFeature(routeFeature);
323
+ this.loading = false;
376
324
  })
377
- .catch(function (error) {
325
+ .catch((error) => {
378
326
  if (error.name === 'AbortError') {
379
327
  // Ignore abort error
380
328
  return;
381
329
  }
382
- _this.segments = [];
330
+ this.segments = [];
383
331
  // Dispatch error event and execute error function
384
- _this.dispatchEvent({
332
+ this.dispatchEvent({
385
333
  type: 'error',
386
- target: _this,
334
+ target: this,
387
335
  });
388
- _this.onRouteError(error, _this);
389
- _this.loading = false;
336
+ this.onRouteError(error, this);
337
+ this.loading = false;
390
338
  });
391
339
  }));
392
- };
340
+ }
393
341
  /**
394
342
  * Draw a via point. This function can parse all the possibilitiies
395
343
  *
396
344
  * @private
397
345
  */
398
- RoutingControl.prototype.drawViaPoint = function (viaPoint, idx, abortController) {
399
- var _a, _b;
400
- var _this = this;
401
- var pointFeature = new ol_1.Feature();
346
+ drawViaPoint(viaPoint, idx, abortController) {
347
+ const pointFeature = new Feature();
402
348
  pointFeature.set('viaPointIdx', idx);
403
349
  // The via point is a coordinate using the current map's projection
404
350
  if (Array.isArray(viaPoint)) {
405
- pointFeature.setGeometry(new geom_1.Point(viaPoint));
351
+ pointFeature.setGeometry(new Point(viaPoint));
406
352
  this.routingLayer.olLayer.getSource().addFeature(pointFeature);
407
353
  return Promise.resolve(pointFeature);
408
354
  }
@@ -411,36 +357,36 @@ var RoutingControl = /** @class */ (function (_super) {
411
357
  // !8596126 a station with id 8596126
412
358
  // !8596126$4 a station with id 8596126
413
359
  if (!this.useRawViaPoints || REGEX_VIA_POINT_STATION_ID.test(viaPoint)) {
414
- var stationId = void 0;
415
- var track_1;
360
+ let stationId;
361
+ let track;
416
362
  if (this.useRawViaPoints) {
417
- _a = REGEX_VIA_POINT_STATION_ID.exec(viaPoint), stationId = _a[1], track_1 = _a[3];
363
+ [, stationId, , track] = REGEX_VIA_POINT_STATION_ID.exec(viaPoint);
418
364
  }
419
365
  else {
420
- _b = viaPoint.split('$'), stationId = _b[0], track_1 = _b[1];
366
+ [stationId, track] = viaPoint.split('$');
421
367
  }
422
- return fetch("".concat(this.stopsApiUrl, "lookup/").concat(stationId, "?key=").concat(this.stopsApiKey), { signal: abortController.signal })
423
- .then(function (res) { return res.json(); })
424
- .then(function (stationData) {
425
- var coordinates = stationData.features[0].geometry.coordinates;
426
- _this.cacheStationData[viaPoint] = (0, proj_1.fromLonLat)(coordinates);
427
- pointFeature.set('viaPointTrack', track_1);
428
- pointFeature.setGeometry(new geom_1.Point((0, proj_1.fromLonLat)(coordinates)));
429
- _this.routingLayer.olLayer.getSource().addFeature(pointFeature);
368
+ return fetch(`${this.stopsApiUrl}lookup/${stationId}?key=${this.stopsApiKey}`, { signal: abortController.signal })
369
+ .then((res) => res.json())
370
+ .then((stationData) => {
371
+ const { coordinates } = stationData.features[0].geometry;
372
+ this.cacheStationData[viaPoint] = fromLonLat(coordinates);
373
+ pointFeature.set('viaPointTrack', track);
374
+ pointFeature.setGeometry(new Point(fromLonLat(coordinates)));
375
+ this.routingLayer.olLayer.getSource().addFeature(pointFeature);
430
376
  return pointFeature;
431
377
  })
432
- .catch(function (error) {
378
+ .catch((error) => {
433
379
  if (error.name === 'AbortError') {
434
380
  // Ignore abort error
435
381
  return;
436
382
  }
437
383
  // Dispatch error event and execute error function
438
- _this.dispatchEvent({
384
+ this.dispatchEvent({
439
385
  type: 'error',
440
- target: _this,
386
+ target: this,
441
387
  });
442
- _this.onRouteError(error, _this);
443
- _this.loading = false;
388
+ this.onRouteError(error, this);
389
+ this.loading = false;
444
390
  });
445
391
  }
446
392
  // Only when this.useRawViaPoints is true.
@@ -448,9 +394,9 @@ var RoutingControl = /** @class */ (function (_super) {
448
394
  //
449
395
  // 47.37811,8.53935 a position 47.37811, 8.53935
450
396
  if (this.useRawViaPoints && REGEX_VIA_POINT_COORD.test(viaPoint)) {
451
- var _c = REGEX_VIA_POINT_COORD.exec(viaPoint), lat_1 = _c[0], lon_1 = _c[1];
452
- var coordinates = (0, proj_1.fromLonLat)([parseFloat(lon_1), parseFloat(lat_1)], this.map.getView().getProjection());
453
- pointFeature.setGeometry(new geom_1.Point(coordinates));
397
+ const [lat, lon] = REGEX_VIA_POINT_COORD.exec(viaPoint);
398
+ const coordinates = fromLonLat([parseFloat(lon), parseFloat(lat)], this.map.getView().getProjection());
399
+ pointFeature.setGeometry(new Point(coordinates));
454
400
  this.routingLayer.olLayer.getSource().addFeature(pointFeature);
455
401
  return Promise.resolve(pointFeature);
456
402
  }
@@ -462,49 +408,49 @@ var RoutingControl = /** @class */ (function (_super) {
462
408
  // @47.37811,8.53935 a station at position 47.37811, 8.53935
463
409
  // @47.37811,8.53935$4 track 4 in a station at position 47.37811, 8.53935
464
410
  // zürich hb@47.37811,8.53935$8 track 8 in station "Zürich HB" at position 47.37811, 8.53935
465
- var _d = REGEX_VIA_POINT.exec(viaPoint), stationName = _d[1], lat = _d[3], lon = _d[4], track = _d[6];
411
+ const [, stationName, , lat, lon, , track] = REGEX_VIA_POINT.exec(viaPoint);
466
412
  if (lon && lat) {
467
- var coordinates = (0, proj_1.fromLonLat)([parseFloat(lon), parseFloat(lat)], this.map.getView().getProjection());
413
+ const coordinates = fromLonLat([parseFloat(lon), parseFloat(lat)], this.map.getView().getProjection());
468
414
  pointFeature.set('viaPointTrack', track);
469
- pointFeature.setGeometry(new geom_1.Point(coordinates));
415
+ pointFeature.setGeometry(new Point(coordinates));
470
416
  this.routingLayer.olLayer.getSource().addFeature(pointFeature);
471
417
  return Promise.resolve(pointFeature);
472
418
  }
473
419
  if (stationName) {
474
- return fetch("".concat(this.stopsApiUrl, "?key=").concat(this.stopsApiKey, "&q=").concat(stationName, "&limit=1"), { signal: abortController.signal })
475
- .then(function (res) { return res.json(); })
476
- .then(function (stationData) {
477
- var coordinates = stationData.features[0].geometry.coordinates;
478
- _this.cacheStationData[viaPoint] = (0, proj_1.fromLonLat)(coordinates);
420
+ return fetch(`${this.stopsApiUrl}?key=${this.stopsApiKey}&q=${stationName}&limit=1`, { signal: abortController.signal })
421
+ .then((res) => res.json())
422
+ .then((stationData) => {
423
+ const { coordinates } = stationData.features[0].geometry;
424
+ this.cacheStationData[viaPoint] = fromLonLat(coordinates);
479
425
  pointFeature.set('viaPointTrack', track);
480
- pointFeature.setGeometry(new geom_1.Point((0, proj_1.fromLonLat)(coordinates)));
481
- _this.routingLayer.olLayer.getSource().addFeature(pointFeature);
426
+ pointFeature.setGeometry(new Point(fromLonLat(coordinates)));
427
+ this.routingLayer.olLayer.getSource().addFeature(pointFeature);
482
428
  return pointFeature;
483
429
  })
484
- .catch(function (error) {
430
+ .catch((error) => {
485
431
  // Dispatch error event and execute error function
486
- _this.dispatchEvent({
432
+ this.dispatchEvent({
487
433
  type: 'error',
488
- target: _this,
434
+ target: this,
489
435
  });
490
- _this.onRouteError(error, _this);
491
- _this.loading = false;
436
+ this.onRouteError(error, this);
437
+ this.loading = false;
492
438
  return null;
493
439
  });
494
440
  }
495
441
  return Promise.resolve(null);
496
- };
442
+ }
497
443
  /**
498
444
  * Used on click on map while control is active:
499
445
  * By default adds a viaPoint to the end of array.
500
446
  * If an existing viaPoint is clicked removes the clicked viaPoint.
501
447
  * @private
502
448
  */
503
- RoutingControl.prototype.onMapClick = function (e) {
504
- var feats = e.target.getFeaturesAtPixel(e.pixel);
505
- var viaPoint = feats.find(function (feat) {
449
+ onMapClick(e) {
450
+ const feats = e.target.getFeaturesAtPixel(e.pixel);
451
+ const viaPoint = feats.find((feat) => {
506
452
  var _a;
507
- return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === GeometryType_1.default.POINT &&
453
+ return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === GeomType.POINT &&
508
454
  feat.get('viaPointIdx') !== undefined;
509
455
  });
510
456
  if (viaPoint) {
@@ -513,48 +459,46 @@ var RoutingControl = /** @class */ (function (_super) {
513
459
  return;
514
460
  }
515
461
  this.addViaPoint(e.coordinate);
516
- };
462
+ }
517
463
  /**
518
464
  * Used on start of the modify interaction. Stores relevant data
519
465
  * in this.initialRouteDrag object
520
466
  * @private
521
467
  */
522
- RoutingControl.prototype.onModifyStart = function (evt) {
468
+ onModifyStart(evt) {
523
469
  // When modify start, we search the index of the segment that is modifying.
524
- var segmentIndex = -1;
525
- var route = evt.features
470
+ let segmentIndex = -1;
471
+ const route = evt.features
526
472
  .getArray()
527
- .find(function (feat) { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === GeometryType_1.default.LINE_STRING; });
473
+ .find((feat) => { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === GeomType.LINE_STRING; });
528
474
  // Find the segment index that is being modified
529
475
  if (route) {
530
476
  // We use a buff extent to fix floating issues , see https://github.com/openlayers/openlayers/issues/7130#issuecomment-535856422
531
- var closestExtent_1 = (0, extent_1.buffer)(new geom_1.Point(route.getGeometry().getClosestPoint(evt.mapBrowserEvent.coordinate)).getExtent(), 0.001);
532
- segmentIndex = this.segments.findIndex(function (segment) {
533
- return segment.getGeometry().intersectsExtent(closestExtent_1);
534
- });
477
+ const closestExtent = buffer(new Point(route.getGeometry().getClosestPoint(evt.mapBrowserEvent.coordinate)).getExtent(), 0.001);
478
+ segmentIndex = this.segments.findIndex((segment) => segment.getGeometry().intersectsExtent(closestExtent));
535
479
  }
536
480
  // Find the viaPoint that is being modified
537
- var viaPoint = (evt.features
481
+ const viaPoint = (evt.features
538
482
  .getArray()
539
- .filter(function (feat) { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === GeometryType_1.default.POINT; }) ||
483
+ .filter((feat) => { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === GeomType.POINT; }) ||
540
484
  [])[0];
541
485
  // Write object with modify info
542
486
  /** @ignore */
543
487
  this.initialRouteDrag = {
544
- viaPoint: viaPoint,
488
+ viaPoint,
545
489
  oldRoute: route && route.clone(),
546
- segmentIndex: segmentIndex,
490
+ segmentIndex,
547
491
  };
548
- };
492
+ }
549
493
  /**
550
494
  * Used on end of the modify interaction. Resolves feature modification:
551
495
  * Line drag creates new viaPoint at the final coordinate of drag.
552
496
  * Point drag replaces old viaPoint.
553
497
  * @private
554
498
  */
555
- RoutingControl.prototype.onModifyEnd = function (evt) {
556
- var coord = evt.mapBrowserEvent.coordinate;
557
- var _a = this.initialRouteDrag, oldRoute = _a.oldRoute, viaPoint = _a.viaPoint, segmentIndex = _a.segmentIndex;
499
+ onModifyEnd(evt) {
500
+ const coord = evt.mapBrowserEvent.coordinate;
501
+ const { oldRoute, viaPoint, segmentIndex } = this.initialRouteDrag;
558
502
  // If viaPoint is being relocated overwrite the old viaPoint
559
503
  if (viaPoint) {
560
504
  return this.addViaPoint(coord, viaPoint.get('viaPointIdx'), 1);
@@ -569,54 +513,50 @@ var RoutingControl = /** @class */ (function (_super) {
569
513
  }
570
514
  // Insert new viaPoint at the modified segment index + 1
571
515
  return this.addViaPoint(coord, segmentIndex + 1);
572
- };
516
+ }
573
517
  /**
574
518
  * Define a default element.
575
519
  *
576
520
  * @private
577
521
  */
578
- RoutingControl.prototype.createDefaultElement = function () {
579
- var _this = this;
522
+ createDefaultElement() {
580
523
  /** @ignore */
581
524
  this.element = document.createElement('button');
582
525
  this.element.id = 'ol-toggle-routing';
583
526
  this.element.innerHTML = 'Toggle Route Control';
584
- this.element.onclick = function () {
585
- return _this.active ? _this.deactivate() : _this.activate();
586
- };
527
+ this.element.onclick = () => this.active ? this.deactivate() : this.activate();
587
528
  Object.assign(this.element.style, {
588
529
  position: 'absolute',
589
530
  right: '10px',
590
531
  top: '10px',
591
532
  });
592
- };
533
+ }
593
534
  /**
594
535
  * Create the interaction used to modify vertexes of features.
595
536
  * @private
596
537
  */
597
- RoutingControl.prototype.createModifyInteraction = function () {
598
- var _this = this;
538
+ createModifyInteraction() {
599
539
  /**
600
540
  * @type {ol.interaction.Modify}
601
541
  * @private
602
542
  */
603
543
  // Define and add modify interaction
604
- this.modifyInteraction = new interaction_1.Modify({
544
+ this.modifyInteraction = new Modify({
605
545
  source: this.routingLayer.olLayer.getSource(),
606
546
  pixelTolerance: 4,
607
547
  hitDetection: this.routingLayer.olLayer,
608
- deleteCondition: function (e) {
609
- var feats = e.target.getFeaturesAtPixel(e.pixel, {
548
+ deleteCondition: (e) => {
549
+ const feats = e.target.getFeaturesAtPixel(e.pixel, {
610
550
  hitTolerance: 5,
611
551
  });
612
- var viaPoint = feats.find(function (feat) {
552
+ const viaPoint = feats.find((feat) => {
613
553
  var _a;
614
- return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === GeometryType_1.default.POINT &&
554
+ return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === GeomType.POINT &&
615
555
  feat.get('index');
616
556
  });
617
- if ((0, condition_1.click)(e) && viaPoint) {
557
+ if (click(e) && viaPoint) {
618
558
  // Remove node & viaPoint if an existing viaPoint was clicked
619
- _this.removeViaPoint(viaPoint.get('index'));
559
+ this.removeViaPoint(viaPoint.get('index'));
620
560
  return true;
621
561
  }
622
562
  return false;
@@ -625,31 +565,31 @@ var RoutingControl = /** @class */ (function (_super) {
625
565
  this.modifyInteraction.on('modifystart', this.onModifyStart);
626
566
  this.modifyInteraction.on('modifyend', this.onModifyEnd);
627
567
  this.modifyInteraction.setActive(false);
628
- };
568
+ }
629
569
  /**
630
570
  * Add click listener to map.
631
571
  * @private
632
572
  */
633
- RoutingControl.prototype.addListeners = function () {
573
+ addListeners() {
634
574
  if (!this.modify) {
635
575
  return;
636
576
  }
637
577
  this.removeListeners();
638
578
  /** @ignore */
639
579
  this.onMapClickKey = this.map.on('singleclick', this.onMapClick);
640
- };
580
+ }
641
581
  /**
642
582
  * Remove click listener from map.
643
583
  * @private
644
584
  */
645
- RoutingControl.prototype.removeListeners = function () {
646
- (0, Observable_1.unByKey)(this.onMapClickKey);
647
- };
648
- RoutingControl.prototype.activate = function () {
649
- _super.prototype.activate.call(this);
585
+ removeListeners() {
586
+ unByKey(this.onMapClickKey);
587
+ }
588
+ activate() {
589
+ super.activate();
650
590
  if (this.map) {
651
591
  /** @ignore */
652
- this.format = new format_1.GeoJSON({
592
+ this.format = new GeoJSON({
653
593
  featureProjection: this.map.getView().getProjection(),
654
594
  });
655
595
  /** @ignore */
@@ -664,11 +604,11 @@ var RoutingControl = /** @class */ (function (_super) {
664
604
  }
665
605
  else {
666
606
  // fall back to some default values if map is not available
667
- this.format = new format_1.GeoJSON({ featureProjection: 'EPSG:3857' });
607
+ this.format = new GeoJSON({ featureProjection: 'EPSG:3857' });
668
608
  this.graphsResolutions = this.graphs;
669
609
  }
670
- };
671
- RoutingControl.prototype.deactivate = function () {
610
+ }
611
+ deactivate() {
672
612
  if (this.map) {
673
613
  // Remove modify interaction, RoutingLayer, listeners and viaPoints
674
614
  this.routingLayer.detachFromMap(this.map);
@@ -676,8 +616,7 @@ var RoutingControl = /** @class */ (function (_super) {
676
616
  this.removeListeners();
677
617
  this.reset();
678
618
  }
679
- _super.prototype.deactivate.call(this);
680
- };
681
- return RoutingControl;
682
- }(Control_1.default));
683
- exports.default = RoutingControl;
619
+ super.deactivate();
620
+ }
621
+ }
622
+ export default RoutingControl;