mobility-toolbox-js 3.0.0-beta.2 → 3.0.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/api/HttpAPI.d.ts +20 -0
  2. package/api/HttpAPI.js +0 -11
  3. package/api/RealtimeAPI.d.ts +404 -0
  4. package/api/RealtimeAPI.js +342 -276
  5. package/api/RoutingAPI.d.ts +47 -0
  6. package/api/RoutingAPI.js +17 -7
  7. package/api/StopsAPI.d.ts +44 -0
  8. package/api/StopsAPI.js +16 -10
  9. package/api/WebSocketAPI.d.ts +147 -0
  10. package/api/WebSocketAPI.js +164 -164
  11. package/api/index.d.ts +3 -0
  12. package/api/index.js +1 -1
  13. package/api/typedefs.d.ts +76 -0
  14. package/api/typedefs.js +27 -42
  15. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  16. package/common/controls/StopFinderControlCommon.js +31 -31
  17. package/common/index.d.ts +2 -0
  18. package/common/index.js +1 -1
  19. package/common/mixins/RealtimeLayerMixin.d.ts +267 -0
  20. package/common/mixins/RealtimeLayerMixin.js +401 -393
  21. package/common/styles/index.d.ts +4 -0
  22. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  23. package/common/styles/realtimeDefaultStyle.js +6 -6
  24. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  25. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  26. package/common/styles/realtimeHeadingStyle.js +5 -5
  27. package/common/styles/realtimeSimpleStyle.d.ts +4 -0
  28. package/common/typedefs.d.ts +219 -0
  29. package/common/typedefs.js +7 -1
  30. package/common/utils/compareDepartures.d.ts +10 -0
  31. package/common/utils/compareDepartures.js +2 -2
  32. package/common/utils/constants.d.ts +5 -0
  33. package/common/utils/createCanvas.d.ts +10 -0
  34. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  35. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  36. package/common/utils/createRealtimeFilters.d.ts +12 -0
  37. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  38. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  39. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  40. package/common/utils/getLayersAsFlatArray.js +5 -1
  41. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  42. package/common/utils/getMapGlCopyrights.js +3 -3
  43. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  44. package/common/utils/getRealtimeModeSuffix.js +1 -0
  45. package/common/utils/getUrlWithParams.d.ts +8 -0
  46. package/common/utils/getVehiclePosition.d.ts +17 -0
  47. package/common/utils/getVehiclePosition.js +9 -3
  48. package/common/utils/index.d.ts +16 -0
  49. package/common/utils/realtimeConfig.d.ts +64 -0
  50. package/common/utils/removeDuplicate.d.ts +9 -0
  51. package/common/utils/renderTrajectories.d.ts +16 -0
  52. package/common/utils/renderTrajectories.js +6 -6
  53. package/common/utils/sortAndFilterDepartures.d.ts +15 -0
  54. package/common/utils/sortAndFilterDepartures.js +1 -1
  55. package/common/utils/sortByDelay.d.ts +3 -0
  56. package/common/utils/sortByDelay.js +5 -1
  57. package/common/utils/timeUtils.d.ts +23 -0
  58. package/common/utils/toMercatorExtent.d.ts +5 -0
  59. package/iife.d.ts +2 -0
  60. package/index.d.ts +9 -0
  61. package/maplibre/controls/CopyrightControl.d.ts +35 -0
  62. package/maplibre/controls/index.d.ts +1 -0
  63. package/maplibre/index.d.ts +5 -0
  64. package/maplibre/layers/Layer.d.ts +28 -0
  65. package/maplibre/layers/Layer.js +1 -1
  66. package/maplibre/layers/RealtimeLayer.d.ts +181 -0
  67. package/maplibre/layers/RealtimeLayer.js +29 -5
  68. package/maplibre/layers/index.d.ts +2 -0
  69. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  70. package/maplibre/utils/getSourceCoordinates.d.ts +7 -0
  71. package/maplibre/utils/getSourceCoordinates.js +5 -5
  72. package/maplibre/utils/index.d.ts +2 -0
  73. package/mbt.js +22103 -14430
  74. package/mbt.js.map +4 -4
  75. package/mbt.min.js +61 -58
  76. package/mbt.min.js.map +4 -4
  77. package/ol/controls/CopyrightControl.d.ts +31 -0
  78. package/ol/controls/CopyrightControl.js +18 -8
  79. package/ol/controls/RoutingControl.d.ts +202 -0
  80. package/ol/controls/RoutingControl.js +220 -219
  81. package/ol/controls/StopFinderControl.d.ts +37 -0
  82. package/ol/controls/StopFinderControl.js +4 -1
  83. package/ol/controls/index.d.ts +3 -0
  84. package/ol/index.d.ts +7 -0
  85. package/ol/index.js +1 -0
  86. package/ol/layers/Layer.d.ts +101 -0
  87. package/ol/layers/Layer.js +25 -0
  88. package/ol/layers/MaplibreLayer.d.ts +160 -0
  89. package/ol/layers/MaplibreLayer.js +97 -27
  90. package/ol/layers/MaplibreStyleLayer.d.ts +237 -0
  91. package/ol/layers/MaplibreStyleLayer.js +291 -267
  92. package/ol/layers/RealtimeLayer.d.ts +283 -0
  93. package/ol/layers/RealtimeLayer.js +143 -128
  94. package/ol/layers/VectorLayer.d.ts +18 -0
  95. package/ol/layers/VectorLayer.js +31 -0
  96. package/ol/layers/index.d.ts +5 -0
  97. package/ol/layers/index.js +3 -0
  98. package/ol/mixins/MobilityLayerMixin.d.ts +96 -0
  99. package/ol/mixins/MobilityLayerMixin.js +1 -4
  100. package/ol/mixins/PropertiesLayerMixin.d.ts +135 -0
  101. package/ol/mixins/PropertiesLayerMixin.js +112 -140
  102. package/ol/mixins/index.d.ts +1 -0
  103. package/ol/mixins/index.js +2 -0
  104. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
  105. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  106. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  107. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  108. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  109. package/ol/renderers/RealtimeLayerRenderer.js +58 -53
  110. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  111. package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
  112. package/ol/styles/index.d.ts +3 -0
  113. package/ol/styles/routingStyle.d.ts +4 -0
  114. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  115. package/ol/utils/getFeatureInfoAtCoordinate.js +12 -18
  116. package/ol/utils/index.d.ts +1 -0
  117. package/package.json +31 -31
  118. package/setupTests.d.ts +1 -0
  119. package/setupTests.js +3 -4
  120. package/types/common.d.ts +55 -48
  121. package/types/index.d.ts +1 -1
  122. package/types/realtime.d.ts +91 -93
  123. package/types/routing.d.ts +60 -60
  124. package/types/stops.d.ts +62 -62
  125. package/ol/layers/MapGlLayer.js +0 -142
@@ -0,0 +1,31 @@
1
+ import { MapEvent } from 'ol';
2
+ import Control, { Options } from 'ol/control/Control';
3
+ export type CopyrightControlOptions = Options & {
4
+ className?: 'string';
5
+ format?: (copyrights: string[]) => string;
6
+ };
7
+ /**
8
+ * Display layer's copyrights.
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-copyright">Openlayers copyright example</a>
23
+ *
24
+ * @extends {ol/control/Control}
25
+ */
26
+ declare class CopyrightControl extends Control {
27
+ format: (copyrights: string[]) => string;
28
+ constructor(options?: CopyrightControlOptions);
29
+ render({ frameState }: MapEvent): void;
30
+ }
31
+ export default CopyrightControl;
@@ -26,6 +26,11 @@ class CopyrightControl extends Control {
26
26
  const element = createDefaultCopyrightElement();
27
27
  element.className = options.className || 'mbt-copyright';
28
28
  super(Object.assign({ element }, options));
29
+ this.format =
30
+ options.format ||
31
+ ((copyrights) => {
32
+ return copyrights === null || copyrights === void 0 ? void 0 : copyrights.join(' | ');
33
+ });
29
34
  }
30
35
  render({ frameState }) {
31
36
  if (!frameState) {
@@ -35,18 +40,23 @@ class CopyrightControl extends Control {
35
40
  let copyrights = [];
36
41
  // This code loop comes mainly from ol.
37
42
  frameState === null || frameState === void 0 ? void 0 : frameState.layerStatesArray.forEach((layerState) => {
43
+ var _a;
38
44
  const { layer } = layerState;
39
- if (frameState &&
40
- inView(layerState, frameState.viewState) &&
41
- layer &&
42
- layer.getSource &&
43
- layer.getSource() &&
44
- layer.getSource().getAttributions()) {
45
- copyrights = copyrights.concat(layer.getSource().getAttributions()(frameState));
45
+ if (frameState && inView(layerState, frameState.viewState)) {
46
+ if ((_a = layer === null || layer === void 0 ? void 0 : layer.getSource()) === null || _a === void 0 ? void 0 : _a.getAttributions()) {
47
+ copyrights = copyrights.concat(layer.getSource().getAttributions()(frameState));
48
+ }
49
+ if (layer === null || layer === void 0 ? void 0 : layer.get('copyrights')) {
50
+ let copyProp = layer.get('copyrights');
51
+ copyProp = !Array.isArray(copyProp) ? [copyProp] : copyProp;
52
+ if (copyProp === null || copyProp === void 0 ? void 0 : copyProp.length) {
53
+ copyrights.push(...copyProp);
54
+ }
55
+ }
46
56
  }
47
57
  });
48
58
  const unique = removeDuplicate(copyrights) || [];
49
- this.element.innerHTML = unique.join(' | ');
59
+ this.element.innerHTML = this.format(unique);
50
60
  }
51
61
  }
52
62
  export default CopyrightControl;
@@ -0,0 +1,202 @@
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 { RoutingAPI } from '../../api';
10
+ import type { Map, MapBrowserEvent } from 'ol';
11
+ import type { Coordinate } from 'ol/coordinate';
12
+ import type { StyleLike } from 'ol/style/Style';
13
+ import type { RoutingGraph, RoutingMot, RoutingParameters, RoutingViaPoint } from '../../types';
14
+ export type RoutingControlOptions = {
15
+ active?: boolean;
16
+ apiKey?: string;
17
+ graphs?: RoutingGraph[];
18
+ modify?: boolean;
19
+ mot?: string;
20
+ onRouteError?: () => void;
21
+ routingApiParams?: RoutingParameters;
22
+ routingLayer?: VectorLayer<Feature>;
23
+ snapToClosestStation?: boolean;
24
+ stopsApiKey?: string;
25
+ stopsApiUrl?: string;
26
+ style?: StyleLike;
27
+ useRawViaPoints?: boolean;
28
+ } & Options;
29
+ export type AbotControllersByGraph = Record<string, AbortController>;
30
+ /**
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
+ *
33
+ * @example
34
+ * import { Map } from 'ol';
35
+ * import { RoutingControl } from 'mobility-toolbox-js/ol';
36
+ *
37
+ * const map = new Map({
38
+ * target: 'map'
39
+ * });
40
+ *
41
+ * const control = new RoutingControl();
42
+ *
43
+ * control.attachToMap(map)
44
+ *
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
+ * @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
+ * @classproperty {VectorLayer} routingLayer - Layer for adding route features.
54
+ * @classproperty {function} onRouteError - Callback on error.
55
+ * @classproperty {boolean} loading - True if the control is requesting the backend.
56
+ * @see <a href="/example/ol-routing">Openlayers routing example</a>
57
+ *
58
+ * @extends {Control}
59
+ * @implements {RoutingInterface}
60
+ * @public
61
+ */
62
+ declare class RoutingControl extends Control {
63
+ abortControllers: Record<string, AbortController>;
64
+ api?: RoutingAPI;
65
+ apiKey?: string;
66
+ cacheStationData: Record<string, Coordinate>;
67
+ format: GeoJSON;
68
+ graphs: RoutingGraph[];
69
+ graphsResolutions?: [number, number][];
70
+ initialRouteDrag?: {
71
+ oldRoute?: Feature<LineString>;
72
+ segmentIndex?: number;
73
+ viaPoint?: Feature<Point>;
74
+ };
75
+ map?: Map;
76
+ modifyInteraction?: Modify;
77
+ onMapClickKey?: EventsKey;
78
+ onRouteError: (error?: Error, control?: RoutingControl) => void;
79
+ routingApiParams?: RoutingParameters;
80
+ routingLayer?: VectorLayer<Feature>;
81
+ segments: Feature<LineString>[];
82
+ snapToClosestStation: boolean;
83
+ stopsApiKey?: string;
84
+ stopsApiUrl?: string;
85
+ useRawViaPoints: boolean;
86
+ viaPoints: RoutingViaPoint[];
87
+ constructor(options?: RoutingControlOptions);
88
+ /**
89
+ * Calculate at which resolutions corresponds each generalizations.
90
+ *
91
+ * @private
92
+ */
93
+ static getGraphsResolutions(graphs: RoutingGraph[], map: Map): [number, number][];
94
+ /**
95
+ * Aborts viapoint and route requests
96
+ * @private
97
+ */
98
+ abortRequests(): void;
99
+ activate(): void;
100
+ /**
101
+ * Add click listener to map.
102
+ * @private
103
+ */
104
+ addListeners(): void;
105
+ /**
106
+ * Adds/Replaces a viaPoint to the viaPoints array and redraws route:
107
+ * Adds a viaPoint at end of array by default.
108
+ * If an index is passed a viaPoint is added at the specified index.
109
+ * If an index is passed and overwrite x is > 0, x viaPoints at the specified
110
+ * index are replaced with a single new viaPoint.
111
+ * @param {number[]|string} coordinates Array of coordinates
112
+ * @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
+ * @param {number} [overwrite=0] Marks the number of viaPoints that are removed at the specified index on add.
114
+ * @public
115
+ */
116
+ addViaPoint(coordinatesOrString: RoutingViaPoint, index?: number, overwrite?: number): void;
117
+ /**
118
+ * Define a default element.
119
+ *
120
+ * @private
121
+ */
122
+ createDefaultElement(): void;
123
+ /**
124
+ * Create the interaction used to modify vertexes of features.
125
+ * @private
126
+ */
127
+ createModifyInteraction(): void;
128
+ deactivate(): void;
129
+ /**
130
+ * Draws route on map using an array of coordinates:
131
+ * If a single coordinate is passed a single point feature is added to map.
132
+ * If two or more coordinates are passed a request to the RoutingAPI fetches
133
+ * the route using the passed coordinates and the current mot.
134
+ * @private
135
+ */
136
+ drawRoute(): Promise<void | Feature<Geometry>> | Promise<Feature<Geometry> | null> | Promise<(void | never[])[]> | null;
137
+ /**
138
+ * Draw a via point. This function can parse all the possibilitiies
139
+ *
140
+ * @private
141
+ */
142
+ drawViaPoint(viaPoint: RoutingViaPoint, idx: number, abortController: AbortController): Promise<void | Feature<Geometry>> | Promise<Feature<Geometry> | null>;
143
+ /**
144
+ * Activet7deactivate the control when activ eproperty changes
145
+ * @private
146
+ */
147
+ onActiveChange(): void;
148
+ /**
149
+ * Used on click on map while control is active:
150
+ * By default adds a viaPoint to the end of array.
151
+ * If an existing viaPoint is clicked removes the clicked viaPoint.
152
+ * @private
153
+ */
154
+ onMapClick(evt: MapBrowserEvent<MouseEvent>): void;
155
+ /**
156
+ * Used on end of the modify interaction. Resolves feature modification:
157
+ * Line drag creates new viaPoint at the final coordinate of drag.
158
+ * Point drag replaces old viaPoint.
159
+ * @private
160
+ */
161
+ onModifyEnd(evt: ModifyEvent): void | Promise<never>;
162
+ /**
163
+ * Used on start of the modify interaction. Stores relevant data
164
+ * in this.initialRouteDrag object
165
+ * @private
166
+ */
167
+ onModifyStart(evt: ModifyEvent): void;
168
+ /**
169
+ * Remove click listener from map.
170
+ * @private
171
+ */
172
+ removeListeners(): void;
173
+ /**
174
+ * Removes a viaPoint at the passed array index and redraws route
175
+ * By default the last viaPoint is removed.
176
+ * @param {number} index Integer representing the index of the viaPoint to delete.
177
+ * @public
178
+ */
179
+ removeViaPoint(index?: number): void;
180
+ render(): void;
181
+ /**
182
+ * Removes all viaPoints, clears the source and triggers a change event
183
+ * @public
184
+ */
185
+ reset(): void;
186
+ setMap(map: Map): void;
187
+ /**
188
+ * Replaces the current viaPoints with a new coordinate array.
189
+ * @param {Array<Array<number>>} coordinateArray Array of nested coordinates
190
+ * @public
191
+ */
192
+ setViaPoints(coordinateArray: Coordinate[]): void;
193
+ get active(): boolean;
194
+ set active(newValue: boolean);
195
+ get loading(): boolean;
196
+ set loading(newValue: boolean);
197
+ get modify(): any;
198
+ set modify(newValue: any);
199
+ get mot(): RoutingMot;
200
+ set mot(newValue: RoutingMot);
201
+ }
202
+ export default RoutingControl;