Skip to content

Commit

Permalink
fix(pattern): fix add stop to pattern after fresh fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
landonreed committed May 14, 2018
1 parent e31ad3f commit 36f5d0f
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions lib/editor/actions/map/stopStrategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,27 @@ export function addStopToPattern (pattern, stop, index) {
const newStop = stopToPatternStop(stop, stopSequence)

if (missingIndex || index === patternStops.length) {
// If there is no index, handle adding stop to end (also a proxy for
// extending pattern to point).
// First, add stop to list of pattern stops.
// Push pattern stop to cloned list.
patternStops.push(newStop)
dispatch(updatePatternStops(pattern, patternStops))
if (hasShapePoints) {
// console.log('extending pattern to new stop', stop)
// If a pattern shape already exists, extend it from the current end
// point to the new stop.
const {shapePtLon, shapePtLat} = shapePoints[shapePoints.length - 1]
const currentEndPoint = ll.toLeaflet([shapePtLon, shapePtLat])
const {stop_lon: lng, stop_lat: lat} = stop
// Extend pattern to the new point. NOTE: This includes saving the
// pattern.
// Extend pattern to the new point.
return dispatch(extendPatternToPoint(pattern, currentEndPoint, {lng, lat}, stop))
.then(result => {
// Update pattern stops and pattern geometry together. This ensures
// that a recalcuation of the control points / pattern segments does
// not cause issues when the pattern stops quantity does not match
// the control points. TODO: add optional pattern stops to update pattern
// geometry, so that these are more closely bound.
dispatch(updatePatternStops(pattern, patternStops))
dispatch(updatePatternGeometry(result))
return dispatch(saveActiveGtfsEntity('trippattern'))
})
} else {
// Otherwise, check if a shape ought to be created. Then, save.
if (patternStops.length === 2 && followStreets) {
Expand All @@ -235,6 +241,8 @@ export function addStopToPattern (pattern, stop, index) {
const points = [previousStop, stop]
.map((stop, index) => ({lng: stop.stop_lon, lat: stop.stop_lat}))
const patternSegments = await getPolyline(points, true)
// Update pattern stops and geometry.
dispatch(updatePatternStops(pattern, patternStops))
const controlPoints = controlPointsFromSegments(patternStops, patternSegments)
dispatch(updatePatternGeometry({controlPoints, patternSegments}))
}
Expand Down Expand Up @@ -434,16 +442,11 @@ function extendPatternToPoint (pattern, endPoint, newEndPoint, stop = null, spli
}
clonedControlPoints.push(controlPoint)
}
// Update pattern geometry and control points
const result = {
// Return updated pattern geometry and control points
return {
controlPoints: clonedControlPoints,
patternSegments: newPatternSegments
}
if (stop) {
dispatch(updatePatternGeometry(result))
await dispatch(saveActiveGtfsEntity('trippattern'))
}
return result
}
}

Expand Down

0 comments on commit 36f5d0f

Please sign in to comment.