add roundabout info about exit number and turn angle
This commit is contained in:
parent
fbb1c770a1
commit
17bfdad2c6
2 changed files with 45 additions and 29 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -98,24 +98,19 @@ public class GraphhopperEngine extends OnlineRoutingEngine {
|
|||
JSONArray instructions = root.getJSONArray("instructions");
|
||||
List<RouteDirectionInfo> 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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue