Skip to content

Commit d4a2c2b

Browse files
committed
feat(geocoding): use custom pelias instance and focusPoint
fixes ibi-group/trimet-mod-otp#2 and ibi-group/trimet-mod-otp#3
1 parent 333ded5 commit d4a2c2b

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

example-config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ geocoder:
2222
minLat: 45.273
2323
maxLat: 45.7445
2424
MAPZEN_KEY: MAPZEN_KEY
25+
focusPoint:
26+
lat: 45.5223452
27+
lon: -122.6821804
28+
# Optional custom Pelias instance (defaults to Mapzen Search)
29+
# baseUrl: https://geocoder.example.com/pelias/v1
2530

2631
modeGroups:
2732
- name: Transit

lib/actions/map.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ export function setLocation (payload) {
3030
const otpState = getState().otp
3131
// reverse geocode point location if requested
3232
if (payload.reverseGeocode) {
33-
console.log(otpState)
34-
const apiKey = otpState.config.geocoder.MAPZEN_KEY
33+
const {MAPZEN_KEY, baseUrl} = otpState.config.geocoder
3534
const {location: point} = payload
3635
reverse({
37-
apiKey,
36+
apiKey: MAPZEN_KEY,
3837
point,
39-
format: true
38+
format: true,
39+
url: baseUrl ? `${baseUrl}/reverse` : null
4040
}).then((json) => {
4141
console.log(json[0].address)
4242
// override location name if reverse geocode is successful

lib/components/form/location-field.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ class LocationField extends Component {
6161
}
6262

6363
_geocode (text) {
64-
const { config } = this.props
64+
const {MAPZEN_KEY, baseUrl, boundary, focusPoint} = this.props.config.geocoder
6565
autocomplete({
66-
apiKey: config.geocoder.MAPZEN_KEY,
67-
boundary: config.geocoder.boundary,
68-
// TODO: use current location as focus point
69-
text
66+
apiKey: MAPZEN_KEY,
67+
boundary,
68+
focusPoint,
69+
text,
70+
url: baseUrl ? `${baseUrl}/autocomplete` : null
7071
}).then((result) => {
7172
console.log(result)
7273
this.setState({ geocodedFeatures: result.features })

0 commit comments

Comments
 (0)