@@ -9,6 +9,7 @@ import lineSlice from 'turf-line-slice'
99import lineString from 'turf-linestring'
1010import point from 'turf-point'
1111import turfPolygon from 'turf-polygon'
12+ // $FlowFixMe flow doesn't understand new packages
1213import centerOfMass from '@turf/center-of-mass'
1314
1415import { updateActiveGtfsEntity , saveActiveGtfsEntity } from '../active'
@@ -230,7 +231,7 @@ export function addStopAtInterval (latlng: LatLng, activePattern: Pattern, contr
230231 }
231232}
232233
233- export function addStopToPattern ( pattern : Pattern , stop : GtfsStop | GtfsLocation , index ?: ?number ) {
234+ export function addStopToPattern ( pattern : Pattern , origStop : GtfsStop | GtfsLocation , index ?: ?number ) {
234235 // eslint-disable-next-line complexity
235236 return async function ( dispatch : dispatchFn , getState : getStateFn ) {
236237 const { data , editSettings } = getState ( ) . editor
@@ -243,6 +244,9 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop | GtfsLocatio
243244 const { controlPoints , patternSegments } = getControlPoints ( getState ( ) )
244245 const hasShapePoints = shapePoints && shapePoints . length > 1
245246
247+ // $FlowFixMe this is a bit of a hack to get locations to work with methods built for stops. We do the work required to have all methods work.
248+ const stop : GtfsStop = clone ( origStop )
249+
246250 if ( stop . stop_id === undefined || stop . stop_id === null ) {
247251 // convert stop to turf polygon
248252 const polygon = stop . location_shapes . map ( ls => [ ls . geometry_pt_lat , ls . geometry_pt_lon ] )
@@ -306,7 +310,7 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop | GtfsLocatio
306310 const locationgroups = getTableById ( data . tables , 'locationgroup' )
307311 const previousStop = stops . find ( s => s . stop_id === previousStopId ) || locations . find ( s => s . location_id === previousStopId ) || locationgroups . find ( s => s . location_group_id === previousStopId )
308312 if ( ! previousStop ) {
309- throw new Error ( `Stop not found for stop_id ${ previousStopId } .` )
313+ throw new Error ( `Stop not found for stop_id ${ previousStopId || '(no previous stop id)' } .` )
310314 }
311315 const points = [ previousStop , stop ]
312316 . map ( ( stop , index ) => ( { lng : stop . stop_lon , lat : stop . stop_lat } ) )
@@ -551,6 +555,7 @@ export function removeStopFromPattern (pattern: Pattern, stop: GtfsLocation | Gt
551555 const clonedControlPoints = clone ( controlPoints )
552556 const clonedPatternSegments = clone ( patternSegments )
553557 const { shapePoints, patternStops} = pattern
558+ // $FlowFixMe Flow doesn't understand this property check
554559 const stopIsStop = stop . hasOwnProperty ( 'stopId' ) && stop . stopId !== null
555560 // Use control points to determine control point index for removed stop.
556561 // This is distinct from the index arg supplied because there may be more
0 commit comments