1
1
import Icon from '@conveyal/woonerf/components/icon'
2
2
import React , { Component } from 'react'
3
3
import { Button , ButtonGroup } from 'react-bootstrap'
4
+ import ll from '@conveyal/lonlat'
4
5
import numeral from 'numeral'
5
6
import lineDistance from 'turf-line-distance'
6
7
7
8
import EditSettings from './EditSettings'
8
9
import { polyline as getPolyline } from '../../../scenario-editor/utils/valhalla'
9
10
10
11
export 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} } )
15
18
this . props . saveActiveEntity ( 'trippattern' )
16
19
return true
17
20
} else {
@@ -27,7 +30,7 @@ export default class EditShapePanel extends Component {
27
30
}
28
31
29
32
createFromStops = ( ) => {
30
- const { activePattern, showConfirmModal, stops} = this . props
33
+ const { activePattern, editSettings , showConfirmModal, stops} = this . props
31
34
showConfirmModal ( {
32
35
title : `Create pattern shape from stops?` ,
33
36
body : `Are you sure you want to overwrite this trip pattern?` ,
@@ -38,7 +41,7 @@ export default class EditShapePanel extends Component {
38
41
return { lng : stop . stop_lon , lat : stop . stop_lat }
39
42
} )
40
43
: [ ]
41
- return this . drawPatternFromStops ( activePattern , stopLocations )
44
+ return this . drawPatternFromStops ( activePattern , stopLocations , editSettings . followStreets )
42
45
}
43
46
} )
44
47
}
@@ -67,7 +70,7 @@ export default class EditShapePanel extends Component {
67
70
}
68
71
69
72
render ( ) {
70
- const { activePattern, editSettings, undoActiveTripPatternEdits} = this . props
73
+ const { activePattern, editSettings, updateEditSetting , undoActiveTripPatternEdits} = this . props
71
74
let buttons
72
75
if ( editSettings . editGeometry ) {
73
76
buttons = [ {
@@ -112,8 +115,8 @@ export default class EditShapePanel extends Component {
112
115
) ) }
113
116
</ ButtonGroup >
114
117
< EditSettings
115
- editSettings = { this . props . editSettings }
116
- updateEditSetting = { this . props . updateEditSetting } />
118
+ editSettings = { editSettings }
119
+ updateEditSetting = { updateEditSetting } />
117
120
</ div >
118
121
: < Button
119
122
block
0 commit comments