Skip to content

Commit

Permalink
fix(follw-streets): fix add extendPatternToPoint to account for follo…
Browse files Browse the repository at this point in the history
…wStreets bool
  • Loading branch information
landonreed committed Jun 15, 2017
1 parent d77323d commit 0513ea1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
16 changes: 10 additions & 6 deletions lib/editor/actions/map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,19 @@ export function displayRoutesShapefile (feedSource, file) {

export function extendPatternToPoint (pattern, endPoint, newEndPoint) {
return async function (dispatch, getState) {
let newShape = await getPolyline([endPoint, newEndPoint])

// get single coordinate if polyline fails
const {followStreets} = getState().editor.editSettings
let newShape
if (followStreets) {
newShape = await getPolyline([endPoint, newEndPoint])
}
// get single coordinate for straight line if polyline fails or if not following streets
if (!newShape) {
newShape = [ll.toCoordinates(newEndPoint)]
}
const updatedShape = {type: 'LineString', coordinates: [...pattern.shape.coordinates, ...newShape]}
dispatch(updateActiveGtfsEntity(pattern, 'trippattern', {shape: updatedShape}))
// append newShape coords to existing pattern coords
const shape = {type: 'LineString', coordinates: [...pattern.shape.coordinates, ...newShape]}
dispatch(updateActiveGtfsEntity(pattern, 'trippattern', {shape}))
await dispatch(saveActiveGtfsEntity('trippattern'))
return updatedShape
return shape
}
}
15 changes: 6 additions & 9 deletions lib/editor/actions/map/stopStrategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,16 @@ export function addStopAtPoint (latlng, addToPattern = false, index, activePatte
return function (dispatch, getState) {
// create stop
return constructStop(latlng, activePattern.feedId)
.then(stop => {
return dispatch(newGtfsEntity(activePattern.feedId, 'stop', stop, true))
.then(stop => dispatch(newGtfsEntity(activePattern.feedId, 'stop', stop, true))
.then(s => {
const gtfsStop = stopToGtfs(s)
// add stop to end of pattern
if (addToPattern && gtfsStop) {
return dispatch(addStopToPattern(activePattern, gtfsStop, index))
.then(result => {
return gtfsStop
})
.then(result => gtfsStop)
}
return gtfsStop
})
})
}))
}
}

Expand Down Expand Up @@ -163,9 +159,10 @@ export function addStopToPattern (pattern, stop, index) {
if (coordinates) {
const endPoint = ll.toLeaflet(coordinates[coordinates.length - 1])
patternStops.push(newStop)
dispatch(updateActiveGtfsEntity(pattern, 'trippattern', {patternStops: patternStops}))
dispatch(updateActiveGtfsEntity(pattern, 'trippattern', {patternStops}))
// saveActiveGtfsEntity('trippattern')
return dispatch(extendPatternToPoint(pattern, endPoint, {lng: stop.stop_lon, lat: stop.stop_lat}))
const {stop_lon: lng, stop_lat: lat} = stop
return dispatch(extendPatternToPoint(pattern, endPoint, {lng, lat}))
} else {
// if shape coordinates do not exist, add pattern stop and get shape between stops (if multiple stops exist)
patternStops.push(newStop)
Expand Down

0 comments on commit 0513ea1

Please sign in to comment.