mobility-toolbox-js 3.0.0-beta.11 → 3.0.0-beta.13

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 (51) hide show
  1. package/api/RealtimeAPI.d.ts +28 -22
  2. package/api/RealtimeAPI.js +23 -16
  3. package/api/RoutingAPI.d.ts +16 -6
  4. package/api/RoutingAPI.js +16 -6
  5. package/api/StopsAPI.d.ts +3 -3
  6. package/api/StopsAPI.js +3 -3
  7. package/api/WebSocketAPI.d.ts +2 -2
  8. package/api/WebSocketAPI.js +2 -2
  9. package/api/typedefs.d.ts +0 -102
  10. package/api/typedefs.js +27 -42
  11. package/common/controls/StopFinderControlCommon.d.ts +1 -1
  12. package/common/controls/StopFinderControlCommon.js +1 -1
  13. package/common/mixins/RealtimeLayerMixin.d.ts +10 -11
  14. package/common/mixins/RealtimeLayerMixin.js +17 -9
  15. package/common/typedefs.d.ts +7 -0
  16. package/common/typedefs.js +6 -0
  17. package/common/utils/compareDepartures.d.ts +2 -2
  18. package/common/utils/compareDepartures.js +2 -2
  19. package/common/utils/getRealtimeModeSuffix.d.ts +1 -0
  20. package/common/utils/getRealtimeModeSuffix.js +1 -0
  21. package/common/utils/getVehiclePosition.d.ts +3 -2
  22. package/common/utils/getVehiclePosition.js +6 -1
  23. package/common/utils/renderTrajectories.d.ts +1 -1
  24. package/common/utils/renderTrajectories.js +1 -1
  25. package/common/utils/sortAndFilterDepartures.d.ts +1 -1
  26. package/common/utils/sortAndFilterDepartures.js +1 -1
  27. package/common/utils/sortByDelay.d.ts +2 -2
  28. package/common/utils/sortByDelay.js +5 -1
  29. package/maplibre/layers/Layer.d.ts +1 -1
  30. package/maplibre/layers/Layer.js +1 -1
  31. package/maplibre/layers/RealtimeLayer.d.ts +40 -11
  32. package/maplibre/layers/RealtimeLayer.js +27 -3
  33. package/mbt.js +86 -43
  34. package/mbt.js.map +4 -4
  35. package/mbt.min.js +13 -13
  36. package/mbt.min.js.map +4 -4
  37. package/ol/controls/RoutingControl.d.ts +1 -1
  38. package/ol/controls/RoutingControl.js +1 -1
  39. package/ol/index.d.ts +1 -0
  40. package/ol/index.js +1 -0
  41. package/ol/layers/Layer.d.ts +101 -0
  42. package/ol/layers/Layer.js +17 -0
  43. package/ol/layers/MaplibreLayer.d.ts +3 -3
  44. package/ol/layers/MaplibreLayer.js +3 -3
  45. package/ol/layers/RealtimeLayer.d.ts +15 -12
  46. package/ol/layers/index.d.ts +1 -0
  47. package/ol/layers/index.js +1 -0
  48. package/ol/mixins/index.d.ts +1 -0
  49. package/ol/mixins/index.js +2 -0
  50. package/ol/renderers/RealtimeLayerRenderer.js +4 -1
  51. package/package.json +1 -1
@@ -3,8 +3,7 @@ import { EventsKey } from 'ol/events';
3
3
  import { Coordinate } from 'ol/coordinate';
4
4
  import { Options } from 'ol/layer/Layer';
5
5
  import { RealtimeAPI } from '../../api';
6
- import { AnyCanvas, AnyLayerClass, AnyMap, AnyRealtimeLayer, LayerGetFeatureInfoOptions, RealtimeGeneralizationLevel, RealtimeMode, RealtimeMot, RealtimeRenderState, RealtimeStyleFunction, RealtimeStyleOptions, RealtimeTenant, RealtimeTrainId, ViewState, AnyLayer, LayerGetFeatureInfoResponse } from '../../types';
7
- import { RealtimeTrajectory } from '../../api/typedefs';
6
+ import { AnyCanvas, AnyLayerClass, AnyMap, AnyRealtimeLayer, LayerGetFeatureInfoOptions, RealtimeGeneralizationLevel, RealtimeMode, RealtimeMot, RealtimeRenderState, RealtimeStyleFunction, RealtimeStyleOptions, RealtimeTenant, RealtimeTrainId, ViewState, AnyLayer, LayerGetFeatureInfoResponse, RealtimeTrajectory } from '../../types';
8
7
  import { WebSocketAPIMessageEventData } from '../../api/WebSocketAPI';
9
8
  import { FilterFunction, SortFunction } from '../typedefs';
10
9
  export type RealtimeLayerMixinOptions = Options & {
@@ -75,7 +74,7 @@ export declare class RealtimeLayerInterface {
75
74
  *
76
75
  * @param {string} id The vehicle identifier (the train_id property).
77
76
  * @param {RealtimeMode} mode The mode to request. If not defined, the layer´s mode propetrty will be used.
78
- * @return {Promise<{stopSequence: StopSequence, fullTrajectory: FullTrajectory>} A promise that will be resolved with the trajectory informations.
77
+ * @return {Promise<{stopSequence: RealtimeStopSequence, fullTrajectory: RealtimeFullTrajectory>} A promise that will be resolved with the trajectory informations.
79
78
  */
80
79
  getTrajectoryInfos(id: string, mode: RealtimeMode): void;
81
80
  }
@@ -91,7 +90,7 @@ declare function RealtimeLayerMixin<T extends AnyLayerClass>(Base: T): {
91
90
  [x: string]: any;
92
91
  debug: boolean;
93
92
  trajectories?: {
94
- [key: string]: GeoJSONFeature;
93
+ [key: string]: RealtimeTrajectory;
95
94
  } | undefined;
96
95
  canvas?: AnyCanvas | undefined;
97
96
  mode: RealtimeMode;
@@ -126,7 +125,7 @@ declare function RealtimeLayerMixin<T extends AnyLayerClass>(Base: T): {
126
125
  updateTimeInterval?: number | undefined;
127
126
  updateTimeDelay?: number | undefined;
128
127
  visibilityRef: EventsKey;
129
- selectedVehicle: GeoJSONFeature;
128
+ selectedVehicle: RealtimeTrajectory;
130
129
  getMotsByZoom: (zoom: number) => RealtimeMot[];
131
130
  getGeneralizationLevelByZoom: (zoom: number) => RealtimeGeneralizationLevel;
132
131
  getRenderTimeIntervalByZoom: (zoom: number) => number;
@@ -198,7 +197,7 @@ declare function RealtimeLayerMixin<T extends AnyLayerClass>(Base: T): {
198
197
  * @param {function} filterFc A function use to filter results.
199
198
  * @return {Array<Object>} Array of vehicle.
200
199
  */
201
- getVehicle(filterFc: FilterFunction): GeoJSONFeature[];
200
+ getVehicle(filterFc: FilterFunction): RealtimeTrajectory[];
202
201
  /**
203
202
  * Request feature information for a given coordinate.
204
203
  *
@@ -213,11 +212,11 @@ declare function RealtimeLayerMixin<T extends AnyLayerClass>(Base: T): {
213
212
  * Request the stopSequence and the fullTrajectory informations for a vehicle.
214
213
  *
215
214
  * @param {string} id The vehicle identifier (the train_id property).
216
- * @return {Promise<{stopSequence: StopSequence, fullTrajectory: FullTrajectory>} A promise that will be resolved with the trajectory informations.
215
+ * @return {Promise<{stopSequence: RealtimeStopSequence, fullTrajectory: RealtimeFullTrajectory>} A promise that will be resolved with the trajectory informations.
217
216
  */
218
217
  getTrajectoryInfos(id: RealtimeTrainId): Promise<{
219
- stopSequence: WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory> | WebSocketAPIMessageEventData<GeoJSONFeature[]>;
220
- fullTrajectory: WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory> | WebSocketAPIMessageEventData<GeoJSONFeature[]>;
218
+ stopSequence: WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory> | WebSocketAPIMessageEventData<import("../../types").RealtimeStopSequence[]>;
219
+ fullTrajectory: WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory> | WebSocketAPIMessageEventData<import("../../types").RealtimeStopSequence[]>;
221
220
  }>;
222
221
  /**
223
222
  * Remove all trajectories that are in the past.
@@ -235,13 +234,13 @@ declare function RealtimeLayerMixin<T extends AnyLayerClass>(Base: T): {
235
234
  * @return {boolean} if the trajectory must be displayed or not.
236
235
  * @private
237
236
  */
238
- purgeTrajectory(trajectory: GeoJSONFeature, extent: [number, number, number, number], zoom: number): boolean;
237
+ purgeTrajectory(trajectory: RealtimeTrajectory, extent: [number, number, number, number], zoom: number): boolean;
239
238
  /**
240
239
  * Add a trajectory.
241
240
  * @param {RealtimeTrajectory} trajectory The trajectory to add.
242
241
  * @private
243
242
  */
244
- addTrajectory(trajectory: GeoJSONFeature): void;
243
+ addTrajectory(trajectory: RealtimeTrajectory): void;
245
244
  removeTrajectory(trajectoryOrId: RealtimeTrajectory | RealtimeTrainId): void;
246
245
  /**
247
246
  * On zoomend we adjust the time interval of the update of vehicles positions.
@@ -42,7 +42,7 @@ export class RealtimeLayerInterface {
42
42
  *
43
43
  * @param {string} id The vehicle identifier (the train_id property).
44
44
  * @param {RealtimeMode} mode The mode to request. If not defined, the layer´s mode propetrty will be used.
45
- * @return {Promise<{stopSequence: StopSequence, fullTrajectory: FullTrajectory>} A promise that will be resolved with the trajectory informations.
45
+ * @return {Promise<{stopSequence: RealtimeStopSequence, fullTrajectory: RealtimeFullTrajectory>} A promise that will be resolved with the trajectory informations.
46
46
  */
47
47
  getTrajectoryInfos(id, mode) { }
48
48
  }
@@ -551,8 +551,9 @@ function RealtimeLayerMixin(Base) {
551
551
  }
552
552
  const vehicles = [];
553
553
  for (let i = 0; i < trajectories.length; i += 1) {
554
- if (trajectories[i].properties.coordinate &&
555
- containsCoordinate(ext, trajectories[i].properties.coordinate)) {
554
+ // @ts-expect-error coordinate is added by the RealtimeLayer
555
+ const { coordinate: trajcoord } = trajectories[i].properties;
556
+ if (trajcoord && containsCoordinate(ext, trajcoord)) {
556
557
  vehicles.push(trajectories[i]);
557
558
  }
558
559
  if (vehicles.length === nb) {
@@ -561,7 +562,7 @@ function RealtimeLayerMixin(Base) {
561
562
  }
562
563
  return Promise.resolve({
563
564
  layer: this,
564
- features: vehicles,
565
+ features: vehicles.map((vehicle) => this.format.readFeature(vehicle)),
565
566
  coordinate,
566
567
  });
567
568
  }
@@ -569,7 +570,7 @@ function RealtimeLayerMixin(Base) {
569
570
  * Request the stopSequence and the fullTrajectory informations for a vehicle.
570
571
  *
571
572
  * @param {string} id The vehicle identifier (the train_id property).
572
- * @return {Promise<{stopSequence: StopSequence, fullTrajectory: FullTrajectory>} A promise that will be resolved with the trajectory informations.
573
+ * @return {Promise<{stopSequence: RealtimeStopSequence, fullTrajectory: RealtimeFullTrajectory>} A promise that will be resolved with the trajectory informations.
573
574
  */
574
575
  getTrajectoryInfos(id) {
575
576
  var _a, _b;
@@ -594,9 +595,9 @@ function RealtimeLayerMixin(Base) {
594
595
  Object.entries(this.trajectories || {}).forEach(([key, trajectory]) => {
595
596
  var _a;
596
597
  const timeIntervals = (_a = trajectory === null || trajectory === void 0 ? void 0 : trajectory.properties) === null || _a === void 0 ? void 0 : _a.time_intervals;
597
- if (this.time && timeIntervals.length) {
598
+ if (this.time && (timeIntervals === null || timeIntervals === void 0 ? void 0 : timeIntervals.length)) {
598
599
  const lastTimeInterval = timeIntervals[timeIntervals.length - 1][0];
599
- if (lastTimeInterval < this.time) {
600
+ if (lastTimeInterval < this.time.getTime()) {
600
601
  this.removeTrajectory(key);
601
602
  }
602
603
  }
@@ -632,7 +633,10 @@ function RealtimeLayerMixin(Base) {
632
633
  if (!this.trajectories) {
633
634
  this.trajectories = {};
634
635
  }
635
- this.trajectories[trajectory.properties.train_id] = trajectory;
636
+ const id = trajectory.properties.train_id;
637
+ if (id !== undefined) {
638
+ this.trajectories[id] = trajectory;
639
+ }
636
640
  // @ts-ignore the parameter are set by subclasses
637
641
  this.renderTrajectories();
638
642
  }
@@ -645,7 +649,7 @@ function RealtimeLayerMixin(Base) {
645
649
  else {
646
650
  id = trajectoryOrId;
647
651
  }
648
- if (this.trajectories) {
652
+ if (id !== undefined && this.trajectories) {
649
653
  delete this.trajectories[id];
650
654
  }
651
655
  }
@@ -686,6 +690,7 @@ function RealtimeLayerMixin(Base) {
686
690
  const trajectory = data.content;
687
691
  const { geometry, properties: { train_id: id, time_since_update: timeSinceUpdate, raw_coordinates: rawCoordinates, }, } = trajectory;
688
692
  // ignore old events [SBAHNM-97]
693
+ // @ts-ignore
689
694
  if (timeSinceUpdate < 0) {
690
695
  return;
691
696
  }
@@ -697,15 +702,18 @@ function RealtimeLayerMixin(Base) {
697
702
  if (this.debug &&
698
703
  this.mode === RealtimeModes.TOPOGRAPHIC &&
699
704
  rawCoordinates) {
705
+ // @ts-ignore
700
706
  trajectory.properties.olGeometry = this.format.readGeometry({
701
707
  type: 'Point',
702
708
  coordinates: fromLonLat(rawCoordinates, this.map.getView().getProjection()),
703
709
  });
704
710
  }
705
711
  else {
712
+ // @ts-ignore
706
713
  trajectory.properties.olGeometry = this.format.readGeometry(geometry);
707
714
  }
708
715
  // TODO Make sure the timeOffset is useful. May be we can remove it.
716
+ // @ts-ignore
709
717
  trajectory.properties.timeOffset = Date.now() - data.timestamp;
710
718
  this.addTrajectory(trajectory);
711
719
  }
@@ -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.
@@ -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.
@@ -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.
@@ -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
  */
@@ -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,7 +1,8 @@
1
1
  import { Coordinate } from 'ol/coordinate';
2
+ import { RealtimeTrajectory } from '../../types';
2
3
  export type VehiclePosition = {
3
4
  coord: Coordinate;
4
- rotation: number;
5
+ rotation?: number;
5
6
  };
6
7
  /**
7
8
  * Interpolate or not the vehicle position from a trajectory at a specific date.
@@ -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,7 +9,12 @@ 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;
12
+ const { time_intervals: timeIntervals,
13
+ // @ts-expect-error olGeometry is added by the RealtimeLayer
14
+ olGeometry,
15
+ // @ts-expect-error coordinate is added by the RealtimeLayer
16
+ coordinate, } = trajectory.properties;
17
+ // @ts-ignore
13
18
  let { type, coordinates } = trajectory.geometry;
14
19
  let geometry = olGeometry;
15
20
  let coord;
@@ -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.
@@ -2,7 +2,7 @@ import { compose, apply, 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.
@@ -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-ignore
13
13
  if (props1.cancelled && !props2.cancelled) {
14
+ // @ts-ignore
14
15
  return props2.delay < 180000 ? -1 : 1;
15
16
  }
17
+ // @ts-ignore
16
18
  if (props2.cancelled && !props1.cancelled) {
19
+ // @ts-ignore
17
20
  return props1.delay < 180000 ? 1 : -1;
18
21
  }
22
+ // @ts-ignore
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
  */
@@ -8,7 +8,7 @@ declare const RealtimeLayer_base: {
8
8
  [x: string]: any;
9
9
  debug: boolean;
10
10
  trajectories?: {
11
- [key: string]: GeoJSONFeature;
11
+ [key: string]: import("../../types").RealtimeTrajectory;
12
12
  } | undefined;
13
13
  canvas?: import("../../types").AnyCanvas | undefined;
14
14
  mode: import("../../types").RealtimeMode;
@@ -43,7 +43,12 @@ declare const RealtimeLayer_base: {
43
43
  updateTimeInterval?: number | undefined;
44
44
  updateTimeDelay?: number | undefined;
45
45
  visibilityRef: import("ol/events").EventsKey;
46
- selectedVehicle: GeoJSONFeature;
46
+ /**
47
+ * Render the trajectories using current map's size, resolution and rotation.
48
+ * @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
49
+ * @private
50
+ */
51
+ selectedVehicle: import("../../types").RealtimeTrajectory;
47
52
  getMotsByZoom: (zoom: number) => import("../../types").RealtimeMot[];
48
53
  getGeneralizationLevelByZoom: (zoom: number) => import("../../types").RealtimeGeneralizationLevel;
49
54
  getRenderTimeIntervalByZoom: (zoom: number) => number;
@@ -62,19 +67,19 @@ declare const RealtimeLayer_base: {
62
67
  renderTrajectories(viewState: ViewState | undefined, noInterpolate: boolean | undefined): void;
63
68
  setBbox(extent: [number, number, number, number], zoom: number): void;
64
69
  getRefreshTimeInMs(zoom?: number | undefined): number;
65
- getVehicle(filterFc: Function): GeoJSONFeature[];
70
+ getVehicle(filterFc: Function): import("../../types").RealtimeTrajectory[];
66
71
  getFeatureInfoAtCoordinate(coordinate: import("ol/coordinate").Coordinate, options: import("../../types").LayerGetFeatureInfoOptions): Promise<import("../../types").LayerGetFeatureInfoResponse>;
67
72
  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[]>;
73
+ stopSequence: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory> | import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeStopSequence[]>;
74
+ fullTrajectory: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory> | import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeStopSequence[]>;
70
75
  }>;
71
76
  purgeOutOfDateTrajectories(): void;
72
- purgeTrajectory(trajectory: GeoJSONFeature, extent: [number, number, number, number], zoom: number): boolean;
73
- addTrajectory(trajectory: GeoJSONFeature): void;
74
- removeTrajectory(trajectoryOrId: any): void;
77
+ purgeTrajectory(trajectory: import("../../types").RealtimeTrajectory, extent: [number, number, number, number], zoom: number): boolean;
78
+ addTrajectory(trajectory: import("../../types").RealtimeTrajectory): void;
79
+ removeTrajectory(trajectoryOrId: string | import("../../types").RealtimeTrajectory): void;
75
80
  onZoomEnd(): void;
76
81
  onDocumentVisibilityChange(): void;
77
- onTrajectoryMessage(data: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<GeoJSONFeature>): void;
82
+ onTrajectoryMessage(data: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeTrajectory>): void;
78
83
  onDeleteTrajectoryMessage(data: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<string>): void;
79
84
  highlightVehicle(id: string): void;
80
85
  selectVehicle(id: string): void;
@@ -84,18 +89,36 @@ declare const RealtimeLayer_base: {
84
89
  * A Maplibre layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
85
90
  *
86
91
  * @example
92
+ * import { Map } from 'maplibre-gl';
87
93
  * import { RealtimeLayer } from 'mobility-toolbox-js/maplibre';
88
94
  *
95
+ * // Define the map
96
+ * const map = new Map({ ... });
97
+ *
98
+ * // Define your layer map
89
99
  * const layer = new RealtimeLayer({
90
100
  * apiKey: "yourApiKey"
91
101
  * // url: "wss://api.geops.io/tracker-ws/v1/",
92
102
  * });
93
103
  *
104
+ * // Add the layer to your map *
105
+ * map.on('load', () => {
106
+ * map.addLayer(layer);
107
+ * });
108
+ *
94
109
  *
95
110
  * @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
111
+ * @see <a href="/example/mb-realtime>Live example</a>
96
112
  *
97
- * @implements {maplibregl.CustomLayer}
113
+ * @implements {maplibregl.CustomLayerInterface}
98
114
  * @extends {maplibregl.Evented}
115
+ * @classproperty {function} filter
116
+ * @classproperty {RealtimeMode} mode
117
+ * @classproperty {RealtimeMot[]} mots
118
+ * @classproperty {RealtimeTenant} tenant
119
+ * @classproperty {function} sort
120
+ * @classproperty {function} style
121
+
99
122
  * @public
100
123
  */
101
124
  declare class RealtimeLayer extends RealtimeLayer_base {
@@ -104,8 +127,14 @@ declare class RealtimeLayer extends RealtimeLayer_base {
104
127
  *
105
128
  * @param {RealtimeLayerOptions} options
106
129
  * @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
130
+ * @param {FilterFunction} options.filter Filter out a train. This function must be fast, it is executed for every trajectory on every render frame.
131
+ * @param {getMotsByZoomFunction} options.getMotsByZoom Returns for each zoom level the list of MOTs to display. It filters trains on backend side.
132
+ * @param {number} [options.minZoomInterpolation=8] Minimal zoom level where to start to interpolate train positions.
133
+ * @param {RealtimeMode} [options.mode='topographic'] The realtime mode to use.
134
+ * @param {SortFunction} options.sort Sort trains. This function must be fast, it is executed on every render frame.
135
+ * @param {RealtimeStyleFunction} options.style Function to style the trajectories.
136
+ * @param {RealtimeTenant} options.tenant Filter trains by its tenant. It filters trains on backend side.
107
137
  * @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps Realtime API url.
108
- *
109
138
  */
110
139
  constructor(options?: {});
111
140
  /**
@@ -11,18 +11,36 @@ import toMercatorExtent from '../../common/utils/toMercatorExtent';
11
11
  * A Maplibre layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
12
12
  *
13
13
  * @example
14
+ * import { Map } from 'maplibre-gl';
14
15
  * import { RealtimeLayer } from 'mobility-toolbox-js/maplibre';
15
16
  *
17
+ * // Define the map
18
+ * const map = new Map({ ... });
19
+ *
20
+ * // Define your layer map
16
21
  * const layer = new RealtimeLayer({
17
22
  * apiKey: "yourApiKey"
18
23
  * // url: "wss://api.geops.io/tracker-ws/v1/",
19
24
  * });
20
25
  *
26
+ * // Add the layer to your map *
27
+ * map.on('load', () => {
28
+ * map.addLayer(layer);
29
+ * });
30
+ *
21
31
  *
22
32
  * @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
33
+ * @see <a href="/example/mb-realtime>Live example</a>
23
34
  *
24
- * @implements {maplibregl.CustomLayer}
35
+ * @implements {maplibregl.CustomLayerInterface}
25
36
  * @extends {maplibregl.Evented}
37
+ * @classproperty {function} filter
38
+ * @classproperty {RealtimeMode} mode
39
+ * @classproperty {RealtimeMot[]} mots
40
+ * @classproperty {RealtimeTenant} tenant
41
+ * @classproperty {function} sort
42
+ * @classproperty {function} style
43
+
26
44
  * @public
27
45
  */
28
46
  class RealtimeLayer extends RealtimeLayerMixin(Layer) {
@@ -31,13 +49,19 @@ class RealtimeLayer extends RealtimeLayerMixin(Layer) {
31
49
  *
32
50
  * @param {RealtimeLayerOptions} options
33
51
  * @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
52
+ * @param {FilterFunction} options.filter Filter out a train. This function must be fast, it is executed for every trajectory on every render frame.
53
+ * @param {getMotsByZoomFunction} options.getMotsByZoom Returns for each zoom level the list of MOTs to display. It filters trains on backend side.
54
+ * @param {number} [options.minZoomInterpolation=8] Minimal zoom level where to start to interpolate train positions.
55
+ * @param {RealtimeMode} [options.mode='topographic'] The realtime mode to use.
56
+ * @param {SortFunction} options.sort Sort trains. This function must be fast, it is executed on every render frame.
57
+ * @param {RealtimeStyleFunction} options.style Function to style the trajectories.
58
+ * @param {RealtimeTenant} options.tenant Filter trains by its tenant. It filters trains on backend side.
34
59
  * @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps Realtime API url.
35
- *
36
60
  */
37
61
  constructor(options = {}) {
38
62
  var _a;
39
63
  const canvas = document.createElement('canvas');
40
- super(Object.assign({ canvas }, options));
64
+ super(Object.assign({ canvas, id: 'realtime' }, options));
41
65
  /** @private */
42
66
  this.source = {
43
67
  id: this.id,