From a9915e7e82242ffb8d93071773ffa560805ab18f Mon Sep 17 00:00:00 2001 From: MadWasp79 Date: Wed, 12 Feb 2020 16:44:02 +0200 Subject: [PATCH] Direct to: show projection point only on certain distance from location marker. Direct to: prevent route recalculations. --- .../plus/routing/RouteCalculationParams.java | 1 + .../plus/routing/RouteCalculationResult.java | 3 +- .../osmand/plus/routing/RouteProvider.java | 1 + .../osmand/plus/routing/RoutingHelper.java | 9 ++-- .../src/net/osmand/plus/views/RouteLayer.java | 48 +++++++++++-------- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java index 99d7c6a959..50294d5cbe 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java @@ -35,6 +35,7 @@ public class RouteCalculationParams { public RouteCalculationResultListener resultListener; public boolean showOriginalRoute; + public boolean noRecalculations; public interface RouteCalculationResultListener { void onRouteCalculated(RouteCalculationResult route); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 1c838ec327..56c15fa45d 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -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 list, Location start, LatLon end, List intermediates, diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index f24a47851a..99ad7baa3a 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -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 intermediates = params.intermediates; diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 1e829f7abd..e1fc5ab809 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -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); } } diff --git a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java index 97b22822b4..2c7ea7be68 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java @@ -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 routeNodes, RoutingHelper helper, RotatedTileBox box) { + private double[] calculateProjectionOnRoutePoint(List 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 calculateActionPoints(double topLatitude, double leftLongitude, double bottomLatitude,