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

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 +344 -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 +22160 -14512
  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 +17 -0
  88. package/ol/layers/MaplibreLayer.d.ts +160 -0
  89. package/ol/layers/MaplibreLayer.js +88 -24
  90. package/ol/layers/MaplibreStyleLayer.d.ts +242 -0
  91. package/ol/layers/MaplibreStyleLayer.js +291 -265
  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 +98 -0
  99. package/ol/mixins/MobilityLayerMixin.js +1 -4
  100. package/ol/mixins/PropertiesLayerMixin.d.ts +135 -0
  101. package/ol/mixins/PropertiesLayerMixin.js +108 -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,4 @@
1
+ export { default as realtimeDefaultStyle } from "./realtimeDefaultStyle";
2
+ export { default as realtimeDelayStyle } from "./realtimeDelayStyle";
3
+ export { default as realtimeSimpleStyle } from "./realtimeSimpleStyle";
4
+ export * from "./realtimeDefaultStyle";
@@ -0,0 +1,36 @@
1
+ import type { RealtimeStyleFunction } from '../../types';
2
+ /**
3
+ * Draw circle delay background
4
+ *
5
+ * @private
6
+ */
7
+ export declare const getDelayBgCanvas: (origin: number, radius: number, color: string) => import("../../types").AnyCanvas | null;
8
+ /**
9
+ * Draw delay text
10
+ *
11
+ * @private
12
+ */
13
+ export declare const getDelayTextCanvas: (text: string, fontSize: number, font: string, delayColor: string, delayOutlineColor?: string, pixelRatio?: number) => import("../../types").AnyCanvas | null;
14
+ /**
15
+ * Draw colored circle with black border
16
+ *
17
+ * @private
18
+ */
19
+ export declare const getCircleCanvas: (origin: number, radius: number, color: string, hasStroke: boolean, hasDash: boolean, pixelRatio: number) => import("../../types").AnyCanvas | null;
20
+ /**
21
+ * Draw text in the circle
22
+ *
23
+ * @private
24
+ */
25
+ export declare const getTextCanvas: (text: string, origin: number, textSize: number, fillColor: string, strokeColor: string, hasStroke: boolean, pixelRatio: number, getTextFont: (fontSize: number, text?: string) => string) => import("../../types").AnyCanvas | null;
26
+ /**
27
+ * A tracker style that take in account the delay.
28
+ *
29
+ * @param {RealtimeTrajectory} trajectory The trajectory to render.
30
+ * @param {ViewState} viewState The view state of the map.
31
+ * @param {RealtimeStyleOptions} options Some options to change the rendering
32
+ * @return a canvas
33
+ * @private
34
+ */
35
+ declare const realtimeDefaultStyle: RealtimeStyleFunction;
36
+ export default realtimeDefaultStyle;
@@ -141,11 +141,11 @@ const cache = {};
141
141
  * @private
142
142
  */
143
143
  const realtimeDefaultStyle = (trajectory, viewState, options) => {
144
- const { hoverVehicleId, selectedVehicleId, useDelayStyle, delayOutlineColor = '#000', delayDisplay = 300000, getRadius = () => 0, getBgColor = () => '#000', getDelayColor = () => '#000', getDelayText = () => null, getDelayFont = (fontSize) => `bold ${fontSize}px arial, sans-serif`, getText = (text) => text, getTextFont = (fontSize) => `bold ${fontSize}px arial, sans-serif`, getTextColor = () => '#000', getTextSize = () => 14, getMaxRadiusForText = () => 10, getMaxRadiusForStrokeAndDelay = () => 7, } = options;
145
- const { zoom, pixelRatio = 1 } = viewState;
144
+ const { delayDisplay = 300000, delayOutlineColor = '#000', getBgColor = () => '#000', getDelayColor = () => '#000', getDelayFont = (fontSize) => `bold ${fontSize}px arial, sans-serif`, getDelayText = () => null, getMaxRadiusForStrokeAndDelay = () => 7, getMaxRadiusForText = () => 10, getRadius = () => 0, getText = (text) => text, getTextColor = () => '#000', getTextFont = (fontSize) => `bold ${fontSize}px arial, sans-serif`, getTextSize = () => 14, hoverVehicleId, selectedVehicleId, useDelayStyle, } = options;
145
+ const { pixelRatio = 1, zoom } = viewState;
146
146
  let { type } = trajectory.properties;
147
- const { train_id: id, line, delay, state, operator_provides_realtime_journey: operatorProvidesRealtime, } = trajectory.properties;
148
- let { name, text_color: textColor, color } = line || {};
147
+ const { delay, line, operator_provides_realtime_journey: operatorProvidesRealtime, state, train_id: id, } = trajectory.properties;
148
+ let { color, name, text_color: textColor } = line || {};
149
149
  name = getText(name);
150
150
  const cancelled = state === 'JOURNEY_CANCELLED';
151
151
  if (!type) {
@@ -157,10 +157,10 @@ const realtimeDefaultStyle = (trajectory, viewState, options) => {
157
157
  if (!textColor) {
158
158
  textColor = '#000000';
159
159
  }
160
- if (color && color[0] !== '#') {
160
+ if (color && !color.startsWith('#')) {
161
161
  color = `#${color}`;
162
162
  }
163
- if (textColor[0] !== '#') {
163
+ if (!textColor.startsWith('#')) {
164
164
  textColor = `#${textColor}`;
165
165
  }
166
166
  const z = Math.min(Math.floor(zoom || 1), 16);
@@ -0,0 +1,12 @@
1
+ import type { RealtimeStyleFunction } from '../../types';
2
+ /**
3
+ * A tracker style that display the delay as backgroundColor.
4
+ *
5
+ * @param {*} trajectory The trajectory to render.
6
+ * @param {*} viewState The view state of the map.
7
+ * @param {*} options Some options to change the rendering
8
+ * @return a canvas
9
+ * @private
10
+ */
11
+ declare const realtimeDelayStyle: RealtimeStyleFunction;
12
+ export default realtimeDelayStyle;
@@ -0,0 +1,12 @@
1
+ import type { RealtimeStyleFunction } from '../../types';
2
+ /**
3
+ * A tracker style that take in account the delay.
4
+ *
5
+ * @param {RealtimeTrajectory} trajectory The trajectory to render.
6
+ * @param {ViewState} viewState The view state of the map.
7
+ * @param {RealtimeStyleOptions} options Some options to change the rendering
8
+ * @return a canvas
9
+ * @private
10
+ */
11
+ declare const realtimeHeadingStyle: RealtimeStyleFunction;
12
+ export default realtimeHeadingStyle;
@@ -67,9 +67,8 @@ const getBufferArrowCanvas = (canvas, fillColor, rotation) => {
67
67
  * @private
68
68
  */
69
69
  const realtimeHeadingStyle = (trajectory, viewState, options) => {
70
- var _a, _b;
71
- // @ts-ignore
72
- const { rotation, type, line } = trajectory.properties;
70
+ // @ts-expect-error improve types
71
+ const { line, rotation, type } = trajectory.properties;
73
72
  const { color } = line || {};
74
73
  const canvas = realtimeDefaultStyle(trajectory, viewState, options);
75
74
  if (canvas && rotation !== null) {
@@ -78,8 +77,9 @@ const realtimeHeadingStyle = (trajectory, viewState, options) => {
78
77
  if (bufferArrow) {
79
78
  const bufferSize = (bufferArrow.width - canvas.width) / 2;
80
79
  const vehicleWithArrow = createCanvas(bufferArrow.width, bufferArrow.height);
81
- (_a = vehicleWithArrow === null || vehicleWithArrow === void 0 ? void 0 : vehicleWithArrow.getContext('2d')) === null || _a === void 0 ? void 0 : _a.drawImage(bufferArrow, 0, 0, bufferArrow.width, bufferArrow.height);
82
- (_b = vehicleWithArrow === null || vehicleWithArrow === void 0 ? void 0 : vehicleWithArrow.getContext('2d')) === null || _b === void 0 ? void 0 : _b.drawImage(canvas, bufferSize, bufferSize, canvas.width, canvas.height);
80
+ const context = vehicleWithArrow === null || vehicleWithArrow === void 0 ? void 0 : vehicleWithArrow.getContext('2d');
81
+ context === null || context === void 0 ? void 0 : context.drawImage(bufferArrow, 0, 0, bufferArrow.width, bufferArrow.height);
82
+ context === null || context === void 0 ? void 0 : context.drawImage(canvas, bufferSize, bufferSize, canvas.width, canvas.height);
83
83
  return vehicleWithArrow;
84
84
  }
85
85
  }
@@ -0,0 +1,4 @@
1
+ import type { RealtimeStyleFunction } from '../../types';
2
+ /** @private */
3
+ declare const realtimeSimpleStyle: RealtimeStyleFunction;
4
+ export default realtimeSimpleStyle;
@@ -0,0 +1,219 @@
1
+ export default dummy;
2
+ export type FilterFunction = Function;
3
+ export type SortFunction = Function;
4
+ export type getMotsByZoomFunction = Function;
5
+ export type ViewState = {
6
+ /**
7
+ * A time in ms.
8
+ */
9
+ time: number | undefined;
10
+ /**
11
+ * A center in mercator coordinate.
12
+ */
13
+ center: number[2] | undefined;
14
+ /**
15
+ * An Extent in mercator coordinates.
16
+ */
17
+ extent: number[4];
18
+ /**
19
+ * A size ([width, height]).
20
+ */
21
+ size: number[2];
22
+ /**
23
+ * A rotation in radians.
24
+ */
25
+ rotation: number;
26
+ /**
27
+ * A resolution.
28
+ */
29
+ resolution: number;
30
+ /**
31
+ * A zoom level.
32
+ */
33
+ zoom: number;
34
+ /**
35
+ * A pixel ratio.
36
+ */
37
+ pixelRatio: number | undefined;
38
+ };
39
+ export type FeatureInfo = {
40
+ /**
41
+ * A layer.
42
+ */
43
+ layer: Layer;
44
+ /**
45
+ * An array of features.
46
+ */
47
+ features: Feature[];
48
+ /**
49
+ * The coordinate where to find the featue.
50
+ */
51
+ coordinate: number[2];
52
+ };
53
+ export type MaplibreLayerOptions = {
54
+ /**
55
+ * Access key for [geOps apis](https://developer.geops.io/).
56
+ */
57
+ apiKey: string;
58
+ /**
59
+ * geOps Maps api key name.
60
+ */
61
+ apiKeyName: string;
62
+ /**
63
+ * Maplibre map options.
64
+ */
65
+ mapLibreOptions: maplibregl.MapOptions;
66
+ /**
67
+ * geOps Maps api style.
68
+ */
69
+ style: string;
70
+ /**
71
+ * geOps Maps api url.
72
+ */
73
+ url: string;
74
+ };
75
+ export type ControlCommonOptions = {
76
+ /**
77
+ * Whether the control is active or not.
78
+ */
79
+ active?: boolean | undefined;
80
+ /**
81
+ * The HTML element used to render the control.
82
+ */
83
+ element: HTMLElement;
84
+ /**
85
+ * The HTML element where to render the element property. Default is the map's element.
86
+ */
87
+ target: HTMLElement;
88
+ /**
89
+ * Render function called whenever the control needs to be rerendered.
90
+ */
91
+ render: Function;
92
+ };
93
+ export type LayerCommonOptions = {
94
+ /**
95
+ * Identifier of the layer. Must be unique.
96
+ */
97
+ key: string;
98
+ /**
99
+ * Name of the layer.
100
+ */
101
+ name: string;
102
+ /**
103
+ * Group of the layer.
104
+ */
105
+ group: string;
106
+ /**
107
+ * List of copyrights.
108
+ */
109
+ copyrights: string[];
110
+ /**
111
+ * List of children layers.
112
+ */
113
+ children: Layer[];
114
+ /**
115
+ * Define if the layer is currently display on the map.
116
+ */
117
+ visible: boolean;
118
+ /**
119
+ * Define if the layer is currently display on the map but can't be seen (extent, zoom ,data restrictions).
120
+ */
121
+ disabled: boolean;
122
+ /**
123
+ * Hit-detection tolerance in css pixels. Pixels inside the radius around the given position will be checked for features.
124
+ */
125
+ hittolerance: number;
126
+ /**
127
+ * - Custom properties.
128
+ */
129
+ properties: Object;
130
+ /**
131
+ * - The map used to display the layer.
132
+ */
133
+ map: AnyMap;
134
+ };
135
+ export type VehiclePosition = {
136
+ /**
137
+ * Coordinate of the vehicle position in Mercator .
138
+ */
139
+ coord: number[2];
140
+ /**
141
+ * An angle in radians representing the direction (from the true north) towards which the vehicle is facing.
142
+ */
143
+ rotation: number;
144
+ };
145
+ /**
146
+ * /Map~Map|maplibregl.Map} AnyMap
147
+ */
148
+ type dummy = ol;
149
+ /**
150
+ * @typedef {function} FilterFunction
151
+ * @param {Vehicle} vehicle Vehicle to filter.
152
+ * @returns boolean
153
+ */
154
+ /**
155
+ * @typedef {function} SortFunction
156
+ * @param {any} a Object a to compare.
157
+ * @param {any} b Object b to compare.
158
+ * @returns number
159
+ */
160
+ /**
161
+ * @typedef {function} getMotsByZoomFunction
162
+ * @param {number} zoom Curent zoom level.
163
+ * @param {RealtimeMot[][]} motsByZoom Default array of mots by zoom.
164
+ * @returns number
165
+ */
166
+ /**
167
+ * @typedef {Object} ViewState
168
+ * @property {number|undefined} time A time in ms.
169
+ * @property {number[2]|undefined} center A center in mercator coordinate.
170
+ * @property {number[4]} extent An Extent in mercator coordinates.
171
+ * @property {number[2]} size A size ([width, height]).
172
+ * @property {number} rotation A rotation in radians.
173
+ * @property {number} resolution A resolution.
174
+ * @property {number} zoom A zoom level.
175
+ * @property {number|undefined} pixelRatio A pixel ratio.
176
+ */
177
+ /**
178
+ * @typedef {Object} FeatureInfo
179
+ * @property {Layer} layer A layer.
180
+ * @property {Feature[]} features An array of features.
181
+ * @property {number[2]} coordinate The coordinate where to find the featue.
182
+ */
183
+ /**
184
+ * @typedef {ol/Map~Map|maplibregl.Map} AnyMap
185
+ */
186
+ /**
187
+ * @typedef {Object} MaplibreLayerOptions
188
+ * @property {string} apiKey Access key for [geOps apis](https://developer.geops.io/).
189
+ * @property {string} apiKeyName geOps Maps api key name.
190
+ * @property {maplibregl.MapOptions} options.mapLibreOptions Maplibre map options.
191
+ * @property {string} style geOps Maps api style.
192
+ * @property {string} url geOps Maps api url.
193
+ */
194
+ /**
195
+ * @typedef {Object} ControlCommonOptions
196
+ * @property {boolean} [active = true] Whether the control is active or not.
197
+ * @property {HTMLElement} element The HTML element used to render the control.
198
+ * @property {HTMLElement} target The HTML element where to render the element property. Default is the map's element.
199
+ * @property {function} render Render function called whenever the control needs to be rerendered.
200
+ */
201
+ /**
202
+ * @typedef {Object} LayerCommonOptions
203
+ * @property {string!} key Identifier of the layer. Must be unique.
204
+ * @property {string!} name Name of the layer.
205
+ * @property {string!} group Group of the layer.
206
+ * @property {string[]!} copyrights List of copyrights.
207
+ * @property {Layer[]!} children List of children layers.
208
+ * @property {boolean!} visible Define if the layer is currently display on the map.
209
+ * @property {boolean!} disabled Define if the layer is currently display on the map but can't be seen (extent, zoom ,data restrictions).
210
+ * @property {number!} hittolerance Hit-detection tolerance in css pixels. Pixels inside the radius around the given position will be checked for features.
211
+ * @property {Object!} properties - Custom properties.
212
+ * @property {AnyMap!} map - The map used to display the layer.
213
+ */
214
+ /**
215
+ * @typedef {Object} VehiclePosition
216
+ * @property {number[2]} coord Coordinate of the vehicle position in Mercator .
217
+ * @property {number!} rotation An angle in radians representing the direction (from the true north) towards which the vehicle is facing.
218
+ */
219
+ declare function dummy(): void;
@@ -9,6 +9,12 @@
9
9
  * @param {any} b Object b to compare.
10
10
  * @returns number
11
11
  */
12
+ /**
13
+ * @typedef {function} getMotsByZoomFunction
14
+ * @param {number} zoom Curent zoom level.
15
+ * @param {RealtimeMot[][]} motsByZoom Default array of mots by zoom.
16
+ * @returns number
17
+ */
12
18
  /**
13
19
  * @typedef {Object} ViewState
14
20
  * @property {number|undefined} time A time in ms.
@@ -33,7 +39,7 @@
33
39
  * @typedef {Object} MaplibreLayerOptions
34
40
  * @property {string} apiKey Access key for [geOps apis](https://developer.geops.io/).
35
41
  * @property {string} apiKeyName geOps Maps api key name.
36
- * @property {maplibregl.MapOptions} options.mapOptions Maplibre map options.
42
+ * @property {maplibregl.MapOptions} options.mapLibreOptions Maplibre map options.
37
43
  * @property {string} style geOps Maps api style.
38
44
  * @property {string} url geOps Maps api url.
39
45
  */
@@ -0,0 +1,10 @@
1
+ import { RealtimeDeparture } from '../../types';
2
+ /**
3
+ * Compare two given departures for sort alogithm,
4
+ * @param {RealtimeDeparture} a First departure.
5
+ * @param {RealtimeDeparture} b Second departure.
6
+ * @param {boolean} [sortByMinArrivalTime=false] Sort departures by arrival time.
7
+ * @private
8
+ */
9
+ declare const compareDepartures: (a: RealtimeDeparture, b: RealtimeDeparture, sortByMinArrivalTime?: boolean) => number;
10
+ export default compareDepartures;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Compare two given departures for sort alogithm,
3
- * @param {Departure} a First departure.
4
- * @param {Departure} b Second departure.
3
+ * @param {RealtimeDeparture} a First departure.
4
+ * @param {RealtimeDeparture} b Second departure.
5
5
  * @param {boolean} [sortByMinArrivalTime=false] Sort departures by arrival time.
6
6
  * @private
7
7
  */
@@ -0,0 +1,5 @@
1
+ export declare const VECTOR_TILE_FEATURE_PROPERTY = "vectorTileFeature";
2
+ declare const _default: {
3
+ VECTOR_TILE_FEATURE_PROPERTY: string;
4
+ };
5
+ export default _default;
@@ -0,0 +1,10 @@
1
+ import { AnyCanvas } from '../../types';
2
+ /**
3
+ * This function try to create a canvas element and return it.
4
+ * it uses document.createElement('canvas') if document is available
5
+ * or new OffscreenCanvas(width, height) if OffscreenCanvas is avalaible (for web worker)
6
+ * or it returns null if neither is available.
7
+ * @private
8
+ */
9
+ declare const createCanvas: (width: number, height: number) => AnyCanvas | null;
10
+ export default createCanvas;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @private
3
+ */
4
+ declare const createDefaultCopyrightElement: () => HTMLDivElement;
5
+ export default createDefaultCopyrightElement;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @private
3
+ */
4
+ declare const createDefaultStopFinderElement: () => HTMLDivElement;
5
+ export default createDefaultStopFinderElement;
@@ -0,0 +1,12 @@
1
+ import { RealtimeTrajectory } from '../../types';
2
+ /**
3
+ * Return a filter functions based on some parameters of a vehicle.
4
+ *
5
+ * @param {string|Array<string>} line - A list of vehicle's name to filter. Names can be separated by a comma. Ex: 'S1,S2,S3'
6
+ * @param {string|Array<string} route - A list of vehicle's route (contained in route_identifier property) to filter. Indentifiers can be separated by a comma. Ex: 'id1,id2,id3'
7
+ * @param {string|Array<string} operator A list of vehicle's operator to filter. Operators can be separated by a comma. Ex: 'SBB,DB'
8
+ * @param {Regexp} regexLine - A regex aplly of vehcile's name.
9
+ * @private
10
+ */
11
+ declare const createRealtimeFilters: (line: string | string[], route: string | string[], operator: string | string[], regexLine: string | string[]) => ((trajectory: RealtimeTrajectory) => boolean) | null;
12
+ export default createRealtimeFilters;
@@ -0,0 +1,12 @@
1
+ import type { RealtimeDeparture, RealtimeDepartureExtended } from '../../types';
2
+ import type { WebSocketAPIMessageCallback } from '../../api/WebSocketAPI';
3
+ /**
4
+ * This function returns a WebSocket api callback, and call the onDeparturesUpdate function with the list of current departures to display.
5
+ * @param {function(departures: RealtimeDeparture[])} onDeparturesUpdate callback when list of departures changes, called after 100 ms
6
+ * @param {boolean} [sortByMinArrivalTime = true] Sort departures by arrival time
7
+ * @param {number} [maxDepartureAge = 30] max departure age of departures in minutes
8
+ * @param {number} [timeout = 100] debounce timeout in ms
9
+ * @private
10
+ */
11
+ declare const debounceDeparturesMessages: (onDeparturesUpdate: (departures: RealtimeDepartureExtended[]) => {}, sortByMinArrivalTime?: boolean, maxDepartureAge?: number, timeout?: number) => WebSocketAPIMessageCallback<RealtimeDeparture>;
12
+ export default debounceDeparturesMessages;
@@ -0,0 +1,11 @@
1
+ import type { WebSocketAPIMessageCallback } from '../../api/WebSocketAPI';
2
+ /**
3
+ * This function returns a WebSocket api callback, and call the onUpdate function with the list of of subscribed objects changes.
4
+ *
5
+ * @param {function(objects: any[])} onUpdate callback when list of subscribed objects changes, called after 100 ms
6
+ * @param {function(object: any)} [getObjectId = true] function returning the id of an object
7
+ * @param {number} [timeout = 100] debounce timeout in ms
8
+ * @private
9
+ */
10
+ declare const debounceWebsocketMessages: (onUpdate: (objects: any[]) => void, getObjectId?: (object: any) => string, timeout?: number) => WebSocketAPIMessageCallback<any>;
11
+ export default debounceWebsocketMessages;
@@ -0,0 +1,3 @@
1
+ /** @private */
2
+ declare const getLayersAsFlatArray: (layersOrLayer: any | any[]) => any[];
3
+ export default getLayersAsFlatArray;
@@ -7,8 +7,12 @@ const getLayersAsFlatArray = (layersOrLayer) => {
7
7
  }
8
8
  let flatLayers = [];
9
9
  layers.forEach((layer) => {
10
+ var _a, _b;
10
11
  flatLayers.push(layer);
11
- const children = layer.children || layer.get('children') || {};
12
+ // Handle children property and ol.layer.Group
13
+ const children = layer.children ||
14
+ layer.get('children') ||
15
+ ((_b = (_a = layer.getLayers) === null || _a === void 0 ? void 0 : _a.call(layer)) === null || _b === void 0 ? void 0 : _b.getArray());
12
16
  flatLayers = flatLayers.concat(getLayersAsFlatArray(children || []));
13
17
  });
14
18
  return flatLayers;
@@ -0,0 +1,17 @@
1
+ export interface Source {
2
+ attribution: string;
3
+ options: {
4
+ attribution: string;
5
+ };
6
+ }
7
+ export interface SourceCache {
8
+ getSource: () => Source;
9
+ used: boolean;
10
+ }
11
+ /**
12
+ * Return the copyright a Maplibre map.
13
+ * @param {maplibregl.Map} map A Maplibre map
14
+ * @private
15
+ */
16
+ declare const getMapGlCopyrights: (map: maplibregl.Map) => any[];
17
+ export default getMapGlCopyrights;
@@ -8,7 +8,6 @@ const getMapGlCopyrights = (map) => {
8
8
  if (!map) {
9
9
  return [];
10
10
  }
11
- // @ts-ignore
12
11
  const { style } = map;
13
12
  if (!style) {
14
13
  return [];
@@ -16,10 +15,11 @@ const getMapGlCopyrights = (map) => {
16
15
  const { sourceCaches } = style;
17
16
  let copyrights = [];
18
17
  Object.values(sourceCaches).forEach((value) => {
18
+ var _a;
19
19
  if (value.used) {
20
20
  const source = value.getSource();
21
- const attribution = // @ts-ignore
22
- source.attribution || (source.options && source.options.attribution);
21
+ // @ts-expect-error improve types
22
+ const attribution = source.attribution || ((_a = source.options) === null || _a === void 0 ? void 0 : _a.attribution);
23
23
  if (attribution) {
24
24
  copyrights = copyrights.concat(attribution.replace(/&copy;/g, '©').split(/(<a.*?<\/a>)/));
25
25
  }
@@ -0,0 +1,10 @@
1
+ import type { RealtimeMode } from '../../types';
2
+ import type { RealtimeModesType } from '../../api/RealtimeAPI';
3
+ /**
4
+ * Get the websocket channel suffix, depending on the current mode.
5
+ * @param {String} mode Mode 'topographic' ou 'schematic'.
6
+ * @param {String[]} modes List of modes
7
+ * @private
8
+ */
9
+ declare const getModeSuffix: (mode: RealtimeMode, modes: RealtimeModesType) => string;
10
+ export default getModeSuffix;
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Get the websocket channel suffix, depending on the current mode.
3
3
  * @param {String} mode Mode 'topographic' ou 'schematic'.
4
+ * @param {String[]} modes List of modes
4
5
  * @private
5
6
  */
6
7
  const getModeSuffix = (mode, modes) => mode === modes.SCHEMATIC ? '_schematic' : '';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Return the styleUrl with apiKey parameters set.
3
+ * @param {string} url a url.
4
+ * @param {Object<String,String>} params a list of key/value pair to add to the url.
5
+ * @private
6
+ */
7
+ declare const getUrlWithParams: (url: string, params: Object) => URL;
8
+ export default getUrlWithParams;
@@ -0,0 +1,17 @@
1
+ import { Coordinate } from 'ol/coordinate';
2
+ import { RealtimeTrajectory } from '../../types';
3
+ export interface VehiclePosition {
4
+ coord: Coordinate;
5
+ rotation?: number;
6
+ }
7
+ /**
8
+ * Interpolate or not the vehicle position from a trajectory at a specific date.
9
+ *
10
+ * @param {number} now Current date to interpolate a position with. In ms.
11
+ * @param {RealtimeTrajectory} trajectory The trajectory to interpolate.
12
+ * @param {boolean} noInterpolate If true, the vehicle position is not interpolated on each render but only once.
13
+ * @returns {VehiclePosition}
14
+ * @private
15
+ */
16
+ declare const getVehiclePosition: (now: number, trajectory: RealtimeTrajectory, noInterpolate: boolean) => VehiclePosition;
17
+ export default getVehiclePosition;
@@ -9,14 +9,20 @@ import { LineString } from 'ol/geom';
9
9
  * @private
10
10
  */
11
11
  const getVehiclePosition = (now, trajectory, noInterpolate) => {
12
- const { time_intervals: timeIntervals, olGeometry, coordinate, } = trajectory.properties;
13
- const { coordinates } = trajectory.geometry;
14
- let { type } = trajectory.geometry;
12
+ const {
13
+ // @ts-expect-error coordinate is added by the RealtimeLayer
14
+ coordinate,
15
+ // @ts-expect-error olGeometry is added by the RealtimeLayer
16
+ olGeometry, time_intervals: timeIntervals, } = trajectory.properties;
17
+ // @ts-expect-error
18
+ let { coordinates, type } = trajectory.geometry;
15
19
  let geometry = olGeometry;
16
20
  let coord;
17
21
  let rotation;
22
+ // If an olGeometry exists we use it. It avoids to create one each time.
18
23
  if (olGeometry) {
19
24
  type = geometry.getType();
25
+ coordinates = geometry.getCoordinates();
20
26
  }
21
27
  if (noInterpolate && coordinate) {
22
28
  coord = coordinate;
@@ -0,0 +1,16 @@
1
+ export { default as getUrlWithParams } from "./getUrlWithParams";
2
+ export { default as getMapGlCopyrights } from "./getMapGlCopyrights";
3
+ export { default as removeDuplicate } from "./removeDuplicate";
4
+ export { default as createRealtimeFilters } from "./createRealtimeFilters";
5
+ export { default as getLayersAsFlatArray } from "./getLayersAsFlatArray";
6
+ export * from "./timeUtils";
7
+ export * from "./constants";
8
+ export { default as sortByDelay } from "./sortByDelay";
9
+ export { default as renderTrajectories } from "./renderTrajectories";
10
+ export { default as debounceDeparturesMessages } from "./debounceDeparturesMessages";
11
+ export { default as debounceWebsocketMessages } from "./debounceWebsocketMessages";
12
+ export { default as sortAndFilterDepartures } from "./sortAndFilterDepartures";
13
+ export { default as compareDepartures } from "./compareDepartures";
14
+ export { default as createCanvas } from "./createCanvas";
15
+ export { default as getVehiclePosition } from "./getVehiclePosition";
16
+ export * as realtimeConfig from "./realtimeConfig";