Fix #9209
This commit is contained in:
parent
b956b63ba1
commit
af17e524d2
4 changed files with 105 additions and 16 deletions
|
@ -466,14 +466,16 @@ public class RoutingOptionsHelper {
|
||||||
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
|
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
|
||||||
RouteProvider.GPXRouteParamsBuilder rparams = routingHelper.getCurrentGPXRoute();
|
RouteProvider.GPXRouteParamsBuilder rparams = routingHelper.getCurrentGPXRoute();
|
||||||
boolean osmandRouter = am.getRouteService() == RouteProvider.RouteService.OSMAND;
|
boolean osmandRouter = am.getRouteService() == RouteProvider.RouteService.OSMAND;
|
||||||
if (rparams != null && !routingHelper.isCurrentGPXRouteV2() && osmandRouter) {
|
if (rparams != null && osmandRouter) {
|
||||||
GPXUtilities.GPXFile fl = rparams.getFile();
|
GPXUtilities.GPXFile fl = rparams.getFile();
|
||||||
if (fl.hasRtePt()) {
|
if (fl.hasRtePt()) {
|
||||||
list.add(new OtherLocalRoutingParameter(R.string.use_points_as_intermediates,
|
list.add(new OtherLocalRoutingParameter(R.string.use_points_as_intermediates,
|
||||||
app.getString(R.string.use_points_as_intermediates), rparams.isUseIntermediatePointsRTE()));
|
app.getString(R.string.use_points_as_intermediates), rparams.isUseIntermediatePointsRTE()));
|
||||||
}
|
}
|
||||||
|
if (!routingHelper.isCurrentGPXRouteV2()) {
|
||||||
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route,
|
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route,
|
||||||
app.getString(R.string.gpx_option_reverse_route), rparams.isReverse()));
|
app.getString(R.string.gpx_option_reverse_route), rparams.isReverse()));
|
||||||
|
}
|
||||||
if (!rparams.isUseIntermediatePointsRTE()) {
|
if (!rparams.isUseIntermediatePointsRTE()) {
|
||||||
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point,
|
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point,
|
||||||
app.getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute()));
|
app.getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute()));
|
||||||
|
|
|
@ -137,7 +137,7 @@ public class RouteCalculationResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
public RouteCalculationResult(List<RouteSegmentResult> list, Location start, LatLon end, List<LatLon> intermediates,
|
public RouteCalculationResult(List<RouteSegmentResult> list, Location start, LatLon end, List<LatLon> intermediates,
|
||||||
OsmandApplication ctx, boolean leftSide, RoutingContext rctx, List<LocationPoint> waypoints, ApplicationMode mode) {
|
OsmandApplication ctx, boolean leftSide, RoutingContext rctx, List<LocationPoint> waypoints, ApplicationMode mode, boolean calculateFirstAndLastPoint) {
|
||||||
if (rctx != null) {
|
if (rctx != null) {
|
||||||
this.routingTime = rctx.routingTime;
|
this.routingTime = rctx.routingTime;
|
||||||
this.visitedSegments = rctx.getVisitedSegments();
|
this.visitedSegments = rctx.getVisitedSegments();
|
||||||
|
@ -162,7 +162,9 @@ public class RouteCalculationResult {
|
||||||
List<Location> locations = new ArrayList<Location>();
|
List<Location> locations = new ArrayList<Location>();
|
||||||
ArrayList<AlarmInfo> alarms = new ArrayList<AlarmInfo>();
|
ArrayList<AlarmInfo> alarms = new ArrayList<AlarmInfo>();
|
||||||
List<RouteSegmentResult> segments = convertVectorResult(computeDirections, locations, list, alarms, ctx);
|
List<RouteSegmentResult> segments = convertVectorResult(computeDirections, locations, list, alarms, ctx);
|
||||||
|
if (calculateFirstAndLastPoint) {
|
||||||
introduceFirstPointAndLastPoint(locations, computeDirections, segments, start, end, ctx);
|
introduceFirstPointAndLastPoint(locations, computeDirections, segments, start, end, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
this.locations = Collections.unmodifiableList(locations);
|
this.locations = Collections.unmodifiableList(locations);
|
||||||
this.segments = Collections.unmodifiableList(segments);
|
this.segments = Collections.unmodifiableList(segments);
|
||||||
|
@ -300,6 +302,37 @@ public class RouteCalculationResult {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<RouteSegmentResult> getRoute(int startIndex) {
|
||||||
|
if (segments.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<RouteSegmentResult> list = new ArrayList<RouteSegmentResult>();
|
||||||
|
int skippedPoints = 0;
|
||||||
|
for (int i = 1; i <= startIndex; i++) {
|
||||||
|
RouteSegmentResult seg = segments.get(i - 1);
|
||||||
|
if (seg != segments.get(i)) {
|
||||||
|
skippedPoints += Math.abs(seg.getEndPointIndex() - seg.getStartPointIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.add(segments.get(startIndex++));
|
||||||
|
for (int i = startIndex; i < segments.size(); i++) {
|
||||||
|
if (segments.get(i - 1) != segments.get(i)) {
|
||||||
|
list.add(segments.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!list.isEmpty()) {
|
||||||
|
RouteSegmentResult seg = list.get(0);
|
||||||
|
if (seg.isForwardDirection()) {
|
||||||
|
int index = seg.getStartPointIndex() + startIndex - skippedPoints;
|
||||||
|
seg.setStartPointIndex(index);
|
||||||
|
} else {
|
||||||
|
int index = seg.getEndPointIndex() + startIndex - skippedPoints;
|
||||||
|
seg.setEndPointIndex(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PREPARATION
|
* PREPARATION
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -79,6 +79,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 ADDITIONAL_DISTANCE_FOR_START_POINT = 300;
|
||||||
private static final int MIN_STRAIGHT_DIST = 50000;
|
private static final int MIN_STRAIGHT_DIST = 50000;
|
||||||
|
|
||||||
public enum RouteService {
|
public enum RouteService {
|
||||||
|
@ -366,15 +367,44 @@ public class RouteProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
private RouteCalculationResult calculateGpxRoute(RouteCalculationParams routeParams) throws IOException {
|
private RouteCalculationResult calculateGpxRoute(RouteCalculationParams routeParams) throws IOException {
|
||||||
|
|
||||||
List<RouteSegmentResult> route = routeParams.gpxRoute.route;
|
|
||||||
if (!Algorithms.isEmpty(route)) {
|
|
||||||
return new RouteCalculationResult(route, routeParams.start, routeParams.end,
|
|
||||||
routeParams.intermediates, routeParams.ctx, routeParams.leftSide, null, null, routeParams.mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the closest point to start and to end
|
// get the closest point to start and to end
|
||||||
GPXRouteParams gpxParams = routeParams.gpxRoute;
|
GPXRouteParams gpxParams = routeParams.gpxRoute;
|
||||||
|
List<RouteSegmentResult> gpxRouteResult = routeParams.gpxRoute.route;
|
||||||
|
if (!Algorithms.isEmpty(gpxRouteResult)) {
|
||||||
|
boolean calculateOsmAndRouteParts = gpxParams.calculateOsmAndRouteParts;
|
||||||
|
if (routeParams.gpxRoute.passWholeRoute && !calculateOsmAndRouteParts) {
|
||||||
|
return new RouteCalculationResult(gpxRouteResult, routeParams.start, routeParams.end,
|
||||||
|
routeParams.intermediates, routeParams.ctx, routeParams.leftSide, null, null, routeParams.mode, true);
|
||||||
|
}
|
||||||
|
RouteCalculationResult result = new RouteCalculationResult(gpxRouteResult, routeParams.start, routeParams.end,
|
||||||
|
routeParams.intermediates, routeParams.ctx, routeParams.leftSide, null, null, routeParams.mode, false);
|
||||||
|
List<Location> gpxRouteLocations = result.getImmutableAllLocations();
|
||||||
|
int gpxNextIndex = routeParams.gpxRoute.passWholeRoute ? 0 : findStartIndexFromRoute(gpxRouteLocations, routeParams.start, calculateOsmAndRouteParts);
|
||||||
|
Location gpxNextLocation;
|
||||||
|
List<RouteSegmentResult> firstSegmentRoute = null;
|
||||||
|
List<RouteSegmentResult> gpxRoute;
|
||||||
|
if (gpxNextIndex > 0) {
|
||||||
|
gpxNextLocation = gpxRouteLocations.get(gpxNextIndex);
|
||||||
|
gpxRoute = result.getRoute(gpxNextIndex);
|
||||||
|
} else {
|
||||||
|
gpxNextLocation = gpxRouteLocations.get(0);
|
||||||
|
gpxRoute = result.getOriginalRoute();
|
||||||
|
}
|
||||||
|
if (calculateOsmAndRouteParts
|
||||||
|
&& routeParams.start != null && gpxNextLocation != null
|
||||||
|
&& gpxNextLocation.distanceTo(routeParams.start) > MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT) {
|
||||||
|
RouteCalculationResult firstSegmentResult = findOfflineRouteSegment(routeParams, routeParams.start, new LatLon(gpxNextLocation.getLatitude(), gpxNextLocation.getLongitude()));
|
||||||
|
firstSegmentRoute = firstSegmentResult.getOriginalRoute();
|
||||||
|
}
|
||||||
|
List<RouteSegmentResult> newGpxRoute = new ArrayList<>();
|
||||||
|
if (firstSegmentRoute != null && !firstSegmentRoute.isEmpty()) {
|
||||||
|
newGpxRoute.addAll(firstSegmentRoute);
|
||||||
|
}
|
||||||
|
newGpxRoute.addAll(gpxRoute);
|
||||||
|
return new RouteCalculationResult(newGpxRoute, routeParams.start, routeParams.end,
|
||||||
|
routeParams.intermediates, routeParams.ctx, routeParams.leftSide, null, null, routeParams.mode, true);
|
||||||
|
}
|
||||||
|
|
||||||
if(routeParams.gpxRoute.useIntermediatePointsRTE){
|
if(routeParams.gpxRoute.useIntermediatePointsRTE){
|
||||||
return calculateOsmAndRouteWithIntermediatePoints(routeParams, gpxParams.points);
|
return calculateOsmAndRouteWithIntermediatePoints(routeParams, gpxParams.points);
|
||||||
}
|
}
|
||||||
|
@ -389,7 +419,7 @@ public class RouteProvider {
|
||||||
gpxRoute = new ArrayList<>();
|
gpxRoute = new ArrayList<>();
|
||||||
Location trackStart = routeLocations.get(0);
|
Location trackStart = routeLocations.get(0);
|
||||||
Location realStart = routeParams.start;
|
Location realStart = routeParams.start;
|
||||||
//insert route segment from current location to next route location if user deviated from route
|
//insert gpxRouteResult segment from current location to next gpxRouteResult location if user deviated from gpxRouteResult
|
||||||
if (realStart != null && trackStart != null
|
if (realStart != null && trackStart != null
|
||||||
&& realStart.distanceTo(trackStart) > MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT
|
&& realStart.distanceTo(trackStart) > MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT
|
||||||
&& !gpxParams.calculateOsmAndRouteParts) {
|
&& !gpxParams.calculateOsmAndRouteParts) {
|
||||||
|
@ -625,6 +655,30 @@ public class RouteProvider {
|
||||||
return sublist;
|
return sublist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int findStartIndexFromRoute(List<Location> route, Location startLoc, boolean calculateOsmAndRouteParts) {
|
||||||
|
float minDist = Integer.MAX_VALUE;
|
||||||
|
int start = 0;
|
||||||
|
if (startLoc != null) {
|
||||||
|
for (int i = 0; i < route.size(); i++) {
|
||||||
|
float d = route.get(i).distanceTo(startLoc);
|
||||||
|
if (d < minDist) {
|
||||||
|
start = i;
|
||||||
|
minDist = d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (start > 0 && calculateOsmAndRouteParts) {
|
||||||
|
Location newStartLoc = route.get(start);
|
||||||
|
for (int i = start + 1; i < route.size(); i++) {
|
||||||
|
Location loc = route.get(i);
|
||||||
|
if (loc.distanceTo(newStartLoc) >= ADDITIONAL_DISTANCE_FOR_START_POINT) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
protected String getString(Context ctx, int resId){
|
protected String getString(Context ctx, int resId){
|
||||||
if(ctx == null){
|
if(ctx == null){
|
||||||
return ""; //$NON-NLS-1$
|
return ""; //$NON-NLS-1$
|
||||||
|
@ -812,7 +866,7 @@ public class RouteProvider {
|
||||||
} else {
|
} else {
|
||||||
RouteCalculationResult res = new RouteCalculationResult(result, params.start, params.end,
|
RouteCalculationResult res = new RouteCalculationResult(result, params.start, params.end,
|
||||||
params.intermediates, params.ctx, params.leftSide, ctx, params.gpxRoute == null? null: params.gpxRoute.wpt,
|
params.intermediates, params.ctx, params.leftSide, ctx, params.gpxRoute == null? null: params.gpxRoute.wpt,
|
||||||
params.mode);
|
params.mode, true);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
|
Loading…
Reference in a new issue