Skip to content

Commit

Permalink
fix(EditShapePanel): fix drawing pattern geometry when not following …
Browse files Browse the repository at this point in the history
…streets
  • Loading branch information
landonreed committed Jul 6, 2017
1 parent 35b4dbd commit acee5b1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/editor/components/pattern/EditShapePanel.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import Icon from '@conveyal/woonerf/components/icon'
import React, {Component} from 'react'
import {Button, ButtonGroup} from 'react-bootstrap'
import ll from '@conveyal/lonlat'
import numeral from 'numeral'
import lineDistance from 'turf-line-distance'

import EditSettings from './EditSettings'
import { polyline as getPolyline } from '../../../scenario-editor/utils/valhalla'

export default class EditShapePanel extends Component {
async drawPatternFromStops (pattern, stops) {
const newShape = await getPolyline(stops)
if (newShape) {
this.props.updateActiveEntity(pattern, 'trippattern', {shape: {type: 'LineString', coordinates: newShape}})
async drawPatternFromStops (pattern, stops, followStreets) {
const coordinates = followStreets
? await getPolyline(stops)
: stops.map(stop => ll.toCoordinates(stop))
if (coordinates) {
this.props.updateActiveEntity(pattern, 'trippattern', {shape: {type: 'LineString', coordinates}})
this.props.saveActiveEntity('trippattern')
return true
} else {
Expand All @@ -27,7 +30,7 @@ export default class EditShapePanel extends Component {
}

createFromStops = () => {
const {activePattern, showConfirmModal, stops} = this.props
const {activePattern, editSettings, showConfirmModal, stops} = this.props
showConfirmModal({
title: `Create pattern shape from stops?`,
body: `Are you sure you want to overwrite this trip pattern?`,
Expand All @@ -38,7 +41,7 @@ export default class EditShapePanel extends Component {
return {lng: stop.stop_lon, lat: stop.stop_lat}
})
: []
return this.drawPatternFromStops(activePattern, stopLocations)
return this.drawPatternFromStops(activePattern, stopLocations, editSettings.followStreets)
}
})
}
Expand Down Expand Up @@ -67,7 +70,7 @@ export default class EditShapePanel extends Component {
}

render () {
const {activePattern, editSettings, undoActiveTripPatternEdits} = this.props
const {activePattern, editSettings, updateEditSetting, undoActiveTripPatternEdits} = this.props
let buttons
if (editSettings.editGeometry) {
buttons = [{
Expand Down Expand Up @@ -112,8 +115,8 @@ export default class EditShapePanel extends Component {
))}
</ButtonGroup>
<EditSettings
editSettings={this.props.editSettings}
updateEditSetting={this.props.updateEditSetting} />
editSettings={editSettings}
updateEditSetting={updateEditSetting} />
</div>
: <Button
block
Expand Down

0 comments on commit acee5b1

Please sign in to comment.