Merge pull request #5714 from osmandapp/Fix_5651

Fix_5651
This commit is contained in:
Vitaliy 2018-07-26 10:34:41 +03:00 committed by GitHub
commit 2a1734843d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View file

@ -76,6 +76,7 @@ import btools.routingapp.IBRouterService;
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;
public enum RouteService {
OSMAND("OsmAnd (offline)"), YOURS("YOURS"),
@ -366,6 +367,28 @@ public class RouteProvider {
int[] endI = new int[]{gpxParams.points.size()};
if(routeParams.gpxRoute.passWholeRoute) {
gpxRoute = gpxParams.points;
if (routeParams.previousToRecalculate != null && routeParams.onlyStartPointChanged) {
List<Location> routeLocations = routeParams.previousToRecalculate.getRouteLocations();
if (routeLocations != null && routeLocations.size() >= 1) {
gpxRoute = new ArrayList<>();
Location trackStart = routeLocations.get(0);
Location realStart = routeParams.start;
//insert route segment from current location to next route location if user deviated from route
if (realStart != null && trackStart != null
&& realStart.distanceTo(trackStart) > MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT
&& !gpxParams.calculateOsmAndRouteParts) {
LatLon nextRouteLocation = new LatLon(trackStart.getLatitude(), trackStart.getLongitude());
RouteCalculationResult newRes = findOfflineRouteSegment(routeParams, realStart, nextRouteLocation);
if (newRes != null && newRes.isCalculated()) {
gpxRoute.addAll(0, newRes.getImmutableAllLocations());
} else {
gpxRoute.add(0, realStart);
}
}
gpxRoute.addAll(new ArrayList<>(routeLocations));
endI = new int[]{gpxRoute.size()};
}
}
} else {
gpxRoute = findStartAndEndLocationsFromRoute(gpxParams.points,
routeParams.start, routeParams.end, startI, endI);
@ -455,7 +478,7 @@ public class RouteProvider {
Location routeEnd = points.get(points.size() - 1);
LatLon e = routeEnd == null ? null : new LatLon(routeEnd.getLatitude(), routeEnd.getLongitude());
LatLon finalEnd = routeParams.end;
if (finalEnd != null && MapUtils.getDistance(finalEnd, e) > 60) {
if (finalEnd != null && MapUtils.getDistance(finalEnd, e) > MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT) {
RouteCalculationResult newRes = null;
if (calculateOsmAndRouteParts) {
newRes = findOfflineRouteSegment(routeParams, routeEnd, finalEnd);
@ -485,7 +508,7 @@ public class RouteProvider {
public void insertInitialSegment(RouteCalculationParams routeParams, List<Location> points,
List<RouteDirectionInfo> directions, boolean calculateOsmAndRouteParts) {
Location realStart = routeParams.start;
if (realStart != null && points.size() > 0 && realStart.distanceTo(points.get(0)) > 60) {
if (realStart != null && points.size() > 0 && realStart.distanceTo(points.get(0)) > MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT) {
Location trackStart = points.get(0);
RouteCalculationResult newRes = null;
if (calculateOsmAndRouteParts) {

View file

@ -957,7 +957,8 @@ public class RoutingHelper {
params.intermediates = intermediates;
params.gpxRoute = gpxRoute == null ? null : gpxRoute.build(start, settings);
params.onlyStartPointChanged = onlyStartPointChanged;
if(recalculateCountInInterval < RECALCULATE_THRESHOLD_COUNT_CAUSING_FULL_RECALCULATE) {
if (recalculateCountInInterval < RECALCULATE_THRESHOLD_COUNT_CAUSING_FULL_RECALCULATE
|| (gpxRoute != null && gpxRoute.isPassWholeRoute() && isDeviatedFromRoute)) {
params.previousToRecalculate = previousRoute;
} else {
recalculateCountInInterval = 0;