Direct to: show projection point only on certain distance from location marker.

Direct to: prevent route recalculations.
This commit is contained in:
MadWasp79 2020-02-12 16:44:02 +02:00
parent 6369969acd
commit a9915e7e82
5 changed files with 36 additions and 26 deletions

View file

@ -35,6 +35,7 @@ public class RouteCalculationParams {
public RouteCalculationResultListener resultListener;
public boolean showOriginalRoute;
public boolean noRecalculations;
public interface RouteCalculationResultListener {
void onRouteCalculated(RouteCalculationResult route);

View file

@ -63,7 +63,7 @@ public class RouteCalculationResult {
protected int currentWaypointGPX = 0;
protected int lastWaypointGPX = 0;
protected ApplicationMode appMode;
protected boolean noRecalculations = false;
protected boolean showOriginalRoute = false;
public RouteCalculationResult(String errorMessage) {
@ -113,6 +113,7 @@ public class RouteCalculationResult {
updateDirectionsTime(this.directions, this.listDistance);
this.showOriginalRoute = params.showOriginalRoute;
this.noRecalculations = params.noRecalculations;
}
public RouteCalculationResult(List<RouteSegmentResult> list, Location start, LatLon end, List<LatLon> intermediates,

View file

@ -1262,6 +1262,7 @@ public class RouteProvider {
private RouteCalculationResult findDirectTo(RouteCalculationParams params) {
params.showOriginalRoute = true;
params.noRecalculations = true;
double[] lats = new double[] { params.start.getLatitude(), params.end.getLatitude() };
double[] lons = new double[] { params.start.getLongitude(), params.end.getLongitude() };
List<LatLon> intermediates = params.intermediates;

View file

@ -437,7 +437,7 @@ public class RoutingHelper {
// 2. Analyze if we need to recalculate route
// >100m off current route (sideways)
if (currentRoute > 0) {
if (currentRoute > 0 && !route.noRecalculations) {
distOrth = getOrthogonalDistance(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
if ((!settings.DISABLE_OFFROUTE_RECALC.get()) && (distOrth > (1.7 * posTolerance))) {
log.info("Recalculate route, because correlation : " + distOrth); //$NON-NLS-1$
@ -448,7 +448,8 @@ public class RoutingHelper {
// 3. Identify wrong movement direction
Location next = route.getNextRouteLocation();
boolean wrongMovementDirection = checkWrongMovementDirection(currentLocation, next);
if ((!settings.DISABLE_WRONG_DIRECTION_RECALC.get()) && wrongMovementDirection && (currentLocation.distanceTo(routeNodes.get(currentRoute)) > (2 * posTolerance))) {
if ((!settings.DISABLE_WRONG_DIRECTION_RECALC.get()) && wrongMovementDirection
&& (currentLocation.distanceTo(routeNodes.get(currentRoute)) > (2 * posTolerance)) && !route.noRecalculations) {
log.info("Recalculate route, because wrong movement direction: " + currentLocation.distanceTo(routeNodes.get(currentRoute))); //$NON-NLS-1$
isDeviatedFromRoute = true;
calculateRoute = true;
@ -464,11 +465,11 @@ public class RoutingHelper {
if (!inRecalc && !wrongMovementDirection) {
voiceRouter.updateStatus(currentLocation, false);
voiceRouterStopped = false;
} else if (isDeviatedFromRoute && !voiceRouterStopped) {
} else if (isDeviatedFromRoute && !voiceRouterStopped && !route.noRecalculations) {
voiceRouter.interruptRouteCommands();
voiceRouterStopped = true; // Prevents excessive execution of stop() code
}
if (distOrth > mode.getOffRouteDistance()) {
if (distOrth > mode.getOffRouteDistance() && !route.noRecalculations) {
voiceRouter.announceOffRoute(distOrth);
}
}

View file

@ -17,6 +17,7 @@ import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.Pair;
import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
@ -315,7 +316,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
}
}
private void drawProjectionPoint(RotatedTileBox box, Canvas canvas, double[] projectionXY) {
private void drawProjectionPoint(Canvas canvas, double[] projectionXY) {
if (projectionIcon == null) {
projectionIcon = (LayerDrawable) view.getResources().getDrawable(helper.getSettings().getApplicationMode().getLocationIcon().getIconId());
}
@ -1120,16 +1121,16 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
}
if (helper.getRoute().isShowOriginalRoute()) {
//add projection point on original route
double[] projectionOnRoute = calculateProjectionOnRoutePoint(helper.getLastProjection(),
double[] projectionOnRoute = calculateProjectionOnRoutePoint(
helper.getOriginalRouteAllLoc(), helper, tb);
if (projectionOnRoute != null) {
drawProjectionPoint(tb, canvas, projectionOnRoute);
drawProjectionPoint(canvas, projectionOnRoute);
}
}
}
}
private double[] calculateProjectionOnRoutePoint(Location lastProjection, List<Location> routeNodes, RoutingHelper helper, RotatedTileBox box) {
private double[] calculateProjectionOnRoutePoint(List<Location> routeNodes, RoutingHelper helper, RotatedTileBox box) {
double[] projectionXY;
boolean visible;
Location previousInRoute = null;
@ -1148,25 +1149,30 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
nextInRoute = routeNodes.get(routeNodes.size() - 1);
}
int centerX = box.getPixXFromLonNoRot(nextInRoute.getLongitude());
int centerY = box.getPixYFromLatNoRot(nextInRoute.getLatitude());
int aX = box.getPixXFromLonNoRot(lastProjection.getLongitude());
int aY = box.getPixYFromLatNoRot(lastProjection.getLatitude());
int bX = box.getPixXFromLonNoRot(previousInRoute.getLongitude());
int bY = box.getPixYFromLatNoRot(previousInRoute.getLatitude());
if (nextInRoute != null && previousInRoute != null) {
final Location ll = view.getApplication().getLocationProvider().getLastKnownLocation();
final int aX = box.getPixXFromLonNoRot(ll.getLongitude());
final int aY = box.getPixYFromLatNoRot(ll.getLatitude());
final int centerX = box.getPixXFromLonNoRot(nextInRoute.getLongitude());
final int centerY = box.getPixYFromLatNoRot(nextInRoute.getLatitude());
final int bX = box.getPixXFromLonNoRot(previousInRoute.getLongitude());
final int bY = box.getPixYFromLatNoRot(previousInRoute.getLatitude());
double radius = MapUtils.getVectorMagnitude(centerX, centerY, aX, aY);
double angle2 = MapUtils.getAngleForRadiusVector(centerX, centerY, bX, bY);
projectionXY = MapUtils.getCoordinatesFromRadiusAndAngle(centerX, centerY, radius, angle2);
visible = box.containsPoint((float)projectionXY[0], (float)projectionXY[1], 20.0f)
&& Math.abs(Math.toDegrees(MapUtils.getAngleBetweenVectors(centerX, centerY, aX, aY, centerX, centerY, bX, bY))) < 90;
if (visible) {
return projectionXY;
} else {
return null;
double radius = MapUtils.getVectorMagnitude(centerX, centerY, aX, aY);
double angle2 = MapUtils.getAngleForRadiusVector(centerX, centerY, bX, bY);
projectionXY = MapUtils.getCoordinatesFromRadiusAndAngle(centerX, centerY, radius, angle2);
double distanceLoc2Proj = MapUtils.getVectorMagnitude(aX, aY, (int)projectionXY[0], (int)projectionXY[1]);
boolean isProjectionOnSegment = MapUtils.getVectorMagnitude(centerX ,centerY, (int) projectionXY[0], (int) projectionXY[1])
< MapUtils.getVectorMagnitude(centerX, centerY, bX, bY);
visible = box.containsPoint((float)projectionXY[0], (float)projectionXY[1], 20.0f)
&& Math.abs(Math.toDegrees(MapUtils.getAngleBetweenVectors(centerX, centerY, aX, aY, centerX, centerY, bX, bY))) < 90
&& distanceLoc2Proj > AndroidUtils.dpToPx(view.getContext(), 52) / 2.0
&& isProjectionOnSegment;
if (visible) {
return projectionXY;
}
}
return null;
}
private List<Location> calculateActionPoints(double topLatitude, double leftLongitude, double bottomLatitude,