Skip to content

Commit

Permalink
Fix Buggy Shapes & Use Parent Stations on Line Page
Browse files Browse the repository at this point in the history
  • Loading branch information
consindo committed Sep 21, 2019
1 parent 73255b1 commit a200743
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
8 changes: 7 additions & 1 deletion js/views/lines/Line.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class Line extends React.Component {

iconHelper = new IconHelper()

interpolatedShape = null

state = {
color: '#666',
stops: [],
Expand Down Expand Up @@ -178,6 +180,10 @@ class Line extends React.Component {
// eslint-disable-next-line promise/prefer-await-to-then
.then(shape => {
this.setState({ isShapeLoaded: true })
if (this.interpolatedShape) {
this.layer.hide(true, true)
this.layer = new Layer()
}
return renderShape(shape, this.layer, route.route_color)
})
.catch(() => this.interpolateShape()) // failed to get a shape, so we'll interpolate one
Expand Down Expand Up @@ -386,7 +392,7 @@ class Line extends React.Component {
type: 'LineString',
coordinates: this.tripStops.map(stop => [stop.stop_lon, stop.stop_lat]),
}
renderShape(
this.interpolatedShape = renderShape(
{ ...shape, ...this.lineData.getShapeBounds(shape) },
this.layer,
color
Expand Down
14 changes: 12 additions & 2 deletions js/views/lines/LineStops.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ export const LineStops = ({
let selectedStopIndex = 0
let afterSelectedStop = false
if (selectedStop) {
selectedStopIndex = stops.findIndex(a => a.stop_id === selectedStop)
selectedStopIndex = stops.findIndex(
a => a.stop_id === selectedStop || a.parent_station === selectedStop
)
// if it couldn't find it for whatever reason
if (selectedStopIndex === -1) {
selectedStopIndex = 0
afterSelectedStop = true
}
} else if (stops.length > 0) {
afterSelectedStop = true
}
Expand Down Expand Up @@ -68,7 +75,10 @@ export const LineStops = ({
) : null}
<View style={styles.wrapper}>
{stops.map((stop, index) => {
if (selectedStop === stop.stop_id) {
if (
selectedStop === stop.stop_id ||
selectedStop === stop.parent_station
) {
afterSelectedStop = true
}
if (!showAll && !afterSelectedStop) return null
Expand Down
2 changes: 1 addition & 1 deletion js/views/lines/lineCommon.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { t } from '../../stores/translationStore.js'
import UiStore from '../../stores/UiStore.js'

export const renderShape = async (shape, layer, routeColor) => {
export const renderShape = (shape, layer, routeColor) => {
layer.add('geojson', shape, {
color: routeColor,
className: 'metro-line',
Expand Down

0 comments on commit a200743

Please sign in to comment.