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

Snap To Rail #1027

Open
wants to merge 6 commits into
base: mtc-deploy
Choose a base branch
from
Open

Snap To Rail #1027

wants to merge 6 commits into from

Conversation

josh-willis-arcadis
Copy link

@josh-willis-arcadis josh-willis-arcadis commented Mar 11, 2025

Add support for a snap to rail feature when editing trip patterns. Uses OpenRailRouter, a fork of GraphHopper.

@josh-willis-arcadis josh-willis-arcadis added the BLOCKED Blocked (waiting on another PR to be merged) label Mar 11, 2025
@josh-willis-arcadis josh-willis-arcadis mentioned this pull request Mar 11, 2025
7 tasks
@miles-grant-ibigroup miles-grant-ibigroup self-assigned this Mar 12, 2025
Copy link
Contributor

@miles-grant-ibigroup miles-grant-ibigroup left a comment

Choose a reason for hiding this comment

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

I see quite a bit of potential to reduce the number of files touched. I'd start by leaving followStreets untouched. That will also make the edits to valhalla less dangerous. We can leave that file mostly untouched and merely add a short check after the alternates section to switch to rail if followRail is true.

That way we can also configure rail routing within alternates. Just have to add a rail flag on each graphhopper alternate!

graphHopperKey = KEY
} else { // no URL or need default value so use graphhopper test environment
graphHopperUrl = 'https://graphhopper.com/api/1/'
// include key here??? this will throw 401 i believe
Copy link
Contributor

Choose a reason for hiding this comment

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

You deleted the code that makes it required to have a graphhopper key! That's a required param

Comment on lines +214 to +215
avoidMotorways?: boolean,
snapToOption: string
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure you're allowed to put an optional before a required parameter

Comment on lines +226 to +231
if (process.env.GRAPH_HOPPER_ALTERNATES) {
// $FlowFixMe This is a bit of a hack and not how env variables are supposed to work, but the yaml loader supports it.
const alternates: Array<GraphHopperAlternateServer> = process.env.GRAPH_HOPPER_ALTERNATES
alternates.forEach(alternative => {
const { BBOX, ROUTING_TYPE, URL, KEY } = alternative
if (BBOX.length !== 4) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The edits to Valhalla are quite clunky. Couldn't we instead mostly keep things as is and only tweak the url/key after the existing block?

Comment on lines +299 to +309
function arePointsValid (points, BBOX) {
return points.every(
(point) => !coordIsOutOfBounds(
point,
L.latLngBounds(
[BBOX[1], BBOX[0]],
[BBOX[3], BBOX[2]]
)
)
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this imported into this file?

@@ -162,17 +162,17 @@ export function handleControlPointDrag (
patternCoordinates: any
) {
return function (dispatch: dispatchFn, getState: getStateFn) {
const {avoidMotorways, currentDragId, followStreets} = getState().editor.editSettings.present
const {avoidMotorways, currentDragId, snapToOption} = getState().editor.editSettings.present
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we call this followOption instead of snapToOption?

@@ -19,6 +19,11 @@ export const CLICK_OPTIONS: Array<string> = [
'ADD_STOPS_AT_INTERVAL',
'ADD_STOPS_AT_INTERSECTIONS'
]
export const SNAP_TO_OPTIONS: Array<string> = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this an array instead of an enum?

return (
<option
key={v}
value={v}>{toSentenceCase(v.replace(/_/g, ' '))}
Copy link
Contributor

Choose a reason for hiding this comment

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

You could avoid this by using an enum and then having a map from enum to string

Copy link
Contributor

Choose a reason for hiding this comment

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

with JS you could even have one large object that has both enum value and string!

@@ -83,7 +97,7 @@ export default class EditSettings extends Component<Props, State> {
// this state would cause the entire shape to disappear).
disabled={
(s.type === 'hideInactiveSegments' && noSegmentIsActive) ||
(s.type === 'avoidMotorways' && !followStreets)
(s.type === 'avoidMotorways' && snapToOption !== 'STREET')
Copy link
Contributor

@miles-grant-ibigroup miles-grant-ibigroup Mar 12, 2025

Choose a reason for hiding this comment

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

No magic strings! Let's use enums instead if we stick with snapToOption

@@ -104,7 +104,7 @@ export default class EditShapePanel extends Component<Props> {
return {lng: stop.stop_lon, lat: stop.stop_lat}
})
: []
this.drawPatternFromStops(activePattern, stopLocations, editSettings.present.followStreets)
this.drawPatternFromStops(activePattern, stopLocations)
Copy link
Contributor

Choose a reason for hiding this comment

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

Uh oh! I'm not sure followStreets was meant to be removed. Maybe let's keep followStreets as is and add a new boolean for followRail. It makes the UI work a bit more tricky but it helps us avoid touching too many files

Comment on lines +99 to +104
// RAIL-TODO: make sure followStreet is properly set.
// RAIL-TODO: use in a lot of places, make sure nothing breaks????
return update(state, {
[setting]: {$set: value},
followStreets: {$set: value === 'STREET'}
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes let's definitely leave followStreets alone

@miles-grant-ibigroup miles-grant-ibigroup removed the BLOCKED Blocked (waiting on another PR to be merged) label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants