@opentripplanner/core-utils 5.0.2 → 6.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/map.js CHANGED
@@ -1,5 +1,4 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import { getPlaceName, isAccessMode, isFlex, isTransit, toSentenceCase } from "./itinerary";
1
+ import { toSentenceCase } from "./itinerary";
3
2
  import { coordsToString, getDetailText, latlngToString, logDeprecationWarning } from "./deprecated";
4
3
  export { coordsToString, getDetailText, latlngToString };
5
4
  export function currentPositionToLocation(currentPosition) {
@@ -45,227 +44,6 @@ export function matchLatLon(location1, location2) {
45
44
  if (!location1 || !location2) return location1 === location2;
46
45
  return location1.lat === location2.lat && location1.lon === location2.lon;
47
46
  }
48
- /**
49
- * Converts an OTP itinerary object to a transtive.js itinerary object.
50
- * @param {*} itin Required OTP itinerary (see @opentripplanner/core-utils/types#itineraryType) to convert.
51
- * @param {*} companies Optional list of companies, used for labeling vehicle rental locations.
52
- * @param {*} getRouteLabel Optional function that takes an itinerary leg (see @opentripplanner/core-utils/types#legType)
53
- * and returns a string representing the route label to display for that leg.
54
- * @returns An itinerary in the transitive.js format.
55
- */
56
-
57
- export function itineraryToTransitive(itin, companies, getRouteLabel, disableFlexArc) {
58
- var _tdata$routes, _tdata$stops;
59
-
60
- var tdata = {
61
- journeys: [],
62
- streetEdges: [],
63
- places: [],
64
- patterns: [],
65
- routes: [],
66
- stops: []
67
- };
68
- var routes = {};
69
- var stops = {};
70
- var streetEdgeId = 0;
71
- var patternId = 0;
72
- var journey = {
73
- journey_id: "itin",
74
- // This string is not shown in the UI
75
- journey_name: "Iterarary-derived Journey",
76
- segments: []
77
- }; // add 'from' and 'to' places to the tdata places array
78
-
79
- tdata.places.push({
80
- place_id: "from",
81
- place_lat: itin.legs[0].from.lat,
82
- place_lon: itin.legs[0].from.lon
83
- });
84
- tdata.places.push({
85
- place_id: "to",
86
- place_lat: itin.legs[itin.legs.length - 1].to.lat,
87
- place_lon: itin.legs[itin.legs.length - 1].to.lon
88
- });
89
- itin.legs.forEach(function (leg, idx) {
90
- if (isAccessMode(leg.mode)) {
91
- var fromPlaceId;
92
-
93
- if (leg.from.bikeShareId) {
94
- fromPlaceId = "bicycle_rent_station_".concat(leg.from.bikeShareId);
95
-
96
- if ( // OTP2 Scooter case
97
- leg.mode === "SCOOTER") {
98
- fromPlaceId = "escooter_rent_station_".concat(leg.from.bikeShareId);
99
- }
100
- } else if (leg.from.vertexType === "VEHICLERENTAL") {
101
- // OTP1 Scooter case
102
- fromPlaceId = "escooter_rent_station_".concat(leg.from.name);
103
- } else if (leg.mode === "CAR" && idx > 0 && itin.legs[idx - 1].mode === "WALK") {
104
- // create a special place ID for car legs preceded by walking legs
105
- fromPlaceId = "itin_car_".concat(streetEdgeId, "_from");
106
- } else if (!fromPlaceId) {
107
- fromPlaceId = "itin_street_".concat(streetEdgeId, "_from");
108
- }
109
-
110
- var toPlaceId;
111
-
112
- if (leg.to.bikeShareId) {
113
- var _itin$legs;
114
-
115
- toPlaceId = "bicycle_rent_station_".concat(leg.to.bikeShareId); // OTP2 scooter case
116
- // Need to check next leg since this is a "to" place "
117
-
118
- if (leg.mode === "SCOOTER" || ((_itin$legs = itin.legs) === null || _itin$legs === void 0 ? void 0 : _itin$legs[idx + 1].mode) === "SCOOTER") {
119
- toPlaceId = "escooter_rent_station_".concat(leg.to.bikeShareId);
120
- }
121
- } else if (leg.to.vertexType === "VEHICLERENTAL") {
122
- toPlaceId = "escooter_rent_station_".concat(leg.to.name);
123
- } else if (leg.mode === "CAR" && idx < itin.legs.length - 1 && itin.legs[idx + 1].mode === "WALK") {
124
- // create a special place ID for car legs followed by walking legs
125
- toPlaceId = "itin_car_".concat(streetEdgeId, "_to");
126
- } else if (!toPlaceId) {
127
- toPlaceId = "itin_street_".concat(streetEdgeId, "_to");
128
- }
129
-
130
- var segment = {
131
- arc: false,
132
- type: leg.mode,
133
- streetEdges: [streetEdgeId],
134
- from: {
135
- type: "PLACE",
136
- place_id: fromPlaceId
137
- },
138
- to: {
139
- type: "PLACE",
140
- place_id: toPlaceId
141
- }
142
- }; // For TNC segments, draw using an arc
143
-
144
- if (leg.mode === "CAR" && leg.hailedCar) segment.arc = true;
145
- journey.segments.push(segment);
146
- tdata.streetEdges.push({
147
- edge_id: streetEdgeId,
148
- geometry: leg.legGeometry
149
- });
150
- tdata.places.push({
151
- place_id: fromPlaceId,
152
- // Do not label the from place in addition to the to place. Otherwise,
153
- // in some cases (bike rental station) the label for a single place will
154
- // appear twice on the rendered transitive view.
155
- // See https://github.com/conveyal/trimet-mod-otp/issues/152
156
- // place_name: leg.from.name,
157
- place_lat: leg.from.lat,
158
- place_lon: leg.from.lon
159
- });
160
- tdata.places.push({
161
- place_id: toPlaceId,
162
- // This string is not shown in the UI
163
- place_name: getPlaceName(leg.to, companies),
164
- place_lat: leg.to.lat,
165
- place_lon: leg.to.lon
166
- });
167
- streetEdgeId++;
168
- }
169
-
170
- if (isTransit(leg.mode)) {
171
- var _leg$legGeometry;
172
-
173
- // Flex routes sometimes have the same from and to IDs, but
174
- // these stops still need to be rendered separately!
175
- if (leg.from.stopId === leg.to.stopId) {
176
- leg.to.stopId = "".concat(leg.to.stopId, "_flexed_to");
177
- } // determine if we have valid inter-stop geometry
178
-
179
-
180
- var hasInterStopGeometry = !!leg.interStopGeometry;
181
- var hasLegGeometry = !!((_leg$legGeometry = leg.legGeometry) !== null && _leg$legGeometry !== void 0 && _leg$legGeometry.points);
182
- var hasIntermediateStopGeometry = hasInterStopGeometry && leg.intermediateStops && leg.interStopGeometry.length === leg.intermediateStops.length + 1; // create leg-specific pattern
183
-
184
- var ptnId = "ptn_".concat(patternId);
185
- var pattern = {
186
- pattern_id: ptnId,
187
- // This string is not shown in the UI
188
- pattern_name: "Pattern ".concat(patternId),
189
- route_id: leg.routeId,
190
- stops: []
191
- }; // add 'from' stop to stops dictionary and pattern object
192
-
193
- stops[leg.from.stopId] = {
194
- stop_id: leg.from.stopId,
195
- stop_name: leg.from.name,
196
- stop_lat: leg.from.lat,
197
- stop_lon: leg.from.lon
198
- };
199
- pattern.stops.push({
200
- stop_id: leg.from.stopId
201
- }); // add intermediate stops to stops dictionary and pattern object
202
- // If there is no intermediateStopGeometry, do not add the intermediate stops
203
- // as it will be straight lines instead of the nice legGeometry (but only if
204
- // the legGeometry exists).
205
-
206
- if (leg.intermediateStops && (hasIntermediateStopGeometry || !hasLegGeometry)) {
207
- leg.intermediateStops.forEach(function (stop, i) {
208
- stops[stop.stopId] = {
209
- stop_id: stop.stopId,
210
- stop_name: stop.name,
211
- stop_lat: stop.lat,
212
- stop_lon: stop.lon
213
- };
214
- pattern.stops.push({
215
- stop_id: stop.stopId,
216
- geometry: hasIntermediateStopGeometry && leg.interStopGeometry[i].points
217
- });
218
- });
219
- } // add 'to' stop to stops dictionary and pattern object
220
-
221
-
222
- stops[leg.to.stopId] = {
223
- stop_id: leg.to.stopId,
224
- stop_name: leg.to.name,
225
- stop_lat: leg.to.lat,
226
- stop_lon: leg.to.lon
227
- };
228
- pattern.stops.push({
229
- stop_id: leg.to.stopId,
230
- geometry: // Some legs don't have intermediateStopGeometry, but do have valid legGeometry
231
- (hasInterStopGeometry || hasLegGeometry) && (hasIntermediateStopGeometry ? leg.interStopGeometry[leg.interStopGeometry.length - 1].points : leg.legGeometry.points)
232
- }); // add route to the route dictionary
233
- // with a custom route label if specified.
234
-
235
- var routeLabel = typeof getRouteLabel === "function" ? getRouteLabel(leg) : leg.routeShortName;
236
- routes[leg.routeId] = {
237
- agency_id: leg.agencyId,
238
- route_id: leg.routeId,
239
- route_short_name: routeLabel || "",
240
- route_long_name: leg.routeLongName || "",
241
- route_type: leg.routeType,
242
- route_color: leg.routeColor
243
- }; // add the pattern to the tdata patterns array
244
-
245
- tdata.patterns.push(pattern); // add the pattern reference to the journey object
246
-
247
- journey.segments.push({
248
- arc: typeof disableFlexArc === "undefined" ? isFlex(leg) : !disableFlexArc,
249
- type: "TRANSIT",
250
- patterns: [{
251
- pattern_id: ptnId,
252
- from_stop_index: 0,
253
- to_stop_index: hasIntermediateStopGeometry ? leg.intermediateStops.length + 2 - 1 : 1
254
- }]
255
- });
256
- patternId++;
257
- }
258
- }); // add the routes and stops to the tdata arrays
259
-
260
- (_tdata$routes = tdata.routes).push.apply(_tdata$routes, _toConsumableArray(Object.values(routes)));
261
-
262
- (_tdata$stops = tdata.stops).push.apply(_tdata$stops, _toConsumableArray(Object.values(stops))); // add the journey to the tdata journeys array
263
-
264
-
265
- tdata.journeys.push(journey); // console.log('derived tdata', tdata);
266
-
267
- return tdata;
268
- }
269
47
  export function isBikeshareStation(place) {
270
48
  return place.place_id.lastIndexOf("bicycle_rent_station") !== -1;
271
49
  }
package/esm/map.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/map.ts"],"names":["getPlaceName","isAccessMode","isFlex","isTransit","toSentenceCase","coordsToString","getDetailText","latlngToString","logDeprecationWarning","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,SACEA,YADF,EAEEC,YAFF,EAGEC,MAHF,EAIEC,SAJF,EAKEC,cALF,QAMO,aANP;AAQA,SACEC,cADF,EAEEC,aAFF,EAGEC,cAHF,EAIEC,qBAJF,QAKO,cALP;AAOA,SAASH,cAAT,EAAyBC,aAAzB,EAAwCC,cAAxC;AAEA,OAAO,SAASE,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;AAED,OAAO,SAASC,cAAT,CAAwBC,GAAxB,EAA+C;AACpD,SAAQA,GAAG,IAAIA,GAAG,CAACC,KAAJ,CAAU,GAAV,EAAeC,GAAf,CAAmB,UAAAC,CAAC;AAAA,WAAI,CAACA,CAAL;AAAA,GAApB,CAAR,IAAwC,EAA/C;AACD;AAED,OAAO,SAASC,iBAAT,CAA2BC,MAA3B,EAGM;AACX,SAAO;AACLX,IAAAA,GAAG,EAAEW,MAAM,CAACX,GADP;AAELE,IAAAA,GAAG,EAAES,MAAM,CAACC;AAFP,GAAP;AAID;AAED,OAAO,SAASC,qBAAT,CACLC,QADK,EAGG;AAAA,MADRC,WACQ,uEADM,IACN;;AACR,MAAIA,WAAJ,EAAiB;AACftB,IAAAA,qBAAqB,CAAC,iDAAD,CAArB;AACD;;AAED,MAAIuB,WAAW,GACbF,QAAQ,CAACG,IAAT,KAAkB,MAAlB,IAA4BH,QAAQ,CAACG,IAAT,KAAkB,MAA9C,GACI5B,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K,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.bikeShareId}`;\n }\n } else if (leg.from.vertexType === \"VEHICLERENTAL\") {\n // OTP1 Scooter case\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 if (!fromPlaceId) {\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 // OTP2 scooter case\n // Need to check next leg since this is a \"to\" place \"\n if (leg.mode === \"SCOOTER\" || itin.legs?.[idx + 1].mode === \"SCOOTER\") {\n toPlaceId = `escooter_rent_station_${leg.to.bikeShareId}`;\n }\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 if (!toPlaceId) {\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"}
1
+ {"version":3,"sources":["../src/map.ts"],"names":["toSentenceCase","coordsToString","getDetailText","latlngToString","logDeprecationWarning","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","isBikeshareStation","place","place_id","lastIndexOf","isEScooterStation","isCarWalkTransition","isValidLat","Number","isFinite","isValidLng","isValidLatLng","arr","Array","isArray","length"],"mappings":"AACA,SAASA,cAAT,QA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AAC,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\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\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/map.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Company, Itinerary, LatLngArray, Leg, Location, TransitiveData, UserPosition } from "@opentripplanner/types";
1
+ import { LatLngArray, Location, UserPosition } from "@opentripplanner/types";
2
2
  import { coordsToString, getDetailText, latlngToString } from "./deprecated";
3
3
  export { coordsToString, getDetailText, latlngToString };
4
4
  export declare function currentPositionToLocation(currentPosition: UserPosition): Location;
@@ -9,15 +9,6 @@ export declare function constructLocation(latlng: {
9
9
  }): Location;
10
10
  export declare function formatStoredPlaceName(location: Location, withDetails?: boolean): string;
11
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
12
  declare type TransitivePlaceRaw = {
22
13
  place_id: string;
23
14
  };
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,EACL,OAAO,EACP,SAAS,EACT,WAAW,EACX,GAAG,EACH,QAAQ,EACR,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ringToCoords = stringToCoords;
8
8
  exports.constructLocation = constructLocation;
9
9
  exports.formatStoredPlaceName = formatStoredPlaceName;
10
10
  exports.matchLatLon = matchLatLon;
11
- exports.itineraryToTransitive = itineraryToTransitive;
12
11
  exports.isBikeshareStation = isBikeshareStation;
13
12
  exports.isEScooterStation = isEScooterStation;
14
13
  exports.isCarWalkTransition = isCarWalkTransition;
@@ -81,224 +80,6 @@ function matchLatLon(location1, location2) {
81
80
  if (!location1 || !location2) return location1 === location2;
82
81
  return location1.lat === location2.lat && location1.lon === location2.lon;
83
82
  }
84
- /**
85
- * Converts an OTP itinerary object to a transtive.js itinerary object.
86
- * @param {*} itin Required OTP itinerary (see @opentripplanner/core-utils/types#itineraryType) to convert.
87
- * @param {*} companies Optional list of companies, used for labeling vehicle rental locations.
88
- * @param {*} getRouteLabel Optional function that takes an itinerary leg (see @opentripplanner/core-utils/types#legType)
89
- * and returns a string representing the route label to display for that leg.
90
- * @returns An itinerary in the transitive.js format.
91
- */
92
-
93
-
94
- function itineraryToTransitive(itin, companies, getRouteLabel, disableFlexArc) {
95
- const tdata = {
96
- journeys: [],
97
- streetEdges: [],
98
- places: [],
99
- patterns: [],
100
- routes: [],
101
- stops: []
102
- };
103
- const routes = {};
104
- const stops = {};
105
- let streetEdgeId = 0;
106
- let patternId = 0;
107
- const journey = {
108
- journey_id: "itin",
109
- // This string is not shown in the UI
110
- journey_name: "Iterarary-derived Journey",
111
- segments: []
112
- }; // add 'from' and 'to' places to the tdata places array
113
-
114
- tdata.places.push({
115
- place_id: "from",
116
- place_lat: itin.legs[0].from.lat,
117
- place_lon: itin.legs[0].from.lon
118
- });
119
- tdata.places.push({
120
- place_id: "to",
121
- place_lat: itin.legs[itin.legs.length - 1].to.lat,
122
- place_lon: itin.legs[itin.legs.length - 1].to.lon
123
- });
124
- itin.legs.forEach((leg, idx) => {
125
- if ((0, _itinerary.isAccessMode)(leg.mode)) {
126
- let fromPlaceId;
127
-
128
- if (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.bikeShareId}`;
134
- }
135
- } else if (leg.from.vertexType === "VEHICLERENTAL") {
136
- // OTP1 Scooter case
137
- fromPlaceId = `escooter_rent_station_${leg.from.name}`;
138
- } else if (leg.mode === "CAR" && idx > 0 && itin.legs[idx - 1].mode === "WALK") {
139
- // create a special place ID for car legs preceded by walking legs
140
- fromPlaceId = `itin_car_${streetEdgeId}_from`;
141
- } else if (!fromPlaceId) {
142
- fromPlaceId = `itin_street_${streetEdgeId}_from`;
143
- }
144
-
145
- let toPlaceId;
146
-
147
- if (leg.to.bikeShareId) {
148
- var _itin$legs;
149
-
150
- toPlaceId = `bicycle_rent_station_${leg.to.bikeShareId}`; // OTP2 scooter case
151
- // Need to check next leg since this is a "to" place "
152
-
153
- if (leg.mode === "SCOOTER" || ((_itin$legs = itin.legs) === null || _itin$legs === void 0 ? void 0 : _itin$legs[idx + 1].mode) === "SCOOTER") {
154
- toPlaceId = `escooter_rent_station_${leg.to.bikeShareId}`;
155
- }
156
- } else if (leg.to.vertexType === "VEHICLERENTAL") {
157
- toPlaceId = `escooter_rent_station_${leg.to.name}`;
158
- } else if (leg.mode === "CAR" && idx < itin.legs.length - 1 && itin.legs[idx + 1].mode === "WALK") {
159
- // create a special place ID for car legs followed by walking legs
160
- toPlaceId = `itin_car_${streetEdgeId}_to`;
161
- } else if (!toPlaceId) {
162
- toPlaceId = `itin_street_${streetEdgeId}_to`;
163
- }
164
-
165
- const segment = {
166
- arc: false,
167
- type: leg.mode,
168
- streetEdges: [streetEdgeId],
169
- from: {
170
- type: "PLACE",
171
- place_id: fromPlaceId
172
- },
173
- to: {
174
- type: "PLACE",
175
- place_id: toPlaceId
176
- }
177
- }; // For TNC segments, draw using an arc
178
-
179
- if (leg.mode === "CAR" && leg.hailedCar) segment.arc = true;
180
- journey.segments.push(segment);
181
- tdata.streetEdges.push({
182
- edge_id: streetEdgeId,
183
- geometry: leg.legGeometry
184
- });
185
- tdata.places.push({
186
- place_id: fromPlaceId,
187
- // Do not label the from place in addition to the to place. Otherwise,
188
- // in some cases (bike rental station) the label for a single place will
189
- // appear twice on the rendered transitive view.
190
- // See https://github.com/conveyal/trimet-mod-otp/issues/152
191
- // place_name: leg.from.name,
192
- place_lat: leg.from.lat,
193
- place_lon: leg.from.lon
194
- });
195
- tdata.places.push({
196
- place_id: toPlaceId,
197
- // This string is not shown in the UI
198
- place_name: (0, _itinerary.getPlaceName)(leg.to, companies),
199
- place_lat: leg.to.lat,
200
- place_lon: leg.to.lon
201
- });
202
- streetEdgeId++;
203
- }
204
-
205
- if ((0, _itinerary.isTransit)(leg.mode)) {
206
- var _leg$legGeometry;
207
-
208
- // Flex routes sometimes have the same from and to IDs, but
209
- // these stops still need to be rendered separately!
210
- if (leg.from.stopId === leg.to.stopId) {
211
- leg.to.stopId = `${leg.to.stopId}_flexed_to`;
212
- } // determine if we have valid inter-stop geometry
213
-
214
-
215
- const hasInterStopGeometry = !!leg.interStopGeometry;
216
- const hasLegGeometry = !!((_leg$legGeometry = leg.legGeometry) !== null && _leg$legGeometry !== void 0 && _leg$legGeometry.points);
217
- const hasIntermediateStopGeometry = hasInterStopGeometry && leg.intermediateStops && leg.interStopGeometry.length === leg.intermediateStops.length + 1; // create leg-specific pattern
218
-
219
- const ptnId = `ptn_${patternId}`;
220
- const pattern = {
221
- pattern_id: ptnId,
222
- // This string is not shown in the UI
223
- pattern_name: `Pattern ${patternId}`,
224
- route_id: leg.routeId,
225
- stops: []
226
- }; // add 'from' stop to stops dictionary and pattern object
227
-
228
- stops[leg.from.stopId] = {
229
- stop_id: leg.from.stopId,
230
- stop_name: leg.from.name,
231
- stop_lat: leg.from.lat,
232
- stop_lon: leg.from.lon
233
- };
234
- pattern.stops.push({
235
- stop_id: leg.from.stopId
236
- }); // add intermediate stops to stops dictionary and pattern object
237
- // If there is no intermediateStopGeometry, do not add the intermediate stops
238
- // as it will be straight lines instead of the nice legGeometry (but only if
239
- // the legGeometry exists).
240
-
241
- if (leg.intermediateStops && (hasIntermediateStopGeometry || !hasLegGeometry)) {
242
- leg.intermediateStops.forEach((stop, i) => {
243
- stops[stop.stopId] = {
244
- stop_id: stop.stopId,
245
- stop_name: stop.name,
246
- stop_lat: stop.lat,
247
- stop_lon: stop.lon
248
- };
249
- pattern.stops.push({
250
- stop_id: stop.stopId,
251
- geometry: hasIntermediateStopGeometry && leg.interStopGeometry[i].points
252
- });
253
- });
254
- } // add 'to' stop to stops dictionary and pattern object
255
-
256
-
257
- stops[leg.to.stopId] = {
258
- stop_id: leg.to.stopId,
259
- stop_name: leg.to.name,
260
- stop_lat: leg.to.lat,
261
- stop_lon: leg.to.lon
262
- };
263
- pattern.stops.push({
264
- stop_id: leg.to.stopId,
265
- geometry: // Some legs don't have intermediateStopGeometry, but do have valid legGeometry
266
- (hasInterStopGeometry || hasLegGeometry) && (hasIntermediateStopGeometry ? leg.interStopGeometry[leg.interStopGeometry.length - 1].points : leg.legGeometry.points)
267
- }); // add route to the route dictionary
268
- // with a custom route label if specified.
269
-
270
- const routeLabel = typeof getRouteLabel === "function" ? getRouteLabel(leg) : leg.routeShortName;
271
- routes[leg.routeId] = {
272
- agency_id: leg.agencyId,
273
- route_id: leg.routeId,
274
- route_short_name: routeLabel || "",
275
- route_long_name: leg.routeLongName || "",
276
- route_type: leg.routeType,
277
- route_color: leg.routeColor
278
- }; // add the pattern to the tdata patterns array
279
-
280
- tdata.patterns.push(pattern); // add the pattern reference to the journey object
281
-
282
- journey.segments.push({
283
- arc: typeof disableFlexArc === "undefined" ? (0, _itinerary.isFlex)(leg) : !disableFlexArc,
284
- type: "TRANSIT",
285
- patterns: [{
286
- pattern_id: ptnId,
287
- from_stop_index: 0,
288
- to_stop_index: hasIntermediateStopGeometry ? leg.intermediateStops.length + 2 - 1 : 1
289
- }]
290
- });
291
- patternId++;
292
- }
293
- }); // add the routes and stops to the tdata arrays
294
-
295
- tdata.routes.push(...Object.values(routes));
296
- tdata.stops.push(...Object.values(stops)); // add the journey to the tdata journeys array
297
-
298
- tdata.journeys.push(journey); // console.log('derived tdata', tdata);
299
-
300
- return tdata;
301
- }
302
83
 
303
84
  function isBikeshareStation(place) {
304
85
  return place.place_id.lastIndexOf("bicycle_rent_station") !== -1;
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","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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AAEM,SAASC,iBAAT,CAA2BF,KAA3B,EAA+D;AACpE,SAAOA,KAAK,CAACzD,QAAN,CAAe0D,WAAf,CAA2B,uBAA3B,MAAwD,CAAC,CAAhE;AACD;;AAEM,SAASE,mBAAT,CAA6BH,KAA7B,EAAiE;AACtE,SAAOA,KAAK,CAACzD,QAAN,CAAe0D,WAAf,CAA2B,WAA3B,MAA4C,CAAC,CAApD;AACD;;AAEM,SAASG,UAAT,CAAoBvG,GAApB,EAA0C;AAC/C,SAAOwG,MAAM,CAACC,QAAP,CAAgBzG,GAAhB,KAAwBA,GAAG,IAAI,CAAC,EAAhC,IAAsCA,GAAG,IAAI,EAApD;AACD;;AAEM,SAAS0G,UAAT,CAAoB9F,GAApB,EAA0C;AAC/C,SAAO4F,MAAM,CAACC,QAAP,CAAgB7F,GAAhB,KAAwBA,GAAG,IAAI,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.bikeShareId}`;\n }\n } else if (leg.from.vertexType === \"VEHICLERENTAL\") {\n // OTP1 Scooter case\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 if (!fromPlaceId) {\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 // OTP2 scooter case\n // Need to check next leg since this is a \"to\" place \"\n if (leg.mode === \"SCOOTER\" || itin.legs?.[idx + 1].mode === \"SCOOTER\") {\n toPlaceId = `escooter_rent_station_${leg.to.bikeShareId}`;\n }\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 if (!toPlaceId) {\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"}
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","isBikeshareStation","place","place_id","lastIndexOf","isEScooterStation","isCarWalkTransition","isValidLat","Number","isFinite","isValidLng","isValidLatLng","arr","Array","isArray","length"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AAEA;;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,KAAJ,CAAU,GAAV,EAAeC,GAAf,CAAmBC,CAAC,IAAI,CAACA,CAAzB,CAAR,IAAwC,EAA/C;A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CAAC,CAApD;AACD;;AAEM,SAASG,UAAT,CAAoB7B,GAApB,EAA0C;AAC/C,SAAO8B,MAAM,CAACC,QAAP,CAAgB/B,GAAhB,KAAwBA,GAAG,IAAI,CAAC,EAAhC,IAAsCA,GAAG,IAAI,EAApD;AACD;;AAEM,SAASgC,UAAT,CAAoBpB,GAApB,EAA0C;AAC/C,SAAOkB,MAAM,CAACC,QAAP,CAAgBnB,GAAhB,KAAwBA,GAAG,IAAI,CAAC,GAAhC,IAAuCA,GAAG,IAAI,GAArD;AACD;;AAEM,SAASqB,aAAT,CAAuBC,GAAvB,EAAkD;AACvD,SACEC,KAAK,CAACC,OAAN,CAAcF,GAAd,KACAA,GAAG,CAACG,MAAJ,KAAe,CADf,IAEAR,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\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\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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentripplanner/core-utils",
3
- "version": "5.0.2",
3
+ "version": "6.0.1-alpha.1",
4
4
  "description": "Core functionality that is shared among numerous UI components",
5
5
  "engines": {
6
6
  "node": ">=13"
@@ -14,6 +14,7 @@
14
14
  "dependencies": {
15
15
  "@mapbox/polyline": "^1.1.0",
16
16
  "@opentripplanner/geocoder": "^1.2.2",
17
+ "@opentripplanner/types": "^2.0.0",
17
18
  "@styled-icons/foundation": "^10.34.0",
18
19
  "@turf/along": "^6.0.1",
19
20
  "bowser": "^2.7.0",