Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions example-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,18 @@ routingTypes:

# Itinerary options
itinerary:
# Provides an array of valid mode combinations that returned itineraries will be filtered against
# If left blank, all itineraries deemed valid by OTP will be returned
validModeCombinations: [
['WALK'],
['WALK', 'PERSONAL'],
['WALK', 'TRANSIT', 'SHARED'],
['WALK', 'SHARED'],
['WALK', 'TRANSIT'],
['WALK', 'TRANSIT', 'PERSONAL'],
['WALK', 'TRANSIT', 'CAR'],
['CAR']
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

# Show fares for each transit leg (false if omitted).
# (Requires using LineItinerary.)
showRouteFares: false
Expand Down
17 changes: 17 additions & 0 deletions lib/actions/apiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
{}

const strictModes = !!config?.itinerary?.strictItineraryFiltering
const validModeCombinations = config?.itinerary?.validModeCombinations

// Filter mode definitions based on active mode keys
const activeModeButtons = config.modes?.modeButtons.filter((mb) =>
Expand Down Expand Up @@ -1114,6 +1115,22 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
activeModeStrings.includes(SIMPLIFICATIONS[leg.mode])
)
)
// If "acceptableValidModeCombos" is provided, filter out itineraries that do not match our list of valid mode combinations
// (e.g. "WALK" + "DRIVE")
// TODO: Remove this once we switch to planConnection API
if (validModeCombinations?.length > 0) {
filteredItineraries = filteredItineraries.filter((itin) => {
const modeCombo = Array.from(
new Set(itin.legs.map((leg) => SIMPLIFICATIONS[leg.mode]))
)
return validModeCombinations.find(
(vc) =>
modeCombo.length === vc.length &&
vc.every((m) => modeCombo.includes(m))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wasn't sure but indeed this is the most efficient way to do this!

)
})
}

// ... Otherwise return all itineraries.
}

Expand Down
Loading