@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 +1 -223
- package/esm/map.js.map +1 -1
- package/lib/map.d.ts +1 -10
- package/lib/map.d.ts.map +1 -1
- package/lib/map.js +0 -219
- package/lib/map.js.map +1 -1
- package/package.json +2 -1
- package/src/map.ts +2 -265
- package/tsconfig.tsbuildinfo +154 -44
package/src/map.ts
CHANGED
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
};
|