Skip to content

Commit

Permalink
fix(geocoder): Fix geocoder issues from using two different ones.
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorgerhardt committed Mar 13, 2017
1 parent 9cac9ba commit 3e999bc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 72 deletions.
7 changes: 4 additions & 3 deletions src/actions/browsochrones.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
} from '@conveyal/woonerf/fetch'
import Browsochrones from 'browsochrones'
import fetch from 'isomorphic-fetch'
import {search as geocode} from 'isomorphic-mapzen-search'

import {getAsObject as getHash} from '../utils/hash'
import {geocode} from '../utils/mapbox-geocoder'
import messages from '../utils/messages'

import {
Expand Down Expand Up @@ -70,13 +70,14 @@ function geocodeQs ({
.map(async (p) => {
if (qs[p]) {
const results = await geocode({
apiKey: process.env.MAPZEN_SEARCH_KEY,
boundary: geocoder.boundary,
focusLatlng: geocoder.focusLatlng,
focusPoint: geocoder.focusLatlng,
text: qs[p]
})
if (results.features.length > 0) {
return {
label: results.features[0].place_name,
label: results.features[0].properties.label,
latlng: lonlat(results.features[0].geometry.coordinates)
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import lonlat from '@conveyal/lonlat'
import Leaflet from 'leaflet'
import {createAction} from 'redux-actions'

import fetch, {
incrementFetches as incrementWork,
decrementFetches as decrementWork
} from '@conveyal/woonerf/fetch'
import {reverse} from 'isomorphic-mapzen-search'
import Leaflet from 'leaflet'
import {createAction} from 'redux-actions'

import featureToLabel from '../utils/feature-to-label'
import {setKeyTo} from '../utils/hash'
import {reverse} from '../utils/mapbox-geocoder'

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

const reverseGeocode = ({latlng}) => reverse(process.env.MAPBOX_ACCESS_TOKEN, latlng)
const reverseGeocode = ({latlng}) => reverse({
apiKey: process.env.MAPZEN_SEARCH_KEY,
point: latlng
})

export const addActionLogItem = createAction('add action log item', (item) => {
const payload = typeof item === 'string'
Expand Down Expand Up @@ -114,7 +115,7 @@ export function updateStart ({
reverseGeocode({latlng})
.then(({features}) => {
if (!features || features.length < 1) return
const label = featureToLabel(features[0])
const label = features[0].properties.label
return [
addActionLogItem(`Set start address to: ${label}`),
setStartLabel(label)
Expand Down Expand Up @@ -312,7 +313,7 @@ export function updateEnd ({
actions.push(
setEnd({latlng}),
reverseGeocode({latlng})
.then(({features}) => setEndLabel(featureToLabel(features[0])))
.then(({features}) => setEndLabel(features[0].properties.label))
)
}

Expand Down
5 changes: 0 additions & 5 deletions src/components/form.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Pure from '@conveyal/woonerf/components/pure'
import React from 'react'
import Geocoder from 'react-select-geocoder'
import featureToLabel from '../utils/feature-to-label'
import messages from '../utils/messages'

export default class Form extends Pure {
Expand All @@ -20,8 +19,6 @@ export default class Form extends Pure {
<Geocoder
apiKey={process.env.MAPZEN_SEARCH_KEY}
{...geocoder}
featureToLabel={featureToLabel}
featureToValue={(f) => f.id}
name='start-address'
onChange={onChangeStart}
placeholder={messages.Geocoding.StartPlaceholder}
Expand All @@ -36,8 +33,6 @@ export default class Form extends Pure {
<Geocoder
apiKey={process.env.MAPZEN_SEARCH_KEY}
{...geocoder}
featureToLabel={featureToLabel}
featureToValue={(f) => f.id}
name='end-address'
onChange={onChangeEnd}
placeholder={messages.Geocoding.EndPlaceholder}
Expand Down
10 changes: 0 additions & 10 deletions src/utils/feature-to-label.js

This file was deleted.

46 changes: 0 additions & 46 deletions src/utils/mapbox-geocoder.js

This file was deleted.

0 comments on commit 3e999bc

Please sign in to comment.