Skip to content
This repository has been archived by the owner on Dec 21, 2020. It is now read-only.

InstructionList.createGPX fails to null Translation #53

Open
devemux86 opened this issue Jun 30, 2017 · 3 comments
Open

InstructionList.createGPX fails to null Translation #53

devemux86 opened this issue Jun 30, 2017 · 3 comments

Comments

@devemux86
Copy link
Contributor

Using the alternative API client to perform online routing and then produce gpx from the result, fails with:

java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String com.graphhopper.util.Translation.tr(java.lang.String, java.lang.Object[])' on a null object reference
    at com.graphhopper.util.FinishInstruction.getTurnDescription(FinishInstruction.java:55)
    at com.graphhopper.util.InstructionList.createWayPointBlock(InstructionList.java:168)
    at com.graphhopper.util.InstructionList.createGPX(InstructionList.java:200)

This is because in GraphHopperWeb.createPathWrapper a null Translation is used:

InstructionList il = new InstructionList(null);

Since we have the online routing result, can we support GPX creation on the client?
e.g. enhance InstructionList to allow external Translation?

@boldtrn
Copy link
Member

boldtrn commented Jul 1, 2017

I just had a more detailed look here. It depends how you call the API.

If you add req.getHints().put("turn_description", false);, then it fails, if you don't add this it works. I created a PR here containing a test that shows this.

enhance InstructionList to allow external Translation?

The easiest way as a workaround if you want to have req.getHints().put("turn_description", false);, would be to create a new instance of the InstructionList with the added TranslationMap. You can extract all instruction from the old InstructionList and add it to the new InstructionList. However, I think it would not hurt to provide a way to set the TranslationMap of the InstructionList, WDYT @karussell?

@devemux86
Copy link
Contributor Author

If you add req.getHints().put("turn_description", false);, then it fails, if you don't add this it works.

Hmm the request hints are that way because they need to be for the wished routing result.
If need to be different for the create gpx to succeed, then a 2nd request would be required, not very convenient. 🙂

@boldtrn
Copy link
Member

boldtrn commented Jul 1, 2017

If need to be different for the create gpx to succeed, then a 2nd request would be required, not very convenient.

As I said, there is a workaround possible. In your code you could do something like:

req.getHints().put("turn_description", false);
ghResponse = gh.route(req);
InstructionList newIL = new InstructionList(tr);
for (int i = 0; i < ghResponse.getBest().getInstructions().size(); i++) {
    newIL.add(i, ghResponse.getBest().getInstructions().get(i));
}

I haven't tested it, but I think this should work. The newIL contains your translations now and creating GPX should work without any problems.

Anyway, I think we should make it possible to set the TranslationMap for an InstructionList, as this would solve the issue and would not hurt us I think.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants