Skip to content

Commit

Permalink
motis2: Don't rely on START and END pseudo place names
Browse files Browse the repository at this point in the history
As the START and END names are considered implementation
details in MOTIS and reflects the internal search direction
instead always use the entered search term for departure of
first leg and arrival of final leg, when these are non-transit
legs.

See: motis-project/motis#703
  • Loading branch information
mlundblad committed Jan 19, 2025
1 parent 0a64602 commit a2bca74
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/transitplugins/motis2.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ export class Motis2 {
departureTimezoneOffset === arrivalTimezoneOffset ?
departureTimezoneOffset * 1000 : null;
const legs =
itinerary.legs.map(leg =>
this._parseLeg(leg, startPlace, destinationPlace,
itinerary.legs.map((leg, index) =>
this._parseLeg(leg, index === 0,
index === itinerary.legs.length - 1,
startPlace, destinationPlace,
commonTimezoneOffset));

return new Itinerary({
Expand All @@ -188,7 +190,8 @@ export class Motis2 {
});
}

_parseLeg(leg, startPlace, destinationPlace, commonTimezoneOffset) {
_parseLeg(leg, isFirst, isLast, startPlace, destinationPlace,
commonTimezoneOffset) {
const isTransit = leg.mode !== 'WALK';
const distance =
leg.distance ?? (!isTransit ?
Expand All @@ -204,8 +207,8 @@ export class Motis2 {
commonTimezoneOffset ??
this._getTimezoneOffset(arrival, this._getTimezone(leg.to.lat,
leg.to.lon));
const from = leg.from.name === 'START' ? startPlace.name : leg.from.name;
const to = leg.to.name === 'END' ? destinationPlace.name : leg.to.name;
const from = isFirst && !isTransit ? startPlace.name : leg.from.name;
const to = isLast && !isTransit ? destinationPlace.name : leg.to.name;

const polyline =
leg?.legGeometry?.points ?
Expand Down

0 comments on commit a2bca74

Please sign in to comment.