@opentripplanner/core-utils 5.0.1 → 6.0.0

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/src/map.ts CHANGED
@@ -1,19 +1,5 @@
1
- import {
2
- Company,
3
- Itinerary,
4
- LatLngArray,
5
- Leg,
6
- Location,
7
- TransitiveData,
8
- UserPosition
9
- } from "@opentripplanner/types";
10
- import {
11
- getPlaceName,
12
- isAccessMode,
13
- isFlex,
14
- isTransit,
15
- toSentenceCase
16
- } from "./itinerary";
1
+ import { LatLngArray, Location, UserPosition } from "@opentripplanner/types";
2
+ import { toSentenceCase } from "./itinerary";
17
3
 
18
4
  import {
19
5
  coordsToString,
@@ -78,255 +64,6 @@ export function matchLatLon(location1: Location, location2: Location): boolean {
78
64
  return location1.lat === location2.lat && location1.lon === location2.lon;
79
65
  }
80
66
 
81
- /**
82
- * Converts an OTP itinerary object to a transtive.js itinerary object.
83
- * @param {*} itin Required OTP itinerary (see @opentripplanner/core-utils/types#itineraryType) to convert.
84
- * @param {*} companies Optional list of companies, used for labeling vehicle rental locations.
85
- * @param {*} getRouteLabel Optional function that takes an itinerary leg (see @opentripplanner/core-utils/types#legType)
86
- * and returns a string representing the route label to display for that leg.
87
- * @returns An itinerary in the transitive.js format.
88
- */
89
- export function itineraryToTransitive(
90
- itin: Itinerary,
91
- companies: Company[],
92
- getRouteLabel: (leg: Leg) => string,
93
- disableFlexArc: boolean
94
- ): TransitiveData {
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
-
108
- const journey = {
109
- journey_id: "itin",
110
- // This string is not shown in the UI
111
- journey_name: "Iterarary-derived Journey",
112
- segments: []
113
- };
114
-
115
- // add 'from' and 'to' places to the tdata places array
116
- tdata.places.push({
117
- place_id: "from",
118
- place_lat: itin.legs[0].from.lat,
119
- place_lon: itin.legs[0].from.lon
120
- });
121
- tdata.places.push({
122
- place_id: "to",
123
- place_lat: itin.legs[itin.legs.length - 1].to.lat,
124
- place_lon: itin.legs[itin.legs.length - 1].to.lon
125
- });
126
-
127
- itin.legs.forEach((leg, idx) => {
128
- if (isAccessMode(leg.mode)) {
129
- let fromPlaceId: string;
130
- if (leg.from.bikeShareId) {
131
- fromPlaceId = `bicycle_rent_station_${leg.from.bikeShareId}`;
132
- if (
133
- // OTP2 Scooter case
134
- leg.mode === "SCOOTER"
135
- ) {
136
- fromPlaceId = `escooter_rent_station_${leg.from.bikeShareId}`;
137
- }
138
- } else if (leg.from.vertexType === "VEHICLERENTAL") {
139
- // OTP1 Scooter case
140
- fromPlaceId = `escooter_rent_station_${leg.from.name}`;
141
- } else if (
142
- leg.mode === "CAR" &&
143
- idx > 0 &&
144
- itin.legs[idx - 1].mode === "WALK"
145
- ) {
146
- // create a special place ID for car legs preceded by walking legs
147
- fromPlaceId = `itin_car_${streetEdgeId}_from`;
148
- } else if (!fromPlaceId) {
149
- fromPlaceId = `itin_street_${streetEdgeId}_from`;
150
- }
151
-
152
- let toPlaceId;
153
- if (leg.to.bikeShareId) {
154
- toPlaceId = `bicycle_rent_station_${leg.to.bikeShareId}`;
155
- // OTP2 scooter case
156
- // Need to check next leg since this is a "to" place "
157
- if (leg.mode === "SCOOTER" || itin.legs?.[idx + 1].mode === "SCOOTER") {
158
- toPlaceId = `escooter_rent_station_${leg.to.bikeShareId}`;
159
- }
160
- } else if (leg.to.vertexType === "VEHICLERENTAL") {
161
- toPlaceId = `escooter_rent_station_${leg.to.name}`;
162
- } else if (
163
- leg.mode === "CAR" &&
164
- idx < itin.legs.length - 1 &&
165
- itin.legs[idx + 1].mode === "WALK"
166
- ) {
167
- // create a special place ID for car legs followed by walking legs
168
- toPlaceId = `itin_car_${streetEdgeId}_to`;
169
- } else if (!toPlaceId) {
170
- toPlaceId = `itin_street_${streetEdgeId}_to`;
171
- }
172
-
173
- const segment = {
174
- arc: false,
175
- type: leg.mode,
176
- streetEdges: [streetEdgeId],
177
- from: { type: "PLACE", place_id: fromPlaceId },
178
- to: { type: "PLACE", place_id: toPlaceId }
179
- };
180
- // For TNC segments, draw using an arc
181
- if (leg.mode === "CAR" && leg.hailedCar) segment.arc = true;
182
- journey.segments.push(segment);
183
-
184
- tdata.streetEdges.push({
185
- edge_id: streetEdgeId,
186
- geometry: leg.legGeometry
187
- });
188
- tdata.places.push({
189
- place_id: fromPlaceId,
190
- // Do not label the from place in addition to the to place. Otherwise,
191
- // in some cases (bike rental station) the label for a single place will
192
- // appear twice on the rendered transitive view.
193
- // See https://github.com/conveyal/trimet-mod-otp/issues/152
194
- // place_name: leg.from.name,
195
- place_lat: leg.from.lat,
196
- place_lon: leg.from.lon
197
- });
198
- tdata.places.push({
199
- place_id: toPlaceId,
200
- // This string is not shown in the UI
201
- place_name: getPlaceName(leg.to, companies),
202
- place_lat: leg.to.lat,
203
- place_lon: leg.to.lon
204
- });
205
- streetEdgeId++;
206
- }
207
-
208
- if (isTransit(leg.mode)) {
209
- // Flex routes sometimes have the same from and to IDs, but
210
- // these stops still need to be rendered separately!
211
- if (leg.from.stopId === leg.to.stopId) {
212
- leg.to.stopId = `${leg.to.stopId}_flexed_to`;
213
- }
214
- // determine if we have valid inter-stop geometry
215
- const hasInterStopGeometry = !!leg.interStopGeometry;
216
- const hasLegGeometry = !!leg.legGeometry?.points;
217
- const hasIntermediateStopGeometry =
218
- hasInterStopGeometry &&
219
- leg.intermediateStops &&
220
- leg.interStopGeometry.length === leg.intermediateStops.length + 1;
221
-
222
- // create leg-specific pattern
223
- const ptnId = `ptn_${patternId}`;
224
- const pattern = {
225
- pattern_id: ptnId,
226
- // This string is not shown in the UI
227
- pattern_name: `Pattern ${patternId}`,
228
- route_id: leg.routeId,
229
- stops: []
230
- };
231
-
232
- // add 'from' stop to stops dictionary and pattern object
233
- stops[leg.from.stopId] = {
234
- stop_id: leg.from.stopId,
235
- stop_name: leg.from.name,
236
- stop_lat: leg.from.lat,
237
- stop_lon: leg.from.lon
238
- };
239
- pattern.stops.push({ stop_id: leg.from.stopId });
240
-
241
- // add intermediate stops to stops dictionary and pattern object
242
- // If there is no intermediateStopGeometry, do not add the intermediate stops
243
- // as it will be straight lines instead of the nice legGeometry (but only if
244
- // the legGeometry exists).
245
- if (
246
- leg.intermediateStops &&
247
- (hasIntermediateStopGeometry || !hasLegGeometry)
248
- ) {
249
- leg.intermediateStops.forEach((stop, i) => {
250
- stops[stop.stopId] = {
251
- stop_id: stop.stopId,
252
- stop_name: stop.name,
253
- stop_lat: stop.lat,
254
- stop_lon: stop.lon
255
- };
256
- pattern.stops.push({
257
- stop_id: stop.stopId,
258
- geometry:
259
- hasIntermediateStopGeometry && leg.interStopGeometry[i].points
260
- });
261
- });
262
- }
263
-
264
- // add 'to' stop to stops dictionary and pattern object
265
- stops[leg.to.stopId] = {
266
- stop_id: leg.to.stopId,
267
- stop_name: leg.to.name,
268
- stop_lat: leg.to.lat,
269
- stop_lon: leg.to.lon
270
- };
271
- pattern.stops.push({
272
- stop_id: leg.to.stopId,
273
- geometry:
274
- // Some legs don't have intermediateStopGeometry, but do have valid legGeometry
275
- (hasInterStopGeometry || hasLegGeometry) &&
276
- (hasIntermediateStopGeometry
277
- ? leg.interStopGeometry[leg.interStopGeometry.length - 1].points
278
- : leg.legGeometry.points)
279
- });
280
-
281
- // add route to the route dictionary
282
- // with a custom route label if specified.
283
- const routeLabel =
284
- typeof getRouteLabel === "function"
285
- ? getRouteLabel(leg)
286
- : leg.routeShortName;
287
- routes[leg.routeId] = {
288
- agency_id: leg.agencyId,
289
- route_id: leg.routeId,
290
- route_short_name: routeLabel || "",
291
- route_long_name: leg.routeLongName || "",
292
- route_type: leg.routeType,
293
- route_color: leg.routeColor
294
- };
295
-
296
- // add the pattern to the tdata patterns array
297
- tdata.patterns.push(pattern);
298
-
299
- // add the pattern reference to the journey object
300
- journey.segments.push({
301
- arc:
302
- typeof disableFlexArc === "undefined" ? isFlex(leg) : !disableFlexArc,
303
- type: "TRANSIT",
304
- patterns: [
305
- {
306
- pattern_id: ptnId,
307
- from_stop_index: 0,
308
- to_stop_index: hasIntermediateStopGeometry
309
- ? leg.intermediateStops.length + 2 - 1
310
- : 1
311
- }
312
- ]
313
- });
314
-
315
- patternId++;
316
- }
317
- });
318
-
319
- // add the routes and stops to the tdata arrays
320
- tdata.routes.push(...Object.values(routes));
321
- tdata.stops.push(...Object.values(stops));
322
-
323
- // add the journey to the tdata journeys array
324
- tdata.journeys.push(journey);
325
-
326
- // console.log('derived tdata', tdata);
327
- return tdata;
328
- }
329
-
330
67
  type TransitivePlaceRaw = {
331
68
  place_id: string;
332
69
  };
@@ -394,8 +394,8 @@ const queryParams = [
394
394
  name: "walkReluctance",
395
395
  routingTypes: ["ITINERARY", "PROFILE"],
396
396
  selector: "SLIDER",
397
- low: 0.5,
398
- high: 20,
397
+ low: 1,
398
+ high: 10,
399
399
  step: 0.5,
400
400
  label: "walk reluctance",
401
401
  labelLow: "More Walking",
@@ -227,8 +227,8 @@
227
227
  "affectsGlobalScope": false
228
228
  },
229
229
  "./src/map.ts": {
230
- "version": "a0e805c7d0db4a9a52d6b2135e414cb146186f16d6da866b8fb0a527cedd573f",
231
- "signature": "bfd604d32f4b9db8bfec69a5a12f13afc760d5ad4010667b01c391d69d1a30e6",
230
+ "version": "56827235c32de3b17b3fe76e381b6780764f101f06bcaac7e6ab9dcc3ab2445e",
231
+ "signature": "043843512a3bc2d7d5404aab10e63317627a35d3755665eb8631b3998e1517dd",
232
232
  "affectsGlobalScope": false
233
233
  },
234
234
  "./src/route.ts": {
@@ -311,16 +311,16 @@
311
311
  "signature": "117ffeecf6c55e25b6446f449ad079029b5e7317399b0a693858faaaea5ca73e",
312
312
  "affectsGlobalScope": false
313
313
  },
314
+ "../../node_modules/@types/estree/index.d.ts": {
315
+ "version": "7d7c8ef7d48a035142c07dae60545ecc0e4af4c337742760cb09726f2f8e31db",
316
+ "signature": "7d7c8ef7d48a035142c07dae60545ecc0e4af4c337742760cb09726f2f8e31db",
317
+ "affectsGlobalScope": false
318
+ },
314
319
  "../../node_modules/@types/flat/index.d.ts": {
315
320
  "version": "d9890ea8f1da57be3c2e2d3627b787cd4b4a463fd1747c823a0de24b240c8fe5",
316
321
  "signature": "d9890ea8f1da57be3c2e2d3627b787cd4b4a463fd1747c823a0de24b240c8fe5",
317
322
  "affectsGlobalScope": false
318
323
  },
319
- "../../node_modules/@types/geojson/index.d.ts": {
320
- "version": "8c2e6e491e1a08855b8bf70820184ff66ae0d43f7cf0311fc680e6d860af211c",
321
- "signature": "8c2e6e491e1a08855b8bf70820184ff66ae0d43f7cf0311fc680e6d860af211c",
322
- "affectsGlobalScope": false
323
- },
324
324
  "../../node_modules/@types/node/assert/strict.d.ts": {
325
325
  "version": "c7bdc99177a2a94d25fb13722adaaf5b3291bf70b4d1b27584ba189dd3889ba3",
326
326
  "signature": "c7bdc99177a2a94d25fb13722adaaf5b3291bf70b4d1b27584ba189dd3889ba3",
@@ -581,6 +581,16 @@
581
581
  "signature": "30368d3789ec56ef3006c5f2115bd00faa21471aed6cbe6fec54a5683e5497ed",
582
582
  "affectsGlobalScope": false
583
583
  },
584
+ "../../node_modules/@types/fs-extra/index.d.ts": {
585
+ "version": "6435575b4feae200831d37df9f871de6e695c64d3148611fe1b4d714d648ea24",
586
+ "signature": "6435575b4feae200831d37df9f871de6e695c64d3148611fe1b4d714d648ea24",
587
+ "affectsGlobalScope": false
588
+ },
589
+ "../../node_modules/@types/geojson/index.d.ts": {
590
+ "version": "8c2e6e491e1a08855b8bf70820184ff66ae0d43f7cf0311fc680e6d860af211c",
591
+ "signature": "8c2e6e491e1a08855b8bf70820184ff66ae0d43f7cf0311fc680e6d860af211c",
592
+ "affectsGlobalScope": false
593
+ },
584
594
  "../../node_modules/@types/minimatch/index.d.ts": {
585
595
  "version": "95c22bc19835e28e2e524a4bb8898eb5f2107b640d7279a6d3aade261916bbf2",
586
596
  "signature": "95c22bc19835e28e2e524a4bb8898eb5f2107b640d7279a6d3aade261916bbf2",
@@ -1146,6 +1156,11 @@
1146
1156
  "signature": "3a1e165b22a1cb8df82c44c9a09502fd2b33f160cd277de2cd3a055d8e5c6b27",
1147
1157
  "affectsGlobalScope": false
1148
1158
  },
1159
+ "../../node_modules/@types/json-stable-stringify/index.d.ts": {
1160
+ "version": "626520302b2c8880e9eaa3a6a12022cc8b577a32e4d903aef85e3dd275063da4",
1161
+ "signature": "626520302b2c8880e9eaa3a6a12022cc8b577a32e4d903aef85e3dd275063da4",
1162
+ "affectsGlobalScope": false
1163
+ },
1149
1164
  "../../node_modules/@types/json5/index.d.ts": {
1150
1165
  "version": "96d14f21b7652903852eef49379d04dbda28c16ed36468f8c9fa08f7c14c9538",
1151
1166
  "signature": "96d14f21b7652903852eef49379d04dbda28c16ed36468f8c9fa08f7c14c9538",
@@ -1466,10 +1481,20 @@
1466
1481
  "../../node_modules/date-fns-tz/typings.d.ts",
1467
1482
  "../../node_modules/date-fns/typings.d.ts"
1468
1483
  ],
1484
+ "../../node_modules/@types/estree/index.d.ts": [
1485
+ "../../node_modules/date-fns-tz/typings.d.ts",
1486
+ "../../node_modules/date-fns/typings.d.ts"
1487
+ ],
1469
1488
  "../../node_modules/@types/flat/index.d.ts": [
1470
1489
  "../../node_modules/date-fns-tz/typings.d.ts",
1471
1490
  "../../node_modules/date-fns/typings.d.ts"
1472
1491
  ],
1492
+ "../../node_modules/@types/fs-extra/index.d.ts": [
1493
+ "../../node_modules/@types/node/fs.d.ts",
1494
+ "../../node_modules/@types/node/index.d.ts",
1495
+ "../../node_modules/date-fns-tz/typings.d.ts",
1496
+ "../../node_modules/date-fns/typings.d.ts"
1497
+ ],
1473
1498
  "../../node_modules/@types/geojson/index.d.ts": [
1474
1499
  "../../node_modules/date-fns-tz/typings.d.ts",
1475
1500
  "../../node_modules/date-fns/typings.d.ts"
@@ -1721,6 +1746,10 @@
1721
1746
  "../../node_modules/date-fns-tz/typings.d.ts",
1722
1747
  "../../node_modules/date-fns/typings.d.ts"
1723
1748
  ],
1749
+ "../../node_modules/@types/json-stable-stringify/index.d.ts": [
1750
+ "../../node_modules/date-fns-tz/typings.d.ts",
1751
+ "../../node_modules/date-fns/typings.d.ts"
1752
+ ],
1724
1753
  "../../node_modules/@types/json5/index.d.ts": [
1725
1754
  "../../node_modules/date-fns-tz/typings.d.ts",
1726
1755
  "../../node_modules/date-fns/typings.d.ts"
@@ -3101,10 +3130,20 @@
3101
3130
  "../../node_modules/date-fns-tz/typings.d.ts",
3102
3131
  "../../node_modules/date-fns/typings.d.ts"
3103
3132
  ],
3133
+ "../../node_modules/@types/estree/index.d.ts": [
3134
+ "../../node_modules/date-fns-tz/typings.d.ts",
3135
+ "../../node_modules/date-fns/typings.d.ts"
3136
+ ],
3104
3137
  "../../node_modules/@types/flat/index.d.ts": [
3105
3138
  "../../node_modules/date-fns-tz/typings.d.ts",
3106
3139
  "../../node_modules/date-fns/typings.d.ts"
3107
3140
  ],
3141
+ "../../node_modules/@types/fs-extra/index.d.ts": [
3142
+ "../../node_modules/@types/node/fs.d.ts",
3143
+ "../../node_modules/@types/node/index.d.ts",
3144
+ "../../node_modules/date-fns-tz/typings.d.ts",
3145
+ "../../node_modules/date-fns/typings.d.ts"
3146
+ ],
3108
3147
  "../../node_modules/@types/geojson/index.d.ts": [
3109
3148
  "../../node_modules/date-fns-tz/typings.d.ts",
3110
3149
  "../../node_modules/date-fns/typings.d.ts"
@@ -3356,6 +3395,10 @@
3356
3395
  "../../node_modules/date-fns-tz/typings.d.ts",
3357
3396
  "../../node_modules/date-fns/typings.d.ts"
3358
3397
  ],
3398
+ "../../node_modules/@types/json-stable-stringify/index.d.ts": [
3399
+ "../../node_modules/date-fns-tz/typings.d.ts",
3400
+ "../../node_modules/date-fns/typings.d.ts"
3401
+ ],
3359
3402
  "../../node_modules/@types/json5/index.d.ts": [
3360
3403
  "../../node_modules/date-fns-tz/typings.d.ts",
3361
3404
  "../../node_modules/date-fns/typings.d.ts"
@@ -4654,7 +4697,9 @@
4654
4697
  "../../node_modules/@types/color-convert/route.d.ts",
4655
4698
  "../../node_modules/@types/color-name/index.d.ts",
4656
4699
  "../../node_modules/@types/cookie/index.d.ts",
4700
+ "../../node_modules/@types/estree/index.d.ts",
4657
4701
  "../../node_modules/@types/flat/index.d.ts",
4702
+ "../../node_modules/@types/fs-extra/index.d.ts",
4658
4703
  "../../node_modules/@types/geojson/index.d.ts",
4659
4704
  "../../node_modules/@types/glob/index.d.ts",
4660
4705
  "../../node_modules/@types/graceful-fs/index.d.ts",
@@ -4694,6 +4739,7 @@
4694
4739
  "../../node_modules/@types/jest/node_modules/pretty-format/build/types.d.ts",
4695
4740
  "../../node_modules/@types/js-levenshtein/index.d.ts",
4696
4741
  "../../node_modules/@types/json-schema/index.d.ts",
4742
+ "../../node_modules/@types/json-stable-stringify/index.d.ts",
4697
4743
  "../../node_modules/@types/json5/index.d.ts",
4698
4744
  "../../node_modules/@types/mdast/index.d.ts",
4699
4745
  "../../node_modules/@types/minimatch/index.d.ts",