From b5aa267c69d15d6a3d1f7685a615c53ead859fba Mon Sep 17 00:00:00 2001 From: Javier Salamanca Date: Thu, 16 Oct 2014 17:01:03 +0200 Subject: [PATCH] Solve Issue 2233: Routing instructions disappearing too early in roundabouts Keep track of the end for directions that are not spots (like roundabouts). Then use this information to keep on this directions until we reach their end. Has a strange side effect. Distance drop as we arrive to start of roundabout (like previously) and when entering roundabout grow up to roundabout distance. modified: src/net/osmand/plus/routing/RouteCalculationResult.java modified: src/net/osmand/plus/routing/RouteDirectionInfo.java --- .../plus/routing/RouteCalculationResult.java | 18 +++++++++++++++--- .../plus/routing/RouteDirectionInfo.java | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index a27081fa12..6631d2cd13 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -243,10 +243,14 @@ public class RouteCalculationResult { if (routeInd < list.size()) { int lind = routeInd; if(turn.isRoundAbout()) { + int roundAboutEnd = prevLocationSize - 1; // take next name for roundabout (not roundabout name) while(lind < list.size() -1 && list.get(lind).getObject().roundabout()) { + roundAboutEnd += Math.abs(list.get(lind).getEndPointIndex()-list.get(lind).getStartPointIndex()); lind++; } + // Consider roundabout end. + info.routeEndPointOffset = roundAboutEnd; } RouteSegmentResult next = list.get(lind); info.setRef(next.getObject().getRef()); @@ -689,7 +693,9 @@ public class RouteCalculationResult { public void updateCurrentRoute(int currentRoute) { this.currentRoute = currentRoute; - while (currentDirectionInfo < directions.size() - 1 && directions.get(currentDirectionInfo + 1).routePointOffset < currentRoute) { + while (currentDirectionInfo < directions.size() - 1 + && directions.get(currentDirectionInfo + 1).routePointOffset < currentRoute + && directions.get(currentDirectionInfo + 1).routeEndPointOffset < currentRoute) { currentDirectionInfo++; } while(nextIntermediate < intermediatePoints.length) { @@ -721,7 +727,7 @@ public class RouteCalculationResult { /*public */NextDirectionInfo getNextRouteDirectionInfo(NextDirectionInfo info, Location fromLoc, boolean toSpeak) { int dirInfo = currentDirectionInfo; if (dirInfo < directions.size()) { - int dist = listDistance[currentRoute]; + // Locate next direction of interest int nextInd = dirInfo + 1; if (toSpeak) { while (nextInd < directions.size()) { @@ -732,12 +738,18 @@ public class RouteCalculationResult { nextInd++; } } + int dist = listDistance[currentRoute]; if (fromLoc != null) { dist += fromLoc.distanceTo(locations.get(currentRoute)); } if (nextInd < directions.size()) { info.directionInfo = directions.get(nextInd); - dist -= listDistance[directions.get(nextInd).routePointOffset]; + if (directions.get(nextInd).routePointOffset <= currentRoute + && currentRoute <= directions.get(nextInd).routeEndPointOffset) + // We are not into a puntual direction. + dist -= listDistance[directions.get(nextInd).routeEndPointOffset]; + else + dist -= listDistance[directions.get(nextInd).routePointOffset]; } if(intermediatePoints != null && nextIntermediate < intermediatePoints.length) { info.intermediatePoint = intermediatePoints[nextIntermediate] == nextInd; diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteDirectionInfo.java b/OsmAnd/src/net/osmand/plus/routing/RouteDirectionInfo.java index 906b36f782..9176b4be9d 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteDirectionInfo.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteDirectionInfo.java @@ -7,6 +7,8 @@ import net.osmand.router.TurnType; public class RouteDirectionInfo { // location when you should action (turn or go ahead) public int routePointOffset; + // location where direction end. useful for roundabouts. + public int routeEndPointOffset = 0; // Type of action to take private TurnType turnType; // Description of the turn and route after