mobility-toolbox-js 3.0.0-beta.9 → 3.0.1-beta.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 (87) hide show
  1. package/api/HttpAPI.d.ts +5 -16
  2. package/api/HttpAPI.js +0 -11
  3. package/api/RealtimeAPI.d.ts +221 -176
  4. package/api/RealtimeAPI.js +317 -258
  5. package/api/RoutingAPI.d.ts +21 -11
  6. package/api/RoutingAPI.js +17 -7
  7. package/api/StopsAPI.d.ts +20 -14
  8. package/api/StopsAPI.js +17 -11
  9. package/api/WebSocketAPI.d.ts +60 -66
  10. package/api/WebSocketAPI.js +164 -164
  11. package/api/index.js +1 -1
  12. package/api/typedefs.d.ts +0 -102
  13. package/api/typedefs.js +27 -42
  14. package/common/controls/StopFinderControlCommon.d.ts +12 -12
  15. package/common/controls/StopFinderControlCommon.js +31 -31
  16. package/common/index.d.ts +1 -1
  17. package/common/index.js +1 -1
  18. package/common/mixins/RealtimeLayerMixin.d.ts +157 -163
  19. package/common/mixins/RealtimeLayerMixin.js +401 -393
  20. package/common/styles/realtimeDefaultStyle.js +6 -6
  21. package/common/styles/realtimeHeadingStyle.js +5 -5
  22. package/common/typedefs.d.ts +13 -6
  23. package/common/typedefs.js +7 -1
  24. package/common/utils/compareDepartures.d.ts +2 -2
  25. package/common/utils/compareDepartures.js +2 -2
  26. package/common/utils/debounceWebsocketMessages.d.ts +1 -1
  27. package/common/utils/getMapGlCopyrights.d.ts +1 -1
  28. package/common/utils/getMapGlCopyrights.js +3 -3
  29. package/common/utils/getRealtimeModeSuffix.d.ts +1 -0
  30. package/common/utils/getRealtimeModeSuffix.js +1 -0
  31. package/common/utils/getVehiclePosition.d.ts +5 -4
  32. package/common/utils/getVehiclePosition.js +9 -3
  33. package/common/utils/renderTrajectories.d.ts +1 -1
  34. package/common/utils/renderTrajectories.js +6 -6
  35. package/common/utils/sortAndFilterDepartures.d.ts +1 -1
  36. package/common/utils/sortAndFilterDepartures.js +1 -1
  37. package/common/utils/sortByDelay.d.ts +2 -2
  38. package/common/utils/sortByDelay.js +5 -1
  39. package/maplibre/layers/Layer.d.ts +1 -1
  40. package/maplibre/layers/Layer.js +1 -1
  41. package/maplibre/layers/RealtimeLayer.d.ts +87 -66
  42. package/maplibre/layers/RealtimeLayer.js +30 -6
  43. package/maplibre/utils/getSourceCoordinates.js +5 -5
  44. package/mbt.js +20988 -13287
  45. package/mbt.js.map +4 -4
  46. package/mbt.min.js +61 -58
  47. package/mbt.min.js.map +4 -4
  48. package/ol/controls/RoutingControl.d.ts +82 -89
  49. package/ol/controls/RoutingControl.js +217 -219
  50. package/ol/controls/StopFinderControl.d.ts +3 -3
  51. package/ol/controls/StopFinderControl.js +2 -2
  52. package/ol/index.d.ts +1 -0
  53. package/ol/index.js +1 -0
  54. package/ol/layers/Layer.d.ts +101 -0
  55. package/ol/layers/Layer.js +25 -0
  56. package/ol/layers/MaplibreLayer.d.ts +121 -24
  57. package/ol/layers/MaplibreLayer.js +98 -27
  58. package/ol/layers/MaplibreStyleLayer.d.ts +93 -91
  59. package/ol/layers/MaplibreStyleLayer.js +281 -257
  60. package/ol/layers/RealtimeLayer.d.ts +119 -121
  61. package/ol/layers/RealtimeLayer.js +143 -134
  62. package/ol/layers/VectorLayer.d.ts +18 -0
  63. package/ol/layers/VectorLayer.js +32 -0
  64. package/ol/layers/index.d.ts +2 -0
  65. package/ol/layers/index.js +3 -0
  66. package/ol/mixins/MobilityLayerMixin.d.ts +32 -34
  67. package/ol/mixins/PropertiesLayerMixin.d.ts +60 -51
  68. package/ol/mixins/PropertiesLayerMixin.js +114 -79
  69. package/ol/mixins/index.d.ts +1 -0
  70. package/ol/mixins/index.js +2 -0
  71. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -20
  72. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  73. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +6 -6
  74. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  75. package/ol/renderers/RealtimeLayerRenderer.d.ts +6 -6
  76. package/ol/renderers/RealtimeLayerRenderer.js +56 -51
  77. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +1 -1
  78. package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
  79. package/package.json +31 -31
  80. package/setupTests.js +3 -4
  81. package/types/common.d.ts +55 -48
  82. package/types/index.d.ts +1 -1
  83. package/types/realtime.d.ts +91 -93
  84. package/types/routing.d.ts +60 -60
  85. package/types/stops.d.ts +62 -62
  86. package/ol/layers/MapGlLayer.d.ts +0 -144
  87. package/ol/layers/MapGlLayer.js +0 -144
@@ -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);
@@ -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
  }
@@ -1,6 +1,7 @@
1
1
  export default dummy;
2
2
  export type FilterFunction = Function;
3
3
  export type SortFunction = Function;
4
+ export type getMotsByZoomFunction = Function;
4
5
  export type ViewState = {
5
6
  /**
6
7
  * A time in ms.
@@ -13,11 +14,11 @@ export type ViewState = {
13
14
  /**
14
15
  * An Extent in mercator coordinates.
15
16
  */
16
- extent: any;
17
+ extent: number[4];
17
18
  /**
18
19
  * A size ([width, height]).
19
20
  */
20
- size: any;
21
+ size: number[2];
21
22
  /**
22
23
  * A rotation in radians.
23
24
  */
@@ -47,7 +48,7 @@ export type FeatureInfo = {
47
48
  /**
48
49
  * The coordinate where to find the featue.
49
50
  */
50
- coordinate: any;
51
+ coordinate: number[2];
51
52
  };
52
53
  export type MaplibreLayerOptions = {
53
54
  /**
@@ -61,7 +62,7 @@ export type MaplibreLayerOptions = {
61
62
  /**
62
63
  * Maplibre map options.
63
64
  */
64
- mapOptions: maplibregl.MapOptions;
65
+ mapLibreOptions: maplibregl.MapOptions;
65
66
  /**
66
67
  * geOps Maps api style.
67
68
  */
@@ -135,7 +136,7 @@ export type VehiclePosition = {
135
136
  /**
136
137
  * Coordinate of the vehicle position in Mercator .
137
138
  */
138
- coord: any;
139
+ coord: number[2];
139
140
  /**
140
141
  * An angle in radians representing the direction (from the true north) towards which the vehicle is facing.
141
142
  */
@@ -156,6 +157,12 @@ type dummy = ol;
156
157
  * @param {any} b Object b to compare.
157
158
  * @returns number
158
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
+ */
159
166
  /**
160
167
  * @typedef {Object} ViewState
161
168
  * @property {number|undefined} time A time in ms.
@@ -180,7 +187,7 @@ type dummy = ol;
180
187
  * @typedef {Object} MaplibreLayerOptions
181
188
  * @property {string} apiKey Access key for [geOps apis](https://developer.geops.io/).
182
189
  * @property {string} apiKeyName geOps Maps api key name.
183
- * @property {maplibregl.MapOptions} options.mapOptions Maplibre map options.
190
+ * @property {maplibregl.MapOptions} options.mapLibreOptions Maplibre map options.
184
191
  * @property {string} style geOps Maps api style.
185
192
  * @property {string} url geOps Maps api url.
186
193
  */
@@ -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
  */
@@ -1,8 +1,8 @@
1
1
  import { RealtimeDeparture } from '../../types';
2
2
  /**
3
3
  * Compare two given departures for sort alogithm,
4
- * @param {Departure} a First departure.
5
- * @param {Departure} b Second departure.
4
+ * @param {RealtimeDeparture} a First departure.
5
+ * @param {RealtimeDeparture} b Second departure.
6
6
  * @param {boolean} [sortByMinArrivalTime=false] Sort departures by arrival time.
7
7
  * @private
8
8
  */
@@ -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
  */
@@ -7,5 +7,5 @@ import type { WebSocketAPIMessageCallback } from '../../api/WebSocketAPI';
7
7
  * @param {number} [timeout = 100] debounce timeout in ms
8
8
  * @private
9
9
  */
10
- declare const debounceWebsocketMessages: (onUpdate: (objects: any[]) => void, getObjectId?: ((object: any) => string) | undefined, timeout?: number) => WebSocketAPIMessageCallback<any>;
10
+ declare const debounceWebsocketMessages: (onUpdate: (objects: any[]) => void, getObjectId?: (object: any) => string, timeout?: number) => WebSocketAPIMessageCallback<any>;
11
11
  export default debounceWebsocketMessages;
@@ -5,8 +5,8 @@ export interface Source {
5
5
  };
6
6
  }
7
7
  export interface SourceCache {
8
- used: boolean;
9
8
  getSource: () => Source;
9
+ used: boolean;
10
10
  }
11
11
  /**
12
12
  * Return the copyright a Maplibre map.
@@ -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
  }
@@ -3,6 +3,7 @@ import type { RealtimeModesType } from '../../api/RealtimeAPI';
3
3
  /**
4
4
  * Get the websocket channel suffix, depending on the current mode.
5
5
  * @param {String} mode Mode 'topographic' ou 'schematic'.
6
+ * @param {String[]} modes List of modes
6
7
  * @private
7
8
  */
8
9
  declare const getModeSuffix: (mode: RealtimeMode, modes: RealtimeModesType) => string;
@@ -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' : '';
@@ -1,8 +1,9 @@
1
1
  import { Coordinate } from 'ol/coordinate';
2
- export type VehiclePosition = {
2
+ import { RealtimeTrajectory } from '../../types';
3
+ export interface VehiclePosition {
3
4
  coord: Coordinate;
4
- rotation: number;
5
- };
5
+ rotation?: number;
6
+ }
6
7
  /**
7
8
  * Interpolate or not the vehicle position from a trajectory at a specific date.
8
9
  *
@@ -12,5 +13,5 @@ export type VehiclePosition = {
12
13
  * @returns {VehiclePosition}
13
14
  * @private
14
15
  */
15
- declare const getVehiclePosition: (now: number, trajectory: GeoJSONFeature, noInterpolate: boolean) => VehiclePosition;
16
+ declare const getVehiclePosition: (now: number, trajectory: RealtimeTrajectory, noInterpolate: boolean) => VehiclePosition;
16
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;
@@ -1,7 +1,7 @@
1
1
  import { AnyCanvas, RealtimeRenderState, RealtimeStyleFunction, RealtimeStyleOptions, RealtimeTrajectories, ViewState } from '../../types';
2
2
  /**
3
3
  * Draw all the trajectories available in a canvas.
4
- * @param {HTMLCanvas|HTMLOffscreenCanvas} The canvas where to draw the trajectories.
4
+ * @param {HTMLCanvas|HTMLOffscreenCanvas} canvas The canvas where to draw the trajectories.
5
5
  * @param {ViewState} trajectories An array of trajectories.
6
6
  * @param {Function} style A function that returns a canvas representing a vehicle of a specific trajectory.
7
7
  * @param {ViewState} viewState The view state of the map.
@@ -1,8 +1,8 @@
1
- import { compose, apply, create } from 'ol/transform';
1
+ import { apply, compose, create } from 'ol/transform';
2
2
  import getVehiclePosition from './getVehiclePosition';
3
3
  /**
4
4
  * Draw all the trajectories available in a canvas.
5
- * @param {HTMLCanvas|HTMLOffscreenCanvas} The canvas where to draw the trajectories.
5
+ * @param {HTMLCanvas|HTMLOffscreenCanvas} canvas The canvas where to draw the trajectories.
6
6
  * @param {ViewState} trajectories An array of trajectories.
7
7
  * @param {Function} style A function that returns a canvas representing a vehicle of a specific trajectory.
8
8
  * @param {ViewState} viewState The view state of the map.
@@ -17,13 +17,13 @@ const renderTrajectories = (canvas, trajectories, style, viewState, options) =>
17
17
  if (!canvas) {
18
18
  return { renderedTrajectories: [] };
19
19
  }
20
- const { time = Date.now(), size = [], center, resolution, rotation = 0, pixelRatio = 1, } = viewState;
20
+ const { center, pixelRatio = 1, resolution, rotation = 0, size = [], time = Date.now(), } = viewState;
21
21
  if (!resolution || !center) {
22
22
  return { renderedTrajectories: [] };
23
23
  }
24
- const { noInterpolate = false, hoverVehicleId, selectedVehicleId, filter, getScreenPixel = (pixel, viewStat) => (viewStat.zoom || 0) < 12
24
+ const { filter, getScreenPixel = (pixel, viewStat) => (viewStat.zoom || 0) < 12
25
25
  ? pixel.map((coord) => Math.floor(coord))
26
- : pixel, } = options;
26
+ : pixel, hoverVehicleId, noInterpolate = false, selectedVehicleId, } = options;
27
27
  const context = canvas.getContext('2d');
28
28
  context === null || context === void 0 ? void 0 : context.clearRect(0, 0, canvas.width, canvas.height);
29
29
  const [width, height] = size;
@@ -49,7 +49,7 @@ const renderTrajectories = (canvas, trajectories, style, viewState, options) =>
49
49
  continue;
50
50
  }
51
51
  // We simplify the trajectory object
52
- const { train_id: id, timeOffset } = trajectory.properties;
52
+ const { timeOffset, train_id: id } = trajectory.properties;
53
53
  // We set the rotation and the timeFraction of the trajectory (used by tralis).
54
54
  // if rotation === null that seems there is no rotation available.
55
55
  const { coord, rotation: rotationIcon } = getVehiclePosition(time - (timeOffset || 0), trajectory, noInterpolate);
@@ -8,7 +8,7 @@ import type { RealtimeDepartureExtended } from '../../types';
8
8
  *
9
9
  * @param {Object} depObject The object containing departures by id.
10
10
  * @param {boolean} [sortByMinArrivalTime=false] If true sort departures by arrival time.
11
- * @return {Array<Departure>} Return departures array.
11
+ * @return {RealtimeDeparture[]} Return departures array.
12
12
  * @private
13
13
  */
14
14
  declare const sortAndfilterDepartures: (depObject: RealtimeAPIDeparturesById, sortByMinArrivalTime?: boolean, maxDepartureAge?: number) => RealtimeDepartureExtended[];
@@ -7,7 +7,7 @@ import compareDepartures from './compareDepartures';
7
7
  *
8
8
  * @param {Object} depObject The object containing departures by id.
9
9
  * @param {boolean} [sortByMinArrivalTime=false] If true sort departures by arrival time.
10
- * @return {Array<Departure>} Return departures array.
10
+ * @return {RealtimeDeparture[]} Return departures array.
11
11
  * @private
12
12
  */
13
13
  const sortAndfilterDepartures = (depObject, sortByMinArrivalTime = false, maxDepartureAge = 30) => {
@@ -1,3 +1,3 @@
1
- /** @private */
2
- declare const sortByDelay: (traj1: GeoJSONFeature, traj2: GeoJSONFeature) => number;
1
+ import { RealtimeTrajectory } from '../../types';
2
+ declare const sortByDelay: (traj1: RealtimeTrajectory, traj2: RealtimeTrajectory) => number;
3
3
  export default sortByDelay;
@@ -1,4 +1,3 @@
1
- /** @private */
2
1
  const sortByDelay = (traj1, traj2) => {
3
2
  const props1 = traj1.properties;
4
3
  const props2 = traj2.properties;
@@ -10,12 +9,17 @@ const sortByDelay = (traj1, traj2) => {
10
9
  }
11
10
  // We put cancelled train inbetween green and yellow trains
12
11
  // >=180000ms corresponds to yellow train
12
+ // @ts-expect-error
13
13
  if (props1.cancelled && !props2.cancelled) {
14
+ // @ts-expect-error
14
15
  return props2.delay < 180000 ? -1 : 1;
15
16
  }
17
+ // @ts-expect-error
16
18
  if (props2.cancelled && !props1.cancelled) {
19
+ // @ts-expect-error
17
20
  return props1.delay < 180000 ? 1 : -1;
18
21
  }
22
+ // @ts-expect-error
19
23
  return props2.delay - props1.delay;
20
24
  };
21
25
  export default sortByDelay;
@@ -11,7 +11,7 @@ export type LayerOptions = {
11
11
  *
12
12
  * const layer = new Layer({ id:'MyLayer' });
13
13
  *
14
- * @implements {maplibregl.CustomLayer}
14
+ * @implements {maplibregl.CustomLayerInterface}
15
15
  * @extends {maplibregl.Evented}
16
16
  * @private
17
17
  */
@@ -8,7 +8,7 @@ import { Evented } from 'maplibre-gl';
8
8
  *
9
9
  * const layer = new Layer({ id:'MyLayer' });
10
10
  *
11
- * @implements {maplibregl.CustomLayer}
11
+ * @implements {maplibregl.CustomLayerInterface}
12
12
  * @extends {maplibregl.Evented}
13
13
  * @private
14
14
  */
@@ -6,96 +6,111 @@ export type RealtimeLayerOptions = LayerOptions & RealtimeLayerMixinOptions;
6
6
  declare const RealtimeLayer_base: {
7
7
  new (options: RealtimeLayerMixinOptions): {
8
8
  [x: string]: any;
9
+ [x: symbol]: any;
10
+ api: import("..").RealtimeAPI;
11
+ bboxParameters?: Record<string, boolean | boolean[] | number | number[] | string | string[]>;
12
+ canvas?: import("../../types").AnyCanvas;
13
+ debounceRenderTrajectories: (viewState: ViewState, noInterpolate?: boolean) => void;
9
14
  debug: boolean;
10
- trajectories?: {
11
- [key: string]: GeoJSONFeature;
12
- } | undefined;
13
- canvas?: import("../../types").AnyCanvas | undefined;
14
- mode: import("../../types").RealtimeMode;
15
- api: import("../../api/RealtimeAPI").default;
16
- tenant: string;
17
- bboxParameters?: {
18
- [index: string]: string | number | boolean | string[] | number[] | boolean[];
19
- } | undefined;
20
- time?: Date | undefined;
21
- live?: boolean | undefined;
22
- speed?: number | undefined;
23
- filter?: Function | undefined;
24
- sort?: Function | undefined;
25
- style?: import("../../types").RealtimeStyleFunction | undefined;
26
- styleOptions?: import("../../types").RealtimeStyleOptions | undefined;
27
- pixelRatio?: number | undefined;
28
- minZoomInterpolation: number;
15
+ filter?: import("../../common/typedefs").FilterFunction;
16
+ format: import("ol/format").GeoJSON;
17
+ generalizationLevel?: import("../../types").RealtimeGeneralizationLevel;
18
+ generalizationLevelByZoom: import("../../types").RealtimeGeneralizationLevel[];
19
+ getGeneralizationLevelByZoom: (zoom: number) => import("../../types").RealtimeGeneralizationLevel;
20
+ getMotsByZoom: (zoom: number) => import("../../types").RealtimeMot[];
21
+ getRenderTimeIntervalByZoom: (zoom: number) => number;
22
+ hoverVehicleId?: import("../../types").RealtimeTrainId;
29
23
  isUpdateBboxOnMoveEnd: boolean;
30
- hoverVehicleId?: string | undefined;
31
- selectedVehicleId?: string | undefined;
32
- renderState?: import("../../types").RealtimeRenderState | undefined;
33
- useRequestAnimationFrame?: boolean | undefined;
34
- useDebounce?: boolean | undefined;
35
- useThrottle?: boolean | undefined;
36
- mots?: import("../../types").RealtimeMot[] | undefined;
24
+ live?: boolean;
25
+ minZoomInterpolation: number;
26
+ mode: import("../../types").RealtimeMode;
27
+ mots?: import("../../types").RealtimeMot[];
37
28
  motsByZoom: import("../../types").RealtimeMot[][];
38
- generalizationLevel?: import("../../types").RealtimeGeneralizationLevel | undefined;
39
- generalizationLevelByZoom: import("../../types").RealtimeGeneralizationLevel[];
29
+ onStart?: ((realtimeLayer: import("../../types").AnyLayer) => void) | undefined;
30
+ onStop?: ((realtimeLayer: import("../../types").AnyLayer) => void) | undefined;
31
+ pixelRatio?: number;
32
+ renderState?: import("../../types").RealtimeRenderState;
40
33
  renderTimeIntervalByZoom: number[];
41
- format: import("ol/format/GeoJSON").default<typeof import("ol/Feature").default>;
42
- requestId?: number | undefined;
43
- updateTimeInterval?: number | undefined;
44
- updateTimeDelay?: number | undefined;
34
+ requestId?: number;
35
+ selectedVehicle: import("../../types").RealtimeTrajectory;
36
+ selectedVehicleId?: import("../../types").RealtimeTrainId;
37
+ sort?: import("../../common/typedefs").SortFunction;
38
+ speed?: number;
39
+ style?: import("../../types").RealtimeStyleFunction;
40
+ styleOptions?: import("../../types").RealtimeStyleOptions;
41
+ tenant: import("../../types").RealtimeTenant;
42
+ throttleRenderTrajectories: (viewState: ViewState, noInterpolate?: boolean) => void;
43
+ time?: Date;
44
+ trajectories?: Record<import("../../types").RealtimeTrainId, import("../../types").RealtimeTrajectory>;
45
+ updateTimeDelay?: number;
46
+ updateTimeInterval?: number;
47
+ useDebounce?: boolean;
48
+ useRequestAnimationFrame?: boolean;
49
+ useThrottle?: boolean;
45
50
  visibilityRef: import("ol/events").EventsKey;
46
- selectedVehicle: GeoJSONFeature;
47
- getMotsByZoom: (zoom: number) => import("../../types").RealtimeMot[];
48
- getGeneralizationLevelByZoom: (zoom: number) => import("../../types").RealtimeGeneralizationLevel;
49
- getRenderTimeIntervalByZoom: (zoom: number) => number;
50
- throttleRenderTrajectories: (viewState: ViewState, noInterpolate?: boolean | undefined) => void;
51
- debounceRenderTrajectories: (viewState: ViewState, noInterpolate?: boolean | undefined) => void;
52
- onStart?: ((realtimeLayer: any) => void) | undefined;
53
- onStop?: ((realtimeLayer: any) => void) | undefined;
51
+ addTrajectory(trajectory: import("../../types").RealtimeTrajectory): void;
52
+ attachToMap(map: import("../../types").AnyMap): void;
54
53
  defineProperties(options: RealtimeLayerMixinOptions): void;
55
- attachToMap(map: any): void;
56
54
  detachFromMap(): void;
55
+ getFeatureInfoAtCoordinate(coordinate: import("ol/coordinate").Coordinate, options: import("../../types").LayerGetFeatureInfoOptions): Promise<import("../../types").LayerGetFeatureInfoResponse>;
56
+ getRefreshTimeInMs(zoom?: number | undefined): number;
57
+ getTrajectoryInfos(id: import("../../types").RealtimeTrainId): Promise<{
58
+ fullTrajectory: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeStopSequence[]> | import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory>;
59
+ stopSequence: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeStopSequence[]> | import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory>;
60
+ }>;
61
+ getVehicle(filterFc: import("../../common/typedefs").FilterFunction): import("../../types").RealtimeTrajectory[];
62
+ highlightVehicle(id: import("../../types").RealtimeTrainId): void;
63
+ onDeleteTrajectoryMessage(data: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeTrainId>): void;
64
+ onDocumentVisibilityChange(): void;
65
+ onTrajectoryMessage(data: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeTrajectory>): void;
66
+ onZoomEnd(): void;
67
+ purgeOutOfDateTrajectories(): void;
68
+ purgeTrajectory(trajectory: import("../../types").RealtimeTrajectory, extent: [number, number, number, number], zoom: number): boolean;
69
+ removeTrajectory(trajectoryOrId: import("../../types").RealtimeTrainId | import("../../types").RealtimeTrajectory): void;
70
+ renderTrajectories(viewState: undefined | ViewState, noInterpolate: boolean | undefined): void;
71
+ renderTrajectoriesInternal(viewState: ViewState, noInterpolate?: boolean): boolean;
72
+ selectVehicle(id: import("../../types").RealtimeTrainId): void;
73
+ setBbox(extent: [number, number, number, number], zoom: number): void;
57
74
  start(): void;
58
75
  startUpdateTime(): void;
59
76
  stop(): void;
60
77
  stopUpdateTime(): void;
61
- renderTrajectoriesInternal(viewState: ViewState, noInterpolate?: boolean): boolean;
62
- renderTrajectories(viewState: ViewState | undefined, noInterpolate: boolean | undefined): void;
63
- setBbox(extent: [number, number, number, number], zoom: number): void;
64
- getRefreshTimeInMs(zoom?: number | undefined): number;
65
- getVehicle(filterFc: Function): GeoJSONFeature[];
66
- getFeatureInfoAtCoordinate(coordinate: import("ol/coordinate").Coordinate, options: import("../../types").LayerGetFeatureInfoOptions): Promise<import("../../types").LayerGetFeatureInfoResponse>;
67
- getTrajectoryInfos(id: string): Promise<{
68
- stopSequence: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory> | import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<GeoJSONFeature[]>;
69
- fullTrajectory: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory> | import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<GeoJSONFeature[]>;
70
- }>;
71
- purgeOutOfDateTrajectories(): void;
72
- purgeTrajectory(trajectory: GeoJSONFeature, extent: [number, number, number, number], zoom: number): boolean;
73
- addTrajectory(trajectory: GeoJSONFeature): void;
74
- removeTrajectory(trajectoryOrId: any): void;
75
- onZoomEnd(): void;
76
- onDocumentVisibilityChange(): void;
77
- onTrajectoryMessage(data: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<GeoJSONFeature>): void;
78
- onDeleteTrajectoryMessage(data: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<string>): void;
79
- highlightVehicle(id: string): void;
80
- selectVehicle(id: string): void;
81
78
  };
82
79
  } & typeof Layer;
83
80
  /**
84
- * Responsible for loading and display data from a geOps realtime API.
81
+ * A Maplibre layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
85
82
  *
86
83
  * @example
87
- * import { RealtimeLayer } from 'mobility-toolbox-js/Maplibre';
84
+ * import { Map } from 'maplibre-gl';
85
+ * import { RealtimeLayer } from 'mobility-toolbox-js/maplibre';
88
86
  *
87
+ * // Define the map
88
+ * const map = new Map({ ... });
89
+ *
90
+ * // Define your layer map
89
91
  * const layer = new RealtimeLayer({
90
92
  * apiKey: "yourApiKey"
91
93
  * // url: "wss://api.geops.io/tracker-ws/v1/",
92
94
  * });
93
95
  *
96
+ * // Add the layer to your map *
97
+ * map.on('load', () => {
98
+ * map.addLayer(layer);
99
+ * });
100
+ *
94
101
  *
95
102
  * @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
103
+ * @see <a href="/example/mb-realtime>Live example</a>
96
104
  *
97
- * @implements {maplibregl.CustomLayer}
105
+ * @implements {maplibregl.CustomLayerInterface}
98
106
  * @extends {maplibregl.Evented}
107
+ * @classproperty {function} filter - Filter out a train. This function must be fast, it is executed for every trajectory on every render frame.
108
+ * @classproperty {RealtimeMode} mode - The realtime mode to use.
109
+ * @classproperty {RealtimeMot[]} mots - Filter trains by its mode of transportation. It filters trains on backend side.
110
+ * @classproperty {RealtimeTenant} tenant - Filter trains by its tenant. It filters trains on backend side.
111
+ * @classproperty {function} sort - Sort trains. This function must be fast, it is executed on every render frame.
112
+ * @classproperty {function} style - Function to style the vehicles.
113
+ s
99
114
  * @public
100
115
  */
101
116
  declare class RealtimeLayer extends RealtimeLayer_base {
@@ -104,8 +119,14 @@ declare class RealtimeLayer extends RealtimeLayer_base {
104
119
  *
105
120
  * @param {RealtimeLayerOptions} options
106
121
  * @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
107
- * @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps realtime API url.
108
- *
122
+ * @param {FilterFunction} options.filter Filter out a train. This function must be fast, it is executed for every trajectory on every render frame.
123
+ * @param {getMotsByZoomFunction} options.getMotsByZoom Returns for each zoom level the list of MOTs to display. It filters trains on backend side.
124
+ * @param {number} [options.minZoomInterpolation=8] Minimal zoom level where to start to interpolate train positions.
125
+ * @param {RealtimeMode} [options.mode='topographic'] The realtime mode to use.
126
+ * @param {SortFunction} options.sort Sort trains. This function must be fast, it is executed on every render frame.
127
+ * @param {RealtimeStyleFunction} options.style Function to style the vehicles.
128
+ * @param {RealtimeTenant} options.tenant Filter trains by its tenant. It filters trains on backend side.
129
+ * @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps Realtime API url.
109
130
  */
110
131
  constructor(options?: {});
111
132
  /**