Skip to content

Commit

Permalink
fix(editor-stops): fix deletion of pattern stop when shape is null
Browse files Browse the repository at this point in the history
  • Loading branch information
landonreed committed Jul 11, 2017
1 parent 19c60cc commit 406e115
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/editor/actions/map/stopStrategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,24 @@ export function removeStopFromPattern (pattern, stop, index, controlPoints) {
: []
}
try {
const cpIndex = controlPoints.findIndex(cp => cp.stopId === stop.id)
// if not the first stop, use the previous control point as beginning of slice
const begin = controlPoints[cpIndex - 2] ? controlPoints[cpIndex - 1].point : null
// if not last stop, use previous control point as end of slice
const end = controlPoints[cpIndex + 2] ? controlPoints[cpIndex + 1].point : null
const { followStreets, patternCoordinates } = getState().editor.editSettings
const coordinates = await handlePatternEdit(null, begin, end, pattern, followStreets, patternCoordinates)
let shape
// if pattern shape is null, don't attempt to refactor pattern shape
if (!pattern.shape) {
shape = null
} else {
// else, reconstruct pattern shape to splice line segment
const cpIndex = controlPoints.findIndex(cp => cp.stopId === stop.id)
// if not the first stop, use the previous control point as beginning of slice
const begin = controlPoints[cpIndex - 2] ? controlPoints[cpIndex - 1].point : null
// if not last stop, use previous control point as end of slice
const end = controlPoints[cpIndex + 2] ? controlPoints[cpIndex + 1].point : null
const {followStreets, patternCoordinates} = getState().editor.editSettings
const coordinates = await handlePatternEdit(null, begin, end, pattern, followStreets, patternCoordinates)
shape = {type: 'LineString', coordinates}
}
const patternStops = [...pattern.patternStops]
patternStops.splice(index, 1)
dispatch(updateActiveGtfsEntity(pattern, 'trippattern', {patternStops, shape: {type: 'LineString', coordinates}}))
dispatch(updateActiveGtfsEntity(pattern, 'trippattern', {patternStops, shape}))
dispatch(saveActiveGtfsEntity('trippattern'))
} catch (err) {
console.log(err)
Expand Down

0 comments on commit 406e115

Please sign in to comment.