Fix left distance widget

This commit is contained in:
Victor Shcherb 2020-02-18 17:16:31 +01:00
parent 1428148a07
commit 4b5f338fca
2 changed files with 15 additions and 18 deletions

View file

@ -1037,10 +1037,7 @@ public class RouteCalculationResult {
nextInd++; nextInd++;
} }
} }
int dist = getListDistance(currentRoute); int dist = getDistanceToFinish(fromLoc);
if (fromLoc != null) {
dist += fromLoc.distanceTo(locations.get(currentRoute));
}
if (nextInd < directions.size()) { if (nextInd < directions.size()) {
info.directionInfo = directions.get(nextInd); info.directionInfo = directions.get(nextInd);
if (directions.get(nextInd).routePointOffset <= currentRoute if (directions.get(nextInd).routePointOffset <= currentRoute
@ -1162,10 +1159,15 @@ public class RouteCalculationResult {
} }
public int getDistanceToFinish(Location fromLoc) { public int getDistanceToFinish(Location fromLoc) {
if(listDistance != null && currentRoute < listDistance.length){ Location ap = this.currentStraightAnglePoint;
int dist = listDistance[currentRoute]; int rp = currentStraightAngleRoute > currentRoute ? currentStraightAngleRoute : currentRoute;
Location l = locations.get(currentRoute); if(listDistance != null && rp < listDistance.length){
if(fromLoc != null){ int dist = listDistance[rp];
Location l = locations.get(rp);
if(ap != null){
dist += fromLoc.distanceTo(ap);
dist += ap.distanceTo(l);
} else {
dist += fromLoc.distanceTo(l); dist += fromLoc.distanceTo(l);
} }
return dist; return dist;
@ -1174,12 +1176,8 @@ public class RouteCalculationResult {
} }
public int getDistanceToNextIntermediate(Location fromLoc) { public int getDistanceToNextIntermediate(Location fromLoc) {
int dist = getDistanceToFinish(fromLoc);
if(listDistance != null && currentRoute < listDistance.length){ if(listDistance != null && currentRoute < listDistance.length){
int dist = listDistance[currentRoute];
Location l = locations.get(currentRoute);
if(fromLoc != null){
dist += fromLoc.distanceTo(l);
}
if(nextIntermediate >= intermediatePoints.length ){ if(nextIntermediate >= intermediatePoints.length ){
return 0; return 0;
} else { } else {
@ -1245,8 +1243,8 @@ public class RouteCalculationResult {
} }
public void updateNextVisiblePoint(int nextPoint, Location mp) { public void updateNextVisiblePoint(int nextPoint, Location mp) {
currentStraightAngleRoute = nextPoint;
currentStraightAnglePoint = mp; currentStraightAnglePoint = mp;
currentStraightAngleRoute = nextPoint;
} }
public static class NextDirectionInfo { public static class NextDirectionInfo {

View file

@ -78,7 +78,7 @@ public class RouteProvider {
private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(RouteProvider.class); private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(RouteProvider.class);
private static final String OSMAND_ROUTER = "OsmAndRouter"; private static final String OSMAND_ROUTER = "OsmAndRouter";
private static final int MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT = 60; private static final int MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT = 60;
private static final int MIN_STRAIGHT_DIST = 150; private static final int MIN_STRAIGHT_DIST = 50000;
public enum RouteService { public enum RouteService {
OSMAND("OsmAnd (offline)"), OSMAND("OsmAnd (offline)"),
@ -1249,13 +1249,12 @@ public class RouteProvider {
} }
} }
points.add(new Location("", params.end.getLatitude(), params.end.getLongitude())); points.add(new Location("", params.end.getLatitude(), params.end.getLongitude()));
Location lastAdded = points.poll(); Location lastAdded = null;
segments.add(lastAdded);
float speed = params.mode.getDefaultSpeed(); float speed = params.mode.getDefaultSpeed();
List<RouteDirectionInfo> computeDirections = new ArrayList<RouteDirectionInfo>(); List<RouteDirectionInfo> computeDirections = new ArrayList<RouteDirectionInfo>();
while(!points.isEmpty()) { while(!points.isEmpty()) {
Location pl = points.peek(); Location pl = points.peek();
if (lastAdded.distanceTo(pl) < MIN_STRAIGHT_DIST) { if (lastAdded == null || lastAdded.distanceTo(pl) < MIN_STRAIGHT_DIST) {
lastAdded = points.poll(); lastAdded = points.poll();
if(lastAdded.getProvider().equals("pnt")) { if(lastAdded.getProvider().equals("pnt")) {
RouteDirectionInfo previousInfo = new RouteDirectionInfo(speed, TurnType.straight()); RouteDirectionInfo previousInfo = new RouteDirectionInfo(speed, TurnType.straight());