mobility-toolbox-js 2.0.0-beta.3 → 2.0.0-beta.33
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 +4 -1
- package/api/RealtimeAPI.d.ts +268 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RoutingAPI.d.ts +33 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/StopsAPI.d.ts +36 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/index.d.ts +5 -0
- package/api/index.d.ts.map +1 -0
- package/api/typedefs.d.ts +105 -0
- package/api/typedefs.d.ts.map +1 -0
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.d.ts +95 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/controls/Control.d.ts +74 -0
- package/common/controls/Control.d.ts.map +1 -0
- package/common/index.d.ts +3 -0
- package/common/index.d.ts.map +1 -0
- package/common/layers/Layer.d.ts +80 -0
- package/common/layers/Layer.d.ts.map +1 -0
- package/common/mixins/CopyrightMixin.d.ts +22 -0
- package/common/mixins/CopyrightMixin.d.ts.map +1 -0
- package/common/mixins/MapboxLayerMixin.d.ts +27 -0
- package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/StopFinderMixin.d.ts +40 -0
- package/common/mixins/StopFinderMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/styles/index.d.ts +5 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.d.ts +15 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/{trackerDelayStyle.js → realtimeDelayStyle.d.ts} +3 -9
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.d.ts +3 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/typedefs.d.ts +50 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/utils/cleanStopTime.d.ts +7 -0
- package/common/utils/cleanStopTime.d.ts.map +1 -0
- package/common/utils/compareDepartures.d.ts +9 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/createCanvas.d.ts +9 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createTrackerFilters.d.ts +12 -0
- package/common/utils/createTrackerFilters.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxRender.d.ts +5 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.d.ts +5 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.d.ts +14 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/index.d.ts +12 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/renderTrajectories.d.ts +20 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/timeUtils.d.ts +5 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/trackerConfig.d.ts +24 -0
- package/common/utils/trackerConfig.d.ts.map +1 -0
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/index.d.ts +6 -0
- package/index.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.d.ts +32 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/index.d.ts +2 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/index.d.ts +5 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/layers/Layer.d.ts +47 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.d.ts +118 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/index.d.ts +3 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/utils.d.ts +8 -0
- package/mapbox/utils.d.ts.map +1 -0
- package/mbt.js +50042 -0
- package/mbt.js.map +7 -0
- package/mbt.min.js +1008 -0
- package/mbt.min.js.map +7 -0
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.d.ts +180 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.d.ts +32 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/index.d.ts +4 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/index.d.ts +6 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/layers/Layer.d.ts +49 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.d.ts +42 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.d.ts +146 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.d.ts +27 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.d.ts +119 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.d.ts +24 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.d.ts +23 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.d.ts +38 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/index.d.ts +9 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/package.json +56 -95
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/types/index.d.ts +10 -0
- package/types/realtime.d.ts +24 -0
- package/types/routing.d.ts +206 -0
- package/types/stops.d.ts +143 -0
- package/api/index.js +0 -3
- package/api/routing/RoutingAPI.js +0 -44
- package/api/routing/RoutingAPI.test.js +0 -41
- package/api/stops/StopsAPI.js +0 -41
- package/api/stops/StopsAPI.test.js +0 -34
- package/api/tralis/TralisAPI.js +0 -731
- package/api/tralis/TralisAPI.test.js +0 -75
- package/api/tralis/TralisAPIUtils.js +0 -73
- package/api/tralis/WebSocketConnector.js +0 -338
- package/api/tralis/WebSocketConnector.test.js +0 -356
- package/api/tralis/typedefs.js +0 -81
- package/common/Tracker.js +0 -197
- package/common/api/api.js +0 -64
- package/common/api/api.test.js +0 -68
- package/common/controls/Control.js +0 -146
- package/common/controls/Control.test.js +0 -98
- package/common/layers/Layer.js +0 -404
- package/common/layers/Layer.test.js +0 -585
- package/common/mixins/CopyrightMixin.js +0 -48
- package/common/mixins/SearchMixin.js +0 -176
- package/common/mixins/TralisLayerMixin.js +0 -930
- package/common/styles/index.js +0 -4
- package/common/styles/trackerDefaultStyle.js +0 -333
- package/common/styles/trackerSimpleStyle.js +0 -22
- package/common/trackerConfig.js +0 -190
- package/common/trackerConfig.test.js +0 -25
- package/common/typedefs.js +0 -23
- package/common/utils/createTrackerFilters.js +0 -87
- package/common/utils/createTrackerFilters.test.js +0 -95
- package/common/utils/getMapboxMapCopyrights.js +0 -32
- package/common/utils/getMapboxMapCopyrights.test.js +0 -47
- package/common/utils/getMapboxStyleUrl.js +0 -32
- package/common/utils/getVehiclePosition.js +0 -72
- package/common/utils/index.js +0 -6
- package/common/utils/removeDuplicate.js +0 -22
- package/common/utils/removeDuplicate.test.js +0 -22
- package/common/utils/sortByDelay.js +0 -23
- package/common/utils/timeUtils.js +0 -44
- package/common/utils/timeUtils.test.js +0 -16
- package/index.js +0 -2
- package/index.js.map +0 -1
- package/mapbox/controls/CopyrightControl.js +0 -58
- package/mapbox/index.js +0 -3
- package/mapbox/layers/Layer.js +0 -118
- package/mapbox/layers/Layer.test.js +0 -202
- package/mapbox/layers/TralisLayer.js +0 -329
- package/mapbox/layers/TralisLayer.test.js +0 -40
- package/mapbox/utils.js +0 -46
- package/module.js +0 -23
- package/ol/README.md +0 -0
- package/ol/controls/CopyrightControl.js +0 -80
- package/ol/controls/CopyrightControl.test.js +0 -211
- package/ol/controls/RoutingControl.js +0 -752
- package/ol/controls/RoutingControl.test.js +0 -216
- package/ol/controls/StopFinderControl.js +0 -38
- package/ol/controls/StopFinderControl.test.js +0 -59
- package/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
- package/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
- package/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
- package/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
- package/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
- package/ol/controls/snapshots/RoutingControlStation1.json +0 -60
- package/ol/controls/snapshots/RoutingControlStation2.json +0 -49
- package/ol/index.js +0 -13
- package/ol/layers/Layer.js +0 -193
- package/ol/layers/Layer.test.js +0 -197
- package/ol/layers/MapboxLayer.js +0 -378
- package/ol/layers/MapboxLayer.test.js +0 -186
- package/ol/layers/MapboxStyleLayer.js +0 -417
- package/ol/layers/MapboxStyleLayer.test.js +0 -262
- package/ol/layers/MaplibreLayer.js +0 -280
- package/ol/layers/RoutingLayer.js +0 -91
- package/ol/layers/RoutingLayer.test.js +0 -49
- package/ol/layers/TralisLayer.js +0 -359
- package/ol/layers/TralisLayer.test.js +0 -97
- package/ol/layers/VectorLayer.js +0 -43
- package/ol/layers/VectorLayer.test.js +0 -98
- package/ol/layers/WMSLayer.js +0 -80
- package/ol/layers/WMSLayer.test.js +0 -84
- package/ol/styles/fullTrajectoryDelayStyle.js +0 -35
- package/ol/styles/fullTrajectoryStyle.js +0 -51
- package/ol/styles/index.js +0 -2
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import createTrackerFilters from './createTrackerFilters';
|
|
2
|
-
|
|
3
|
-
const u1 = {
|
|
4
|
-
properties: {
|
|
5
|
-
routeIdentifier: '001.000827.004:7',
|
|
6
|
-
operator: 'FoO',
|
|
7
|
-
line: {
|
|
8
|
-
name: 'U1',
|
|
9
|
-
},
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
const ireta = {
|
|
13
|
-
properties: {
|
|
14
|
-
routeIdentifier: '0022.000827.004:7',
|
|
15
|
-
operator: 'BAR',
|
|
16
|
-
line: {
|
|
17
|
-
name: 'IRETA',
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
const arb = {
|
|
22
|
-
properties: {
|
|
23
|
-
routeIdentifier: '00333.000827.004:7',
|
|
24
|
-
operator: 'qux',
|
|
25
|
-
line: {
|
|
26
|
-
name: 'ARB',
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const trajectories = [u1, ireta, arb];
|
|
32
|
-
|
|
33
|
-
describe('#createTrackerFilter()', () => {
|
|
34
|
-
test('returns null', () => {
|
|
35
|
-
const filterFunc = createTrackerFilters();
|
|
36
|
-
expect(filterFunc).toBe(null);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('using line', () => {
|
|
40
|
-
test('as string', () => {
|
|
41
|
-
const filterFunc = createTrackerFilters('u1,foo');
|
|
42
|
-
expect(trajectories.filter(filterFunc)).toEqual([u1]);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('as array of string', () => {
|
|
46
|
-
const filterFunc = createTrackerFilters(['u1', 'foo', 'IRETA']);
|
|
47
|
-
expect(trajectories.filter(filterFunc)).toEqual([u1, ireta]);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe('using route identifier', () => {
|
|
52
|
-
test('as string', () => {
|
|
53
|
-
const filterFunc = createTrackerFilters(null, '1,foo');
|
|
54
|
-
expect(trajectories.filter(filterFunc)).toEqual([u1]);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('as array of string', () => {
|
|
58
|
-
const filterFunc = createTrackerFilters(null, ['22', 'foo', '1']);
|
|
59
|
-
expect(trajectories.filter(filterFunc)).toEqual([u1, ireta]);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('using operator', () => {
|
|
64
|
-
test('as string', () => {
|
|
65
|
-
const filterFunc = createTrackerFilters(null, null, 'foo');
|
|
66
|
-
expect(trajectories.filter(filterFunc)).toEqual([u1]);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('as array of string', () => {
|
|
70
|
-
const filterFunc = createTrackerFilters(null, null, ['bar', 'foo', '1']);
|
|
71
|
-
expect(trajectories.filter(filterFunc)).toEqual([u1, ireta]);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('using regexLine', () => {
|
|
76
|
-
test('as string', () => {
|
|
77
|
-
const filterFunc = createTrackerFilters(
|
|
78
|
-
null,
|
|
79
|
-
null,
|
|
80
|
-
null,
|
|
81
|
-
'^(S|R$|RE|PE|D|IRE|RB|TER)',
|
|
82
|
-
);
|
|
83
|
-
expect(trajectories.filter(filterFunc)).toEqual([ireta]);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('as array of string', () => {
|
|
87
|
-
const filterFunc = createTrackerFilters(null, null, null, [
|
|
88
|
-
'^IR',
|
|
89
|
-
'^ARB$',
|
|
90
|
-
'foo',
|
|
91
|
-
]);
|
|
92
|
-
expect(trajectories.filter(filterFunc)).toEqual([ireta, arb]);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import removeDuplicate from './removeDuplicate';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Return the copyright a Mapbox map.
|
|
5
|
-
* @param {mapboxgl.Map} map A Mapbox map
|
|
6
|
-
* @ignore
|
|
7
|
-
*/
|
|
8
|
-
const getMapboxMapCopyrights = (map) => {
|
|
9
|
-
if (!map || !map.style) {
|
|
10
|
-
return [];
|
|
11
|
-
}
|
|
12
|
-
const { sourceCaches } = map.style;
|
|
13
|
-
let copyrights = [];
|
|
14
|
-
|
|
15
|
-
Object.values(sourceCaches).forEach((sourceCache) => {
|
|
16
|
-
if (sourceCache.used) {
|
|
17
|
-
const source = sourceCache.getSource();
|
|
18
|
-
const attribution =
|
|
19
|
-
source.attribution || (source.options && source.options.attribution);
|
|
20
|
-
|
|
21
|
-
if (attribution) {
|
|
22
|
-
copyrights = copyrights.concat(
|
|
23
|
-
attribution.replace(/©/g, '©').split(/(<a.*?<\/a>)/),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
return removeDuplicate(copyrights);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export default getMapboxMapCopyrights;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import getMapboxMapCopyrights from './getMapboxMapCopyrights';
|
|
2
|
-
|
|
3
|
-
describe('getMapboxMapCopyrights()', () => {
|
|
4
|
-
test('returns an empty array if map is not defined', () => {
|
|
5
|
-
expect(getMapboxMapCopyrights().length).toBe(0);
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
test('returns an empty array if map.style is not defined', () => {
|
|
9
|
-
expect(getMapboxMapCopyrights({}).length).toBe(0);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('returns non depluicated copyrights in an array', () => {
|
|
13
|
-
expect(
|
|
14
|
-
getMapboxMapCopyrights({
|
|
15
|
-
style: {
|
|
16
|
-
sourceCaches: {
|
|
17
|
-
used: {
|
|
18
|
-
used: true,
|
|
19
|
-
getSource() {
|
|
20
|
-
return {
|
|
21
|
-
attribution:
|
|
22
|
-
'<a href="https://www.openmaptiles.org/" target="_blank">© OpenMapTiles</a> <a href="https://www.openstreetmap.org/about/" target="_blank">© OpenStreetMap contributors</a>',
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
'not used': {
|
|
27
|
-
used: false,
|
|
28
|
-
},
|
|
29
|
-
'also used': {
|
|
30
|
-
used: true,
|
|
31
|
-
getSource() {
|
|
32
|
-
return {
|
|
33
|
-
attribution:
|
|
34
|
-
'<a href="https://www.openmaptiles.org/" target="_blank">© OpenMapTiles</a> <a href="https://www.imagico.de/" target="_blank">© imagico</a>',
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
}),
|
|
41
|
-
).toEqual([
|
|
42
|
-
'<a href="https://www.openmaptiles.org/" target="_blank">© OpenMapTiles</a>',
|
|
43
|
-
'<a href="https://www.openstreetmap.org/about/" target="_blank">© OpenStreetMap contributors</a>',
|
|
44
|
-
'<a href="https://www.imagico.de/" target="_blank">© imagico</a>',
|
|
45
|
-
]);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import qs from 'query-string';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Return the styleUrl with apiKey parameters set.
|
|
5
|
-
* @param {string} apiKey apiKey value for the mapbox request.
|
|
6
|
-
* @param {string} apiKeyName parameter name for apiKey in the mapbox request.
|
|
7
|
-
* @param {string} styleUrl mapbox styleUrl value.
|
|
8
|
-
* @ignore
|
|
9
|
-
*/
|
|
10
|
-
const getMapboxStyleUrl = (apiKey, apiKeyName, styleUrl) => {
|
|
11
|
-
if (apiKey === false) {
|
|
12
|
-
return styleUrl;
|
|
13
|
-
}
|
|
14
|
-
const parsedStyle = qs.parseUrl(styleUrl);
|
|
15
|
-
if (!apiKey && parsedStyle.query[apiKeyName]) {
|
|
16
|
-
return styleUrl;
|
|
17
|
-
}
|
|
18
|
-
if (!apiKey) {
|
|
19
|
-
// eslint-disable-next-line no-console
|
|
20
|
-
console.warn(`No apiKey is defined for request to ${styleUrl}`);
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
return qs.stringifyUrl({
|
|
24
|
-
...parsedStyle,
|
|
25
|
-
query: {
|
|
26
|
-
...parsedStyle.query,
|
|
27
|
-
[apiKeyName]: apiKey,
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export default getMapboxStyleUrl;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import GeomType from 'ol/geom/GeometryType';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Interpolate or not the vehicle position from a trajectory at a specific date.
|
|
5
|
-
*
|
|
6
|
-
* @param {number} now Current date to interpolate a position with. In ms.
|
|
7
|
-
* @param {TralisTrajectory} trajectory The trajectory to interpolate.
|
|
8
|
-
* @param {boolean} noInterpolate If true, the vehicle position is not interpolated on each render but only once.
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
const getVehiclePosition = (now, trajectory, noInterpolate) => {
|
|
12
|
-
const {
|
|
13
|
-
time_intervals: timeIntervals,
|
|
14
|
-
olGeometry: geometry,
|
|
15
|
-
coordinate,
|
|
16
|
-
} = trajectory.properties;
|
|
17
|
-
|
|
18
|
-
let coord;
|
|
19
|
-
let rotation;
|
|
20
|
-
|
|
21
|
-
if (noInterpolate && coordinate) {
|
|
22
|
-
coord = coordinate;
|
|
23
|
-
} else if (geometry.getType() === GeomType.POINT) {
|
|
24
|
-
coord = geometry.getCoordinates();
|
|
25
|
-
} else if (geometry.getType() === GeomType.LINE_STRING) {
|
|
26
|
-
const intervals = timeIntervals || [[]];
|
|
27
|
-
const firstInterval = intervals[0];
|
|
28
|
-
const lastInterval = intervals[intervals.length - 1];
|
|
29
|
-
|
|
30
|
-
// Between the last time interval of a trajectory event and the beginning
|
|
31
|
-
// of the new trajectory event, there is few seconds, can be 6 to 30
|
|
32
|
-
// seconds (that's why the vehicle jumps sometimes).
|
|
33
|
-
// So we make the choice here to display the last (or the first) position
|
|
34
|
-
// of an trajectory event instead of removing them, if the current date is
|
|
35
|
-
// outside the time intervals we display the vehicle at the last (or first) position known.
|
|
36
|
-
if (now < firstInterval[0]) {
|
|
37
|
-
// Display first position known.
|
|
38
|
-
[, , rotation] = firstInterval;
|
|
39
|
-
coord = geometry.getFirstCoordinate();
|
|
40
|
-
} else if (now > lastInterval[0]) {
|
|
41
|
-
// Display last position known.
|
|
42
|
-
[, , rotation] = lastInterval;
|
|
43
|
-
coord = geometry.getLastCoordinate();
|
|
44
|
-
} else {
|
|
45
|
-
// Interpolate position using time intervals.
|
|
46
|
-
for (let j = 0; j < intervals.length - 1; j += 1) {
|
|
47
|
-
// Rotation only available in tralis layer.
|
|
48
|
-
const [start, startFrac] = intervals[j];
|
|
49
|
-
const [end, endFrac] = intervals[j + 1];
|
|
50
|
-
|
|
51
|
-
if (start <= now && now <= end) {
|
|
52
|
-
// interpolate position inside the time interval.
|
|
53
|
-
const timeFrac = Math.min((now - start) / (end - start), 1);
|
|
54
|
-
const geomFrac = timeFrac * (endFrac - startFrac) + startFrac;
|
|
55
|
-
coord = geometry.getCoordinateAt(geomFrac);
|
|
56
|
-
[, , rotation] = intervals[j];
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
// eslint-disable-next-line no-console
|
|
63
|
-
console.error(
|
|
64
|
-
'This geometry type is not supported. Only Point or LineString are. Current geometry: ',
|
|
65
|
-
geometry,
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return { coord, rotation };
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export default getVehiclePosition;
|
package/common/utils/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { default as getMapboxStyleUrl } from './getMapboxStyleUrl';
|
|
2
|
-
export { default as getMapboxMapCopyrights } from './getMapboxMapCopyrights';
|
|
3
|
-
export { default as removeDuplicate } from './removeDuplicate';
|
|
4
|
-
export * from './timeUtils';
|
|
5
|
-
export * from '../styles';
|
|
6
|
-
export { default as sortByDelay } from './sortByDelay';
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
* @ignore
|
|
7
|
-
*/
|
|
8
|
-
const removeDuplicate = (array) => {
|
|
9
|
-
const arrWithoutEmptyValues = array.filter(
|
|
10
|
-
(val) => val !== undefined && val !== null && val.trim && val.trim(),
|
|
11
|
-
);
|
|
12
|
-
const lowerCasesValues = arrWithoutEmptyValues.map((str) =>
|
|
13
|
-
str.toLowerCase(),
|
|
14
|
-
);
|
|
15
|
-
const uniqueLowerCaseValues = [...new Set(lowerCasesValues)];
|
|
16
|
-
const uniqueValues = uniqueLowerCaseValues.map((uniqueStr) =>
|
|
17
|
-
arrWithoutEmptyValues.find((str) => str.toLowerCase() === uniqueStr),
|
|
18
|
-
);
|
|
19
|
-
return uniqueValues;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export default removeDuplicate;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import removeDuplicate from './removeDuplicate';
|
|
2
|
-
|
|
3
|
-
describe('removeDuplicate()', () => {
|
|
4
|
-
test('removes duplicates', () => {
|
|
5
|
-
expect(
|
|
6
|
-
removeDuplicate([
|
|
7
|
-
'a',
|
|
8
|
-
' ',
|
|
9
|
-
' ',
|
|
10
|
-
'b',
|
|
11
|
-
'a',
|
|
12
|
-
undefined,
|
|
13
|
-
null,
|
|
14
|
-
'A',
|
|
15
|
-
0,
|
|
16
|
-
'c',
|
|
17
|
-
'b',
|
|
18
|
-
'B',
|
|
19
|
-
]),
|
|
20
|
-
).toEqual(['a', 'b', 'c']);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const sortByDelay = (traj1, traj2) => {
|
|
2
|
-
const props1 = traj1.properties;
|
|
3
|
-
const props2 = traj2.properties;
|
|
4
|
-
|
|
5
|
-
if (props1.delay === null && props2.delay !== null) {
|
|
6
|
-
return 1;
|
|
7
|
-
}
|
|
8
|
-
if (props2.delay === null && props1.delay !== null) {
|
|
9
|
-
return -1;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// We put cancelled train inbetween green and yellow trains
|
|
13
|
-
// >=180000ms corresponds to yellow train
|
|
14
|
-
if (props1.cancelled && !props2.cancelled) {
|
|
15
|
-
return props2.delay < 180000 ? -1 : 1;
|
|
16
|
-
}
|
|
17
|
-
if (props2.cancelled && !props1.cancelled) {
|
|
18
|
-
return props1.delay < 180000 ? 1 : -1;
|
|
19
|
-
}
|
|
20
|
-
return props2.delay - props1.delay;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default sortByDelay;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get a Date object as UTC date string .
|
|
3
|
-
* ex: 2019 09 01
|
|
4
|
-
* @ignore
|
|
5
|
-
*/
|
|
6
|
-
export const getUTCDateString = (now = new Date()) => {
|
|
7
|
-
let month = (now.getUTCMonth() + 1).toString();
|
|
8
|
-
month = month.length === 1 ? `0${month}` : month;
|
|
9
|
-
let day = now.getUTCDate().toString();
|
|
10
|
-
day = day.length === 1 ? `0${day}` : day;
|
|
11
|
-
|
|
12
|
-
return [now.getUTCFullYear(), month, day].join('');
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Get the UTC time string of Date object.
|
|
17
|
-
* ex: 09:05:01.123
|
|
18
|
-
* @ignore
|
|
19
|
-
*/
|
|
20
|
-
export const getUTCTimeString = (date) =>
|
|
21
|
-
[
|
|
22
|
-
date.getUTCHours(),
|
|
23
|
-
date.getUTCMinutes(),
|
|
24
|
-
`${date.getUTCSeconds()}.${date.getUTCMilliseconds()}`,
|
|
25
|
-
].join(':');
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Returns a string representation of a number, with a zero if the number is lower than 10.
|
|
29
|
-
* @ignore
|
|
30
|
-
*/
|
|
31
|
-
export const pad = (integer) => (integer < 10 ? `0${integer}` : integer);
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Returns a 'hh:mm' string from a time in ms.
|
|
35
|
-
* @param {Number} timeInMs Time in milliseconds.
|
|
36
|
-
* @ignore
|
|
37
|
-
*/
|
|
38
|
-
export const getHoursAndMinutes = (timeInMs) => {
|
|
39
|
-
if (!timeInMs || timeInMs <= 0) {
|
|
40
|
-
return '';
|
|
41
|
-
}
|
|
42
|
-
const date = new Date(timeInMs);
|
|
43
|
-
return `${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
44
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { getUTCDateString, getUTCTimeString } from './timeUtils';
|
|
2
|
-
|
|
3
|
-
describe('timeUtils', () => {
|
|
4
|
-
test('getUTCDateString should be correct.', () => {
|
|
5
|
-
expect(getUTCDateString(new Date(2020, 5, 30))).toBe('20200630');
|
|
6
|
-
expect(
|
|
7
|
-
getUTCDateString(new Date('January 1, 2021 00:15:30 GMT+2:00')),
|
|
8
|
-
).toBe('20201231');
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('getUTCTimeString should be correct.', () => {
|
|
12
|
-
expect(getUTCTimeString(new Date(2020, 5, 30, 11, 5, 1, 123))).toBe(
|
|
13
|
-
'11:5:1.123',
|
|
14
|
-
);
|
|
15
|
-
});
|
|
16
|
-
});
|