Repository navigation
Conversation
| return encodePolyline(poly, includeElevation, 1e5); | ||
| } | ||
|
|
||
| public static String encodePolyline(PointList poly, boolean includeElevation, double precision) { |
There was a problem hiding this comment.
passing the precision is required to support the request parameter polyline6
karussell
left a comment
There was a problem hiding this comment.
Looks good and straightforward if I understand this all correctly :) Nice!
| public class MapboxResponseConverter { | ||
|
|
||
| // TODO: this is already in GraphHopper, but getting it from there is not possible easily? | ||
| private static final TranslationMap trMap = new TranslationMap().doImport(); |
There was a problem hiding this comment.
Do you mean hopper.getTranslationMap?
There was a problem hiding this comment.
Yes, but in the web-bundle we only have a reference to the GraphHopperAPI interface. We could probably check if the object is instance of GraphHopper and then get the TranslationMap? I thought that this would be too much overhead, but we could try?
There was a problem hiding this comment.
As we bind
bind(translationMap).to(TranslationMap.class);
We could maybe inject it in the resource?
There was a problem hiding this comment.
Ah thanks, that's a good idea. I tried to inject it and it seems to work. Could you check if this is what you meant?
| ObjectNode json = JsonNodeFactory.instance.objectNode(); | ||
|
|
||
| if (ghResponse.hasErrors()) | ||
| throw new IllegalStateException("Cannot convert an errornous ghResponse"); |
There was a problem hiding this comment.
This should be possible. I mean, what if the route is not found or you want to go to the US from Europe. We have to support error JSON too.
There was a problem hiding this comment.
Yes, it is :). It's just a different method, see MapboxResponseConverter#convertFromGHResponseError. Since we have to change the http response status to 422 in MapboxResource (at line ~137), I thought it would be a bit cleaner to have the two methods separated. It would be easily mergeable though. WDYT?
There was a problem hiding this comment.
I see. Then the error message needs to be changed to "should be handled before in MapboxResource"?
|
|
||
| json.put("code", "Ok"); | ||
| // TODO: Maybe we need a different format... uuid: "cji4ja4f8004o6xrsta8w4p4h" | ||
| json.put("uuid", UUID.randomUUID().toString().replaceAll("-", "")); |
There was a problem hiding this comment.
What is the purpose of this uuid? Maybe we have to hash the response somehow for error reporting?
There was a problem hiding this comment.
The purpose is not documented (or I could not find it). I haven't checked how it is used in the code. I think this is used internally to match error reports with requests. I tried sending multiple requests with the same parameters, and the UUID was different every time (but only at the end, the first characters were similar, so there seems to be some logic behind this).
| { | ||
| distanceAlongGeometry: 40.9, | ||
| announcement: "Exit the traffic circle", | ||
| ssmlAnnouncement: "<speak><amazon:effect name="drc"><prosody rate="1.08">Exit the traffic circle</prosody></amazon:effect></speak>", |
There was a problem hiding this comment.
I love this xml style inside JSON :D
There was a problem hiding this comment.
This is actually called SSML which is used to change the way TTS speaks the instructions. So the idea is that voice instructions are generated by the server, also the frequency and distance of the voice instructions is generated by the server.
| * @author Robin Boldt | ||
| */ | ||
| @Path("mapbox/directions/v5/mapbox") | ||
| public class MapboxResource { |
There was a problem hiding this comment.
Is it possible to use OSRM for the Mapbox SDK? If yes, can we rename to OSRMResource? If no, this is perfect already :)
There was a problem hiding this comment.
Actually I don't think that this is possible easily. The problem is that the OSRM endpoint does not generate voice instructions nor banner instructions which are both important for the MapboxSDK.
| } | ||
|
|
||
| private void throwIllegalArgumentException(String exceptionMessage) { | ||
| logger.error(exceptionMessage); |
There was a problem hiding this comment.
Why do we need this method? An exception should be logged from dropwizard automatically
There was a problem hiding this comment.
Thanks, I will try this again, but IIRC in my tests so far, errors have not been logged by dropwizard, that's why I added this :). But maybe this is only true for the test environment during the IT?
There was a problem hiding this comment.
Sorry, IllegalArgEx are supposed to avoid extra logging. But still it should print the request and info about a 'bad request'. If not, then we need to fix it globally for all IllegalArgEx
There was a problem hiding this comment.
Not sure if I understand you correct, as a user the result would look like:
{
message: "Voice units only support metric right now",
hints: [
{
message: "Voice units only support metric right now",
details: "java.lang.IllegalArgumentException",
}
],
}
And yes, this is currently the GH style and not Mapbox style for error responses :). Not sure if we should and can change that for a single resource like using a custom exception mapper?
There was a problem hiding this comment.
The exception should not be logged separately (please just throw an IllegalArgumentException or if not a bad request but indicating an error throw RuntimeException or IllegalState or whatever).
If there is a bad request and it is not logged at all, we have to fix it for all resources, not sure here.
There was a problem hiding this comment.
Ok, will simply change this :)
|
|
||
| } catch (Exception e) { | ||
| logger.error("Exception while processing: ", e); | ||
| throw new MultiException(e); |
There was a problem hiding this comment.
Same here: I think logging + throwing an exception seems duplicated
| private List<GHPoint> getPointsFromRequest(PathSegment pathSegment) { | ||
|
|
||
| // TODO: Could the map at some point break the order? | ||
| Set<String> pointParams = pathSegment.getMatrixParameters().keySet(); |
There was a problem hiding this comment.
This seems to be indeed a bit risky. What is the parameter form? Isn't it possible to use the same approach like in RouteResource? @QueryParam("point") List<GHPoint> requestPoints
There was a problem hiding this comment.
The problem is that the points in the Mapbox SDK are so called "MatrixParameters" and not as QueryParameters.
An example would look like this: ...directions/v5/mapbox/driving-traffic/9.453778,48.70906;9.450624,48.706879
I did some research, but only found this option to read this parameter form. As noted in the TODO, I am not especially happy with this either :).
There was a problem hiding this comment.
And did you try it for multiple points and does it work?
There was a problem hiding this comment.
I double checked. It does not work, it seems that it can change the order.
There was a problem hiding this comment.
There was a problem hiding this comment.
Ok, according to SO, this is not easily fixable with JAX-RS. I switched to parsing the URL string manually. This seems to work well enough :).
| ObjectNode json = JsonNodeFactory.instance.objectNode(); | ||
|
|
||
| if (ghResponse.hasErrors()) | ||
| throw new IllegalStateException("Cannot convert an errornous ghResponse"); |
There was a problem hiding this comment.
I see. Then the error message needs to be changed to "should be handled before in MapboxResource"?
| ArrayNode location = node.putArray("location"); | ||
| // GeoJson lon,lat | ||
| location.add(Helper.round6(lon)); | ||
| location.add(Helper.round6(lat)); |
There was a problem hiding this comment.
Maybe this is also dependent on the precision asked from outside? (I think I saw something for the simplification)
There was a problem hiding this comment.
No, this is only for the polyline. The request parameter is geometries=polyline6 and only changes the precision of the Google Polyline like encoding.
|
|
||
| double minPathPrecision = 1; | ||
| if (overview.equals("full")) | ||
| minPathPrecision = 0.1; |
There was a problem hiding this comment.
Any reason why simplification is disabled? Does it not work or do we avoid a second request for the details?
There was a problem hiding this comment.
Any reason why simplification is disabled?
Yes, the overview parameter means: "Type of returned overview geometry. Can be full (the most detailed geometry available), simplified (a simplified version of the full geometry), or false (no overview geometry). The default is simplified".
I found that the Mapbox SDK works better, when more points are in the geometry. That's why I disabled simplification. Even with disabled simplification, the Mapbox API seems to return a more detailed geometry than GH.
Regarding PathDetails: This is not yet implemented for the Mapbox endpoint. This seems to work different to the way we do PathDetails and might require a bit of time and planning (haven't checked in detail yet).
|
I updated this PR, improved the error logging and changed the way the points are parsed. Let me know if we can merge this or if there is anything else? |
| } | ||
|
|
||
| return points; | ||
| } |
There was a problem hiding this comment.
Will the following work?
@Path("/{profile}/{coordinatesString}")
and then String[] pointStrings = coordinatesString.split(";");
This way at least the first three lines can be avoided.
There was a problem hiding this comment.
No, this was my first idea as well :).
The problem is that the path parameter coordinate string would only contain the first coordinate up to the first ;, everything else is parsed as matrix parameter, which is unsorted.
There was a problem hiding this comment.
Oh, ugly. And this means {coordinatesArray: .*} is no longer in use?
There was a problem hiding this comment.
Yes, the parameter {coordinatesArray: .*} is no longer used. I could rename it or see if I can remove it?
There was a problem hiding this comment.
Can you try out a different regex and see if this works? See e.g. https://stackoverflow.com/q/2291428/194609
There was a problem hiding this comment.
I tried it like this:
@Path("/{profile}/{coordinatesArray : .+}")
...
@PathParam("coordinatesArray") String coordinates
I think this is what you meant? It does not work. The variable coordinates only contains the first coordinate up to the first ;, everything after that seems to be read as matrix parameter.
|
This feature will be developed in its separate repository: https://github.com/graphhopper/graphhopper-navigation |
* Initial commit, moving relevant files from #1422 over to the new repository * Remove debugging output * Update README.md * Rename to graphhopper-navigation-mapbox * Add Tests (#3) * Make MapboxResponseConverter testable * Added Travis.yml * Mavenbuild (#4) * try maven build * packaging pom * Corrected conflict resolution * Add Travis build status image * Minor test improvement * Fix indentation issue * Remove WebHelper, fixes #1 * added a few properties required for deploying to maven central * let's configure executable from settings * Allow multiple waypoints (#5) * First approach at allowing multiple waypoints * Fix resetting time and distance * First improvement to repeat instructions regularly * Add a very far distance instruction to instruct users to continue on the road * Moved the very far message a bit * Reduce initial delay * Improve roundabout banner instructions * Add the very close instruction fall back * Added a simple translation map * Upper case the first letter of turn descriptions in bannerInstructions * Update README.md * Use GH translation map * Move translations to resources * Use Helper.firstBig * Have TranslationMap as singleton * TranslationMap as static variable * Update README.md * Update README.md * Update README.md * Update README.md * move to stable dep of GH core 0.11.0 * set explicit version to maven-compiler-plugin * Add bearings (#17) * Inigial approach of using bearings in the request * Disable CH * log test * Added Tests for MapboxResource#getBearing * Sett pass through to false * Add alternative Routes to Navigation Endpoint (#18) * Allow the addition of multiple routes when using headings * Use alternative routes by default * Add test for alternative routes * Remove alternative route calculation * upgrade GH core dependency * Add then voice and banner instruction (#19) Add comment and minor rename * Change Endpoint name and Maven Package (#20) * Rename maven package, endpoint, and files * Fix tmp issue with openjdk * Remove tmp fix for jdk issue * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * use jdk-12 instead of 10 * Add points * updated GH core version * upgraded to 0.12.0-pre3 * updated GH core to 0.12.0-pre6 * upgrade to 0.13-SNAPSHOT and using GH core 0.12.0 * upgrade GH core to 0.13.0-pre1 * upgrade GH core to 0.13.0-pre2 * Upgrade gh core to 0.13.0-pre3 * Init imperial voice unit support * Move VoiceInstructionConfig to seperate file * Add imperial unit translations * Add voice instruction tests * Set right inital voice instruction key * Remove redundant init from unit * Remove voiceUnit metric check * Set imperial as default if no voiceUnit is set * Refactor voice instruction configuration creation * Upgrade gh core to 0.13.0-pre4 * upgrade GH core to 0.13.0-pre5 * upgrade GH core to 0.13.0-pre6 * upgrade GH core to 0.13.0-pre7 * upgrade GH core to 0.13.0-pre8 * upgrade GH core to 0.13.0-pre12 * Fallback to the original profile (#26) * Load the correct translation map * upgrade GH core to 0.13.0-pre15 * Upgrade GH core to 0.13.0-pre16 * Upgrade GH core to 0.13.0-pre17 * Upgrade GH core to 0.13.0-pre18 * Upgrade GH core to 0.13.0-pre19 * Upgrade GH core to 0.13.0 * Upgrade GH core to 0.14.0-pre1 * Upgrade GH core to 1.0-pre1 * Upgrade GH core to 1.0-pre2 * Upgrade GH core to 1.0-pre3 * Upgrade GH core to 1.0-pre4 * Upgrade GH core to 1.0-pre5 * Update README.md * Fix continue instruction translation (#27) * Fix issues with Continue instruction and fixed some typos * Use GH translation map instead * Upgrade GH core to 1.0-pre7 (#28) * Upgrade GH core to 1.0-pre9 * Update pom.xml * Upgrade GH core to 1.0-pre11 * Upgrade GH core to 1.0-pre12 * Upgrade GH core to 1.0-pre14 * Upgrade GH core to 1.0-pre16 * Upgrade GH core to 1.0-pre17 * Upgrade GH core to 1.0-pre18 * Upgrade GH core to 1.0-pre21 * Upgrade GH core to 1.0-pre22 * Upgrade GH core to 1.0-pre23 * Upgrade GH core to 1.0-pre24 * Upgrade GH core to 1.0-pre25 * Upgrade GH core to 1.0-pre27 * Upgrade GH core to 1.0-pre28 * Upgrade GH core to 1.0-pre29 * Upgrade GH core to 1.0-pre30 * Fix compiler error, tests still fail * fix tests #31 * Upgrade GH core to 1.0-pre31 * update to jdk14 * Upgrade core to 1.0-pre32 * Upgrade core to 1.0-pre33 * Upgrade core to 1.0-pre33.2 * Upgrade core to 1.0-pre33.3 * Upgrade core to 1.0-pre33.4 * Upgrade core to 1.0-pre35 * fix resource * Upgrade core to 1.0-pre37 * Upgrade core to 1.0-pre38 * for now we need the legacy resolver also here * add logging * make profile mapping between mapbox and graphhopper configurable; remove legacy resolver * Update README.md * Update README.md * Update README.md * updated GH core * Set versions to 1.0-SNAPSHOT in pom.xml, keep dependency hashes in separate file * Move gh_dependencies into pom.xml instead * Rename: PathWrapper -> ResponsePath * Use core dependency from jitpack * Remove hash * Upgrade to 1.0-pre42, revert to old build process * Upgrade GH core to 1.0-pre43 * Upgrade GH core to 1.0 * Upgrade version to 2.0-SNAPSHOT * add development profile * Update core version, use GitHub packages, remove sonatype snapshot repository * Add GitHub workflow to publish packages, see core/#n2049 * Add missing distributionManagement * Add access token setup for travis with github packages * travis job: include access also for github packages * Update core version * Include sources for GitHub Packages deployments * Update core to 'remove unused methods encoder.defineNodeBits...' * Update core to 'Set default algo for edge-based CH back to Dijkstra' * Update core to 'Use Envelope in API' * Update core to 'Add comment about module GpxFromInstructions belongs to' * Update core to 'Add creator method for LMApproximator' * move into navigation subfolder * remove duplicate files * removed andorra osm * added apache license header to 2 files * added note in changelog Co-authored-by: Robin <[email protected]> Co-authored-by: easbar <[email protected]> Co-authored-by: Stefan Kienzl <[email protected]>
This PR approaches #1265.
So far the implementation is still quite limited, but works well in my tests with the Mapbox SDK. This PR tries not to change anything in the GraphHopper core.
Some of the current limitations are:
Let me know what you think about the current state :).