@opentripplanner/core-utils 4.11.5 → 5.0.1-alpha.1
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/esm/deprecated-with-types.js +47 -0
- package/esm/deprecated-with-types.js.map +1 -0
- package/esm/deprecated.js +7 -0
- package/esm/deprecated.js.map +1 -1
- package/esm/index.js +0 -4
- package/esm/index.js.map +1 -1
- package/esm/itinerary.js +3 -9
- package/esm/itinerary.js.map +1 -1
- package/esm/map.js +9 -2
- package/esm/map.js.map +1 -1
- package/esm/route.js +5 -3
- package/esm/route.js.map +1 -1
- package/esm/storage.js +1 -0
- package/esm/storage.js.map +1 -1
- package/esm/time.js +6 -36
- package/esm/time.js.map +1 -1
- package/esm/ui.js +1 -1
- package/esm/ui.js.map +1 -1
- package/lib/deprecated-with-types.d.ts +23 -0
- package/lib/deprecated-with-types.d.ts.map +1 -0
- package/lib/deprecated-with-types.js +61 -0
- package/lib/deprecated-with-types.js.map +1 -0
- package/lib/deprecated.js +9 -0
- package/lib/deprecated.js.map +1 -1
- package/lib/index.d.ts +19 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +0 -6
- package/lib/index.js.map +1 -1
- package/lib/itinerary.d.ts +113 -0
- package/lib/itinerary.d.ts.map +1 -0
- package/lib/itinerary.js +8 -9
- package/lib/itinerary.js.map +1 -1
- package/lib/map.d.ts +30 -0
- package/lib/map.d.ts.map +1 -0
- package/lib/map.js +8 -1
- package/lib/map.js.map +1 -1
- package/lib/route.d.ts +98 -0
- package/lib/route.d.ts.map +1 -0
- package/lib/route.js +5 -3
- package/lib/route.js.map +1 -1
- package/lib/storage.d.ts +19 -0
- package/lib/storage.d.ts.map +1 -0
- package/lib/storage.js +2 -0
- package/lib/storage.js.map +1 -1
- package/lib/time.d.ts +65 -0
- package/lib/time.d.ts.map +1 -0
- package/lib/time.js +22 -39
- package/lib/time.js.map +1 -1
- package/lib/ui.d.ts +13 -0
- package/lib/ui.d.ts.map +1 -0
- package/lib/ui.js +1 -1
- package/lib/ui.js.map +1 -1
- package/package.json +4 -1
- package/src/__tests__/__snapshots__/route.js.snap +30 -30
- package/src/deprecated-with-types.ts +62 -0
- package/src/deprecated.js +16 -0
- package/src/{index.js → index.ts} +0 -4
- package/src/{itinerary.js → itinerary.ts} +72 -50
- package/src/{map.js → map.ts} +48 -21
- package/src/{route.js → route.ts} +52 -28
- package/src/{storage.js → storage.ts} +6 -5
- package/src/{time.js → time.ts} +28 -46
- package/src/{ui.js → ui.ts} +8 -8
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +4921 -0
- package/esm/messages.js +0 -25
- package/esm/messages.js.map +0 -1
- package/esm/types.js +0 -560
- package/esm/types.js.map +0 -1
- package/lib/messages.js +0 -29
- package/lib/messages.js.map +0 -1
- package/lib/types.js +0 -661
- package/lib/types.js.map +0 -1
- package/src/messages.js +0 -20
- package/src/types.js +0 -605
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
import * as itinerary from "./itinerary";
|
|
2
2
|
import * as map from "./map";
|
|
3
|
-
import * as messages from "./messages";
|
|
4
3
|
import * as profile from "./profile";
|
|
5
4
|
import * as query from "./query";
|
|
6
5
|
import * as queryParams from "./query-params";
|
|
7
6
|
import * as route from "./route";
|
|
8
7
|
import * as storage from "./storage";
|
|
9
8
|
import * as time from "./time";
|
|
10
|
-
import * as types from "./types";
|
|
11
9
|
import * as ui from "./ui";
|
|
12
10
|
|
|
13
11
|
const core = {
|
|
14
12
|
itinerary,
|
|
15
13
|
map,
|
|
16
|
-
messages,
|
|
17
14
|
profile,
|
|
18
15
|
query,
|
|
19
16
|
queryParams,
|
|
20
17
|
route,
|
|
21
18
|
storage,
|
|
22
19
|
time,
|
|
23
|
-
types,
|
|
24
20
|
ui
|
|
25
21
|
};
|
|
26
22
|
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import polyline from "@mapbox/polyline";
|
|
2
|
+
import {
|
|
3
|
+
Company,
|
|
4
|
+
Config,
|
|
5
|
+
ElevationProfile,
|
|
6
|
+
FlexBookingInfo,
|
|
7
|
+
Itinerary,
|
|
8
|
+
LatLngArray,
|
|
9
|
+
Leg,
|
|
10
|
+
Step
|
|
11
|
+
} from "@opentripplanner/types";
|
|
2
12
|
import turfAlong from "@turf/along";
|
|
3
13
|
|
|
4
14
|
import {
|
|
@@ -9,6 +19,7 @@ import {
|
|
|
9
19
|
getStepDirection,
|
|
10
20
|
getStepInstructions,
|
|
11
21
|
getStepStreetName,
|
|
22
|
+
getTimeZoneOffset,
|
|
12
23
|
getTransitFare
|
|
13
24
|
} from "./deprecated";
|
|
14
25
|
|
|
@@ -20,6 +31,7 @@ export {
|
|
|
20
31
|
getStepDirection,
|
|
21
32
|
getStepInstructions,
|
|
22
33
|
getStepStreetName,
|
|
34
|
+
getTimeZoneOffset,
|
|
23
35
|
getTransitFare
|
|
24
36
|
};
|
|
25
37
|
|
|
@@ -38,13 +50,16 @@ export const transitModes = [
|
|
|
38
50
|
* @return {Array} List of all transit modes defined in config; otherwise default mode list
|
|
39
51
|
*/
|
|
40
52
|
|
|
41
|
-
export function getTransitModes(config) {
|
|
53
|
+
export function getTransitModes(config: Config): string[] {
|
|
42
54
|
if (!config || !config.modes || !config.modes.transitModes)
|
|
43
55
|
return transitModes;
|
|
44
|
-
|
|
56
|
+
|
|
57
|
+
return config.modes.transitModes.map(tm =>
|
|
58
|
+
typeof tm !== "string" ? tm.mode : tm
|
|
59
|
+
);
|
|
45
60
|
}
|
|
46
61
|
|
|
47
|
-
export function isTransit(mode) {
|
|
62
|
+
export function isTransit(mode: string): boolean {
|
|
48
63
|
return transitModes.includes(mode) || mode === "TRANSIT";
|
|
49
64
|
}
|
|
50
65
|
|
|
@@ -53,7 +68,7 @@ export function isTransit(mode) {
|
|
|
53
68
|
* calling ahead for the service to run. "mustPhone" is the only
|
|
54
69
|
* property of boardRule which encodes this info.
|
|
55
70
|
*/
|
|
56
|
-
export function isReservationRequired(leg) {
|
|
71
|
+
export function isReservationRequired(leg: Leg): boolean {
|
|
57
72
|
return leg.boardRule === "mustPhone";
|
|
58
73
|
}
|
|
59
74
|
/**
|
|
@@ -61,53 +76,53 @@ export function isReservationRequired(leg) {
|
|
|
61
76
|
* asking the driver to let the user off. "coordinateWithDriver" is the only
|
|
62
77
|
* property of alightRule which encodes this info.
|
|
63
78
|
*/
|
|
64
|
-
export function isContinuousDropoff(leg) {
|
|
79
|
+
export function isContinuousDropoff(leg: Leg): boolean {
|
|
65
80
|
return leg.alightRule === "coordinateWithDriver";
|
|
66
81
|
}
|
|
67
82
|
/**
|
|
68
83
|
* The two rules checked by the above two functions are the only values
|
|
69
84
|
* returned by OTP when a leg is a flex leg.
|
|
70
85
|
*/
|
|
71
|
-
export function isFlex(leg) {
|
|
86
|
+
export function isFlex(leg: Leg): boolean {
|
|
72
87
|
return isReservationRequired(leg) || isContinuousDropoff(leg);
|
|
73
88
|
}
|
|
74
89
|
|
|
75
|
-
export function isAdvanceBookingRequired(info) {
|
|
90
|
+
export function isAdvanceBookingRequired(info: FlexBookingInfo): boolean {
|
|
76
91
|
return info?.latestBookingTime?.daysPrior > 0;
|
|
77
92
|
}
|
|
78
|
-
export function legDropoffRequiresAdvanceBooking(leg) {
|
|
93
|
+
export function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {
|
|
79
94
|
return isAdvanceBookingRequired(leg.dropOffBookingInfo);
|
|
80
95
|
}
|
|
81
96
|
|
|
82
|
-
export function isWalk(mode) {
|
|
97
|
+
export function isWalk(mode: string): boolean {
|
|
83
98
|
if (!mode) return false;
|
|
84
99
|
|
|
85
100
|
return mode === "WALK";
|
|
86
101
|
}
|
|
87
102
|
|
|
88
|
-
export function isBicycle(mode) {
|
|
103
|
+
export function isBicycle(mode: string): boolean {
|
|
89
104
|
if (!mode) return false;
|
|
90
105
|
|
|
91
106
|
return mode === "BICYCLE";
|
|
92
107
|
}
|
|
93
108
|
|
|
94
|
-
export function isBicycleRent(mode) {
|
|
109
|
+
export function isBicycleRent(mode: string): boolean {
|
|
95
110
|
if (!mode) return false;
|
|
96
111
|
|
|
97
112
|
return mode === "BICYCLE_RENT";
|
|
98
113
|
}
|
|
99
114
|
|
|
100
|
-
export function isCar(mode) {
|
|
115
|
+
export function isCar(mode: string): boolean {
|
|
101
116
|
if (!mode) return false;
|
|
102
117
|
return mode.startsWith("CAR");
|
|
103
118
|
}
|
|
104
119
|
|
|
105
|
-
export function isMicromobility(mode) {
|
|
120
|
+
export function isMicromobility(mode: string): boolean {
|
|
106
121
|
if (!mode) return false;
|
|
107
122
|
return mode.startsWith("MICROMOBILITY") || mode.startsWith("SCOOTER");
|
|
108
123
|
}
|
|
109
124
|
|
|
110
|
-
export function isAccessMode(mode) {
|
|
125
|
+
export function isAccessMode(mode: string): boolean {
|
|
111
126
|
return (
|
|
112
127
|
isWalk(mode) ||
|
|
113
128
|
isBicycle(mode) ||
|
|
@@ -121,7 +136,7 @@ export function isAccessMode(mode) {
|
|
|
121
136
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
122
137
|
* @return {boolean} whether any of the modes are transit modes
|
|
123
138
|
*/
|
|
124
|
-
export function hasTransit(modesStr) {
|
|
139
|
+
export function hasTransit(modesStr: string): boolean {
|
|
125
140
|
return modesStr.split(",").some(mode => isTransit(mode));
|
|
126
141
|
}
|
|
127
142
|
|
|
@@ -129,7 +144,7 @@ export function hasTransit(modesStr) {
|
|
|
129
144
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
130
145
|
* @return {boolean} whether any of the modes are car-based modes
|
|
131
146
|
*/
|
|
132
|
-
export function hasCar(modesStr) {
|
|
147
|
+
export function hasCar(modesStr: string): boolean {
|
|
133
148
|
return modesStr.split(",").some(mode => isCar(mode));
|
|
134
149
|
}
|
|
135
150
|
|
|
@@ -137,7 +152,7 @@ export function hasCar(modesStr) {
|
|
|
137
152
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
138
153
|
* @return {boolean} whether any of the modes are bicycle-based modes
|
|
139
154
|
*/
|
|
140
|
-
export function hasBike(modesStr) {
|
|
155
|
+
export function hasBike(modesStr: string): boolean {
|
|
141
156
|
return modesStr
|
|
142
157
|
.split(",")
|
|
143
158
|
.some(mode => isBicycle(mode) || isBicycleRent(mode));
|
|
@@ -147,7 +162,7 @@ export function hasBike(modesStr) {
|
|
|
147
162
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
148
163
|
* @return {boolean} whether any of the modes are micromobility-based modes
|
|
149
164
|
*/
|
|
150
|
-
export function hasMicromobility(modesStr) {
|
|
165
|
+
export function hasMicromobility(modesStr: string): boolean {
|
|
151
166
|
return modesStr.split(",").some(mode => isMicromobility(mode));
|
|
152
167
|
}
|
|
153
168
|
|
|
@@ -155,7 +170,7 @@ export function hasMicromobility(modesStr) {
|
|
|
155
170
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
156
171
|
* @return {boolean} whether any of the modes is a hailing mode
|
|
157
172
|
*/
|
|
158
|
-
export function hasHail(modesStr) {
|
|
173
|
+
export function hasHail(modesStr: string): boolean {
|
|
159
174
|
return modesStr.split(",").some(mode => mode.indexOf("_HAIL") > -1);
|
|
160
175
|
}
|
|
161
176
|
|
|
@@ -163,11 +178,11 @@ export function hasHail(modesStr) {
|
|
|
163
178
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
164
179
|
* @return {boolean} whether any of the modes is a rental mode
|
|
165
180
|
*/
|
|
166
|
-
export function hasRental(modesStr) {
|
|
181
|
+
export function hasRental(modesStr: string): boolean {
|
|
167
182
|
return modesStr.split(",").some(mode => mode.indexOf("_RENT") > -1);
|
|
168
183
|
}
|
|
169
184
|
|
|
170
|
-
export function getMapColor(mode) {
|
|
185
|
+
export function getMapColor(mode: string): string {
|
|
171
186
|
mode = mode || this.get("mode");
|
|
172
187
|
if (mode === "WALK") return "#444";
|
|
173
188
|
if (mode === "BICYCLE") return "#0073e5";
|
|
@@ -181,7 +196,7 @@ export function getMapColor(mode) {
|
|
|
181
196
|
return "#aaa";
|
|
182
197
|
}
|
|
183
198
|
|
|
184
|
-
export function toSentenceCase(str) {
|
|
199
|
+
export function toSentenceCase(str: string): string {
|
|
185
200
|
if (str == null) {
|
|
186
201
|
return "";
|
|
187
202
|
}
|
|
@@ -192,7 +207,7 @@ export function toSentenceCase(str) {
|
|
|
192
207
|
/**
|
|
193
208
|
* Derive the company string based on mode and network associated with leg.
|
|
194
209
|
*/
|
|
195
|
-
export function getCompanyFromLeg(leg) {
|
|
210
|
+
export function getCompanyFromLeg(leg: Leg): string {
|
|
196
211
|
if (!leg) return null;
|
|
197
212
|
const { from, mode, rentedBike, rentedCar, rentedVehicle, tncData } = leg;
|
|
198
213
|
if (mode === "CAR" && rentedCar) {
|
|
@@ -214,12 +229,12 @@ export function getCompanyFromLeg(leg) {
|
|
|
214
229
|
return null;
|
|
215
230
|
}
|
|
216
231
|
|
|
217
|
-
export function getItineraryBounds(itinerary) {
|
|
232
|
+
export function getItineraryBounds(itinerary: Itinerary): LatLngArray[] {
|
|
218
233
|
let coords = [];
|
|
219
234
|
itinerary.legs.forEach(leg => {
|
|
220
235
|
const legCoords = polyline
|
|
221
236
|
.toGeoJSON(leg.legGeometry.points)
|
|
222
|
-
.coordinates.map(c => [c[1], c[0]]);
|
|
237
|
+
.coordinates.map((c: number[]) => [c[1], c[0]]);
|
|
223
238
|
coords = [...coords, ...legCoords];
|
|
224
239
|
});
|
|
225
240
|
return coords;
|
|
@@ -228,7 +243,7 @@ export function getItineraryBounds(itinerary) {
|
|
|
228
243
|
/**
|
|
229
244
|
* Return a coords object that encloses the given leg's geometry.
|
|
230
245
|
*/
|
|
231
|
-
export function getLegBounds(leg) {
|
|
246
|
+
export function getLegBounds(leg: Leg): number[] {
|
|
232
247
|
const coords = polyline
|
|
233
248
|
.toGeoJSON(leg.legGeometry.points)
|
|
234
249
|
.coordinates.map(c => [c[1], c[0]]);
|
|
@@ -244,7 +259,7 @@ export function getLegBounds(leg) {
|
|
|
244
259
|
|
|
245
260
|
/* Returns an interpolated lat-lon at a specified distance along a leg */
|
|
246
261
|
|
|
247
|
-
export function legLocationAtDistance(leg, distance) {
|
|
262
|
+
export function legLocationAtDistance(leg: Leg, distance: number): number[] {
|
|
248
263
|
if (!leg.legGeometry) return null;
|
|
249
264
|
|
|
250
265
|
try {
|
|
@@ -262,7 +277,10 @@ export function legLocationAtDistance(leg, distance) {
|
|
|
262
277
|
|
|
263
278
|
/* Returns an interpolated elevation at a specified distance along a leg */
|
|
264
279
|
|
|
265
|
-
export function legElevationAtDistance(
|
|
280
|
+
export function legElevationAtDistance(
|
|
281
|
+
points: number[][],
|
|
282
|
+
distance: number
|
|
283
|
+
): number {
|
|
266
284
|
// Iterate through the combined elevation profile
|
|
267
285
|
let traversed = 0;
|
|
268
286
|
// If first point distance is not zero, insert starting point at zero with
|
|
@@ -300,7 +318,10 @@ export function legElevationAtDistance(points, distance) {
|
|
|
300
318
|
|
|
301
319
|
// Iterate through the steps, building the array of elevation points and
|
|
302
320
|
// keeping track of the minimum and maximum elevations reached
|
|
303
|
-
export function getElevationProfile(
|
|
321
|
+
export function getElevationProfile(
|
|
322
|
+
steps: Step[],
|
|
323
|
+
unitConversion = 1
|
|
324
|
+
): ElevationProfile {
|
|
304
325
|
let minElev = 100000;
|
|
305
326
|
let maxElev = -100000;
|
|
306
327
|
let traversed = 0;
|
|
@@ -347,11 +368,14 @@ export function getElevationProfile(steps, unitConversion = 1) {
|
|
|
347
368
|
*
|
|
348
369
|
* @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393
|
|
349
370
|
*/
|
|
350
|
-
export function getTextWidth(text, font = "22px Arial") {
|
|
371
|
+
export function getTextWidth(text: string, font = "22px Arial"): number {
|
|
372
|
+
// Create custom type for function including re-used canvas object
|
|
373
|
+
type GetTextWidth = typeof getTextWidth & { canvas: HTMLCanvasElement };
|
|
374
|
+
|
|
351
375
|
// re-use canvas object for better performance
|
|
352
376
|
const canvas =
|
|
353
|
-
getTextWidth.canvas ||
|
|
354
|
-
(getTextWidth.canvas = document.createElement("canvas"));
|
|
377
|
+
(getTextWidth as GetTextWidth).canvas ||
|
|
378
|
+
((getTextWidth as GetTextWidth).canvas = document.createElement("canvas"));
|
|
355
379
|
const context = canvas.getContext("2d");
|
|
356
380
|
context.font = font;
|
|
357
381
|
const metrics = context.measureText(text);
|
|
@@ -362,7 +386,10 @@ export function getTextWidth(text, font = "22px Arial") {
|
|
|
362
386
|
* Get the configured company object for the given network string if the company
|
|
363
387
|
* has been defined in the provided companies array config.
|
|
364
388
|
*/
|
|
365
|
-
export function getCompanyForNetwork(
|
|
389
|
+
export function getCompanyForNetwork(
|
|
390
|
+
networkString: string,
|
|
391
|
+
companies: Company[] = []
|
|
392
|
+
): Company {
|
|
366
393
|
const company = companies.find(co => co.id === networkString);
|
|
367
394
|
if (!company) {
|
|
368
395
|
console.warn(
|
|
@@ -380,7 +407,10 @@ export function getCompanyForNetwork(networkString, companies = []) {
|
|
|
380
407
|
* @param {Array<object>} [companies=[]] An optional list of the companies config.
|
|
381
408
|
* @return {string} A label for use in presentation on a website.
|
|
382
409
|
*/
|
|
383
|
-
export function getCompaniesLabelFromNetworks(
|
|
410
|
+
export function getCompaniesLabelFromNetworks(
|
|
411
|
+
networks: string[],
|
|
412
|
+
companies: Company[] = []
|
|
413
|
+
): string {
|
|
384
414
|
return networks
|
|
385
415
|
.map(network => getCompanyForNetwork(network, companies))
|
|
386
416
|
.filter(co => !!co)
|
|
@@ -388,12 +418,18 @@ export function getCompaniesLabelFromNetworks(networks, companies = []) {
|
|
|
388
418
|
.join("/");
|
|
389
419
|
}
|
|
390
420
|
|
|
391
|
-
export function getTNCLocation(leg, type) {
|
|
421
|
+
export function getTNCLocation(leg: Leg, type: string): string {
|
|
392
422
|
const location = leg[type];
|
|
393
423
|
return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;
|
|
394
424
|
}
|
|
395
425
|
|
|
396
|
-
export function calculatePhysicalActivity(
|
|
426
|
+
export function calculatePhysicalActivity(
|
|
427
|
+
itinerary: Itinerary
|
|
428
|
+
): {
|
|
429
|
+
bikeDuration: number;
|
|
430
|
+
caloriesBurned: number;
|
|
431
|
+
walkDuration: number;
|
|
432
|
+
} {
|
|
397
433
|
let walkDuration = 0;
|
|
398
434
|
let bikeDuration = 0;
|
|
399
435
|
itinerary.legs.forEach(leg => {
|
|
@@ -409,20 +445,6 @@ export function calculatePhysicalActivity(itinerary) {
|
|
|
409
445
|
};
|
|
410
446
|
}
|
|
411
447
|
|
|
412
|
-
export function getTimeZoneOffset(itinerary) {
|
|
413
|
-
if (!itinerary.legs || !itinerary.legs.length) return 0;
|
|
414
|
-
|
|
415
|
-
// Determine if there is a DST offset between now and the itinerary start date
|
|
416
|
-
const dstOffset =
|
|
417
|
-
new Date(itinerary.startTime).getTimezoneOffset() -
|
|
418
|
-
new Date().getTimezoneOffset();
|
|
419
|
-
|
|
420
|
-
return (
|
|
421
|
-
itinerary.legs[0].agencyTimeZoneOffset +
|
|
422
|
-
(new Date().getTimezoneOffset() + dstOffset) * 60000
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
448
|
export function calculateTncFares(itinerary) {
|
|
427
449
|
// TODO: don't rely on deprecated methods!
|
|
428
450
|
// At the moment this is safe as none of these exported variables contain strings
|
package/src/{map.js → map.ts}
RENAMED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Company,
|
|
3
|
+
Itinerary,
|
|
4
|
+
LatLngArray,
|
|
5
|
+
Leg,
|
|
6
|
+
Location,
|
|
7
|
+
TransitiveData,
|
|
8
|
+
UserPosition
|
|
9
|
+
} from "@opentripplanner/types";
|
|
1
10
|
import {
|
|
2
11
|
getPlaceName,
|
|
3
|
-
|
|
12
|
+
isAccessMode,
|
|
4
13
|
isFlex,
|
|
5
|
-
|
|
6
|
-
|
|
14
|
+
isTransit,
|
|
15
|
+
toSentenceCase
|
|
7
16
|
} from "./itinerary";
|
|
8
17
|
|
|
9
18
|
import {
|
|
@@ -15,7 +24,9 @@ import {
|
|
|
15
24
|
|
|
16
25
|
export { coordsToString, getDetailText, latlngToString };
|
|
17
26
|
|
|
18
|
-
export function currentPositionToLocation(
|
|
27
|
+
export function currentPositionToLocation(
|
|
28
|
+
currentPosition: UserPosition
|
|
29
|
+
): Location {
|
|
19
30
|
if (currentPosition.error || !currentPosition.coords) {
|
|
20
31
|
console.warn(
|
|
21
32
|
"Cannot construct location from current position due to geolocation error or missing coordinates."
|
|
@@ -29,18 +40,24 @@ export function currentPositionToLocation(currentPosition) {
|
|
|
29
40
|
};
|
|
30
41
|
}
|
|
31
42
|
|
|
32
|
-
export function stringToCoords(str) {
|
|
43
|
+
export function stringToCoords(str: string): number[] {
|
|
33
44
|
return (str && str.split(",").map(c => +c)) || [];
|
|
34
45
|
}
|
|
35
46
|
|
|
36
|
-
export function constructLocation(latlng
|
|
47
|
+
export function constructLocation(latlng: {
|
|
48
|
+
lat: number;
|
|
49
|
+
lng: number;
|
|
50
|
+
}): Location {
|
|
37
51
|
return {
|
|
38
52
|
lat: latlng.lat,
|
|
39
53
|
lon: latlng.lng
|
|
40
54
|
};
|
|
41
55
|
}
|
|
42
56
|
|
|
43
|
-
export function formatStoredPlaceName(
|
|
57
|
+
export function formatStoredPlaceName(
|
|
58
|
+
location: Location,
|
|
59
|
+
withDetails = true
|
|
60
|
+
): string {
|
|
44
61
|
if (withDetails) {
|
|
45
62
|
logDeprecationWarning("the formatStoredPlaceName withDetails parameter");
|
|
46
63
|
}
|
|
@@ -56,7 +73,7 @@ export function formatStoredPlaceName(location, withDetails = true) {
|
|
|
56
73
|
return displayName;
|
|
57
74
|
}
|
|
58
75
|
|
|
59
|
-
export function matchLatLon(location1, location2) {
|
|
76
|
+
export function matchLatLon(location1: Location, location2: Location): boolean {
|
|
60
77
|
if (!location1 || !location2) return location1 === location2;
|
|
61
78
|
return location1.lat === location2.lat && location1.lon === location2.lon;
|
|
62
79
|
}
|
|
@@ -70,11 +87,11 @@ export function matchLatLon(location1, location2) {
|
|
|
70
87
|
* @returns An itinerary in the transitive.js format.
|
|
71
88
|
*/
|
|
72
89
|
export function itineraryToTransitive(
|
|
73
|
-
itin,
|
|
74
|
-
companies,
|
|
75
|
-
getRouteLabel,
|
|
76
|
-
disableFlexArc
|
|
77
|
-
) {
|
|
90
|
+
itin: Itinerary,
|
|
91
|
+
companies: Company[],
|
|
92
|
+
getRouteLabel: (leg: Leg) => string,
|
|
93
|
+
disableFlexArc: boolean
|
|
94
|
+
): TransitiveData {
|
|
78
95
|
const tdata = {
|
|
79
96
|
journeys: [],
|
|
80
97
|
streetEdges: [],
|
|
@@ -109,10 +126,16 @@ export function itineraryToTransitive(
|
|
|
109
126
|
|
|
110
127
|
itin.legs.forEach((leg, idx) => {
|
|
111
128
|
if (isAccessMode(leg.mode)) {
|
|
112
|
-
let fromPlaceId;
|
|
129
|
+
let fromPlaceId: string;
|
|
113
130
|
if (leg.from.bikeShareId) {
|
|
114
131
|
fromPlaceId = `bicycle_rent_station_${leg.from.bikeShareId}`;
|
|
115
|
-
|
|
132
|
+
if (
|
|
133
|
+
// OTP2 Scooter case
|
|
134
|
+
leg.mode === "SCOOTER"
|
|
135
|
+
) {
|
|
136
|
+
fromPlaceId = `escooter_rent_station_${leg.from.name}`;
|
|
137
|
+
}
|
|
138
|
+
// OTP1 Scooter case
|
|
116
139
|
} else if (leg.from.vertexType === "VEHICLERENTAL") {
|
|
117
140
|
fromPlaceId = `escooter_rent_station_${leg.from.name}`;
|
|
118
141
|
} else if (
|
|
@@ -143,6 +166,7 @@ export function itineraryToTransitive(
|
|
|
143
166
|
}
|
|
144
167
|
|
|
145
168
|
const segment = {
|
|
169
|
+
arc: false,
|
|
146
170
|
type: leg.mode,
|
|
147
171
|
streetEdges: [streetEdgeId],
|
|
148
172
|
from: { type: "PLACE", place_id: fromPlaceId },
|
|
@@ -298,27 +322,30 @@ export function itineraryToTransitive(
|
|
|
298
322
|
return tdata;
|
|
299
323
|
}
|
|
300
324
|
|
|
301
|
-
|
|
325
|
+
type TransitivePlaceRaw = {
|
|
326
|
+
place_id: string;
|
|
327
|
+
};
|
|
328
|
+
export function isBikeshareStation(place: TransitivePlaceRaw): boolean {
|
|
302
329
|
return place.place_id.lastIndexOf("bicycle_rent_station") !== -1;
|
|
303
330
|
}
|
|
304
331
|
|
|
305
|
-
export function isEScooterStation(place) {
|
|
332
|
+
export function isEScooterStation(place: TransitivePlaceRaw): boolean {
|
|
306
333
|
return place.place_id.lastIndexOf("escooter_rent_station") !== -1;
|
|
307
334
|
}
|
|
308
335
|
|
|
309
|
-
export function isCarWalkTransition(place) {
|
|
336
|
+
export function isCarWalkTransition(place: TransitivePlaceRaw): boolean {
|
|
310
337
|
return place.place_id.lastIndexOf("itin_car_") !== -1;
|
|
311
338
|
}
|
|
312
339
|
|
|
313
|
-
export function isValidLat(lat) {
|
|
340
|
+
export function isValidLat(lat: number): boolean {
|
|
314
341
|
return Number.isFinite(lat) && lat >= -90 && lat <= 90;
|
|
315
342
|
}
|
|
316
343
|
|
|
317
|
-
export function isValidLng(lng) {
|
|
344
|
+
export function isValidLng(lng: number): boolean {
|
|
318
345
|
return Number.isFinite(lng) && lng >= -180 && lng <= 180;
|
|
319
346
|
}
|
|
320
347
|
|
|
321
|
-
export function isValidLatLng(arr) {
|
|
348
|
+
export function isValidLatLng(arr: LatLngArray): boolean {
|
|
322
349
|
return (
|
|
323
350
|
Array.isArray(arr) &&
|
|
324
351
|
arr.length === 2 &&
|