Skip to content

Commit b809f44

Browse files
use snap to option to calculate shape
1 parent 23f5fa3 commit b809f44

File tree

8 files changed

+114
-56
lines changed

8 files changed

+114
-56
lines changed

lib/editor/actions/map/index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,17 @@ export function handleControlPointDrag (
162162
patternCoordinates: any
163163
) {
164164
return function (dispatch: dispatchFn, getState: getStateFn) {
165-
const {avoidMotorways, currentDragId, followStreets} = getState().editor.editSettings.present
165+
const {avoidMotorways, currentDragId, snapToOption} = getState().editor.editSettings.present
166166
recalculateShape({
167167
avoidMotorways,
168168
controlPoints,
169169
defaultToStraightLine: false,
170170
dragId: currentDragId,
171171
editType: 'update',
172-
followStreets,
173172
index,
174173
newPoint: latlng,
175-
patternCoordinates
174+
patternCoordinates,
175+
snapToOption
176176
}).then(result => {
177177
const {currentDragId} = getState().editor.editSettings.present
178178
// If there is a dragId in the store and it matches the result, the user
@@ -204,17 +204,17 @@ export function handleControlPointDragEnd (
204204
dispatch(controlPointDragOrEnd())
205205

206206
// recalculate shape for final position
207-
const {avoidMotorways, followStreets} = getState().editor.editSettings.present
207+
const {avoidMotorways, snapToOption} = getState().editor.editSettings.present
208208
recalculateShape({
209209
avoidMotorways,
210210
controlPoints,
211211
defaultToStraightLine: false,
212212
editType: 'update',
213213
index,
214-
followStreets,
215214
newPoint: latlng,
216215
patternCoordinates,
217-
snapControlPointToNewSegment: true
216+
snapControlPointToNewSegment: true,
217+
snapToOption
218218
}).then(result => {
219219
// const {updatedShapePoints: shapePoints, updatedControlPoints} = result
220220
if (!result.coordinates) {

lib/editor/actions/map/stopStrategies.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,10 @@ export function addStopAtInterval (latlng: LatLng, activePattern: Pattern, contr
220220
}
221221

222222
export function addStopToPattern (pattern: Pattern, stop: GtfsStop, index?: ?number) {
223+
// eslint-disable-next-line complexity
223224
return async function (dispatch: dispatchFn, getState: getStateFn) {
224225
const {data, editSettings} = getState().editor
225-
const {avoidMotorways, followStreets} = editSettings.present
226+
const {avoidMotorways, snapToOption} = editSettings.present
226227
const {patternStops: currentPatternStops, shapePoints} = pattern
227228
const patternStops = clone(currentPatternStops)
228229
const {controlPoints, patternSegments} = getControlPoints(getState())
@@ -260,7 +261,7 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop, index?: ?num
260261
} else {
261262
dispatch(updatePatternStops(pattern, patternStops))
262263
// Otherwise, check if a shape ought to be created. Then, save.
263-
if (patternStops.length === 2 && followStreets) {
264+
if (patternStops.length === 2 && snapToOption) {
264265
// Create shape between stops the added stop is the second one and
265266
// followStreets is enabled. Otherwise, there is no need to create a
266267
// new shape because it would just be a straight line segment anyways.
@@ -272,7 +273,7 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop, index?: ?num
272273
}
273274
const points = [previousStop, stop]
274275
.map((stop, index) => ({lng: stop.stop_lon, lat: stop.stop_lat}))
275-
const patternSegments = await getPolyline(points, true, avoidMotorways)
276+
const patternSegments = await getPolyline(points, true, avoidMotorways, snapToOption)
276277
// Update pattern stops and geometry.
277278
const controlPoints = controlPointsFromSegments(patternStops, patternSegments)
278279
dispatch(updatePatternGeometry({controlPoints, patternSegments}))
@@ -335,11 +336,11 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop, index?: ?num
335336
controlPoints: clonedControlPoints,
336337
defaultToStraightLine: false,
337338
editType: 'update',
338-
followStreets,
339339
index: spliceIndex,
340340
newPoint: {lng: stop.stop_lon, lat: stop.stop_lat},
341341
snapControlPointToNewSegment: true,
342-
patternCoordinates: clonedPatternSegments
342+
patternCoordinates: clonedPatternSegments,
343+
snapToOption
343344
})
344345
} catch (err) {
345346
console.log(err)
@@ -376,11 +377,11 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop, index?: ?num
376377
controlPoints: clonedControlPoints,
377378
defaultToStraightLine: false,
378379
editType: 'update',
379-
followStreets,
380380
index,
381381
newPoint: {lng: stop.stop_lon, lat: stop.stop_lat},
382382
snapControlPointToNewSegment: true,
383-
patternCoordinates: clonedPatternSegments
383+
patternCoordinates: clonedPatternSegments,
384+
snapToOption
384385
})
385386
} catch (err) {
386387
console.log(err)
@@ -406,12 +407,12 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop, index?: ?num
406407
*/
407408
function extendPatternToPoint (pattern, endPoint, newEndPoint, stop = null, splitInterval = 0) {
408409
return async function (dispatch: dispatchFn, getState: getStateFn) {
409-
const {avoidMotorways, followStreets} = getState().editor.editSettings.present
410+
const {avoidMotorways, snapToOption} = getState().editor.editSettings.present
410411
const {controlPoints, patternSegments} = getControlPoints(getState())
411412
const clonedControlPoints = clone(controlPoints)
412413
let newShape
413-
if (followStreets) {
414-
newShape = await getPolyline([endPoint, newEndPoint], false, avoidMotorways)
414+
if (snapToOption) {
415+
newShape = await getPolyline([endPoint, newEndPoint], false, avoidMotorways, snapToOption)
415416
}
416417
if (!newShape) {
417418
// 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-6
Original file line numberDiff line numberDiff line change
@@ -263,22 +263,22 @@ export async function recalculateShape ({
263263
defaultToStraightLine = true,
264264
dragId,
265265
editType,
266-
followStreets,
267266
index,
268267
newPoint,
269268
patternCoordinates,
270-
snapControlPointToNewSegment = false
269+
snapControlPointToNewSegment = false,
270+
snapToOption
271271
}: {
272272
avoidMotorways?: boolean,
273273
controlPoints: Array<ControlPoint>,
274274
defaultToStraightLine?: boolean,
275275
dragId?: null | string,
276276
editType: string,
277-
followStreets: boolean,
278277
index: number,
279278
newPoint?: LatLng,
280279
patternCoordinates: Array<Coordinates>,
281-
snapControlPointToNewSegment?: boolean
280+
snapControlPointToNewSegment?: boolean,
281+
snapToOption: string
282282
}): Promise<{
283283
coordinates: ?Array<any>,
284284
dragId?: ?string,
@@ -392,9 +392,9 @@ export async function recalculateShape ({
392392
// calculate new segment (valhalla or straight line)
393393
const newSegment = await getSegment(
394394
pointsToRoute,
395-
followStreets,
396395
defaultToStraightLine,
397-
avoidMotorways
396+
avoidMotorways,
397+
snapToOption
398398
)
399399
if (!newSegment || !newSegment.coordinates) {
400400
// If new segment calculation is unsuccessful, return null for coordinates and

0 commit comments

Comments
 (0)