Skip to content

Commit

Permalink
fix(manager): handle invalid bounds in feed version map
Browse files Browse the repository at this point in the history
fixes #150
  • Loading branch information
landonreed committed May 15, 2018
1 parent 15bc8b2 commit 00dbafe
Showing 1 changed file with 80 additions and 74 deletions.
154 changes: 80 additions & 74 deletions lib/gtfs/components/GtfsMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import PatternGeoJson from './PatternGeoJson'
import StopMarker from './StopMarker'
import { getFeedsBounds } from '../../common/util/geo'

const DEFAULT_BOUNDS = [[70, 130], [-70, -130]]

export default class GtfsMap extends Component {
static propTypes = {
bounds: PropTypes.array,
Expand Down Expand Up @@ -35,7 +37,7 @@ export default class GtfsMap extends Component {
}

state = {
bounds: this.props.bounds || [[70, 130], [-70, -130]],
bounds: this.props.bounds || DEFAULT_BOUNDS,
map: {}
}

Expand All @@ -47,7 +49,7 @@ export default class GtfsMap extends Component {
setTimeout(() => {
if (this.refs.map) {
this.refs.map.leafletElement.invalidateSize()
resetBounds && this.refs.map.leafletElement.fitBounds(this.getBounds())
resetBounds && this.refs.map.leafletElement.fitBounds(this._getBounds())
}
}, 500)
}
Expand Down Expand Up @@ -110,15 +112,20 @@ export default class GtfsMap extends Component {
}
}

getBounds () {
_boundsAreValid = bounds => bounds && bounds.north && !isNaN(bounds.north)

_getBounds () {
let bounds
if (this.props.feeds) {
bounds = getFeedsBounds(this.props.feeds)
} else if (this.props.version) {
bounds = this.props.version.validationSummary.bounds
}
bounds = bounds && bounds.north ? [[bounds.north, bounds.east], [bounds.south, bounds.west]] : this.state.bounds
return bounds
if (this._boundsAreValid(bounds)) {
return [[bounds.north, bounds.east], [bounds.south, bounds.west]]
} else {
return this.state.bounds
}
}

fetchIsochrones (latlng) {
Expand Down Expand Up @@ -236,94 +243,93 @@ export default class GtfsMap extends Component {
const MAPBOX_MAP_ID = process.env.MAPBOX_MAP_ID
const MAPBOX_ACCESS_TOKEN = process.env.MAPBOX_ACCESS_TOKEN
const MAPBOX_ATTRIBUTION = process.env.MAPBOX_ATTRIBUTION
const bounds = this._getBounds()
return (
<div>
<Map
ref='map'
style={mapStyle}
bounds={mapState.bounds}
zoom={mapState.zoom}
scrollWheelZoom={!disableScroll}
onClick={this.mapClicked}
onMoveEnd={this.mapMoved}
onLayerAdd={this.layerAddHandler}
className='Gtfs-Map'>
<TileLayer
url={`https://api.tiles.mapbox.com/v4/${MAPBOX_MAP_ID}/{z}/{x}/{y}${Browser.retina ? '@2x' : ''}.png?access_token=${MAPBOX_ACCESS_TOKEN}`}
attribution={MAPBOX_ATTRIBUTION} />
{/* feed bounds */}
{showBounds &&
<Rectangle
bounds={this.getBounds()}
fillOpacity={0} />
}

{/* Stops from map bounds search */}
{showStops && stops && stops.length && <FeatureGroup ref='stops'>
{stops.map((s, index) => {
if (!s) return null
return (
<StopMarker
stop={s}
routes={routes}
key={`marker-${s.stop_id}`}
feeds={feeds}
renderTransferPerformance={renderTransferPerformance}
onStopClick={onStopClick}
newEntityId={newEntityId}
popupAction={popupAction}
/>
)
})}
</FeatureGroup>}
<Map
ref='map'
style={mapStyle}
bounds={mapState.bounds}
zoom={mapState.zoom}
scrollWheelZoom={!disableScroll}
onClick={this.mapClicked}
onMoveEnd={this.mapMoved}
onLayerAdd={this.layerAddHandler}
className='Gtfs-Map'>
<TileLayer
url={`https://api.tiles.mapbox.com/v4/${MAPBOX_MAP_ID}/{z}/{x}/{y}${Browser.retina ? '@2x' : ''}.png?access_token=${MAPBOX_ACCESS_TOKEN}`}
attribution={MAPBOX_ATTRIBUTION} />
{/* Feed version bounding box (show if not set to default indicating invalid version bounds) */}
{showBounds && bounds !== DEFAULT_BOUNDS &&
<Rectangle
bounds={bounds}
fillOpacity={0} />
}

{/* Stop from GtfsSearch */}
{stop && (
<FeatureGroup>
{/* Stops from map bounds search */}
{showStops && stops && stops.length && <FeatureGroup ref='stops'>
{stops.map((s, index) => {
if (!s) return null
return (
<StopMarker
stop={stop}
stop={s}
routes={routes}
key={`marker-${s.stop_id}`}
feeds={feeds}
renderTransferPerformance={renderTransferPerformance}
onStopClick={onStopClick}
newEntityId={newEntityId}
popupAction={popupAction}
/>
</FeatureGroup>
)}
)
})}
</FeatureGroup>}

{/* Group of Patterns from search */}
{showPatterns && displayedPatterns && displayedPatterns.length && (
<FeatureGroup>
{displayedPatterns.map((pattern, index) => (
<PatternGeoJson
pattern={pattern}
key={pattern.pattern_id}
feeds={feeds}
index={index}
onRouteClick={onRouteClick}
newEntityId={newEntityId}
popupAction={popupAction} />
))}
</FeatureGroup>
)}
{/* Stop from GtfsSearch */}
{stop && (
<FeatureGroup>
<StopMarker
stop={stop}
routes={routes}
feeds={feeds}
renderTransferPerformance={renderTransferPerformance}
onStopClick={onStopClick}
newEntityId={newEntityId}
popupAction={popupAction}
/>
</FeatureGroup>
)}

{/* Single Pattern from GtfsSearch */}
{pattern &&
<FeatureGroup>
{/* Group of Patterns from search */}
{showPatterns && displayedPatterns && displayedPatterns.length && (
<FeatureGroup>
{displayedPatterns.map((pattern, index) => (
<PatternGeoJson
pattern={pattern}
key={pattern.pattern_id}
feeds={feeds}
index={index}
onRouteClick={onRouteClick}
newEntityId={newEntityId}
popupAction={popupAction} />
</FeatureGroup>
}
))}
</FeatureGroup>
)}

{/* Single Pattern from GtfsSearch */}
{pattern &&
<FeatureGroup>
<PatternGeoJson
pattern={pattern}
feeds={feeds}
onRouteClick={onRouteClick}
newEntityId={newEntityId}
popupAction={popupAction} />
</FeatureGroup>
}

{/* Isochrones from map click */}
{showIsochrones && this.renderIsochrones(isochroneBand, version)}
</Map>
</div>
{/* Isochrones from map click */}
{showIsochrones && this.renderIsochrones(isochroneBand, version)}
</Map>
)
}
}

0 comments on commit 00dbafe

Please sign in to comment.