11import Icon from '@conveyal/woonerf/components/icon'
22import React , { Component } from 'react'
33import { Button , ButtonGroup } from 'react-bootstrap'
4+ import ll from '@conveyal/lonlat'
45import numeral from 'numeral'
56import lineDistance from 'turf-line-distance'
67
78import EditSettings from './EditSettings'
89import { polyline as getPolyline } from '../../../scenario-editor/utils/valhalla'
910
1011export default class EditShapePanel extends Component {
11- async drawPatternFromStops ( pattern , stops ) {
12- const newShape = await getPolyline ( stops )
13- if ( newShape ) {
14- this . props . updateActiveEntity ( pattern , 'trippattern' , { shape : { type : 'LineString' , coordinates : newShape } } )
12+ async drawPatternFromStops ( pattern , stops , followStreets ) {
13+ const coordinates = followStreets
14+ ? await getPolyline ( stops )
15+ : stops . map ( stop => ll . toCoordinates ( stop ) )
16+ if ( coordinates ) {
17+ this . props . updateActiveEntity ( pattern , 'trippattern' , { shape : { type : 'LineString' , coordinates} } )
1518 this . props . saveActiveEntity ( 'trippattern' )
1619 return true
1720 } else {
@@ -27,7 +30,7 @@ export default class EditShapePanel extends Component {
2730 }
2831
2932 createFromStops = ( ) => {
30- const { activePattern, showConfirmModal, stops} = this . props
33+ const { activePattern, editSettings , showConfirmModal, stops} = this . props
3134 showConfirmModal ( {
3235 title : `Create pattern shape from stops?` ,
3336 body : `Are you sure you want to overwrite this trip pattern?` ,
@@ -38,7 +41,7 @@ export default class EditShapePanel extends Component {
3841 return { lng : stop . stop_lon , lat : stop . stop_lat }
3942 } )
4043 : [ ]
41- return this . drawPatternFromStops ( activePattern , stopLocations )
44+ return this . drawPatternFromStops ( activePattern , stopLocations , editSettings . followStreets )
4245 }
4346 } )
4447 }
@@ -67,7 +70,7 @@ export default class EditShapePanel extends Component {
6770 }
6871
6972 render ( ) {
70- const { activePattern, editSettings, undoActiveTripPatternEdits} = this . props
73+ const { activePattern, editSettings, updateEditSetting , undoActiveTripPatternEdits} = this . props
7174 let buttons
7275 if ( editSettings . editGeometry ) {
7376 buttons = [ {
@@ -112,8 +115,8 @@ export default class EditShapePanel extends Component {
112115 ) ) }
113116 </ ButtonGroup >
114117 < EditSettings
115- editSettings = { this . props . editSettings }
116- updateEditSetting = { this . props . updateEditSetting } />
118+ editSettings = { editSettings }
119+ updateEditSetting = { updateEditSetting } />
117120 </ div >
118121 : < Button
119122 block
0 commit comments