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
This commit is contained in:
Javier Salamanca 2014-10-16 17:01:03 +02:00
parent 2c0d1fdcd0
commit b5aa267c69
2 changed files with 17 additions and 3 deletions

View file

@ -243,10 +243,14 @@ public class RouteCalculationResult {
if (routeInd < list.size()) { if (routeInd < list.size()) {
int lind = routeInd; int lind = routeInd;
if(turn.isRoundAbout()) { if(turn.isRoundAbout()) {
int roundAboutEnd = prevLocationSize - 1;
// take next name for roundabout (not roundabout name) // take next name for roundabout (not roundabout name)
while(lind < list.size() -1 && list.get(lind).getObject().roundabout()) { while(lind < list.size() -1 && list.get(lind).getObject().roundabout()) {
roundAboutEnd += Math.abs(list.get(lind).getEndPointIndex()-list.get(lind).getStartPointIndex());
lind++; lind++;
} }
// Consider roundabout end.
info.routeEndPointOffset = roundAboutEnd;
} }
RouteSegmentResult next = list.get(lind); RouteSegmentResult next = list.get(lind);
info.setRef(next.getObject().getRef()); info.setRef(next.getObject().getRef());
@ -689,7 +693,9 @@ public class RouteCalculationResult {
public void updateCurrentRoute(int currentRoute) { public void updateCurrentRoute(int currentRoute) {
this.currentRoute = 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++; currentDirectionInfo++;
} }
while(nextIntermediate < intermediatePoints.length) { while(nextIntermediate < intermediatePoints.length) {
@ -721,7 +727,7 @@ public class RouteCalculationResult {
/*public */NextDirectionInfo getNextRouteDirectionInfo(NextDirectionInfo info, Location fromLoc, boolean toSpeak) { /*public */NextDirectionInfo getNextRouteDirectionInfo(NextDirectionInfo info, Location fromLoc, boolean toSpeak) {
int dirInfo = currentDirectionInfo; int dirInfo = currentDirectionInfo;
if (dirInfo < directions.size()) { if (dirInfo < directions.size()) {
int dist = listDistance[currentRoute]; // Locate next direction of interest
int nextInd = dirInfo + 1; int nextInd = dirInfo + 1;
if (toSpeak) { if (toSpeak) {
while (nextInd < directions.size()) { while (nextInd < directions.size()) {
@ -732,12 +738,18 @@ public class RouteCalculationResult {
nextInd++; nextInd++;
} }
} }
int dist = listDistance[currentRoute];
if (fromLoc != null) { if (fromLoc != null) {
dist += fromLoc.distanceTo(locations.get(currentRoute)); dist += fromLoc.distanceTo(locations.get(currentRoute));
} }
if (nextInd < directions.size()) { if (nextInd < directions.size()) {
info.directionInfo = directions.get(nextInd); 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) { if(intermediatePoints != null && nextIntermediate < intermediatePoints.length) {
info.intermediatePoint = intermediatePoints[nextIntermediate] == nextInd; info.intermediatePoint = intermediatePoints[nextIntermediate] == nextInd;

View file

@ -7,6 +7,8 @@ import net.osmand.router.TurnType;
public class RouteDirectionInfo { public class RouteDirectionInfo {
// location when you should action (turn or go ahead) // location when you should action (turn or go ahead)
public int routePointOffset; public int routePointOffset;
// location where direction end. useful for roundabouts.
public int routeEndPointOffset = 0;
// Type of action to take // Type of action to take
private TurnType turnType; private TurnType turnType;
// Description of the turn and route after // Description of the turn and route after