Skip to content

Commit

Permalink
only add one via point marker per each marker, no matter how many tim…
Browse files Browse the repository at this point in the history
…es it matches
  • Loading branch information
tkalvas committed Dec 10, 2024
1 parent deb1d53 commit dc5f57b
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions app/util/legUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,31 @@ function syntheticEndpoint(originalEndpoint, place) {
};
}

/**
* Adds intermediate: true to legs if their start point should have a via point
* marker, possibly splitting legs in case the via point belongs in the middle.
*
* @param originalLegs Leg objects from graphql query
* @param viaPlaces Location objects (otpToLocation) from query parameter
* @returns {*[]}
*/
export function splitLegsAtViaPoints(originalLegs, viaPlaces) {
const splitLegs = [];
// Once a via place is matched, it is used and will not match again.
function includesAndRemove(array, id) {
const index = array.indexOf(id);
if (index >= 0) {
array.splice(index, 1);
return true;
}
return false;
}
const viaPoints = viaPlaces.map(p => p.gtfsId);
const isViaPointMatch = stop =>
stop &&
(viaPoints.includes(stop.gtfsId) ||
(stop.parentStation && viaPoints.includes(stop.parentStation.gtfsId)));
(includesAndRemove(viaPoints, stop.gtfsId) ||
(stop.parentStation &&
includesAndRemove(viaPoints, stop.parentStation.gtfsId)));
let isFirstTransitLeg = true;
let nextLegStartsWithIntermediate = false;
originalLegs.forEach(originalLeg => {
Expand All @@ -212,6 +230,7 @@ export function splitLegsAtViaPoints(originalLegs, viaPlaces) {
(leg.transitLeg && isFirstTransitLeg && isViaPointMatch(leg.from.stop))
) {
leg.intermediatePlace = true;
nextLegStartsWithIntermediate = false;
}
if (leg.transitLeg) {
isFirstTransitLeg = false;
Expand Down

0 comments on commit dc5f57b

Please sign in to comment.