From 762f2840f3a2a8a934a9808e7b0bb2be266ea014 Mon Sep 17 00:00:00 2001 From: MadWasp79 Date: Tue, 18 Feb 2020 18:59:17 +0200 Subject: [PATCH] fix direct to --- .../src/main/java/net/osmand/util/MapUtils.java | 5 +++++ .../src/net/osmand/plus/views/RouteLayer.java | 17 +++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java b/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java index b1c4c54566..aa206ae2fb 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java @@ -49,6 +49,11 @@ public class MapUtils { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_', '~' }; + + + public static double getDistance(Location l1, Location l2) { + return getDistance(l1.getLatitude(), l1.getLongitude(), l2.getLatitude(), l2.getLongitude()); + } public static double getDistance(LatLon l, double latitude, double longitude) { return getDistance(l.getLatitude(), l.getLongitude(), latitude, longitude); } diff --git a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java index 91af884301..f45625b466 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java @@ -35,6 +35,7 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu; import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu.TrackChartPoints; +import net.osmand.plus.profiles.LocationIcon; import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.routing.RouteDirectionInfo; @@ -319,7 +320,8 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont private void drawProjectionPoint(Canvas canvas, double[] projectionXY) { if (projectionIcon == null) { - projectionIcon = (LayerDrawable) view.getResources().getDrawable(helper.getSettings().getApplicationMode().getLocationIcon().DEFAULT.getIconId()); + helper.getSettings().getApplicationMode().getLocationIcon(); + projectionIcon = (LayerDrawable) view.getResources().getDrawable(LocationIcon.DEFAULT.getIconId()); } int locationX = (int) projectionXY[0]; int locationY = (int) projectionXY[1]; @@ -1148,33 +1150,32 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont private double[] calculateProjectionOnRoutePoint(List routeNodes, RoutingHelper helper, RotatedTileBox box) { double[] projectionXY; boolean visible; - Location previousInRoute = null; Location nextInRoute = null; - //need to change this code by fixing helper.route.getCurrentRoute() miscalculation // TODO simplifiy all culation! + Location ll = helper.getLastFixedLocation(); + Location previousInRoute = routeNodes.get(helper.getRoute().getCurrentRoute() > 0 ? helper.getRoute().getCurrentRoute() - 1 : 0); if (helper.getRoute().getIntermediatePointsToPass() > 0) { for (int i = 1; i < routeNodes.size(); i++) { LatLon routePoint = new LatLon(routeNodes.get(i).getLatitude(), routeNodes.get(i).getLongitude()); if (routePoint.equals(helper.getIntermediatePoints().get(0))) { - previousInRoute = routeNodes.get(i - 1); nextInRoute = routeNodes.get(i); } } } else { - previousInRoute = routeNodes.get(routeNodes.size() - 2); - nextInRoute = routeNodes.get(routeNodes.size() - 1); + nextInRoute = routeNodes.get(routeNodes.size()-1); } if (nextInRoute != null && previousInRoute != null) { - final Location ll = view.getApplication().getLocationProvider().getLastKnownLocation(); +// double Ri = MapUtils.getDistance(nextInRoute, ll); +// + 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);