From 406e115190d85335ba056c398be1bed750e944ef Mon Sep 17 00:00:00 2001 From: Landon Reed Date: Tue, 11 Jul 2017 11:59:46 -0400 Subject: [PATCH] fix(editor-stops): fix deletion of pattern stop when shape is null --- lib/editor/actions/map/stopStrategies.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/editor/actions/map/stopStrategies.js b/lib/editor/actions/map/stopStrategies.js index 24a559821..15bcb485e 100644 --- a/lib/editor/actions/map/stopStrategies.js +++ b/lib/editor/actions/map/stopStrategies.js @@ -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)