diff --git a/OsmAnd-java/src/main/java/net/osmand/router/TurnType.java b/OsmAnd-java/src/main/java/net/osmand/router/TurnType.java index 7b67669cf3..6f0db3fa86 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/TurnType.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/TurnType.java @@ -140,7 +140,7 @@ public class TurnType { r.setTurnAngle(angle); return r; } - + private TurnType(int vl) { this.value = vl; @@ -156,6 +156,10 @@ public class TurnType { return value == RNLB || value == TRU; } + public void setExitOut(int exitOut) { + this.exitOut = exitOut; + } + public void setTurnAngle(float turnAngle) { this.turnAngle = turnAngle; } diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/engine/GraphhopperEngine.java b/OsmAnd/src/net/osmand/plus/onlinerouting/engine/GraphhopperEngine.java index bcb3654ac3..20bbfaa70e 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/engine/GraphhopperEngine.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/engine/GraphhopperEngine.java @@ -98,24 +98,19 @@ public class GraphhopperEngine extends OnlineRoutingEngine { JSONArray instructions = root.getJSONArray("instructions"); List directions = new ArrayList<>(); for (int i = 0; i < instructions.length(); i++) { - JSONObject item = instructions.getJSONObject(i); - int sign = item.getInt("sign"); - int distance = (int) Math.round(item.getDouble("distance")); - String description = item.getString("text"); - String streetName = item.getString("street_name"); - int timeInSeconds = Math.round(item.getInt("time") / 1000f); - JSONArray interval = item.getJSONArray("interval"); + JSONObject instruction = instructions.getJSONObject(i); + int distance = (int) Math.round(instruction.getDouble("distance")); + String description = instruction.getString("text"); + String streetName = instruction.getString("street_name"); + int timeInSeconds = Math.round(instruction.getInt("time") / 1000f); + JSONArray interval = instruction.getJSONArray("interval"); int startPointOffset = interval.getInt(0); int endPointOffset = interval.getInt(1); float averageSpeed = (float) distance / timeInSeconds; - TurnType turnType = identifyTurnType(sign, leftSideNavigation); - if (turnType == null) { - turnType = TurnType.straight(); - } - // TODO turnType.setTurnAngle() - + TurnType turnType = parseTurnType(instruction, leftSideNavigation); RouteDirectionInfo direction = new RouteDirectionInfo(averageSpeed, turnType); + direction.routePointOffset = startPointOffset; direction.setDescriptionRoute(description); direction.setStreetName(streetName); @@ -125,24 +120,30 @@ public class GraphhopperEngine extends OnlineRoutingEngine { return new OnlineRoutingResponse(route, directions); } - @Override - public boolean parseServerMessage(@NonNull StringBuilder sb, - @NonNull String content) throws JSONException { - JSONObject obj = new JSONObject(content); - if (obj.has("message")) { - String message = obj.getString("message"); - sb.append(message); + @NonNull + private TurnType parseTurnType(@NonNull JSONObject instruction, + boolean leftSide) throws JSONException { + int sign = instruction.getInt("sign"); + TurnType turnType = identifyTurnType(sign, leftSide); + + if (turnType == null) { + turnType = TurnType.straight(); + } else if (turnType.isRoundAbout()) { + if (instruction.has("exit_number")) { + int exit = instruction.getInt("exit_number"); + turnType.setExitOut(exit); + } + if (instruction.has("turn_angle")) { + float angle = (float) instruction.getDouble("turn_angle"); + turnType.setTurnAngle(angle); + } + } else { + // TODO turnType.setTurnAngle() } - return obj.has("paths"); + + return turnType; } - /** - * @param sign - a number which specifies the turn type to show (Graphhopper API value) - * @return a TurnType object defined in OsmAnd which is equivalent to a value from the Graphhopper API - * - * For future compatibility it is important that all clients - * are able to handle also unknown instruction sign numbers - */ @Nullable public static TurnType identifyTurnType(int sign, boolean leftSide) { Integer id = null; @@ -214,4 +215,15 @@ public class GraphhopperEngine extends OnlineRoutingEngine { return id != null ? TurnType.valueOf(id, leftSide) : null; } + + @Override + public boolean parseServerMessage(@NonNull StringBuilder sb, + @NonNull String content) throws JSONException { + JSONObject obj = new JSONObject(content); + if (obj.has("message")) { + String message = obj.getString("message"); + sb.append(message); + } + return obj.has("paths"); + } }