diff --git a/configurations/default/env.yml.tmp b/configurations/default/env.yml.tmp index cd33e6772..8671f80de 100644 --- a/configurations/default/env.yml.tmp +++ b/configurations/default/env.yml.tmp @@ -11,6 +11,8 @@ SLACK_WEBHOOK: optional-slack-webhook GRAPH_HOPPER_KEY: your-graph-hopper-key # Optional override to use a custom service instead of the graphhopper.com hosted service. # GRAPH_HOPPER_URL: http://localhost:8989/ +# If your'e hosting a version 7 graphhopper instance set this to yes, default is false or not configured +# GRAPH_HOPPER_V7: true # Optional overrides to use custom service or different api key for certain bounding boxes. # (uncomment below to enable) # GRAPH_HOPPER_ALTERNATES: diff --git a/lib/scenario-editor/utils/valhalla.js b/lib/scenario-editor/utils/valhalla.js index 408a8cec5..2cb9dc7ec 100644 --- a/lib/scenario-editor/utils/valhalla.js +++ b/lib/scenario-editor/utils/valhalla.js @@ -204,7 +204,8 @@ export async function getSegment ( /** * Call GraphHopper routing service with lat/lng coordinates. * - * Example URL: https://graphhopper.com/api/1/route?point=49.932707,11.588051&point=50.3404,11.64705&vehicle=car&debug=true&&type=json + * Example URL V5/6: https://graphhopper.com/api/1/route?point=49.932707,11.588051&point=50.3404,11.64705&vehicle=car&debug=true&type=json + * Example URL V7: https://graphhopper.com/api/1/route?point=49.932707,11.588051&point=50.3404,11.64705&profile=car&debug=true&type=json */ export function routeWithGraphHopper (points: Array, avoidMotorways?: boolean): ?Promise { if (points.length < 2) { @@ -255,30 +256,41 @@ export function routeWithGraphHopper (points: Array, avoidMotorways?: bo }) } + // Version 7 of the graphhopper api uses profile instead of vehicle. + let profilecar = false + let profileveh = true + // Only check for definition not the value. + if (process.env.GRAPH_HOPPER_V7) { + profilecar = true + profileveh = false + } const params = { key: graphHopperKey, - vehicle: 'car', debug: true, - type: 'json' + type: 'json', + ...(profilecar && { profile: 'car' }), + ...(profileveh && { vehicle: 'car' }) } const locations = points.map(p => (`point=${p.lat},${p.lng}`)).join('&') // Avoiding motorways requires a POST request with a formatted body + const avoidmotorwaysbody = { + 'ch.disable': true, + // Custom model disincentives motorways + custom_model: { + 'priority': [{ + 'if': 'road_class == MOTORWAY', + 'multiply_by': 0.1 + }] + }, + debug: params.debug, + points: points.map(p => [p.lng, p.lat]), + ...(profilecar && { profile: 'car' }), + ...(profileveh && { vehicle: 'car' }) + } const graphHopperRequest = avoidMotorways ? fetch(`${graphHopperUrl}route?key=${params.key}`, { - body: JSON.stringify({ - 'ch.disable': true, - // Custom model disincentives motorways - custom_model: { - 'priority': [{ - 'if': 'road_class == MOTORWAY', - 'multiply_by': 0.1 - }] - }, - debug: params.debug, - points: points.map(p => [p.lng, p.lat]), - profile: params.vehicle - }), + body: JSON.stringify(avoidmotorwaysbody), headers: { 'Content-Type': 'application/json' },