mobility-toolbox-js 3.0.0-beta.8 → 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 (130) hide show
  1. package/README.md +11 -3
  2. package/api/HttpAPI.d.ts +20 -0
  3. package/api/HttpAPI.js +1 -14
  4. package/api/RealtimeAPI.d.ts +404 -0
  5. package/api/RealtimeAPI.js +265 -206
  6. package/api/RoutingAPI.d.ts +47 -0
  7. package/api/RoutingAPI.js +17 -7
  8. package/api/StopsAPI.d.ts +44 -0
  9. package/api/StopsAPI.js +17 -11
  10. package/api/WebSocketAPI.d.ts +147 -0
  11. package/api/WebSocketAPI.js +164 -165
  12. package/api/index.d.ts +3 -0
  13. package/api/index.js +1 -1
  14. package/api/typedefs.d.ts +76 -0
  15. package/api/typedefs.js +27 -42
  16. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  17. package/common/controls/StopFinderControlCommon.js +32 -32
  18. package/common/index.d.ts +2 -0
  19. package/common/index.js +1 -1
  20. package/common/styles/index.d.ts +4 -0
  21. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  22. package/common/styles/realtimeDefaultStyle.js +6 -11
  23. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  24. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  25. package/common/styles/realtimeHeadingStyle.js +5 -10
  26. package/common/styles/realtimeSimpleStyle.d.ts +3 -0
  27. package/common/styles/realtimeSimpleStyle.js +0 -1
  28. package/common/typedefs.d.ts +102 -0
  29. package/common/typedefs.js +6 -31
  30. package/common/utils/RealtimeEngine.d.ts +214 -0
  31. package/common/utils/RealtimeEngine.js +554 -0
  32. package/common/utils/compareDepartures.d.ts +10 -0
  33. package/common/utils/compareDepartures.js +2 -2
  34. package/common/utils/constants.d.ts +5 -0
  35. package/common/utils/createCanvas.d.ts +10 -0
  36. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  37. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  38. package/common/utils/createRealtimeFilters.d.ts +12 -0
  39. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  40. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  41. package/common/utils/getLayersAsFlatArray.d.ts +2 -0
  42. package/common/utils/getLayersAsFlatArray.js +0 -1
  43. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  44. package/common/utils/getMapGlCopyrights.js +3 -3
  45. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  46. package/common/utils/getRealtimeModeSuffix.js +1 -0
  47. package/common/utils/getUrlWithParams.d.ts +8 -0
  48. package/common/utils/getVehiclePosition.d.ts +17 -0
  49. package/common/utils/getVehiclePosition.js +6 -3
  50. package/common/utils/index.d.ts +16 -0
  51. package/common/utils/realtimeConfig.d.ts +64 -0
  52. package/common/utils/realtimeConfig.js +0 -1
  53. package/common/utils/removeDuplicate.d.ts +9 -0
  54. package/common/utils/renderTrajectories.d.ts +17 -0
  55. package/common/utils/renderTrajectories.js +7 -6
  56. package/common/utils/sortAndFilterDepartures.d.ts +16 -0
  57. package/common/utils/sortAndFilterDepartures.js +2 -1
  58. package/common/utils/sortByDelay.d.ts +3 -0
  59. package/common/utils/sortByDelay.js +5 -1
  60. package/common/utils/timeUtils.d.ts +23 -0
  61. package/common/utils/toMercatorExtent.d.ts +5 -0
  62. package/iife.d.ts +2 -0
  63. package/index.d.ts +9 -0
  64. package/maplibre/controls/CopyrightControl.d.ts +38 -0
  65. package/maplibre/controls/CopyrightControl.js +11 -8
  66. package/maplibre/controls/index.d.ts +1 -0
  67. package/maplibre/index.d.ts +5 -0
  68. package/maplibre/layers/Layer.d.ts +29 -0
  69. package/maplibre/layers/Layer.js +2 -3
  70. package/maplibre/layers/RealtimeLayer.d.ts +124 -0
  71. package/maplibre/layers/RealtimeLayer.js +154 -118
  72. package/maplibre/layers/index.d.ts +2 -0
  73. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  74. package/maplibre/utils/getSourceCoordinates.d.ts +8 -0
  75. package/maplibre/utils/getSourceCoordinates.js +6 -5
  76. package/maplibre/utils/index.d.ts +2 -0
  77. package/mbt.js +14585 -14557
  78. package/mbt.js.map +4 -4
  79. package/mbt.min.js +75 -75
  80. package/mbt.min.js.map +4 -4
  81. package/ol/controls/CopyrightControl.d.ts +39 -0
  82. package/ol/controls/CopyrightControl.js +13 -5
  83. package/ol/controls/RoutingControl.d.ts +213 -0
  84. package/ol/controls/RoutingControl.js +250 -264
  85. package/ol/controls/StopFinderControl.d.ts +56 -0
  86. package/ol/controls/StopFinderControl.js +24 -5
  87. package/ol/controls/index.d.ts +3 -0
  88. package/ol/index.d.ts +6 -0
  89. package/ol/layers/Layer.d.ts +26 -0
  90. package/ol/layers/Layer.js +39 -0
  91. package/ol/layers/MaplibreLayer.d.ts +91 -0
  92. package/ol/layers/MaplibreLayer.js +154 -31
  93. package/ol/layers/MaplibreStyleLayer.d.ts +157 -0
  94. package/ol/layers/MaplibreStyleLayer.js +281 -210
  95. package/ol/layers/RealtimeLayer.d.ts +150 -0
  96. package/ol/layers/RealtimeLayer.js +210 -206
  97. package/ol/layers/VectorLayer.d.ts +17 -0
  98. package/ol/layers/VectorLayer.js +33 -0
  99. package/ol/layers/index.d.ts +5 -0
  100. package/ol/layers/index.js +3 -0
  101. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
  102. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  103. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  104. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  105. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  106. package/ol/renderers/RealtimeLayerRenderer.js +50 -70
  107. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  108. package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
  109. package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
  110. package/ol/styles/fullTrajectoryStyle.js +5 -7
  111. package/ol/styles/index.d.ts +3 -0
  112. package/ol/styles/routingStyle.d.ts +3 -0
  113. package/ol/styles/routingStyle.js +13 -10
  114. package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
  115. package/ol/utils/defineDeprecatedProperties.js +180 -0
  116. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  117. package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
  118. package/ol/utils/index.d.ts +1 -0
  119. package/package.json +44 -44
  120. package/setupTests.d.ts +1 -0
  121. package/setupTests.js +17 -4
  122. package/types/common.d.ts +53 -69
  123. package/types/index.d.ts +1 -1
  124. package/types/realtime.d.ts +98 -95
  125. package/types/routing.d.ts +60 -60
  126. package/types/stops.d.ts +62 -62
  127. package/common/mixins/RealtimeLayerMixin.js +0 -743
  128. package/ol/layers/MapGlLayer.js +0 -142
  129. package/ol/mixins/MobilityLayerMixin.js +0 -9
  130. package/ol/mixins/PropertiesLayerMixin.js +0 -142
@@ -0,0 +1,39 @@
1
+ import { MapEvent } from 'ol';
2
+ import Control, { Options } from 'ol/control/Control';
3
+ export type CopyrightControlOptions = {
4
+ className?: 'string';
5
+ format?: (copyrights: string[]) => string;
6
+ } & Options;
7
+ /**
8
+ * Display layer's copyrights. Adding the possibility to format them as you wish.
9
+ *
10
+ * @example
11
+ * import { Map } from 'ol';
12
+ * import { CopyrightControl } from 'mobility-toolbox-js/ol';
13
+ *
14
+ * const map = new Map({
15
+ * target: 'map',
16
+ * });
17
+ *
18
+ * const control = new CopyrightControl();
19
+ * map.addControl(control);
20
+ *
21
+ *
22
+ * @see <a href="/example/ol-realtime>OpenLayers Realtime layer example</a>
23
+ *
24
+ * @extends {ol/control/Control~Control}
25
+ *
26
+ */
27
+ declare class CopyrightControl extends Control {
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
+ */
36
+ constructor(options?: CopyrightControlOptions);
37
+ render({ frameState }: MapEvent): void;
38
+ }
39
+ export default CopyrightControl;
@@ -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';
@@ -0,0 +1,213 @@
1
+ import { Feature } from 'ol';
2
+ import Control, { Options } from 'ol/control/Control';
3
+ import { EventsKey } from 'ol/events';
4
+ import { GeoJSON } from 'ol/format';
5
+ import { Geometry, LineString, Point } from 'ol/geom';
6
+ import { Modify } from 'ol/interaction';
7
+ import { ModifyEvent } from 'ol/interaction/Modify';
8
+ import VectorLayer from 'ol/layer/Vector';
9
+ import VectorSource from 'ol/source/Vector';
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
+ import type { RoutingGraph, RoutingMot, RoutingParameters, RoutingViaPoint } from '../../types';
15
+ export type RoutingControlOptions = {
16
+ active?: boolean;
17
+ apiKey?: string;
18
+ apiParams?: RoutingParameters;
19
+ graphs?: RoutingGraph[];
20
+ modify?: boolean;
21
+ mot?: string;
22
+ onRouteError?: () => void;
23
+ routingLayer?: VectorLayer<VectorSource>;
24
+ snapToClosestStation?: boolean;
25
+ stopsApiKey?: string;
26
+ stopsApiUrl?: string;
27
+ style?: StyleLike;
28
+ useRawViaPoints?: boolean;
29
+ } & Options;
30
+ export type AbortControllersByGraph = Record<string, AbortController>;
31
+ /**
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/).
34
+ *
35
+ * @example
36
+ * import { Map } from 'ol';
37
+ * import { RoutingControl } from 'mobility-toolbox-js/ol';
38
+ *
39
+ * const map = new Map({
40
+ * target: 'map'
41
+ * });
42
+ *
43
+ * const control = new RoutingControl();
44
+ *
45
+ * map.addControl(control);
46
+ *
47
+ * @classproperty {string} mot - Mean of transport to be used for routing.
48
+ * @classproperty {VectorLayer} routingLayer - Layer for adding route features.
49
+ * @classproperty {boolean} loading - True if the control is requesting the backend.
50
+ *
51
+ * @see <a href="/example/ol-routing">Openlayers routing example</a>
52
+ *
53
+ * @extends {ol/control/Control~Control}
54
+ *
55
+ * @public
56
+ */
57
+ declare class RoutingControl extends Control {
58
+ abortControllers: Record<string, AbortController>;
59
+ api?: RoutingAPI;
60
+ apiKey?: string;
61
+ apiParams?: RoutingParameters;
62
+ cacheStationData: Record<string, Coordinate>;
63
+ format: GeoJSON;
64
+ graphs: RoutingGraph[];
65
+ graphsResolutions?: [number, number][];
66
+ initialRouteDrag?: {
67
+ oldRoute?: Feature<LineString>;
68
+ segmentIndex?: number;
69
+ viaPoint?: Feature<Point>;
70
+ };
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
+ */
98
+ constructor(options?: RoutingControlOptions);
99
+ /**
100
+ * Calculate at which resolutions corresponds each generalizations.
101
+ *
102
+ * @private
103
+ */
104
+ static getGraphsResolutions(graphs: RoutingGraph[], map: Map): [number, number][];
105
+ /**
106
+ * Aborts viapoint and route requests
107
+ * @private
108
+ */
109
+ abortRequests(): void;
110
+ activate(): void;
111
+ /**
112
+ * Add click listener to map.
113
+ * @private
114
+ */
115
+ addListeners(): void;
116
+ /**
117
+ * Adds/Replaces a viaPoint to the viaPoints array and redraws route:
118
+ * Adds a viaPoint at end of array by default.
119
+ * If an index is passed a viaPoint is added at the specified index.
120
+ * If an index is passed and overwrite x is > 0, x viaPoints at the specified
121
+ * index are replaced with a single new viaPoint.
122
+ * @param {string | Coordinate} coordinatesOrString Array of coordinates or a string representing a station
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.
124
+ * @param {number} [overwrite=0] Marks the number of viaPoints that are removed at the specified index on add.
125
+ * @public
126
+ */
127
+ addViaPoint(coordinatesOrString: RoutingViaPoint, index?: number, overwrite?: number): void;
128
+ /**
129
+ * Define a default element.
130
+ *
131
+ * @private
132
+ */
133
+ createDefaultElement(): void;
134
+ /**
135
+ * Create the interaction used to modify vertexes of features.
136
+ * @private
137
+ */
138
+ createModifyInteraction(): void;
139
+ deactivate(): void;
140
+ /**
141
+ * Draws route on map using an array of coordinates:
142
+ * If a single coordinate is passed a single point feature is added to map.
143
+ * If two or more coordinates are passed a request to the RoutingAPI fetches
144
+ * the route using the passed coordinates and the current mot.
145
+ * @private
146
+ */
147
+ drawRoute(): Promise<void | Feature<Geometry>> | Promise<Feature<Geometry> | null> | Promise<(void | never[])[]> | null;
148
+ /**
149
+ * Draw a via point. This function can parse all the possibilitiies
150
+ *
151
+ * @private
152
+ */
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;
159
+ /**
160
+ * Used on click on map while control is active:
161
+ * By default adds a viaPoint to the end of array.
162
+ * If an existing viaPoint is clicked removes the clicked viaPoint.
163
+ * @private
164
+ */
165
+ onMapClick(evt: MapBrowserEvent<MouseEvent>): void;
166
+ /**
167
+ * Used on end of the modify interaction. Resolves feature modification:
168
+ * Line drag creates new viaPoint at the final coordinate of drag.
169
+ * Point drag replaces old viaPoint.
170
+ * @private
171
+ */
172
+ onModifyEnd(evt: ModifyEvent): void | Promise<never>;
173
+ /**
174
+ * Used on start of the modify interaction. Stores relevant data
175
+ * in this.initialRouteDrag object
176
+ * @private
177
+ */
178
+ onModifyStart(evt: ModifyEvent): void;
179
+ /**
180
+ * Remove click listener from map.
181
+ * @private
182
+ */
183
+ removeListeners(): void;
184
+ /**
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
189
+ */
190
+ removeViaPoint(index?: number): void;
191
+ render(): void;
192
+ /**
193
+ * Removes all viaPoints, clears the source and triggers a change event
194
+ * @public
195
+ */
196
+ reset(): void;
197
+ setMap(map: Map): 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);
212
+ }
213
+ export default RoutingControl;