From a11e5bb9e614c0af5ce1b302ea1e4171eed5eaa8 Mon Sep 17 00:00:00 2001 From: Saikrishna Arcot Date: Sat, 4 Oct 2014 10:39:25 -0400 Subject: [PATCH 1/3] Add basic support for reading turn:lanes and drawing the turns as lanes --- .../osmand/router/RouteResultPreparation.java | 78 ++++++++++++++++++- .../mapwidgets/RouteInfoWidgetsFactory.java | 2 +- 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index 2d935bb105..c53965257c 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -577,6 +577,8 @@ public class RouteResultPreparation { } if (t != null && lanes != null) { t.setLanes(lanes); + + t = attachTurnLanesData(leftSide, prevSegm, t); } return t; } @@ -593,7 +595,81 @@ public class RouteResultPreparation { } return (lns + 1) / 2; } - + + protected String getTurnLanesString(RouteSegmentResult segment) { + if (segment.getObject().getOneway() == 0) { + if (segment.isForwardDirection()) { + return segment.getObject().getValue("turn:lanes:forward"); + } else { + return segment.getObject().getValue("turn:lanes:backward"); + } + } else { + return segment.getObject().getValue("turn:lanes"); + } + } + + private TurnType attachTurnLanesData(boolean leftSide, RouteSegmentResult prevSegm, TurnType t) { + int lanes = prevSegm.getObject().getLanes(); + String turnLanes = getTurnLanesString(prevSegm); + + if (turnLanes == null) { + return t; + } + + String[] splitLaneOptions = turnLanes.split("\\|", -1); + if (splitLaneOptions.length != lanes) { + // Error in data or missing data + return t; + } + + if (t.getLanes().length != lanes) { + // The turn:lanes don't easily match up to the target road. + // TODO: Add support for lanes that can go in multiple directions + return t; + } + + assignTurns(splitLaneOptions, t); + + return t; + } + + private void assignTurns(String[] splitLaneOptions, TurnType t) { + for (int i = 0; i < splitLaneOptions.length; i++) { + String[] laneOptions = splitLaneOptions[i].split(";"); + + for (int j = 0; j < laneOptions.length; j++) { + int turn; + if (laneOptions[j].equals("none") || laneOptions[j].equals("through")) { + turn = TurnType.C; + } else if (laneOptions[j].equals("slight_right")) { + turn = TurnType.TSLR; + } else if (laneOptions[j].equals("slight_left")) { + turn = TurnType.TSLL; + } else if (laneOptions[j].equals("right")) { + turn = TurnType.TR; + } else if (laneOptions[j].equals("left")) { + turn = TurnType.TL; + } else if (laneOptions[j].equals("sharp_right")) { + turn = TurnType.TSHR; + } else if (laneOptions[j].equals("sharp_left")) { + turn = TurnType.TSHL; + } else if (laneOptions[j].equals("reverse")) { + turn = TurnType.TU; + } else { + // Unknown string + continue; + } + + if (TurnType.getPrimaryTurn(t.getLanes()[i]) == 0) { + t.setPrimaryTurn(i, turn); + } else { + t.setSecondaryTurn(i, turn); + break; // Move on to the next lane + } + } + } + } + private boolean isMotorway(RouteSegmentResult s){ String h = s.getObject().getHighway(); return "motorway".equals(h) || "motorway_link".equals(h) || diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index 0bf9e58ae4..5a59193bf6 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -585,7 +585,7 @@ public class RouteInfoWidgetsFactory { int turnType; if ((lanes[i] & 1) == 1) { paintRouteDirection.setColor(imminent ? getResources().getColor(R.color.nav_arrow_imminent) : getResources().getColor(R.color.nav_arrow)); - if(turn != null) { + if(TurnType.getPrimaryTurn(lanes[i]) == 0) { turnType = turn.getValue(); } else { turnType = TurnType.getPrimaryTurn(lanes[i]); From 3ef0a4f9a80439ec2964e47ff9b13999f8a86390 Mon Sep 17 00:00:00 2001 From: Saikrishna Arcot Date: Mon, 6 Oct 2014 12:43:50 -0400 Subject: [PATCH 2/3] Change return type of attachTurnLanesData to void --- .../net/osmand/router/RouteResultPreparation.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index c53965257c..52a01bc0e1 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -578,7 +578,7 @@ public class RouteResultPreparation { if (t != null && lanes != null) { t.setLanes(lanes); - t = attachTurnLanesData(leftSide, prevSegm, t); + attachTurnLanesData(leftSide, prevSegm, t); } return t; } @@ -608,29 +608,27 @@ public class RouteResultPreparation { } } - private TurnType attachTurnLanesData(boolean leftSide, RouteSegmentResult prevSegm, TurnType t) { + private void attachTurnLanesData(boolean leftSide, RouteSegmentResult prevSegm, TurnType t) { int lanes = prevSegm.getObject().getLanes(); String turnLanes = getTurnLanesString(prevSegm); if (turnLanes == null) { - return t; + return; } String[] splitLaneOptions = turnLanes.split("\\|", -1); if (splitLaneOptions.length != lanes) { // Error in data or missing data - return t; + return; } if (t.getLanes().length != lanes) { // The turn:lanes don't easily match up to the target road. // TODO: Add support for lanes that can go in multiple directions - return t; + return; } assignTurns(splitLaneOptions, t); - - return t; } private void assignTurns(String[] splitLaneOptions, TurnType t) { From 88156c0370939349b1a460d1b8a04ba15ff6b03e Mon Sep 17 00:00:00 2001 From: Saikrishna Arcot Date: Mon, 6 Oct 2014 14:10:57 -0400 Subject: [PATCH 3/3] Swap secondary and primary turns if the secondary turn is actually the turn being made. --- .../src/net/osmand/router/RouteResultPreparation.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index 52a01bc0e1..d7bbe78341 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -661,7 +661,13 @@ public class RouteResultPreparation { if (TurnType.getPrimaryTurn(t.getLanes()[i]) == 0) { t.setPrimaryTurn(i, turn); } else { - t.setSecondaryTurn(i, turn); + if (turn == t.getValue()) { + t.setSecondaryTurn(i, TurnType.getPrimaryTurn(t.getLanes()[i])); + t.setPrimaryTurn(i, turn); + } else { + t.setSecondaryTurn(i, turn); + } + break; // Move on to the next lane } }