@opentripplanner/core-utils 4.11.5 → 5.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/deprecated-with-types.js +47 -0
- package/esm/deprecated-with-types.js.map +1 -0
- package/esm/deprecated.js +7 -0
- package/esm/deprecated.js.map +1 -1
- package/esm/index.js +0 -4
- package/esm/index.js.map +1 -1
- package/esm/itinerary.js +3 -9
- package/esm/itinerary.js.map +1 -1
- package/esm/map.js +9 -2
- package/esm/map.js.map +1 -1
- package/esm/route.js +5 -3
- package/esm/route.js.map +1 -1
- package/esm/storage.js +1 -0
- package/esm/storage.js.map +1 -1
- package/esm/time.js +6 -36
- package/esm/time.js.map +1 -1
- package/esm/ui.js +1 -1
- package/esm/ui.js.map +1 -1
- package/lib/deprecated-with-types.d.ts +23 -0
- package/lib/deprecated-with-types.d.ts.map +1 -0
- package/lib/deprecated-with-types.js +61 -0
- package/lib/deprecated-with-types.js.map +1 -0
- package/lib/deprecated.js +9 -0
- package/lib/deprecated.js.map +1 -1
- package/lib/index.d.ts +19 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +0 -6
- package/lib/index.js.map +1 -1
- package/lib/itinerary.d.ts +113 -0
- package/lib/itinerary.d.ts.map +1 -0
- package/lib/itinerary.js +8 -9
- package/lib/itinerary.js.map +1 -1
- package/lib/map.d.ts +30 -0
- package/lib/map.d.ts.map +1 -0
- package/lib/map.js +8 -1
- package/lib/map.js.map +1 -1
- package/lib/route.d.ts +98 -0
- package/lib/route.d.ts.map +1 -0
- package/lib/route.js +5 -3
- package/lib/route.js.map +1 -1
- package/lib/storage.d.ts +19 -0
- package/lib/storage.d.ts.map +1 -0
- package/lib/storage.js +2 -0
- package/lib/storage.js.map +1 -1
- package/lib/time.d.ts +65 -0
- package/lib/time.d.ts.map +1 -0
- package/lib/time.js +22 -39
- package/lib/time.js.map +1 -1
- package/lib/ui.d.ts +13 -0
- package/lib/ui.d.ts.map +1 -0
- package/lib/ui.js +1 -1
- package/lib/ui.js.map +1 -1
- package/package.json +4 -1
- package/src/__tests__/__snapshots__/route.js.snap +30 -30
- package/src/deprecated-with-types.ts +62 -0
- package/src/deprecated.js +16 -0
- package/src/{index.js → index.ts} +0 -4
- package/src/{itinerary.js → itinerary.ts} +72 -50
- package/src/{map.js → map.ts} +48 -21
- package/src/{route.js → route.ts} +52 -28
- package/src/{storage.js → storage.ts} +6 -5
- package/src/{time.js → time.ts} +28 -46
- package/src/{ui.js → ui.ts} +8 -8
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +4921 -0
- package/esm/messages.js +0 -25
- package/esm/messages.js.map +0 -1
- package/esm/types.js +0 -560
- package/esm/types.js.map +0 -1
- package/lib/messages.js +0 -29
- package/lib/messages.js.map +0 -1
- package/lib/types.js +0 -661
- package/lib/types.js.map +0 -1
- package/src/messages.js +0 -20
- package/src/types.js +0 -605
|
@@ -0,0 +1,113 @@
|
|
|
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 };
|
|
4
|
+
export declare const transitModes: string[];
|
|
5
|
+
/**
|
|
6
|
+
* @param {config} config OTP-RR configuration object
|
|
7
|
+
* @return {Array} List of all transit modes defined in config; otherwise default mode list
|
|
8
|
+
*/
|
|
9
|
+
export declare function getTransitModes(config: Config): string[];
|
|
10
|
+
export declare function isTransit(mode: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Returns true if the leg pickup rules enabled which require
|
|
13
|
+
* calling ahead for the service to run. "mustPhone" is the only
|
|
14
|
+
* property of boardRule which encodes this info.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isReservationRequired(leg: Leg): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Returns true if the leg has continuous dropoff enabled which requires
|
|
19
|
+
* asking the driver to let the user off. "coordinateWithDriver" is the only
|
|
20
|
+
* property of alightRule which encodes this info.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isContinuousDropoff(leg: Leg): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The two rules checked by the above two functions are the only values
|
|
25
|
+
* returned by OTP when a leg is a flex leg.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isFlex(leg: Leg): boolean;
|
|
28
|
+
export declare function isAdvanceBookingRequired(info: FlexBookingInfo): boolean;
|
|
29
|
+
export declare function legDropoffRequiresAdvanceBooking(leg: Leg): boolean;
|
|
30
|
+
export declare function isWalk(mode: string): boolean;
|
|
31
|
+
export declare function isBicycle(mode: string): boolean;
|
|
32
|
+
export declare function isBicycleRent(mode: string): boolean;
|
|
33
|
+
export declare function isCar(mode: string): boolean;
|
|
34
|
+
export declare function isMicromobility(mode: string): boolean;
|
|
35
|
+
export declare function isAccessMode(mode: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* @param {string} modesStr a comma-separated list of OTP modes
|
|
38
|
+
* @return {boolean} whether any of the modes are transit modes
|
|
39
|
+
*/
|
|
40
|
+
export declare function hasTransit(modesStr: string): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* @param {string} modesStr a comma-separated list of OTP modes
|
|
43
|
+
* @return {boolean} whether any of the modes are car-based modes
|
|
44
|
+
*/
|
|
45
|
+
export declare function hasCar(modesStr: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* @param {string} modesStr a comma-separated list of OTP modes
|
|
48
|
+
* @return {boolean} whether any of the modes are bicycle-based modes
|
|
49
|
+
*/
|
|
50
|
+
export declare function hasBike(modesStr: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* @param {string} modesStr a comma-separated list of OTP modes
|
|
53
|
+
* @return {boolean} whether any of the modes are micromobility-based modes
|
|
54
|
+
*/
|
|
55
|
+
export declare function hasMicromobility(modesStr: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* @param {string} modesStr a comma-separated list of OTP modes
|
|
58
|
+
* @return {boolean} whether any of the modes is a hailing mode
|
|
59
|
+
*/
|
|
60
|
+
export declare function hasHail(modesStr: string): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* @param {string} modesStr a comma-separated list of OTP modes
|
|
63
|
+
* @return {boolean} whether any of the modes is a rental mode
|
|
64
|
+
*/
|
|
65
|
+
export declare function hasRental(modesStr: string): boolean;
|
|
66
|
+
export declare function getMapColor(mode: string): string;
|
|
67
|
+
export declare function toSentenceCase(str: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Derive the company string based on mode and network associated with leg.
|
|
70
|
+
*/
|
|
71
|
+
export declare function getCompanyFromLeg(leg: Leg): string;
|
|
72
|
+
export declare function getItineraryBounds(itinerary: Itinerary): LatLngArray[];
|
|
73
|
+
/**
|
|
74
|
+
* Return a coords object that encloses the given leg's geometry.
|
|
75
|
+
*/
|
|
76
|
+
export declare function getLegBounds(leg: Leg): number[];
|
|
77
|
+
export declare function legLocationAtDistance(leg: Leg, distance: number): number[];
|
|
78
|
+
export declare function legElevationAtDistance(points: number[][], distance: number): number;
|
|
79
|
+
export declare function getElevationProfile(steps: Step[], unitConversion?: number): ElevationProfile;
|
|
80
|
+
/**
|
|
81
|
+
* Uses canvas.measureText to compute and return the width of the given text of given font in pixels.
|
|
82
|
+
*
|
|
83
|
+
* @param {string} text The text to be rendered.
|
|
84
|
+
* @param {string} font The css font descriptor that text is to be rendered with (e.g. "bold 14px verdana").
|
|
85
|
+
*
|
|
86
|
+
* @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393
|
|
87
|
+
*/
|
|
88
|
+
export declare function getTextWidth(text: string, font?: string): number;
|
|
89
|
+
/**
|
|
90
|
+
* Get the configured company object for the given network string if the company
|
|
91
|
+
* has been defined in the provided companies array config.
|
|
92
|
+
*/
|
|
93
|
+
export declare function getCompanyForNetwork(networkString: string, companies?: Company[]): Company;
|
|
94
|
+
/**
|
|
95
|
+
* Get a string label to display from a list of vehicle rental networks.
|
|
96
|
+
*
|
|
97
|
+
* @param {Array<string>} networks A list of network ids.
|
|
98
|
+
* @param {Array<object>} [companies=[]] An optional list of the companies config.
|
|
99
|
+
* @return {string} A label for use in presentation on a website.
|
|
100
|
+
*/
|
|
101
|
+
export declare function getCompaniesLabelFromNetworks(networks: string[], companies?: Company[]): string;
|
|
102
|
+
export declare function getTNCLocation(leg: Leg, type: string): string;
|
|
103
|
+
export declare function calculatePhysicalActivity(itinerary: Itinerary): {
|
|
104
|
+
bikeDuration: number;
|
|
105
|
+
caloriesBurned: number;
|
|
106
|
+
walkDuration: number;
|
|
107
|
+
};
|
|
108
|
+
export declare function calculateTncFares(itinerary: any): {
|
|
109
|
+
maxTNCFare: any;
|
|
110
|
+
minTNCFare: any;
|
|
111
|
+
tncCurrencyCode: any;
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=itinerary.d.ts.map
|
|
@@ -0,0 +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,IAAI,EACL,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACf,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACf,CAAC;AAGF,eAAO,MAAM,YAAY,UAOxB,CAAC;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E,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB,CAcA;AAED,wBAAgB,iBAAiB,CAAC,SAAS,KAAA;;;;EAQ1C"}
|
package/lib/itinerary.js
CHANGED
|
@@ -37,7 +37,6 @@ exports.getCompanyForNetwork = getCompanyForNetwork;
|
|
|
37
37
|
exports.getCompaniesLabelFromNetworks = getCompaniesLabelFromNetworks;
|
|
38
38
|
exports.getTNCLocation = getTNCLocation;
|
|
39
39
|
exports.calculatePhysicalActivity = calculatePhysicalActivity;
|
|
40
|
-
exports.getTimeZoneOffset = getTimeZoneOffset;
|
|
41
40
|
exports.calculateTncFares = calculateTncFares;
|
|
42
41
|
Object.defineProperty(exports, "calculateFares", {
|
|
43
42
|
enumerable: true,
|
|
@@ -81,6 +80,12 @@ Object.defineProperty(exports, "getStepStreetName", {
|
|
|
81
80
|
return _deprecated.getStepStreetName;
|
|
82
81
|
}
|
|
83
82
|
});
|
|
83
|
+
Object.defineProperty(exports, "getTimeZoneOffset", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function () {
|
|
86
|
+
return _deprecated.getTimeZoneOffset;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
84
89
|
Object.defineProperty(exports, "getTransitFare", {
|
|
85
90
|
enumerable: true,
|
|
86
91
|
get: function () {
|
|
@@ -106,7 +111,7 @@ exports.transitModes = transitModes;
|
|
|
106
111
|
|
|
107
112
|
function getTransitModes(config) {
|
|
108
113
|
if (!config || !config.modes || !config.modes.transitModes) return transitModes;
|
|
109
|
-
return config.modes.transitModes.map(tm => tm.mode);
|
|
114
|
+
return config.modes.transitModes.map(tm => typeof tm !== "string" ? tm.mode : tm);
|
|
110
115
|
}
|
|
111
116
|
|
|
112
117
|
function isTransit(mode) {
|
|
@@ -436,6 +441,7 @@ function getElevationProfile(steps, unitConversion = 1) {
|
|
|
436
441
|
|
|
437
442
|
|
|
438
443
|
function getTextWidth(text, font = "22px Arial") {
|
|
444
|
+
// Create custom type for function including re-used canvas object
|
|
439
445
|
// re-use canvas object for better performance
|
|
440
446
|
const canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement("canvas"));
|
|
441
447
|
const context = canvas.getContext("2d");
|
|
@@ -491,13 +497,6 @@ function calculatePhysicalActivity(itinerary) {
|
|
|
491
497
|
};
|
|
492
498
|
}
|
|
493
499
|
|
|
494
|
-
function getTimeZoneOffset(itinerary) {
|
|
495
|
-
if (!itinerary.legs || !itinerary.legs.length) return 0; // Determine if there is a DST offset between now and the itinerary start date
|
|
496
|
-
|
|
497
|
-
const dstOffset = new Date(itinerary.startTime).getTimezoneOffset() - new Date().getTimezoneOffset();
|
|
498
|
-
return itinerary.legs[0].agencyTimeZoneOffset + (new Date().getTimezoneOffset() + dstOffset) * 60000;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
500
|
function calculateTncFares(itinerary) {
|
|
502
501
|
// TODO: don't rely on deprecated methods!
|
|
503
502
|
// At the moment this is safe as none of these exported variables contain strings
|
package/lib/itinerary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/itinerary.js"],"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","getTimeZoneOffset","dstOffset","Date","startTime","getTimezoneOffset","agencyTimeZoneOffset","calculateTncFares","maxTNCFare","minTNCFare","tncCurrencyCode"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AAsBA;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,EAAiC;AACtC,MAAI,CAACA,MAAD,IAAW,CAACA,MAAM,CAACC,KAAnB,IAA4B,CAACD,MAAM,CAACC,KAAP,CAAaH,YAA9C,EACE,OAAOA,YAAP;AACF,SAAOE,MAAM,CAACC,KAAP,CAAaH,YAAb,CAA0BI,GAA1B,CAA8BC,EAAE,IAAIA,EAAE,CAACC,IAAvC,CAAP;AACD;;AAEM,SAASC,SAAT,CAAmBD,IAAnB,EAAyB;AAC9B,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,EAAoC;AACzC,SAAOA,GAAG,CAACC,SAAJ,KAAkB,WAAzB;AACD;AACD;AACA;AACA;AACA;AACA;;;AACO,SAASC,mBAAT,CAA6BF,GAA7B,EAAkC;AACvC,SA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X,EAFF;AAIA,SACEpF,SAAS,CAACE,IAAV,CAAe,CAAf,EAAkBmF,oBAAlB,GACA,CAAC,IAAIH,IAAJ,GAAWE,iBAAX,KAAiCH,SAAlC,IAA+C,KAFjD;AAID;;AAEM,SAASK,iBAAT,CAA2BtF,SAA3B,EAAsC;AAC3C;AACA;AACA,QAAM;AAAEuF,IAAAA,UAAF;AAAcC,IAAAA,UAAd;AAA0BC,IAAAA;AAA1B,MAA8C,gCAClDzF,SADkD,EAElD,IAFkD,CAApD;AAIA,SAAO;AAAEuF,IAAAA,UAAF;AAAcC,IAAAA,UAAd;AAA0BC,IAAAA;AAA1B,GAAP;AACD","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport turfAlong from \"@turf/along\";\n\nimport {\n calculateFares,\n getLegModeLabel,\n getModeForPlace,\n getPlaceName,\n getStepDirection,\n getStepInstructions,\n getStepStreetName,\n getTransitFare\n} from \"./deprecated\";\n\nexport {\n calculateFares,\n getLegModeLabel,\n getModeForPlace,\n getPlaceName,\n getStepDirection,\n getStepInstructions,\n getStepStreetName,\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) {\n if (!config || !config.modes || !config.modes.transitModes)\n return transitModes;\n return config.modes.transitModes.map(tm => tm.mode);\n}\n\nexport function isTransit(mode) {\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) {\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) {\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) {\n return isReservationRequired(leg) || isContinuousDropoff(leg);\n}\n\nexport function isAdvanceBookingRequired(info) {\n return info?.latestBookingTime?.daysPrior > 0;\n}\nexport function legDropoffRequiresAdvanceBooking(leg) {\n return isAdvanceBookingRequired(leg.dropOffBookingInfo);\n}\n\nexport function isWalk(mode) {\n if (!mode) return false;\n\n return mode === \"WALK\";\n}\n\nexport function isBicycle(mode) {\n if (!mode) return false;\n\n return mode === \"BICYCLE\";\n}\n\nexport function isBicycleRent(mode) {\n if (!mode) return false;\n\n return mode === \"BICYCLE_RENT\";\n}\n\nexport function isCar(mode) {\n if (!mode) return false;\n return mode.startsWith(\"CAR\");\n}\n\nexport function isMicromobility(mode) {\n if (!mode) return false;\n return mode.startsWith(\"MICROMOBILITY\") || mode.startsWith(\"SCOOTER\");\n}\n\nexport function isAccessMode(mode) {\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) {\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) {\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) {\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) {\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) {\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) {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_RENT\") > -1);\n}\n\nexport function getMapColor(mode) {\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) {\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) {\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) {\n let coords = [];\n itinerary.legs.forEach(leg => {\n const legCoords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map(c => [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) {\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, distance) {\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(points, distance) {\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(steps, unitConversion = 1) {\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, font = \"22px Arial\") {\n // re-use canvas object for better performance\n const canvas =\n getTextWidth.canvas ||\n (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(networkString, companies = []) {\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(networks, companies = []) {\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, type) {\n const location = leg[type];\n return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;\n}\n\nexport function calculatePhysicalActivity(itinerary) {\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 getTimeZoneOffset(itinerary) {\n if (!itinerary.legs || !itinerary.legs.length) return 0;\n\n // Determine if there is a DST offset between now and the itinerary start date\n const dstOffset =\n new Date(itinerary.startTime).getTimezoneOffset() -\n new Date().getTimezoneOffset();\n\n return (\n itinerary.legs[0].agencyTimeZoneOffset +\n (new Date().getTimezoneOffset() + dstOffset) * 60000\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","maxTNCFare","minTNCFare","tncCurrencyCode"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAWA;;AAEA;;AAwBA;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,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ACA;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"}
|
package/lib/map.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Company, Itinerary, LatLngArray, Leg, Location, TransitiveData, UserPosition } from "@opentripplanner/types";
|
|
2
|
+
import { coordsToString, getDetailText, latlngToString } from "./deprecated";
|
|
3
|
+
export { coordsToString, getDetailText, latlngToString };
|
|
4
|
+
export declare function currentPositionToLocation(currentPosition: UserPosition): Location;
|
|
5
|
+
export declare function stringToCoords(str: string): number[];
|
|
6
|
+
export declare function constructLocation(latlng: {
|
|
7
|
+
lat: number;
|
|
8
|
+
lng: number;
|
|
9
|
+
}): Location;
|
|
10
|
+
export declare function formatStoredPlaceName(location: Location, withDetails?: boolean): string;
|
|
11
|
+
export declare function matchLatLon(location1: Location, location2: Location): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Converts an OTP itinerary object to a transtive.js itinerary object.
|
|
14
|
+
* @param {*} itin Required OTP itinerary (see @opentripplanner/core-utils/types#itineraryType) to convert.
|
|
15
|
+
* @param {*} companies Optional list of companies, used for labeling vehicle rental locations.
|
|
16
|
+
* @param {*} getRouteLabel Optional function that takes an itinerary leg (see @opentripplanner/core-utils/types#legType)
|
|
17
|
+
* and returns a string representing the route label to display for that leg.
|
|
18
|
+
* @returns An itinerary in the transitive.js format.
|
|
19
|
+
*/
|
|
20
|
+
export declare function itineraryToTransitive(itin: Itinerary, companies: Company[], getRouteLabel: (leg: Leg) => string, disableFlexArc: boolean): TransitiveData;
|
|
21
|
+
declare type TransitivePlaceRaw = {
|
|
22
|
+
place_id: string;
|
|
23
|
+
};
|
|
24
|
+
export declare function isBikeshareStation(place: TransitivePlaceRaw): boolean;
|
|
25
|
+
export declare function isEScooterStation(place: TransitivePlaceRaw): boolean;
|
|
26
|
+
export declare function isCarWalkTransition(place: TransitivePlaceRaw): boolean;
|
|
27
|
+
export declare function isValidLat(lat: number): boolean;
|
|
28
|
+
export declare function isValidLng(lng: number): boolean;
|
|
29
|
+
export declare function isValidLatLng(arr: LatLngArray): boolean;
|
|
30
|
+
//# sourceMappingURL=map.d.ts.map
|
package/lib/map.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"A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EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAOvD"}
|
package/lib/map.js
CHANGED
|
@@ -126,7 +126,13 @@ function itineraryToTransitive(itin, companies, getRouteLabel, disableFlexArc) {
|
|
|
126
126
|
let fromPlaceId;
|
|
127
127
|
|
|
128
128
|
if (leg.from.bikeShareId) {
|
|
129
|
-
fromPlaceId = `bicycle_rent_station_${leg.from.bikeShareId}`;
|
|
129
|
+
fromPlaceId = `bicycle_rent_station_${leg.from.bikeShareId}`;
|
|
130
|
+
|
|
131
|
+
if ( // OTP2 Scooter case
|
|
132
|
+
leg.mode === "SCOOTER") {
|
|
133
|
+
fromPlaceId = `escooter_rent_station_${leg.from.name}`;
|
|
134
|
+
} // OTP1 Scooter case
|
|
135
|
+
|
|
130
136
|
} else if (leg.from.vertexType === "VEHICLERENTAL") {
|
|
131
137
|
fromPlaceId = `escooter_rent_station_${leg.from.name}`;
|
|
132
138
|
} else if (leg.mode === "CAR" && idx > 0 && itin.legs[idx - 1].mode === "WALK") {
|
|
@@ -150,6 +156,7 @@ function itineraryToTransitive(itin, companies, getRouteLabel, disableFlexArc) {
|
|
|
150
156
|
}
|
|
151
157
|
|
|
152
158
|
const segment = {
|
|
159
|
+
arc: false,
|
|
153
160
|
type: leg.mode,
|
|
154
161
|
streetEdges: [streetEdgeId],
|
|
155
162
|
from: {
|
package/lib/map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/map.js"],"names":["currentPositionToLocation","currentPosition","error","coords","console","warn","lat","latitude","lon","longitude","category","stringToCoords","str","split","map","c","constructLocation","latlng","lng","formatStoredPlaceName","location","withDetails","displayName","type","name","detailText","matchLatLon","location1","location2","itineraryToTransitive","itin","companies","getRouteLabel","disableFlexArc","tdata","journeys","streetEdges","places","patterns","routes","stops","streetEdgeId","patternId","journey","journey_id","journey_name","segments","push","place_id","place_lat","legs","from","place_lon","length","to","forEach","leg","idx","mode","fromPlaceId","bikeShareId","vertexType","toPlaceId","segment","hailedCar","arc","edge_id","geometry","legGeometry","place_name","stopId","hasInterStopGeometry","interStopGeometry","hasLegGeometry","points","hasIntermediateStopGeometry","intermediateStops","ptnId","pattern","pattern_id","pattern_name","route_id","routeId","stop_id","stop_name","stop_lat","stop_lon","stop","i","routeLabel","routeShortName","agency_id","agencyId","route_short_name","route_long_name","routeLongName","route_type","routeType","route_color","routeColor","from_stop_index","to_stop_index","Object","values","isBikeshareStation","place","lastIndexOf","isEScooterStation","isCarWalkTransition","isValidLat","Number","isFinite","isValidLng","isValidLatLng","arr","Array","isArray"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAQA;;AASO,SAASA,yBAAT,CAAmCC,eAAnC,EAAoD;AACzD,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;;AAEM,SAASC,cAAT,CAAwBC,GAAxB,EAA6B;AAClC,SAAQA,GAAG,IAAIA,GAAG,CAACC,KAAJ,CAAU,GAAV,EAAeC,GAAf,CAAmBC,CAAC,IAAI,CAACA,CAAzB,CAAR,IAAwC,EAA/C;AACD;;AAEM,SAASC,iBAAT,CAA2BC,MAA3B,EAAmC;AACxC,SAAO;AACLX,IAAAA,GAAG,EAAEW,MAAM,CAACX,GADP;AAELE,IAAAA,GAAG,EAAES,MAAM,CAACC;AAFP,GAAP;AAID;;AAEM,SAASC,qBAAT,CAA+BC,QAA/B,EAAyCC,WAAW,GAAG,IAAvD,EAA6D;AAClE,MAAI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AAN,CAAeY,IAAf,CAAoBJ,OAApB,EA1NA,CA4NA;;AACA,SAAOT,KAAP;AACD;;AAEM,SAASsE,kBAAT,CAA4BC,KAA5B,EAAmC;AACxC,SAAOA,KAAK,CAACzD,QAAN,CAAe0D,WAAf,CAA2B,sBAA3B,MAAuD,CAAC,CAA/D;AACD;;AAEM,SAASC,iBAAT,CAA2BF,KAA3B,EAAkC;AACvC,SAAOA,KAAK,CAACzD,QAAN,CAAe0D,WAAf,CAA2B,uBAA3B,MAAwD,CAAC,CAAhE;AACD;;AAEM,SAASE,mBAAT,CAA6BH,KAA7B,EAAoC;AACzC,SAAOA,KAAK,CAACzD,QAAN,CAAe0D,WAAf,CAA2B,WAA3B,MAA4C,CAAC,CAApD;AACD;;AAEM,SAASG,UAAT,CAAoBvG,GAApB,EAAyB;AAC9B,SAAOwG,MAAM,CAACC,QAAP,CAAgBzG,GAAhB,KAAwBA,GAAG,IAAI,CAAC,EAAhC,IAAsCA,GAAG,IAAI,EAApD;AACD;;AAEM,SAAS0G,UAAT,CAAoB9F,GAApB,EAAyB;AAC9B,SAAO4F,MAAM,CAACC,QAAP,CAAgB7F,GAAhB,KAAwBA,GAAG,IAAI,CAAC,GAAhC,IAAuCA,GAAG,IAAI,GAArD;AACD;;AAEM,SAAS+F,aAAT,CAAuBC,GAAvB,EAA4B;AACjC,SACEC,KAAK,CAACC,OAAN,CAAcF,GAAd,KACAA,GAAG,CAAC7D,MAAJ,KAAe,CADf,IAEAwD,UAAU,CAACK,GAAG,CAAC,CAAD,CAAJ,CAFV,IAGAF,UAAU,CAACE,GAAG,CAAC,CAAD,CAAJ,CAJZ;AAMD","sourcesContent":["import {\n getPlaceName,\n isTransit,\n isFlex,\n toSentenceCase,\n isAccessMode\n} from \"./itinerary\";\n\nimport {\n coordsToString,\n getDetailText,\n latlngToString,\n logDeprecationWarning\n} from \"./deprecated\";\n\nexport { coordsToString, getDetailText, latlngToString };\n\nexport function currentPositionToLocation(currentPosition) {\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\nexport function stringToCoords(str) {\n return (str && str.split(\",\").map(c => +c)) || [];\n}\n\nexport function constructLocation(latlng) {\n return {\n lat: latlng.lat,\n lon: latlng.lng\n };\n}\n\nexport function formatStoredPlaceName(location, withDetails = true) {\n if (withDetails) {\n logDeprecationWarning(\"the formatStoredPlaceName withDetails parameter\");\n }\n\n let displayName =\n location.type === \"home\" || location.type === \"work\"\n ? toSentenceCase(location.type)\n : location.name;\n if (withDetails) {\n const detailText = getDetailText(location);\n if (detailText) displayName += ` (${detailText})`;\n }\n return displayName;\n}\n\nexport function matchLatLon(location1, location2) {\n if (!location1 || !location2) return location1 === location2;\n return location1.lat === location2.lat && location1.lon === location2.lon;\n}\n\n/**\n * Converts an OTP itinerary object to a transtive.js itinerary object.\n * @param {*} itin Required OTP itinerary (see @opentripplanner/core-utils/types#itineraryType) to convert.\n * @param {*} companies Optional list of companies, used for labeling vehicle rental locations.\n * @param {*} getRouteLabel Optional function that takes an itinerary leg (see @opentripplanner/core-utils/types#legType)\n * and returns a string representing the route label to display for that leg.\n * @returns An itinerary in the transitive.js format.\n */\nexport function itineraryToTransitive(\n itin,\n companies,\n getRouteLabel,\n disableFlexArc\n) {\n const tdata = {\n journeys: [],\n streetEdges: [],\n places: [],\n patterns: [],\n routes: [],\n stops: []\n };\n const routes = {};\n const stops = {};\n let streetEdgeId = 0;\n let patternId = 0;\n\n const journey = {\n journey_id: \"itin\",\n // This string is not shown in the UI\n journey_name: \"Iterarary-derived Journey\",\n segments: []\n };\n\n // add 'from' and 'to' places to the tdata places array\n tdata.places.push({\n place_id: \"from\",\n place_lat: itin.legs[0].from.lat,\n place_lon: itin.legs[0].from.lon\n });\n tdata.places.push({\n place_id: \"to\",\n place_lat: itin.legs[itin.legs.length - 1].to.lat,\n place_lon: itin.legs[itin.legs.length - 1].to.lon\n });\n\n itin.legs.forEach((leg, idx) => {\n if (isAccessMode(leg.mode)) {\n let fromPlaceId;\n if (leg.from.bikeShareId) {\n fromPlaceId = `bicycle_rent_station_${leg.from.bikeShareId}`;\n // TODO: does this need to change to be OTP2 compatible?\n } else if (leg.from.vertexType === \"VEHICLERENTAL\") {\n fromPlaceId = `escooter_rent_station_${leg.from.name}`;\n } else if (\n leg.mode === \"CAR\" &&\n idx > 0 &&\n itin.legs[idx - 1].mode === \"WALK\"\n ) {\n // create a special place ID for car legs preceded by walking legs\n fromPlaceId = `itin_car_${streetEdgeId}_from`;\n } else {\n fromPlaceId = `itin_street_${streetEdgeId}_from`;\n }\n\n let toPlaceId;\n if (leg.to.bikeShareId) {\n toPlaceId = `bicycle_rent_station_${leg.to.bikeShareId}`;\n } else if (leg.to.vertexType === \"VEHICLERENTAL\") {\n toPlaceId = `escooter_rent_station_${leg.to.name}`;\n } else if (\n leg.mode === \"CAR\" &&\n idx < itin.legs.length - 1 &&\n itin.legs[idx + 1].mode === \"WALK\"\n ) {\n // create a special place ID for car legs followed by walking legs\n toPlaceId = `itin_car_${streetEdgeId}_to`;\n } else {\n toPlaceId = `itin_street_${streetEdgeId}_to`;\n }\n\n const segment = {\n type: leg.mode,\n streetEdges: [streetEdgeId],\n from: { type: \"PLACE\", place_id: fromPlaceId },\n to: { type: \"PLACE\", place_id: toPlaceId }\n };\n // For TNC segments, draw using an arc\n if (leg.mode === \"CAR\" && leg.hailedCar) segment.arc = true;\n journey.segments.push(segment);\n\n tdata.streetEdges.push({\n edge_id: streetEdgeId,\n geometry: leg.legGeometry\n });\n tdata.places.push({\n place_id: fromPlaceId,\n // Do not label the from place in addition to the to place. Otherwise,\n // in some cases (bike rental station) the label for a single place will\n // appear twice on the rendered transitive view.\n // See https://github.com/conveyal/trimet-mod-otp/issues/152\n // place_name: leg.from.name,\n place_lat: leg.from.lat,\n place_lon: leg.from.lon\n });\n tdata.places.push({\n place_id: toPlaceId,\n // This string is not shown in the UI\n place_name: getPlaceName(leg.to, companies),\n place_lat: leg.to.lat,\n place_lon: leg.to.lon\n });\n streetEdgeId++;\n }\n\n if (isTransit(leg.mode)) {\n // Flex routes sometimes have the same from and to IDs, but\n // these stops still need to be rendered separately!\n if (leg.from.stopId === leg.to.stopId) {\n leg.to.stopId = `${leg.to.stopId}_flexed_to`;\n }\n // determine if we have valid inter-stop geometry\n const hasInterStopGeometry = !!leg.interStopGeometry;\n const hasLegGeometry = !!leg.legGeometry?.points;\n const hasIntermediateStopGeometry =\n hasInterStopGeometry &&\n leg.intermediateStops &&\n leg.interStopGeometry.length === leg.intermediateStops.length + 1;\n\n // create leg-specific pattern\n const ptnId = `ptn_${patternId}`;\n const pattern = {\n pattern_id: ptnId,\n // This string is not shown in the UI\n pattern_name: `Pattern ${patternId}`,\n route_id: leg.routeId,\n stops: []\n };\n\n // add 'from' stop to stops dictionary and pattern object\n stops[leg.from.stopId] = {\n stop_id: leg.from.stopId,\n stop_name: leg.from.name,\n stop_lat: leg.from.lat,\n stop_lon: leg.from.lon\n };\n pattern.stops.push({ stop_id: leg.from.stopId });\n\n // add intermediate stops to stops dictionary and pattern object\n // If there is no intermediateStopGeometry, do not add the intermediate stops\n // as it will be straight lines instead of the nice legGeometry (but only if\n // the legGeometry exists).\n if (\n leg.intermediateStops &&\n (hasIntermediateStopGeometry || !hasLegGeometry)\n ) {\n leg.intermediateStops.forEach((stop, i) => {\n stops[stop.stopId] = {\n stop_id: stop.stopId,\n stop_name: stop.name,\n stop_lat: stop.lat,\n stop_lon: stop.lon\n };\n pattern.stops.push({\n stop_id: stop.stopId,\n geometry:\n hasIntermediateStopGeometry && leg.interStopGeometry[i].points\n });\n });\n }\n\n // add 'to' stop to stops dictionary and pattern object\n stops[leg.to.stopId] = {\n stop_id: leg.to.stopId,\n stop_name: leg.to.name,\n stop_lat: leg.to.lat,\n stop_lon: leg.to.lon\n };\n pattern.stops.push({\n stop_id: leg.to.stopId,\n geometry:\n // Some legs don't have intermediateStopGeometry, but do have valid legGeometry\n (hasInterStopGeometry || hasLegGeometry) &&\n (hasIntermediateStopGeometry\n ? leg.interStopGeometry[leg.interStopGeometry.length - 1].points\n : leg.legGeometry.points)\n });\n\n // add route to the route dictionary\n // with a custom route label if specified.\n const routeLabel =\n typeof getRouteLabel === \"function\"\n ? getRouteLabel(leg)\n : leg.routeShortName;\n routes[leg.routeId] = {\n agency_id: leg.agencyId,\n route_id: leg.routeId,\n route_short_name: routeLabel || \"\",\n route_long_name: leg.routeLongName || \"\",\n route_type: leg.routeType,\n route_color: leg.routeColor\n };\n\n // add the pattern to the tdata patterns array\n tdata.patterns.push(pattern);\n\n // add the pattern reference to the journey object\n journey.segments.push({\n arc:\n typeof disableFlexArc === \"undefined\" ? isFlex(leg) : !disableFlexArc,\n type: \"TRANSIT\",\n patterns: [\n {\n pattern_id: ptnId,\n from_stop_index: 0,\n to_stop_index: hasIntermediateStopGeometry\n ? leg.intermediateStops.length + 2 - 1\n : 1\n }\n ]\n });\n\n patternId++;\n }\n });\n\n // add the routes and stops to the tdata arrays\n tdata.routes.push(...Object.values(routes));\n tdata.stops.push(...Object.values(stops));\n\n // add the journey to the tdata journeys array\n tdata.journeys.push(journey);\n\n // console.log('derived tdata', tdata);\n return tdata;\n}\n\nexport function isBikeshareStation(place) {\n return place.place_id.lastIndexOf(\"bicycle_rent_station\") !== -1;\n}\n\nexport function isEScooterStation(place) {\n return place.place_id.lastIndexOf(\"escooter_rent_station\") !== -1;\n}\n\nexport function isCarWalkTransition(place) {\n return place.place_id.lastIndexOf(\"itin_car_\") !== -1;\n}\n\nexport function isValidLat(lat) {\n return Number.isFinite(lat) && lat >= -90 && lat <= 90;\n}\n\nexport function isValidLng(lng) {\n return Number.isFinite(lng) && lng >= -180 && lng <= 180;\n}\n\nexport function isValidLatLng(arr) {\n return (\n Array.isArray(arr) &&\n arr.length === 2 &&\n isValidLat(arr[0]) &&\n isValidLng(arr[1])\n );\n}\n"],"file":"map.js"}
|
|
1
|
+
{"version":3,"sources":["../src/map.ts"],"names":["currentPositionToLocation","currentPosition","error","coords","console","warn","lat","latitude","lon","longitude","category","stringToCoords","str","split","map","c","constructLocation","latlng","lng","formatStoredPlaceName","location","withDetails","displayName","type","name","detailText","matchLatLon","location1","location2","itineraryToTransitive","itin","companies","getRouteLabel","disableFlexArc","tdata","journeys","streetEdges","places","patterns","routes","stops","streetEdgeId","patternId","journey","journey_id","journey_name","segments","push","place_id","place_lat","legs","from","place_lon","length","to","forEach","leg","idx","mode","fromPlaceId","bikeShareId","vertexType","toPlaceId","segment","arc","hailedCar","edge_id","geometry","legGeometry","place_name","stopId","hasInterStopGeometry","interStopGeometry","hasLegGeometry","points","hasIntermediateStopGeometry","intermediateStops","ptnId","pattern","pattern_id","pattern_name","route_id","routeId","stop_id","stop_name","stop_lat","stop_lon","stop","i","routeLabel","routeShortName","agency_id","agencyId","route_short_name","route_long_name","routeLongName","route_type","routeType","route_color","routeColor","from_stop_index","to_stop_index","Object","values","isBikeshareStation","place","lastIndexOf","isEScooterStation","isCarWalkTransition","isValidLat","Number","isFinite","isValidLng","isValidLatLng","arr","Array","isArray"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA;;AAQA;;AASO,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;;AAEM,SAASC,cAAT,CAAwBC,GAAxB,EAA+C;AACpD,SAAQA,GAAG,IAAIA,GAAG,CAACC,KA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,CAAC,GAAhC,IAAuCA,GAAG,IAAI,GAArD;AACD;;AAEM,SAAS+F,aAAT,CAAuBC,GAAvB,EAAkD;AACvD,SACEC,KAAK,CAACC,OAAN,CAAcF,GAAd,KACAA,GAAG,CAAC7D,MAAJ,KAAe,CADf,IAEAwD,UAAU,CAACK,GAAG,CAAC,CAAD,CAAJ,CAFV,IAGAF,UAAU,CAACE,GAAG,CAAC,CAAD,CAAJ,CAJZ;AAMD","sourcesContent":["import {\n Company,\n Itinerary,\n LatLngArray,\n Leg,\n Location,\n TransitiveData,\n UserPosition\n} from \"@opentripplanner/types\";\nimport {\n getPlaceName,\n isAccessMode,\n isFlex,\n isTransit,\n toSentenceCase\n} from \"./itinerary\";\n\nimport {\n coordsToString,\n getDetailText,\n latlngToString,\n logDeprecationWarning\n} from \"./deprecated\";\n\nexport { coordsToString, getDetailText, latlngToString };\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\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(\n location: Location,\n withDetails = true\n): string {\n if (withDetails) {\n logDeprecationWarning(\"the formatStoredPlaceName withDetails parameter\");\n }\n\n let displayName =\n location.type === \"home\" || location.type === \"work\"\n ? toSentenceCase(location.type)\n : location.name;\n if (withDetails) {\n const detailText = getDetailText(location);\n if (detailText) displayName += ` (${detailText})`;\n }\n return displayName;\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\n/**\n * Converts an OTP itinerary object to a transtive.js itinerary object.\n * @param {*} itin Required OTP itinerary (see @opentripplanner/core-utils/types#itineraryType) to convert.\n * @param {*} companies Optional list of companies, used for labeling vehicle rental locations.\n * @param {*} getRouteLabel Optional function that takes an itinerary leg (see @opentripplanner/core-utils/types#legType)\n * and returns a string representing the route label to display for that leg.\n * @returns An itinerary in the transitive.js format.\n */\nexport function itineraryToTransitive(\n itin: Itinerary,\n companies: Company[],\n getRouteLabel: (leg: Leg) => string,\n disableFlexArc: boolean\n): TransitiveData {\n const tdata = {\n journeys: [],\n streetEdges: [],\n places: [],\n patterns: [],\n routes: [],\n stops: []\n };\n const routes = {};\n const stops = {};\n let streetEdgeId = 0;\n let patternId = 0;\n\n const journey = {\n journey_id: \"itin\",\n // This string is not shown in the UI\n journey_name: \"Iterarary-derived Journey\",\n segments: []\n };\n\n // add 'from' and 'to' places to the tdata places array\n tdata.places.push({\n place_id: \"from\",\n place_lat: itin.legs[0].from.lat,\n place_lon: itin.legs[0].from.lon\n });\n tdata.places.push({\n place_id: \"to\",\n place_lat: itin.legs[itin.legs.length - 1].to.lat,\n place_lon: itin.legs[itin.legs.length - 1].to.lon\n });\n\n itin.legs.forEach((leg, idx) => {\n if (isAccessMode(leg.mode)) {\n let fromPlaceId: string;\n if (leg.from.bikeShareId) {\n fromPlaceId = `bicycle_rent_station_${leg.from.bikeShareId}`;\n if (\n // OTP2 Scooter case\n leg.mode === \"SCOOTER\"\n ) {\n fromPlaceId = `escooter_rent_station_${leg.from.name}`;\n }\n // OTP1 Scooter case\n } else if (leg.from.vertexType === \"VEHICLERENTAL\") {\n fromPlaceId = `escooter_rent_station_${leg.from.name}`;\n } else if (\n leg.mode === \"CAR\" &&\n idx > 0 &&\n itin.legs[idx - 1].mode === \"WALK\"\n ) {\n // create a special place ID for car legs preceded by walking legs\n fromPlaceId = `itin_car_${streetEdgeId}_from`;\n } else {\n fromPlaceId = `itin_street_${streetEdgeId}_from`;\n }\n\n let toPlaceId;\n if (leg.to.bikeShareId) {\n toPlaceId = `bicycle_rent_station_${leg.to.bikeShareId}`;\n } else if (leg.to.vertexType === \"VEHICLERENTAL\") {\n toPlaceId = `escooter_rent_station_${leg.to.name}`;\n } else if (\n leg.mode === \"CAR\" &&\n idx < itin.legs.length - 1 &&\n itin.legs[idx + 1].mode === \"WALK\"\n ) {\n // create a special place ID for car legs followed by walking legs\n toPlaceId = `itin_car_${streetEdgeId}_to`;\n } else {\n toPlaceId = `itin_street_${streetEdgeId}_to`;\n }\n\n const segment = {\n arc: false,\n type: leg.mode,\n streetEdges: [streetEdgeId],\n from: { type: \"PLACE\", place_id: fromPlaceId },\n to: { type: \"PLACE\", place_id: toPlaceId }\n };\n // For TNC segments, draw using an arc\n if (leg.mode === \"CAR\" && leg.hailedCar) segment.arc = true;\n journey.segments.push(segment);\n\n tdata.streetEdges.push({\n edge_id: streetEdgeId,\n geometry: leg.legGeometry\n });\n tdata.places.push({\n place_id: fromPlaceId,\n // Do not label the from place in addition to the to place. Otherwise,\n // in some cases (bike rental station) the label for a single place will\n // appear twice on the rendered transitive view.\n // See https://github.com/conveyal/trimet-mod-otp/issues/152\n // place_name: leg.from.name,\n place_lat: leg.from.lat,\n place_lon: leg.from.lon\n });\n tdata.places.push({\n place_id: toPlaceId,\n // This string is not shown in the UI\n place_name: getPlaceName(leg.to, companies),\n place_lat: leg.to.lat,\n place_lon: leg.to.lon\n });\n streetEdgeId++;\n }\n\n if (isTransit(leg.mode)) {\n // Flex routes sometimes have the same from and to IDs, but\n // these stops still need to be rendered separately!\n if (leg.from.stopId === leg.to.stopId) {\n leg.to.stopId = `${leg.to.stopId}_flexed_to`;\n }\n // determine if we have valid inter-stop geometry\n const hasInterStopGeometry = !!leg.interStopGeometry;\n const hasLegGeometry = !!leg.legGeometry?.points;\n const hasIntermediateStopGeometry =\n hasInterStopGeometry &&\n leg.intermediateStops &&\n leg.interStopGeometry.length === leg.intermediateStops.length + 1;\n\n // create leg-specific pattern\n const ptnId = `ptn_${patternId}`;\n const pattern = {\n pattern_id: ptnId,\n // This string is not shown in the UI\n pattern_name: `Pattern ${patternId}`,\n route_id: leg.routeId,\n stops: []\n };\n\n // add 'from' stop to stops dictionary and pattern object\n stops[leg.from.stopId] = {\n stop_id: leg.from.stopId,\n stop_name: leg.from.name,\n stop_lat: leg.from.lat,\n stop_lon: leg.from.lon\n };\n pattern.stops.push({ stop_id: leg.from.stopId });\n\n // add intermediate stops to stops dictionary and pattern object\n // If there is no intermediateStopGeometry, do not add the intermediate stops\n // as it will be straight lines instead of the nice legGeometry (but only if\n // the legGeometry exists).\n if (\n leg.intermediateStops &&\n (hasIntermediateStopGeometry || !hasLegGeometry)\n ) {\n leg.intermediateStops.forEach((stop, i) => {\n stops[stop.stopId] = {\n stop_id: stop.stopId,\n stop_name: stop.name,\n stop_lat: stop.lat,\n stop_lon: stop.lon\n };\n pattern.stops.push({\n stop_id: stop.stopId,\n geometry:\n hasIntermediateStopGeometry && leg.interStopGeometry[i].points\n });\n });\n }\n\n // add 'to' stop to stops dictionary and pattern object\n stops[leg.to.stopId] = {\n stop_id: leg.to.stopId,\n stop_name: leg.to.name,\n stop_lat: leg.to.lat,\n stop_lon: leg.to.lon\n };\n pattern.stops.push({\n stop_id: leg.to.stopId,\n geometry:\n // Some legs don't have intermediateStopGeometry, but do have valid legGeometry\n (hasInterStopGeometry || hasLegGeometry) &&\n (hasIntermediateStopGeometry\n ? leg.interStopGeometry[leg.interStopGeometry.length - 1].points\n : leg.legGeometry.points)\n });\n\n // add route to the route dictionary\n // with a custom route label if specified.\n const routeLabel =\n typeof getRouteLabel === \"function\"\n ? getRouteLabel(leg)\n : leg.routeShortName;\n routes[leg.routeId] = {\n agency_id: leg.agencyId,\n route_id: leg.routeId,\n route_short_name: routeLabel || \"\",\n route_long_name: leg.routeLongName || \"\",\n route_type: leg.routeType,\n route_color: leg.routeColor\n };\n\n // add the pattern to the tdata patterns array\n tdata.patterns.push(pattern);\n\n // add the pattern reference to the journey object\n journey.segments.push({\n arc:\n typeof disableFlexArc === \"undefined\" ? isFlex(leg) : !disableFlexArc,\n type: \"TRANSIT\",\n patterns: [\n {\n pattern_id: ptnId,\n from_stop_index: 0,\n to_stop_index: hasIntermediateStopGeometry\n ? leg.intermediateStops.length + 2 - 1\n : 1\n }\n ]\n });\n\n patternId++;\n }\n });\n\n // add the routes and stops to the tdata arrays\n tdata.routes.push(...Object.values(routes));\n tdata.stops.push(...Object.values(stops));\n\n // add the journey to the tdata journeys array\n tdata.journeys.push(journey);\n\n // console.log('derived tdata', tdata);\n return tdata;\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/route.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Leg, Route, TransitOperator } from "@opentripplanner/types";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the transit operator (if an exact match is found) from the transit
|
|
4
|
+
* operators config value. It is critical to use both the feedId and agencyId in
|
|
5
|
+
* this method because it is possible in OTP for there to be a duplicate
|
|
6
|
+
* agencyId in separate feeds.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} feedId The feedId that this transit agency belongs to
|
|
9
|
+
* @param {string} agencyId The agencyId of the transit agency
|
|
10
|
+
* @param {array} transitOperators The transitOperators list from the config
|
|
11
|
+
* @return {object} The transitOperator if a match was found or null if no match
|
|
12
|
+
* was found
|
|
13
|
+
*/
|
|
14
|
+
export declare function getTransitOperatorFromFeedIdAndAgencyId(feedId: string, agencyId: string | number, transitOperators: TransitOperator[]): TransitOperator;
|
|
15
|
+
/**
|
|
16
|
+
* Looks up an operator from the provided leg.
|
|
17
|
+
*
|
|
18
|
+
* @param {object} leg The Itinerary Leg from which to find the transit
|
|
19
|
+
* operator
|
|
20
|
+
* @param {object} transitOperators transitOperators from config.
|
|
21
|
+
* @return {object} the operator if one was found or null if no match was found
|
|
22
|
+
*/
|
|
23
|
+
export declare function getTransitOperatorFromLeg(leg: Leg, transitOperators: TransitOperator[]): TransitOperator;
|
|
24
|
+
/**
|
|
25
|
+
* Looks up an operator from the provided configuration given an OTP route.
|
|
26
|
+
* NOTE: this assumes the use of the OTP Route model or a modified OTP
|
|
27
|
+
* RouteShort model (such as the one found in the IBI fork of OTP) that also
|
|
28
|
+
* returns the agencyId.
|
|
29
|
+
*
|
|
30
|
+
* @param {object} route Either an OTP Route or RouteShort model
|
|
31
|
+
* @param {array} transitOperators transitOperators from config
|
|
32
|
+
* @return {object} the operator if one was found or null if no match was found
|
|
33
|
+
*/
|
|
34
|
+
export declare function getTransitOperatorFromOtpRoute(route: Route, transitOperators: TransitOperator[]): TransitOperator;
|
|
35
|
+
/**
|
|
36
|
+
* Checks whether an appropriate comparison of numeric values can be made for
|
|
37
|
+
* sorting purposes. If both values are not valid numbers according to the
|
|
38
|
+
* isNaN check, then this function returns undefined which indicates that a
|
|
39
|
+
* secondary sorting criteria should be used instead. If one value is valid and
|
|
40
|
+
* the other is not, then the valid value will be given sorting priority. If
|
|
41
|
+
* both values are valid numbers, the difference is obtained as the sort value.
|
|
42
|
+
*
|
|
43
|
+
* An optional argument can be provided which will be used to obtain the
|
|
44
|
+
* comparison value from the comparison function arguments.
|
|
45
|
+
*
|
|
46
|
+
* IMPORTANT: the comparison values must be numeric values or at least be
|
|
47
|
+
* attempted to be converted to numeric values! If one of the arguments is
|
|
48
|
+
* something crazy like an empty string, unexpected behavior will occur because
|
|
49
|
+
* JavaScript.
|
|
50
|
+
*
|
|
51
|
+
* @param {function} [objGetterFn] An optional function to obtain the
|
|
52
|
+
* comparison value from the comparator function arguments
|
|
53
|
+
*/
|
|
54
|
+
export declare function makeNumericValueComparator(objGetterFn?: (item: Route) => number): (a: number, b: number) => number;
|
|
55
|
+
/**
|
|
56
|
+
* Create a comparator function that compares string values. The comparison
|
|
57
|
+
* values feed to the sort comparator function are assumed to be objects that
|
|
58
|
+
* will have either undefined, null or string values at the given key. If one
|
|
59
|
+
* object has undefined, null or an empty string, but the other does have a
|
|
60
|
+
* string with length > 0, then that string will get priority.
|
|
61
|
+
*
|
|
62
|
+
* @param {function} [objGetterFn] An optional function to obtain the
|
|
63
|
+
* comparison value from the comparator function arguments
|
|
64
|
+
*/
|
|
65
|
+
export declare function makeStringValueComparator(objGetterFn?: (item: Route) => string): (a: string, b: string) => number;
|
|
66
|
+
/**
|
|
67
|
+
* Creates a sort comparator function to compares routes for the purposes of
|
|
68
|
+
* sorting and displaying in a user interface. This takes in a single optional
|
|
69
|
+
* argument which should be a list of transitOperators as defined in the config
|
|
70
|
+
* file. Due to GTFS feeds having varying levels of data quality, a multi-
|
|
71
|
+
* criteria sort is needed to account for various differences. The criteria
|
|
72
|
+
* included here are each applied to the routes in the order listed. If a given
|
|
73
|
+
* sort criterion yields equivalence (e.g., two routes have the short name
|
|
74
|
+
* "20"), the comparator falls back onto the next sort criterion (e.g., long
|
|
75
|
+
* name). The sort operates on the following values (in order):
|
|
76
|
+
*
|
|
77
|
+
* 1. Transit Operator. The transit operator will be attempted to be obtained
|
|
78
|
+
* for each route. If no argument is provided when creating this comparator
|
|
79
|
+
* function, then routes will be sorted by their agency's name. If an
|
|
80
|
+
* argument is provided and a match is found based off of the route's feed_id
|
|
81
|
+
* and agency_id and a transitOperator's feed_id and agency_id, then the
|
|
82
|
+
* field transitOperator.order will be used as the comparator value as long
|
|
83
|
+
* as it is numeric. If it is not numeric, a value is returned indicating
|
|
84
|
+
* that this transit operator should be placed at the end of the list.
|
|
85
|
+
* 2. sortOrder. Routes that do not have a valid sortOrder will be placed
|
|
86
|
+
* beneath those that do.
|
|
87
|
+
* 3. route type (OTP mode). See routeTypeComparator code for prioritization of
|
|
88
|
+
* route types.
|
|
89
|
+
* 4. shortNames that begin with alphabetic characters. shortNames that do not
|
|
90
|
+
* start with alphabetic characters will be place beneath those that do.
|
|
91
|
+
* 5. shortName as integer. shortNames that cannot be parsed as integers will
|
|
92
|
+
* be placed beneath those that are valid.
|
|
93
|
+
* 6. shortName as string. Routes without shortNames will be placed beneath
|
|
94
|
+
* those with shortNames.
|
|
95
|
+
* 7. longName as string.
|
|
96
|
+
*/
|
|
97
|
+
export declare function makeRouteComparator(transitOperators: TransitOperator[]): (a: number, b: number) => number;
|
|
98
|
+
//# sourceMappingURL=route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACrE;;;;;;;;;;;GAWG;AACH,wBAAgB,uCAAuC,CACrD,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GAAG,MAAM,EACzB,gBAAgB,EAAE,eAAe,EAAE,GAClC,eAAe,CAQjB;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,GAAG,EACR,gBAAgB,EAAE,eAAe,EAAE,GAClC,eAAe,CAQjB;AAED;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,KAAK,EACZ,gBAAgB,EAAE,eAAe,EAAE,GAClC,eAAe,CAkBjB;AA0MD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,0BAA0B,CACxC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,OAI1B,MAAM,KAAK,MAAM,KAAG,MAAM,CAatC;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,OAE1B,MAAM,KAAK,MAAM,KAAG,MAAM,CAatC;AAqCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,mBAAmB,CACjC,gBAAgB,EAAE,eAAe,EAAE,GAClC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAUlC"}
|
package/lib/route.js
CHANGED
|
@@ -132,7 +132,7 @@ function makeTransitOperatorComparator(transitOperators) {
|
|
|
132
132
|
if (aVal < bVal) return -1;
|
|
133
133
|
if (aVal > bVal) return 1;
|
|
134
134
|
return 0;
|
|
135
|
-
} // transitOperators are defined and therefore a numeric value is guaranteed
|
|
135
|
+
} // @ts-expect-error transitOperators are defined and therefore a numeric value is guaranteed
|
|
136
136
|
// to be returned
|
|
137
137
|
|
|
138
138
|
|
|
@@ -210,7 +210,7 @@ function getRouteTypeComparatorValue(route) {
|
|
|
210
210
|
// For some strange reason, the short route response in OTP returns the
|
|
211
211
|
// string-based modes, but the long route response returns the
|
|
212
212
|
// integer route type. This attempts to account for both of those cases.
|
|
213
|
-
if (!route) throw new Error(
|
|
213
|
+
if (!route) throw new Error(`Route is undefined. ${route}`);
|
|
214
214
|
|
|
215
215
|
if (typeof modeComparatorValue[route.mode] !== "undefined") {
|
|
216
216
|
return modeComparatorValue[route.mode];
|
|
@@ -220,6 +220,7 @@ function getRouteTypeComparatorValue(route) {
|
|
|
220
220
|
return routeTypeComparatorValue[route.type];
|
|
221
221
|
} // Default the comparator value to a large number (placing the route at the
|
|
222
222
|
// end of the list).
|
|
223
|
+
// eslint-disable-next-line no-console
|
|
223
224
|
|
|
224
225
|
|
|
225
226
|
console.warn("no mode/route type found for route", route);
|
|
@@ -301,7 +302,8 @@ function makeNumericValueComparator(objGetterFn) {
|
|
|
301
302
|
const {
|
|
302
303
|
aVal,
|
|
303
304
|
bVal
|
|
304
|
-
} = getSortValues(objGetterFn, a, b);
|
|
305
|
+
} = getSortValues(objGetterFn, a, b);
|
|
306
|
+
if (typeof aVal !== "number" || typeof bVal !== "number") return 0; // if both values aren't valid numbers, use the next sort criteria
|
|
305
307
|
|
|
306
308
|
if (isNaN(aVal) && isNaN(bVal)) return 0; // b is a valid number, b gets priority
|
|
307
309
|
|