mobility-toolbox-js 3.0.0-beta.9 → 3.0.0

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 (105) hide show
  1. package/README.md +11 -3
  2. package/api/HttpAPI.d.ts +5 -16
  3. package/api/HttpAPI.js +1 -14
  4. package/api/RealtimeAPI.d.ts +188 -143
  5. package/api/RealtimeAPI.js +265 -206
  6. package/api/RoutingAPI.d.ts +21 -11
  7. package/api/RoutingAPI.js +17 -7
  8. package/api/StopsAPI.d.ts +20 -14
  9. package/api/StopsAPI.js +17 -11
  10. package/api/WebSocketAPI.d.ts +60 -66
  11. package/api/WebSocketAPI.js +164 -165
  12. package/api/index.js +1 -1
  13. package/api/typedefs.d.ts +0 -102
  14. package/api/typedefs.js +27 -42
  15. package/common/controls/StopFinderControlCommon.d.ts +13 -13
  16. package/common/controls/StopFinderControlCommon.js +32 -32
  17. package/common/index.d.ts +1 -1
  18. package/common/index.js +1 -1
  19. package/common/styles/realtimeDefaultStyle.js +6 -11
  20. package/common/styles/realtimeHeadingStyle.js +5 -10
  21. package/common/styles/realtimeSimpleStyle.d.ts +0 -1
  22. package/common/styles/realtimeSimpleStyle.js +0 -1
  23. package/common/typedefs.d.ts +11 -121
  24. package/common/typedefs.js +6 -31
  25. package/common/utils/RealtimeEngine.d.ts +214 -0
  26. package/common/utils/RealtimeEngine.js +554 -0
  27. package/common/utils/compareDepartures.d.ts +2 -2
  28. package/common/utils/compareDepartures.js +2 -2
  29. package/common/utils/debounceWebsocketMessages.d.ts +1 -1
  30. package/common/utils/getLayersAsFlatArray.d.ts +0 -1
  31. package/common/utils/getLayersAsFlatArray.js +0 -1
  32. package/common/utils/getMapGlCopyrights.d.ts +1 -1
  33. package/common/utils/getMapGlCopyrights.js +3 -3
  34. package/common/utils/getRealtimeModeSuffix.d.ts +1 -0
  35. package/common/utils/getRealtimeModeSuffix.js +1 -0
  36. package/common/utils/getVehiclePosition.d.ts +5 -4
  37. package/common/utils/getVehiclePosition.js +6 -3
  38. package/common/utils/realtimeConfig.d.ts +1 -1
  39. package/common/utils/realtimeConfig.js +0 -1
  40. package/common/utils/renderTrajectories.d.ts +2 -1
  41. package/common/utils/renderTrajectories.js +7 -6
  42. package/common/utils/sortAndFilterDepartures.d.ts +2 -1
  43. package/common/utils/sortAndFilterDepartures.js +2 -1
  44. package/common/utils/sortByDelay.d.ts +2 -2
  45. package/common/utils/sortByDelay.js +5 -1
  46. package/maplibre/controls/CopyrightControl.d.ts +9 -6
  47. package/maplibre/controls/CopyrightControl.js +11 -8
  48. package/maplibre/layers/Layer.d.ts +8 -7
  49. package/maplibre/layers/Layer.js +2 -3
  50. package/maplibre/layers/RealtimeLayer.d.ts +82 -118
  51. package/maplibre/layers/RealtimeLayer.js +154 -118
  52. package/maplibre/utils/getSourceCoordinates.d.ts +1 -0
  53. package/maplibre/utils/getSourceCoordinates.js +6 -5
  54. package/mbt.js +14611 -14591
  55. package/mbt.js.map +4 -4
  56. package/mbt.min.js +75 -75
  57. package/mbt.min.js.map +4 -4
  58. package/ol/controls/CopyrightControl.d.ts +13 -5
  59. package/ol/controls/CopyrightControl.js +13 -5
  60. package/ol/controls/RoutingControl.d.ts +105 -101
  61. package/ol/controls/RoutingControl.js +250 -264
  62. package/ol/controls/StopFinderControl.d.ts +24 -5
  63. package/ol/controls/StopFinderControl.js +24 -5
  64. package/ol/layers/Layer.d.ts +26 -0
  65. package/ol/layers/Layer.js +39 -0
  66. package/ol/layers/MaplibreLayer.d.ts +56 -28
  67. package/ol/layers/MaplibreLayer.js +154 -31
  68. package/ol/layers/MaplibreStyleLayer.d.ts +71 -149
  69. package/ol/layers/MaplibreStyleLayer.js +281 -210
  70. package/ol/layers/RealtimeLayer.d.ts +95 -230
  71. package/ol/layers/RealtimeLayer.js +209 -211
  72. package/ol/layers/VectorLayer.d.ts +17 -0
  73. package/ol/layers/VectorLayer.js +33 -0
  74. package/ol/layers/index.d.ts +2 -0
  75. package/ol/layers/index.js +3 -0
  76. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -20
  77. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  78. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +6 -6
  79. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  80. package/ol/renderers/RealtimeLayerRenderer.d.ts +7 -7
  81. package/ol/renderers/RealtimeLayerRenderer.js +46 -66
  82. package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
  83. package/ol/styles/fullTrajectoryStyle.d.ts +1 -2
  84. package/ol/styles/fullTrajectoryStyle.js +5 -7
  85. package/ol/styles/routingStyle.d.ts +0 -1
  86. package/ol/styles/routingStyle.js +13 -10
  87. package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
  88. package/ol/utils/defineDeprecatedProperties.js +180 -0
  89. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +1 -1
  90. package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
  91. package/package.json +44 -44
  92. package/setupTests.js +17 -4
  93. package/types/common.d.ts +53 -69
  94. package/types/index.d.ts +1 -1
  95. package/types/realtime.d.ts +98 -95
  96. package/types/routing.d.ts +60 -60
  97. package/types/stops.d.ts +62 -62
  98. package/common/mixins/RealtimeLayerMixin.d.ts +0 -273
  99. package/common/mixins/RealtimeLayerMixin.js +0 -743
  100. package/ol/layers/MapGlLayer.d.ts +0 -144
  101. package/ol/layers/MapGlLayer.js +0 -144
  102. package/ol/mixins/MobilityLayerMixin.d.ts +0 -98
  103. package/ol/mixins/MobilityLayerMixin.js +0 -6
  104. package/ol/mixins/PropertiesLayerMixin.d.ts +0 -127
  105. package/ol/mixins/PropertiesLayerMixin.js +0 -143
@@ -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';
@@ -1,37 +1,36 @@
1
1
  import { Feature } from 'ol';
2
- import type { Map, MapBrowserEvent } from 'ol';
2
+ import Control, { Options } from 'ol/control/Control';
3
+ import { EventsKey } from 'ol/events';
4
+ import { GeoJSON } from 'ol/format';
3
5
  import { Geometry, LineString, Point } from 'ol/geom';
4
6
  import { Modify } from 'ol/interaction';
5
- import { GeoJSON } from 'ol/format';
6
- import type { Coordinate } from 'ol/coordinate';
7
- import type { StyleLike } from 'ol/style/Style';
8
- import { EventsKey } from 'ol/events';
9
7
  import { ModifyEvent } from 'ol/interaction/Modify';
10
8
  import VectorLayer from 'ol/layer/Vector';
11
9
  import VectorSource from 'ol/source/Vector';
12
- import Control, { Options } from 'ol/control/Control';
13
10
  import { RoutingAPI } from '../../api';
11
+ import type { Map, MapBrowserEvent } from 'ol';
12
+ import type { Coordinate } from 'ol/coordinate';
13
+ import type { StyleLike } from 'ol/style/Style';
14
14
  import type { RoutingGraph, RoutingMot, RoutingParameters, RoutingViaPoint } from '../../types';
15
- export type RoutingControlOptions = Options & {
16
- apiKey?: string;
15
+ export type RoutingControlOptions = {
17
16
  active?: boolean;
18
- stopsApiKey?: string;
19
- stopsApiUrl?: string;
20
- routingLayer?: VectorLayer<VectorSource<Feature<Geometry>>>;
17
+ apiKey?: string;
18
+ apiParams?: RoutingParameters;
21
19
  graphs?: RoutingGraph[];
22
- mot?: string;
23
20
  modify?: boolean;
24
- routingApiParams?: RoutingParameters;
25
- useRawViaPoints?: boolean;
21
+ mot?: string;
22
+ onRouteError?: () => void;
23
+ routingLayer?: VectorLayer<VectorSource>;
26
24
  snapToClosestStation?: boolean;
25
+ stopsApiKey?: string;
26
+ stopsApiUrl?: string;
27
27
  style?: StyleLike;
28
- onRouteError?: () => void;
29
- };
30
- export type AbotControllersByGraph = {
31
- [key: string]: AbortController;
32
- };
28
+ useRawViaPoints?: boolean;
29
+ } & Options;
30
+ export type AbortControllersByGraph = Record<string, AbortController>;
33
31
  /**
34
- * Display a route of a specified mean of transport.
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/).
35
34
  *
36
35
  * @example
37
36
  * import { Map } from 'ol';
@@ -43,62 +42,59 @@ export type AbotControllersByGraph = {
43
42
  *
44
43
  * const control = new RoutingControl();
45
44
  *
46
- * control.attachToMap(map)
45
+ * map.addControl(control);
47
46
  *
48
- * @classproperty {string} apiKey - Key used for RoutingApi requests.
49
- * @classproperty {string} stopsApiKey - Key used for Stop lookup requests (defaults to apiKey).
50
- * @classproperty {string} stopsApiUrl - Url used for Stop lookup requests (defaults to https://api.geops.io/stops/v1/lookup/).
51
- * @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]]"
52
47
  * @classproperty {string} mot - Mean of transport to be used for routing.
53
- * @classproperty {object} routingApiParams - object of additional parameters to pass to the routing api request.
54
- * @classproperty {object} snapToClosestStation - If true, the routing will snap the coordinate to the closest station. Default to false.
55
- * @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.
56
48
  * @classproperty {VectorLayer} routingLayer - Layer for adding route features.
57
- * @classproperty {function} onRouteError - Callback on error.
58
49
  * @classproperty {boolean} loading - True if the control is requesting the backend.
50
+ *
59
51
  * @see <a href="/example/ol-routing">Openlayers routing example</a>
60
52
  *
61
- * @extends {Control}
62
- * @implements {RoutingInterface}
53
+ * @extends {ol/control/Control~Control}
54
+ *
63
55
  * @public
64
56
  */
65
57
  declare class RoutingControl extends Control {
66
- map?: Map;
67
- viaPoints: RoutingViaPoint[];
68
- routingLayer?: VectorLayer<VectorSource<Feature<Geometry>>>;
69
- graphs: RoutingGraph[];
70
- routingApiParams?: RoutingParameters;
71
- useRawViaPoints: boolean;
72
- snapToClosestStation: boolean;
73
- cacheStationData: {
74
- [key: string]: Coordinate;
75
- };
76
- abortControllers: {
77
- [key: string]: AbortController;
78
- };
79
- apiKey?: string;
80
- stopsApiKey?: string;
81
- segments: Feature<LineString>[];
82
- stopsApiUrl?: string;
58
+ abortControllers: Record<string, AbortController>;
83
59
  api?: RoutingAPI;
60
+ apiKey?: string;
61
+ apiParams?: RoutingParameters;
62
+ cacheStationData: Record<string, Coordinate>;
84
63
  format: GeoJSON;
64
+ graphs: RoutingGraph[];
85
65
  graphsResolutions?: [number, number][];
86
- onRouteError: (error?: Error, control?: RoutingControl) => void;
87
- onMapClickKey?: EventsKey;
88
- modifyInteraction?: Modify;
89
66
  initialRouteDrag?: {
90
- viaPoint?: Feature<Point>;
91
67
  oldRoute?: Feature<LineString>;
92
68
  segmentIndex?: number;
69
+ viaPoint?: Feature<Point>;
93
70
  };
94
- get active(): boolean;
95
- set active(newValue: boolean);
96
- get loading(): boolean;
97
- set loading(newValue: boolean);
98
- get modify(): any;
99
- set modify(newValue: any);
100
- get mot(): RoutingMot;
101
- set mot(newValue: RoutingMot);
71
+ map?: Map;
72
+ modifyInteraction?: Modify;
73
+ onMapClickKey?: EventsKey;
74
+ onRouteError: (error?: Error, control?: RoutingControl) => void;
75
+ routingLayer?: VectorLayer<VectorSource>;
76
+ segments: Feature<LineString>[];
77
+ snapToClosestStation: boolean;
78
+ stopsApiKey?: string;
79
+ stopsApiUrl?: string;
80
+ useRawViaPoints: boolean;
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
+ */
102
98
  constructor(options?: RoutingControlOptions);
103
99
  /**
104
100
  * Calculate at which resolutions corresponds each generalizations.
@@ -107,45 +103,40 @@ declare class RoutingControl extends Control {
107
103
  */
108
104
  static getGraphsResolutions(graphs: RoutingGraph[], map: Map): [number, number][];
109
105
  /**
110
- * Activet7deactivate the control when activ eproperty changes
106
+ * Aborts viapoint and route requests
111
107
  * @private
112
108
  */
113
- onActiveChange(): void;
109
+ abortRequests(): void;
110
+ activate(): void;
111
+ /**
112
+ * Add click listener to map.
113
+ * @private
114
+ */
115
+ addListeners(): void;
114
116
  /**
115
117
  * Adds/Replaces a viaPoint to the viaPoints array and redraws route:
116
118
  * Adds a viaPoint at end of array by default.
117
119
  * If an index is passed a viaPoint is added at the specified index.
118
120
  * If an index is passed and overwrite x is > 0, x viaPoints at the specified
119
121
  * index are replaced with a single new viaPoint.
120
- * @param {number[]|string} coordinates Array of coordinates
122
+ * @param {string | Coordinate} coordinatesOrString Array of coordinates or a string representing a station
121
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.
122
124
  * @param {number} [overwrite=0] Marks the number of viaPoints that are removed at the specified index on add.
123
125
  * @public
124
126
  */
125
127
  addViaPoint(coordinatesOrString: RoutingViaPoint, index?: number, overwrite?: number): void;
126
128
  /**
127
- * Removes a viaPoint at the passed array index and redraws route
128
- * By default the last viaPoint is removed.
129
- * @param {number} index Integer representing the index of the viaPoint to delete.
130
- * @public
131
- */
132
- removeViaPoint(index?: number): void;
133
- /**
134
- * Replaces the current viaPoints with a new coordinate array.
135
- * @param {Array<Array<number>>} coordinateArray Array of nested coordinates
136
- * @public
137
- */
138
- setViaPoints(coordinateArray: Coordinate[]): void;
139
- /**
140
- * Removes all viaPoints, clears the source and triggers a change event
141
- * @public
129
+ * Define a default element.
130
+ *
131
+ * @private
142
132
  */
143
- reset(): void;
133
+ createDefaultElement(): void;
144
134
  /**
145
- * Aborts viapoint and route requests
135
+ * Create the interaction used to modify vertexes of features.
146
136
  * @private
147
137
  */
148
- abortRequests(): void;
138
+ createModifyInteraction(): void;
139
+ deactivate(): void;
149
140
  /**
150
141
  * Draws route on map using an array of coordinates:
151
142
  * If a single coordinate is passed a single point feature is added to map.
@@ -160,6 +151,11 @@ declare class RoutingControl extends Control {
160
151
  * @private
161
152
  */
162
153
  drawViaPoint(viaPoint: RoutingViaPoint, idx: number, abortController: AbortController): Promise<void | Feature<Geometry>> | Promise<Feature<Geometry> | null>;
154
+ /**
155
+ * Activet7deactivate the control when activ eproperty changes
156
+ * @private
157
+ */
158
+ onActiveChange(): void;
163
159
  /**
164
160
  * Used on click on map while control is active:
165
161
  * By default adds a viaPoint to the end of array.
@@ -167,12 +163,6 @@ declare class RoutingControl extends Control {
167
163
  * @private
168
164
  */
169
165
  onMapClick(evt: MapBrowserEvent<MouseEvent>): void;
170
- /**
171
- * Used on start of the modify interaction. Stores relevant data
172
- * in this.initialRouteDrag object
173
- * @private
174
- */
175
- onModifyStart(evt: ModifyEvent): void;
176
166
  /**
177
167
  * Used on end of the modify interaction. Resolves feature modification:
178
168
  * Line drag creates new viaPoint at the final coordinate of drag.
@@ -181,29 +171,43 @@ declare class RoutingControl extends Control {
181
171
  */
182
172
  onModifyEnd(evt: ModifyEvent): void | Promise<never>;
183
173
  /**
184
- * Define a default element.
185
- *
174
+ * Used on start of the modify interaction. Stores relevant data
175
+ * in this.initialRouteDrag object
186
176
  * @private
187
177
  */
188
- createDefaultElement(): void;
178
+ onModifyStart(evt: ModifyEvent): void;
189
179
  /**
190
- * Create the interaction used to modify vertexes of features.
180
+ * Remove click listener from map.
191
181
  * @private
192
182
  */
193
- createModifyInteraction(): void;
183
+ removeListeners(): void;
194
184
  /**
195
- * Add click listener to map.
196
- * @private
185
+ * Removes a viaPoint at the passed array index and redraws route
186
+ * By default the last viaPoint is removed.
187
+ * @param {number} index Integer representing the index of the viaPoint to delete.
188
+ * @public
197
189
  */
198
- addListeners(): void;
190
+ removeViaPoint(index?: number): void;
191
+ render(): void;
199
192
  /**
200
- * Remove click listener from map.
201
- * @private
193
+ * Removes all viaPoints, clears the source and triggers a change event
194
+ * @public
202
195
  */
203
- removeListeners(): void;
196
+ reset(): void;
204
197
  setMap(map: Map): void;
205
- activate(): void;
206
- deactivate(): void;
207
- render(): void;
198
+ /**
199
+ * Replaces the current viaPoints with a new coordinate array.
200
+ * @param {Array<Array<number>>} coordinateArray Array of nested coordinates
201
+ * @public
202
+ */
203
+ setViaPoints(coordinateArray: Coordinate[]): void;
204
+ get active(): boolean;
205
+ set active(newValue: boolean);
206
+ get loading(): boolean;
207
+ set loading(newValue: boolean);
208
+ get modify(): any;
209
+ set modify(newValue: any);
210
+ get mot(): RoutingMot;
211
+ set mot(newValue: RoutingMot);
208
212
  }
209
213
  export default RoutingControl;