Calculate osmand route to the start point of GPX route (when option pass whole route is selected)

This commit is contained in:
vshcherb 2014-03-27 01:11:21 +01:00
parent 040ad3ad77
commit 6bbac4e892
2 changed files with 42 additions and 10 deletions

View file

@ -296,7 +296,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
bottom = Math.min(bottom, l.getLatitude()); bottom = Math.min(bottom, l.getLatitude());
} }
RotatedTileBox tb = new RotatedTileBox(rt); 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 clat = bottom / 2 + top / 2;
double clon = left / 2 + right / 2; double clon = left / 2 + right / 2;
tb.setLatLonCenter(clat, clon); tb.setLatLonCenter(clat, clon);

View file

@ -150,9 +150,9 @@ public class RouteProvider {
public GPXRouteParams build(Location start, OsmandSettings settings) { public GPXRouteParams build(Location start, OsmandSettings settings) {
GPXRouteParams res = new GPXRouteParams(); GPXRouteParams res = new GPXRouteParams();
res.prepareGPXFile(this); res.prepareGPXFile(this);
if(passWholeRoute && start != null){ // if(passWholeRoute && start != null){
res.points.add(0, start); // res.points.add(0, start);
} // }
return res; return res;
} }
@ -183,6 +183,7 @@ public class RouteProvider {
List<RouteDirectionInfo> directions; List<RouteDirectionInfo> directions;
DataTileManager<WptPt> wpt; DataTileManager<WptPt> wpt;
boolean calculateOsmAndRoute; boolean calculateOsmAndRoute;
boolean passWholeRoute;
public List<Location> getPoints() { public List<Location> getPoints() {
return points; return points;
@ -207,6 +208,7 @@ public class RouteProvider {
public GPXRouteParams prepareGPXFile(GPXRouteParamsBuilder builder){ public GPXRouteParams prepareGPXFile(GPXRouteParamsBuilder builder){
GPXFile file = builder.file; GPXFile file = builder.file;
boolean reverse = builder.reverse; boolean reverse = builder.reverse;
passWholeRoute = builder.passWholeRoute;
boolean announceWaypoints = builder.announceWaypoints; boolean announceWaypoints = builder.announceWaypoints;
calculateOsmAndRoute = false; // Disabled temporary builder.calculateOsmAndRoute; calculateOsmAndRoute = false; // Disabled temporary builder.calculateOsmAndRoute;
if(file.isCloudmadeRouteFile() || OSMAND_ROUTER.equals(file.author)){ 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<Location> loct = newRes.getImmutableLocations();
List<RouteDirectionInfo> dt = newRes.getDirections();
List<RouteDirectionInfo> 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; RouteCalculationResult res;
// get the closest point to start and to end // get the closest point to start and to end
GPXRouteParams params = pars.gpxRoute; GPXRouteParams params = rParams.gpxRoute;
List<Location> gpxRoute = params.points; List<Location> gpxRoute = params.points;
int[] startI = new int[]{0}; int[] startI = new int[]{0};
int[] endI = new int[]{gpxRoute.size()}; int[] endI = new int[]{gpxRoute.size()};
ArrayList<Location> sublist = findGpxLocations(pars, startI, endI); ArrayList<Location> sublist = findGpxLocations(rParams, startI, endI);
pars.intermediates = null; rParams.intermediates = null;
if(params.directions == null){ if(params.directions == null){
res = new RouteCalculationResult(sublist, null, pars, params.wpt); res = new RouteCalculationResult(sublist, null, rParams, params.wpt);
} else { } else {
List<RouteDirectionInfo> subdirections = new ArrayList<RouteDirectionInfo>(); List<RouteDirectionInfo> subdirections = new ArrayList<RouteDirectionInfo>();
for (RouteDirectionInfo info : params.directions) { for (RouteDirectionInfo info : params.directions) {
@ -335,7 +367,7 @@ public class RouteProvider {
subdirections.add(ch); subdirections.add(ch);
} }
} }
res = new RouteCalculationResult(sublist, subdirections, pars, params.wpt); res = new RouteCalculationResult(sublist, subdirections, rParams, params.wpt);
} }
return res; return res;
} }