Skip to content

Commit 0513ea1

Browse files
committed
fix(follw-streets): fix add extendPatternToPoint to account for followStreets bool
1 parent d77323d commit 0513ea1

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

lib/editor/actions/map/index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,19 @@ export function displayRoutesShapefile (feedSource, file) {
139139

140140
export function extendPatternToPoint (pattern, endPoint, newEndPoint) {
141141
return async function (dispatch, getState) {
142-
let newShape = await getPolyline([endPoint, newEndPoint])
143-
144-
// get single coordinate if polyline fails
142+
const {followStreets} = getState().editor.editSettings
143+
let newShape
144+
if (followStreets) {
145+
newShape = await getPolyline([endPoint, newEndPoint])
146+
}
147+
// get single coordinate for straight line if polyline fails or if not following streets
145148
if (!newShape) {
146149
newShape = [ll.toCoordinates(newEndPoint)]
147150
}
148-
const updatedShape = {type: 'LineString', coordinates: [...pattern.shape.coordinates, ...newShape]}
149-
dispatch(updateActiveGtfsEntity(pattern, 'trippattern', {shape: updatedShape}))
151+
// append newShape coords to existing pattern coords
152+
const shape = {type: 'LineString', coordinates: [...pattern.shape.coordinates, ...newShape]}
153+
dispatch(updateActiveGtfsEntity(pattern, 'trippattern', {shape}))
150154
await dispatch(saveActiveGtfsEntity('trippattern'))
151-
return updatedShape
155+
return shape
152156
}
153157
}

lib/editor/actions/map/stopStrategies.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,16 @@ export function addStopAtPoint (latlng, addToPattern = false, index, activePatte
2424
return function (dispatch, getState) {
2525
// create stop
2626
return constructStop(latlng, activePattern.feedId)
27-
.then(stop => {
28-
return dispatch(newGtfsEntity(activePattern.feedId, 'stop', stop, true))
27+
.then(stop => dispatch(newGtfsEntity(activePattern.feedId, 'stop', stop, true))
2928
.then(s => {
3029
const gtfsStop = stopToGtfs(s)
3130
// add stop to end of pattern
3231
if (addToPattern && gtfsStop) {
3332
return dispatch(addStopToPattern(activePattern, gtfsStop, index))
34-
.then(result => {
35-
return gtfsStop
36-
})
33+
.then(result => gtfsStop)
3734
}
3835
return gtfsStop
39-
})
40-
})
36+
}))
4137
}
4238
}
4339

@@ -163,9 +159,10 @@ export function addStopToPattern (pattern, stop, index) {
163159
if (coordinates) {
164160
const endPoint = ll.toLeaflet(coordinates[coordinates.length - 1])
165161
patternStops.push(newStop)
166-
dispatch(updateActiveGtfsEntity(pattern, 'trippattern', {patternStops: patternStops}))
162+
dispatch(updateActiveGtfsEntity(pattern, 'trippattern', {patternStops}))
167163
// saveActiveGtfsEntity('trippattern')
168-
return dispatch(extendPatternToPoint(pattern, endPoint, {lng: stop.stop_lon, lat: stop.stop_lat}))
164+
const {stop_lon: lng, stop_lat: lat} = stop
165+
return dispatch(extendPatternToPoint(pattern, endPoint, {lng, lat}))
169166
} else {
170167
// if shape coordinates do not exist, add pattern stop and get shape between stops (if multiple stops exist)
171168
patternStops.push(newStop)

0 commit comments

Comments
 (0)