@opentripplanner/core-utils 13.0.0-alpha.1 → 13.0.0-alpha.3
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/LICENSE +21 -0
- package/README.md +3 -0
- package/esm/graphql.d.js.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/itinerary.js +78 -115
- package/esm/itinerary.js.map +1 -1
- package/esm/map.js +3 -3
- package/esm/map.js.map +1 -1
- package/esm/profile.js +17 -18
- package/esm/profile.js.map +1 -1
- package/esm/query-gen.js +35 -45
- package/esm/query-gen.js.map +1 -1
- package/esm/query.js +135 -191
- package/esm/query.js.map +1 -1
- package/esm/route.js +74 -97
- package/esm/route.js.map +1 -1
- package/esm/storage.js +4 -5
- package/esm/storage.js.map +1 -1
- package/esm/suspense.js +1 -3
- package/esm/suspense.js.map +1 -1
- package/esm/time.js +13 -17
- package/esm/time.js.map +1 -1
- package/esm/ui.js +0 -5
- package/esm/ui.js.map +1 -1
- package/lib/graphql.d.js.map +1 -1
- package/lib/index.js +3 -19
- package/lib/index.js.map +1 -1
- package/lib/itinerary.js +114 -199
- package/lib/itinerary.js.map +1 -1
- package/lib/map.d.ts +1 -1
- package/lib/map.d.ts.map +1 -1
- package/lib/map.js +9 -20
- package/lib/map.js.map +1 -1
- package/lib/profile.js +17 -19
- package/lib/profile.js.map +1 -1
- package/lib/query-gen.d.ts +4 -4
- package/lib/query-gen.d.ts.map +1 -1
- package/lib/query-gen.js +34 -45
- package/lib/query-gen.js.map +1 -1
- package/lib/query-params.jsx +893 -0
- package/lib/query.js +66 -118
- package/lib/query.js.map +1 -1
- package/lib/route.js +73 -101
- package/lib/route.js.map +1 -1
- package/lib/storage.js +6 -11
- package/lib/storage.js.map +1 -1
- package/lib/suspense.d.ts +1 -1
- package/lib/suspense.d.ts.map +1 -1
- package/lib/suspense.js +3 -9
- package/lib/suspense.js.map +1 -1
- package/lib/time.js +19 -38
- package/lib/time.js.map +1 -1
- package/lib/ui.js +1 -8
- package/lib/ui.js.map +1 -1
- package/package.json +7 -8
- package/src/query-params.jsx +893 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/esm/query-params.js +0 -786
- package/esm/query-params.js.map +0 -1
- package/lib/query-params.js +0 -756
- package/lib/query-params.js.map +0 -1
- /package/{src/query-params.js → esm/query-params.jsx} +0 -0
package/lib/itinerary.js
CHANGED
|
@@ -1,88 +1,82 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
-
exports.isReservationRequired = isReservationRequired;
|
|
12
|
-
exports.isCoordinationRequired = isCoordinationRequired;
|
|
7
|
+
exports.calculateEmissions = calculateEmissions;
|
|
8
|
+
exports.calculatePhysicalActivity = calculatePhysicalActivity;
|
|
9
|
+
exports.calculateTncFares = calculateTncFares;
|
|
13
10
|
exports.containsGeometry = containsGeometry;
|
|
11
|
+
exports.convertGraphQLResponseToLegacy = void 0;
|
|
14
12
|
exports.endsWithGeometry = endsWithGeometry;
|
|
15
|
-
exports.
|
|
16
|
-
exports.
|
|
13
|
+
exports.getCompaniesLabelFromNetworks = getCompaniesLabelFromNetworks;
|
|
14
|
+
exports.getCompanyForNetwork = getCompanyForNetwork;
|
|
15
|
+
exports.getCompanyFromLeg = getCompanyFromLeg;
|
|
16
|
+
exports.getDisplayedStopId = getDisplayedStopId;
|
|
17
|
+
exports.getElevationProfile = getElevationProfile;
|
|
18
|
+
exports.getItineraryBounds = getItineraryBounds;
|
|
19
|
+
exports.getItineraryCost = getItineraryCost;
|
|
20
|
+
exports.getLegBounds = getLegBounds;
|
|
21
|
+
exports.getLegCost = getLegCost;
|
|
22
|
+
exports.getLegRouteShortName = exports.getLegRouteName = exports.getLegRouteLongName = void 0;
|
|
23
|
+
exports.getMapColor = getMapColor;
|
|
24
|
+
exports.getTNCLocation = getTNCLocation;
|
|
25
|
+
exports.getTextWidth = getTextWidth;
|
|
26
|
+
exports.getTransitModes = getTransitModes;
|
|
27
|
+
exports.hasBike = hasBike;
|
|
28
|
+
exports.hasCar = hasCar;
|
|
29
|
+
exports.hasHail = hasHail;
|
|
30
|
+
exports.hasMicromobility = hasMicromobility;
|
|
31
|
+
exports.hasRental = hasRental;
|
|
32
|
+
exports.hasTransit = hasTransit;
|
|
33
|
+
exports.isAccessMode = isAccessMode;
|
|
17
34
|
exports.isAdvanceBookingRequired = isAdvanceBookingRequired;
|
|
18
|
-
exports.legDropoffRequiresAdvanceBooking = legDropoffRequiresAdvanceBooking;
|
|
19
|
-
exports.isFlex = isFlex;
|
|
20
|
-
exports.isRideshareLeg = isRideshareLeg;
|
|
21
|
-
exports.isWalk = isWalk;
|
|
22
35
|
exports.isBicycle = isBicycle;
|
|
23
36
|
exports.isBicycleRent = isBicycleRent;
|
|
24
37
|
exports.isCar = isCar;
|
|
38
|
+
exports.isCoordinationRequired = isCoordinationRequired;
|
|
39
|
+
exports.isFlex = isFlex;
|
|
25
40
|
exports.isMicromobility = isMicromobility;
|
|
26
|
-
exports.
|
|
27
|
-
exports.
|
|
28
|
-
exports.
|
|
29
|
-
exports.
|
|
30
|
-
exports.
|
|
31
|
-
exports.
|
|
32
|
-
exports.
|
|
33
|
-
exports.getMapColor = getMapColor;
|
|
34
|
-
exports.toSentenceCase = toSentenceCase;
|
|
35
|
-
exports.getCompanyFromLeg = getCompanyFromLeg;
|
|
36
|
-
exports.getItineraryBounds = getItineraryBounds;
|
|
37
|
-
exports.getLegBounds = getLegBounds;
|
|
38
|
-
exports.legLocationAtDistance = legLocationAtDistance;
|
|
41
|
+
exports.isReservationRequired = isReservationRequired;
|
|
42
|
+
exports.isRideshareLeg = isRideshareLeg;
|
|
43
|
+
exports.isTransit = isTransit;
|
|
44
|
+
exports.isTransitLeg = isTransitLeg;
|
|
45
|
+
exports.isWalk = isWalk;
|
|
46
|
+
exports.legContainsGeometry = legContainsGeometry;
|
|
47
|
+
exports.legDropoffRequiresAdvanceBooking = legDropoffRequiresAdvanceBooking;
|
|
39
48
|
exports.legElevationAtDistance = legElevationAtDistance;
|
|
49
|
+
exports.legLocationAtDistance = legLocationAtDistance;
|
|
40
50
|
exports.mapOldElevationComponentToNew = mapOldElevationComponentToNew;
|
|
41
|
-
exports.
|
|
42
|
-
exports.
|
|
43
|
-
exports.
|
|
44
|
-
exports.getCompaniesLabelFromNetworks = getCompaniesLabelFromNetworks;
|
|
45
|
-
exports.getTNCLocation = getTNCLocation;
|
|
46
|
-
exports.calculatePhysicalActivity = calculatePhysicalActivity;
|
|
47
|
-
exports.calculateTncFares = calculateTncFares;
|
|
48
|
-
exports.calculateEmissions = calculateEmissions;
|
|
49
|
-
exports.getDisplayedStopId = getDisplayedStopId;
|
|
50
|
-
exports.getLegCost = getLegCost;
|
|
51
|
-
exports.getItineraryCost = getItineraryCost;
|
|
52
|
-
exports.getLegRouteName = exports.getLegRouteLongName = exports.getLegRouteShortName = exports.convertGraphQLResponseToLegacy = exports.transitModes = void 0;
|
|
53
|
-
|
|
51
|
+
exports.startsWithGeometry = startsWithGeometry;
|
|
52
|
+
exports.toSentenceCase = toSentenceCase;
|
|
53
|
+
exports.transitModes = void 0;
|
|
54
54
|
var _polyline = _interopRequireDefault(require("@mapbox/polyline"));
|
|
55
|
-
|
|
56
55
|
var _along = _interopRequireDefault(require("@turf/along"));
|
|
57
|
-
|
|
58
56
|
// All OTP transit modes
|
|
59
|
-
const transitModes = ["TRAM", "TROLLEYBUS", "BUS", "SUBWAY", "FERRY", "RAIL", "GONDOLA"];
|
|
57
|
+
const transitModes = exports.transitModes = ["TRAM", "TROLLEYBUS", "BUS", "SUBWAY", "FERRY", "RAIL", "GONDOLA"];
|
|
58
|
+
|
|
60
59
|
/**
|
|
61
60
|
* @param {config} config OTP-RR configuration object
|
|
62
61
|
* @return {Array} List of all transit modes defined in config; otherwise default mode list
|
|
63
62
|
*/
|
|
64
63
|
|
|
65
|
-
exports.transitModes = transitModes;
|
|
66
|
-
|
|
67
64
|
function getTransitModes(config) {
|
|
68
65
|
if (!config || !config.modes || !config.modes.transitModes) return transitModes;
|
|
69
66
|
return config.modes.transitModes.map(tm => typeof tm !== "string" ? tm.mode : tm);
|
|
70
67
|
}
|
|
71
|
-
|
|
72
68
|
function isTransitLeg(leg) {
|
|
73
69
|
return leg.transitLeg;
|
|
74
70
|
}
|
|
75
|
-
|
|
76
71
|
function isTransit(mode) {
|
|
77
72
|
return transitModes.includes(mode) || mode === "TRANSIT";
|
|
78
73
|
}
|
|
74
|
+
|
|
79
75
|
/**
|
|
80
76
|
* Returns true if the leg pickup rules enabled which require
|
|
81
77
|
* calling ahead for the service to run. "mustPhone" is the only
|
|
82
78
|
* property which encodes this info.
|
|
83
79
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
80
|
function isReservationRequired(leg) {
|
|
87
81
|
return (leg === null || leg === void 0 ? void 0 : leg.boardRule) === "mustPhone" || (leg === null || leg === void 0 ? void 0 : leg.alightRule) === "mustPhone";
|
|
88
82
|
}
|
|
@@ -91,139 +85,114 @@ function isReservationRequired(leg) {
|
|
|
91
85
|
* or if the user must flag the driver down for pickup.
|
|
92
86
|
* "coordinateWithDriver" in board/alight rule encodes this info.
|
|
93
87
|
*/
|
|
94
|
-
|
|
95
|
-
|
|
96
88
|
function isCoordinationRequired(leg) {
|
|
97
89
|
return (leg === null || leg === void 0 ? void 0 : leg.boardRule) === "coordinateWithDriver" || (leg === null || leg === void 0 ? void 0 : leg.alightRule) === "coordinateWithDriver";
|
|
98
90
|
}
|
|
99
|
-
|
|
100
91
|
function containsGeometry(place) {
|
|
101
92
|
var _place$stop, _place$stop2;
|
|
102
|
-
|
|
103
|
-
return (place === null || place === void 0 ? void 0 : (_place$stop = place.stop) === null || _place$stop === void 0 ? void 0 : _place$stop.geometries) !== null && (place === null || place === void 0 ? void 0 : (_place$stop2 = place.stop) === null || _place$stop2 === void 0 ? void 0 : _place$stop2.geometries) !== undefined;
|
|
93
|
+
return (place === null || place === void 0 || (_place$stop = place.stop) === null || _place$stop === void 0 ? void 0 : _place$stop.geometries) !== null && (place === null || place === void 0 || (_place$stop2 = place.stop) === null || _place$stop2 === void 0 ? void 0 : _place$stop2.geometries) !== undefined;
|
|
104
94
|
}
|
|
105
|
-
|
|
106
95
|
function endsWithGeometry(leg) {
|
|
107
96
|
return containsGeometry(leg === null || leg === void 0 ? void 0 : leg.to);
|
|
108
97
|
}
|
|
109
|
-
|
|
110
98
|
function startsWithGeometry(leg) {
|
|
111
99
|
return containsGeometry(leg === null || leg === void 0 ? void 0 : leg.from);
|
|
112
100
|
}
|
|
113
|
-
|
|
114
101
|
function legContainsGeometry(leg) {
|
|
115
102
|
return endsWithGeometry(leg) || startsWithGeometry(leg);
|
|
116
103
|
}
|
|
117
|
-
|
|
118
104
|
function isAdvanceBookingRequired(info) {
|
|
119
105
|
var _info$latestBookingTi;
|
|
120
|
-
|
|
121
|
-
return (info === null || info === void 0 ? void 0 : (_info$latestBookingTi = info.latestBookingTime) === null || _info$latestBookingTi === void 0 ? void 0 : _info$latestBookingTi.daysPrior) > 0;
|
|
106
|
+
return (info === null || info === void 0 || (_info$latestBookingTi = info.latestBookingTime) === null || _info$latestBookingTi === void 0 ? void 0 : _info$latestBookingTi.daysPrior) > 0;
|
|
122
107
|
}
|
|
123
|
-
|
|
124
108
|
function legDropoffRequiresAdvanceBooking(leg) {
|
|
125
109
|
return isAdvanceBookingRequired(leg === null || leg === void 0 ? void 0 : leg.dropOffBookingInfo);
|
|
126
110
|
}
|
|
111
|
+
|
|
127
112
|
/**
|
|
128
113
|
* The two rules checked by the above two functions are the only values
|
|
129
114
|
* returned by OTP when a leg is a flex leg.
|
|
130
115
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
116
|
function isFlex(leg) {
|
|
134
117
|
return isReservationRequired(leg) || isCoordinationRequired(leg) || legDropoffRequiresAdvanceBooking(leg) || isAdvanceBookingRequired(leg === null || leg === void 0 ? void 0 : leg.pickupBookingInfo) || legContainsGeometry(leg);
|
|
135
|
-
}
|
|
136
|
-
|
|
118
|
+
}
|
|
137
119
|
|
|
120
|
+
// alpha-only comment
|
|
138
121
|
function isRideshareLeg(leg) {
|
|
139
|
-
var _leg$rideHailingEstim
|
|
140
|
-
|
|
141
|
-
return !!((_leg$rideHailingEstim = leg.rideHailingEstimate) !== null && _leg$rideHailingEstim !== void 0 && (_leg$rideHailingEstim2 = _leg$rideHailingEstim.provider) !== null && _leg$rideHailingEstim2 !== void 0 && _leg$rideHailingEstim2.id);
|
|
122
|
+
var _leg$rideHailingEstim;
|
|
123
|
+
return !!((_leg$rideHailingEstim = leg.rideHailingEstimate) !== null && _leg$rideHailingEstim !== void 0 && (_leg$rideHailingEstim = _leg$rideHailingEstim.provider) !== null && _leg$rideHailingEstim !== void 0 && _leg$rideHailingEstim.id);
|
|
142
124
|
}
|
|
143
|
-
|
|
144
125
|
function isWalk(mode) {
|
|
145
126
|
if (!mode) return false;
|
|
146
127
|
return mode === "WALK";
|
|
147
128
|
}
|
|
148
|
-
|
|
149
129
|
function isBicycle(mode) {
|
|
150
130
|
if (!mode) return false;
|
|
151
131
|
return mode === "BICYCLE";
|
|
152
132
|
}
|
|
153
|
-
|
|
154
133
|
function isBicycleRent(mode) {
|
|
155
134
|
if (!mode) return false;
|
|
156
135
|
return mode === "BICYCLE_RENT";
|
|
157
136
|
}
|
|
158
|
-
|
|
159
137
|
function isCar(mode) {
|
|
160
138
|
if (!mode) return false;
|
|
161
139
|
return mode.startsWith("CAR");
|
|
162
140
|
}
|
|
163
|
-
|
|
164
141
|
function isMicromobility(mode) {
|
|
165
142
|
if (!mode) return false;
|
|
166
143
|
return mode.startsWith("MICROMOBILITY") || mode.startsWith("SCOOTER");
|
|
167
144
|
}
|
|
168
|
-
|
|
169
145
|
function isAccessMode(mode) {
|
|
170
146
|
return isWalk(mode) || isBicycle(mode) || isBicycleRent(mode) || isCar(mode) || isMicromobility(mode);
|
|
171
147
|
}
|
|
148
|
+
|
|
172
149
|
/**
|
|
173
150
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
174
151
|
* @return {boolean} whether any of the modes are transit modes
|
|
175
152
|
*/
|
|
176
|
-
|
|
177
|
-
|
|
178
153
|
function hasTransit(modesStr) {
|
|
179
154
|
return modesStr.split(",").some(mode => isTransit(mode));
|
|
180
155
|
}
|
|
156
|
+
|
|
181
157
|
/**
|
|
182
158
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
183
159
|
* @return {boolean} whether any of the modes are car-based modes
|
|
184
160
|
*/
|
|
185
|
-
|
|
186
|
-
|
|
187
161
|
function hasCar(modesStr) {
|
|
188
162
|
return modesStr.split(",").some(mode => isCar(mode));
|
|
189
163
|
}
|
|
164
|
+
|
|
190
165
|
/**
|
|
191
166
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
192
167
|
* @return {boolean} whether any of the modes are bicycle-based modes
|
|
193
168
|
*/
|
|
194
|
-
|
|
195
|
-
|
|
196
169
|
function hasBike(modesStr) {
|
|
197
170
|
return modesStr.split(",").some(mode => isBicycle(mode) || isBicycleRent(mode));
|
|
198
171
|
}
|
|
172
|
+
|
|
199
173
|
/**
|
|
200
174
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
201
175
|
* @return {boolean} whether any of the modes are micromobility-based modes
|
|
202
176
|
*/
|
|
203
|
-
|
|
204
|
-
|
|
205
177
|
function hasMicromobility(modesStr) {
|
|
206
178
|
return modesStr.split(",").some(mode => isMicromobility(mode));
|
|
207
179
|
}
|
|
180
|
+
|
|
208
181
|
/**
|
|
209
182
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
210
183
|
* @return {boolean} whether any of the modes is a hailing mode
|
|
211
184
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
214
185
|
function hasHail(modesStr) {
|
|
215
186
|
return modesStr.split(",").some(mode => mode.indexOf("_HAIL") > -1);
|
|
216
187
|
}
|
|
188
|
+
|
|
217
189
|
/**
|
|
218
190
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
219
191
|
* @return {boolean} whether any of the modes is a rental mode
|
|
220
192
|
*/
|
|
221
|
-
|
|
222
|
-
|
|
223
193
|
function hasRental(modesStr) {
|
|
224
194
|
return modesStr.split(",").some(mode => mode.indexOf("_RENT") > -1);
|
|
225
195
|
}
|
|
226
|
-
|
|
227
196
|
function getMapColor(mode) {
|
|
228
197
|
mode = mode || this.get("mode");
|
|
229
198
|
if (mode === "WALK") return "#444";
|
|
@@ -238,20 +207,17 @@ function getMapColor(mode) {
|
|
|
238
207
|
if (mode === "MICROMOBILITY" || mode === "SCOOTER") return "#f5a729";
|
|
239
208
|
return "#aaa";
|
|
240
209
|
}
|
|
241
|
-
|
|
242
210
|
function toSentenceCase(str) {
|
|
243
211
|
if (str == null) {
|
|
244
212
|
return "";
|
|
245
213
|
}
|
|
246
|
-
|
|
247
214
|
str = String(str);
|
|
248
215
|
return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();
|
|
249
216
|
}
|
|
217
|
+
|
|
250
218
|
/**
|
|
251
219
|
* Derive the company string based on mode and network associated with leg.
|
|
252
220
|
*/
|
|
253
|
-
|
|
254
|
-
|
|
255
221
|
function getCompanyFromLeg(leg) {
|
|
256
222
|
if (!leg) return null;
|
|
257
223
|
const {
|
|
@@ -262,93 +228,78 @@ function getCompanyFromLeg(leg) {
|
|
|
262
228
|
rentedVehicle,
|
|
263
229
|
rideHailingEstimate
|
|
264
230
|
} = leg;
|
|
265
|
-
|
|
266
231
|
if (mode === "CAR" && rentedCar) {
|
|
267
232
|
return from.networks[0];
|
|
268
233
|
}
|
|
269
|
-
|
|
270
234
|
if (mode === "CAR" && rideHailingEstimate) {
|
|
271
235
|
return rideHailingEstimate.provider.id;
|
|
272
236
|
}
|
|
273
|
-
|
|
274
237
|
if (mode === "BICYCLE" && rentedBike && from.networks) {
|
|
275
238
|
return from.networks[0];
|
|
276
239
|
}
|
|
277
|
-
|
|
278
240
|
if (from.rentalVehicle) {
|
|
279
241
|
return from.rentalVehicle.network;
|
|
280
242
|
}
|
|
281
|
-
|
|
282
243
|
if ((mode === "MICROMOBILITY" || mode === "SCOOTER") && rentedVehicle && from.networks) {
|
|
283
244
|
return from.networks[0];
|
|
284
245
|
}
|
|
285
|
-
|
|
286
246
|
return null;
|
|
287
247
|
}
|
|
288
|
-
|
|
289
248
|
function getItineraryBounds(itinerary) {
|
|
290
249
|
let coords = [];
|
|
291
250
|
itinerary.legs.forEach(leg => {
|
|
292
251
|
const legCoords = _polyline.default.toGeoJSON(leg.legGeometry.points).coordinates.map(c => [c[1], c[0]]);
|
|
293
|
-
|
|
294
252
|
coords = [...coords, ...legCoords];
|
|
295
253
|
});
|
|
296
254
|
return coords;
|
|
297
255
|
}
|
|
256
|
+
|
|
298
257
|
/**
|
|
299
258
|
* Return a coords object that encloses the given leg's geometry.
|
|
300
259
|
*/
|
|
301
|
-
|
|
302
|
-
|
|
303
260
|
function getLegBounds(leg) {
|
|
304
|
-
const coords = _polyline.default.toGeoJSON(leg.legGeometry.points).coordinates.map(c => [c[1], c[0]]);
|
|
261
|
+
const coords = _polyline.default.toGeoJSON(leg.legGeometry.points).coordinates.map(c => [c[1], c[0]]);
|
|
262
|
+
|
|
263
|
+
// in certain cases, there might be zero-length coordinates in the leg
|
|
305
264
|
// geometry. In these cases, build us an array of coordinates using the from
|
|
306
265
|
// and to data of the leg.
|
|
307
|
-
|
|
308
|
-
|
|
309
266
|
if (coords.length === 0) {
|
|
310
267
|
coords.push([leg.from.lat, leg.from.lon], [leg.to.lat, leg.to.lon]);
|
|
311
268
|
}
|
|
312
|
-
|
|
313
269
|
return coords;
|
|
314
270
|
}
|
|
315
|
-
/* Returns an interpolated lat-lon at a specified distance along a leg */
|
|
316
271
|
|
|
272
|
+
/* Returns an interpolated lat-lon at a specified distance along a leg */
|
|
317
273
|
|
|
318
274
|
function legLocationAtDistance(leg, distance) {
|
|
319
275
|
if (!leg.legGeometry) return null;
|
|
320
|
-
|
|
321
276
|
try {
|
|
322
277
|
const line = _polyline.default.toGeoJSON(leg.legGeometry.points);
|
|
323
|
-
|
|
324
278
|
const pt = (0, _along.default)(line, distance, {
|
|
325
279
|
units: "meters"
|
|
326
280
|
});
|
|
327
|
-
|
|
328
281
|
if (pt && pt.geometry && pt.geometry.coordinates) {
|
|
329
282
|
return [pt.geometry.coordinates[1], pt.geometry.coordinates[0]];
|
|
330
283
|
}
|
|
331
|
-
} catch (e) {
|
|
284
|
+
} catch (e) {
|
|
285
|
+
// FIXME handle error!
|
|
332
286
|
}
|
|
333
|
-
|
|
334
287
|
return null;
|
|
335
288
|
}
|
|
336
|
-
/* Returns an interpolated elevation at a specified distance along a leg */
|
|
337
289
|
|
|
290
|
+
/* Returns an interpolated elevation at a specified distance along a leg */
|
|
338
291
|
|
|
339
292
|
function legElevationAtDistance(points, distance) {
|
|
340
293
|
// Iterate through the combined elevation profile
|
|
341
|
-
let traversed = 0;
|
|
294
|
+
let traversed = 0;
|
|
295
|
+
// If first point distance is not zero, insert starting point at zero with
|
|
342
296
|
// null elevation. Encountering this value should trigger the warning below.
|
|
343
|
-
|
|
344
297
|
if (points[0][0] > 0) {
|
|
345
298
|
points.unshift([0, null]);
|
|
346
299
|
}
|
|
347
|
-
|
|
348
300
|
for (let i = 1; i < points.length; i++) {
|
|
349
301
|
const start = points[i - 1];
|
|
350
302
|
const elevDistanceSpan = points[i][0] - start[0];
|
|
351
|
-
|
|
352
303
|
if (distance >= traversed && distance <= traversed + elevDistanceSpan) {
|
|
353
304
|
// Distance falls within this point and the previous one;
|
|
354
305
|
// compute & return interpolated elevation value
|
|
@@ -356,28 +307,24 @@ function legElevationAtDistance(points, distance) {
|
|
|
356
307
|
console.warn("Elevation value does not exist for distance.", distance, traversed);
|
|
357
308
|
return null;
|
|
358
309
|
}
|
|
359
|
-
|
|
360
310
|
const pct = (distance - traversed) / elevDistanceSpan;
|
|
361
311
|
const elevSpan = points[i][1] - start[1];
|
|
362
312
|
return start[1] + elevSpan * pct;
|
|
363
313
|
}
|
|
364
|
-
|
|
365
314
|
traversed += elevDistanceSpan;
|
|
366
315
|
}
|
|
367
|
-
|
|
368
316
|
console.warn("Elevation value does not exist for distance.", distance, traversed);
|
|
369
317
|
return null;
|
|
370
318
|
}
|
|
371
|
-
|
|
372
319
|
function mapOldElevationComponentToNew(oldElev) {
|
|
373
320
|
return {
|
|
374
321
|
distance: oldElev.first,
|
|
375
322
|
elevation: oldElev.second
|
|
376
323
|
};
|
|
377
|
-
}
|
|
378
|
-
// keeping track of the minimum and maximum elevations reached
|
|
379
|
-
|
|
324
|
+
}
|
|
380
325
|
|
|
326
|
+
// Iterate through the steps, building the array of elevation points and
|
|
327
|
+
// keeping track of the minimum and maximum elevations reached
|
|
381
328
|
function getElevationProfile(steps, unitConversion = 1) {
|
|
382
329
|
let minElev = 100000;
|
|
383
330
|
let maxElev = -100000;
|
|
@@ -388,38 +335,32 @@ function getElevationProfile(steps, unitConversion = 1) {
|
|
|
388
335
|
const points = [];
|
|
389
336
|
steps.forEach(step => {
|
|
390
337
|
var _step$elevation;
|
|
391
|
-
|
|
392
338
|
// Support for old REST response data (in step.elevation)
|
|
393
339
|
const stepElevationProfile = step.elevationProfile || Array.isArray(step.elevation) && ((_step$elevation = step.elevation) === null || _step$elevation === void 0 ? void 0 : _step$elevation.map(mapOldElevationComponentToNew));
|
|
394
|
-
|
|
395
340
|
if (!stepElevationProfile || stepElevationProfile.length === 0) {
|
|
396
341
|
traversed += step.distance;
|
|
397
342
|
return;
|
|
398
343
|
}
|
|
399
|
-
|
|
400
344
|
for (let i = 0; i < stepElevationProfile.length; i++) {
|
|
401
345
|
const elev = stepElevationProfile[i];
|
|
402
|
-
|
|
403
346
|
if (previous) {
|
|
404
347
|
const diff = (elev.elevation - previous.elevation) * unitConversion;
|
|
405
348
|
if (diff > 0) gain += diff;else loss += diff;
|
|
406
349
|
}
|
|
407
|
-
|
|
408
|
-
|
|
350
|
+
if (i === 0 && elev.distance !== 0) {
|
|
351
|
+
// console.warn(`No elevation data available for step ${stepIndex}-${i} at beginning of segment`, elev)
|
|
409
352
|
}
|
|
410
|
-
|
|
411
353
|
const convertedElevation = elev.elevation * unitConversion;
|
|
412
354
|
if (convertedElevation < minElev) minElev = convertedElevation;
|
|
413
355
|
if (convertedElevation > maxElev) maxElev = convertedElevation;
|
|
414
|
-
points.push([traversed + elev.distance, elev.elevation]);
|
|
356
|
+
points.push([traversed + elev.distance, elev.elevation]);
|
|
357
|
+
// Insert "filler" point if the last point in elevation profile does not
|
|
415
358
|
// reach the full distance of the step.
|
|
416
|
-
|
|
417
|
-
|
|
359
|
+
if (i === stepElevationProfile.length - 1 && elev.distance !== step.distance) {
|
|
360
|
+
// points.push([traversed + step.distance, elev.second])
|
|
418
361
|
}
|
|
419
|
-
|
|
420
362
|
previous = elev;
|
|
421
363
|
}
|
|
422
|
-
|
|
423
364
|
traversed += step.distance;
|
|
424
365
|
});
|
|
425
366
|
return {
|
|
@@ -431,6 +372,7 @@ function getElevationProfile(steps, unitConversion = 1) {
|
|
|
431
372
|
loss
|
|
432
373
|
};
|
|
433
374
|
}
|
|
375
|
+
|
|
434
376
|
/**
|
|
435
377
|
* Uses canvas.measureText to compute and return the width of the given text of given font in pixels.
|
|
436
378
|
*
|
|
@@ -439,10 +381,9 @@ function getElevationProfile(steps, unitConversion = 1) {
|
|
|
439
381
|
*
|
|
440
382
|
* @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393
|
|
441
383
|
*/
|
|
442
|
-
|
|
443
|
-
|
|
444
384
|
function getTextWidth(text, font = "22px Arial") {
|
|
445
385
|
// Create custom type for function including reused canvas object
|
|
386
|
+
|
|
446
387
|
// reuse canvas object for better performance
|
|
447
388
|
const canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement("canvas"));
|
|
448
389
|
const context = canvas.getContext("2d");
|
|
@@ -450,21 +391,19 @@ function getTextWidth(text, font = "22px Arial") {
|
|
|
450
391
|
const metrics = context.measureText(text);
|
|
451
392
|
return metrics.width;
|
|
452
393
|
}
|
|
394
|
+
|
|
453
395
|
/**
|
|
454
396
|
* Get the configured company object for the given network string if the company
|
|
455
397
|
* has been defined in the provided companies array config.
|
|
456
398
|
*/
|
|
457
|
-
|
|
458
|
-
|
|
459
399
|
function getCompanyForNetwork(networkString, companies = []) {
|
|
460
400
|
const company = companies.find(co => co.id === networkString);
|
|
461
|
-
|
|
462
401
|
if (!company) {
|
|
463
402
|
console.warn(`No company found in config.yml that matches rented vehicle network: ${networkString}`, companies);
|
|
464
403
|
}
|
|
465
|
-
|
|
466
404
|
return company;
|
|
467
405
|
}
|
|
406
|
+
|
|
468
407
|
/**
|
|
469
408
|
* Get a string label to display from a list of vehicle rental networks.
|
|
470
409
|
*
|
|
@@ -472,17 +411,13 @@ function getCompanyForNetwork(networkString, companies = []) {
|
|
|
472
411
|
* @param {Array<object>} [companies=[]] An optional list of the companies config.
|
|
473
412
|
* @return {string} A label for use in presentation on a website.
|
|
474
413
|
*/
|
|
475
|
-
|
|
476
|
-
|
|
477
414
|
function getCompaniesLabelFromNetworks(networks, companies = []) {
|
|
478
415
|
return (Array.isArray(networks) ? networks : [networks]).map(network => getCompanyForNetwork(network, companies)).filter(co => !!co).map(co => co.label).join("/");
|
|
479
416
|
}
|
|
480
|
-
|
|
481
417
|
function getTNCLocation(leg, type) {
|
|
482
418
|
const location = leg[type];
|
|
483
419
|
return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;
|
|
484
420
|
}
|
|
485
|
-
|
|
486
421
|
function calculatePhysicalActivity(itinerary) {
|
|
487
422
|
let walkDuration = 0;
|
|
488
423
|
let bikeDuration = 0;
|
|
@@ -497,13 +432,12 @@ function calculatePhysicalActivity(itinerary) {
|
|
|
497
432
|
walkDuration
|
|
498
433
|
};
|
|
499
434
|
}
|
|
435
|
+
|
|
500
436
|
/**
|
|
501
437
|
* For an itinerary, calculates the TNC fares and returns an object with
|
|
502
438
|
* these values and currency info.
|
|
503
439
|
* It is assumed that the same currency is used for all TNC legs.
|
|
504
440
|
*/
|
|
505
|
-
|
|
506
|
-
|
|
507
441
|
function calculateTncFares(itinerary) {
|
|
508
442
|
return itinerary.legs.filter(leg => leg.mode === "CAR" && leg.rideHailingEstimate).reduce(({
|
|
509
443
|
maxTNCFare,
|
|
@@ -527,6 +461,7 @@ function calculateTncFares(itinerary) {
|
|
|
527
461
|
minTNCFare: 0
|
|
528
462
|
});
|
|
529
463
|
}
|
|
464
|
+
|
|
530
465
|
/**
|
|
531
466
|
* Sources:
|
|
532
467
|
* - https://www.itf-oecd.org/sites/default/files/docs/environmental-performance-new-mobility.pdf
|
|
@@ -534,8 +469,6 @@ function calculateTncFares(itinerary) {
|
|
|
534
469
|
* - https://www.itf-oecd.org/sites/default/files/life-cycle-assessment-calculations-2020.xlsx
|
|
535
470
|
* Other values extrapolated.
|
|
536
471
|
*/
|
|
537
|
-
|
|
538
|
-
|
|
539
472
|
const CARBON_INTENSITY_DEFAULTS = {
|
|
540
473
|
walk: 0.026,
|
|
541
474
|
bicycle: 0.017,
|
|
@@ -554,55 +487,50 @@ const CARBON_INTENSITY_DEFAULTS = {
|
|
|
554
487
|
airplane: 0.382,
|
|
555
488
|
micromobility: 0.095
|
|
556
489
|
};
|
|
490
|
+
|
|
557
491
|
/**
|
|
558
492
|
* @param {itinerary} itinerary OTP trip itinierary, only legs is required.
|
|
559
493
|
* @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter
|
|
560
494
|
* @param {units} units units to be used in return value
|
|
561
495
|
* @return Amount of carbon in chosen unit
|
|
562
496
|
*/
|
|
563
|
-
|
|
564
|
-
|
|
497
|
+
function calculateEmissions(
|
|
498
|
+
// This type makes all the properties from Itinerary optional except legs.
|
|
565
499
|
itinerary, carbonIntensity = {}, units) {
|
|
566
500
|
var _itinerary$legs;
|
|
567
|
-
|
|
568
501
|
// Apply defaults for any values that we don't have.
|
|
569
|
-
const carbonIntensityWithDefaults = {
|
|
502
|
+
const carbonIntensityWithDefaults = {
|
|
503
|
+
...CARBON_INTENSITY_DEFAULTS,
|
|
570
504
|
...carbonIntensity
|
|
571
|
-
};
|
|
505
|
+
};
|
|
572
506
|
|
|
573
|
-
|
|
507
|
+
// Distance is in meters, totalCarbon is in grams
|
|
508
|
+
const totalCarbon = (itinerary === null || itinerary === void 0 || (_itinerary$legs = itinerary.legs) === null || _itinerary$legs === void 0 ? void 0 : _itinerary$legs.reduce((total, leg) => {
|
|
574
509
|
return (leg.distance * carbonIntensityWithDefaults[leg.mode.toLowerCase()] || 0) + total;
|
|
575
510
|
}, 0)) || 0;
|
|
576
|
-
|
|
577
511
|
switch (units) {
|
|
578
512
|
case "ounce":
|
|
579
513
|
return totalCarbon / 28.35;
|
|
580
|
-
|
|
581
514
|
case "kilogram":
|
|
582
515
|
return totalCarbon / 1000;
|
|
583
|
-
|
|
584
516
|
case "pound":
|
|
585
517
|
return totalCarbon / 454;
|
|
586
|
-
|
|
587
518
|
case "gram":
|
|
588
519
|
default:
|
|
589
520
|
return totalCarbon;
|
|
590
521
|
}
|
|
591
522
|
}
|
|
523
|
+
|
|
592
524
|
/**
|
|
593
525
|
* Returns the user-facing stop id to display for a stop or place, using the following priority:
|
|
594
526
|
* 1. stop code,
|
|
595
527
|
* 2. stop id without the agency id portion, if stop id contains an agency portion,
|
|
596
528
|
* 3. stop id, whether null or not (this is the fallback case).
|
|
597
529
|
*/
|
|
598
|
-
|
|
599
|
-
|
|
600
530
|
function getDisplayedStopId(placeOrStop) {
|
|
601
531
|
var _stopId;
|
|
602
|
-
|
|
603
532
|
let stopId;
|
|
604
533
|
let stopCode;
|
|
605
|
-
|
|
606
534
|
if ("stopId" in placeOrStop) {
|
|
607
535
|
({
|
|
608
536
|
stopCode,
|
|
@@ -614,9 +542,9 @@ function getDisplayedStopId(placeOrStop) {
|
|
|
614
542
|
id: stopId
|
|
615
543
|
} = placeOrStop);
|
|
616
544
|
}
|
|
617
|
-
|
|
618
545
|
return stopCode || ((_stopId = stopId) === null || _stopId === void 0 ? void 0 : _stopId.split(":")[1]) || stopId;
|
|
619
546
|
}
|
|
547
|
+
|
|
620
548
|
/**
|
|
621
549
|
* Extracts useful data from the fare products on a leg, such as the leg cost and transfer info.
|
|
622
550
|
* @param leg Leg with fare products (must have used getLegsWithFares)
|
|
@@ -624,8 +552,6 @@ function getDisplayedStopId(placeOrStop) {
|
|
|
624
552
|
* @param container Fare container (cash, electronic)
|
|
625
553
|
* @returns Object containing price as well as the transfer discount amount, if a transfer was used.
|
|
626
554
|
*/
|
|
627
|
-
|
|
628
|
-
|
|
629
555
|
function getLegCost(leg, mediumId, riderCategoryId) {
|
|
630
556
|
if (!leg.fareProducts) return {
|
|
631
557
|
price: undefined
|
|
@@ -636,8 +562,9 @@ function getLegCost(leg, mediumId, riderCategoryId) {
|
|
|
636
562
|
// riderCategory and medium can be specifically defined as null to handle
|
|
637
563
|
// generic GTFS based fares from OTP when there is no fare model
|
|
638
564
|
return (product.riderCategory === null ? null : product.riderCategory.id) === riderCategoryId && (product.medium === null ? null : product.medium.id) === mediumId;
|
|
639
|
-
});
|
|
565
|
+
});
|
|
640
566
|
|
|
567
|
+
// Custom fare models return "rideCost", generic GTFS fares return "regular"
|
|
641
568
|
const totalCostProduct = relevantFareProducts.find(fp => fp.product.name === "rideCost" || fp.product.name === "regular");
|
|
642
569
|
const transferFareProduct = relevantFareProducts.find(fp => fp.product.name === "transfer");
|
|
643
570
|
return {
|
|
@@ -646,6 +573,7 @@ function getLegCost(leg, mediumId, riderCategoryId) {
|
|
|
646
573
|
productUseId: totalCostProduct === null || totalCostProduct === void 0 ? void 0 : totalCostProduct.id
|
|
647
574
|
};
|
|
648
575
|
}
|
|
576
|
+
|
|
649
577
|
/**
|
|
650
578
|
* Returns the total itinerary cost for a given set of legs.
|
|
651
579
|
* @param legs Itinerary legs with fare products (must have used getLegsWithFares)
|
|
@@ -653,16 +581,16 @@ function getLegCost(leg, mediumId, riderCategoryId) {
|
|
|
653
581
|
* @param container Fare container (cash, electronic)
|
|
654
582
|
* @returns Money object for the total itinerary cost.
|
|
655
583
|
*/
|
|
656
|
-
|
|
657
|
-
|
|
658
584
|
function getItineraryCost(legs, mediumId, riderCategoryId) {
|
|
659
|
-
const legCosts = legs
|
|
585
|
+
const legCosts = legs
|
|
586
|
+
// Only legs with fares (no walking legs)
|
|
660
587
|
.filter(leg => {
|
|
661
588
|
var _leg$fareProducts;
|
|
662
|
-
|
|
663
589
|
return ((_leg$fareProducts = leg.fareProducts) === null || _leg$fareProducts === void 0 ? void 0 : _leg$fareProducts.length) > 0;
|
|
664
|
-
})
|
|
665
|
-
|
|
590
|
+
})
|
|
591
|
+
// Get the leg cost object of each leg
|
|
592
|
+
.map(leg => getLegCost(leg, mediumId, riderCategoryId)).filter(cost => cost.price !== undefined)
|
|
593
|
+
// Filter out duplicate use IDs
|
|
666
594
|
// One fare product can be used on multiple legs,
|
|
667
595
|
// and we don't want to count it more than once.
|
|
668
596
|
.reduce((prev, cur) => {
|
|
@@ -672,14 +600,12 @@ function getItineraryCost(legs, mediumId, riderCategoryId) {
|
|
|
672
600
|
price: cur.price
|
|
673
601
|
});
|
|
674
602
|
}
|
|
675
|
-
|
|
676
603
|
return prev;
|
|
677
604
|
}, []).map(productUse => productUse.price);
|
|
678
|
-
if (legCosts.length === 0) return undefined;
|
|
679
|
-
|
|
605
|
+
if (legCosts.length === 0) return undefined;
|
|
606
|
+
// Calculate the total
|
|
680
607
|
return legCosts.reduce((prev, cur) => {
|
|
681
608
|
var _prev$currency;
|
|
682
|
-
|
|
683
609
|
return {
|
|
684
610
|
amount: prev.amount + (cur === null || cur === void 0 ? void 0 : cur.amount) || 0,
|
|
685
611
|
currency: (_prev$currency = prev.currency) !== null && _prev$currency !== void 0 ? _prev$currency : cur === null || cur === void 0 ? void 0 : cur.currency
|
|
@@ -689,30 +615,24 @@ function getItineraryCost(legs, mediumId, riderCategoryId) {
|
|
|
689
615
|
currency: null
|
|
690
616
|
});
|
|
691
617
|
}
|
|
692
|
-
|
|
693
618
|
const pickupDropoffTypeToOtp1 = otp2Type => {
|
|
694
619
|
switch (otp2Type) {
|
|
695
620
|
case "COORDINATE_WITH_DRIVER":
|
|
696
621
|
return "coordinateWithDriver";
|
|
697
|
-
|
|
698
622
|
case "CALL_AGENCY":
|
|
699
623
|
return "mustPhone";
|
|
700
|
-
|
|
701
624
|
case "SCHEDULED":
|
|
702
625
|
return "scheduled";
|
|
703
|
-
|
|
704
626
|
case "NONE":
|
|
705
627
|
return "none";
|
|
706
|
-
|
|
707
628
|
default:
|
|
708
629
|
return null;
|
|
709
630
|
}
|
|
710
631
|
};
|
|
711
|
-
|
|
712
632
|
const convertGraphQLResponseToLegacy = leg => {
|
|
713
633
|
var _leg$agency, _leg$agency2, _leg$agency3, _leg$agency4, _leg$from$stop, _leg$from$stop2, _leg$route, _leg$route2, _leg$route3, _leg$route4, _leg$route5, _leg$route6, _leg$to$stop, _leg$to$stop2, _leg$trip, _leg$trip2;
|
|
714
|
-
|
|
715
|
-
|
|
634
|
+
return {
|
|
635
|
+
...leg,
|
|
716
636
|
agencyBrandingUrl: (_leg$agency = leg.agency) === null || _leg$agency === void 0 ? void 0 : _leg$agency.url,
|
|
717
637
|
agencyId: (_leg$agency2 = leg.agency) === null || _leg$agency2 === void 0 ? void 0 : _leg$agency2.id,
|
|
718
638
|
agencyName: (_leg$agency3 = leg.agency) === null || _leg$agency3 === void 0 ? void 0 : _leg$agency3.name,
|
|
@@ -722,7 +642,8 @@ const convertGraphQLResponseToLegacy = leg => {
|
|
|
722
642
|
dropOffBookingInfo: {
|
|
723
643
|
latestBookingTime: leg.dropOffBookingInfo
|
|
724
644
|
},
|
|
725
|
-
from: {
|
|
645
|
+
from: {
|
|
646
|
+
...leg.from,
|
|
726
647
|
stopCode: (_leg$from$stop = leg.from.stop) === null || _leg$from$stop === void 0 ? void 0 : _leg$from$stop.code,
|
|
727
648
|
stopId: (_leg$from$stop2 = leg.from.stop) === null || _leg$from$stop2 === void 0 ? void 0 : _leg$from$stop2.gtfsId
|
|
728
649
|
},
|
|
@@ -732,7 +653,8 @@ const convertGraphQLResponseToLegacy = leg => {
|
|
|
732
653
|
routeLongName: (_leg$route4 = leg.route) === null || _leg$route4 === void 0 ? void 0 : _leg$route4.longName,
|
|
733
654
|
routeShortName: (_leg$route5 = leg.route) === null || _leg$route5 === void 0 ? void 0 : _leg$route5.shortName,
|
|
734
655
|
routeTextColor: (_leg$route6 = leg.route) === null || _leg$route6 === void 0 ? void 0 : _leg$route6.textColor,
|
|
735
|
-
to: {
|
|
656
|
+
to: {
|
|
657
|
+
...leg.to,
|
|
736
658
|
stopCode: (_leg$to$stop = leg.to.stop) === null || _leg$to$stop === void 0 ? void 0 : _leg$to$stop.code,
|
|
737
659
|
stopId: (_leg$to$stop2 = leg.to.stop) === null || _leg$to$stop2 === void 0 ? void 0 : _leg$to$stop2.gtfsId
|
|
738
660
|
},
|
|
@@ -740,43 +662,36 @@ const convertGraphQLResponseToLegacy = leg => {
|
|
|
740
662
|
tripId: (_leg$trip2 = leg.trip) === null || _leg$trip2 === void 0 ? void 0 : _leg$trip2.gtfsId
|
|
741
663
|
};
|
|
742
664
|
};
|
|
743
|
-
/** Extracts the route number for a leg returned from OTP1 or OTP2. */
|
|
744
|
-
|
|
745
665
|
|
|
666
|
+
/** Extracts the route number for a leg returned from OTP1 or OTP2. */
|
|
746
667
|
exports.convertGraphQLResponseToLegacy = convertGraphQLResponseToLegacy;
|
|
747
|
-
|
|
748
668
|
const getLegRouteShortName = leg => {
|
|
749
669
|
const {
|
|
750
670
|
route,
|
|
751
671
|
routeShortName
|
|
752
|
-
} = leg;
|
|
753
|
-
|
|
672
|
+
} = leg;
|
|
673
|
+
// typeof route === "object" denotes newer OTP2 responses. routeShortName and route as string is OTP1.
|
|
754
674
|
return typeof route === "object" ? route === null || route === void 0 ? void 0 : route.shortName : routeShortName || route;
|
|
755
675
|
};
|
|
756
|
-
/** Extract the route long name for a leg returned from OTP1 or OTP2. */
|
|
757
|
-
|
|
758
676
|
|
|
677
|
+
/** Extract the route long name for a leg returned from OTP1 or OTP2. */
|
|
759
678
|
exports.getLegRouteShortName = getLegRouteShortName;
|
|
760
|
-
|
|
761
679
|
const getLegRouteLongName = leg => {
|
|
762
680
|
const {
|
|
763
681
|
route,
|
|
764
682
|
routeLongName
|
|
765
|
-
} = leg;
|
|
766
|
-
|
|
683
|
+
} = leg;
|
|
684
|
+
// typeof route === "object" denotes newer OTP2 responses. routeLongName is OTP1.
|
|
767
685
|
return typeof route === "object" ? route === null || route === void 0 ? void 0 : route.longName : routeLongName;
|
|
768
686
|
};
|
|
687
|
+
|
|
769
688
|
/**
|
|
770
689
|
* Returns the route short name, or the route long name if no short name is provided.
|
|
771
690
|
* This is happens with Seattle area streetcars and ferries.
|
|
772
691
|
*/
|
|
773
|
-
|
|
774
|
-
|
|
775
692
|
exports.getLegRouteLongName = getLegRouteLongName;
|
|
776
|
-
|
|
777
693
|
const getLegRouteName = leg => {
|
|
778
694
|
return getLegRouteShortName(leg) || getLegRouteLongName(leg);
|
|
779
695
|
};
|
|
780
|
-
|
|
781
696
|
exports.getLegRouteName = getLegRouteName;
|
|
782
697
|
//# sourceMappingURL=itinerary.js.map
|