@opentripplanner/core-utils 6.0.1-alpha.1 → 7.0.0-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/itinerary.js +74 -11
- package/esm/itinerary.js.map +1 -1
- package/esm/map.js +19 -16
- package/esm/map.js.map +1 -1
- package/esm/query.js +14 -11
- package/esm/query.js.map +1 -1
- package/esm/time.js +5 -56
- package/esm/time.js.map +1 -1
- package/lib/itinerary.d.ts +14 -7
- package/lib/itinerary.d.ts.map +1 -1
- package/lib/itinerary.js +79 -65
- package/lib/itinerary.js.map +1 -1
- package/lib/map.d.ts +3 -3
- package/lib/map.d.ts.map +1 -1
- package/lib/map.js +18 -32
- package/lib/map.js.map +1 -1
- package/lib/query.js +11 -15
- package/lib/query.js.map +1 -1
- package/lib/time.d.ts +1 -16
- package/lib/time.d.ts.map +1 -1
- package/lib/time.js +4 -72
- package/lib/time.js.map +1 -1
- package/package.json +4 -6
- package/src/__tests__/__snapshots__/itinerary.js.snap +2 -38
- package/src/__tests__/__snapshots__/time.js.snap +7 -13
- package/src/__tests__/itinerary.js +6 -29
- package/src/__tests__/time.js +7 -27
- package/src/itinerary.ts +72 -27
- package/src/map.ts +17 -22
- package/src/query.js +19 -16
- package/src/time.ts +11 -76
- package/tsconfig.tsbuildinfo +1294 -1311
- package/esm/deprecated-with-types.js +0 -47
- package/esm/deprecated-with-types.js.map +0 -1
- package/esm/deprecated.js +0 -325
- package/esm/deprecated.js.map +0 -1
- package/lib/deprecated-with-types.d.ts +0 -23
- package/lib/deprecated-with-types.d.ts.map +0 -1
- package/lib/deprecated-with-types.js +0 -61
- package/lib/deprecated-with-types.js.map +0 -1
- package/lib/deprecated.js +0 -355
- package/lib/deprecated.js.map +0 -1
- package/src/__tests__/__mocks__/multi-currency-itinerary.json +0 -1728
- package/src/deprecated-with-types.ts +0 -62
- package/src/deprecated.js +0 -334
package/esm/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/time.ts"],"names":["startOfDay","add","format","
|
|
1
|
+
{"version":3,"sources":["../src/time.ts"],"names":["startOfDay","add","format","utcToZonedTime","OTP_API_DATE_FORMAT","OTP_API_DATE_FORMAT_DATE_FNS","OTP_API_TIME_FORMAT","toHoursMinutesSeconds","seconds","hours","Math","floor","minutes","getTimeFormat","config","dateTime","timeFormat","getDateFormat","dateFormat","getLongDateFormat","longDateFormat","offsetTime","ms","options","offset","formatSecondsAfterMidnight","time","Date","getUserTimezone","fallbackTimezone","process","env","NODE_ENV","TZ","Intl","DateTimeFormat","resolvedOptions","timeZone","getCurrentTime","timezone","now","getCurrentDate"],"mappings":"AACA,SAASA,UAAT,EAAqBC,GAArB,EAA0BC,MAA1B,QAAwC,UAAxC;AACA,SAASC,cAAT,QAA+B,aAA/B,C,CAEA;AACA;;AACA,OAAO,IAAMC,mBAAmB,GAAG,YAA5B,C,CACP;AACA;;AACA,OAAO,IAAMC,4BAA4B,GAAG,YAArC;AACP,OAAO,IAAMC,mBAAmB,GAAG,OAA5B;AAEP;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,qBAAT,CACLC,OADK,EAML;AACA,SAAO;AACLC,IAAAA,KAAK,EAAEC,IAAI,CAACC,KAAL,CAAWH,OAAO,GAAG,IAArB,CADF;AAELI,IAAAA,OAAO,EAAEF,IAAI,CAACC,KAAL,CAAWH,OAAO,GAAG,EAArB,IAA2B,EAF/B;AAGLA,IAAAA,OAAO,EAAEA,OAAO,GAAG;AAHd,GAAP;AAKD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASK,aAAT,CAAuBC,MAAvB,EAA+C;AAAA;;AACpD,SAAO,CAAAA,MAAM,SAAN,IAAAA,MAAM,WAAN,gCAAAA,MAAM,CAAEC,QAAR,sEAAkBC,UAAlB,KAAgCV,mBAAvC;AACD;AAED,OAAO,SAASW,aAAT,CAAuBH,MAAvB,EAA+C;AAAA;;AACpD,SAAO,CAAAA,MAAM,SAAN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Ab;AACD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASmC,cAAT,GAA8D;AAAA,MAAtCF,QAAsC,uEAA3BX,eAAe,EAAY;AACnE,SAAO1B,MAAM,CACXC,cAAc,CAACwB,IAAI,CAACa,GAAL,EAAD,EAAaD,QAAb,CADH,EAEXlC,4BAFW,CAAb;AAID","sourcesContent":["import { Config } from \"@opentripplanner/types\";\nimport { startOfDay, add, format } from \"date-fns\";\nimport { utcToZonedTime } from \"date-fns-tz\";\n\n// special constants for making sure the following date format is always sent to\n// OTP regardless of whatever the user has configured as the display format\nexport const OTP_API_DATE_FORMAT = \"YYYY-MM-DD\";\n// Date-Fns uses a different string format than moment.js\n// see https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md\nexport const OTP_API_DATE_FORMAT_DATE_FNS = \"yyyy-MM-dd\";\nexport const OTP_API_TIME_FORMAT = \"HH:mm\";\n\n/**\n * Breaks up a duration in seconds into hours, minutes, and seconds.\n * @param {number} seconds The number of seconds to break up\n * @returns an object with fields with the corresponding, hours, minutes, seconds.\n */\nexport function toHoursMinutesSeconds(\n seconds: number\n): {\n hours: number;\n minutes: number;\n seconds: number;\n} {\n return {\n hours: Math.floor(seconds / 3600),\n minutes: Math.floor(seconds / 60) % 60,\n seconds: seconds % 60\n };\n}\n\n/**\n * @param {[type]} config the OTP config object found in store\n * @return {string} the config-defined time formatter or HH:mm (24-hr time)\n */\nexport function getTimeFormat(config: Config): string {\n return config?.dateTime?.timeFormat || OTP_API_TIME_FORMAT;\n}\n\nexport function getDateFormat(config: Config): string {\n return config?.dateTime?.dateFormat || OTP_API_DATE_FORMAT;\n}\n\nexport function getLongDateFormat(config: Config): string {\n return config?.dateTime?.longDateFormat || \"D MMMM YYYY\";\n}\n/**\n * Offsets a time according to the provided time options\n * and returns the result.\n */\nexport function offsetTime(ms, options) {\n return ms + (options?.offset || 0);\n}\n\n/**\n * Formats a seconds after midnight value for display in narrative\n * @param {number} seconds time since midnight in seconds\n * @param {string} timeFormat A valid date-fns time format\n * @return {string} formatted text representation\n */\nexport function formatSecondsAfterMidnight(\n seconds: number,\n timeFormat: string\n): string {\n const time = add(startOfDay(new Date()), { seconds });\n return format(time, timeFormat);\n}\n\n/**\n * Uses Intl.DateTimeFormat() api to get the user's time zone. In a test\n * environment, pulls timezone information from an env variable. Default to\n * GMT+0 if the Intl API is unavailable.\n */\nexport function getUserTimezone(fallbackTimezone = \"Etc/Greenwich\"): string {\n if (process.env.NODE_ENV === \"test\") return process.env.TZ;\n return Intl?.DateTimeFormat().resolvedOptions().timeZone || fallbackTimezone;\n}\n\n/**\n * Formats current time for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentTime(timezone = getUserTimezone()): string {\n return format(utcToZonedTime(Date.now(), timezone), OTP_API_TIME_FORMAT);\n}\n\n/**\n * Formats current date for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentDate(timezone = getUserTimezone()): string {\n return format(\n utcToZonedTime(Date.now(), timezone),\n OTP_API_DATE_FORMAT_DATE_FNS\n );\n}\n"],"file":"time.js"}
|
package/lib/itinerary.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { Company, Config, ElevationProfile, FlexBookingInfo, Itinerary, LatLngArray, Leg, Step } from "@opentripplanner/types";
|
|
2
|
-
import { calculateFares, getLegModeLabel, getModeForPlace, getPlaceName, getStepDirection, getStepInstructions, getStepStreetName, getTimeZoneOffset, getTransitFare } from "./deprecated";
|
|
3
|
-
export { calculateFares, getLegModeLabel, getModeForPlace, getPlaceName, getStepDirection, getStepInstructions, getStepStreetName, getTimeZoneOffset, getTransitFare };
|
|
1
|
+
import { Company, Config, ElevationProfile, FlexBookingInfo, Itinerary, LatLngArray, Leg, Money, Step, TncFare } from "@opentripplanner/types";
|
|
4
2
|
export declare const transitModes: string[];
|
|
5
3
|
/**
|
|
6
4
|
* @param {config} config OTP-RR configuration object
|
|
@@ -105,9 +103,18 @@ export declare function calculatePhysicalActivity(itinerary: Itinerary): {
|
|
|
105
103
|
caloriesBurned: number;
|
|
106
104
|
walkDuration: number;
|
|
107
105
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
106
|
+
/**
|
|
107
|
+
* For an itinerary, calculates the TNC fares and returns an object with
|
|
108
|
+
* these values and currency info.
|
|
109
|
+
* It is assumed that the same currency is used for all TNC legs.
|
|
110
|
+
*/
|
|
111
|
+
export declare function calculateTncFares(itinerary: Itinerary): TncFare;
|
|
112
|
+
/**
|
|
113
|
+
* For a given fare component (either total fare or component parts), returns
|
|
114
|
+
* an object with the fare value (in cents).
|
|
115
|
+
*/
|
|
116
|
+
export declare function getTransitFare(fareComponent: Money): {
|
|
117
|
+
currencyCode: string;
|
|
118
|
+
transitFare: number;
|
|
112
119
|
};
|
|
113
120
|
//# sourceMappingURL=itinerary.d.ts.map
|
package/lib/itinerary.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"itinerary.d.ts","sourceRoot":"","sources":["../src/itinerary.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,WAAW,EACX,GAAG,EACH,
|
|
1
|
+
{"version":3,"file":"itinerary.d.ts","sourceRoot":"","sources":["../src/itinerary.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,WAAW,EACX,GAAG,EACH,KAAK,EACL,IAAI,EACJ,OAAO,EACR,MAAM,wBAAwB,CAAC;AA8BhC,eAAO,MAAM,YAAY,UAOxB,CAAC;AAEF;;;GAGG;AAEH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAOxD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,C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,wBAAgB,cAAc,CAC5B,aAAa,EAAE,KAAK,GACnB;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB,CAcA"}
|
package/lib/itinerary.js
CHANGED
|
@@ -38,68 +38,38 @@ exports.getCompaniesLabelFromNetworks = getCompaniesLabelFromNetworks;
|
|
|
38
38
|
exports.getTNCLocation = getTNCLocation;
|
|
39
39
|
exports.calculatePhysicalActivity = calculatePhysicalActivity;
|
|
40
40
|
exports.calculateTncFares = calculateTncFares;
|
|
41
|
-
|
|
42
|
-
enumerable: true,
|
|
43
|
-
get: function () {
|
|
44
|
-
return _deprecated.calculateFares;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
Object.defineProperty(exports, "getLegModeLabel", {
|
|
48
|
-
enumerable: true,
|
|
49
|
-
get: function () {
|
|
50
|
-
return _deprecated.getLegModeLabel;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
Object.defineProperty(exports, "getModeForPlace", {
|
|
54
|
-
enumerable: true,
|
|
55
|
-
get: function () {
|
|
56
|
-
return _deprecated.getModeForPlace;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
Object.defineProperty(exports, "getPlaceName", {
|
|
60
|
-
enumerable: true,
|
|
61
|
-
get: function () {
|
|
62
|
-
return _deprecated.getPlaceName;
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
Object.defineProperty(exports, "getStepDirection", {
|
|
66
|
-
enumerable: true,
|
|
67
|
-
get: function () {
|
|
68
|
-
return _deprecated.getStepDirection;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
Object.defineProperty(exports, "getStepInstructions", {
|
|
72
|
-
enumerable: true,
|
|
73
|
-
get: function () {
|
|
74
|
-
return _deprecated.getStepInstructions;
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
Object.defineProperty(exports, "getStepStreetName", {
|
|
78
|
-
enumerable: true,
|
|
79
|
-
get: function () {
|
|
80
|
-
return _deprecated.getStepStreetName;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
Object.defineProperty(exports, "getTimeZoneOffset", {
|
|
84
|
-
enumerable: true,
|
|
85
|
-
get: function () {
|
|
86
|
-
return _deprecated.getTimeZoneOffset;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
Object.defineProperty(exports, "getTransitFare", {
|
|
90
|
-
enumerable: true,
|
|
91
|
-
get: function () {
|
|
92
|
-
return _deprecated.getTransitFare;
|
|
93
|
-
}
|
|
94
|
-
});
|
|
41
|
+
exports.getTransitFare = getTransitFare;
|
|
95
42
|
exports.transitModes = void 0;
|
|
96
43
|
|
|
97
44
|
var _polyline = _interopRequireDefault(require("@mapbox/polyline"));
|
|
98
45
|
|
|
99
46
|
var _along = _interopRequireDefault(require("@turf/along"));
|
|
100
47
|
|
|
101
|
-
|
|
102
|
-
|
|
48
|
+
/*
|
|
49
|
+
import {
|
|
50
|
+
// calculateFares,
|
|
51
|
+
// getLegModeLabel,
|
|
52
|
+
// getModeForPlace,
|
|
53
|
+
// getPlaceName,
|
|
54
|
+
// getStepDirection,
|
|
55
|
+
// getStepInstructions,
|
|
56
|
+
// getStepStreetName,
|
|
57
|
+
// getTimeZoneOffset,
|
|
58
|
+
// getTransitFare
|
|
59
|
+
} from "./deprecated";
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
// calculateFares,
|
|
63
|
+
// getLegModeLabel,
|
|
64
|
+
// getModeForPlace,
|
|
65
|
+
// getPlaceName,
|
|
66
|
+
// getStepDirection,
|
|
67
|
+
// getStepInstructions,
|
|
68
|
+
// getStepStreetName,
|
|
69
|
+
// getTimeZoneOffset,
|
|
70
|
+
// getTransitFare
|
|
71
|
+
};
|
|
72
|
+
*/
|
|
103
73
|
// All OTP transit modes
|
|
104
74
|
const transitModes = ["TRAM", "BUS", "SUBWAY", "FERRY", "RAIL", "GONDOLA"];
|
|
105
75
|
/**
|
|
@@ -496,19 +466,63 @@ function calculatePhysicalActivity(itinerary) {
|
|
|
496
466
|
walkDuration
|
|
497
467
|
};
|
|
498
468
|
}
|
|
469
|
+
/**
|
|
470
|
+
* For an itinerary, calculates the TNC fares and returns an object with
|
|
471
|
+
* these values and currency info.
|
|
472
|
+
* It is assumed that the same currency is used for all TNC legs.
|
|
473
|
+
*/
|
|
474
|
+
|
|
499
475
|
|
|
500
476
|
function calculateTncFares(itinerary) {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
477
|
+
let minTNCFare = 0;
|
|
478
|
+
let maxTNCFare = 0;
|
|
479
|
+
let currencyCode;
|
|
480
|
+
itinerary.legs.forEach(({
|
|
481
|
+
hailedCar,
|
|
482
|
+
mode,
|
|
483
|
+
tncData
|
|
484
|
+
}) => {
|
|
485
|
+
if (mode === "CAR" && hailedCar && tncData) {
|
|
486
|
+
const {
|
|
487
|
+
currency,
|
|
488
|
+
maxCost,
|
|
489
|
+
minCost
|
|
490
|
+
} = tncData;
|
|
491
|
+
minTNCFare += minCost;
|
|
492
|
+
maxTNCFare += maxCost; // Assumes a single currency for entire itinerary.
|
|
493
|
+
|
|
494
|
+
currencyCode = currency;
|
|
495
|
+
}
|
|
496
|
+
});
|
|
508
497
|
return {
|
|
498
|
+
currencyCode,
|
|
509
499
|
maxTNCFare,
|
|
510
|
-
minTNCFare
|
|
511
|
-
|
|
500
|
+
minTNCFare
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* For a given fare component (either total fare or component parts), returns
|
|
505
|
+
* an object with the fare value (in cents).
|
|
506
|
+
*/
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
function getTransitFare(fareComponent) {
|
|
510
|
+
// Default values (if fare component is not valid).
|
|
511
|
+
let transitFare = 0;
|
|
512
|
+
let currencyCode = "USD";
|
|
513
|
+
|
|
514
|
+
if (fareComponent) {
|
|
515
|
+
// Assign values without declaration.
|
|
516
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#assignment_without_declaration
|
|
517
|
+
({
|
|
518
|
+
currencyCode
|
|
519
|
+
} = fareComponent.currency);
|
|
520
|
+
transitFare = fareComponent.cents;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
return {
|
|
524
|
+
currencyCode,
|
|
525
|
+
transitFare
|
|
512
526
|
};
|
|
513
527
|
}
|
|
514
528
|
//# sourceMappingURL=itinerary.js.map
|
package/lib/itinerary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/itinerary.ts"],"names":["transitModes","getTransitModes","config","modes","map","tm","mode","isTransit","includes","isReservationRequired","leg","boardRule","isContinuousDropoff","alightRule","isFlex","isAdvanceBookingRequired","info","latestBookingTime","daysPrior","legDropoffRequiresAdvanceBooking","dropOffBookingInfo","isWalk","isBicycle","isBicycleRent","isCar","startsWith","isMicromobility","isAccessMode","hasTransit","modesStr","split","some","hasCar","hasBike","hasMicromobility","hasHail","indexOf","hasRental","getMapColor","get","toSentenceCase","str","String","charAt","toUpperCase","substr","toLowerCase","getCompanyFromLeg","from","rentedBike","rentedCar","rentedVehicle","tncData","networks","company","getItineraryBounds","itinerary","coords","legs","forEach","legCoords","polyline","toGeoJSON","legGeometry","points","coordinates","c","getLegBounds","length","push","lat","lon","to","legLocationAtDistance","distance","line","pt","units","geometry","e","legElevationAtDistance","traversed","unshift","i","start","elevDistanceSpan","console","warn","pct","elevSpan","getElevationProfile","steps","unitConversion","minElev","maxElev","gain","loss","previous","step","elevation","elev","diff","second","first","convertedElevation","getTextWidth","text","font","canvas","document","createElement","context","getContext","metrics","measureText","width","getCompanyForNetwork","networkString","companies","find","co","id","getCompaniesLabelFromNetworks","network","filter","label","join","getTNCLocation","type","location","toFixed","calculatePhysicalActivity","walkDuration","bikeDuration","duration","caloriesBurned","calculateTncFares","maxTNCFare","minTNCFare","tncCurrencyCode"],"mappings":";;;;;;;;;;;;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AAwB,EAA7D;AACD;;AAEM,SAASC,yBAAT,CACL3E,SADK,EAML;AACA,MAAI4E,YAAY,GAAG,CAAnB;AACA,MAAIC,YAAY,GAAG,CAAnB;AACA7E,EAAAA,SAAS,CAACE,IAAV,CAAeC,OAAf,CAAuBjD,GAAG,IAAI;AAC5B,QAAIA,GAAG,CAACJ,IAAJ,CAASmB,UAAT,CAAoB,MAApB,CAAJ,EAAiC2G,YAAY,IAAI1H,GAAG,CAAC4H,QAApB;AACjC,QAAI5H,GAAG,CAACJ,IAAJ,CAASmB,UAAT,CAAoB,SAApB,CAAJ,EAAoC4G,YAAY,IAAI3H,GAAG,CAAC4H,QAApB;AACrC,GAHD;AAIA,QAAMC,cAAc,GACjBH,YAAY,GAAG,IAAhB,GAAwB,GAAxB,GAA+BC,YAAY,GAAG,IAAhB,GAAwB,GADxD;AAEA,SAAO;AACLA,IAAAA,YADK;AAELE,IAAAA,cAFK;AAGLH,IAAAA;AAHK,GAAP;AAKD;;AAEM,SAASI,iBAAT,CAA2BhF,SAA3B,EAAsC;AAC3C;AACA;AACA,QAAM;AAAEiF,IAAAA,UAAF;AAAcC,IAAAA,UAAd;AAA0BC,IAAAA;AAA1B,MAA8C,gCAClDnF,SADkD,EAElD,IAFkD,CAApD;AAIA,SAAO;AAAEiF,IAAAA,UAAF;AAAcC,IAAAA,UAAd;AAA0BC,IAAAA;AAA1B,GAAP;AACD","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport {\n Company,\n Config,\n ElevationProfile,\n FlexBookingInfo,\n Itinerary,\n LatLngArray,\n Leg,\n Step\n} from \"@opentripplanner/types\";\nimport turfAlong from \"@turf/along\";\n\nimport {\n calculateFares,\n getLegModeLabel,\n getModeForPlace,\n getPlaceName,\n getStepDirection,\n getStepInstructions,\n getStepStreetName,\n getTimeZoneOffset,\n getTransitFare\n} from \"./deprecated\";\n\nexport {\n calculateFares,\n getLegModeLabel,\n getModeForPlace,\n getPlaceName,\n getStepDirection,\n getStepInstructions,\n getStepStreetName,\n getTimeZoneOffset,\n getTransitFare\n};\n\n// All OTP transit modes\nexport const transitModes = [\n \"TRAM\",\n \"BUS\",\n \"SUBWAY\",\n \"FERRY\",\n \"RAIL\",\n \"GONDOLA\"\n];\n\n/**\n * @param {config} config OTP-RR configuration object\n * @return {Array} List of all transit modes defined in config; otherwise default mode list\n */\n\nexport function getTransitModes(config: Config): string[] {\n if (!config || !config.modes || !config.modes.transitModes)\n return transitModes;\n\n return config.modes.transitModes.map(tm =>\n typeof tm !== \"string\" ? tm.mode : tm\n );\n}\n\nexport function isTransit(mode: string): boolean {\n return transitModes.includes(mode) || mode === \"TRANSIT\";\n}\n\n/**\n * Returns true if the leg pickup rules enabled which require\n * calling ahead for the service to run. \"mustPhone\" is the only\n * property of boardRule which encodes this info.\n */\nexport function isReservationRequired(leg: Leg): boolean {\n return leg.boardRule === \"mustPhone\";\n}\n/**\n * Returns true if the leg has continuous dropoff enabled which requires\n * asking the driver to let the user off. \"coordinateWithDriver\" is the only\n * property of alightRule which encodes this info.\n */\nexport function isContinuousDropoff(leg: Leg): boolean {\n return leg.alightRule === \"coordinateWithDriver\";\n}\n/**\n * The two rules checked by the above two functions are the only values\n * returned by OTP when a leg is a flex leg.\n */\nexport function isFlex(leg: Leg): boolean {\n return isReservationRequired(leg) || isContinuousDropoff(leg);\n}\n\nexport function isAdvanceBookingRequired(info: FlexBookingInfo): boolean {\n return info?.latestBookingTime?.daysPrior > 0;\n}\nexport function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {\n return isAdvanceBookingRequired(leg.dropOffBookingInfo);\n}\n\nexport function isWalk(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"WALK\";\n}\n\nexport function isBicycle(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE\";\n}\n\nexport function isBicycleRent(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE_RENT\";\n}\n\nexport function isCar(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"CAR\");\n}\n\nexport function isMicromobility(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"MICROMOBILITY\") || mode.startsWith(\"SCOOTER\");\n}\n\nexport function isAccessMode(mode: string): boolean {\n return (\n isWalk(mode) ||\n isBicycle(mode) ||\n isBicycleRent(mode) ||\n isCar(mode) ||\n isMicromobility(mode)\n );\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are transit modes\n */\nexport function hasTransit(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isTransit(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are car-based modes\n */\nexport function hasCar(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isCar(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are bicycle-based modes\n */\nexport function hasBike(modesStr: string): boolean {\n return modesStr\n .split(\",\")\n .some(mode => isBicycle(mode) || isBicycleRent(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are micromobility-based modes\n */\nexport function hasMicromobility(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isMicromobility(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a hailing mode\n */\nexport function hasHail(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_HAIL\") > -1);\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a rental mode\n */\nexport function hasRental(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_RENT\") > -1);\n}\n\nexport function getMapColor(mode: string): string {\n mode = mode || this.get(\"mode\");\n if (mode === \"WALK\") return \"#444\";\n if (mode === \"BICYCLE\") return \"#0073e5\";\n if (mode === \"SUBWAY\") return \"#e60000\";\n if (mode === \"RAIL\") return \"#b00\";\n if (mode === \"BUS\") return \"#080\";\n if (mode === \"TRAM\") return \"#800\";\n if (mode === \"FERRY\") return \"#008\";\n if (mode === \"CAR\") return \"#444\";\n if (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") return \"#f5a729\";\n return \"#aaa\";\n}\n\nexport function toSentenceCase(str: string): string {\n if (str == null) {\n return \"\";\n }\n str = String(str);\n return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();\n}\n\n/**\n * Derive the company string based on mode and network associated with leg.\n */\nexport function getCompanyFromLeg(leg: Leg): string {\n if (!leg) return null;\n const { from, mode, rentedBike, rentedCar, rentedVehicle, tncData } = leg;\n if (mode === \"CAR\" && rentedCar) {\n return from.networks[0];\n }\n if (mode === \"CAR\" && tncData) {\n return tncData.company;\n }\n if (mode === \"BICYCLE\" && rentedBike && from.networks) {\n return from.networks[0];\n }\n if (\n (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") &&\n rentedVehicle &&\n from.networks\n ) {\n return from.networks[0];\n }\n return null;\n}\n\nexport function getItineraryBounds(itinerary: Itinerary): LatLngArray[] {\n let coords = [];\n itinerary.legs.forEach(leg => {\n const legCoords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map((c: number[]) => [c[1], c[0]]);\n coords = [...coords, ...legCoords];\n });\n return coords;\n}\n\n/**\n * Return a coords object that encloses the given leg's geometry.\n */\nexport function getLegBounds(leg: Leg): number[] {\n const coords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map(c => [c[1], c[0]]);\n\n // in certain cases, there might be zero-length coordinates in the leg\n // geometry. In these cases, build us an array of coordinates using the from\n // and to data of the leg.\n if (coords.length === 0) {\n coords.push([leg.from.lat, leg.from.lon], [leg.to.lat, leg.to.lon]);\n }\n return coords;\n}\n\n/* Returns an interpolated lat-lon at a specified distance along a leg */\n\nexport function legLocationAtDistance(leg: Leg, distance: number): number[] {\n if (!leg.legGeometry) return null;\n\n try {\n const line = polyline.toGeoJSON(leg.legGeometry.points);\n const pt = turfAlong(line, distance, { units: \"meters\" });\n if (pt && pt.geometry && pt.geometry.coordinates) {\n return [pt.geometry.coordinates[1], pt.geometry.coordinates[0]];\n }\n } catch (e) {\n // FIXME handle error!\n }\n\n return null;\n}\n\n/* Returns an interpolated elevation at a specified distance along a leg */\n\nexport function legElevationAtDistance(\n points: number[][],\n distance: number\n): number {\n // Iterate through the combined elevation profile\n let traversed = 0;\n // If first point distance is not zero, insert starting point at zero with\n // null elevation. Encountering this value should trigger the warning below.\n if (points[0][0] > 0) {\n points.unshift([0, null]);\n }\n for (let i = 1; i < points.length; i++) {\n const start = points[i - 1];\n const elevDistanceSpan = points[i][0] - start[0];\n if (distance >= traversed && distance <= traversed + elevDistanceSpan) {\n // Distance falls within this point and the previous one;\n // compute & return iterpolated elevation value\n if (start[1] === null) {\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n }\n const pct = (distance - traversed) / elevDistanceSpan;\n const elevSpan = points[i][1] - start[1];\n return start[1] + elevSpan * pct;\n }\n traversed += elevDistanceSpan;\n }\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n}\n\n// Iterate through the steps, building the array of elevation points and\n// keeping track of the minimum and maximum elevations reached\nexport function getElevationProfile(\n steps: Step[],\n unitConversion = 1\n): ElevationProfile {\n let minElev = 100000;\n let maxElev = -100000;\n let traversed = 0;\n let gain = 0;\n let loss = 0;\n let previous = null;\n const points = [];\n steps.forEach(step => {\n if (!step.elevation || step.elevation.length === 0) {\n traversed += step.distance;\n return;\n }\n for (let i = 0; i < step.elevation.length; i++) {\n const elev = step.elevation[i];\n if (previous) {\n const diff = (elev.second - previous.second) * unitConversion;\n if (diff > 0) gain += diff;\n else loss += diff;\n }\n if (i === 0 && elev.first !== 0) {\n // console.warn(`No elevation data available for step ${stepIndex}-${i} at beginning of segment`, elev)\n }\n const convertedElevation = elev.second * unitConversion;\n if (convertedElevation < minElev) minElev = convertedElevation;\n if (convertedElevation > maxElev) maxElev = convertedElevation;\n points.push([traversed + elev.first, elev.second]);\n // Insert \"filler\" point if the last point in elevation profile does not\n // reach the full distance of the step.\n if (i === step.elevation.length - 1 && elev.first !== step.distance) {\n // points.push([traversed + step.distance, elev.second])\n }\n previous = elev;\n }\n traversed += step.distance;\n });\n return { maxElev, minElev, points, traversed, gain, loss };\n}\n\n/**\n * Uses canvas.measureText to compute and return the width of the given text of given font in pixels.\n *\n * @param {string} text The text to be rendered.\n * @param {string} font The css font descriptor that text is to be rendered with (e.g. \"bold 14px verdana\").\n *\n * @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393\n */\nexport function getTextWidth(text: string, font = \"22px Arial\"): number {\n // Create custom type for function including re-used canvas object\n type GetTextWidth = typeof getTextWidth & { canvas: HTMLCanvasElement };\n\n // re-use canvas object for better performance\n const canvas =\n (getTextWidth as GetTextWidth).canvas ||\n ((getTextWidth as GetTextWidth).canvas = document.createElement(\"canvas\"));\n const context = canvas.getContext(\"2d\");\n context.font = font;\n const metrics = context.measureText(text);\n return metrics.width;\n}\n\n/**\n * Get the configured company object for the given network string if the company\n * has been defined in the provided companies array config.\n */\nexport function getCompanyForNetwork(\n networkString: string,\n companies: Company[] = []\n): Company {\n const company = companies.find(co => co.id === networkString);\n if (!company) {\n console.warn(\n `No company found in config.yml that matches rented vehicle network: ${networkString}`,\n companies\n );\n }\n return company;\n}\n\n/**\n * Get a string label to display from a list of vehicle rental networks.\n *\n * @param {Array<string>} networks A list of network ids.\n * @param {Array<object>} [companies=[]] An optional list of the companies config.\n * @return {string} A label for use in presentation on a website.\n */\nexport function getCompaniesLabelFromNetworks(\n networks: string[],\n companies: Company[] = []\n): string {\n return networks\n .map(network => getCompanyForNetwork(network, companies))\n .filter(co => !!co)\n .map(co => co.label)\n .join(\"/\");\n}\n\nexport function getTNCLocation(leg: Leg, type: string): string {\n const location = leg[type];\n return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;\n}\n\nexport function calculatePhysicalActivity(\n itinerary: Itinerary\n): {\n bikeDuration: number;\n caloriesBurned: number;\n walkDuration: number;\n} {\n let walkDuration = 0;\n let bikeDuration = 0;\n itinerary.legs.forEach(leg => {\n if (leg.mode.startsWith(\"WALK\")) walkDuration += leg.duration;\n if (leg.mode.startsWith(\"BICYCLE\")) bikeDuration += leg.duration;\n });\n const caloriesBurned =\n (walkDuration / 3600) * 280 + (bikeDuration / 3600) * 290;\n return {\n bikeDuration,\n caloriesBurned,\n walkDuration\n };\n}\n\nexport function calculateTncFares(itinerary) {\n // TODO: don't rely on deprecated methods!\n // At the moment this is safe as none of these exported variables contain strings\n const { maxTNCFare, minTNCFare, tncCurrencyCode } = calculateFares(\n itinerary,\n true\n );\n return { maxTNCFare, minTNCFare, tncCurrencyCode };\n}\n"],"file":"itinerary.js"}
|
|
1
|
+
{"version":3,"sources":["../src/itinerary.ts"],"names":["transitModes","getTransitModes","config","modes","map","tm","mode","isTransit","includes","isReservationRequired","leg","boardRule","isContinuousDropoff","alightRule","isFlex","isAdvanceBookingRequired","info","latestBookingTime","daysPrior","legDropoffRequiresAdvanceBooking","dropOffBookingInfo","isWalk","isBicycle","isBicycleRent","isCar","startsWith","isMicromobility","isAccessMode","hasTransit","modesStr","split","some","hasCar","hasBike","hasMicromobility","hasHail","indexOf","hasRental","getMapColor","get","toSentenceCase","str","String","charAt","toUpperCase","substr","toLowerCase","getCompanyFromLeg","from","rentedBike","rentedCar","rentedVehicle","tncData","networks","company","getItineraryBounds","itinerary","coords","legs","forEach","legCoords","polyline","toGeoJSON","legGeometry","points","coordinates","c","getLegBounds","length","push","lat","lon","to","legLocationAtDistance","distance","line","pt","units","geometry","e","legElevationAtDistance","traversed","unshift","i","start","elevDistanceSpan","console","warn","pct","elevSpan","getElevationProfile","steps","unitConversion","minElev","maxElev","gain","loss","previous","step","elevation","elev","diff","second","first","convertedElevation","getTextWidth","text","font","canvas","document","createElement","context","getContext","metrics","measureText","width","getCompanyForNetwork","networkString","companies","find","co","id","getCompaniesLabelFromNetworks","network","filter","label","join","getTNCLocation","type","location","toFixed","calculatePhysicalActivity","walkDuration","bikeDuration","duration","caloriesBurned","calculateTncFares","minTNCFare","maxTNCFare","currencyCode","hailedCar","currency","maxCost","minCost","getTransitFare","fareComponent","transitFare","cents"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAaA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACO,MAAMA,YAAY,GAAG,CAC1B,MAD0B,EAE1B,KAF0B,EAG1B,QAH0B,EAI1B,OAJ0B,EAK1B,MAL0B,EAM1B,SAN0B,CAArB;AASP;AACA;AACA;AACA;;;;AAEO,SAASC,eAAT,CAAyBC,MAAzB,EAAmD;AACxD,MAAI,CAACA,MAAD,IAAW,CAACA,MAAM,CAACC,KAAnB,IAA4B,CAACD,MAAM,CAACC,KAAP,CAAaH,YAA9C,EACE,OAAOA,YAAP;AAEF,SAAOE,MAAM,CAACC,KAAP,CAAaH,YAAb,CAA0BI,GAA1B,CAA8BC,EAAE,IACrC,OAAOA,EAAP,KAAc,QAAd,GAAyBA,EAAE,CAACC,IAA5B,GAAmCD,EAD9B,CAAP;AAGD;;AAEM,SAASE,SAAT,CAAmBD,IAAnB,EAA0C;AAC/C,SAAON,YAAY,CAACQ,QAAb,CAAsBF,IAAtB,KAA+BA,IAAI,KAAK,SAA/C;AACD;AAED;AACA;AACA;AACA;AACA;;;AACO,SAASG,qBAAT,CAA+BC,GAA/B,EAAkD;AACvD,SAAOA,GAAG,CAACC,SAAJ,KAAkB,WAAzB;AACD;AACD;AACA;AACA;AACA;AACA;;;AACO,SAASC,mBAAT,CAA6BF,GAA7B,EAAgD;AACrD,SAAOA,GAAG,CAACG,UAAJ,KAAmB,sBAA1B;AACD;AACD;AACA;AACA;AACA;;;AACO,SAASC,MAAT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yF,QAAAA,QAAF;AAAYC,QAAAA,OAAZ;AAAqBC,QAAAA;AAArB,UAAiC3F,OAAvC;AACAqF,MAAAA,UAAU,IAAIM,OAAd;AACAL,MAAAA,UAAU,IAAII,OAAd,CAH0C,CAI1C;;AACAH,MAAAA,YAAY,GAAGE,QAAf;AACD;AACF,GARD;AAUA,SAAO;AACLF,IAAAA,YADK;AAELD,IAAAA,UAFK;AAGLD,IAAAA;AAHK,GAAP;AAKD;AAED;AACA;AACA;AACA;;;AACO,SAASO,cAAT,CACLC,aADK,EAKL;AACA;AACA,MAAIC,WAAW,GAAG,CAAlB;AACA,MAAIP,YAAY,GAAG,KAAnB;;AACA,MAAIM,aAAJ,EAAmB;AACjB;AACA;AACA,KAAC;AAAEN,MAAAA;AAAF,QAAmBM,aAAa,CAACJ,QAAlC;AACAK,IAAAA,WAAW,GAAGD,aAAa,CAACE,KAA5B;AACD;;AACD,SAAO;AACLR,IAAAA,YADK;AAELO,IAAAA;AAFK,GAAP;AAID","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport {\n Company,\n Config,\n ElevationProfile,\n FlexBookingInfo,\n Itinerary,\n LatLngArray,\n Leg,\n Money,\n Step,\n TncFare\n} from \"@opentripplanner/types\";\nimport turfAlong from \"@turf/along\";\n\n/*\nimport {\n // calculateFares,\n // getLegModeLabel,\n // getModeForPlace,\n // getPlaceName,\n // getStepDirection,\n // getStepInstructions,\n // getStepStreetName,\n // getTimeZoneOffset,\n // getTransitFare\n} from \"./deprecated\";\n\nexport {\n // calculateFares,\n // getLegModeLabel,\n // getModeForPlace,\n // getPlaceName,\n // getStepDirection,\n // getStepInstructions,\n // getStepStreetName,\n // getTimeZoneOffset,\n // getTransitFare\n};\n*/\n\n// All OTP transit modes\nexport const transitModes = [\n \"TRAM\",\n \"BUS\",\n \"SUBWAY\",\n \"FERRY\",\n \"RAIL\",\n \"GONDOLA\"\n];\n\n/**\n * @param {config} config OTP-RR configuration object\n * @return {Array} List of all transit modes defined in config; otherwise default mode list\n */\n\nexport function getTransitModes(config: Config): string[] {\n if (!config || !config.modes || !config.modes.transitModes)\n return transitModes;\n\n return config.modes.transitModes.map(tm =>\n typeof tm !== \"string\" ? tm.mode : tm\n );\n}\n\nexport function isTransit(mode: string): boolean {\n return transitModes.includes(mode) || mode === \"TRANSIT\";\n}\n\n/**\n * Returns true if the leg pickup rules enabled which require\n * calling ahead for the service to run. \"mustPhone\" is the only\n * property of boardRule which encodes this info.\n */\nexport function isReservationRequired(leg: Leg): boolean {\n return leg.boardRule === \"mustPhone\";\n}\n/**\n * Returns true if the leg has continuous dropoff enabled which requires\n * asking the driver to let the user off. \"coordinateWithDriver\" is the only\n * property of alightRule which encodes this info.\n */\nexport function isContinuousDropoff(leg: Leg): boolean {\n return leg.alightRule === \"coordinateWithDriver\";\n}\n/**\n * The two rules checked by the above two functions are the only values\n * returned by OTP when a leg is a flex leg.\n */\nexport function isFlex(leg: Leg): boolean {\n return isReservationRequired(leg) || isContinuousDropoff(leg);\n}\n\nexport function isAdvanceBookingRequired(info: FlexBookingInfo): boolean {\n return info?.latestBookingTime?.daysPrior > 0;\n}\nexport function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {\n return isAdvanceBookingRequired(leg.dropOffBookingInfo);\n}\n\nexport function isWalk(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"WALK\";\n}\n\nexport function isBicycle(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE\";\n}\n\nexport function isBicycleRent(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE_RENT\";\n}\n\nexport function isCar(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"CAR\");\n}\n\nexport function isMicromobility(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"MICROMOBILITY\") || mode.startsWith(\"SCOOTER\");\n}\n\nexport function isAccessMode(mode: string): boolean {\n return (\n isWalk(mode) ||\n isBicycle(mode) ||\n isBicycleRent(mode) ||\n isCar(mode) ||\n isMicromobility(mode)\n );\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are transit modes\n */\nexport function hasTransit(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isTransit(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are car-based modes\n */\nexport function hasCar(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isCar(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are bicycle-based modes\n */\nexport function hasBike(modesStr: string): boolean {\n return modesStr\n .split(\",\")\n .some(mode => isBicycle(mode) || isBicycleRent(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are micromobility-based modes\n */\nexport function hasMicromobility(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isMicromobility(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a hailing mode\n */\nexport function hasHail(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_HAIL\") > -1);\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a rental mode\n */\nexport function hasRental(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_RENT\") > -1);\n}\n\nexport function getMapColor(mode: string): string {\n mode = mode || this.get(\"mode\");\n if (mode === \"WALK\") return \"#444\";\n if (mode === \"BICYCLE\") return \"#0073e5\";\n if (mode === \"SUBWAY\") return \"#e60000\";\n if (mode === \"RAIL\") return \"#b00\";\n if (mode === \"BUS\") return \"#080\";\n if (mode === \"TRAM\") return \"#800\";\n if (mode === \"FERRY\") return \"#008\";\n if (mode === \"CAR\") return \"#444\";\n if (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") return \"#f5a729\";\n return \"#aaa\";\n}\n\nexport function toSentenceCase(str: string): string {\n if (str == null) {\n return \"\";\n }\n str = String(str);\n return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();\n}\n\n/**\n * Derive the company string based on mode and network associated with leg.\n */\nexport function getCompanyFromLeg(leg: Leg): string {\n if (!leg) return null;\n const { from, mode, rentedBike, rentedCar, rentedVehicle, tncData } = leg;\n if (mode === \"CAR\" && rentedCar) {\n return from.networks[0];\n }\n if (mode === \"CAR\" && tncData) {\n return tncData.company;\n }\n if (mode === \"BICYCLE\" && rentedBike && from.networks) {\n return from.networks[0];\n }\n if (\n (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") &&\n rentedVehicle &&\n from.networks\n ) {\n return from.networks[0];\n }\n return null;\n}\n\nexport function getItineraryBounds(itinerary: Itinerary): LatLngArray[] {\n let coords = [];\n itinerary.legs.forEach(leg => {\n const legCoords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map((c: number[]) => [c[1], c[0]]);\n coords = [...coords, ...legCoords];\n });\n return coords;\n}\n\n/**\n * Return a coords object that encloses the given leg's geometry.\n */\nexport function getLegBounds(leg: Leg): number[] {\n const coords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map(c => [c[1], c[0]]);\n\n // in certain cases, there might be zero-length coordinates in the leg\n // geometry. In these cases, build us an array of coordinates using the from\n // and to data of the leg.\n if (coords.length === 0) {\n coords.push([leg.from.lat, leg.from.lon], [leg.to.lat, leg.to.lon]);\n }\n return coords;\n}\n\n/* Returns an interpolated lat-lon at a specified distance along a leg */\n\nexport function legLocationAtDistance(leg: Leg, distance: number): number[] {\n if (!leg.legGeometry) return null;\n\n try {\n const line = polyline.toGeoJSON(leg.legGeometry.points);\n const pt = turfAlong(line, distance, { units: \"meters\" });\n if (pt && pt.geometry && pt.geometry.coordinates) {\n return [pt.geometry.coordinates[1], pt.geometry.coordinates[0]];\n }\n } catch (e) {\n // FIXME handle error!\n }\n\n return null;\n}\n\n/* Returns an interpolated elevation at a specified distance along a leg */\n\nexport function legElevationAtDistance(\n points: number[][],\n distance: number\n): number {\n // Iterate through the combined elevation profile\n let traversed = 0;\n // If first point distance is not zero, insert starting point at zero with\n // null elevation. Encountering this value should trigger the warning below.\n if (points[0][0] > 0) {\n points.unshift([0, null]);\n }\n for (let i = 1; i < points.length; i++) {\n const start = points[i - 1];\n const elevDistanceSpan = points[i][0] - start[0];\n if (distance >= traversed && distance <= traversed + elevDistanceSpan) {\n // Distance falls within this point and the previous one;\n // compute & return iterpolated elevation value\n if (start[1] === null) {\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n }\n const pct = (distance - traversed) / elevDistanceSpan;\n const elevSpan = points[i][1] - start[1];\n return start[1] + elevSpan * pct;\n }\n traversed += elevDistanceSpan;\n }\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n}\n\n// Iterate through the steps, building the array of elevation points and\n// keeping track of the minimum and maximum elevations reached\nexport function getElevationProfile(\n steps: Step[],\n unitConversion = 1\n): ElevationProfile {\n let minElev = 100000;\n let maxElev = -100000;\n let traversed = 0;\n let gain = 0;\n let loss = 0;\n let previous = null;\n const points = [];\n steps.forEach(step => {\n if (!step.elevation || step.elevation.length === 0) {\n traversed += step.distance;\n return;\n }\n for (let i = 0; i < step.elevation.length; i++) {\n const elev = step.elevation[i];\n if (previous) {\n const diff = (elev.second - previous.second) * unitConversion;\n if (diff > 0) gain += diff;\n else loss += diff;\n }\n if (i === 0 && elev.first !== 0) {\n // console.warn(`No elevation data available for step ${stepIndex}-${i} at beginning of segment`, elev)\n }\n const convertedElevation = elev.second * unitConversion;\n if (convertedElevation < minElev) minElev = convertedElevation;\n if (convertedElevation > maxElev) maxElev = convertedElevation;\n points.push([traversed + elev.first, elev.second]);\n // Insert \"filler\" point if the last point in elevation profile does not\n // reach the full distance of the step.\n if (i === step.elevation.length - 1 && elev.first !== step.distance) {\n // points.push([traversed + step.distance, elev.second])\n }\n previous = elev;\n }\n traversed += step.distance;\n });\n return { maxElev, minElev, points, traversed, gain, loss };\n}\n\n/**\n * Uses canvas.measureText to compute and return the width of the given text of given font in pixels.\n *\n * @param {string} text The text to be rendered.\n * @param {string} font The css font descriptor that text is to be rendered with (e.g. \"bold 14px verdana\").\n *\n * @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393\n */\nexport function getTextWidth(text: string, font = \"22px Arial\"): number {\n // Create custom type for function including re-used canvas object\n type GetTextWidth = typeof getTextWidth & { canvas: HTMLCanvasElement };\n\n // re-use canvas object for better performance\n const canvas =\n (getTextWidth as GetTextWidth).canvas ||\n ((getTextWidth as GetTextWidth).canvas = document.createElement(\"canvas\"));\n const context = canvas.getContext(\"2d\");\n context.font = font;\n const metrics = context.measureText(text);\n return metrics.width;\n}\n\n/**\n * Get the configured company object for the given network string if the company\n * has been defined in the provided companies array config.\n */\nexport function getCompanyForNetwork(\n networkString: string,\n companies: Company[] = []\n): Company {\n const company = companies.find(co => co.id === networkString);\n if (!company) {\n console.warn(\n `No company found in config.yml that matches rented vehicle network: ${networkString}`,\n companies\n );\n }\n return company;\n}\n\n/**\n * Get a string label to display from a list of vehicle rental networks.\n *\n * @param {Array<string>} networks A list of network ids.\n * @param {Array<object>} [companies=[]] An optional list of the companies config.\n * @return {string} A label for use in presentation on a website.\n */\nexport function getCompaniesLabelFromNetworks(\n networks: string[],\n companies: Company[] = []\n): string {\n return networks\n .map(network => getCompanyForNetwork(network, companies))\n .filter(co => !!co)\n .map(co => co.label)\n .join(\"/\");\n}\n\nexport function getTNCLocation(leg: Leg, type: string): string {\n const location = leg[type];\n return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;\n}\n\nexport function calculatePhysicalActivity(\n itinerary: Itinerary\n): {\n bikeDuration: number;\n caloriesBurned: number;\n walkDuration: number;\n} {\n let walkDuration = 0;\n let bikeDuration = 0;\n itinerary.legs.forEach(leg => {\n if (leg.mode.startsWith(\"WALK\")) walkDuration += leg.duration;\n if (leg.mode.startsWith(\"BICYCLE\")) bikeDuration += leg.duration;\n });\n const caloriesBurned =\n (walkDuration / 3600) * 280 + (bikeDuration / 3600) * 290;\n return {\n bikeDuration,\n caloriesBurned,\n walkDuration\n };\n}\n\n/**\n * For an itinerary, calculates the TNC fares and returns an object with\n * these values and currency info.\n * It is assumed that the same currency is used for all TNC legs.\n */\nexport function calculateTncFares(itinerary: Itinerary): TncFare {\n let minTNCFare = 0;\n let maxTNCFare = 0;\n let currencyCode;\n itinerary.legs.forEach(({ hailedCar, mode, tncData }) => {\n if (mode === \"CAR\" && hailedCar && tncData) {\n const { currency, maxCost, minCost } = tncData;\n minTNCFare += minCost;\n maxTNCFare += maxCost;\n // Assumes a single currency for entire itinerary.\n currencyCode = currency;\n }\n });\n\n return {\n currencyCode,\n maxTNCFare,\n minTNCFare\n };\n}\n\n/**\n * For a given fare component (either total fare or component parts), returns\n * an object with the fare value (in cents).\n */\nexport function getTransitFare(\n fareComponent: Money\n): {\n currencyCode: string;\n transitFare: number;\n} {\n // Default values (if fare component is not valid).\n let transitFare = 0;\n let currencyCode = \"USD\";\n if (fareComponent) {\n // Assign values without declaration.\n // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#assignment_without_declaration\n ({ currencyCode } = fareComponent.currency);\n transitFare = fareComponent.cents;\n }\n return {\n currencyCode,\n transitFare\n };\n}\n"],"file":"itinerary.js"}
|
package/lib/map.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { LatLngArray, Location, UserPosition } from "@opentripplanner/types";
|
|
2
|
-
import { coordsToString, getDetailText, latlngToString } from "./deprecated";
|
|
3
|
-
export { coordsToString, getDetailText, latlngToString };
|
|
4
2
|
export declare function currentPositionToLocation(currentPosition: UserPosition): Location;
|
|
3
|
+
export declare function coordsToString(coords: number[]): string;
|
|
5
4
|
export declare function stringToCoords(str: string): number[];
|
|
6
5
|
export declare function constructLocation(latlng: {
|
|
7
6
|
lat: number;
|
|
8
7
|
lng: number;
|
|
9
8
|
}): Location;
|
|
10
|
-
export declare function formatStoredPlaceName(location: Location
|
|
9
|
+
export declare function formatStoredPlaceName(location: Location): string;
|
|
11
10
|
export declare function matchLatLon(location1: Location, location2: Location): boolean;
|
|
12
11
|
declare type TransitivePlaceRaw = {
|
|
13
12
|
place_id: string;
|
|
@@ -18,4 +17,5 @@ export declare function isCarWalkTransition(place: TransitivePlaceRaw): boolean;
|
|
|
18
17
|
export declare function isValidLat(lat: number): boolean;
|
|
19
18
|
export declare function isValidLng(lng: number): boolean;
|
|
20
19
|
export declare function isValidLatLng(arr: LatLngArray): boolean;
|
|
20
|
+
export {};
|
|
21
21
|
//# sourceMappingURL=map.d.ts.map
|
package/lib/map.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAc7E,wBAAgB,yBAAyB,CACvC,eAAe,EAAE,YAAY,GAC5B,QAAQ,CAYV;AAID,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAEvD;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAEpD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb,GAAG,QAAQ,CAKX;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAIhE;AAED,wBAAgB,WAAW,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,GAAG,OAAO,CAG7E;AAED,aAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AACF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAErE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAEpE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAEtE;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAOvD"}
|
package/lib/map.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.currentPositionToLocation = currentPositionToLocation;
|
|
7
|
+
exports.coordsToString = coordsToString;
|
|
7
8
|
exports.stringToCoords = stringToCoords;
|
|
8
9
|
exports.constructLocation = constructLocation;
|
|
9
10
|
exports.formatStoredPlaceName = formatStoredPlaceName;
|
|
@@ -14,29 +15,19 @@ exports.isCarWalkTransition = isCarWalkTransition;
|
|
|
14
15
|
exports.isValidLat = isValidLat;
|
|
15
16
|
exports.isValidLng = isValidLng;
|
|
16
17
|
exports.isValidLatLng = isValidLatLng;
|
|
17
|
-
Object.defineProperty(exports, "coordsToString", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () {
|
|
20
|
-
return _deprecated.coordsToString;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(exports, "getDetailText", {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
get: function () {
|
|
26
|
-
return _deprecated.getDetailText;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
Object.defineProperty(exports, "latlngToString", {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function () {
|
|
32
|
-
return _deprecated.latlngToString;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
18
|
|
|
36
19
|
var _itinerary = require("./itinerary");
|
|
37
20
|
|
|
38
|
-
|
|
21
|
+
/*
|
|
22
|
+
import {
|
|
23
|
+
// coordsToString,
|
|
24
|
+
// getDetailText //,
|
|
25
|
+
// latlngToString,
|
|
26
|
+
// logDeprecationWarning
|
|
27
|
+
} from "./deprecated";
|
|
39
28
|
|
|
29
|
+
export { coordsToString, getDetailText , latlngToString };
|
|
30
|
+
*/
|
|
40
31
|
function currentPositionToLocation(currentPosition) {
|
|
41
32
|
if (currentPosition.error || !currentPosition.coords) {
|
|
42
33
|
console.warn("Cannot construct location from current position due to geolocation error or missing coordinates.");
|
|
@@ -48,6 +39,12 @@ function currentPositionToLocation(currentPosition) {
|
|
|
48
39
|
lon: currentPosition.coords.longitude,
|
|
49
40
|
category: "CURRENT_LOCATION"
|
|
50
41
|
};
|
|
42
|
+
} // TRICKY: It is used in query.js and in the context of
|
|
43
|
+
// otp-rr actions where the intl context is not available.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
function coordsToString(coords) {
|
|
47
|
+
return coords.length && coords.map(c => (+c).toFixed(5)).join(", ");
|
|
51
48
|
}
|
|
52
49
|
|
|
53
50
|
function stringToCoords(str) {
|
|
@@ -61,19 +58,8 @@ function constructLocation(latlng) {
|
|
|
61
58
|
};
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
function formatStoredPlaceName(location
|
|
65
|
-
|
|
66
|
-
(0, _deprecated.logDeprecationWarning)("the formatStoredPlaceName withDetails parameter");
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
let displayName = location.type === "home" || location.type === "work" ? (0, _itinerary.toSentenceCase)(location.type) : location.name;
|
|
70
|
-
|
|
71
|
-
if (withDetails) {
|
|
72
|
-
const detailText = (0, _deprecated.getDetailText)(location);
|
|
73
|
-
if (detailText) displayName += ` (${detailText})`;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return displayName;
|
|
61
|
+
function formatStoredPlaceName(location) {
|
|
62
|
+
return location.type === "home" || location.type === "work" ? (0, _itinerary.toSentenceCase)(location.type) : location.name;
|
|
77
63
|
}
|
|
78
64
|
|
|
79
65
|
function matchLatLon(location1, location2) {
|
package/lib/map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/map.ts"],"names":["currentPositionToLocation","currentPosition","error","coords","console","warn","lat","latitude","lon","longitude","category","
|
|
1
|
+
{"version":3,"sources":["../src/map.ts"],"names":["currentPositionToLocation","currentPosition","error","coords","console","warn","lat","latitude","lon","longitude","category","coordsToString","length","map","c","toFixed","join","stringToCoords","str","split","constructLocation","latlng","lng","formatStoredPlaceName","location","type","name","matchLatLon","location1","location2","isBikeshareStation","place","place_id","lastIndexOf","isEScooterStation","isCarWalkTransition","isValidLat","Number","isFinite","isValidLng","isValidLatLng","arr","Array","isArray"],"mappings":";;;;;;;;;;;;;;;;;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEO,SAASA,yBAAT,CACLC,eADK,EAEK;AACV,MAAIA,eAAe,CAACC,KAAhB,IAAyB,CAACD,eAAe,CAACE,MAA9C,EAAsD;AACpDC,IAAAA,OAAO,CAACC,IAAR,CACE,kGADF;AAGA,WAAO,IAAP;AACD;;AACD,SAAO;AACLC,IAAAA,GAAG,EAAEL,eAAe,CAACE,MAAhB,CAAuBI,QADvB;AAELC,IAAAA,GAAG,EAAEP,eAAe,CAACE,MAAhB,CAAuBM,SAFvB;AAGLC,IAAAA,QAAQ,EAAE;AAHL,GAAP;AAKD,C,CAED;AACA;;;AACO,SAASC,cAAT,CAAwBR,MAAxB,EAAkD;AACvD,SAAOA,MAAM,CAACS,MAAP,IAAiBT,MAAM,CAACU,GAAP,CAAWC,CAAC,IAAI,CAAC,CAACA,CAAF,EAAKC,OAAL,CAAa,CAAb,CAAhB,EAAiCC,IA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9B,GAApB,EAA0C;AAC/C,SAAO+B,MAAM,CAACC,QAAP,CAAgBhC,GAAhB,KAAwBA,GAAG,IAAI,CAAC,EAAhC,IAAsCA,GAAG,IAAI,EAApD;AACD;;AAEM,SAASiC,UAAT,CAAoBjB,GAApB,EAA0C;AAC/C,SAAOe,MAAM,CAACC,QAAP,CAAgBhB,GAAhB,KAAwBA,GAAG,IAAI,CAAC,GAAhC,IAAuCA,GAAG,IAAI,GAArD;AACD;;AAEM,SAASkB,aAAT,CAAuBC,GAAvB,EAAkD;AACvD,SACEC,KAAK,CAACC,OAAN,CAAcF,GAAd,KACAA,GAAG,CAAC7B,MAAJ,KAAe,CADf,IAEAwB,UAAU,CAACK,GAAG,CAAC,CAAD,CAAJ,CAFV,IAGAF,UAAU,CAACE,GAAG,CAAC,CAAD,CAAJ,CAJZ;AAMD","sourcesContent":["import { LatLngArray, Location, UserPosition } from \"@opentripplanner/types\";\nimport { toSentenceCase } from \"./itinerary\";\n\n/*\nimport {\n // coordsToString,\n // getDetailText //,\n // latlngToString,\n // logDeprecationWarning\n} from \"./deprecated\";\n\nexport { coordsToString, getDetailText , latlngToString };\n*/\n\nexport function currentPositionToLocation(\n currentPosition: UserPosition\n): Location {\n if (currentPosition.error || !currentPosition.coords) {\n console.warn(\n \"Cannot construct location from current position due to geolocation error or missing coordinates.\"\n );\n return null;\n }\n return {\n lat: currentPosition.coords.latitude,\n lon: currentPosition.coords.longitude,\n category: \"CURRENT_LOCATION\"\n };\n}\n\n// TRICKY: It is used in query.js and in the context of\n// otp-rr actions where the intl context is not available.\nexport function coordsToString(coords: number[]): string {\n return coords.length && coords.map(c => (+c).toFixed(5)).join(\", \");\n}\n\nexport function stringToCoords(str: string): number[] {\n return (str && str.split(\",\").map(c => +c)) || [];\n}\n\nexport function constructLocation(latlng: {\n lat: number;\n lng: number;\n}): Location {\n return {\n lat: latlng.lat,\n lon: latlng.lng\n };\n}\n\nexport function formatStoredPlaceName(location: Location): string {\n return location.type === \"home\" || location.type === \"work\"\n ? toSentenceCase(location.type)\n : location.name;\n}\n\nexport function matchLatLon(location1: Location, location2: Location): boolean {\n if (!location1 || !location2) return location1 === location2;\n return location1.lat === location2.lat && location1.lon === location2.lon;\n}\n\ntype TransitivePlaceRaw = {\n place_id: string;\n};\nexport function isBikeshareStation(place: TransitivePlaceRaw): boolean {\n return place.place_id.lastIndexOf(\"bicycle_rent_station\") !== -1;\n}\n\nexport function isEScooterStation(place: TransitivePlaceRaw): boolean {\n return place.place_id.lastIndexOf(\"escooter_rent_station\") !== -1;\n}\n\nexport function isCarWalkTransition(place: TransitivePlaceRaw): boolean {\n return place.place_id.lastIndexOf(\"itin_car_\") !== -1;\n}\n\nexport function isValidLat(lat: number): boolean {\n return Number.isFinite(lat) && lat >= -90 && lat <= 90;\n}\n\nexport function isValidLng(lng: number): boolean {\n return Number.isFinite(lng) && lng >= -180 && lng <= 180;\n}\n\nexport function isValidLatLng(arr: LatLngArray): boolean {\n return (\n Array.isArray(arr) &&\n arr.length === 2 &&\n isValidLat(arr[0]) &&\n isValidLng(arr[1])\n );\n}\n"],"file":"map.js"}
|
package/lib/query.js
CHANGED
|
@@ -18,15 +18,9 @@ exports.parseLocationString = parseLocationString;
|
|
|
18
18
|
exports.planParamsToQuery = planParamsToQuery;
|
|
19
19
|
exports.planParamsToQueryAsync = planParamsToQueryAsync;
|
|
20
20
|
exports.getRoutingParams = getRoutingParams;
|
|
21
|
-
Object.defineProperty(exports, "summarizeQuery", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _deprecated.summarizeQuery;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
21
|
exports.defaultParams = void 0;
|
|
28
22
|
|
|
29
|
-
var
|
|
23
|
+
var _dateFns = require("date-fns");
|
|
30
24
|
|
|
31
25
|
var _lib = _interopRequireDefault(require("@opentripplanner/geocoder/lib"));
|
|
32
26
|
|
|
@@ -40,7 +34,8 @@ var _queryParams = _interopRequireDefault(require("./query-params"));
|
|
|
40
34
|
|
|
41
35
|
var _time = require("./time");
|
|
42
36
|
|
|
43
|
-
|
|
37
|
+
// import { coordsToString, summarizeQuery } from "./deprecated";
|
|
38
|
+
// export { summarizeQuery };
|
|
44
39
|
|
|
45
40
|
/* The list of default parameters considered in the settings panel */
|
|
46
41
|
const defaultParams = ["wheelchair", "maxWalkDistance", "walkReluctance", "maxWalkTime", "walkSpeed", "maxBikeDistance", "maxBikeTime", "bikeSpeed", "optimize", "optimizeBike", "maxEScooterDistance", "watts"];
|
|
@@ -272,7 +267,7 @@ function parseLocationString(value) {
|
|
|
272
267
|
if (!value) return null;
|
|
273
268
|
const parts = value.split("::");
|
|
274
269
|
const coordinates = parts[1] ? (0, _map.stringToCoords)(parts[1]) : (0, _map.stringToCoords)(parts[0]);
|
|
275
|
-
const name = parts[1] ? parts[0] : (0,
|
|
270
|
+
const name = parts[1] ? parts[0] : (0, _map.coordsToString)(coordinates);
|
|
276
271
|
return coordinates.length === 2 ? {
|
|
277
272
|
name: name || null,
|
|
278
273
|
lat: coordinates[0] || null,
|
|
@@ -330,8 +325,9 @@ function planParamsToQuery(params) {
|
|
|
330
325
|
|
|
331
326
|
case "time":
|
|
332
327
|
{
|
|
333
|
-
|
|
334
|
-
|
|
328
|
+
// Match one of the supported time formats
|
|
329
|
+
const matchedTimeFormat = TIME_FORMATS.find(timeFormat => (0, _dateFns.isMatch)(params.time, timeFormat));
|
|
330
|
+
query.time = matchedTimeFormat ? (0, _dateFns.format)((0, _dateFns.parse)(params.time, matchedTimeFormat, new Date()), _time.OTP_API_TIME_FORMAT) : (0, _time.getCurrentTime)();
|
|
335
331
|
}
|
|
336
332
|
break;
|
|
337
333
|
|
|
@@ -423,8 +419,8 @@ function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {
|
|
|
423
419
|
} // check date/time validity; ignore both if either is invalid
|
|
424
420
|
|
|
425
421
|
|
|
426
|
-
const dateValid = (0,
|
|
427
|
-
const timeValid = (0,
|
|
422
|
+
const dateValid = (0, _dateFns.isMatch)(params.date, _time.OTP_API_DATE_FORMAT_DATE_FNS);
|
|
423
|
+
const timeValid = (0, _dateFns.isMatch)(params.time, _time.OTP_API_TIME_FORMAT);
|
|
428
424
|
|
|
429
425
|
if (!dateValid || !timeValid) {
|
|
430
426
|
delete params.time;
|
|
@@ -445,8 +441,8 @@ function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {
|
|
|
445
441
|
|
|
446
442
|
} else {
|
|
447
443
|
// check start and end time validity; ignore both if either is invalid
|
|
448
|
-
const startTimeValid = (0,
|
|
449
|
-
const endTimeValid = (0,
|
|
444
|
+
const startTimeValid = (0, _dateFns.isMatch)(params.startTime, _time.OTP_API_TIME_FORMAT);
|
|
445
|
+
const endTimeValid = (0, _dateFns.isMatch)(params.endTime, _time.OTP_API_TIME_FORMAT);
|
|
450
446
|
|
|
451
447
|
if (!startTimeValid || !endTimeValid) {
|
|
452
448
|
delete params.startTimeValid;
|