Skip to content

Commit

Permalink
fix(isochrone): Fix the isochrone rednering problem
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorgerhardt committed May 3, 2018
1 parent bbe40db commit 255756f
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 57 deletions.
56 changes: 40 additions & 16 deletions src/components/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
UIStore
} from '../types'
import {getAsObject} from '../utils/hash'
import downloadJson from '../utils/download-json'

import Form from './form'
import Gridualizer from './gridualizer'
Expand Down Expand Up @@ -77,15 +78,16 @@ type State = {
componentError: any
}

const getStyle = color => ({
const getStyle = color => () => ({
fillColor: color,
fillOpacity: 0.4,
pointerEvents: 'none',
stroke: color,
weight: 1
})

const BASE_ISOCHRONE_STYLE = getStyle('#4269a4')
const COMP_ISOCHRONE_STYLE = getStyle('darkorange')
const COMP_ISOCHRONE_STYLE = getStyle('#ff8c00')

/**
*
Expand Down Expand Up @@ -196,6 +198,21 @@ export default class Application extends Component<Props, State> {

_setActiveNetwork = memoize(name => () => this.props.setActiveNetwork(name))

_downloadIsochrone = memoize(index => () => {
const p = this.props
const isochrone = p.isochrones[index]
if (isochrone) {
const name = p.data.networks[index].name
const ll = lonlat.toString(p.geocoder.start.position)
downloadJson({
data: isochrone,
filename: `${name}-${ll}-${p.timeCutoff.selected}min-isochrone.json`
})
} else {
window.alert('No isochrone has been generated for this network.')
}
})

/**
*
*/
Expand Down Expand Up @@ -245,16 +262,21 @@ export default class Application extends Component<Props, State> {
{drawActiveOpportunityDataset &&
<Gridualizer drawTile={drawActiveOpportunityDataset} />}

{!isLoading &&
<div>
{isochrones[0] &&
<GeoJSON data={isochrones[0]} key={isochrones[0].key} style={BASE_ISOCHRONE_STYLE} />}
{!isLoading && isochrones[0] &&
<GeoJSON
data={isochrones[0]}
key={isochrones[0].key}
style={BASE_ISOCHRONE_STYLE}
/>}

{comparisonIsochrone &&
<GeoJSON data={comparisonIsochrone} key={comparisonIsochrone.key} style={COMP_ISOCHRONE_STYLE} />}
{!isLoading && comparisonIsochrone &&
<GeoJSON
data={comparisonIsochrone}
key={comparisonIsochrone.key}
style={COMP_ISOCHRONE_STYLE}
/>}

<TransitiveLayer data={activeTransitive} />
</div>}
{!isLoading && <TransitiveLayer data={activeTransitive} />}
</Map>
</div>
<Dock showSpinner={ui.fetches > 0} componentError={componentError}>
Expand All @@ -274,9 +296,10 @@ export default class Application extends Component<Props, State> {
<RouteCard
active={network.active}
alternate={index !== 0}
downloadIsochrone={this._downloadIsochrone(index)}
isLoading={isLoading}
key={`${index}-route-card`}
onClick={this._setActiveNetwork(network.name)}
showIsochrone={this._setActiveNetwork(network.name)}
title={network.name}
>
{!isLoading &&
Expand Down Expand Up @@ -304,14 +327,15 @@ export default class Application extends Component<Props, State> {
</div>}
{ui.allowChangeConfig &&
<div className='Card'>
<a
<div
className='CardTitle'
tabIndex={0}
onClick={this._updateConfig}
>
<span className='fa fa-cog' /> Configure
<span className='pull-right'>save changes</span>
</a>
<a
className='pull-right'
onClick={this._updateConfig}
>save changes</a>
</div>
<div className='CardContent'>
<br /><a href='https://github.com/conveyal/taui/blob/aa9e6285002d59b4b6ae38890229569311cc4b6d/config.json.tmp' target='_blank'>See example config</a>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/components/geojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ export default class GeoJSON extends MapLayer {
})
}
}

1 change: 0 additions & 1 deletion src/components/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ import React from 'react'
export default function Icon ({type}) {
return <span className={`fa fa-${type}`} />
}

11 changes: 9 additions & 2 deletions src/components/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const TILE_URL = Leaflet.Browser.retina && process.env.LEAFLET_RETINA_URL
? process.env.LEAFLET_RETINA_URL
: process.env.LEAFLET_TILE_URL

const LABEL_URL = process.env.LABEL_URL

const TILE_LAYER_PROPS = {}
if (Leaflet.Browser.retina) {
TILE_LAYER_PROPS.tileSize = 512
Expand Down Expand Up @@ -177,18 +179,23 @@ export default class Map extends PureComponent<Props, State> {
onZoomend={this._setZoom}
zoom={zoom}
onClick={this._onMapClick}
preferCanvas
zoomControl={false}
>
<ZoomControl position='topright' />
<TileLayer
url={TILE_URL}
attribution={process.env.LEAFLET_ATTRIBUTION}
{...TILE_LAYER_PROPS}
/>

{children}

{LABEL_URL &&
<TileLayer
attribution={process.env.LEAFLET_ATTRIBUTION}
url={LABEL_URL}
zIndex={40}
/>}

{(!start || !end) &&
pointsOfInterest.length > 0 &&
<GeoJSON
Expand Down
1 change: 0 additions & 1 deletion src/components/route-access.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @flow
import Icon from '@conveyal/woonerf/components/icon'
import message from '@conveyal/woonerf/message'
import toSpaceCase from 'lodash/lowerCase'

Expand Down
28 changes: 18 additions & 10 deletions src/components/route-card.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @flow
import Icon from '@conveyal/woonerf/components/icon'
import message from '@conveyal/woonerf/message'
import React from 'react'

type Props = {
Expand All @@ -17,7 +16,8 @@ export default class RouteCard extends React.PureComponent<Props> {
active,
alternate,
children,
onClick,
downloadIsochrone,
showIsochrone,
title
} = this.props
return (
Expand All @@ -28,17 +28,25 @@ export default class RouteCard extends React.PureComponent<Props> {
(active ? ' Card-active' : '')
}
>
<a
<div
className='CardTitle'
onClick={onClick}
tabIndex={0}
title='Set network active'
>
{title}
<span className='pull-right'>
{active ? <Icon type='map' /> : message('Systems.Show')}
</span>
</a>
<a
className='pull-right'
onClick={showIsochrone}
title='Show/hide isochrone for network'
>
{active ? <Icon type='eye-slash' /> : <Icon type='eye' />}
</a>
<a
className='pull-right'
onClick={downloadIsochrone}
title='Download GeoJSON isochrone for network'
>
<Icon type='download' />
</a>
</div>
<table className='CardContent'>{children}</table>
</div>
)
Expand Down
3 changes: 2 additions & 1 deletion src/components/route-segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function RouteSegments ({routeSegments, oldTravelTime, travelTime
return (
<tbody>
<tr className='BestTrip'>
<td><span className='fa fa-tachometer' /></td>
<td><span className='fa fa-street-view' /></td>
<td>
<span>Take </span>
{bestJourney.map((segment, index) => (
Expand Down Expand Up @@ -55,6 +55,7 @@ const Segment = ({segment}) => (
backgroundColor: segment.backgroundColor || 'inherit',
color: segment.color || 'inherit'
}}
title={segment.name}
>
<i className={`fa fa-${segment.type}`} /> {segment.name}
</span>
Expand Down
42 changes: 23 additions & 19 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,23 @@ html, body {
}

.Card-alternate .CardTitle {
background-color: orange;
background-color: #ff8c00;
}

.CardTitle {
background-color: #4269a4;
color: rgba(255, 255, 255);
padding: 0.5rem 1rem;
padding: 1rem 0.5rem 1rem 1rem;
font-weight: var(--bold);
}

.CardTitle > a {
cursor: pointer;
display: block;
padding: 0 0.5rem;
}

.CardTitle:focus {
outline: none;
.CardTitle > a:hover {
color: #D0021B;
}

.Card-active > .CardTitle {
Expand All @@ -193,20 +196,21 @@ html, body {
}

table.CardContent {
padding: 0;
border-spacing: 1rem 0.75rem;
padding: 0.25rem 0;
border-spacing: 1rem 0.5rem;
line-height: 1.5rem;
}

table.CardContent td {
vertical-align: top;
}

.CardContent .alert {
color: #c92336;
table.CardContent td:first-of-type {
text-align: center;
}

.BestTrip {
margin-bottom: 1rem;
.CardContent .alert {
color: #c92336;
}

.Attribution {
Expand All @@ -227,10 +231,15 @@ table.CardContent td {

.CardSegment {
font-size: 0.75rem;
padding: 0.25rem;
padding: 0 0.25rem;
border-radius: var(--rad);
margin-right: 0.25rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 40px;
margin-bottom: -6px;
display: inline-block;
}

.Card .increase {
Expand All @@ -241,11 +250,6 @@ table.CardContent td {
color: red;
}

.AlternateTrips {
margin: 0 0 0.75em;
line-height: 1.5em;
}

.leaflet-popup-content-wrapper,
.map-legends,
.map-tooltip {
Expand Down Expand Up @@ -335,11 +339,11 @@ table.CardContent td {
}

.LeafletIcon.End {
background-color: orange;
background-color: #ff8c00;
}

.LeafletIcon.End:before {
border-top: 20px solid orange;
border-top: 20px solid #ff8c00;
}

.LeafletIcon.End:after {
Expand Down
1 change: 0 additions & 1 deletion src/selectors/active-opportunity-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ export default createSelector(
(state) => state.data.grids,
(grids) => grids[0]
)

1 change: 0 additions & 1 deletion src/selectors/draw-active-opportunity-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ export default createSelector(
interpolator: gridualizer.interpolators.bicubic
})
)

30 changes: 30 additions & 0 deletions src/selectors/draw-isochrones.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @flow
import gdlz from '@conveyal/gridualizer'
import {createSelector} from 'reselect'
import get from 'lodash/get'

const colors = [
'rgba(0, 0, 0, 0.0)',
'rgba(66, 105, 164, 0.2)',
'rgba(66, 105, 164, 0.4)',
'rgba(66, 105, 164, 0.6)',
'rgba(66, 105, 164, 0.8)'
]

colors.reverse()

export default createSelector(
state => get(state, 'data.networks'),
(networks = []) =>
networks.map(n => {
if (n.travelTimeSurface && n.travelTimeSurface.data) {
const eq = gdlz.classifiers.equal()
const breaks = eq({min: 0, max: 120}, colors.length)
return gdlz.createDrawTile({
colorizer: gdlz.colorizers.choropleth(breaks, colors),
grid: n.travelTimeSurface,
interpolator: gdlz.interpolators.spline
})
}
})
)
1 change: 1 addition & 0 deletions src/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export {default as activeNetworkIndex} from './active-network-index'
export {default as activeTransitive} from './active-transitive'
export {default as allTransitiveData} from './all-transitive-data'
export {default as drawActiveOpportunityDataset} from './draw-active-opportunity-dataset'
export {default as drawIsochrones} from './draw-isochrones'
export {default as isochrones} from './isochrones'
export {default as loading} from './loading'
export {default as pointsOfInterest} from './points-of-interest'
Expand Down

0 comments on commit 255756f

Please sign in to comment.