fix settings formatting
calculate pointToReturn on track.
This commit is contained in:
parent
6069ee0a38
commit
38e935fb96
6 changed files with 54 additions and 17 deletions
|
@ -11,8 +11,8 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="route_recalculation_dist_title">Minimal distance to recalculate</string>
|
||||
<string name="route_recalculation_dist_descr">Minimal distance of deviation from route to start recalculation</string>
|
||||
<string name="route_recalculation_dist_title">Minimal distance to recalculate route</string>
|
||||
<string name="route_recalculation_dist_descr">The route will be recalculated if the distance to the route is longer than specified parameter</string>
|
||||
<string name="routing_profile_direct_to">Direct-to-point</string>
|
||||
<string name="clear_recorded_data">Clear recorded data</string>
|
||||
<string name="release_3_6">
|
||||
|
|
|
@ -3282,7 +3282,7 @@ public class OsmandSettings {
|
|||
return customBooleanRoutingProps.get(attrName);
|
||||
}
|
||||
|
||||
public final CommonPreference<Float> ROUTE_RECALCULATION_DISTANCE = new FloatPreference("routing_recalc_distance", 10.f).makeProfile();
|
||||
public final CommonPreference<Float> ROUTE_RECALCULATION_DISTANCE = new FloatPreference("routing_recalc_distance", -1.f).makeProfile();
|
||||
|
||||
public final OsmandPreference<Boolean> USE_OSM_LIVE_FOR_ROUTING = new BooleanPreference("enable_osmc_routing", true).makeGlobal();
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ public class RouteCalculationResult {
|
|||
protected ApplicationMode appMode;
|
||||
protected boolean noRecalculations = false;
|
||||
protected boolean showOriginalRoute = false;
|
||||
protected float routeRecalcDistance = 10.f;
|
||||
protected float routeRecalcDistance = -1f;
|
||||
|
||||
public RouteCalculationResult(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
|
@ -115,6 +115,7 @@ public class RouteCalculationResult {
|
|||
|
||||
this.showOriginalRoute = params.showOriginalRoute;
|
||||
this.noRecalculations = params.noRecalculations;
|
||||
if (params.routeRecalculationDistance != 0)
|
||||
this.routeRecalcDistance = params.routeRecalculationDistance;
|
||||
}
|
||||
|
||||
|
@ -236,6 +237,10 @@ public class RouteCalculationResult {
|
|||
}
|
||||
}
|
||||
|
||||
public float getRouteRecalcDistance() {
|
||||
return routeRecalcDistance;
|
||||
}
|
||||
|
||||
public List<RouteSegmentResult> getOriginalRoute() {
|
||||
if (segments.size() == 0) {
|
||||
return null;
|
||||
|
|
|
@ -398,6 +398,13 @@ public class RoutingHelper {
|
|||
return getOrthogonalDistance(lastFixedLocation, routeNodes.get(route.currentRoute -1), routeNodes.get(route.currentRoute));
|
||||
}
|
||||
|
||||
public float getPosTolerance(Location currentLocation) {
|
||||
if(currentLocation.hasAccuracy()) {
|
||||
return POSITION_TOLERANCE / 2 + currentLocation.getAccuracy();
|
||||
}
|
||||
return POSITION_TOLERANCE;
|
||||
}
|
||||
|
||||
private Location setCurrentLocation(Location currentLocation, boolean returnUpdatedLocation,
|
||||
RouteCalculationResult previousRoute, boolean targetPointsChanged) {
|
||||
Location locationProjection = currentLocation;
|
||||
|
@ -413,10 +420,7 @@ public class RoutingHelper {
|
|||
isDeviatedFromRoute = false;
|
||||
return locationProjection;
|
||||
}
|
||||
float posTolerance = POSITION_TOLERANCE;
|
||||
if(currentLocation.hasAccuracy()) {
|
||||
posTolerance = POSITION_TOLERANCE / 2 + currentLocation.getAccuracy();
|
||||
}
|
||||
float posTolerance = getPosTolerance(currentLocation);
|
||||
boolean calculateRoute = false;
|
||||
synchronized (this) {
|
||||
isDeviatedFromRoute = false;
|
||||
|
@ -436,10 +440,11 @@ public class RoutingHelper {
|
|||
int currentRoute = route.currentRoute;
|
||||
|
||||
// 2. Analyze if we need to recalculate route
|
||||
// >100m off current route (sideways)
|
||||
// >100m off current route (sideways) or parameter (for Straight line)
|
||||
if (currentRoute > 0 && !route.noRecalculations) {
|
||||
double allowableDeviation = route.routeRecalcDistance <= 0 ? (1.7 * posTolerance) : route.routeRecalcDistance;
|
||||
distOrth = getOrthogonalDistance(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
|
||||
if ((!settings.DISABLE_OFFROUTE_RECALC.get()) && (distOrth > (1.7 * posTolerance))) {
|
||||
if ((!settings.DISABLE_OFFROUTE_RECALC.get()) && (distOrth > allowableDeviation)) {
|
||||
log.info("Recalculate route, because correlation : " + distOrth); //$NON-NLS-1$
|
||||
isDeviatedFromRoute = true;
|
||||
calculateRoute = true;
|
||||
|
@ -448,8 +453,9 @@ public class RoutingHelper {
|
|||
// 3. Identify wrong movement direction
|
||||
Location next = route.getNextRouteLocation();
|
||||
boolean wrongMovementDirection = checkWrongMovementDirection(currentLocation, next);
|
||||
double allowableDeviation = route.routeRecalcDistance <= 0 ? (2 * posTolerance) : route.routeRecalcDistance;
|
||||
if ((!settings.DISABLE_WRONG_DIRECTION_RECALC.get()) && wrongMovementDirection
|
||||
&& (currentLocation.distanceTo(routeNodes.get(currentRoute)) > (2 * posTolerance)) && !route.noRecalculations) {
|
||||
&& (currentLocation.distanceTo(routeNodes.get(currentRoute)) > allowableDeviation) && !route.noRecalculations) {
|
||||
log.info("Recalculate route, because wrong movement direction: " + currentLocation.distanceTo(routeNodes.get(currentRoute))); //$NON-NLS-1$
|
||||
isDeviatedFromRoute = true;
|
||||
calculateRoute = true;
|
||||
|
@ -1099,6 +1105,7 @@ public class RoutingHelper {
|
|||
params.fast = settings.FAST_ROUTE_MODE.getModeValue(mode);
|
||||
params.mode = mode;
|
||||
params.ctx = app;
|
||||
params.routeRecalculationDistance = settings.ROUTE_RECALCULATION_DISTANCE.getModeValue(mode);
|
||||
boolean updateProgress = false;
|
||||
if (params.mode.getRouteService() == RouteService.OSMAND) {
|
||||
params.calculationProgress = new RouteCalculationProgress();
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.widget.ImageView;
|
|||
|
||||
import net.osmand.StateChangedListener;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.OsmandSettings.BooleanPreference;
|
||||
|
@ -234,11 +235,11 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
|||
}
|
||||
|
||||
private void setupSelectRouteRecalcDistance(PreferenceScreen screen) {
|
||||
Float[] entryValues = new Float[] {10.f, 20.0f, 30.0f, 50.0f, 100.0f, 200.0f, 500.0f, 1000.0f, 1500.0f};
|
||||
Float[] entryValues = new Float[] {-1.0f, 10.f, 20.0f, 30.0f, 50.0f, 100.0f, 200.0f, 500.0f, 1000.0f, 1500.0f};
|
||||
String[] entries = new String[entryValues.length];
|
||||
entries[0] = getString(R.string.shared_string_not_selected);
|
||||
for (int i = 1; i < entryValues.length; i++) {
|
||||
entries[i] = entryValues[i].intValue() + " " + getString(R.string.m) + " (" + Math.round(entryValues[i] / 0.3048f) + " " + getString(R.string.foot) + ")";
|
||||
entries[i] = OsmAndFormatter.getFormattedDistance(entryValues[i], app, false);
|
||||
}
|
||||
ListPreferenceEx routeRecalculationDist = createListPreferenceEx(settings.ROUTE_RECALCULATION_DISTANCE.getId(),
|
||||
entries, entryValues, R.string.route_recalculation_dist_title, R.layout.preference_with_descr);
|
||||
|
|
|
@ -952,7 +952,8 @@ 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, boolean showOriginalRoute) {
|
||||
double bottomLatitude, double rightLongitude, Location lastProjection, int currentRoute, boolean showOriginalRoute,
|
||||
Location pointToReturn) {
|
||||
if (locations.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -966,6 +967,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
|
|||
new GeometrySolidWayStyle(wayContext, attrs.paint.getColor());
|
||||
GeometryWayStyle style = defaultWayStyle;
|
||||
boolean previousVisible = false;
|
||||
|
||||
if (lastProjection != null) {
|
||||
if (leftLongitude <= lastProjection.getLongitude() && lastProjection.getLongitude() <= rightLongitude
|
||||
&& bottomLatitude <= lastProjection.getLatitude() && lastProjection.getLatitude() <= topLatitude) {
|
||||
|
@ -1099,7 +1101,8 @@ 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, false);
|
||||
routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude,
|
||||
startLocation, 0, false, null);
|
||||
}
|
||||
} else {
|
||||
RouteCalculationResult route = helper.getRoute();
|
||||
|
@ -1107,10 +1110,31 @@ 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(), 0, true);
|
||||
helper.getOriginalStartingLocation(), 0, true, null);
|
||||
} else {
|
||||
Location currentLoc = helper.getLastProjection();
|
||||
int currentRoute = route == null ? 0 : route.getCurrentRoute();
|
||||
Location pointToReturn = null;
|
||||
if (route != null && currentRoute > 0 && route.getRouteRecalcDistance() > 0) {
|
||||
final Location from = routeGeometry.locations.get(currentRoute - 1);
|
||||
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);
|
||||
//how to draw line to this point from lastProjection?!
|
||||
}
|
||||
}
|
||||
|
||||
routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude,
|
||||
helper.getLastProjection(), route == null ? 0 : route.getCurrentRoute(), false);
|
||||
helper.getLastProjection(), route == null ? 0 : route.getCurrentRoute(), false, pointToReturn);
|
||||
}
|
||||
List<RouteDirectionInfo> rd = helper.getRouteDirections();
|
||||
Iterator<RouteDirectionInfo> it = rd.iterator();
|
||||
|
|
Loading…
Reference in a new issue