This commit is contained in:
Victor Shcherb 2020-02-17 18:06:38 +01:00
parent 298893ae17
commit c419845b0c
2 changed files with 23 additions and 66 deletions

View file

@ -61,7 +61,6 @@ public class RoutingHelper {
private List<LatLon> intermediatePoints; private List<LatLon> intermediatePoints;
private Location lastProjection; private Location lastProjection;
private Location lastFixedLocation; private Location lastFixedLocation;
private Location originalStartingLocation;
private RouteCalculationResult originalRoute = null; private RouteCalculationResult originalRoute = null;
@ -180,7 +179,6 @@ public class RoutingHelper {
} }
public synchronized void setFinalAndCurrentLocation(LatLon finalLocation, List<LatLon> intermediatePoints, Location currentLocation){ public synchronized void setFinalAndCurrentLocation(LatLon finalLocation, List<LatLon> intermediatePoints, Location currentLocation){
setOriginalStartLocation(currentLocation);
checkAndUpdateStartLocation(currentLocation); checkAndUpdateStartLocation(currentLocation);
RouteCalculationResult previousRoute = route; RouteCalculationResult previousRoute = route;
clearCurrentRoute(finalLocation, intermediatePoints); clearCurrentRoute(finalLocation, intermediatePoints);
@ -188,25 +186,6 @@ public class RoutingHelper {
setCurrentLocation(currentLocation, false, previousRoute, true); setCurrentLocation(currentLocation, false, previousRoute, true);
} }
public RouteCalculationResult getOriginalRoute() {
return originalRoute;
}
public List<Location> 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<LatLon> newIntermediatePoints) { public synchronized void clearCurrentRoute(LatLon newFinalLocation, List<LatLon> newIntermediatePoints) {
route = new RouteCalculationResult(""); route = new RouteCalculationResult("");
isDeviatedFromRoute = false; isDeviatedFromRoute = false;

View file

@ -953,8 +953,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
} }
private void drawSegments(RotatedTileBox tb, Canvas canvas, double topLatitude, double leftLongitude, private void drawSegments(RotatedTileBox tb, Canvas canvas, double topLatitude, double leftLongitude,
double bottomLatitude, double rightLongitude, Location lastProjection, int currentRoute, boolean showOriginalRoute, double bottomLatitude, double rightLongitude, Location lastProjection, int currentRoute) {
Location pointToReturn) {
if (locations.size() == 0) { if (locations.size() == 0) {
return; return;
} }
@ -969,26 +968,20 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
GeometryWayStyle style = defaultWayStyle; GeometryWayStyle style = defaultWayStyle;
boolean previousVisible = false; boolean previousVisible = false;
if (lastProjection != null) { Location lastPoint = lastProjection;
if (leftLongitude <= lastProjection.getLongitude() && lastProjection.getLongitude() <= rightLongitude if (lastPoint != null) {
&& bottomLatitude <= lastProjection.getLatitude() && lastProjection.getLatitude() <= topLatitude) { previousVisible = addPoint(tb, topLatitude, leftLongitude, bottomLatitude, rightLongitude, style, previousVisible, lastPoint);
addLocation(tb, lastProjection, style, tx, ty, angles, distances, 0, styles);
previousVisible = true;
}
} }
List<Location> routeNodes; Location sp = helper.getRoute().getCurrentStraightAnglePoint();
if (showOriginalRoute && helper.getOriginalRoute() != null && helper.getOriginalRouteAllLoc() != null) { if (sp != null) {
routeNodes = helper.getOriginalRouteAllLoc(); lastPoint = sp;
} else { previousVisible = addPoint(tb, topLatitude, leftLongitude, bottomLatitude, rightLongitude, style, previousVisible, sp);
routeNodes = locations;
} }
List<Location> routeNodes = locations;
int previous = -1; int previous = -1;
for (int i = currentRoute; i < routeNodes.size(); i++) { for (int i = currentRoute; i < routeNodes.size(); i++) {
Location ls = routeNodes.get(i); Location ls = routeNodes.get(i);
style = getStyle(i, defaultWayStyle); style = getStyle(i, defaultWayStyle);
if (!showOriginalRoute && (simplification.getQuick(i) == 0 && !styleMap.containsKey(i))) {
continue;
}
if (leftLongitude <= ls.getLongitude() && ls.getLongitude() <= rightLongitude && bottomLatitude <= ls.getLatitude() if (leftLongitude <= ls.getLongitude() && ls.getLongitude() <= rightLongitude && bottomLatitude <= ls.getLatitude()
&& ls.getLatitude() <= topLatitude) { && ls.getLatitude() <= topLatitude) {
double dist = 0; double dist = 0;
@ -1019,6 +1012,15 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
drawRouteSegment(tb, canvas, tx, ty, angles, distances, 0, styles); drawRouteSegment(tb, canvas, tx, ty, angles, distances, 0, styles);
} }
private boolean addPoint(RotatedTileBox tb, double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, GeometryWayStyle style, boolean previousVisible, Location lastPoint) {
if (leftLongitude <= lastPoint .getLongitude() && lastPoint .getLongitude() <= rightLongitude
&& bottomLatitude <= lastPoint .getLatitude() && lastPoint .getLatitude() <= topLatitude) {
addLocation(tb, lastPoint, style, tx, ty, angles, distances, 0, styles);
previousVisible = true;
}
return previousVisible;
}
private void clearArrays() { private void clearArrays() {
tx.clear(); tx.clear();
ty.clear(); ty.clear();
@ -1103,7 +1105,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
startLocation.setLatitude(start.getLatitude()); startLocation.setLatitude(start.getLatitude());
startLocation.setLongitude(start.getLongitude()); startLocation.setLongitude(start.getLongitude());
routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude,
startLocation, 0, false, null); startLocation, 0);
} }
} else { } else {
@ -1112,36 +1114,12 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
routeGeometry.clearTransportRoute(); routeGeometry.clearTransportRoute();
routeGeometry.updateRoute(tb, route); routeGeometry.updateRoute(tb, route);
RouteProvider.RouteService rs = helper.getRoute().getRouteService(); RouteProvider.RouteService rs = helper.getRoute().getRouteService();
if (directTo && helper.getOriginalStartingLocation() != null) { if (directTo) {
routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude,
helper.getOriginalStartingLocation(), 0, true, null); null, 0);
} else { } else {
Location currentLoc = helper.getLastProjection();
int currentRoute = route == null ? 0 : route.getCurrentRoute();
Location pointToReturn = null;
if (route != null && currentRoute > 0 && route.getRouteRecalcDistance() > 0) {
// Location currentLoc = helper.getApplication().getLocationProvider().getLastKnownLocation();
// final Location from = routeGeometry.locations.get(currentRoute - 1);o
// final Location to = routeGeometry.locations.get(currentRoute);
// final LatLon projection = MapUtils.getProjection(currentLoc.getLatitude(),
// currentLoc.getLongitude(), from.getLatitude(), from.getLongitude(),
// to.getLatitude(), to.getLongitude());
//
// final double deviation = MapUtils.getDistance(projection.getLatitude(), projection.getLongitude(), currentLoc.getLatitude(), currentLoc.getLongitude());
// if (deviation < route.getRouteRecalcDistance()) {
// double distFromProjectionToEnd = Math.sqrt(Math.pow(to.getLatitude() - projection.getLatitude(), 2) + Math.pow(to.getLongitude() - projection.getLongitude(), 2));
// double coef = deviation / distFromProjectionToEnd;
// pointToReturn = new Location("route_layer");
// pointToReturn.setLatitude(projection.getLatitude() + (to.getLatitude() - projection.getLatitude()) * coef);
// pointToReturn.setLongitude(projection.getLongitude() + (to.getLongitude() - projection.getLatitude()) * coef);
// }
// if (pointToReturn != null) {
// drawProjectionPoint(canvas, new double[]{tb.getPixXFromLonNoRot(pointToReturn.getLongitude()), tb.getPixYFromLatNoRot(pointToReturn.getLatitude())});
// }
}
routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude,
helper.getLastProjection(), route == null ? 0 : route.getCurrentRoute(), false, pointToReturn); helper.getLastProjection(), route.getCurrentStraightAngleRoute());
} }
List<RouteDirectionInfo> rd = helper.getRouteDirections(); List<RouteDirectionInfo> rd = helper.getRouteDirections();
Iterator<RouteDirectionInfo> it = rd.iterator(); Iterator<RouteDirectionInfo> it = rd.iterator();
@ -1153,7 +1131,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
if (directTo) { if (directTo) {
//add projection point on original route //add projection point on original route
double[] projectionOnRoute = calculateProjectionOnRoutePoint( double[] projectionOnRoute = calculateProjectionOnRoutePoint(
helper.getOriginalRouteAllLoc(), helper, tb); helper.getRoute().getImmutableAllLocations(), helper, tb);
if (projectionOnRoute != null) { if (projectionOnRoute != null) {
drawProjectionPoint(canvas, projectionOnRoute); drawProjectionPoint(canvas, projectionOnRoute);
} }