mobility-toolbox-js 3.0.1-beta.0 → 3.0.1-beta.2

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 (78) hide show
  1. package/README.md +11 -3
  2. package/api/HttpAPI.js +1 -3
  3. package/api/RealtimeAPI.d.ts +47 -47
  4. package/api/RealtimeAPI.js +74 -74
  5. package/api/WebSocketAPI.js +0 -1
  6. package/common/controls/StopFinderControlCommon.d.ts +1 -1
  7. package/common/controls/StopFinderControlCommon.js +1 -1
  8. package/common/styles/realtimeDefaultStyle.js +0 -5
  9. package/common/styles/realtimeHeadingStyle.js +0 -5
  10. package/common/styles/realtimeSimpleStyle.d.ts +0 -1
  11. package/common/styles/realtimeSimpleStyle.js +0 -1
  12. package/common/typedefs.d.ts +0 -117
  13. package/common/typedefs.js +0 -31
  14. package/common/utils/RealtimeEngine.d.ts +214 -0
  15. package/common/utils/RealtimeEngine.js +554 -0
  16. package/common/utils/getLayersAsFlatArray.d.ts +0 -1
  17. package/common/utils/getLayersAsFlatArray.js +0 -1
  18. package/common/utils/getVehiclePosition.js +1 -4
  19. package/common/utils/realtimeConfig.d.ts +1 -1
  20. package/common/utils/realtimeConfig.js +0 -1
  21. package/common/utils/renderTrajectories.d.ts +1 -0
  22. package/common/utils/renderTrajectories.js +1 -0
  23. package/common/utils/sortAndFilterDepartures.d.ts +1 -0
  24. package/common/utils/sortAndFilterDepartures.js +1 -0
  25. package/maplibre/controls/CopyrightControl.d.ts +9 -6
  26. package/maplibre/controls/CopyrightControl.js +11 -8
  27. package/maplibre/layers/Layer.d.ts +7 -6
  28. package/maplibre/layers/Layer.js +1 -2
  29. package/maplibre/layers/RealtimeLayer.d.ts +54 -111
  30. package/maplibre/layers/RealtimeLayer.js +126 -114
  31. package/maplibre/utils/getSourceCoordinates.d.ts +1 -0
  32. package/maplibre/utils/getSourceCoordinates.js +5 -4
  33. package/mbt.js +6960 -14605
  34. package/mbt.js.map +4 -4
  35. package/mbt.min.js +68 -71
  36. package/mbt.min.js.map +4 -4
  37. package/ol/controls/CopyrightControl.d.ts +13 -5
  38. package/ol/controls/CopyrightControl.js +13 -5
  39. package/ol/controls/RoutingControl.d.ts +29 -18
  40. package/ol/controls/RoutingControl.js +44 -56
  41. package/ol/controls/StopFinderControl.d.ts +21 -2
  42. package/ol/controls/StopFinderControl.js +22 -3
  43. package/ol/index.d.ts +0 -1
  44. package/ol/index.js +0 -1
  45. package/ol/layers/Layer.d.ts +17 -92
  46. package/ol/layers/Layer.js +17 -3
  47. package/ol/layers/MaplibreLayer.d.ts +47 -114
  48. package/ol/layers/MaplibreLayer.js +102 -46
  49. package/ol/layers/MaplibreStyleLayer.d.ts +67 -147
  50. package/ol/layers/MaplibreStyleLayer.js +170 -123
  51. package/ol/layers/RealtimeLayer.d.ts +85 -218
  52. package/ol/layers/RealtimeLayer.js +170 -181
  53. package/ol/layers/VectorLayer.d.ts +1 -2
  54. package/ol/layers/VectorLayer.js +7 -6
  55. package/ol/renderers/MaplibreLayerRenderer.d.ts +9 -0
  56. package/ol/renderers/MaplibreLayerRenderer.js +35 -137
  57. package/ol/renderers/MaplibreStyleLayerRenderer.js +2 -2
  58. package/ol/renderers/RealtimeLayerRenderer.d.ts +1 -1
  59. package/ol/renderers/RealtimeLayerRenderer.js +6 -31
  60. package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
  61. package/ol/styles/fullTrajectoryStyle.d.ts +1 -2
  62. package/ol/styles/fullTrajectoryStyle.js +5 -7
  63. package/ol/styles/routingStyle.d.ts +0 -1
  64. package/ol/styles/routingStyle.js +13 -10
  65. package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
  66. package/ol/utils/defineDeprecatedProperties.js +180 -0
  67. package/package.json +40 -39
  68. package/setupTests.js +14 -0
  69. package/types/common.d.ts +4 -27
  70. package/types/realtime.d.ts +7 -2
  71. package/common/mixins/RealtimeLayerMixin.d.ts +0 -267
  72. package/common/mixins/RealtimeLayerMixin.js +0 -751
  73. package/ol/mixins/MobilityLayerMixin.d.ts +0 -96
  74. package/ol/mixins/MobilityLayerMixin.js +0 -6
  75. package/ol/mixins/PropertiesLayerMixin.d.ts +0 -136
  76. package/ol/mixins/PropertiesLayerMixin.js +0 -178
  77. package/ol/mixins/index.d.ts +0 -1
  78. package/ol/mixins/index.js +0 -2
@@ -1,11 +1,11 @@
1
1
  import { MapEvent } from 'ol';
2
2
  import Control, { Options } from 'ol/control/Control';
3
- export type CopyrightControlOptions = Options & {
3
+ export type CopyrightControlOptions = {
4
4
  className?: 'string';
5
5
  format?: (copyrights: string[]) => string;
6
- };
6
+ } & Options;
7
7
  /**
8
- * Display layer's copyrights.
8
+ * Display layer's copyrights. Adding the possibility to format them as you wish.
9
9
  *
10
10
  * @example
11
11
  * import { Map } from 'ol';
@@ -19,12 +19,20 @@ export type CopyrightControlOptions = Options & {
19
19
  * map.addControl(control);
20
20
  *
21
21
  *
22
- * @see <a href="/example/ol-copyright">Openlayers copyright example</a>
22
+ * @see <a href="/example/ol-realtime>OpenLayers Realtime layer example</a>
23
+ *
24
+ * @extends {ol/control/Control~Control}
23
25
  *
24
- * @extends {ol/control/Control}
25
26
  */
26
27
  declare class CopyrightControl extends Control {
27
28
  format: (copyrights: string[]) => string;
29
+ /**
30
+ * Constructor.
31
+ *
32
+ * @param {Object} options
33
+ * @param {Function} format Function used to format the list of copyrights available to a single string. By default join all the copyrights with a |.
34
+ * @public
35
+ */
28
36
  constructor(options?: CopyrightControlOptions);
29
37
  render({ frameState }: MapEvent): void;
30
38
  }
@@ -1,9 +1,9 @@
1
- import { inView } from 'ol/layer/Layer';
2
1
  import Control from 'ol/control/Control';
3
- import removeDuplicate from '../../common/utils/removeDuplicate';
2
+ import { inView } from 'ol/layer/Layer';
4
3
  import createDefaultCopyrightElement from '../../common/utils/createDefaultCopyrightElt';
4
+ import removeDuplicate from '../../common/utils/removeDuplicate';
5
5
  /**
6
- * Display layer's copyrights.
6
+ * Display layer's copyrights. Adding the possibility to format them as you wish.
7
7
  *
8
8
  * @example
9
9
  * import { Map } from 'ol';
@@ -17,11 +17,19 @@ import createDefaultCopyrightElement from '../../common/utils/createDefaultCopyr
17
17
  * map.addControl(control);
18
18
  *
19
19
  *
20
- * @see <a href="/example/ol-copyright">Openlayers copyright example</a>
20
+ * @see <a href="/example/ol-realtime>OpenLayers Realtime layer example</a>
21
+ *
22
+ * @extends {ol/control/Control~Control}
21
23
  *
22
- * @extends {ol/control/Control}
23
24
  */
24
25
  class CopyrightControl extends Control {
26
+ /**
27
+ * Constructor.
28
+ *
29
+ * @param {Object} options
30
+ * @param {Function} format Function used to format the list of copyrights available to a single string. By default join all the copyrights with a |.
31
+ * @public
32
+ */
25
33
  constructor(options = {}) {
26
34
  const element = createDefaultCopyrightElement();
27
35
  element.className = options.className || 'mbt-copyright';
@@ -6,6 +6,7 @@ import { Geometry, LineString, Point } from 'ol/geom';
6
6
  import { Modify } from 'ol/interaction';
7
7
  import { ModifyEvent } from 'ol/interaction/Modify';
8
8
  import VectorLayer from 'ol/layer/Vector';
9
+ import VectorSource from 'ol/source/Vector';
9
10
  import { RoutingAPI } from '../../api';
10
11
  import type { Map, MapBrowserEvent } from 'ol';
11
12
  import type { Coordinate } from 'ol/coordinate';
@@ -14,21 +15,22 @@ import type { RoutingGraph, RoutingMot, RoutingParameters, RoutingViaPoint } fro
14
15
  export type RoutingControlOptions = {
15
16
  active?: boolean;
16
17
  apiKey?: string;
18
+ apiParams?: RoutingParameters;
17
19
  graphs?: RoutingGraph[];
18
20
  modify?: boolean;
19
21
  mot?: string;
20
22
  onRouteError?: () => void;
21
- routingApiParams?: RoutingParameters;
22
- routingLayer?: VectorLayer<Feature>;
23
+ routingLayer?: VectorLayer<VectorSource>;
23
24
  snapToClosestStation?: boolean;
24
25
  stopsApiKey?: string;
25
26
  stopsApiUrl?: string;
26
27
  style?: StyleLike;
27
28
  useRawViaPoints?: boolean;
28
29
  } & Options;
29
- export type AbotControllersByGraph = Record<string, AbortController>;
30
+ export type AbortControllersByGraph = Record<string, AbortController>;
30
31
  /**
31
- * This OpenLayers control allows the user to add and modifiy via points to a map and request a route from the [geOps Routing API](https://developer.geops.io/apis/routing/).
32
+ * This OpenLayers control allows the user to add and modifiy via points to
33
+ * a map and request a route from the [geOps Routing API](https://developer.geops.io/apis/routing/).
32
34
  *
33
35
  * @example
34
36
  * import { Map } from 'ol';
@@ -40,29 +42,23 @@ export type AbotControllersByGraph = Record<string, AbortController>;
40
42
  *
41
43
  * const control = new RoutingControl();
42
44
  *
43
- * control.attachToMap(map)
45
+ * map.addControl(control);
44
46
  *
45
- * @classproperty {string} apiKey - Key used for RoutingApi requests.
46
- * @classproperty {string} stopsApiKey - Key used for Stop lookup requests (defaults to apiKey).
47
- * @classproperty {string} stopsApiUrl - Url used for Stop lookup requests (defaults to https://api.geops.io/stops/v1/lookup/).
48
- * @classproperty {Array.<Array<graph="osm", minZoom=0, maxZoom=99>>} graphs - Array of routing graphs and min/max zoom levels. If you use the control in combination with the [geOps Maps API](https://developer.geops.io/apis/maps/), you may want to use the optimal level of generalizations: "[['gen4', 0, 8], ['gen3', 8, 9], ['gen2', 9, 11], ['gen1', 11, 13], ['osm', 13, 99]]"
49
47
  * @classproperty {string} mot - Mean of transport to be used for routing.
50
- * @classproperty {object} routingApiParams - object of additional parameters to pass to the routing api request.
51
- * @classproperty {object} snapToClosestStation - If true, the routing will snap the coordinate to the closest station. Default to false.
52
- * @classproperty {boolean} useRawViaPoints - Experimental property. Wen true, it allows the user to add via points using different kind of string. See "via" parameter defined by the [geOps Routing API](https://developer.geops.io/apis/routing/). Default to false, only array of coordinates and station's id are supported as via points.
53
48
  * @classproperty {VectorLayer} routingLayer - Layer for adding route features.
54
- * @classproperty {function} onRouteError - Callback on error.
55
49
  * @classproperty {boolean} loading - True if the control is requesting the backend.
50
+ *
56
51
  * @see <a href="/example/ol-routing">Openlayers routing example</a>
57
52
  *
58
- * @extends {Control}
59
- * @implements {RoutingInterface}
53
+ * @extends {ol/control/Control~Control}
54
+ *
60
55
  * @public
61
56
  */
62
57
  declare class RoutingControl extends Control {
63
58
  abortControllers: Record<string, AbortController>;
64
59
  api?: RoutingAPI;
65
60
  apiKey?: string;
61
+ apiParams?: RoutingParameters;
66
62
  cacheStationData: Record<string, Coordinate>;
67
63
  format: GeoJSON;
68
64
  graphs: RoutingGraph[];
@@ -76,14 +72,29 @@ declare class RoutingControl extends Control {
76
72
  modifyInteraction?: Modify;
77
73
  onMapClickKey?: EventsKey;
78
74
  onRouteError: (error?: Error, control?: RoutingControl) => void;
79
- routingApiParams?: RoutingParameters;
80
- routingLayer?: VectorLayer<Feature>;
75
+ routingLayer?: VectorLayer<VectorSource>;
81
76
  segments: Feature<LineString>[];
82
77
  snapToClosestStation: boolean;
83
78
  stopsApiKey?: string;
84
79
  stopsApiUrl?: string;
85
80
  useRawViaPoints: boolean;
86
81
  viaPoints: RoutingViaPoint[];
82
+ /**
83
+ * Constructor.
84
+ *
85
+ * @param {Object} options
86
+ * @param {string} options.apiKey Access key for [geOps APIs](https://developer.geops.io/).
87
+ * @param {Object} options.apiParams Request parameters. See [geOps Routing API documentation](https://developer.geops.io/apis/routing/).
88
+ * @param {Array.<Array<graph="osm", minZoom=0, maxZoom=99>>} [options.graphs=[['osm', 0, 99]]] - Array of routing graphs and min/max zoom levels. If you use the control in combination with the [geOps Maps API](https://developer.geops.io/apis/maps/), you may want to use the optimal level of generalizations: "[['gen4', 0, 8], ['gen3', 8, 9], ['gen2', 9, 11], ['gen1', 11, 13], ['osm', 13, 99]]".
89
+ * @param {string} [options.mot="bus"] Mean of transport to be used for routing.
90
+ * @param {function} options.onRouteError Callback on request errors.
91
+ * @param {VectorLayer} [options.routingLayer=new VectorLayer()] Vector layer for adding route features.
92
+ * @param {boolean} [options.snapToClosestStation=false] If true, the routing will snap the coordinate to the closest station. Default to false.
93
+ * @param {StyleLike} options.style Style of the default vector layer.
94
+ * @param {boolean} [options.useRawViaPoints=fale] Experimental property. If true, it allows the user to add via points using different kind of string. See "via" parameter defined by the [geOps Routing API](https://developer.geops.io/apis/routing/). Default to false, only array of coordinates and station's id are supported as via points.
95
+ * @param {string} [options.url='https://api.geops.io/routing/v1/'] [geOps Realtime API](https://developer.geops.io/apis/realtime/) url.
96
+ * @public
97
+ */
87
98
  constructor(options?: RoutingControlOptions);
88
99
  /**
89
100
  * Calculate at which resolutions corresponds each generalizations.
@@ -108,7 +119,7 @@ declare class RoutingControl extends Control {
108
119
  * If an index is passed a viaPoint is added at the specified index.
109
120
  * If an index is passed and overwrite x is > 0, x viaPoints at the specified
110
121
  * index are replaced with a single new viaPoint.
111
- * @param {number[]|string} coordinates Array of coordinates
122
+ * @param {string | Coordinate} coordinatesOrString Array of coordinates or a string representing a station
112
123
  * @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.
113
124
  * @param {number} [overwrite=0] Marks the number of viaPoints that are removed at the specified index on add.
114
125
  * @public
@@ -18,27 +18,22 @@ import { RoutingAPI } from '../../api';
18
18
  // @47.37811,8.53935 a station at position 47.37811, 8.53935
19
19
  // @47.37811,8.53935$4 track 4 in a station at position 47.37811, 8.53935
20
20
  // zürich hb@47.37811,8.53935$8 track 8 in station "Zürich HB" at position 47.37811, 8.53935
21
- /** @private */
22
21
  const REGEX_VIA_POINT = /^([^@$!\n]*)(@?([\d.]+),([\d.]+))?(\$?([a-zA-Z0-9]{0,2}))$/;
23
22
  // Examples for a single hop:
24
23
  //
25
24
  // 47.37811,8.53935 a position 47.37811, 8.53935
26
- /** @private */
27
25
  const REGEX_VIA_POINT_COORD = /^([\d.]+),([\d.]+)$/;
28
26
  // Examples for a single hop:
29
27
  //
30
28
  // !8596126 a station with id 8596126
31
29
  // !8596126$4 a station with id 8596126
32
- /** @private */
33
30
  const REGEX_VIA_POINT_STATION_ID = /^!([^$]*)(\$?([a-zA-Z0-9]{0,2}))$/;
34
- /** @private */
35
31
  const STOP_FETCH_ABORT_CONTROLLER_KEY = 'stop-fetch';
36
- /** @private */
37
32
  const getFlatCoordinatesFromSegments = (segmentArray) => {
38
33
  const coords = [];
39
34
  segmentArray.forEach((seg) => {
40
35
  var _a;
41
- // @ts-expect-error
36
+ // @ts-expect-error missing type
42
37
  const coordArr = (_a = seg.getGeometry()) === null || _a === void 0 ? void 0 : _a.getCoordinates();
43
38
  if (coordArr === null || coordArr === void 0 ? void 0 : coordArr.length) {
44
39
  coords.push(...coordArr);
@@ -47,7 +42,8 @@ const getFlatCoordinatesFromSegments = (segmentArray) => {
47
42
  return coords;
48
43
  };
49
44
  /**
50
- * This OpenLayers control allows the user to add and modifiy via points to a map and request a route from the [geOps Routing API](https://developer.geops.io/apis/routing/).
45
+ * This OpenLayers control allows the user to add and modifiy via points to
46
+ * a map and request a route from the [geOps Routing API](https://developer.geops.io/apis/routing/).
51
47
  *
52
48
  * @example
53
49
  * import { Map } from 'ol';
@@ -59,26 +55,35 @@ const getFlatCoordinatesFromSegments = (segmentArray) => {
59
55
  *
60
56
  * const control = new RoutingControl();
61
57
  *
62
- * control.attachToMap(map)
58
+ * map.addControl(control);
63
59
  *
64
- * @classproperty {string} apiKey - Key used for RoutingApi requests.
65
- * @classproperty {string} stopsApiKey - Key used for Stop lookup requests (defaults to apiKey).
66
- * @classproperty {string} stopsApiUrl - Url used for Stop lookup requests (defaults to https://api.geops.io/stops/v1/lookup/).
67
- * @classproperty {Array.<Array<graph="osm", minZoom=0, maxZoom=99>>} graphs - Array of routing graphs and min/max zoom levels. If you use the control in combination with the [geOps Maps API](https://developer.geops.io/apis/maps/), you may want to use the optimal level of generalizations: "[['gen4', 0, 8], ['gen3', 8, 9], ['gen2', 9, 11], ['gen1', 11, 13], ['osm', 13, 99]]"
68
60
  * @classproperty {string} mot - Mean of transport to be used for routing.
69
- * @classproperty {object} routingApiParams - object of additional parameters to pass to the routing api request.
70
- * @classproperty {object} snapToClosestStation - If true, the routing will snap the coordinate to the closest station. Default to false.
71
- * @classproperty {boolean} useRawViaPoints - Experimental property. Wen true, it allows the user to add via points using different kind of string. See "via" parameter defined by the [geOps Routing API](https://developer.geops.io/apis/routing/). Default to false, only array of coordinates and station's id are supported as via points.
72
61
  * @classproperty {VectorLayer} routingLayer - Layer for adding route features.
73
- * @classproperty {function} onRouteError - Callback on error.
74
62
  * @classproperty {boolean} loading - True if the control is requesting the backend.
63
+ *
75
64
  * @see <a href="/example/ol-routing">Openlayers routing example</a>
76
65
  *
77
- * @extends {Control}
78
- * @implements {RoutingInterface}
66
+ * @extends {ol/control/Control~Control}
67
+ *
79
68
  * @public
80
69
  */
81
70
  class RoutingControl extends Control {
71
+ /**
72
+ * Constructor.
73
+ *
74
+ * @param {Object} options
75
+ * @param {string} options.apiKey Access key for [geOps APIs](https://developer.geops.io/).
76
+ * @param {Object} options.apiParams Request parameters. See [geOps Routing API documentation](https://developer.geops.io/apis/routing/).
77
+ * @param {Array.<Array<graph="osm", minZoom=0, maxZoom=99>>} [options.graphs=[['osm', 0, 99]]] - Array of routing graphs and min/max zoom levels. If you use the control in combination with the [geOps Maps API](https://developer.geops.io/apis/maps/), you may want to use the optimal level of generalizations: "[['gen4', 0, 8], ['gen3', 8, 9], ['gen2', 9, 11], ['gen1', 11, 13], ['osm', 13, 99]]".
78
+ * @param {string} [options.mot="bus"] Mean of transport to be used for routing.
79
+ * @param {function} options.onRouteError Callback on request errors.
80
+ * @param {VectorLayer} [options.routingLayer=new VectorLayer()] Vector layer for adding route features.
81
+ * @param {boolean} [options.snapToClosestStation=false] If true, the routing will snap the coordinate to the closest station. Default to false.
82
+ * @param {StyleLike} options.style Style of the default vector layer.
83
+ * @param {boolean} [options.useRawViaPoints=fale] Experimental property. If true, it allows the user to add via points using different kind of string. See "via" parameter defined by the [geOps Routing API](https://developer.geops.io/apis/routing/). Default to false, only array of coordinates and station's id are supported as via points.
84
+ * @param {string} [options.url='https://api.geops.io/routing/v1/'] [geOps Realtime API](https://developer.geops.io/apis/realtime/) url.
85
+ * @public
86
+ */
82
87
  constructor(options = {}) {
83
88
  super(options);
84
89
  this.abortControllers = {};
@@ -95,36 +100,23 @@ class RoutingControl extends Control {
95
100
  }
96
101
  /** True if the control is requesting the backend. */
97
102
  this.loading = false;
98
- /** @private */
99
103
  this.active = options.active || true;
100
- /** @private */
101
104
  this.graphs = options.graphs || [['osm', 0, 99]];
102
- /** @private */
103
105
  this.mot = options.mot || 'bus';
104
- /** @private */
105
106
  this.modify = options.modify !== false;
106
- /** @private */
107
- this.routingApiParams = options.routingApiParams;
108
- /** @private */
107
+ this.apiParams = options.apiParams;
109
108
  this.useRawViaPoints = options.useRawViaPoints || false;
110
- /** @private */
111
109
  this.snapToClosestStation = options.snapToClosestStation || false;
112
- /** @private */
113
110
  this.apiKey = options.apiKey;
114
- /** @private */
115
111
  this.stopsApiKey = options.stopsApiKey || this.apiKey;
116
- /** @private */
117
112
  this.stopsApiUrl = options.stopsApiUrl || 'https://api.geops.io/stops/v1/';
118
- /** @private */
119
113
  this.api = new RoutingAPI(Object.assign({}, options));
120
- /** @private */
121
114
  this.routingLayer =
122
115
  options.routingLayer ||
123
116
  new VectorLayer({
124
117
  source: new VectorSource(),
125
118
  style: options.style,
126
119
  });
127
- /** @private */
128
120
  this.onRouteError =
129
121
  options.onRouteError ||
130
122
  ((error) => {
@@ -133,13 +125,9 @@ class RoutingControl extends Control {
133
125
  // eslint-disable-next-line no-console
134
126
  console.error(error);
135
127
  });
136
- /** @private */
137
128
  this.onMapClick = this.onMapClick.bind(this);
138
- /** @private */
139
129
  this.onModifyEnd = this.onModifyEnd.bind(this);
140
- /** @private */
141
130
  this.onModifyStart = this.onModifyStart.bind(this);
142
- /** @private */
143
131
  this.createModifyInteraction();
144
132
  this.on('propertychange', (evt) => {
145
133
  if (evt.key === 'active') {
@@ -188,11 +176,9 @@ class RoutingControl extends Control {
188
176
  var _a;
189
177
  const map = this.getMap();
190
178
  if (map) {
191
- /** @private */
192
179
  this.format = new GeoJSON({
193
180
  featureProjection: map.getView().getProjection(),
194
181
  });
195
- /** @private */
196
182
  this.graphsResolutions = RoutingControl.getGraphsResolutions(this.graphs, map);
197
183
  // Clean the modifyInteraction if present
198
184
  if (this.modifyInteraction) {
@@ -217,7 +203,6 @@ class RoutingControl extends Control {
217
203
  return;
218
204
  }
219
205
  this.removeListeners();
220
- /** @private */
221
206
  this.onMapClickKey = (_a = this.getMap()) === null || _a === void 0 ? void 0 : _a.on('singleclick', this.onMapClick);
222
207
  }
223
208
  /**
@@ -226,7 +211,7 @@ class RoutingControl extends Control {
226
211
  * If an index is passed a viaPoint is added at the specified index.
227
212
  * If an index is passed and overwrite x is > 0, x viaPoints at the specified
228
213
  * index are replaced with a single new viaPoint.
229
- * @param {number[]|string} coordinates Array of coordinates
214
+ * @param {string | Coordinate} coordinatesOrString Array of coordinates or a string representing a station
230
215
  * @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.
231
216
  * @param {number} [overwrite=0] Marks the number of viaPoints that are removed at the specified index on add.
232
217
  * @public
@@ -243,7 +228,6 @@ class RoutingControl extends Control {
243
228
  * @private
244
229
  */
245
230
  createDefaultElement() {
246
- /** @private */
247
231
  this.element = document.createElement('button');
248
232
  this.element.id = 'ol-toggle-routing';
249
233
  this.element.innerHTML = 'Toggle Route Control';
@@ -266,12 +250,12 @@ class RoutingControl extends Control {
266
250
  */
267
251
  // Define and add modify interaction
268
252
  this.modifyInteraction = new Modify({
269
- // hitDetection: this.routingLayer, // Create a bug, the first point is always selected even if the mous eis far away
253
+ // hitDetection: this.routingLayer, // TODO: wait for ol, fixed in https://github.com/openlayers/openlayers/pull/16393
270
254
  deleteCondition: (e) => {
271
255
  var _a;
272
- const feats = (_a = e.target) === null || _a === void 0 ? void 0 : _a.getFeaturesAtPixel(e.pixel, {
256
+ const feats = ((_a = e.target) === null || _a === void 0 ? void 0 : _a.getFeaturesAtPixel(e.pixel, {
273
257
  hitTolerance: 5,
274
- } || []);
258
+ })) || [];
275
259
  const viaPoint = feats.find((feat) => { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === 'Point' && feat.get('index'); });
276
260
  if (click(e) && viaPoint) {
277
261
  // Remove node & viaPoint if an existing viaPoint was clicked
@@ -310,7 +294,7 @@ class RoutingControl extends Control {
310
294
  var _a, _b;
311
295
  /* Calls RoutingAPI to draw a route using the viaPoints array */
312
296
  this.abortRequests();
313
- (_b = (_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear(true);
297
+ (_b = (_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear();
314
298
  if (!this.viaPoints.length) {
315
299
  return null;
316
300
  }
@@ -332,7 +316,9 @@ class RoutingControl extends Control {
332
316
  });
333
317
  this.loading = true;
334
318
  // Create point features for the viaPoints
335
- this.viaPoints.forEach((viaPoint, idx) => this.drawViaPoint(viaPoint, idx, this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]));
319
+ this.viaPoints.forEach((viaPoint, idx) => {
320
+ this.drawViaPoint(viaPoint, idx, this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]);
321
+ });
336
322
  return Promise.all(this.graphs.map(([graph], index) => {
337
323
  const { signal } = this.abortControllers[graph];
338
324
  if (!this.api) {
@@ -341,7 +327,7 @@ class RoutingControl extends Control {
341
327
  return this.api
342
328
  .route(Object.assign({ 'coord-punish': 1000.0, 'coord-radius': 100.0,
343
329
  // @ts-expect-error missing property in swagger
344
- elevation: false, graph, mot: this.mot, 'resolve-hops': false, via: `${formattedViaPoints.join('|')}` }, (this.routingApiParams || {})), { signal })
330
+ elevation: false, graph, mot: this.mot, 'resolve-hops': false, via: `${formattedViaPoints.join('|')}` }, (this.apiParams || {})), { signal })
345
331
  .then((featureCollection) => {
346
332
  var _a, _b, _c;
347
333
  this.segments = this.format.readFeatures(featureCollection);
@@ -381,8 +367,7 @@ class RoutingControl extends Control {
381
367
  this.loading = false;
382
368
  })
383
369
  .catch((error) => {
384
- var _a, _b;
385
- if (/AbortError/.test(error.message)) {
370
+ if (/AbortError/.test(error.name)) {
386
371
  // Ignore abort error
387
372
  return;
388
373
  }
@@ -390,7 +375,6 @@ class RoutingControl extends Control {
390
375
  // Dispatch error event and execute error function
391
376
  this.dispatchEvent(new BaseEvent('error'));
392
377
  this.onRouteError(error, this);
393
- (_b = (_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear();
394
378
  this.loading = false;
395
379
  });
396
380
  }));
@@ -427,15 +411,19 @@ class RoutingControl extends Control {
427
411
  return fetch(`${this.stopsApiUrl}lookup/${stationId}?key=${this.stopsApiKey}`, { signal: abortController.signal })
428
412
  .then((res) => res.json())
429
413
  .then((stationData) => {
430
- var _a, _b;
431
- const { coordinates } = stationData.features[0].geometry;
414
+ var _a, _b, _c, _d;
415
+ const { coordinates } = ((_b = (_a = stationData === null || stationData === void 0 ? void 0 : stationData.features) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.geometry) || {};
416
+ if (!coordinates) {
417
+ console.log('No coordinates found for station ' + stationId, stationData);
418
+ }
432
419
  this.cacheStationData[viaPoint] = fromLonLat(coordinates);
433
420
  pointFeature.set('viaPointTrack', track);
434
421
  pointFeature.setGeometry(new Point(fromLonLat(coordinates)));
435
- (_b = (_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.addFeature(pointFeature);
422
+ (_d = (_c = this.routingLayer) === null || _c === void 0 ? void 0 : _c.getSource()) === null || _d === void 0 ? void 0 : _d.addFeature(pointFeature);
436
423
  return pointFeature;
437
424
  })
438
425
  .catch((error) => {
426
+ var _a, _b;
439
427
  if (/AbortError/.test(error.message)) {
440
428
  // Ignore abort error
441
429
  return;
@@ -443,6 +431,7 @@ class RoutingControl extends Control {
443
431
  // Dispatch error event and execute error function
444
432
  this.dispatchEvent(new BaseEvent('error'));
445
433
  this.onRouteError(error, this);
434
+ (_b = (_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear();
446
435
  this.loading = false;
447
436
  });
448
437
  }
@@ -575,7 +564,7 @@ class RoutingControl extends Control {
575
564
  if ((route === null || route === void 0 ? void 0 : route.getGeometry()) && evt.mapBrowserEvent.coordinate) {
576
565
  // We use a buff extent to fix floating issues , see https://github.com/openlayers/openlayers/issues/7130#issuecomment-535856422
577
566
  const closestExtent = buffer(new Point(
578
- // @ts-expect-error
567
+ // @ts-expect-error bad def
579
568
  (_a = route.getGeometry()) === null || _a === void 0 ? void 0 : _a.getClosestPoint(evt.mapBrowserEvent.coordinate)).getExtent(), 0.001);
580
569
  segmentIndex = this.segments.findIndex((segment) => { var _a; return (_a = segment.getGeometry()) === null || _a === void 0 ? void 0 : _a.intersectsExtent(closestExtent); });
581
570
  }
@@ -585,9 +574,8 @@ class RoutingControl extends Control {
585
574
  .filter((feat) => { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === 'Point'; }) ||
586
575
  [])[0];
587
576
  // Write object with modify info
588
- /** @private */
589
577
  this.initialRouteDrag = {
590
- oldRoute: route && route.clone(),
578
+ oldRoute: route === null || route === void 0 ? void 0 : route.clone(),
591
579
  segmentIndex,
592
580
  viaPoint,
593
581
  };
@@ -23,15 +23,34 @@ export type StopFinderControlOptions = {
23
23
  *
24
24
  *
25
25
  * @see <a href="/example/ol-search">Openlayers search example</a>
26
+ *
27
+ * @extends {ol/control/Control~Control}
28
+ *
26
29
  * @public
27
30
  */
28
31
  declare class StopFinderControl extends Control {
29
32
  controller: StopFinderControlCommon;
30
- constructor(options: StopFinderControlOptions);
31
33
  /**
32
- * @private
34
+ * Constructor.
35
+ *
36
+ * @param {Object} options
37
+ * @param {HTMLElement} options.element HTML element where to attach input and suggestions.
38
+ * @param {string} options.apiKey Access key for [geOps APIs](https://developer.geops.io/).
39
+ * @param {StopsSearchParams} [options.apiParams={ limit: 20 }] Request parameters. See [geOps Stops API documentation](https://developer.geops.io/apis/5dcbd702a256d90001cf1361/).
40
+ * @param {string} [options.placeholder='Search for a stop...'] Input field placeholder.
41
+ * @param {string} [options.url='https://api.geops.io/stops/v1/'] [geOps Stops API](https://developer.geops.io/apis/stops/) url.
42
+ * @public
33
43
  */
44
+ constructor(options: StopFinderControlOptions);
34
45
  onSuggestionClick(suggestion: Feature): void;
46
+ /**
47
+ * Search for stations using a query.
48
+ *
49
+ * @param {string} q Query used to search stops.
50
+ * @param {AbortController} abortController Abort controller used to abort requests.
51
+ * @returns {Promise<Array<GeoJSONFeature>>}
52
+ * @public
53
+ */
35
54
  search(q: string, abortController: AbortController): Promise<void>;
36
55
  }
37
56
  export default StopFinderControl;
@@ -21,9 +21,23 @@ import createDefaultStopFinderElement from '../../common/utils/createDefaultStop
21
21
  *
22
22
  *
23
23
  * @see <a href="/example/ol-search">Openlayers search example</a>
24
+ *
25
+ * @extends {ol/control/Control~Control}
26
+ *
24
27
  * @public
25
28
  */
26
29
  class StopFinderControl extends Control {
30
+ /**
31
+ * Constructor.
32
+ *
33
+ * @param {Object} options
34
+ * @param {HTMLElement} options.element HTML element where to attach input and suggestions.
35
+ * @param {string} options.apiKey Access key for [geOps APIs](https://developer.geops.io/).
36
+ * @param {StopsSearchParams} [options.apiParams={ limit: 20 }] Request parameters. See [geOps Stops API documentation](https://developer.geops.io/apis/5dcbd702a256d90001cf1361/).
37
+ * @param {string} [options.placeholder='Search for a stop...'] Input field placeholder.
38
+ * @param {string} [options.url='https://api.geops.io/stops/v1/'] [geOps Stops API](https://developer.geops.io/apis/stops/) url.
39
+ * @public
40
+ */
27
41
  constructor(options) {
28
42
  const element = createDefaultStopFinderElement();
29
43
  element.className = (options === null || options === void 0 ? void 0 : options.className) || 'mbt-stop-finder';
@@ -31,14 +45,19 @@ class StopFinderControl extends Control {
31
45
  super(opt);
32
46
  this.controller = new StopFinderControlCommon(Object.assign({ onSuggestionClick: this.onSuggestionClick.bind(this) }, opt));
33
47
  }
34
- /**
35
- * @private
36
- */
37
48
  onSuggestionClick(suggestion) {
38
49
  var _a;
39
50
  const coord = fromLonLat(suggestion.geometry.coordinates);
40
51
  (_a = this.getMap()) === null || _a === void 0 ? void 0 : _a.getView().setCenter(coord);
41
52
  }
53
+ /**
54
+ * Search for stations using a query.
55
+ *
56
+ * @param {string} q Query used to search stops.
57
+ * @param {AbortController} abortController Abort controller used to abort requests.
58
+ * @returns {Promise<Array<GeoJSONFeature>>}
59
+ * @public
60
+ */
42
61
  search(q, abortController) {
43
62
  return this.controller.search(q, abortController);
44
63
  }
package/ol/index.d.ts CHANGED
@@ -2,6 +2,5 @@ export * from "../api";
2
2
  export * from "../common";
3
3
  export * from "./controls";
4
4
  export * from "./layers";
5
- export * from "./mixins";
6
5
  export * from "./styles";
7
6
  export * from "./utils";
package/ol/index.js CHANGED
@@ -2,6 +2,5 @@ export * from '../api';
2
2
  export * from '../common';
3
3
  export * from './controls';
4
4
  export * from './layers';
5
- export * from './mixins';
6
5
  export * from './styles';
7
6
  export * from './utils';