From 6bbac4e892ac210693c2f51195542e419d362e3d Mon Sep 17 00:00:00 2001 From: vshcherb Date: Thu, 27 Mar 2014 01:11:21 +0100 Subject: [PATCH] Calculate osmand route to the start point of GPX route (when option pass whole route is selected) --- .../plus/base/MapViewTrackingUtilities.java | 2 +- .../osmand/plus/routing/RouteProvider.java | 50 +++++++++++++++---- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java index 8048e22e71..3424f3e8a5 100644 --- a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java +++ b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java @@ -296,7 +296,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc bottom = Math.min(bottom, l.getLatitude()); } RotatedTileBox tb = new RotatedTileBox(rt); - tb.setPixelDimensions(2 * tb.getPixWidth() / 3, 2 * tb.getPixHeight() / 3); + tb.setPixelDimensions(3 * tb.getPixWidth() / 4, 3 * tb.getPixHeight() / 4); double clat = bottom / 2 + top / 2; double clon = left / 2 + right / 2; tb.setLatLonCenter(clat, clon); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 8922e75576..dd4dbb58c5 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -150,9 +150,9 @@ public class RouteProvider { public GPXRouteParams build(Location start, OsmandSettings settings) { GPXRouteParams res = new GPXRouteParams(); res.prepareGPXFile(this); - if(passWholeRoute && start != null){ - res.points.add(0, start); - } +// if(passWholeRoute && start != null){ +// res.points.add(0, start); +// } return res; } @@ -183,6 +183,7 @@ public class RouteProvider { List directions; DataTileManager wpt; boolean calculateOsmAndRoute; + boolean passWholeRoute; public List getPoints() { return points; @@ -207,6 +208,7 @@ public class RouteProvider { public GPXRouteParams prepareGPXFile(GPXRouteParamsBuilder builder){ GPXFile file = builder.file; boolean reverse = builder.reverse; + passWholeRoute = builder.passWholeRoute; boolean announceWaypoints = builder.announceWaypoints; calculateOsmAndRoute = false; // Disabled temporary builder.calculateOsmAndRoute; if(file.isCloudmadeRouteFile() || OSMAND_ROUTER.equals(file.author)){ @@ -310,17 +312,47 @@ public class RouteProvider { } - private RouteCalculationResult calculateGpxRoute(RouteCalculationParams pars) { + private RouteCalculationResult calculateGpxRoute(RouteCalculationParams rParams) { + if(rParams.start != null && rParams.gpxRoute.passWholeRoute) { + Location startOfGpx = rParams.gpxRoute.getStartPointForRoute(); + if (startOfGpx != null && rParams.start.distanceTo(startOfGpx) > 60) { + RouteCalculationParams newParams = new RouteCalculationParams(); + newParams.start = rParams.start; + newParams.end = new LatLon(startOfGpx.getLatitude(), startOfGpx.getLongitude()); + newParams.ctx = rParams.ctx; + newParams.calculationProgress = rParams.calculationProgress; + newParams.mode = rParams.mode; + newParams.type = RouteService.OSMAND; + newParams.leftSide = rParams.leftSide; + RouteCalculationResult newRes = null; + try { + newRes = findVectorMapsRoute(newParams, false); + } catch (IOException e) { + } + if(newRes == null || !newRes.isCalculated()) { + rParams.gpxRoute.points.add(rParams.start); + } else { + List loct = newRes.getImmutableLocations(); + List dt = newRes.getDirections(); + List gpxRouteDirections = rParams.gpxRoute.directions; + rParams.gpxRoute.points.addAll(0, loct); + gpxRouteDirections.addAll(0, dt); + for(int i = dt.size() ; i < gpxRouteDirections.size(); i++ ) { + gpxRouteDirections.get(i).routePointOffset += loct.size(); + } + } + } + } RouteCalculationResult res; // get the closest point to start and to end - GPXRouteParams params = pars.gpxRoute; + GPXRouteParams params = rParams.gpxRoute; List gpxRoute = params.points; int[] startI = new int[]{0}; int[] endI = new int[]{gpxRoute.size()}; - ArrayList sublist = findGpxLocations(pars, startI, endI); - pars.intermediates = null; + ArrayList sublist = findGpxLocations(rParams, startI, endI); + rParams.intermediates = null; if(params.directions == null){ - res = new RouteCalculationResult(sublist, null, pars, params.wpt); + res = new RouteCalculationResult(sublist, null, rParams, params.wpt); } else { List subdirections = new ArrayList(); for (RouteDirectionInfo info : params.directions) { @@ -335,7 +367,7 @@ public class RouteProvider { subdirections.add(ch); } } - res = new RouteCalculationResult(sublist, subdirections, pars, params.wpt); + res = new RouteCalculationResult(sublist, subdirections, rParams, params.wpt); } return res; }