From 4b5f338fca575f43e8bf4d6dfbddde1bbd8cad93 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 18 Feb 2020 17:16:31 +0100 Subject: [PATCH] Fix left distance widget --- .../plus/routing/RouteCalculationResult.java | 26 +++++++++---------- .../osmand/plus/routing/RouteProvider.java | 7 +++-- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 94a56369d3..b133d185aa 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -1037,10 +1037,7 @@ public class RouteCalculationResult { nextInd++; } } - int dist = getListDistance(currentRoute); - if (fromLoc != null) { - dist += fromLoc.distanceTo(locations.get(currentRoute)); - } + int dist = getDistanceToFinish(fromLoc); if (nextInd < directions.size()) { info.directionInfo = directions.get(nextInd); if (directions.get(nextInd).routePointOffset <= currentRoute @@ -1162,10 +1159,15 @@ public class RouteCalculationResult { } public int getDistanceToFinish(Location fromLoc) { - if(listDistance != null && currentRoute < listDistance.length){ - int dist = listDistance[currentRoute]; - Location l = locations.get(currentRoute); - if(fromLoc != null){ + Location ap = this.currentStraightAnglePoint; + int rp = currentStraightAngleRoute > currentRoute ? currentStraightAngleRoute : currentRoute; + if(listDistance != null && rp < listDistance.length){ + 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); } return dist; @@ -1174,12 +1176,8 @@ public class RouteCalculationResult { } public int getDistanceToNextIntermediate(Location fromLoc) { + int dist = getDistanceToFinish(fromLoc); 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 ){ return 0; } else { @@ -1245,8 +1243,8 @@ public class RouteCalculationResult { } public void updateNextVisiblePoint(int nextPoint, Location mp) { - currentStraightAngleRoute = nextPoint; currentStraightAnglePoint = mp; + currentStraightAngleRoute = nextPoint; } public static class NextDirectionInfo { diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 43cd6907f6..45b15fdab1 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -78,7 +78,7 @@ public class RouteProvider { private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(RouteProvider.class); private static final String OSMAND_ROUTER = "OsmAndRouter"; 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 { OSMAND("OsmAnd (offline)"), @@ -1249,13 +1249,12 @@ public class RouteProvider { } } points.add(new Location("", params.end.getLatitude(), params.end.getLongitude())); - Location lastAdded = points.poll(); - segments.add(lastAdded); + Location lastAdded = null; float speed = params.mode.getDefaultSpeed(); List computeDirections = new ArrayList(); while(!points.isEmpty()) { Location pl = points.peek(); - if (lastAdded.distanceTo(pl) < MIN_STRAIGHT_DIST) { + if (lastAdded == null || lastAdded.distanceTo(pl) < MIN_STRAIGHT_DIST) { lastAdded = points.poll(); if(lastAdded.getProvider().equals("pnt")) { RouteDirectionInfo previousInfo = new RouteDirectionInfo(speed, TurnType.straight());