Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 786f690

Browse files
committedMar 7, 2022
feat(valhalla): allow graphhopper to avoid road classes
1 parent 3b87118 commit 786f690

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed
 

‎lib/scenario-editor/utils/valhalla.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import fetch from 'isomorphic-fetch'
44
import {decode as decodePolyline} from 'polyline'
55
import {isEqual as coordinatesAreEqual} from '@conveyal/lonlat'
6-
import qs from 'qs'
76
import lineString from 'turf-linestring'
87

98
// This can be used for logging line strings to geojson.io URLs for easy
@@ -204,14 +203,27 @@ export function routeWithGraphHopper (points: Array<LatLng>): ?Promise<GraphHopp
204203
}
205204
// Use custom url if it exists, otherwise default to the hosted service.
206205
const GRAPH_HOPPER_URL = process.env.GRAPH_HOPPER_URL || 'https://graphhopper.com/api/1/'
207-
const params = {
208-
key: process.env.GRAPH_HOPPER_KEY,
209-
vehicle: 'car',
210-
debug: true,
211-
type: 'json'
212-
}
213-
const locations = points.map(p => (`point=${p.lat},${p.lng}`)).join('&')
206+
214207
return fetch(
215-
`${GRAPH_HOPPER_URL}route?${locations}&${qs.stringify(params)}`
208+
`${GRAPH_HOPPER_URL}route?key=${process.env.GRAPH_HOPPER_KEY}`,
209+
// New custom routing headers
210+
{
211+
method: 'POST',
212+
headers: {
213+
'Content-Type': 'application/json'
214+
},
215+
body: JSON.stringify({
216+
'ch.disable': true,
217+
custom_model: {
218+
'priority': [{
219+
'if': 'road_class == MOTORWAY',
220+
'multiply_by': 0.1
221+
}]
222+
},
223+
key: process.env.GRAPH_HOPPER_KEY,
224+
points: points.map(p => [p.lng, p.lat]),
225+
profile: 'car'
226+
})
227+
}
216228
).then(res => res.json())
217229
}

0 commit comments

Comments
 (0)
Please sign in to comment.