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
|
@ -156,6 +156,10 @@ public class TurnType {
|
||||||
return value == RNLB || value == TRU;
|
return value == RNLB || value == TRU;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setExitOut(int exitOut) {
|
||||||
|
this.exitOut = exitOut;
|
||||||
|
}
|
||||||
|
|
||||||
public void setTurnAngle(float turnAngle) {
|
public void setTurnAngle(float turnAngle) {
|
||||||
this.turnAngle = turnAngle;
|
this.turnAngle = turnAngle;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,24 +98,19 @@ public class GraphhopperEngine extends OnlineRoutingEngine {
|
||||||
JSONArray instructions = root.getJSONArray("instructions");
|
JSONArray instructions = root.getJSONArray("instructions");
|
||||||
List<RouteDirectionInfo> directions = new ArrayList<>();
|
List<RouteDirectionInfo> directions = new ArrayList<>();
|
||||||
for (int i = 0; i < instructions.length(); i++) {
|
for (int i = 0; i < instructions.length(); i++) {
|
||||||
JSONObject item = instructions.getJSONObject(i);
|
JSONObject instruction = instructions.getJSONObject(i);
|
||||||
int sign = item.getInt("sign");
|
int distance = (int) Math.round(instruction.getDouble("distance"));
|
||||||
int distance = (int) Math.round(item.getDouble("distance"));
|
String description = instruction.getString("text");
|
||||||
String description = item.getString("text");
|
String streetName = instruction.getString("street_name");
|
||||||
String streetName = item.getString("street_name");
|
int timeInSeconds = Math.round(instruction.getInt("time") / 1000f);
|
||||||
int timeInSeconds = Math.round(item.getInt("time") / 1000f);
|
JSONArray interval = instruction.getJSONArray("interval");
|
||||||
JSONArray interval = item.getJSONArray("interval");
|
|
||||||
int startPointOffset = interval.getInt(0);
|
int startPointOffset = interval.getInt(0);
|
||||||
int endPointOffset = interval.getInt(1);
|
int endPointOffset = interval.getInt(1);
|
||||||
|
|
||||||
float averageSpeed = (float) distance / timeInSeconds;
|
float averageSpeed = (float) distance / timeInSeconds;
|
||||||
TurnType turnType = identifyTurnType(sign, leftSideNavigation);
|
TurnType turnType = parseTurnType(instruction, leftSideNavigation);
|
||||||
if (turnType == null) {
|
|
||||||
turnType = TurnType.straight();
|
|
||||||
}
|
|
||||||
// TODO turnType.setTurnAngle()
|
|
||||||
|
|
||||||
RouteDirectionInfo direction = new RouteDirectionInfo(averageSpeed, turnType);
|
RouteDirectionInfo direction = new RouteDirectionInfo(averageSpeed, turnType);
|
||||||
|
|
||||||
direction.routePointOffset = startPointOffset;
|
direction.routePointOffset = startPointOffset;
|
||||||
direction.setDescriptionRoute(description);
|
direction.setDescriptionRoute(description);
|
||||||
direction.setStreetName(streetName);
|
direction.setStreetName(streetName);
|
||||||
|
@ -125,24 +120,30 @@ public class GraphhopperEngine extends OnlineRoutingEngine {
|
||||||
return new OnlineRoutingResponse(route, directions);
|
return new OnlineRoutingResponse(route, directions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@NonNull
|
||||||
public boolean parseServerMessage(@NonNull StringBuilder sb,
|
private TurnType parseTurnType(@NonNull JSONObject instruction,
|
||||||
@NonNull String content) throws JSONException {
|
boolean leftSide) throws JSONException {
|
||||||
JSONObject obj = new JSONObject(content);
|
int sign = instruction.getInt("sign");
|
||||||
if (obj.has("message")) {
|
TurnType turnType = identifyTurnType(sign, leftSide);
|
||||||
String message = obj.getString("message");
|
|
||||||
sb.append(message);
|
if (turnType == null) {
|
||||||
|
turnType = TurnType.straight();
|
||||||
|
} else if (turnType.isRoundAbout()) {
|
||||||
|
if (instruction.has("exit_number")) {
|
||||||
|
int exit = instruction.getInt("exit_number");
|
||||||
|
turnType.setExitOut(exit);
|
||||||
}
|
}
|
||||||
return obj.has("paths");
|
if (instruction.has("turn_angle")) {
|
||||||
|
float angle = (float) instruction.getDouble("turn_angle");
|
||||||
|
turnType.setTurnAngle(angle);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO turnType.setTurnAngle()
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
@Nullable
|
||||||
public static TurnType identifyTurnType(int sign, boolean leftSide) {
|
public static TurnType identifyTurnType(int sign, boolean leftSide) {
|
||||||
Integer id = null;
|
Integer id = null;
|
||||||
|
@ -214,4 +215,15 @@ public class GraphhopperEngine extends OnlineRoutingEngine {
|
||||||
|
|
||||||
return id != null ? TurnType.valueOf(id, leftSide) : null;
|
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