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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/api/HttpAPI.d.ts +20 -0
  2. package/api/HttpAPI.js +0 -11
  3. package/api/RealtimeAPI.d.ts +404 -0
  4. package/api/RealtimeAPI.js +342 -276
  5. package/api/RoutingAPI.d.ts +47 -0
  6. package/api/RoutingAPI.js +17 -7
  7. package/api/StopsAPI.d.ts +44 -0
  8. package/api/StopsAPI.js +16 -10
  9. package/api/WebSocketAPI.d.ts +147 -0
  10. package/api/WebSocketAPI.js +164 -164
  11. package/api/index.d.ts +3 -0
  12. package/api/index.js +1 -1
  13. package/api/typedefs.d.ts +76 -0
  14. package/api/typedefs.js +27 -42
  15. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  16. package/common/controls/StopFinderControlCommon.js +31 -31
  17. package/common/index.d.ts +2 -0
  18. package/common/index.js +1 -1
  19. package/common/mixins/RealtimeLayerMixin.d.ts +267 -0
  20. package/common/mixins/RealtimeLayerMixin.js +401 -393
  21. package/common/styles/index.d.ts +4 -0
  22. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  23. package/common/styles/realtimeDefaultStyle.js +6 -6
  24. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  25. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  26. package/common/styles/realtimeHeadingStyle.js +5 -5
  27. package/common/styles/realtimeSimpleStyle.d.ts +4 -0
  28. package/common/typedefs.d.ts +219 -0
  29. package/common/typedefs.js +7 -1
  30. package/common/utils/compareDepartures.d.ts +10 -0
  31. package/common/utils/compareDepartures.js +2 -2
  32. package/common/utils/constants.d.ts +5 -0
  33. package/common/utils/createCanvas.d.ts +10 -0
  34. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  35. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  36. package/common/utils/createRealtimeFilters.d.ts +12 -0
  37. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  38. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  39. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  40. package/common/utils/getLayersAsFlatArray.js +5 -1
  41. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  42. package/common/utils/getMapGlCopyrights.js +3 -3
  43. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  44. package/common/utils/getRealtimeModeSuffix.js +1 -0
  45. package/common/utils/getUrlWithParams.d.ts +8 -0
  46. package/common/utils/getVehiclePosition.d.ts +17 -0
  47. package/common/utils/getVehiclePosition.js +9 -3
  48. package/common/utils/index.d.ts +16 -0
  49. package/common/utils/realtimeConfig.d.ts +64 -0
  50. package/common/utils/removeDuplicate.d.ts +9 -0
  51. package/common/utils/renderTrajectories.d.ts +16 -0
  52. package/common/utils/renderTrajectories.js +6 -6
  53. package/common/utils/sortAndFilterDepartures.d.ts +15 -0
  54. package/common/utils/sortAndFilterDepartures.js +1 -1
  55. package/common/utils/sortByDelay.d.ts +3 -0
  56. package/common/utils/sortByDelay.js +5 -1
  57. package/common/utils/timeUtils.d.ts +23 -0
  58. package/common/utils/toMercatorExtent.d.ts +5 -0
  59. package/iife.d.ts +2 -0
  60. package/index.d.ts +9 -0
  61. package/maplibre/controls/CopyrightControl.d.ts +35 -0
  62. package/maplibre/controls/index.d.ts +1 -0
  63. package/maplibre/index.d.ts +5 -0
  64. package/maplibre/layers/Layer.d.ts +28 -0
  65. package/maplibre/layers/Layer.js +1 -1
  66. package/maplibre/layers/RealtimeLayer.d.ts +181 -0
  67. package/maplibre/layers/RealtimeLayer.js +29 -5
  68. package/maplibre/layers/index.d.ts +2 -0
  69. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  70. package/maplibre/utils/getSourceCoordinates.d.ts +7 -0
  71. package/maplibre/utils/getSourceCoordinates.js +5 -5
  72. package/maplibre/utils/index.d.ts +2 -0
  73. package/mbt.js +22103 -14430
  74. package/mbt.js.map +4 -4
  75. package/mbt.min.js +61 -58
  76. package/mbt.min.js.map +4 -4
  77. package/ol/controls/CopyrightControl.d.ts +31 -0
  78. package/ol/controls/CopyrightControl.js +18 -8
  79. package/ol/controls/RoutingControl.d.ts +202 -0
  80. package/ol/controls/RoutingControl.js +220 -219
  81. package/ol/controls/StopFinderControl.d.ts +37 -0
  82. package/ol/controls/StopFinderControl.js +4 -1
  83. package/ol/controls/index.d.ts +3 -0
  84. package/ol/index.d.ts +7 -0
  85. package/ol/index.js +1 -0
  86. package/ol/layers/Layer.d.ts +101 -0
  87. package/ol/layers/Layer.js +25 -0
  88. package/ol/layers/MaplibreLayer.d.ts +160 -0
  89. package/ol/layers/MaplibreLayer.js +97 -27
  90. package/ol/layers/MaplibreStyleLayer.d.ts +237 -0
  91. package/ol/layers/MaplibreStyleLayer.js +291 -267
  92. package/ol/layers/RealtimeLayer.d.ts +283 -0
  93. package/ol/layers/RealtimeLayer.js +143 -128
  94. package/ol/layers/VectorLayer.d.ts +18 -0
  95. package/ol/layers/VectorLayer.js +31 -0
  96. package/ol/layers/index.d.ts +5 -0
  97. package/ol/layers/index.js +3 -0
  98. package/ol/mixins/MobilityLayerMixin.d.ts +96 -0
  99. package/ol/mixins/MobilityLayerMixin.js +1 -4
  100. package/ol/mixins/PropertiesLayerMixin.d.ts +135 -0
  101. package/ol/mixins/PropertiesLayerMixin.js +112 -140
  102. package/ol/mixins/index.d.ts +1 -0
  103. package/ol/mixins/index.js +2 -0
  104. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
  105. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  106. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  107. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  108. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  109. package/ol/renderers/RealtimeLayerRenderer.js +58 -53
  110. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  111. package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
  112. package/ol/styles/index.d.ts +3 -0
  113. package/ol/styles/routingStyle.d.ts +4 -0
  114. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  115. package/ol/utils/getFeatureInfoAtCoordinate.js +12 -18
  116. package/ol/utils/index.d.ts +1 -0
  117. package/package.json +31 -31
  118. package/setupTests.d.ts +1 -0
  119. package/setupTests.js +3 -4
  120. package/types/common.d.ts +55 -48
  121. package/types/index.d.ts +1 -1
  122. package/types/realtime.d.ts +91 -93
  123. package/types/routing.d.ts +60 -60
  124. package/types/stops.d.ts +62 -62
  125. package/ol/layers/MapGlLayer.js +0 -142
@@ -0,0 +1,64 @@
1
+ import { AnyCanvasContext, RealtimeMot } from '../../types';
2
+ /**
3
+ * @private
4
+ */
5
+ export declare const MOTS_ONLY_RAIL: RealtimeMot[];
6
+ /**
7
+ * @private
8
+ */
9
+ export declare const MOTS_WITH_CABLE: RealtimeMot[];
10
+ /**
11
+ * @private
12
+ */
13
+ export declare const MOTS_WITHOUT_CABLE: RealtimeMot[];
14
+ /**
15
+ * @private
16
+ */
17
+ export declare const MOTS_ALL: RealtimeMot[];
18
+ /**
19
+ * Trajserv value: 'Tram', 'Subway / Metro / S-Bahn', 'Train', 'Bus', 'Ferry', 'Cable Car', 'Gondola', 'Funicular', 'Long distance bus', 'Rail',
20
+ * New endpoint use Rail instead of Train.
21
+ * New tracker values: null, "tram", "subway", "rail", "bus", "ferry", "cablecar", "gondola", "funicular", "coach".
22
+ *
23
+ * @private
24
+ */
25
+ export declare const types: RegExp[];
26
+ /**
27
+ * @private
28
+ */
29
+ export declare const bgColors: string[];
30
+ /**
31
+ * @private
32
+ */
33
+ export declare const textColors: string[];
34
+ /**
35
+ * @private
36
+ */
37
+ export declare const getTypeIndex: (type: RealtimeMot) => number;
38
+ /**
39
+ * @private
40
+ */
41
+ export declare const getRadius: (type: RealtimeMot, zoom: number) => number;
42
+ /**
43
+ * @private
44
+ */
45
+ export declare const getBgColor: (type: RealtimeMot) => string;
46
+ /**
47
+ * @private
48
+ */
49
+ export declare const getTextColor: (type: RealtimeMot) => string;
50
+ /**
51
+ * @private
52
+ */
53
+ export declare const getTextSize: (ctx: AnyCanvasContext, markerSize: number, text: string, fontSize: number, getTextFont: (fontSize: number, text?: string) => string) => number;
54
+ /**
55
+ * @private
56
+ * @param {number} delayInMs Delay in milliseconds.
57
+ * @param {boolean} cancelled true if the journey is cancelled.
58
+ * @param {boolean} isDelayText true if the color is used for delay text of the symbol.
59
+ */
60
+ export declare const getDelayColor: (delayInMs: number | null, cancelled?: boolean, isDelayText?: boolean) => string;
61
+ /**
62
+ * @private
63
+ */
64
+ export declare const getDelayText: (delayInMs: number, cancelled: boolean) => string;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * This function remove duplicates lower case string value of an array.
3
+ * It removes also null, undefined or non string values.
4
+ *
5
+ * @param {array} array Array of values.
6
+ * @private
7
+ */
8
+ declare const removeDuplicate: (array: any[]) => any[];
9
+ export default removeDuplicate;
@@ -0,0 +1,16 @@
1
+ import { AnyCanvas, RealtimeRenderState, RealtimeStyleFunction, RealtimeStyleOptions, RealtimeTrajectories, ViewState } from '../../types';
2
+ /**
3
+ * Draw all the trajectories available in a canvas.
4
+ * @param {HTMLCanvas|HTMLOffscreenCanvas} canvas The canvas where to draw the trajectories.
5
+ * @param {ViewState} trajectories An array of trajectories.
6
+ * @param {Function} style A function that returns a canvas representing a vehicle of a specific trajectory.
7
+ * @param {ViewState} viewState The view state of the map.
8
+ * @param {boolean} options.hoverVehicleId The id of the vehicle to highlight.
9
+ * @param {boolean} options.selectedVehicleId The id of the vehicle to select.
10
+ * @param {boolean} options.noInterpolate If true trajectories are not interpolated but
11
+ * drawn at the last known coordinate. Use this for performance optimization
12
+ * during map navigation.
13
+ * @private
14
+ */
15
+ declare const renderTrajectories: (canvas: AnyCanvas, trajectories: RealtimeTrajectories, style: RealtimeStyleFunction, viewState: ViewState, options: RealtimeStyleOptions) => RealtimeRenderState;
16
+ export default renderTrajectories;
@@ -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);
@@ -0,0 +1,15 @@
1
+ import { RealtimeAPIDeparturesById } from '../../api/RealtimeAPI';
2
+ import type { RealtimeDepartureExtended } from '../../types';
3
+ /**
4
+ * This function sort Departures by arrival time and filter out unwanted departures:
5
+ * - when dparture time is in the past
6
+ * - when departure are duplicated
7
+ * - when departure is not in the next 30 min
8
+ *
9
+ * @param {Object} depObject The object containing departures by id.
10
+ * @param {boolean} [sortByMinArrivalTime=false] If true sort departures by arrival time.
11
+ * @return {RealtimeDeparture[]} Return departures array.
12
+ * @private
13
+ */
14
+ declare const sortAndfilterDepartures: (depObject: RealtimeAPIDeparturesById, sortByMinArrivalTime?: boolean, maxDepartureAge?: number) => RealtimeDepartureExtended[];
15
+ export default sortAndfilterDepartures;
@@ -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) => {
@@ -0,0 +1,3 @@
1
+ import { RealtimeTrajectory } from '../../types';
2
+ declare const sortByDelay: (traj1: RealtimeTrajectory, traj2: RealtimeTrajectory) => number;
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;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Get a Date object as UTC date string .
3
+ * ex: 2019 09 01
4
+ * @private
5
+ */
6
+ export declare const getUTCDateString: (now?: Date) => string;
7
+ /**
8
+ * Get the UTC time string of Date object.
9
+ * ex: 09:05:01.123
10
+ * @private
11
+ */
12
+ export declare const getUTCTimeString: (date: Date) => string;
13
+ /**
14
+ * Returns a string representation of a number, with a zero if the number is lower than 10.
15
+ * @private
16
+ */
17
+ export declare const pad: (integer: number) => string;
18
+ /**
19
+ * Returns a 'hh:mm' string from a time in ms.
20
+ * @param {Number} timeInMs Time in milliseconds.
21
+ * @private
22
+ */
23
+ export declare const getHoursAndMinutes: (timeInMs: number) => string;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @private
3
+ */
4
+ declare const toMercatorExtent: (bounds: maplibregl.LngLatBounds) => import("ol/extent").Extent;
5
+ export default toMercatorExtent;
package/iife.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export default mbt;
2
+ import mbt from './index';
package/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * as ol from "./ol";
2
+ export * as maplibre from "./maplibre";
3
+ declare namespace _default {
4
+ export { ol };
5
+ export { maplibre };
6
+ }
7
+ export default _default;
8
+ import * as ol from './ol';
9
+ import * as maplibre from './maplibre';
@@ -0,0 +1,35 @@
1
+ import { ControlPosition, IControl } from 'maplibre-gl';
2
+ /**
3
+ * Display layer's copyrights.
4
+ *
5
+ * @example
6
+ * import { Map } from 'Maplibre-gl';
7
+ * import { CopyrightControl } from 'mobility-toolbox-js/Maplibre';
8
+ *
9
+ * const map = new Map({
10
+ * container: 'map',
11
+ * style: `https://maps.geops.io/styles/travic_v2/style.json?key=${window.apiKey}`,
12
+ * });
13
+ *
14
+ * const control = new CopyrightControl();
15
+ * map.addControl(control);
16
+ *
17
+ *
18
+ * @see <a href="/example/mb-copyright">Maplibre copyright example</a>
19
+ *
20
+ */
21
+ declare class CopyrightControl implements IControl {
22
+ map?: maplibregl.Map;
23
+ container?: HTMLElement;
24
+ content?: string;
25
+ options?: {
26
+ customAttribution?: string | string[];
27
+ separator?: string;
28
+ };
29
+ constructor(options?: {});
30
+ onAdd(map: maplibregl.Map): HTMLElement;
31
+ onRemove(): HTMLElement | undefined;
32
+ getDefaultPosition(): ControlPosition;
33
+ render(): void;
34
+ }
35
+ export default CopyrightControl;
@@ -0,0 +1 @@
1
+ export { default as CopyrightControl } from "./CopyrightControl";
@@ -0,0 +1,5 @@
1
+ export * from "../api";
2
+ export * from "../common";
3
+ export * from "./controls";
4
+ export * from "./layers";
5
+ export * from "./utils";
@@ -0,0 +1,28 @@
1
+ import { CustomLayerInterface, Evented } from 'maplibre-gl';
2
+ import type { AnyMapGlMap } from '../../types';
3
+ export type LayerOptions = {
4
+ id?: string;
5
+ };
6
+ /**
7
+ * A class representing a layer to display on an Maplibre map.
8
+ *
9
+ * @example
10
+ * import { Layer } from 'mobility-toolbox-js/Maplibre';
11
+ *
12
+ * const layer = new Layer({ id:'MyLayer' });
13
+ *
14
+ * @implements {maplibregl.CustomLayerInterface}
15
+ * @extends {maplibregl.Evented}
16
+ * @private
17
+ */
18
+ declare class Layer extends Evented implements CustomLayerInterface {
19
+ id: string;
20
+ map: AnyMapGlMap | undefined;
21
+ options: LayerOptions;
22
+ type: 'custom';
23
+ constructor(options?: LayerOptions);
24
+ onAdd(map: AnyMapGlMap, gl: WebGLRenderingContext | WebGL2RenderingContext): void;
25
+ onRemove(map: AnyMapGlMap, gl: WebGLRenderingContext | WebGL2RenderingContext): void;
26
+ render(gl: WebGLRenderingContext | WebGL2RenderingContext): void;
27
+ }
28
+ export default Layer;
@@ -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
  */
@@ -0,0 +1,181 @@
1
+ import { RealtimeLayerMixinOptions } from '../../common/mixins/RealtimeLayerMixin';
2
+ import Layer, { LayerOptions } from './Layer';
3
+ import type { AnyMapGlMap, ViewState } from '../../types';
4
+ import type { RealtimeTrajectory } from '../../api/typedefs';
5
+ export type RealtimeLayerOptions = LayerOptions & RealtimeLayerMixinOptions;
6
+ declare const RealtimeLayer_base: {
7
+ new (options: RealtimeLayerMixinOptions): {
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;
14
+ debug: boolean;
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;
23
+ isUpdateBboxOnMoveEnd: boolean;
24
+ live?: boolean;
25
+ minZoomInterpolation: number;
26
+ mode: import("../../types").RealtimeMode;
27
+ mots?: import("../../types").RealtimeMot[];
28
+ motsByZoom: import("../../types").RealtimeMot[][];
29
+ onStart?: ((realtimeLayer: import("../../types").AnyLayer) => void) | undefined;
30
+ onStop?: ((realtimeLayer: import("../../types").AnyLayer) => void) | undefined;
31
+ pixelRatio?: number;
32
+ renderState?: import("../../types").RealtimeRenderState;
33
+ renderTimeIntervalByZoom: number[];
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;
50
+ visibilityRef: import("ol/events").EventsKey;
51
+ addTrajectory(trajectory: import("../../types").RealtimeTrajectory): void;
52
+ attachToMap(map: import("../../types").AnyMap): void;
53
+ defineProperties(options: RealtimeLayerMixinOptions): void;
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;
74
+ start(): void;
75
+ startUpdateTime(): void;
76
+ stop(): void;
77
+ stopUpdateTime(): void;
78
+ };
79
+ } & typeof Layer;
80
+ /**
81
+ * A Maplibre layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
82
+ *
83
+ * @example
84
+ * import { Map } from 'maplibre-gl';
85
+ * import { RealtimeLayer } from 'mobility-toolbox-js/maplibre';
86
+ *
87
+ * // Define the map
88
+ * const map = new Map({ ... });
89
+ *
90
+ * // Define your layer map
91
+ * const layer = new RealtimeLayer({
92
+ * apiKey: "yourApiKey"
93
+ * // url: "wss://api.geops.io/tracker-ws/v1/",
94
+ * });
95
+ *
96
+ * // Add the layer to your map *
97
+ * map.on('load', () => {
98
+ * map.addLayer(layer);
99
+ * });
100
+ *
101
+ *
102
+ * @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
103
+ * @see <a href="/example/mb-realtime>Live example</a>
104
+ *
105
+ * @implements {maplibregl.CustomLayerInterface}
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
114
+ * @public
115
+ */
116
+ declare class RealtimeLayer extends RealtimeLayer_base {
117
+ /**
118
+ * Constructor.
119
+ *
120
+ * @param {RealtimeLayerOptions} options
121
+ * @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
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.
130
+ */
131
+ constructor(options?: {});
132
+ /**
133
+ * Add sources, layers and listeners to the map.
134
+ */
135
+ onAdd(map: AnyMapGlMap, gl: WebGLRenderingContext | WebGL2RenderingContext): void;
136
+ /**
137
+ * Remove source, layers and listeners from the map.
138
+ */
139
+ onRemove(map: AnyMapGlMap, gl: WebGLRenderingContext | WebGL2RenderingContext): void;
140
+ onLoad(): void;
141
+ /**
142
+ * Start updating vehicles position.
143
+ *
144
+ * @public
145
+ */
146
+ start(): void;
147
+ /**
148
+ * Stop updating vehicles position.
149
+ *
150
+ * @public
151
+ */
152
+ stop(): void;
153
+ /**
154
+ * Render the trajectories using current map's size, resolution and rotation.
155
+ * @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
156
+ * @private
157
+ */
158
+ renderTrajectories(noInterpolate?: boolean): void;
159
+ /**
160
+ * Return the delay in ms before the next rendering.
161
+ */
162
+ getRefreshTimeInMs(): number;
163
+ /**
164
+ * Remove the trajectory form the list if necessary.
165
+ */
166
+ purgeTrajectory(trajectory: RealtimeTrajectory, extent: [number, number, number, number], zoom: number): boolean;
167
+ /**
168
+ * Send the current bbox to the websocket
169
+ */
170
+ setBbox(extent?: [number, number, number, number], zoom?: number): void;
171
+ renderTrajectoriesInternal(viewState: ViewState, noInterpolate?: boolean): boolean;
172
+ /**
173
+ * Callback on 'move' event.
174
+ */
175
+ onMove(): void;
176
+ /**
177
+ * Callback on 'moveend' event.
178
+ */
179
+ onMoveEnd(): void;
180
+ }
181
+ export default RealtimeLayer;
@@ -8,21 +8,39 @@ import Layer from './Layer';
8
8
  import { getSourceCoordinates } from '../utils';
9
9
  import toMercatorExtent from '../../common/utils/toMercatorExtent';
10
10
  /**
11
- * Responsible for loading and display data from a geOps Realtime API.
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 { RealtimeLayer } from 'mobility-toolbox-js/Maplibre';
14
+ * import { Map } from 'maplibre-gl';
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 - Filter out a train. This function must be fast, it is executed for every trajectory on every render frame.
38
+ * @classproperty {RealtimeMode} mode - The realtime mode to use.
39
+ * @classproperty {RealtimeMot[]} mots - Filter trains by its mode of transportation. It filters trains on backend side.
40
+ * @classproperty {RealtimeTenant} tenant - Filter trains by its tenant. It filters trains on backend side.
41
+ * @classproperty {function} sort - Sort trains. This function must be fast, it is executed on every render frame.
42
+ * @classproperty {function} style - Function to style the vehicles.
43
+ s
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 vehicles.
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,
@@ -0,0 +1,2 @@
1
+ export { default as Layer } from "./Layer";
2
+ export { default as RealtimeLayer } from "./RealtimeLayer";
@@ -0,0 +1,7 @@
1
+ import { AnyMapGlMap } from '../../types';
2
+ /**
3
+ * Get the current resolution of a Maplibre map.
4
+ * @param {maplibregl.Map} map A map object.
5
+ */
6
+ declare const getMercatorResolution: (map: AnyMapGlMap) => number;
7
+ export default getMercatorResolution;
@@ -0,0 +1,7 @@
1
+ import { AnyMapGlMap } from '../../types';
2
+ /**
3
+ * Get the canvas source coordinates of the current map's extent.
4
+ * @param {maplibregl.Map} map A map object.
5
+ */
6
+ export declare const getSourceCoordinates: (map: AnyMapGlMap, pixelRatio?: number) => number[][];
7
+ export default getSourceCoordinates;
@@ -4,17 +4,17 @@
4
4
  */
5
5
  export const getSourceCoordinates = (map, pixelRatio = 1) => {
6
6
  // Requesting getBounds is not enough when we rotate the map, so we request manually each corner.
7
- const { width, height } = map.getCanvas();
8
- // @ts-ignore
7
+ const { height, width } = map.getCanvas();
8
+ // @ts-expect-error
9
9
  const leftTop = map.unproject({ x: 0, y: 0 });
10
- // @ts-ignore
10
+ // @ts-expect-error
11
11
  const leftBottom = map.unproject({ x: 0, y: height / pixelRatio }); // southWest
12
- // @ts-ignore
12
+ // @ts-expect-error
13
13
  const rightBottom = map.unproject({
14
14
  x: width / pixelRatio,
15
15
  y: height / pixelRatio,
16
16
  });
17
- // @ts-ignore
17
+ // @ts-expect-error
18
18
  const rightTop = map.unproject({ x: width / pixelRatio, y: 0 }); // north east
19
19
  return [
20
20
  [leftTop.lng, leftTop.lat],
@@ -0,0 +1,2 @@
1
+ export { default as getSourceCoordinates } from "./getSourceCoordinates";
2
+ export { default as getMercatorResolution } from "./getMercatorResolution";