Skip to content

Commit

Permalink
Merge pull request #104 from conveyal/add-preloaded-locations
Browse files Browse the repository at this point in the history
Points of interest
  • Loading branch information
trevorgerhardt committed May 31, 2017
2 parents 12ea1a6 + 7831e64 commit e1a8f2c
Show file tree
Hide file tree
Showing 40 changed files with 2,514 additions and 1,504 deletions.
4 changes: 4 additions & 0 deletions configurations/default/messages.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Systems:
CalculatingAccessibility: Calculating accessibility...
SelectStart: Select a location to see accessibility
SelectEnd: Select an endpoint to see possible trips
Show: show
AccessTitle: Access to
BaseTitle: Proposed Transit
ComparisonTitle: Current Transit
Expand Down
15 changes: 10 additions & 5 deletions configurations/default/store.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ browsochrones:
- Jobs_total
- Workers_total
origins:
- https://dz69bcpxxuhn6.cloudfront.net/indy-baseline-v6
- https://dz69bcpxxuhn6.cloudfront.net/indyconnect-marion-v6
- https://dz69bcpxxuhn6.cloudfront.net/indyconnect-marion-v6
destinations:
accessibility: []
- name: Baseline
url: https://dz69bcpxxuhn6.cloudfront.net/indy-baseline-v6
- name: Marion
url: https://dz69bcpxxuhn6.cloudfront.net/indyconnect-marion-v6
destinations: []
geocoder:
focusLatlng:
lat: 39.7691
Expand All @@ -22,6 +22,11 @@ geocoder:
maxLon: -85.462646484375
minLat: 39.35978526869001
minLon: -86.8524169921875
pointsOfInterest:
- name: Location 1
coordinates: [-86.1570, 39.7691]
- name: Location 2
coordinates: [-86.1580, 39.7681]
map:
active: 0
centerCoordinates: [39.7691, -86.1570]
Expand Down
7 changes: 7 additions & 0 deletions configurations/test/env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BROWSOCHRONES_BASE_URL:
LEAFLET_TILE_URL:
LEAFLET_RETINA_URL:
LEAFLET_ATTRIBUTION:
MAPBOX_ACCESS_TOKEN:
MAPZEN_SEARCH_KEY:

24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"scripts": {
"build": "mastarm build",
"deploy": "mastarm deploy --env production --minify",
"predeploy": "yarn",
"prestart": "yarn",
"pretest": "yarn",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"start": "mastarm build --serve --env development",
"test": "mastarm lint && mastarm flow && mastarm test --env test"
"test": "mastarm lint && mastarm flow && mastarm test --env test --config configurations/test"
},
"repository": {
"type": "git",
Expand All @@ -28,35 +29,34 @@
"devDependencies": {
"enzyme": "^2.8.2",
"enzyme-to-json": "^1.5.1",
"flow-bin": "^0.45.0",
"mastarm": "^3.8.0",
"mastarm": "^3.9.3",
"react-addons-test-utils": "^15.5.1",
"redux-mock-store": "^1.2.3",
"semantic-release": "^6.3.2"
},
"dependencies": {
"@conveyal/lonlat": "^1.1.1",
"@conveyal/woonerf": "^2.1.0",
"@conveyal/woonerf": "^2.3.0",
"browsochrones": "^0.9.1",
"color": "^1.0.3",
"debug": "^2.6.1",
"date-fns": "^1.28.5",
"debug": "^2.6.8",
"font-awesome": "^4.6.3",
"isomorphic-fetch": "^2.2.1",
"isomorphic-mapzen-search": "^1.2.0",
"leaflet": "^0.7.7",
"leaflet-transitivelayer": "^0.2.0",
"lodash": "^4.17.4",
"mapbox.js": "^2.4.0",
"moment": "^2.17.1",
"normalize.css": "^5.0.0",
"qs": "^6.3.1",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"normalize.css": "^7.0.0",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-leaflet": "^0.12.2",
"react-redux": "^5.0.2",
"react-redux": "^5.0.5",
"react-select-geocoder": "^1.2.0",
"redux": "^3.6.0",
"redux-actions": "^1.2.1",
"redux-actions": "^2.0.3",
"reselect": "^3.0.1",
"transitive-js": "^0.9.2"
},
"standard": {
Expand Down
77 changes: 46 additions & 31 deletions src/actions/browsochrones.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import lonlat from '@conveyal/lonlat'
import {decrementFetches, incrementFetches} from '@conveyal/woonerf/fetch'
import Browsochrones from 'browsochrones'
Expand All @@ -19,7 +20,14 @@ import {
setStartLabel
} from '../actions'

export default function initialize ({browsochrones, geocoder, map}) {
import type {Store} from '../types'

export default function initialize ({
browsochrones,
geocoder,
map,
timeCutoff
}: Store) {
const {origins} = browsochrones
const qs = getHash()
return [
Expand All @@ -38,14 +46,17 @@ export default function initialize ({browsochrones, geocoder, map}) {
if (end) actions.push(setEnd(end))
actions.push(
fetchGrids(browsochrones)
.then(grids => loadAllOrigins({grids, origins}))
.then(grids =>
loadAllOrigins({grids, origins, gridNames: browsochrones.grids})
)
.then(instances => [
setBrowsochronesInstances(instances),
start &&
fetchAllBrowsochrones({
browsochronesInstances: instances,
endLatlng: end && end.latlng,
latlng: start.latlng,
timeCutoff: timeCutoff.selected,
zoom: map.zoom
}),
addActionLogItem(messages.Strings.ApplicationReady),
Expand All @@ -57,47 +68,49 @@ export default function initialize ({browsochrones, geocoder, map}) {
]
}

function geocodeQs ({geocoder, qs}) {
return Promise.all(
['start', 'end'].map(async p => {
if (qs[p]) {
const results = await geocode({
apiKey: process.env.MAPZEN_SEARCH_KEY,
boundary: geocoder.boundary,
focusPoint: geocoder.focusLatlng,
text: qs[p]
})
if (results.features.length > 0) {
return {
label: results.features[0].properties.label,
latlng: lonlat(results.features[0].geometry.coordinates)
}
async function geocodeQs ({geocoder, qs}) {
async function geocodeP (p) {
if (qs[p]) {
const results = await geocode({
apiKey: process.env.MAPZEN_SEARCH_KEY,
boundary: geocoder.boundary,
focusPoint: geocoder.focusLatlng,
text: qs[p]
})
if (results.features.length > 0) {
return {
label: results.features[0].properties.label,
latlng: lonlat(results.features[0].geometry.coordinates)
}
}
})
)
}
}
return [await geocodeP('start'), await geocodeP('end')]
}

function fetchGrids ({grids, gridsUrl}) {
function fetchGrids ({
grids,
gridsUrl
}: {
grids: string[],
gridsUrl: string
}): Promise<ArrayBuffer[]> {
return Promise.all(
grids.map(async name => {
const res = await fetch(`${gridsUrl}/${name}.grid`)
const grid = await res.arrayBuffer()
grid.name = name
return grid
})
grids.map(name =>
fetch(`${gridsUrl}/${name}.grid`).then(r => r.arrayBuffer())
)
)
}

function loadAllOrigins ({grids, origins}) {
return Promise.all(origins.map(origin => load(origin, grids)))
function loadAllOrigins ({grids, origins, gridNames}) {
return Promise.all(origins.map(origin => load(origin, grids, gridNames)))
}

async function load (origin, grids) {
async function load (origin, grids, gridNames) {
const bs = new Browsochrones()
bs.name = origin.name
bs.originsUrl = origin.url
bs.grids = grids.map(g => g.name)
bs.grids = gridNames
const fetches = [
fetch(`${origin.url}/query.json`).then(res => res.json()),
fetch(`${origin.url}/stop_trees.dat`).then(res => res.arrayBuffer())
Expand All @@ -107,7 +120,9 @@ async function load (origin, grids) {
await bs.setStopTrees(stopTrees)
await bs.setTransitiveNetwork(query.transitiveData)

const putGrids = grids.map(grid => bs.putGrid(grid.name, grid))
const putGrids = grids.map((grid, index) =>
bs.putGrid(gridNames[index], grid)
)
await Promise.all(putGrids)

return bs
Expand Down
37 changes: 35 additions & 2 deletions src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// @flow
import lonlat from '@conveyal/lonlat'
import type Browsochrones from 'browsochrones'
import fetch, {
incrementFetches as incrementWork,
decrementFetches as decrementWork
Expand All @@ -9,6 +11,8 @@ import {createAction} from 'redux-actions'

import {setKeyTo} from '../utils/hash'

import type {LatLng} from '../types'

const END = 'end'
const START = 'start'

Expand Down Expand Up @@ -96,6 +100,13 @@ export function updateStart ({
label,
timeCutoff,
zoom
}: {
browsochronesInstances: Browsochrones[],
endLatlng: LatLng,
latlng: LatLng,
label: string,
timeCutoff: number,
zoom: number
}) {
const actions = [
addActionLogItem('Generating origins...'),
Expand Down Expand Up @@ -135,7 +146,9 @@ export function updateStart ({
)
}

if (!browsochronesInstances || browsochronesInstances.length === 0) { return actions }
if (!browsochronesInstances || browsochronesInstances.length === 0) {
return actions
}

actions.push(
fetchAllBrowsochrones({
Expand All @@ -156,6 +169,12 @@ export function fetchAllBrowsochrones ({
latlng,
timeCutoff,
zoom
}: {
browsochronesInstances: Browsochrones[],
endLatlng?: LatLng,
latlng: LatLng,
timeCutoff: number,
zoom: number
}) {
const point = Leaflet.CRS.EPSG3857.latLngToPoint(
lonlat.toLeaflet(latlng),
Expand Down Expand Up @@ -289,7 +308,15 @@ function generateDestinationDataFor ({
]
}

export function updateSelectedTimeCutoff ({browsochrones, latlng, timeCutoff}) {
export function updateSelectedTimeCutoff ({
browsochrones,
latlng,
timeCutoff
}: {
browsochrones: Browsochrones,
latlng: LatLng,
timeCutoff: number
}) {
const actions = [setSelectedTimeCutoff(timeCutoff)]

browsochrones.instances.map((instance, index) => {
Expand Down Expand Up @@ -329,6 +356,12 @@ export function updateEnd ({
latlng,
label,
zoom
}: {
browsochronesInstances: Browsochrones[],
startLatlng: LatLng,
latlng: LatLng,
label: string,
zoom: number
}) {
const actions = []

Expand Down
Loading

0 comments on commit e1a8f2c

Please sign in to comment.