From db4f832b04ca4e1fb7f400d35af52dcc00b861ff Mon Sep 17 00:00:00 2001 From: MadWasp79 Date: Tue, 11 Feb 2020 10:56:34 +0200 Subject: [PATCH 1/5] basic implementation --- .../main/java/net/osmand/util/MapUtils.java | 35 ++++++++ .../profiles/RoutingProfileDataObject.java | 1 + .../plus/routing/RouteCalculationParams.java | 3 +- .../plus/routing/RouteCalculationResult.java | 11 ++- .../osmand/plus/routing/RouteProvider.java | 39 +++++++-- .../osmand/plus/routing/RoutingHelper.java | 32 +++++++ .../src/net/osmand/plus/views/RouteLayer.java | 87 +++++++++++++++++-- 7 files changed, 191 insertions(+), 17 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 aeb0570950..7c83cb8f89 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java @@ -661,6 +661,41 @@ public class MapUtils { return new LatLon(Math.toDegrees(phi2), Math.toDegrees(lambda2)); } + + public static double getVectorMagnitude(int startX, int startY, int endX, int endY) { + return Math.sqrt(Math.pow((double) (endX - startX), 2.0) + Math.pow((double) (endY - startY), 2.0)); + } + + //angle of vector + public static double getAngleForRadiusVector(int startX, int startY, int endX, int endY) { + return 2 * Math.atan((endY - startY) / (endX - startX + + Math.sqrt(Math.pow((double) (endX - startX), 2.0) + Math.pow((double) (endY - startY), 2.0)))); + } + + //returns coordinates of point on circle + public static double[] getCoordinatesFromRadiusAndAngle(double centerX, double centerY, double radius, double angle) { + double x = centerX + radius * Math.cos(angle); + double y = centerY + radius * Math.sin(angle); + return new double[]{x,y}; + } + + //returns signed angle between vectors in radians + public static double getAngleBetweenVectors(int vectorAStartX, int vectorAStartY, int vectorAEndX, int vectorAEndY, + int vectorBStartX, int vectorBStartY, int vectorBEndX, int vectorBEndY) { + int[] vectorA = new int[] {getVectorAxisValue(vectorAStartX, vectorAEndX), getVectorAxisValue(vectorAStartY, vectorAEndY)}; + int[] vectorB = new int[] {getVectorAxisValue(vectorBStartX, vectorBEndX), getVectorAxisValue(vectorBStartY, vectorBEndY)}; + return Math.atan2(vectorA[0] * vectorB[1] - vectorA[1] * vectorB [0], vectorA[0] * vectorB[0] + vectorA[1] * vectorB[1]); + } + + //calculates vector value for axis + public static int getVectorAxisValue(int axisStart, int axisEnd) { + if (axisEnd < axisStart) { + return Math.abs(axisEnd) - Math.abs(axisStart); + } else { + return Math.abs(axisStart) - Math.abs(axisEnd); + } + } + } diff --git a/OsmAnd/src/net/osmand/plus/profiles/RoutingProfileDataObject.java b/OsmAnd/src/net/osmand/plus/profiles/RoutingProfileDataObject.java index b812022ec1..9674ce43ee 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/RoutingProfileDataObject.java +++ b/OsmAnd/src/net/osmand/plus/profiles/RoutingProfileDataObject.java @@ -20,6 +20,7 @@ public class RoutingProfileDataObject extends ProfileDataObject { } public enum RoutingProfilesResources { + STRAIGHT_TO_LINE_MODE(R.string.routing_profile_straight_to, R.drawable.ic_action_split_interval), STRAIGHT_LINE_MODE(R.string.routing_profile_straightline, R.drawable.ic_action_split_interval), BROUTER_MODE(R.string.routing_profile_broutrer, R.drawable.ic_action_split_interval), CAR(R.string.rendering_value_car_name, R.drawable.ic_action_car_dark), diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java index 00b414465c..99d7c6a959 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java @@ -18,7 +18,6 @@ public class RouteCalculationParams { public LatLon end; public List intermediates; - public OsmandApplication ctx; public RoutingContext cachedRoutingContext; public ApplicationMode mode; @@ -35,6 +34,8 @@ public class RouteCalculationParams { public RouteCalculationProgressCallback calculationProgressCallback; public RouteCalculationResultListener resultListener; + public boolean showOriginalRoute; + 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 2faaca1a3a..f9daa250d1 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -63,6 +63,8 @@ public class RouteCalculationResult { protected int lastWaypointGPX = 0; protected ApplicationMode appMode; + protected boolean showOriginalRoute = false; + public RouteCalculationResult(String errorMessage) { this.errorMessage = errorMessage; this.routingTime = 0; @@ -76,7 +78,7 @@ public class RouteCalculationResult { this.directions = new ArrayList(); this.alarmInfo = new ArrayList(); } - + public RouteCalculationResult(List list, List directions, RouteCalculationParams params, List waypoints, boolean addMissingTurns) { this.routingTime = 0; this.loadedTiles = 0; @@ -108,6 +110,8 @@ public class RouteCalculationResult { calculateIntermediateIndexes(params.ctx, this.locations, params.intermediates, localDirections, this.intermediatePoints); this.directions = Collections.unmodifiableList(localDirections); updateDirectionsTime(this.directions, this.listDistance); + + this.showOriginalRoute = params.showOriginalRoute; } public RouteCalculationResult(List list, Location start, LatLon end, List intermediates, @@ -1154,5 +1158,8 @@ public class RouteCalculationResult { public int imminent; private int directionInfoInd; } - + + public boolean isShowOriginalRoute() { + return showOriginalRoute; + } } diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 018bb5ae9c..a357fed452 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -79,7 +79,8 @@ public class RouteProvider { public enum RouteService { OSMAND("OsmAnd (offline)"), BROUTER("BRouter (offline)"), - STRAIGHT("Straight line"); + STRAIGHT("Straight line"), + STRAIGHT_TO("Straight To"); private final String name; @@ -305,7 +306,7 @@ public class RouteProvider { try { RouteCalculationResult res; boolean calcGPXRoute = params.gpxRoute != null && !params.gpxRoute.points.isEmpty(); - if(calcGPXRoute && !params.gpxRoute.calculateOsmAndRoute){ + if (calcGPXRoute && !params.gpxRoute.calculateOsmAndRoute) { res = calculateGpxRoute(params); } else if (params.mode.getRouteService() == RouteService.OSMAND) { res = findVectorMapsRoute(params, calcGPXRoute); @@ -315,10 +316,11 @@ public class RouteProvider { // res = findORSRoute(params); // } else if (params.type == RouteService.OSRM) { // res = findOSRMRoute(params); - } else if (params.mode.getRouteService() == RouteService.STRAIGHT){ + } else if (params.mode.getRouteService() == RouteService.STRAIGHT) { res = findStraightRoute(params); - } - else { + } else if (params.mode.getRouteService() == RouteService.STRAIGHT_TO) { + res = findStraightTo(params); + } else { res = new RouteCalculationResult("Selected route service is not available"); } if(log.isInfoEnabled() ){ @@ -1257,4 +1259,31 @@ public class RouteProvider { dots.add(location); return new RouteCalculationResult(dots, null, params, null, true); } + + private RouteCalculationResult findStraightTo(RouteCalculationParams params) { + params.showOriginalRoute = 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; + List dots = new ArrayList(); + //writing start location + Location location = new Location(String.valueOf("start")); + location.setLatitude(lats[0]); + location.setLongitude(lons[0]); + //adding intermediate dots if they exists + if (intermediates != null){ + for(int i =0; i intermediatePoints; private Location lastProjection; private Location lastFixedLocation; + private Location originalStartingLocation; + + private RouteCalculationResult originalRoute = null; private static final int RECALCULATE_THRESHOLD_COUNT_CAUSING_FULL_RECALCULATE = 3; private static final int RECALCULATE_THRESHOLD_CAUSING_FULL_RECALCULATE_INTERVAL = 2*60*1000; @@ -174,6 +177,7 @@ public class RoutingHelper { } public synchronized void setFinalAndCurrentLocation(LatLon finalLocation, List intermediatePoints, Location currentLocation){ + setOriginalStartLocation(currentLocation); checkAndUpdateStartLocation(currentLocation); RouteCalculationResult previousRoute = route; clearCurrentRoute(finalLocation, intermediatePoints); @@ -181,10 +185,30 @@ public class RoutingHelper { setCurrentLocation(currentLocation, false, previousRoute, true); } + public RouteCalculationResult getOriginalRoute() { + return originalRoute; + } + public List getOriginalRouteAllLoc() { + return originalRoute.getImmutableAllLocations(); + } + + public void setOriginalRoute(RouteCalculationResult originalRoute) { + this.originalRoute = originalRoute; + } + + private void setOriginalStartLocation(Location currentLocation) { + originalStartingLocation = currentLocation; + } + + public Location getOriginalStartingLocation() { + return originalStartingLocation; + } + public synchronized void clearCurrentRoute(LatLon newFinalLocation, List newIntermediatePoints) { route = new RouteCalculationResult(""); isDeviatedFromRoute = false; evalWaitInterval = 0; + originalRoute = null; app.getWaypointHelper().setNewRoute(route); app.runInUIThread(new Runnable() { @Override @@ -399,6 +423,7 @@ public class RoutingHelper { // 0. Route empty or needs to be extended? Then re-calculate route. if(route.isEmpty()) { calculateRoute = true; + //originalRoute = null; } else { // 1. Update current route position status according to latest received location boolean finished = updateCurrentRouteStatus(currentLocation, posTolerance); @@ -987,6 +1012,7 @@ public class RoutingHelper { if (res.isCalculated()) { if (!params.inSnapToRoadMode && !params.inPublicTransportMode) { route = res; + updateOriginalRoute(); } if (params.resultListener != null) { params.resultListener.onRouteCalculated(res); @@ -1092,6 +1118,12 @@ public class RoutingHelper { } } + private void updateOriginalRoute() { + if (originalRoute == null) { + originalRoute = route; + } + } + public void startRouteCalculationThread(RouteCalculationParams params, boolean paramsChanged, boolean updateProgress) { synchronized (this) { final Thread prevRunningJob = currentRunningJob; diff --git a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java index 6475fa6d78..acdcb2450d 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java @@ -18,6 +18,7 @@ import android.support.v4.content.ContextCompat; import android.util.Pair; import net.osmand.Location; +import net.osmand.PlatformUtil; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; @@ -45,6 +46,8 @@ import net.osmand.router.TransportRoutePlanner.TransportRouteResult; import net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment; import net.osmand.util.MapUtils; +import org.apache.commons.logging.Log; + import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -68,6 +71,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont // keep array lists created private List actionPoints = new ArrayList(); private List routeTransportStops = new ArrayList<>(); + private double[] lastProjectionOnPathPoint; // cache private Bitmap actionArrow; @@ -87,6 +91,8 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont private GeometryWayContext wayContext; + private LayerDrawable projectionIcon; + public RouteLayer(RoutingHelper helper) { this.helper = helper; this.transportHelper = helper.getTransportRoutingHelper(); @@ -309,6 +315,21 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont } } + private void drawProjectionPoint(RotatedTileBox box, Canvas canvas, double[] projectionXY) { + if (projectionIcon == null) { + projectionIcon = (LayerDrawable) view.getResources().getDrawable(helper.getSettings().getApplicationMode().getLocationIcon().getIconId()); + } + int locationX = (int) projectionXY[0]; + int locationY = (int) projectionXY[1]; + + projectionIcon.setBounds(locationX - projectionIcon.getIntrinsicWidth() / 2, + locationY - projectionIcon.getIntrinsicHeight() / 2, + locationX + projectionIcon.getIntrinsicWidth() / 2, + locationY + projectionIcon.getIntrinsicHeight() / 2); + projectionIcon.draw(canvas); + + } + @ColorInt public int getRouteLineColor(boolean night) { updateAttrs(new DrawSettings(night), view.getCurrentRotatedTileBox()); @@ -820,7 +841,8 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont return simplifyPoints; } } - + private final static Log log = PlatformUtil.getLog(RouteLayer.class); + private class RouteSimplificationGeometry { RouteCalculationResult route; TransportRouteResult transportRoute; @@ -930,7 +952,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont } private void drawSegments(RotatedTileBox tb, Canvas canvas, double topLatitude, double leftLongitude, - double bottomLatitude, double rightLongitude, Location lastProjection, int currentRoute) { + double bottomLatitude, double rightLongitude, Location lastProjection, int currentRoute, boolean showOriginalRoute) { if (locations.size() == 0) { return; } @@ -951,12 +973,17 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont previousVisible = true; } } - List routeNodes = locations; + List routeNodes; + if (showOriginalRoute && helper.getOriginalRoute() != null && helper.getOriginalRouteAllLoc() != null) { + routeNodes = helper.getOriginalRouteAllLoc(); + } else { + routeNodes = locations; + } int previous = -1; for (int i = currentRoute; i < routeNodes.size(); i++) { Location ls = routeNodes.get(i); style = getStyle(i, defaultWayStyle); - if (simplification.getQuick(i) == 0 && !styleMap.containsKey(i)) { + if (!showOriginalRoute && (simplification.getQuick(i) == 0 && !styleMap.containsKey(i))) { continue; } if (leftLongitude <= ls.getLongitude() && ls.getLongitude() <= rightLongitude && bottomLatitude <= ls.getLatitude() @@ -1072,25 +1099,67 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont Location startLocation = new Location("transport"); startLocation.setLatitude(start.getLatitude()); startLocation.setLongitude(start.getLongitude()); - routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, startLocation, 0); + routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, startLocation, 0, false); } } else { RouteCalculationResult route = helper.getRoute(); routeGeometry.clearTransportRoute(); routeGeometry.updateRoute(tb, route); - routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, - helper.getLastProjection(), route == null ? 0 : route.getCurrentRoute()); + if (helper.getRoute().isShowOriginalRoute()) { + routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, + helper.getOriginalStartingLocation(), route == null ? 0 : route.getCurrentRoute(), true); + } else { + routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, + helper.getLastProjection(), route == null ? 0 : route.getCurrentRoute(), false); + } List rd = helper.getRouteDirections(); Iterator it = rd.iterator(); - if (tb.getZoom() >= 14) { + if (!helper.getRoute().isShowOriginalRoute() && tb.getZoom() >= 14) { List actionPoints = calculateActionPoints(topLatitude, leftLongitude, bottomLatitude, rightLongitude, helper.getLastProjection(), helper.getRoute().getRouteLocations(), helper.getRoute().getCurrentRoute(), it, tb.getZoom()); drawAction(tb, canvas, actionPoints); } + if (helper.getRoute().isShowOriginalRoute()) { + //add projection point on original route + + double[] projectionOnRoute = calculateProjectionOnRoutePoint(helper.getLastProjection(), + helper.getOriginalRouteAllLoc(), helper.getRoute().getCurrentRoute(), tb); + if (projectionOnRoute != null) { + log.debug("Draw projection"); + drawProjectionPoint(tb, canvas, projectionOnRoute); + } + } } } - + private double[] calculateProjectionOnRoutePoint(Location lastProjection, List routeNodes, int cd, RotatedTileBox box) { + + double[] projectionXY = new double[2]; + boolean visible = false; + if (cd < routeNodes.size() - 1) { + Location previousInRoute = routeNodes.get(cd); + Location nextInRoute = routeNodes.get(cd + 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()); + + double radius = MapUtils.getVectorMagnitude(centerX, centerY, aX, aY); + double angle2 = MapUtils.getAngleForRadiusVector(centerX, centerY, bX, bY); + projectionXY = MapUtils.getCoordinatesFromRadiusAndAngle(centerX, centerY, radius, angle2); + log.debug("Projection: " + projectionXY[0] + ", " + projectionXY[1]); + 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; + } + + } private List calculateActionPoints(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, Location lastProjection, List routeNodes, int cd, From f4645fcaf22ef3fcfa6f03389fc2478c04e22024 Mon Sep 17 00:00:00 2001 From: MadWasp79 Date: Tue, 11 Feb 2020 12:47:44 +0200 Subject: [PATCH 2/5] work in progress --- .../src/net/osmand/plus/views/RouteLayer.java | 55 +++++++++++-------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java index acdcb2450d..9dcca6e9c4 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java @@ -92,7 +92,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont private GeometryWayContext wayContext; private LayerDrawable projectionIcon; - + private final static Log log = PlatformUtil.getLog(RouteLayer.class); public RouteLayer(RoutingHelper helper) { this.helper = helper; this.transportHelper = helper.getTransportRoutingHelper(); @@ -841,7 +841,6 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont return simplifyPoints; } } - private final static Log log = PlatformUtil.getLog(RouteLayer.class); private class RouteSimplificationGeometry { RouteCalculationResult route; @@ -1105,7 +1104,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont RouteCalculationResult route = helper.getRoute(); routeGeometry.clearTransportRoute(); routeGeometry.updateRoute(tb, route); - if (helper.getRoute().isShowOriginalRoute()) { + if (helper.getRoute().isShowOriginalRoute() && helper.getOriginalStartingLocation() != null) { routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, helper.getOriginalStartingLocation(), route == null ? 0 : route.getCurrentRoute(), true); } else { @@ -1121,11 +1120,9 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont } if (helper.getRoute().isShowOriginalRoute()) { //add projection point on original route - double[] projectionOnRoute = calculateProjectionOnRoutePoint(helper.getLastProjection(), helper.getOriginalRouteAllLoc(), helper.getRoute().getCurrentRoute(), tb); if (projectionOnRoute != null) { - log.debug("Draw projection"); drawProjectionPoint(tb, canvas, projectionOnRoute); } } @@ -1133,26 +1130,36 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont } private double[] calculateProjectionOnRoutePoint(Location lastProjection, List routeNodes, int cd, RotatedTileBox box) { - - double[] projectionXY = new double[2]; - boolean visible = false; - if (cd < routeNodes.size() - 1) { - Location previousInRoute = routeNodes.get(cd); - Location nextInRoute = routeNodes.get(cd + 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()); - - double radius = MapUtils.getVectorMagnitude(centerX, centerY, aX, aY); - double angle2 = MapUtils.getAngleForRadiusVector(centerX, centerY, bX, bY); - projectionXY = MapUtils.getCoordinatesFromRadiusAndAngle(centerX, centerY, radius, angle2); - log.debug("Projection: " + projectionXY[0] + ", " + projectionXY[1]); - 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; + log.debug("cd: " + cd); + double[] projectionXY; + boolean visible; + Location previousInRoute; + Location nextInRoute; + //need to change this code by fixing helper.route.getCurrentRoute() miscalculation + if (cd == 0) { + previousInRoute = routeNodes.get(cd); + nextInRoute = routeNodes.get(cd + 1); + } else if (cd == routeNodes.size() - 1) { + previousInRoute = routeNodes.get(cd - 1); + nextInRoute = routeNodes.get(cd); + } else { + previousInRoute = routeNodes.get(cd); + nextInRoute = routeNodes.get(cd + 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()); + + double radius = MapUtils.getVectorMagnitude(centerX, centerY, aX, aY); + double angle2 = MapUtils.getAngleForRadiusVector(centerX, centerY, bX, bY); + projectionXY = MapUtils.getCoordinatesFromRadiusAndAngle(centerX, centerY, radius, angle2); +// log.debug("Projection: " + projectionXY[0] + ", " + projectionXY[1]); + 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 { From 3035a186dfb6c81f2e4bc7bc8d75141474542d69 Mon Sep 17 00:00:00 2001 From: MadWasp79 Date: Tue, 11 Feb 2020 14:39:02 +0200 Subject: [PATCH 3/5] fix intermediate points --- OsmAnd/src/net/osmand/plus/views/RouteLayer.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java index 9dcca6e9c4..1faff9aac7 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java @@ -1121,7 +1121,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont if (helper.getRoute().isShowOriginalRoute()) { //add projection point on original route double[] projectionOnRoute = calculateProjectionOnRoutePoint(helper.getLastProjection(), - helper.getOriginalRouteAllLoc(), helper.getRoute().getCurrentRoute(), tb); + helper.getOriginalRouteAllLoc(), helper, tb); if (projectionOnRoute != null) { drawProjectionPoint(tb, canvas, projectionOnRoute); } @@ -1129,12 +1129,11 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont } } - private double[] calculateProjectionOnRoutePoint(Location lastProjection, List routeNodes, int cd, RotatedTileBox box) { - log.debug("cd: " + cd); + private double[] calculateProjectionOnRoutePoint(Location lastProjection, List routeNodes, RoutingHelper helper, RotatedTileBox box) { double[] projectionXY; boolean visible; - Location previousInRoute; - Location nextInRoute; + Location previousInRoute = null; + Location nextInRoute = null; //need to change this code by fixing helper.route.getCurrentRoute() miscalculation if (cd == 0) { previousInRoute = routeNodes.get(cd); @@ -1143,9 +1142,10 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont previousInRoute = routeNodes.get(cd - 1); nextInRoute = routeNodes.get(cd); } else { - previousInRoute = routeNodes.get(cd); - nextInRoute = routeNodes.get(cd + 1); + previousInRoute = routeNodes.get(routeNodes.size() - 2); + nextInRoute = routeNodes.get(routeNodes.size() - 1); } + int centerX = box.getPixXFromLonNoRot(nextInRoute.getLongitude()); int centerY = box.getPixYFromLatNoRot(nextInRoute.getLatitude()); int aX = box.getPixXFromLonNoRot(lastProjection.getLongitude()); From 328826902ca0727abc184f64f8b87714c5263936 Mon Sep 17 00:00:00 2001 From: MadWasp79 Date: Tue, 11 Feb 2020 15:30:59 +0200 Subject: [PATCH 4/5] fix intermediate points --- .../src/net/osmand/plus/views/RouteLayer.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java index 1faff9aac7..0cd64df9fe 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java @@ -1106,7 +1106,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont routeGeometry.updateRoute(tb, route); if (helper.getRoute().isShowOriginalRoute() && helper.getOriginalStartingLocation() != null) { routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, - helper.getOriginalStartingLocation(), route == null ? 0 : route.getCurrentRoute(), true); + helper.getOriginalStartingLocation(), 0, true); } else { routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, helper.getLastProjection(), route == null ? 0 : route.getCurrentRoute(), false); @@ -1135,12 +1135,15 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont Location previousInRoute = null; Location nextInRoute = null; //need to change this code by fixing helper.route.getCurrentRoute() miscalculation - if (cd == 0) { - previousInRoute = routeNodes.get(cd); - nextInRoute = routeNodes.get(cd + 1); - } else if (cd == routeNodes.size() - 1) { - previousInRoute = routeNodes.get(cd - 1); - nextInRoute = routeNodes.get(cd); + log.debug("intermediates: " + helper.getIntermediatePoints()); + 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); @@ -1156,7 +1159,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont double radius = MapUtils.getVectorMagnitude(centerX, centerY, aX, aY); double angle2 = MapUtils.getAngleForRadiusVector(centerX, centerY, bX, bY); projectionXY = MapUtils.getCoordinatesFromRadiusAndAngle(centerX, centerY, radius, angle2); -// log.debug("Projection: " + projectionXY[0] + ", " + projectionXY[1]); + log.debug("Projection: " + projectionXY[0] + ", " + projectionXY[1]); 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; From 6369969acdb911801ea32102582e8509acd559e2 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Tue, 11 Feb 2020 19:28:47 +0100 Subject: [PATCH 5/5] Update RouteLayer.java --- OsmAnd/src/net/osmand/plus/views/RouteLayer.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java index 0cd64df9fe..97b22822b4 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java @@ -1135,7 +1135,6 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont Location previousInRoute = null; Location nextInRoute = null; //need to change this code by fixing helper.route.getCurrentRoute() miscalculation - log.debug("intermediates: " + helper.getIntermediatePoints()); 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()); @@ -1159,7 +1158,6 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont double radius = MapUtils.getVectorMagnitude(centerX, centerY, aX, aY); double angle2 = MapUtils.getAngleForRadiusVector(centerX, centerY, bX, bY); projectionXY = MapUtils.getCoordinatesFromRadiusAndAngle(centerX, centerY, radius, angle2); - log.debug("Projection: " + projectionXY[0] + ", " + projectionXY[1]); 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;