Skip to content

Commit c479ae1

Browse files
use snapToOption string to calculate shapes
1 parent a69fee7 commit c479ae1

File tree

8 files changed

+89
-84
lines changed

8 files changed

+89
-84
lines changed

lib/editor/actions/map/index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,17 @@ export function handleControlPointDrag (
165165
patternCoordinates: any
166166
) {
167167
return function (dispatch: dispatchFn, getState: getStateFn) {
168-
const {avoidMotorways, currentDragId, followStreets} = getState().editor.editSettings.present
168+
const {avoidMotorways, currentDragId, snapToOption} = getState().editor.editSettings.present
169169
recalculateShape({
170170
avoidMotorways,
171171
controlPoints,
172172
defaultToStraightLine: false,
173173
dragId: currentDragId,
174174
editType: 'update',
175-
followStreets,
176175
index,
177176
newPoint: latlng,
178-
patternCoordinates
177+
patternCoordinates,
178+
snapToOption
179179
}).then(result => {
180180
const {currentDragId} = getState().editor.editSettings.present
181181
// If there is a dragId in the store and it matches the result, the user
@@ -207,17 +207,17 @@ export function handleControlPointDragEnd (
207207
dispatch(controlPointDragOrEnd())
208208

209209
// recalculate shape for final position
210-
const {avoidMotorways, followStreets} = getState().editor.editSettings.present
210+
const {avoidMotorways, snapToOption} = getState().editor.editSettings.present
211211
recalculateShape({
212212
avoidMotorways,
213213
controlPoints,
214214
defaultToStraightLine: false,
215215
editType: 'update',
216216
index,
217-
followStreets,
218217
newPoint: latlng,
219218
patternCoordinates,
220-
snapControlPointToNewSegment: true
219+
snapControlPointToNewSegment: true,
220+
snapToOption
221221
}).then(result => {
222222
// const {updatedShapePoints: shapePoints, updatedControlPoints} = result
223223
if (!result.coordinates) {

lib/editor/actions/map/stopStrategies.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,10 @@ export function addStopAtInterval (latlng: LatLng, activePattern: Pattern, contr
227227
}
228228

229229
export function addStopToPattern (pattern: Pattern, stop: GtfsStop, index?: ?number) {
230+
// eslint-disable-next-line complexity
230231
return async function (dispatch: dispatchFn, getState: getStateFn) {
231232
const {data, editSettings} = getState().editor
232-
const {avoidMotorways, followStreets} = editSettings.present
233+
const {avoidMotorways, snapToOption} = editSettings.present
233234
const {patternStops: currentPatternStops, shapePoints} = pattern
234235
const patternStops = clone(currentPatternStops)
235236
const {controlPoints, patternSegments} = getControlPoints(getState())
@@ -265,7 +266,7 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop, index?: ?num
265266
} else {
266267
dispatch(updatePatternStops(pattern, patternStops))
267268
// Otherwise, check if a shape ought to be created. Then, save.
268-
if (patternStops.length === 2 && followStreets) {
269+
if (patternStops.length === 2 && snapToOption) {
269270
// Create shape between stops the added stop is the second one and
270271
// followStreets is enabled. Otherwise, there is no need to create a
271272
// new shape because it would just be a straight line segment anyways.
@@ -277,7 +278,7 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop, index?: ?num
277278
}
278279
const points = [previousStop, stop]
279280
.map((stop, index) => ({lng: stop.stop_lon, lat: stop.stop_lat}))
280-
const patternSegments = await getPolyline(points, true, avoidMotorways)
281+
const patternSegments = await getPolyline(points, true, avoidMotorways, snapToOption)
281282
// Update pattern stops and geometry.
282283
const controlPoints = controlPointsFromSegments(patternStops, patternSegments)
283284
dispatch(updatePatternGeometry({controlPoints, patternSegments}))
@@ -330,7 +331,7 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop, index?: ?num
330331
// as recalculate shape.
331332
let result
332333
try {
333-
const newFromSegment = await getSegment(newFromSegmentCoords, true)
334+
const newFromSegment = await getSegment(newFromSegmentCoords, true, avoidMotorways, snapToOption)
334335
const segmentDistance = lineDistance(newFromSegment, 'meters')
335336
const addedControlPoint = newControlPoint(
336337
previousStopControlPoint.distance + segmentDistance,
@@ -358,11 +359,11 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop, index?: ?num
358359
controlPoints: clonedControlPoints,
359360
defaultToStraightLine: false,
360361
editType: 'update',
361-
followStreets,
362362
index: spliceIndex,
363363
newPoint: {lng: stop.stop_lon, lat: stop.stop_lat},
364364
snapControlPointToNewSegment: true,
365-
patternCoordinates: clonedPatternSegments
365+
patternCoordinates: clonedPatternSegments,
366+
snapToOption
366367
})
367368
} catch (err) {
368369
console.log(err)
@@ -399,11 +400,11 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop, index?: ?num
399400
controlPoints: clonedControlPoints,
400401
defaultToStraightLine: false,
401402
editType: 'update',
402-
followStreets,
403403
index,
404404
newPoint: {lng: stop.stop_lon, lat: stop.stop_lat},
405405
snapControlPointToNewSegment: true,
406-
patternCoordinates: clonedPatternSegments
406+
patternCoordinates: clonedPatternSegments,
407+
snapToOption
407408
})
408409
} catch (err) {
409410
console.log(err)
@@ -429,12 +430,12 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop, index?: ?num
429430
*/
430431
function extendPatternToPoint (pattern, endPoint, newEndPoint, stop = null, splitInterval = 0) {
431432
return async function (dispatch: dispatchFn, getState: getStateFn) {
432-
const {avoidMotorways, followStreets} = getState().editor.editSettings.present
433+
const {avoidMotorways, snapToOption} = getState().editor.editSettings.present
433434
const {controlPoints, patternSegments} = getControlPoints(getState())
434435
const clonedControlPoints = clone(controlPoints)
435436
let newShape
436-
if (followStreets) {
437-
newShape = await getPolyline([endPoint, newEndPoint], false, avoidMotorways)
437+
if (snapToOption) {
438+
newShape = await getPolyline([endPoint, newEndPoint], false, avoidMotorways, snapToOption)
438439
}
439440
if (!newShape) {
440441
// Get single coordinate for straight line if polyline fails or if not

lib/editor/components/pattern/EditSettings.js

+5-13
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,11 @@ export default class EditSettings extends Component<Props, State> {
5959
const {editSettings, patternSegment, updateEditSetting} = this.props
6060
const {
6161
editGeometry,
62-
followStreets,
6362
onMapClick,
64-
stopInterval
63+
stopInterval,
64+
snapToOption
6565
} = editSettings
6666
const SETTINGS = [
67-
// RAIL-TODO remove snap to streets
68-
{type: 'followStreets', label: 'Snap to streets'},
6967
{type: 'avoidMotorways', label: 'Avoid highways in routing'},
7068
{type: 'hideStopHandles', label: 'Hide stop handles'},
7169
{type: 'hideInactiveSegments', label: 'Hide inactive segments'},
@@ -79,19 +77,13 @@ export default class EditSettings extends Component<Props, State> {
7977
<ControlLabel><small>Snap to options</small></ControlLabel>
8078
<FormControl
8179
componentClass='select'
82-
value={onMapClick}
83-
name={'onMapClick'}
80+
value={snapToOption}
81+
name={'snapToOption'}
8482
onChange={this._onSelectChange}>
8583
{SNAP_TO_OPTIONS.map(v => {
86-
// ADD_STOPS_AT_INTERSECTIONS only enabled for nysdot extenstion
87-
// (due to custom r5 deployment)
88-
// FIXME: Temporarily disable add stops at intersection entirely
89-
// (needs to be fixed for sql editor).
90-
const disabled = v === 'ADD_STOPS_AT_INTERSECTIONS' // && !isExtensionEnabled('nysdot')
9184
return (
9285
<option
9386
key={v}
94-
disabled={disabled}
9587
value={v}>{toSentenceCase(v.replace(/_/g, ' '))}
9688
</option>
9789
)
@@ -105,7 +97,7 @@ export default class EditSettings extends Component<Props, State> {
10597
// this state would cause the entire shape to disappear).
10698
disabled={
10799
(s.type === 'hideInactiveSegments' && noSegmentIsActive) ||
108-
(s.type === 'avoidMotorways' && !followStreets)
100+
(s.type === 'avoidMotorways' && snapToOption !== 'STREET')
109101
}
110102
name={s.type}
111103
style={{margin: '3px 0'}}

lib/editor/components/pattern/EditShapePanel.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ export default class EditShapePanel extends Component<Props> {
5151
async drawPatternFromStops (pattern: Pattern, stopsCoordinates: Array<LatLng>, followStreets: boolean): Promise<any> {
5252
const {editSettings, saveActiveGtfsEntity, setErrorMessage, updatePatternGeometry} = this.props
5353
let patternSegments = []
54-
if (followStreets) {
55-
patternSegments = await getPolyline(stopsCoordinates, true, editSettings.present.avoidMotorways)
54+
if (editSettings.present.snapToOption !== 'NONE') {
55+
patternSegments = await getPolyline(stopsCoordinates, true, editSettings.present.avoidMotorways, editSettings.present.snapToOption)
5656
} else {
5757
// Construct straight-line segments using stop coordinates
5858
stopsCoordinates

lib/editor/reducers/settings.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export const defaultState = {
2020
currentDragId: null,
2121
distanceFromIntersection: 5,
2222
editGeometry: false,
23-
followStreets: true,
2423
hideInactiveSegments: false,
2524
intersectionStep: 2,
2625
onMapClick: CLICK_OPTIONS[0],
@@ -29,6 +28,7 @@ export const defaultState = {
2928
showStops: true,
3029
showTooltips: true,
3130
hideStopHandles: true,
31+
snapToOption: 'NONE',
3232
stopInterval: 400
3333
}
3434

@@ -96,6 +96,11 @@ export const reducers = {
9696
action: ActionType<typeof updateEditSetting>
9797
): EditSettingsState {
9898
const {setting, value} = action.payload
99-
return update(state, { [setting]: {$set: value} })
99+
// RAIL-TODO: make sure followStreet is properly set.
100+
// RAIL-TODO: use in a lot of places, make sure nothing breaks????
101+
return update(state, {
102+
[setting]: {$set: value},
103+
followStreets: {$set: value === 'STREET'}
104+
})
100105
}
101106
}

lib/editor/util/map.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -262,30 +262,29 @@ export function getPatternEndPoint (pattern: Pattern, controlPoints?: Array<Cont
262262
throw new Error('Control point is missing coordinates')
263263
}
264264

265-
// RAIL-TODO: remove followRoad for generic routing options
266265
/* eslint-disable complexity */
267266
export async function recalculateShape ({
268267
avoidMotorways = false,
269268
controlPoints,
270269
defaultToStraightLine = true,
271270
dragId,
272271
editType,
273-
followStreets,
274272
index,
275273
newPoint,
276274
patternCoordinates,
277-
snapControlPointToNewSegment = false
275+
snapControlPointToNewSegment = false,
276+
snapToOption
278277
}: {
279278
avoidMotorways?: boolean,
280279
controlPoints: Array<ControlPoint>,
281280
defaultToStraightLine?: boolean,
282281
dragId?: null | string,
283282
editType: string,
284-
followStreets: boolean,
285283
index: number,
286284
newPoint?: LatLng,
287285
patternCoordinates: Array<Coordinates>,
288-
snapControlPointToNewSegment?: boolean
286+
snapControlPointToNewSegment?: boolean,
287+
snapToOption: string
289288
}): Promise<{
290289
coordinates: ?Array<any>,
291290
dragId?: ?string,
@@ -397,12 +396,11 @@ export async function recalculateShape ({
397396
throw new Error('Invalid editType. Must be either "update" or "delete".')
398397
}
399398
// calculate new segment (valhalla or straight line)
400-
// RAIL-TODO: remove followRoad for generic routing options
401399
const newSegment = await getSegment(
402400
pointsToRoute,
403-
followStreets,
404401
defaultToStraightLine,
405-
avoidMotorways
402+
avoidMotorways,
403+
snapToOption
406404
)
407405
if (!newSegment || !newSegment.coordinates) {
408406
// If new segment calculation is unsuccessful, return null for coordinates and

0 commit comments

Comments
 (0)