mobility-toolbox-js 2.0.1-beta.13 → 2.1.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/api/RealtimeAPI.d.ts +279 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RealtimeAPI.js +466 -0
- package/api/RoutingAPI.d.ts +37 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/RoutingAPI.js +32 -12
- package/api/StopsAPI.d.ts +38 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/StopsAPI.js +33 -9
- package/api/index.d.ts +4 -0
- package/api/index.d.ts.map +1 -0
- package/api/index.js +3 -3
- package/api/typedefs.d.ts +179 -0
- package/api/typedefs.d.ts.map +1 -0
- package/api/typedefs.js +75 -0
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/HttpAPI.js +54 -27
- package/common/api/WebSocketAPI.d.ts +153 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.js +330 -164
- package/common/controls/ControlCommon.d.ts +76 -0
- package/common/controls/ControlCommon.d.ts.map +1 -0
- package/common/controls/ControlCommon.js +150 -0
- package/common/controls/CopyrightControlCommon.d.ts +13 -0
- package/common/controls/CopyrightControlCommon.d.ts.map +1 -0
- package/common/controls/CopyrightControlCommon.js +34 -0
- package/common/controls/StopFinderControlCommon.d.ts +55 -0
- package/common/controls/StopFinderControlCommon.d.ts.map +1 -0
- package/common/controls/StopFinderControlCommon.js +144 -0
- package/common/index.d.ts +3 -0
- package/common/index.d.ts.map +1 -0
- package/common/index.js +2 -4
- package/common/layers/LayerCommon.d.ts +94 -0
- package/common/layers/LayerCommon.d.ts.map +1 -0
- package/common/layers/LayerCommon.js +244 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +286 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.js +776 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts +60 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.js +241 -0
- package/common/styles/index.d.ts +5 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/index.js +4 -4
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.js +275 -0
- package/common/styles/realtimeDelayStyle.d.ts +12 -0
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeDelayStyle.js +13 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts.map +1 -0
- package/common/styles/realtimeHeadingStyle.js +85 -0
- package/common/styles/realtimeSimpleStyle.d.ts +4 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.js +23 -0
- package/common/typedefs.d.ts +111 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/typedefs.js +52 -0
- package/common/utils/compareDepartures.d.ts +11 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/compareDepartures.js +35 -0
- package/common/utils/createCanvas.d.ts +10 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createCanvas.js +27 -0
- package/common/utils/createRealtimeFilters.d.ts +13 -0
- package/common/utils/createRealtimeFilters.d.ts.map +1 -0
- package/common/utils/createRealtimeFilters.js +74 -0
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts.map +1 -0
- package/common/utils/debounceDeparturesMessages.js +24 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/debounceWebsocketMessages.d.ts.map +1 -0
- package/common/utils/debounceWebsocketMessages.js +29 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.js +15 -0
- package/common/utils/getMapboxMapCopyrights.d.ts +18 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.js +26 -15
- package/common/utils/getMapboxRender.d.ts +7 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMapboxRender.js +87 -0
- package/common/utils/getMaplibreRender.d.ts +7 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.js +38 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.js +7 -0
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.js +18 -0
- package/common/utils/getVehiclePosition.d.ts +16 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.js +67 -37
- package/common/utils/index.d.ts +17 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/index.js +17 -5
- package/common/utils/realtimeConfig.d.ts +49 -0
- package/common/utils/realtimeConfig.d.ts.map +1 -0
- package/common/utils/realtimeConfig.js +173 -0
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/removeDuplicate.js +12 -5
- package/common/utils/renderTrajectories.d.ts +17 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/renderTrajectories.js +110 -0
- package/common/utils/sortAndFilterDepartures.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.d.ts.map +1 -0
- package/common/utils/sortAndFilterDepartures.js +58 -0
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/sortByDelay.js +17 -15
- package/common/utils/timeUtils.d.ts +24 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/timeUtils.js +34 -15
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/iife.js +5 -0
- package/index.d.ts +10 -0
- package/index.d.ts.map +1 -0
- package/index.js +8 -6
- package/mapbox/controls/CopyrightControl.d.ts +29 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.js +44 -25
- package/mapbox/controls/index.d.ts +2 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/controls/index.js +2 -1
- package/mapbox/index.d.ts +6 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/index.js +5 -4
- package/mapbox/layers/Layer.d.ts +59 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/Layer.js +99 -55
- package/mapbox/layers/RealtimeLayer.d.ts +181 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.js +276 -0
- package/mapbox/layers/index.d.ts +3 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/layers/index.js +2 -2
- package/mapbox/utils/getMercatorResolution.d.ts +9 -0
- package/mapbox/utils/getMercatorResolution.d.ts.map +1 -0
- package/mapbox/utils/getMercatorResolution.js +18 -0
- package/mapbox/utils/getSourceCoordinates.d.ts +9 -0
- package/mapbox/utils/getSourceCoordinates.d.ts.map +1 -0
- package/mapbox/utils/getSourceCoordinates.js +27 -0
- package/mapbox/utils/index.d.ts +3 -0
- package/mapbox/utils/index.d.ts.map +1 -0
- package/mapbox/utils/index.js +2 -0
- package/mbt.js +26061 -16500
- package/mbt.js.map +4 -4
- package/mbt.min.js +205 -126
- package/mbt.min.js.map +4 -4
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.js +62 -36
- package/ol/controls/RoutingControl.d.ts +193 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.js +601 -357
- package/ol/controls/StopFinderControl.d.ts +30 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.js +30 -8
- package/ol/controls/index.d.ts +4 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/controls/index.js +3 -3
- package/ol/index.d.ts +6 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/index.js +5 -5
- package/ol/layers/Layer.d.ts +86 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/Layer.js +163 -77
- package/ol/layers/MapGlLayer.d.ts +67 -0
- package/ol/layers/MapGlLayer.d.ts.map +1 -0
- package/ol/layers/MapGlLayer.js +218 -0
- package/ol/layers/MapboxLayer.d.ts +50 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.js +99 -193
- package/ol/layers/MapboxStyleLayer.d.ts +129 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.js +362 -171
- package/ol/layers/MaplibreLayer.d.ts +28 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.js +30 -135
- package/ol/layers/RealtimeLayer.d.ts +202 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.js +340 -0
- package/ol/layers/RoutingLayer.d.ts +34 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.js +72 -48
- package/ol/layers/VectorLayer.d.ts +25 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.js +34 -18
- package/ol/layers/WMSLayer.d.ts +42 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.js +84 -34
- package/ol/layers/index.d.ts +9 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/layers/index.js +8 -8
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +26 -24
- package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.js +40 -39
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/ol/styles/index.js +2 -2
- package/package.json +81 -133
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/setupTests.js +26 -0
- package/types/common.d.ts +122 -0
- package/types/index.d.ts +11 -0
- package/types/realtime.d.ts +320 -0
- package/types/routing.d.ts +206 -0
- package/types/stops.d.ts +143 -0
- package/README.md +0 -23
- package/api/RoutingAPI.test.js +0 -25
- package/api/StopsAPI.test.js +0 -22
- package/api/TralisAPI.js +0 -359
- package/api/TralisAPI.test.js +0 -67
- package/api/TralisAPIUtils.js +0 -43
- package/common/Tracker.js +0 -93
- package/common/api/HttpAPI.test.js +0 -50
- package/common/api/WebSocketAPI.test.js +0 -311
- package/common/controls/Control.js +0 -81
- package/common/controls/Control.test.js +0 -87
- package/common/layers/Layer.js +0 -213
- package/common/layers/Layer.test.js +0 -526
- package/common/mixins/CopyrightMixin.js +0 -24
- package/common/mixins/SearchMixin.js +0 -110
- package/common/mixins/TralisLayerMixin.js +0 -479
- package/common/styles/trackerDefaultStyle.js +0 -197
- package/common/styles/trackerDelayStyle.js +0 -8
- package/common/styles/trackerSimpleStyle.js +0 -18
- package/common/trackerConfig.js +0 -152
- package/common/trackerConfig.test.js +0 -23
- package/common/utils/createTrackerFilters.js +0 -56
- package/common/utils/createTrackerFilters.test.js +0 -79
- package/common/utils/getMapboxMapCopyrights.test.js +0 -40
- package/common/utils/getMapboxStyleUrl.js +0 -22
- package/common/utils/removeDuplicate.test.js +0 -19
- package/common/utils/timeUtils.test.js +0 -10
- package/mapbox/layers/Layer.test.js +0 -182
- package/mapbox/layers/TralisLayer.js +0 -182
- package/mapbox/layers/TralisLayer.test.js +0 -38
- package/mapbox/utils.js +0 -32
- package/ol/controls/CopyrightControl.test.js +0 -165
- package/ol/controls/RoutingControl.test.js +0 -151
- package/ol/controls/StopFinderControl.test.js +0 -48
- package/ol/layers/Layer.test.js +0 -174
- package/ol/layers/MapboxLayer.test.js +0 -160
- package/ol/layers/MapboxStyleLayer.test.js +0 -231
- package/ol/layers/RoutingLayer.test.js +0 -40
- package/ol/layers/TralisLayer.js +0 -185
- package/ol/layers/TralisLayer.test.js +0 -79
- package/ol/layers/VectorLayer.test.js +0 -87
- package/ol/layers/WMSLayer.test.js +0 -76
package/types/stops.d.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by openapi-typescript.
|
|
3
|
+
* Do not make direct changes to the file.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface Paths {
|
|
7
|
+
'/': {
|
|
8
|
+
/** Returns a stop (or multiple) as GeoJSON FeatureCollection */
|
|
9
|
+
get: {
|
|
10
|
+
parameters: {
|
|
11
|
+
query: {
|
|
12
|
+
/** Control how many matches will be returned */
|
|
13
|
+
limit?: number;
|
|
14
|
+
/** Anything you'd like to search for */
|
|
15
|
+
q: string;
|
|
16
|
+
/**
|
|
17
|
+
* comma seperated list, order chooses which agency will be preferred
|
|
18
|
+
* as ident_source (for id and code fields)
|
|
19
|
+
*/
|
|
20
|
+
prefagencies?: 'sbb' | 'db';
|
|
21
|
+
/**
|
|
22
|
+
* comma seperated list of mot's which should be available
|
|
23
|
+
* at the stop
|
|
24
|
+
*/
|
|
25
|
+
mots?:
|
|
26
|
+
| 'bus'
|
|
27
|
+
| 'ferry'
|
|
28
|
+
| 'gondola'
|
|
29
|
+
| 'tram'
|
|
30
|
+
| 'rail'
|
|
31
|
+
| 'funicular'
|
|
32
|
+
| 'cable_car'
|
|
33
|
+
| 'subway';
|
|
34
|
+
/**
|
|
35
|
+
* left,bottom,right,up coordinates in WGS84 wherein the
|
|
36
|
+
* station should lie
|
|
37
|
+
*/
|
|
38
|
+
bbox?: string;
|
|
39
|
+
/** which field to look up, default: all of them */
|
|
40
|
+
field?: 'id' | 'name' | 'coords';
|
|
41
|
+
/**
|
|
42
|
+
* Coordinates in WGS84 (in lat,lon order) used to rank stops close to
|
|
43
|
+
* this position higher
|
|
44
|
+
*/
|
|
45
|
+
ref_location?: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
responses: {
|
|
49
|
+
/** stop(s) */
|
|
50
|
+
200: {
|
|
51
|
+
schema: {
|
|
52
|
+
/** @enum {string} */
|
|
53
|
+
type?: 'FeatureCollection';
|
|
54
|
+
features?: {
|
|
55
|
+
/** @enum {string} */
|
|
56
|
+
type?: 'Feature';
|
|
57
|
+
properties?: {
|
|
58
|
+
/** @description internal ID */
|
|
59
|
+
uid?: string;
|
|
60
|
+
/**
|
|
61
|
+
* @description name of the stop
|
|
62
|
+
* @example Bern
|
|
63
|
+
*/
|
|
64
|
+
name?: string;
|
|
65
|
+
/**
|
|
66
|
+
* @description 2 letter country code where the station is located
|
|
67
|
+
* @example CH
|
|
68
|
+
*/
|
|
69
|
+
country_code?: string;
|
|
70
|
+
/**
|
|
71
|
+
* @description how well the result matches your query, 0
|
|
72
|
+
* means best
|
|
73
|
+
*/
|
|
74
|
+
rank?: number;
|
|
75
|
+
/**
|
|
76
|
+
* @description array of translations of the stopname
|
|
77
|
+
* @default []
|
|
78
|
+
*/
|
|
79
|
+
translated_names?: {
|
|
80
|
+
value?: string;
|
|
81
|
+
/** @enum {string} */
|
|
82
|
+
language?: 'de' | 'en' | 'fr' | 'it';
|
|
83
|
+
}[];
|
|
84
|
+
/** @description Means of transport that are available at this station */
|
|
85
|
+
mot?: {
|
|
86
|
+
bus?: boolean;
|
|
87
|
+
ferry?: boolean;
|
|
88
|
+
gondola?: boolean;
|
|
89
|
+
tram?: boolean;
|
|
90
|
+
rail?: boolean;
|
|
91
|
+
funicular?: boolean;
|
|
92
|
+
cable_car?: boolean;
|
|
93
|
+
subway?: boolean;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* @description source agency for id and code (see below)
|
|
97
|
+
* @example sbb
|
|
98
|
+
*/
|
|
99
|
+
ident_source?: string;
|
|
100
|
+
/**
|
|
101
|
+
* @description uic number
|
|
102
|
+
* @example 8507000
|
|
103
|
+
*/
|
|
104
|
+
id?: string;
|
|
105
|
+
/**
|
|
106
|
+
* @description Abbreviation code from the transport agency (e.g. DS100 for Deutsche Bahn)
|
|
107
|
+
*
|
|
108
|
+
* @example BN
|
|
109
|
+
*/
|
|
110
|
+
code?: string;
|
|
111
|
+
/** @description ifopt identifier, if available */
|
|
112
|
+
ifopt?: string;
|
|
113
|
+
};
|
|
114
|
+
/** @description the coordinates of the stop */
|
|
115
|
+
geometry?: {
|
|
116
|
+
/** @enum {string} */
|
|
117
|
+
type?: 'Point';
|
|
118
|
+
/**
|
|
119
|
+
* @example [
|
|
120
|
+
* 7.439119,
|
|
121
|
+
* 46.94882
|
|
122
|
+
* ]
|
|
123
|
+
*/
|
|
124
|
+
coordinates?: number[];
|
|
125
|
+
};
|
|
126
|
+
}[];
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
/** limit parameter too high */
|
|
130
|
+
400: {
|
|
131
|
+
schema: {
|
|
132
|
+
/** @enum {string} */
|
|
133
|
+
error?: '400 Bad Request: Limit has to be an integer between 1 and 500';
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface Operations {}
|
|
142
|
+
|
|
143
|
+
export interface External {}
|
package/README.md
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# mobility-toolbox-js
|
|
2
|
-
|
|
3
|
-
Toolbox for JavaScript applications in the domains of mobility and logistics.
|
|
4
|
-
The tools in this library have been inspired by many projects realized for public transport agencies, mobility providers and logistics companies.
|
|
5
|
-
|
|
6
|
-
[](https://www.npmjs.com/package/mobility-toolbox-js)
|
|
7
|
-
[](https://github.com/geops/mobility-toolbox-js/actions?query=workflow%3ABuild)
|
|
8
|
-
[](https://app.netlify.com/sites/mobility-toolbox-js/deploys)
|
|
9
|
-
|
|
10
|
-
## Main Features
|
|
11
|
-
|
|
12
|
-
* Display [real-time vehicle positions and prognosis data](http://tracker.geops.ch/) on a map.
|
|
13
|
-
* Search for [stops and stations](https://maps2.trafimage.ch) all over the world.
|
|
14
|
-
* Get [precise geographic courses](https://geops.github.io/geops-routing-demo/) for all modes of transport.
|
|
15
|
-
* Generate beautiful maps for public transport, mobility and logistics
|
|
16
|
-
|
|
17
|
-
## Documentation and examples
|
|
18
|
-
|
|
19
|
-
Visit https://master--mobility-toolbox-js.netlify.app/
|
|
20
|
-
|
|
21
|
-
## Version 1.x.x
|
|
22
|
-
|
|
23
|
-
The master branch is now open for the version 2 development. The version 1 is still available in [1.x.x](https://github.com/geops/mobility-toolbox-js/tree/1.x.x) branch.
|
package/api/RoutingAPI.test.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import fetch from "jest-fetch-mock";
|
|
2
|
-
import RoutingAPI from "./RoutingAPI";
|
|
3
|
-
let api;
|
|
4
|
-
describe("RoutingAPI", () => {
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
global.fetch = fetch;
|
|
7
|
-
fetch.resetMocks();
|
|
8
|
-
api = new RoutingAPI({ apiKey: "apiKey" });
|
|
9
|
-
});
|
|
10
|
-
describe("#route", () => {
|
|
11
|
-
test("should success", (done) => {
|
|
12
|
-
fetch.mockResponseOnce(JSON.stringify(global.fetchRouteResponse));
|
|
13
|
-
return api.route({
|
|
14
|
-
mot: "bus",
|
|
15
|
-
via: "47.3739194713294,8.538274823394632|47.37595378493421,8.537490375951839"
|
|
16
|
-
}).then((featureCollection) => {
|
|
17
|
-
expect(fetch.mock.calls[0][0]).toEqual("https://api.geops.io/routing/v1/?key=apiKey&mot=bus&via=47.3739194713294%2C8.538274823394632%7C47.37595378493421%2C8.537490375951839");
|
|
18
|
-
expect(featureCollection.features[0].geometry.type).toEqual("LineString");
|
|
19
|
-
expect(featureCollection.features[0].properties.lines).toBeDefined();
|
|
20
|
-
expect(featureCollection.features[0].properties.station_to).toBeDefined();
|
|
21
|
-
done();
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
});
|
package/api/StopsAPI.test.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import fetch from "jest-fetch-mock";
|
|
2
|
-
import StopsAPI from "./StopsAPI";
|
|
3
|
-
let api;
|
|
4
|
-
describe("StopsAPI", () => {
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
global.fetch = fetch;
|
|
7
|
-
fetch.resetMocks();
|
|
8
|
-
api = new StopsAPI({ apiKey: "apiKey" });
|
|
9
|
-
});
|
|
10
|
-
describe("#search", () => {
|
|
11
|
-
test("should success", (done) => {
|
|
12
|
-
fetch.mockResponseOnce(JSON.stringify(global.stopsSearchResponse));
|
|
13
|
-
return api.search({
|
|
14
|
-
q: "Bern"
|
|
15
|
-
}).then((featureCollection) => {
|
|
16
|
-
expect(fetch.mock.calls[0][0]).toEqual("https://api.geops.io/stops/v1/?key=apiKey&q=Bern");
|
|
17
|
-
expect(featureCollection.features[0].properties.name).toEqual("Bern");
|
|
18
|
-
done();
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
});
|
package/api/TralisAPI.js
DELETED
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
import WebSocketAPI from "../common/api/WebSocketAPI";
|
|
2
|
-
import {
|
|
3
|
-
getModeSuffix,
|
|
4
|
-
cleanStopTime,
|
|
5
|
-
compareDepartures
|
|
6
|
-
} from "./TralisAPIUtils";
|
|
7
|
-
export const TralisModes = {
|
|
8
|
-
RAW: "raw",
|
|
9
|
-
TOPOGRAPHIC: "topographic",
|
|
10
|
-
SCHEMATIC: "schematic"
|
|
11
|
-
};
|
|
12
|
-
class TralisAPI {
|
|
13
|
-
constructor(options = {}) {
|
|
14
|
-
this.defineProperties(options);
|
|
15
|
-
this.subscribedStationUic = null;
|
|
16
|
-
this.departureUpdateTimeout = null;
|
|
17
|
-
this.maxDepartureAge = 30;
|
|
18
|
-
this.extraGeoms = {};
|
|
19
|
-
this.prefix = options.prefix || "";
|
|
20
|
-
this.onOpen = this.onOpen.bind(this);
|
|
21
|
-
}
|
|
22
|
-
defineProperties(options) {
|
|
23
|
-
let opt = options;
|
|
24
|
-
if (typeof options === "string") {
|
|
25
|
-
opt = { url: options };
|
|
26
|
-
}
|
|
27
|
-
const { apiKey } = opt;
|
|
28
|
-
let { url, projection, bbox, buffer = [100, 100] } = opt;
|
|
29
|
-
const wsApi = new WebSocketAPI();
|
|
30
|
-
if (apiKey) {
|
|
31
|
-
url = `${url || "wss://api.geops.io/tracker-ws/v1/"}?key=${apiKey}`;
|
|
32
|
-
}
|
|
33
|
-
Object.defineProperties(this, {
|
|
34
|
-
url: {
|
|
35
|
-
get: () => url,
|
|
36
|
-
set: (newUrl) => {
|
|
37
|
-
url = newUrl;
|
|
38
|
-
this.open();
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
projection: {
|
|
42
|
-
get: () => projection,
|
|
43
|
-
set: (newProjection) => {
|
|
44
|
-
if (newProjection !== projection) {
|
|
45
|
-
projection = newProjection;
|
|
46
|
-
if (this.wsApi) {
|
|
47
|
-
this.wsApi.send(`PROJECTION ${projection}`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
bbox: {
|
|
53
|
-
get: () => bbox,
|
|
54
|
-
set: (newBbox) => {
|
|
55
|
-
if (JSON.stringify(newBbox) !== JSON.stringify(bbox)) {
|
|
56
|
-
bbox = newBbox;
|
|
57
|
-
if (this.wsApi) {
|
|
58
|
-
this.wsApi.send(`BBOX ${bbox.join(" ")}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
buffer: {
|
|
64
|
-
get: () => buffer,
|
|
65
|
-
set: (newBuffer) => {
|
|
66
|
-
if (JSON.stringify(newBuffer) !== JSON.stringify(buffer)) {
|
|
67
|
-
buffer = newBuffer;
|
|
68
|
-
if (this.wsApi) {
|
|
69
|
-
this.wsApi.send(`BUFFER ${buffer.join(" ")}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
wsApi: {
|
|
75
|
-
value: wsApi,
|
|
76
|
-
writable: true
|
|
77
|
-
},
|
|
78
|
-
pingIntervalMs: {
|
|
79
|
-
value: options.pingIntervalMs || 1e4,
|
|
80
|
-
writable: true
|
|
81
|
-
},
|
|
82
|
-
reconnectTimeoutMs: {
|
|
83
|
-
value: options.pingIntervalMs || 100,
|
|
84
|
-
writable: true
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
open() {
|
|
89
|
-
this.close();
|
|
90
|
-
this.wsApi.connect(this.url, this.onOpen);
|
|
91
|
-
this.wsApi.websocket.onclose = () => {
|
|
92
|
-
this.onClose();
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
close() {
|
|
96
|
-
this.wsApi.close();
|
|
97
|
-
}
|
|
98
|
-
reset() {
|
|
99
|
-
this.wsApi.send("RESET");
|
|
100
|
-
}
|
|
101
|
-
onOpen() {
|
|
102
|
-
if (this.projection) {
|
|
103
|
-
this.wsApi.send(`PROJECTION ${this.projection}`);
|
|
104
|
-
}
|
|
105
|
-
if (this.bbox) {
|
|
106
|
-
this.wsApi.send(`BBOX ${this.bbox.join(" ")}`);
|
|
107
|
-
}
|
|
108
|
-
if (this.buffer) {
|
|
109
|
-
this.wsApi.send(`BUFFER ${this.buffer.join(" ")}`);
|
|
110
|
-
}
|
|
111
|
-
if (this.pingIntervalMs) {
|
|
112
|
-
window.clearInterval(this.pingInterval);
|
|
113
|
-
this.pingInterval = setInterval(() => {
|
|
114
|
-
this.wsApi.send("PING");
|
|
115
|
-
}, this.pingIntervalMs);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
onClose() {
|
|
119
|
-
window.clearTimeout(this.pingInterval);
|
|
120
|
-
window.clearTimeout(this.reconnectTimeout);
|
|
121
|
-
if (this.reconnectTimeoutMs) {
|
|
122
|
-
this.reconnectTimeout = window.setTimeout(() => this.open(), this.reconnectTimeoutMs);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
subscribe(channel, onSuccess, onError, quiet = false) {
|
|
126
|
-
this.wsApi.subscribe({ channel }, onSuccess, onError, quiet);
|
|
127
|
-
}
|
|
128
|
-
unsubscribe(channel, suffix, cb) {
|
|
129
|
-
this.wsApi.unsubscribe(`${channel}${getModeSuffix(TralisModes.SCHEMATIC, TralisModes)}${suffix}`, cb);
|
|
130
|
-
this.wsApi.unsubscribe(`${channel}${getModeSuffix(TralisModes.TOPOGRAPHIC, TralisModes)}${suffix || ""}`, cb);
|
|
131
|
-
}
|
|
132
|
-
filterDepartures(depObject, sortByMinArrivalTime = false) {
|
|
133
|
-
const departures = Object.keys(depObject).map((k) => depObject[k]);
|
|
134
|
-
departures.sort((a, b) => compareDepartures(a, b, sortByMinArrivalTime));
|
|
135
|
-
let future = new Date();
|
|
136
|
-
future.setMinutes(future.getMinutes() + this.maxDepartureAge);
|
|
137
|
-
future = future.getTime();
|
|
138
|
-
let past = new Date();
|
|
139
|
-
past.setMinutes(past.getMinutes() - this.maxDepartureAge);
|
|
140
|
-
past = past.getTime();
|
|
141
|
-
const departureArray = [];
|
|
142
|
-
const platformsBoarding = [];
|
|
143
|
-
let previousDeparture = null;
|
|
144
|
-
for (let i = departures.length - 1; i >= 0; i -= 1) {
|
|
145
|
-
const d = departures[i];
|
|
146
|
-
const t = new Date(d.time).getTime();
|
|
147
|
-
if (t > past && t < future) {
|
|
148
|
-
if (d.state === "BOARDING") {
|
|
149
|
-
if (platformsBoarding.indexOf(d.platform) === -1) {
|
|
150
|
-
platformsBoarding.push(d.platform);
|
|
151
|
-
} else {
|
|
152
|
-
d.state = "HIDDEN";
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (previousDeparture && d.to[0] === previousDeparture.to[0] && Math.abs(t - previousDeparture.time) < 1e3 && d.line.name === previousDeparture.line.name) {
|
|
156
|
-
d.state = "HIDDEN";
|
|
157
|
-
}
|
|
158
|
-
if (/(STOP_CANCELLED|JOURNEY_CANCELLED)/.test(d.state)) {
|
|
159
|
-
d.cancelled = true;
|
|
160
|
-
}
|
|
161
|
-
previousDeparture = d;
|
|
162
|
-
previousDeparture.time = t;
|
|
163
|
-
departureArray.unshift(d);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return departureArray;
|
|
167
|
-
}
|
|
168
|
-
subscribeDepartures(stationId, sortByMinArrivalTime, onMessage) {
|
|
169
|
-
window.clearTimeout(this.departureUpdateTimeout);
|
|
170
|
-
this.unsubscribeDepartures();
|
|
171
|
-
this.subscribedStationUic = stationId;
|
|
172
|
-
const channel = stationId ? `timetable_${stationId}` : null;
|
|
173
|
-
const departureObject = {};
|
|
174
|
-
this.subscribe(channel, (data) => {
|
|
175
|
-
if (data.source === channel) {
|
|
176
|
-
const content = data.content || {};
|
|
177
|
-
const tDiff = new Date(content.timestamp).getTime() - Date.now();
|
|
178
|
-
content.timediff = tDiff;
|
|
179
|
-
departureObject[content.call_id] = content;
|
|
180
|
-
window.clearTimeout(this.departureUpdateTimeout);
|
|
181
|
-
this.departureUpdateTimeout = window.setTimeout(() => {
|
|
182
|
-
const departures = this.filterDepartures(departureObject, sortByMinArrivalTime || false);
|
|
183
|
-
onMessage(departures);
|
|
184
|
-
}, 100);
|
|
185
|
-
}
|
|
186
|
-
}, () => {
|
|
187
|
-
onMessage([]);
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
unsubscribeDepartures(cb) {
|
|
191
|
-
if (this.subscribedStationUic) {
|
|
192
|
-
this.unsubscribe(`timetable_${this.subscribedStationUic}`, "", cb);
|
|
193
|
-
this.subscribedStationUic = null;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
subscribeDisruptions(onMessage) {
|
|
197
|
-
this.subscribe(`${this.prefix}newsticker`, (data) => {
|
|
198
|
-
onMessage(data.content);
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
unsubscribeDisruptions(cb) {
|
|
202
|
-
this.unsubscribe(`${this.prefix}newsticker`, "", cb);
|
|
203
|
-
}
|
|
204
|
-
getStation(uic, mode) {
|
|
205
|
-
const params = {
|
|
206
|
-
channel: `station${getModeSuffix(mode, TralisModes)}`,
|
|
207
|
-
args: uic
|
|
208
|
-
};
|
|
209
|
-
return new Promise((resolve, reject) => {
|
|
210
|
-
this.wsApi.get(params, (data) => {
|
|
211
|
-
if (data.content) {
|
|
212
|
-
resolve(data.content);
|
|
213
|
-
} else {
|
|
214
|
-
reject();
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
getStations(mode) {
|
|
220
|
-
const stations = [];
|
|
221
|
-
const params = {
|
|
222
|
-
channel: `station${getModeSuffix(mode, TralisModes)}`
|
|
223
|
-
};
|
|
224
|
-
window.clearTimeout(this.stationUpdateTimeout);
|
|
225
|
-
return new Promise((resolve, reject) => {
|
|
226
|
-
this.wsApi.get(params, (data) => {
|
|
227
|
-
if (data.content) {
|
|
228
|
-
stations.push(data.content);
|
|
229
|
-
window.clearTimeout(this.stationUpdateTimeout);
|
|
230
|
-
this.stationUpdateTimeout = window.setTimeout(() => {
|
|
231
|
-
resolve(stations);
|
|
232
|
-
}, 50);
|
|
233
|
-
} else {
|
|
234
|
-
reject(data.content);
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
subscribeStations(mode, onMessage) {
|
|
240
|
-
this.unsubscribeStations();
|
|
241
|
-
this.subscribe(`station${getModeSuffix(mode, TralisModes)}`, (data) => {
|
|
242
|
-
if (data.content) {
|
|
243
|
-
onMessage(data.content);
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
unsubscribeStations(cb) {
|
|
248
|
-
window.clearTimeout(this.stationUpdateTimeout);
|
|
249
|
-
this.unsubscribe("station", "", cb);
|
|
250
|
-
}
|
|
251
|
-
subscribeExtraGeoms(onMessage) {
|
|
252
|
-
this.subscribe("extra_geoms", (data) => {
|
|
253
|
-
const extraGeom = data.content;
|
|
254
|
-
if (extraGeom) {
|
|
255
|
-
const { ref } = extraGeom.properties;
|
|
256
|
-
if (extraGeom.type === "Feature") {
|
|
257
|
-
this.extraGeoms[ref] = extraGeom;
|
|
258
|
-
} else {
|
|
259
|
-
delete this.extraGeoms[ref];
|
|
260
|
-
}
|
|
261
|
-
onMessage(Object.keys(this.extraGeoms).map((key) => this.extraGeoms[key]));
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
unsubscribeExtraGeoms(cb) {
|
|
266
|
-
this.unsubscribe("extra_geoms", "", cb);
|
|
267
|
-
}
|
|
268
|
-
subscribeTrajectory(mode, onMessage, quiet = false) {
|
|
269
|
-
this.unsubscribeTrajectory(onMessage);
|
|
270
|
-
this.subscribe(`trajectory${getModeSuffix(mode, TralisModes)}`, onMessage, null, quiet);
|
|
271
|
-
}
|
|
272
|
-
unsubscribeTrajectory(cb) {
|
|
273
|
-
this.unsubscribe(`trajectory`, "", cb);
|
|
274
|
-
}
|
|
275
|
-
subscribeDeletedVehicles(mode, onMessage, quiet = false) {
|
|
276
|
-
this.unsubscribeDeletedVehicles(onMessage);
|
|
277
|
-
this.subscribe(`deleted_vehicles${getModeSuffix(mode, TralisModes)}`, onMessage, null, quiet);
|
|
278
|
-
}
|
|
279
|
-
unsubscribeDeletedVehicles(cb) {
|
|
280
|
-
this.unsubscribe("deleted_vehicles", "", cb);
|
|
281
|
-
}
|
|
282
|
-
getFullTrajectory(id, mode, generalizationLevel) {
|
|
283
|
-
const channel = [`full_trajectory${getModeSuffix(mode, TralisModes)}`];
|
|
284
|
-
if (id) {
|
|
285
|
-
channel.push(id);
|
|
286
|
-
}
|
|
287
|
-
if ((!mode || mode === TralisModes.TOPOGRAPHIC) && generalizationLevel) {
|
|
288
|
-
channel.push(`gen${generalizationLevel}`);
|
|
289
|
-
}
|
|
290
|
-
const params = {
|
|
291
|
-
channel: channel.join("_")
|
|
292
|
-
};
|
|
293
|
-
return new Promise((resolve) => {
|
|
294
|
-
this.wsApi.get(params, (data) => {
|
|
295
|
-
if (data.content) {
|
|
296
|
-
resolve(data.content);
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
getFullTrajectories(ids, mode, generalizationLevel) {
|
|
302
|
-
const promises = ids.map((id) => this.getFullTrajectory(id, mode, generalizationLevel));
|
|
303
|
-
return Promise.all(promises);
|
|
304
|
-
}
|
|
305
|
-
subscribeFullTrajectory(id, mode) {
|
|
306
|
-
this.unsubscribeFullTrajectory(id);
|
|
307
|
-
this.subscribe(`full_trajectory${getModeSuffix(mode, TralisModes)}_${id}`, (data) => {
|
|
308
|
-
console.log("subscribe full_trajectory", data);
|
|
309
|
-
}, (err) => {
|
|
310
|
-
console.log("subscribe full_trajectory error", err);
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
unsubscribeFullTrajectory(id, cb) {
|
|
314
|
-
this.unsubscribe("full_trajectory", `_${id}`, cb);
|
|
315
|
-
}
|
|
316
|
-
getStopSequence(id) {
|
|
317
|
-
const params = {
|
|
318
|
-
channel: `stopsequence_${id}`
|
|
319
|
-
};
|
|
320
|
-
return new Promise((resolve, reject) => {
|
|
321
|
-
this.wsApi.get(params, (data) => {
|
|
322
|
-
if (data.content && data.content.length) {
|
|
323
|
-
const content = data.content.map((stopSequence) => cleanStopTime(stopSequence));
|
|
324
|
-
resolve(content);
|
|
325
|
-
}
|
|
326
|
-
resolve([]);
|
|
327
|
-
}, (err) => {
|
|
328
|
-
reject(err);
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
getStopSequences(ids) {
|
|
333
|
-
const promises = ids.map((id) => this.getStopSequence(id));
|
|
334
|
-
return Promise.all(promises);
|
|
335
|
-
}
|
|
336
|
-
subscribeStopSequence(id, onMessage) {
|
|
337
|
-
window.clearTimeout(this.fullTrajectoryUpdateTimeout);
|
|
338
|
-
this.unsubscribeStopSequence(id);
|
|
339
|
-
this.subscribe(`stopsequence_${id}`, (data) => {
|
|
340
|
-
if (data.content && data.content.length) {
|
|
341
|
-
const content = data.content.map((stopSequence) => cleanStopTime(stopSequence));
|
|
342
|
-
onMessage(content);
|
|
343
|
-
}
|
|
344
|
-
}, (err) => {
|
|
345
|
-
console.log("subscribe stopsequence error", err);
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
unsubscribeStopSequence(id, cb) {
|
|
349
|
-
this.unsubscribe(`stopsequence`, `_${id}`, cb);
|
|
350
|
-
}
|
|
351
|
-
subscribeHealthCheck(onMessage) {
|
|
352
|
-
this.unsubscribeHealthCheck();
|
|
353
|
-
this.subscribe("healthcheck", onMessage);
|
|
354
|
-
}
|
|
355
|
-
unsubscribeHealthCheck() {
|
|
356
|
-
this.unsubscribe("healthcheck");
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
export default TralisAPI;
|
package/api/TralisAPI.test.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { TralisAPI, TralisModes } from ".";
|
|
2
|
-
describe("TralisAPI", () => {
|
|
3
|
-
let tralisAPI;
|
|
4
|
-
let get;
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
get = jest.fn((params, cb) => {
|
|
7
|
-
cb({ content: "content" });
|
|
8
|
-
});
|
|
9
|
-
tralisAPI = new TralisAPI();
|
|
10
|
-
tralisAPI.wsApi = {
|
|
11
|
-
get
|
|
12
|
-
};
|
|
13
|
-
});
|
|
14
|
-
describe("#getFullTrajectory() calls fullTrajectory channel", () => {
|
|
15
|
-
test("without parameters", (done) => {
|
|
16
|
-
tralisAPI.getFullTrajectory().then(() => {
|
|
17
|
-
expect(get.mock.calls.length).toBe(1);
|
|
18
|
-
expect(get.mock.calls[0][0]).toEqual({
|
|
19
|
-
channel: "full_trajectory"
|
|
20
|
-
});
|
|
21
|
-
done();
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
[null, TralisModes.TOPOGRAPHIC].forEach((mode) => {
|
|
25
|
-
describe(`using mode ${mode}`, () => {
|
|
26
|
-
test("using id", (done) => {
|
|
27
|
-
tralisAPI.getFullTrajectory("foo", mode).then(() => {
|
|
28
|
-
expect(get.mock.calls.length).toBe(1);
|
|
29
|
-
expect(get.mock.calls[0][0]).toEqual({
|
|
30
|
-
channel: "full_trajectory_foo"
|
|
31
|
-
});
|
|
32
|
-
done();
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
test("using id and generalizationLevel param", (done) => {
|
|
36
|
-
tralisAPI.getFullTrajectory("foo", mode, 5).then(() => {
|
|
37
|
-
expect(get.mock.calls.length).toBe(1);
|
|
38
|
-
expect(get.mock.calls[0][0]).toEqual({
|
|
39
|
-
channel: "full_trajectory_foo_gen5"
|
|
40
|
-
});
|
|
41
|
-
done();
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
describe("using schematic mode ", () => {
|
|
47
|
-
test("using id", (done) => {
|
|
48
|
-
tralisAPI.getFullTrajectory("foo", TralisModes.SCHEMATIC).then(() => {
|
|
49
|
-
expect(get.mock.calls.length).toBe(1);
|
|
50
|
-
expect(get.mock.calls[0][0]).toEqual({
|
|
51
|
-
channel: "full_trajectory_schematic_foo"
|
|
52
|
-
});
|
|
53
|
-
done();
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
test("doesn't use generalizationLevel param", (done) => {
|
|
57
|
-
tralisAPI.getFullTrajectory("foo", TralisModes.SCHEMATIC, 10).then(() => {
|
|
58
|
-
expect(get.mock.calls.length).toBe(1);
|
|
59
|
-
expect(get.mock.calls[0][0]).toEqual({
|
|
60
|
-
channel: "full_trajectory_schematic_foo"
|
|
61
|
-
});
|
|
62
|
-
done();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|
package/api/TralisAPIUtils.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export const getModeSuffix = (mode, modes) => mode === modes.SCHEMATIC ? "_schematic" : "";
|
|
2
|
-
export const compareDepartures = (a, b, sortByMinArrivalTime = false) => {
|
|
3
|
-
const topStates = ["HIDDEN", "LEAVING", "BOARDING"];
|
|
4
|
-
const aTop = a.has_fzo && topStates.indexOf(a.state) > -1;
|
|
5
|
-
const bTop = b.has_fzo && topStates.indexOf(b.state) > -1;
|
|
6
|
-
if (aTop || bTop) {
|
|
7
|
-
if (aTop !== bTop) {
|
|
8
|
-
return aTop ? -1 : 1;
|
|
9
|
-
}
|
|
10
|
-
if (a.state !== b.state) {
|
|
11
|
-
return topStates.indexOf(a.state) - topStates.indexOf(b.state);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
let aDuration = null;
|
|
15
|
-
let bDuration = null;
|
|
16
|
-
const now = Date.now();
|
|
17
|
-
if (sortByMinArrivalTime) {
|
|
18
|
-
aDuration = new Date(a.min_arrival_time || a.time).getTime() - now;
|
|
19
|
-
bDuration = new Date(b.min_arrival_time || b.time).getTime() - now;
|
|
20
|
-
} else {
|
|
21
|
-
aDuration = new Date(a.time).getTime() - now;
|
|
22
|
-
bDuration = new Date(b.time).getTime() - now;
|
|
23
|
-
}
|
|
24
|
-
return aDuration - bDuration;
|
|
25
|
-
};
|
|
26
|
-
export const cleanStopTime = (content) => {
|
|
27
|
-
if (!content) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
content.stations.forEach((station) => {
|
|
31
|
-
station.arrivalTimeWithDelay = station.arrivalTime;
|
|
32
|
-
if (station.departureTime) {
|
|
33
|
-
station.departureTimeWithDelay = station.departureTime;
|
|
34
|
-
}
|
|
35
|
-
if (station.arrivalDelay) {
|
|
36
|
-
station.arrivalTime -= station.arrivalDelay;
|
|
37
|
-
if (station.departureTime) {
|
|
38
|
-
station.departureTime -= station.arrivalDelay;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
return content;
|
|
43
|
-
};
|