-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update valhalla.js Graphhopper to V7 #948
Open
mvanlaar
wants to merge
19
commits into
ibi-group:dev
Choose a base branch
from
mvanlaar:patch-1
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
317b952
Update valhalla.js Graphhopper to V7
mvanlaar 2f2b50a
Update env.yml.tmp
mvanlaar 7c149ad
set true instead of yes/no
mvanlaar 5fc821c
Update valhalla.js to use paramater for V7
mvanlaar 5df01cd
Fix linting
mvanlaar 797db24
Update valhalla.js fix linting v2
mvanlaar 4645f7c
Update valhalla.js fix linting V3
mvanlaar 2cfe699
Update valhalla.js fix linting v5
mvanlaar 95835bf
Use other defintion of the profile property
mvanlaar 40fdf61
Update valhalla.js fix alternative method
mvanlaar f349f66
Update valhalla.js fix linting
mvanlaar 6d2231c
Update valhalla.js fix linting v2
mvanlaar 2f9b053
Update valhalla.js make default false
mvanlaar 8d3e66b
Update valhalla.js different check based on 2 values
mvanlaar dc6d49f
Update valhalla.js explicit boolean
mvanlaar 60e1db7
Update valhalla.js fix type name
mvanlaar c0c00eb
Update valhalla.js fix boolean
mvanlaar 8400445
Update valhalla.js boolean
mvanlaar 1ad0d99
Update valhalla.js fix for review
mvanlaar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<LatLng>, avoidMotorways?: boolean): ?Promise<GraphHopperResponse> { | ||
if (points.length < 2) { | ||
|
@@ -255,30 +256,41 @@ export function routeWithGraphHopper (points: Array<LatLng>, 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 = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this configurable? Also please camel case |
||
'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' }) | ||
Comment on lines
+287
to
+288
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. re-use the dynamic object key from earlier |
||
} | ||
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' | ||
}, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the value is always
car
can we instead adjust params after it is set to either add a profile: car or a vehicle: car depending on the config?