Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

via point routing mvp #5191

Merged
merged 6 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 28 additions & 2 deletions app/component/itinerary/Itinerary.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import RouteNumberContainer from '../RouteNumberContainer';
import { getActiveLegAlertSeverityLevel } from '../../util/alertUtils';
import {
getLegMode,
splitLegsAtViaPoints,
compressLegs,
getLegBadgeProps,
isCallAgencyPickupType,
Expand Down Expand Up @@ -287,7 +288,8 @@ const Itinerary = (
const mobile = bp => !(bp === 'large');
const legs = [];
let noTransitLegs = true;
const compressedLegs = compressLegs(itinerary.legs).map(leg => ({
const splitLegs = splitLegsAtViaPoints(itinerary.legs, intermediatePlaces);
const compressedLegs = compressLegs(splitLegs).map(leg => ({
...leg,
}));
let intermediateSlack = 0;
Expand Down Expand Up @@ -389,9 +391,14 @@ const Itinerary = (
renderBar = false;
addition += legLength; // carry over the length of the leg to the next
}
// There are two places which inject ViaLegs in this logic, but we certainly
// don't want to add it twice in the same place with the same key, so we
// record whether we added it here at the first place.
let viaAdded = false;
if (leg.intermediatePlace) {
onlyIconLegs += 1;
legs.push(<ViaLeg key={`via_${leg.mode}_${startMs}`} />);
viaAdded = true;
}
if (isLegOnFoot(leg) && renderBar) {
const walkingTime = Math.floor(leg.duration / 60);
Expand Down Expand Up @@ -555,7 +562,8 @@ const Itinerary = (
if (
previousLeg &&
!previousLeg.intermediatePlace &&
connectsFromViaPoint(leg, intermediatePlaces)
connectsFromViaPoint(leg, intermediatePlaces) &&
!viaAdded
) {
legs.push(<ViaLeg key={`via_${leg.mode}_${startMs}`} />);
}
Expand Down Expand Up @@ -970,13 +978,15 @@ Itinerary.propTypes = {
intermediatePlaces: PropTypes.arrayOf(locationShape),
hideSelectionIndicator: PropTypes.bool,
lowestCo2value: PropTypes.number,
viaPoints: PropTypes.arrayOf(locationShape),
};

Itinerary.defaultProps = {
passive: false,
intermediatePlaces: [],
hideSelectionIndicator: true,
lowestCo2value: 0,
viaPoints: [],
};

Itinerary.contextTypes = {
Expand Down Expand Up @@ -1021,6 +1031,16 @@ const containerComponent = createFragmentContainer(ItineraryWithBreakpoint, {
intermediatePlaces {
stop {
zoneId
gtfsId
parentStation {
gtfsId
}
}
arrival {
scheduledTime
estimated {
time
}
}
}
route {
Expand Down Expand Up @@ -1056,6 +1076,9 @@ const containerComponent = createFragmentContainer(ItineraryWithBreakpoint, {
name
stop {
gtfsId
parentStation {
gtfsId
}
zoneId
alerts {
alertSeverityLevel
Expand All @@ -1075,6 +1098,9 @@ const containerComponent = createFragmentContainer(ItineraryWithBreakpoint, {
to {
stop {
gtfsId
parentStation {
gtfsId
}
zoneId
alerts {
alertSeverityLevel
Expand Down
9 changes: 9 additions & 0 deletions app/component/itinerary/ItineraryDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,9 @@ const withRelay = createFragmentContainer(
}
}
}
parentStation {
gtfsId
}
}
}
to {
Expand Down Expand Up @@ -553,6 +556,9 @@ const withRelay = createFragmentContainer(
}
}
}
parentStation {
gtfsId
}
}
vehicleParking {
vehicleParkingId
Expand All @@ -574,6 +580,9 @@ const withRelay = createFragmentContainer(
code
platformCode
zoneId
parentStation {
gtfsId
}
}
}
realTime
Expand Down
1 change: 1 addition & 0 deletions app/component/itinerary/ItineraryPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ export default function ItineraryPage(props, context) {
params.to,
query.time,
query.arriveBy,
query.intermediatePlaces,
]);

useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions app/component/itinerary/OriginDestinationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class OriginDestinationBar extends React.Component {
let action;
if (id === parseInt(id, 10)) {
// id = via point index
// item == { ...gtfsId: 'HSL:1000004' }
action = 'EditJourneyViaPoint';
const points = [...this.props.viaPoints];
points[id] = { ...item };
Expand Down
2 changes: 2 additions & 0 deletions app/component/itinerary/PlanConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const planConnection = graphql`
$first: Int
$before: String
$last: Int
$via: [PlanViaLocationInput!]
) {
plan: planConnection(
dateTime: $datetime
Expand All @@ -28,6 +29,7 @@ const planConnection = graphql`
origin: $fromPlace
destination: $toPlace
modes: $modes
via: $via
preferences: {
accessibility: { wheelchair: { enabled: $wheelchair } }
street: {
Expand Down
14 changes: 9 additions & 5 deletions app/component/map/tile-layer/TileLayerContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class TileLayerContainer extends GridLayer {
tileSize: PropTypes.number.isRequired,
zoomOffset: PropTypes.number.isRequired,
locationPopup: PropTypes.string, // all, none, reversegeocoding, origindestination
allowViaPoint: PropTypes.bool, // temporary, until OTP2 handles arbitrary via points
onSelectLocation: PropTypes.func,
mergeStops: PropTypes.bool,
mapLayers: mapLayerShape.isRequired,
Expand All @@ -70,6 +71,7 @@ class TileLayerContainer extends GridLayer {
static defaultProps = {
onSelectLocation: undefined,
locationPopup: undefined,
allowViaPoint: false,
objectsToHide: { vehicleRentalStations: [] },
hilightedStops: undefined,
stopsToShow: undefined,
Expand Down Expand Up @@ -353,6 +355,10 @@ class TileLayerContainer extends GridLayer {
let contents;
const breakpoint = getClientBreakpoint();
let showPopup = true;
const locationPopup =
this.props.allowViaPoint || this.props.locationPopup !== 'all'
? this.props.locationPopup
: 'origindestination';

if (typeof this.state.selectableTargets !== 'undefined') {
if (this.state.selectableTargets.length === 1) {
Expand Down Expand Up @@ -434,24 +440,22 @@ class TileLayerContainer extends GridLayer {
) {
showPopup = false;
}
popup = this.props.locationPopup !== 'none' && (
popup = locationPopup !== 'none' && (
<Popup
key={this.state.coords.toString()}
{...this.PopupOptions}
maxHeight={220}
maxWidth="auto"
position={this.state.coords}
className={`${this.PopupOptions.className} ${
this.props.locationPopup === 'all'
? 'single-popup'
: 'narrow-popup'
locationPopup === 'all' ? 'single-popup' : 'narrow-popup'
}`}
>
<LocationPopup
lat={this.state.coords.lat}
lon={this.state.coords.lng}
onSelectLocation={this.props.onSelectLocation}
locationPopup={this.props.locationPopup}
locationPopup={locationPopup}
/>
</Popup>
);
Expand Down
2 changes: 1 addition & 1 deletion app/configurations/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ export default {
itinerary: false,
},

viaPointsEnabled: false,
viaPointsEnabled: true,

// Toggling this off shows the alert bodytext instead of the header
showAlertHeader: true,
Expand Down
80 changes: 80 additions & 0 deletions app/util/legUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,86 @@ export function getInterliningLegs(legs, index) {
function bikingEnded(leg1) {
return leg1.from.vehicleRentalStation && leg1.mode === 'WALK';
}

function syntheticEndpoint(originalEndpoint, place) {
return {
...originalEndpoint,
stop: place.stop,
lat: place.stop.lat,
lon: place.stop.lon,
name: place.stop.name,
};
}

/**
* 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 &&
(includesAndRemove(viaPoints, stop.gtfsId) ||
(stop.parentStation &&
includesAndRemove(viaPoints, stop.parentStation.gtfsId)));
let nextLegStartsWithIntermediate = false;
originalLegs.forEach(originalLeg => {
const leg = { ...originalLeg };
const { intermediatePlaces } = leg;
if (
nextLegStartsWithIntermediate ||
(leg.transitLeg && isViaPointMatch(leg.from.stop))
) {
leg.intermediatePlace = true;
nextLegStartsWithIntermediate = false;
}
if (intermediatePlaces) {
let start = 0;
let lastSplit = -1;
intermediatePlaces.forEach((place, i) => {
if (isViaPointMatch(place.stop)) {
const leftLeg = {
...leg,
to: syntheticEndpoint(leg.to, place),
end: place.arrival,
intermediatePlaces: intermediatePlaces.slice(start, i),
};
leg.intermediatePlace = true;
leg.start = place.arrival;
leg.from = syntheticEndpoint(leg.from, place);
splitLegs.push(leftLeg);
start = i + 1;
lastSplit = i;
}
});
if (lastSplit >= 0) {
const lastPlace = intermediatePlaces[lastSplit];
leg.from = syntheticEndpoint(leg.from, lastPlace);
leg.start = lastPlace.arrival;
leg.intermediatePlaces = intermediatePlaces.slice(lastSplit + 1);
}
}
splitLegs.push(leg);
if (leg.transitLeg && isViaPointMatch(leg.to.stop)) {
nextLegStartsWithIntermediate = true;
}
});
return splitLegs;
}
/**
* Compresses the incoming legs (affects only legs with mode BICYCLE, WALK or CITYBIKE). These are combined
* so that the person will be walking their bicycle and there won't be multiple similar legs
Expand Down
5 changes: 4 additions & 1 deletion app/util/otpStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ export function locationToOTP(location) {
if (location.lat) {
const address = location.address || '';
const slack = location.locationSlack ? `::${location.locationSlack}` : '';
return `${address}::${location.lat},${location.lon}${slack}`;
const addressParts = location.gtfsId
? `${address}**${location.gtfsId}`
: address;
return `${addressParts}::${location.lat},${location.lon}${slack}`;
}
if (location.type === 'SelectFromMap') {
return location.type;
Expand Down
6 changes: 6 additions & 0 deletions app/util/planParamUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ export function getPlanParams(
const intermediateLocations = getIntermediatePlaces({
intermediatePlaces,
});
const via = intermediateLocations.map(loc => ({
passThrough: {
stopLocationIds: [loc.gtfsId],
},
}));
const distance = estimateItineraryDistance(
fromLocation,
toLocation,
Expand Down Expand Up @@ -401,5 +406,6 @@ export function getPlanParams(
modes,
planType,
noIterationsForShortTrips,
via,
};
}
Loading
Loading