Skip to content

DT-6955 Viapoint by coordinates #5438

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

Draft
wants to merge 7 commits into
base: v3
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion app/component/itinerary/Itinerary.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ const Itinerary = (
// 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) {
if (leg.intermediatePlace || leg.from.name?.indexOf('Via') > -1) {
onlyIconLegs += 1;
legs.push(<ViaLeg key={`via_${leg.mode}_${startMs}`} />);
viaAdded = true;
Expand Down
5 changes: 4 additions & 1 deletion app/component/itinerary/WalkLeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function WalkLeg(
appendClass={appendClass}
index={index}
modeClassName={modeClassName}
isVia={!!leg.viaAddress}
/>
<div
className={`small-9 columns itinerary-instruction-column ${leg.mode.toLowerCase()}`}
Expand Down Expand Up @@ -219,7 +220,9 @@ function WalkLeg(
/>
</div>
)}
{!returnNotice && !alightNotice && leg[toOrFrom].name}
{!returnNotice &&
!alightNotice &&
(leg.viaAddress || leg[toOrFrom].name)}
{leg[toOrFrom].stop && !alightNotice && (
<Icon
img="icon-icon_arrow-collapse--right"
Expand Down
4 changes: 2 additions & 2 deletions app/component/map/ItineraryPageMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ const ItineraryPageMap = (
let onSelectLocation;

if (isLocationPopupEnabled) {
// max 5 viapoints
locationPopup =
config.viaPointsEnabled && viaPoints.length < 5
config.viaPointsEnabled &&
(!config.viaPointsMax || viaPoints.length < config.viaPointsMax)
? 'all'
: 'origindestination';
onSelectLocation = (item, id) =>
Expand Down
7 changes: 1 addition & 6 deletions app/component/map/tile-layer/TileLayerContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ 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 @@ -71,7 +70,6 @@ class TileLayerContainer extends GridLayer {
static defaultProps = {
onSelectLocation: undefined,
locationPopup: undefined,
allowViaPoint: false,
objectsToHide: { vehicleRentalStations: [] },
highlightedStops: undefined,
stopsToShow: undefined,
Expand Down Expand Up @@ -355,10 +353,7 @@ 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';
const { locationPopup } = this.props;

if (typeof this.state.selectableTargets !== 'undefined') {
if (this.state.selectableTargets.length === 1) {
Expand Down
1 change: 1 addition & 0 deletions app/configurations/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ export default {
},

viaPointsEnabled: true,
viaPointsMax: 1,

// Toggling this off shows the alert bodytext instead of the header
showAlertHeader: true,
Expand Down
15 changes: 14 additions & 1 deletion app/util/legUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@ function isViaPointMatch(stop, viaPoints) {
);
}

function getViaPointAddress(from, viaPoints) {
if (!from || !from.lat || !from.lon || from.name?.indexOf('Via') < 0) {
return null;
}
return viaPoints.find(
p =>
p.lat.toFixed(5) === from.lat.toFixed(5) &&
p.lon.toFixed(5) === from.lon.toFixed(5),
);
}

/**
* 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.
Expand Down Expand Up @@ -309,7 +320,8 @@ export function markViaPoints(originalLegs, viaPlaces) {
const legs = [];
const viaPoints = viaPlaces.map(p => p.gtfsId);
originalLegs.forEach(leg => {
const isViaPoint = isViaPointMatch(leg.from.stop, viaPoints);
const viaAddress = getViaPointAddress(leg.from, viaPlaces)?.address;
const isViaPoint = isViaPointMatch(leg.from.stop, viaPoints) || viaAddress;
if (leg.intermediatePlaces) {
const intermediatePlaces = [];
leg.intermediatePlaces.forEach(place => {
Expand All @@ -327,6 +339,7 @@ export function markViaPoints(originalLegs, viaPlaces) {
legs.push({
...leg,
isViaPoint,
viaAddress,
});
}
});
Expand Down
28 changes: 23 additions & 5 deletions app/util/planParamUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,29 @@ export function getPlanParams(
const intermediateLocations = getIntermediatePlaces({
intermediatePlaces,
});
const via = intermediateLocations.map(loc => ({
passThrough: {
stopLocationIds: [loc.gtfsId],
},
}));
const via = intermediateLocations
.map(loc => {
if (loc.gtfsId) {
return {
passThrough: {
stopLocationIds: [loc.gtfsId],
},
};
}
if (loc.lat && loc.lon) {
return {
visit: {
coordinate: {
latitude: loc.lat,
longitude: loc.lon,
},
},
};
}
return null;
})
.filter(Boolean);

const distance = estimateItineraryDistance(
fromLocation,
toLocation,
Expand Down
Loading
Loading