mobility-toolbox-js 3.0.0-beta.8 → 3.0.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.
- package/README.md +11 -3
- package/api/HttpAPI.d.ts +20 -0
- package/api/HttpAPI.js +1 -14
- package/api/RealtimeAPI.d.ts +404 -0
- package/api/RealtimeAPI.js +265 -206
- package/api/RoutingAPI.d.ts +47 -0
- package/api/RoutingAPI.js +17 -7
- package/api/StopsAPI.d.ts +44 -0
- package/api/StopsAPI.js +17 -11
- package/api/WebSocketAPI.d.ts +147 -0
- package/api/WebSocketAPI.js +164 -165
- package/api/index.d.ts +3 -0
- package/api/index.js +1 -1
- package/api/typedefs.d.ts +76 -0
- package/api/typedefs.js +27 -42
- package/common/controls/StopFinderControlCommon.d.ts +53 -0
- package/common/controls/StopFinderControlCommon.js +32 -32
- package/common/index.d.ts +2 -0
- package/common/index.js +1 -1
- package/common/styles/index.d.ts +4 -0
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.js +6 -11
- package/common/styles/realtimeDelayStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.js +5 -10
- package/common/styles/realtimeSimpleStyle.d.ts +3 -0
- package/common/styles/realtimeSimpleStyle.js +0 -1
- package/common/typedefs.d.ts +102 -0
- package/common/typedefs.js +6 -31
- package/common/utils/RealtimeEngine.d.ts +214 -0
- package/common/utils/RealtimeEngine.js +554 -0
- package/common/utils/compareDepartures.d.ts +10 -0
- package/common/utils/compareDepartures.js +2 -2
- package/common/utils/constants.d.ts +5 -0
- package/common/utils/createCanvas.d.ts +10 -0
- package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
- package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
- package/common/utils/createRealtimeFilters.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/getLayersAsFlatArray.d.ts +2 -0
- package/common/utils/getLayersAsFlatArray.js +0 -1
- package/common/utils/getMapGlCopyrights.d.ts +17 -0
- package/common/utils/getMapGlCopyrights.js +3 -3
- package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
- package/common/utils/getRealtimeModeSuffix.js +1 -0
- package/common/utils/getUrlWithParams.d.ts +8 -0
- package/common/utils/getVehiclePosition.d.ts +17 -0
- package/common/utils/getVehiclePosition.js +6 -3
- package/common/utils/index.d.ts +16 -0
- package/common/utils/realtimeConfig.d.ts +64 -0
- package/common/utils/realtimeConfig.js +0 -1
- package/common/utils/removeDuplicate.d.ts +9 -0
- package/common/utils/renderTrajectories.d.ts +17 -0
- package/common/utils/renderTrajectories.js +7 -6
- package/common/utils/sortAndFilterDepartures.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.js +2 -1
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.js +5 -1
- package/common/utils/timeUtils.d.ts +23 -0
- package/common/utils/toMercatorExtent.d.ts +5 -0
- package/iife.d.ts +2 -0
- package/index.d.ts +9 -0
- package/maplibre/controls/CopyrightControl.d.ts +38 -0
- package/maplibre/controls/CopyrightControl.js +11 -8
- package/maplibre/controls/index.d.ts +1 -0
- package/maplibre/index.d.ts +5 -0
- package/maplibre/layers/Layer.d.ts +29 -0
- package/maplibre/layers/Layer.js +2 -3
- package/maplibre/layers/RealtimeLayer.d.ts +124 -0
- package/maplibre/layers/RealtimeLayer.js +154 -118
- package/maplibre/layers/index.d.ts +2 -0
- package/maplibre/utils/getMercatorResolution.d.ts +7 -0
- package/maplibre/utils/getSourceCoordinates.d.ts +8 -0
- package/maplibre/utils/getSourceCoordinates.js +6 -5
- package/maplibre/utils/index.d.ts +2 -0
- package/mbt.js +14585 -14557
- package/mbt.js.map +4 -4
- package/mbt.min.js +75 -75
- package/mbt.min.js.map +4 -4
- package/ol/controls/CopyrightControl.d.ts +39 -0
- package/ol/controls/CopyrightControl.js +13 -5
- package/ol/controls/RoutingControl.d.ts +213 -0
- package/ol/controls/RoutingControl.js +250 -264
- package/ol/controls/StopFinderControl.d.ts +56 -0
- package/ol/controls/StopFinderControl.js +24 -5
- package/ol/controls/index.d.ts +3 -0
- package/ol/index.d.ts +6 -0
- package/ol/layers/Layer.d.ts +26 -0
- package/ol/layers/Layer.js +39 -0
- package/ol/layers/MaplibreLayer.d.ts +91 -0
- package/ol/layers/MaplibreLayer.js +154 -31
- package/ol/layers/MaplibreStyleLayer.d.ts +157 -0
- package/ol/layers/MaplibreStyleLayer.js +281 -210
- package/ol/layers/RealtimeLayer.d.ts +150 -0
- package/ol/layers/RealtimeLayer.js +210 -206
- package/ol/layers/VectorLayer.d.ts +17 -0
- package/ol/layers/VectorLayer.js +33 -0
- package/ol/layers/index.d.ts +5 -0
- package/ol/layers/index.js +3 -0
- package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
- package/ol/renderers/MaplibreLayerRenderer.js +142 -114
- package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
- package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
- package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
- package/ol/renderers/RealtimeLayerRenderer.js +50 -70
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
- package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryStyle.js +5 -7
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/routingStyle.d.ts +3 -0
- package/ol/styles/routingStyle.js +13 -10
- package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
- package/ol/utils/defineDeprecatedProperties.js +180 -0
- package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
- package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
- package/ol/utils/index.d.ts +1 -0
- package/package.json +44 -44
- package/setupTests.d.ts +1 -0
- package/setupTests.js +17 -4
- package/types/common.d.ts +53 -69
- package/types/index.d.ts +1 -1
- package/types/realtime.d.ts +98 -95
- package/types/routing.d.ts +60 -60
- package/types/stops.d.ts +62 -62
- package/common/mixins/RealtimeLayerMixin.js +0 -743
- package/ol/layers/MapGlLayer.js +0 -142
- package/ol/mixins/MobilityLayerMixin.js +0 -9
- package/ol/mixins/PropertiesLayerMixin.js +0 -142
|
@@ -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
|
-
|
|
22
|
-
|
|
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(/©/g, '©').split(/(<a.*?<\/a>)/));
|
|
25
25
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RealtimeMode } from '../../types';
|
|
2
|
+
import type { RealtimeModesType } from '../../api/RealtimeAPI';
|
|
3
|
+
/**
|
|
4
|
+
* Get the websocket channel suffix, depending on the current mode.
|
|
5
|
+
* @param {String} mode Mode 'topographic' ou 'schematic'.
|
|
6
|
+
* @param {String[]} modes List of modes
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
declare const getModeSuffix: (mode: RealtimeMode, modes: RealtimeModesType) => string;
|
|
10
|
+
export default getModeSuffix;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Get the websocket channel suffix, depending on the current mode.
|
|
3
3
|
* @param {String} mode Mode 'topographic' ou 'schematic'.
|
|
4
|
+
* @param {String[]} modes List of modes
|
|
4
5
|
* @private
|
|
5
6
|
*/
|
|
6
7
|
const getModeSuffix = (mode, modes) => mode === modes.SCHEMATIC ? '_schematic' : '';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return the styleUrl with apiKey parameters set.
|
|
3
|
+
* @param {string} url a url.
|
|
4
|
+
* @param {Object<String,String>} params a list of key/value pair to add to the url.
|
|
5
|
+
* @private
|
|
6
|
+
*/
|
|
7
|
+
declare const getUrlWithParams: (url: string, params: Object) => URL;
|
|
8
|
+
export default getUrlWithParams;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Coordinate } from 'ol/coordinate';
|
|
2
|
+
import { RealtimeTrajectory } from '../../types';
|
|
3
|
+
export interface VehiclePosition {
|
|
4
|
+
coord: Coordinate;
|
|
5
|
+
rotation?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Interpolate or not the vehicle position from a trajectory at a specific date.
|
|
9
|
+
*
|
|
10
|
+
* @param {number} now Current date to interpolate a position with. In ms.
|
|
11
|
+
* @param {RealtimeTrajectory} trajectory The trajectory to interpolate.
|
|
12
|
+
* @param {boolean} noInterpolate If true, the vehicle position is not interpolated on each render but only once.
|
|
13
|
+
* @returns {VehiclePosition}
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
declare const getVehiclePosition: (now: number, trajectory: RealtimeTrajectory, noInterpolate: boolean) => VehiclePosition;
|
|
17
|
+
export default getVehiclePosition;
|
|
@@ -9,14 +9,17 @@ import { LineString } from 'ol/geom';
|
|
|
9
9
|
* @private
|
|
10
10
|
*/
|
|
11
11
|
const getVehiclePosition = (now, trajectory, noInterpolate) => {
|
|
12
|
-
const {
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const { coordinate,
|
|
13
|
+
// @ts-expect-error olGeometry is added by the RealtimeLayer
|
|
14
|
+
olGeometry, time_intervals: timeIntervals, } = trajectory.properties;
|
|
15
|
+
let { coordinates, type } = trajectory.geometry;
|
|
15
16
|
let geometry = olGeometry;
|
|
16
17
|
let coord;
|
|
17
18
|
let rotation;
|
|
19
|
+
// If an olGeometry exists we use it. It avoids to create one each time.
|
|
18
20
|
if (olGeometry) {
|
|
19
21
|
type = geometry.getType();
|
|
22
|
+
coordinates = geometry.getCoordinates();
|
|
20
23
|
}
|
|
21
24
|
if (noInterpolate && coordinate) {
|
|
22
25
|
coord = coordinate;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { default as getUrlWithParams } from "./getUrlWithParams";
|
|
2
|
+
export { default as getMapGlCopyrights } from "./getMapGlCopyrights";
|
|
3
|
+
export { default as removeDuplicate } from "./removeDuplicate";
|
|
4
|
+
export { default as createRealtimeFilters } from "./createRealtimeFilters";
|
|
5
|
+
export { default as getLayersAsFlatArray } from "./getLayersAsFlatArray";
|
|
6
|
+
export * from "./timeUtils";
|
|
7
|
+
export * from "./constants";
|
|
8
|
+
export { default as sortByDelay } from "./sortByDelay";
|
|
9
|
+
export { default as renderTrajectories } from "./renderTrajectories";
|
|
10
|
+
export { default as debounceDeparturesMessages } from "./debounceDeparturesMessages";
|
|
11
|
+
export { default as debounceWebsocketMessages } from "./debounceWebsocketMessages";
|
|
12
|
+
export { default as sortAndFilterDepartures } from "./sortAndFilterDepartures";
|
|
13
|
+
export { default as compareDepartures } from "./compareDepartures";
|
|
14
|
+
export { default as createCanvas } from "./createCanvas";
|
|
15
|
+
export { default as getVehiclePosition } from "./getVehiclePosition";
|
|
16
|
+
export * as realtimeConfig from "./realtimeConfig";
|
|
@@ -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: null | number, 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,17 @@
|
|
|
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 {Object} options The options.
|
|
9
|
+
* @param {boolean} options.hoverVehicleId The id of the vehicle to highlight.
|
|
10
|
+
* @param {boolean} options.selectedVehicleId The id of the vehicle to select.
|
|
11
|
+
* @param {boolean} options.noInterpolate If true trajectories are not interpolated but
|
|
12
|
+
* drawn at the last known coordinate. Use this for performance optimization
|
|
13
|
+
* during map navigation.
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
declare const renderTrajectories: (canvas: AnyCanvas, trajectories: RealtimeTrajectories, style: RealtimeStyleFunction, viewState: ViewState, options: RealtimeStyleOptions) => RealtimeRenderState;
|
|
17
|
+
export default renderTrajectories;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
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.
|
|
9
|
+
* @param {Object} options The options.
|
|
9
10
|
* @param {boolean} options.hoverVehicleId The id of the vehicle to highlight.
|
|
10
11
|
* @param {boolean} options.selectedVehicleId The id of the vehicle to select.
|
|
11
12
|
* @param {boolean} options.noInterpolate If true trajectories are not interpolated but
|
|
@@ -17,13 +18,13 @@ const renderTrajectories = (canvas, trajectories, style, viewState, options) =>
|
|
|
17
18
|
if (!canvas) {
|
|
18
19
|
return { renderedTrajectories: [] };
|
|
19
20
|
}
|
|
20
|
-
const {
|
|
21
|
+
const { center, pixelRatio = 1, resolution, rotation = 0, size = [], time = Date.now(), } = viewState;
|
|
21
22
|
if (!resolution || !center) {
|
|
22
23
|
return { renderedTrajectories: [] };
|
|
23
24
|
}
|
|
24
|
-
const {
|
|
25
|
+
const { filter, getScreenPixel = (pixel, viewStat) => (viewStat.zoom || 0) < 12
|
|
25
26
|
? pixel.map((coord) => Math.floor(coord))
|
|
26
|
-
: pixel, } = options;
|
|
27
|
+
: pixel, hoverVehicleId, noInterpolate = false, selectedVehicleId, } = options;
|
|
27
28
|
const context = canvas.getContext('2d');
|
|
28
29
|
context === null || context === void 0 ? void 0 : context.clearRect(0, 0, canvas.width, canvas.height);
|
|
29
30
|
const [width, height] = size;
|
|
@@ -49,7 +50,7 @@ const renderTrajectories = (canvas, trajectories, style, viewState, options) =>
|
|
|
49
50
|
continue;
|
|
50
51
|
}
|
|
51
52
|
// We simplify the trajectory object
|
|
52
|
-
const { train_id: id
|
|
53
|
+
const { timeOffset, train_id: id } = trajectory.properties;
|
|
53
54
|
// We set the rotation and the timeFraction of the trajectory (used by tralis).
|
|
54
55
|
// if rotation === null that seems there is no rotation available.
|
|
55
56
|
const { coord, rotation: rotationIcon } = getVehiclePosition(time - (timeOffset || 0), trajectory, noInterpolate);
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
* @param {number} [maxDepartureAge=30] The maximum departure age in minutes.
|
|
12
|
+
* @return {RealtimeDeparture[]} Return departures array.
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
declare const sortAndfilterDepartures: (depObject: RealtimeAPIDeparturesById, sortByMinArrivalTime?: boolean, maxDepartureAge?: number) => RealtimeDepartureExtended[];
|
|
16
|
+
export default sortAndfilterDepartures;
|
|
@@ -7,7 +7,8 @@ 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
|
-
* @
|
|
10
|
+
* @param {number} [maxDepartureAge=30] The maximum departure age in minutes.
|
|
11
|
+
* @return {RealtimeDeparture[]} Return departures array.
|
|
11
12
|
* @private
|
|
12
13
|
*/
|
|
13
14
|
const sortAndfilterDepartures = (depObject, sortByMinArrivalTime = false, maxDepartureAge = 30) => {
|
|
@@ -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;
|
package/iife.d.ts
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ControlPosition, IControl } from 'maplibre-gl';
|
|
2
|
+
/**
|
|
3
|
+
* Display layer's attributions trying to remove duplicated ones.
|
|
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-realtime>MapLibre Realtime layer example</a>
|
|
19
|
+
*
|
|
20
|
+
* @implements {maplibregl.IControl}
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
declare class CopyrightControl implements IControl {
|
|
25
|
+
container?: HTMLElement;
|
|
26
|
+
content?: string;
|
|
27
|
+
map?: maplibregl.Map;
|
|
28
|
+
options?: {
|
|
29
|
+
customAttribution?: string | string[];
|
|
30
|
+
separator?: string;
|
|
31
|
+
};
|
|
32
|
+
constructor(options?: {});
|
|
33
|
+
getDefaultPosition(): ControlPosition;
|
|
34
|
+
onAdd(map: maplibregl.Map): HTMLElement;
|
|
35
|
+
onRemove(): HTMLElement | undefined;
|
|
36
|
+
render(): void;
|
|
37
|
+
}
|
|
38
|
+
export default CopyrightControl;
|
|
@@ -4,11 +4,11 @@ import { getMapGlCopyrights } from '../../common/utils';
|
|
|
4
4
|
*/
|
|
5
5
|
const DEFAULT_SEPARATOR = ' | ';
|
|
6
6
|
/**
|
|
7
|
-
* Display layer's
|
|
7
|
+
* Display layer's attributions trying to remove duplicated ones.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* import { Map } from '
|
|
11
|
-
* import { CopyrightControl } from 'mobility-toolbox-js/
|
|
10
|
+
* import { Map } from 'maplibre-gl';
|
|
11
|
+
* import { CopyrightControl } from 'mobility-toolbox-js/maplibre';
|
|
12
12
|
*
|
|
13
13
|
* const map = new Map({
|
|
14
14
|
* container: 'map',
|
|
@@ -19,13 +19,20 @@ const DEFAULT_SEPARATOR = ' | ';
|
|
|
19
19
|
* map.addControl(control);
|
|
20
20
|
*
|
|
21
21
|
*
|
|
22
|
-
* @see <a href="/example/mb-
|
|
22
|
+
* @see <a href="/example/mb-realtime>MapLibre Realtime layer example</a>
|
|
23
23
|
*
|
|
24
|
+
* @implements {maplibregl.IControl}
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
24
27
|
*/
|
|
25
28
|
class CopyrightControl {
|
|
26
29
|
constructor(options = {}) {
|
|
27
30
|
this.options = options;
|
|
28
31
|
}
|
|
32
|
+
// eslint-disable-next-line class-methods-use-this
|
|
33
|
+
getDefaultPosition() {
|
|
34
|
+
return 'bottom-right';
|
|
35
|
+
}
|
|
29
36
|
onAdd(map) {
|
|
30
37
|
this.map = map;
|
|
31
38
|
if (!this.container) {
|
|
@@ -51,10 +58,6 @@ class CopyrightControl {
|
|
|
51
58
|
this.map = undefined;
|
|
52
59
|
return this.container;
|
|
53
60
|
}
|
|
54
|
-
// eslint-disable-next-line class-methods-use-this
|
|
55
|
-
getDefaultPosition() {
|
|
56
|
-
return 'bottom-right';
|
|
57
|
-
}
|
|
58
61
|
render() {
|
|
59
62
|
var _a, _b;
|
|
60
63
|
if (this.map && this.container) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as CopyrightControl } from "./CopyrightControl";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CustomLayerInterface, Evented } from 'maplibre-gl';
|
|
2
|
+
import type { AnyMapGlMap } from '../../types';
|
|
3
|
+
export interface LayerOptions {
|
|
4
|
+
id?: string;
|
|
5
|
+
}
|
|
6
|
+
export type CUSTOM = 'custom';
|
|
7
|
+
/**
|
|
8
|
+
* A class representing a layer to display on an Maplibre map.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { Layer } from 'mobility-toolbox-js/Maplibre';
|
|
12
|
+
*
|
|
13
|
+
* const layer = new Layer({ id:'MyLayer' });
|
|
14
|
+
*
|
|
15
|
+
* @implements {maplibregl.CustomLayerInterface}
|
|
16
|
+
* @extends {maplibregl.Evented}
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
declare class Layer extends Evented implements CustomLayerInterface {
|
|
20
|
+
id: string;
|
|
21
|
+
map: AnyMapGlMap | undefined;
|
|
22
|
+
options: LayerOptions;
|
|
23
|
+
type: CUSTOM;
|
|
24
|
+
constructor(options?: LayerOptions);
|
|
25
|
+
onAdd(map: AnyMapGlMap, gl: WebGL2RenderingContext | WebGLRenderingContext): void;
|
|
26
|
+
onRemove(map: AnyMapGlMap, gl: WebGL2RenderingContext | WebGLRenderingContext): void;
|
|
27
|
+
render(gl: WebGL2RenderingContext | WebGLRenderingContext): void;
|
|
28
|
+
}
|
|
29
|
+
export default Layer;
|
package/maplibre/layers/Layer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { v4 as uuid } from 'uuid';
|
|
2
1
|
import { Evented } from 'maplibre-gl';
|
|
2
|
+
import { v4 as uuid } from 'uuid';
|
|
3
3
|
/**
|
|
4
4
|
* A class representing a layer to display on an Maplibre map.
|
|
5
5
|
*
|
|
@@ -8,7 +8,7 @@ import { Evented } from 'maplibre-gl';
|
|
|
8
8
|
*
|
|
9
9
|
* const layer = new Layer({ id:'MyLayer' });
|
|
10
10
|
*
|
|
11
|
-
* @implements {maplibregl.
|
|
11
|
+
* @implements {maplibregl.CustomLayerInterface}
|
|
12
12
|
* @extends {maplibregl.Evented}
|
|
13
13
|
* @private
|
|
14
14
|
*/
|
|
@@ -19,7 +19,6 @@ class Layer extends Evented {
|
|
|
19
19
|
this.type = 'custom';
|
|
20
20
|
this.options = options;
|
|
21
21
|
this.id = options.id || uuid();
|
|
22
|
-
this.type = 'custom';
|
|
23
22
|
}
|
|
24
23
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
25
24
|
onAdd(map, gl) {
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { CanvasSourceSpecification, LayerSpecification } from 'maplibre-gl';
|
|
2
|
+
import RealtimeEngine, { RealtimeEngineOptions } from '../../common/utils/RealtimeEngine';
|
|
3
|
+
import Layer, { LayerOptions } from './Layer';
|
|
4
|
+
import type { AnyCanvas, AnyMapGlMap } from '../../types';
|
|
5
|
+
export type RealtimeLayerOptions = LayerOptions & RealtimeEngineOptions;
|
|
6
|
+
/**
|
|
7
|
+
* A Maplibre layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* import { Map } from 'maplibre-gl';
|
|
11
|
+
* import { RealtimeLayer } from 'mobility-toolbox-js/maplibre';
|
|
12
|
+
*
|
|
13
|
+
* // Define the map
|
|
14
|
+
* const map = new Map({ ... });
|
|
15
|
+
*
|
|
16
|
+
* // Define your layer map
|
|
17
|
+
* const layer = new RealtimeLayer({
|
|
18
|
+
* apiKey: "yourApiKey"
|
|
19
|
+
* // url: "wss://api.geops.io/tracker-ws/v1/",
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Add the layer to your map *
|
|
23
|
+
* map.on('load', () => {
|
|
24
|
+
* map.addLayer(layer);
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
*
|
|
28
|
+
* @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
|
|
29
|
+
* @see <a href="/example/mb-realtime>MapLibre Realtime layer example</a>
|
|
30
|
+
*
|
|
31
|
+
* @implements {maplibregl.CustomLayerInterface}
|
|
32
|
+
* @extends {maplibregl.Evented}
|
|
33
|
+
* @classproperty {function} filter - Filter out a train. This function must be fast, it is executed for every trajectory on every render frame.
|
|
34
|
+
* @classproperty {RealtimeMode} mode - The realtime mode to use.
|
|
35
|
+
* @classproperty {RealtimeMot[]} mots - Filter trains by its mode of transportation. It filters trains on backend side.
|
|
36
|
+
* @classproperty {RealtimeTenant} tenant - Filter trains by its tenant. It filters trains on backend side.
|
|
37
|
+
* @classproperty {function} sort - Sort trains. This function must be fast, it is executed on every render frame.
|
|
38
|
+
* @classproperty {function} style - Function to style the vehicles.
|
|
39
|
+
s
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
declare class RealtimeLayer extends Layer {
|
|
43
|
+
#private;
|
|
44
|
+
engine: RealtimeEngine;
|
|
45
|
+
layer: LayerSpecification;
|
|
46
|
+
source: CanvasSourceSpecification;
|
|
47
|
+
sourceId: string;
|
|
48
|
+
/**
|
|
49
|
+
* Constructor.
|
|
50
|
+
*
|
|
51
|
+
* @param {RealtimeLayerOptions} options
|
|
52
|
+
* @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
|
|
53
|
+
* @param {FilterFunction} options.filter Filter out a train. This function must be fast, it is executed for every trajectory on every render frame.
|
|
54
|
+
* @param {getMotsByZoomFunction} options.getMotsByZoom Returns for each zoom level the list of MOTs to display. It filters trains on backend side.
|
|
55
|
+
* @param {number} [options.minZoomInterpolation=8] Minimal zoom level where to start to interpolate train positions.
|
|
56
|
+
* @param {RealtimeMode} [options.mode='topographic'] The realtime mode to use.
|
|
57
|
+
* @param {SortFunction} options.sort Sort trains. This function must be fast, it is executed on every render frame.
|
|
58
|
+
* @param {RealtimeStyleFunction} options.style Function to style the vehicles.
|
|
59
|
+
* @param {RealtimeTenant} options.tenant Filter trains by its tenant. It filters trains on backend side.
|
|
60
|
+
* @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps Realtime API url.
|
|
61
|
+
*/
|
|
62
|
+
constructor(options?: RealtimeLayerOptions);
|
|
63
|
+
/**
|
|
64
|
+
* Return the current view state. Used by the RealtimeEngine.
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
getViewState(): {
|
|
68
|
+
center?: undefined;
|
|
69
|
+
extent?: undefined;
|
|
70
|
+
pixelRatio?: undefined;
|
|
71
|
+
resolution?: undefined;
|
|
72
|
+
rotation?: undefined;
|
|
73
|
+
size?: undefined;
|
|
74
|
+
visible?: undefined;
|
|
75
|
+
zoom?: undefined;
|
|
76
|
+
} | {
|
|
77
|
+
center: import("ol/coordinate").Coordinate;
|
|
78
|
+
extent: number[];
|
|
79
|
+
pixelRatio: number;
|
|
80
|
+
resolution: number;
|
|
81
|
+
rotation: number;
|
|
82
|
+
size: number[];
|
|
83
|
+
visible: boolean;
|
|
84
|
+
zoom: number;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Add sources, layers and listeners to the map.
|
|
88
|
+
*/
|
|
89
|
+
onAdd(map: AnyMapGlMap, gl: WebGL2RenderingContext | WebGLRenderingContext): void;
|
|
90
|
+
onLoad(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Callback on 'move' event.
|
|
93
|
+
*/
|
|
94
|
+
onMove(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Callback on 'moveend' event.
|
|
97
|
+
*/
|
|
98
|
+
onMoveEnd(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Callback when the RealtimeEngine has rendered successfully.
|
|
101
|
+
*/
|
|
102
|
+
onRealtimeEngineRender(): void;
|
|
103
|
+
/**
|
|
104
|
+
* Remove source, layers and listeners from the map.
|
|
105
|
+
*/
|
|
106
|
+
onRemove(map: AnyMapGlMap, gl: WebGL2RenderingContext | WebGLRenderingContext): void;
|
|
107
|
+
onZoomEnd(): void;
|
|
108
|
+
/**
|
|
109
|
+
* Start updating vehicles position.
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
113
|
+
start(): void;
|
|
114
|
+
/**
|
|
115
|
+
* Stop updating vehicles position.
|
|
116
|
+
*
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
stop(): void;
|
|
120
|
+
get canvas(): AnyCanvas | undefined;
|
|
121
|
+
get pixelRatio(): number | undefined;
|
|
122
|
+
set pixelRatio(pixelRatio: number | undefined);
|
|
123
|
+
}
|
|
124
|
+
export default RealtimeLayer;
|