Fix settings

This commit is contained in:
Victor Shcherb 2020-02-14 18:03:35 +01:00
parent a3dc78c8cd
commit 116673f081
5 changed files with 46 additions and 43 deletions

View file

@ -3283,23 +3283,6 @@ public class OsmandSettings {
} }
public final CommonPreference<Float> ROUTE_RECALCULATION_DISTANCE = new FloatPreference("routing_recalc_distance", 0.f){ public final CommonPreference<Float> ROUTE_RECALCULATION_DISTANCE = new FloatPreference("routing_recalc_distance", 0.f){
@Override
public Float getProfileDefaultValue(ApplicationMode mode) {
if (DISABLE_OFFROUTE_RECALC.getModeValue(mode)) {
return -1.0f;
} else if (mode.getRouteService() == RouteService.DIRECT_TO) {
DISABLE_OFFROUTE_RECALC.setModeValue(mode, true);
return -1.0f;
} else if (mode.getRouteService() == RouteService.STRAIGHT) {
MetricsConstants mc = METRIC_SYSTEM.getModeValue(mode);
if (mc == MetricsConstants.KILOMETERS_AND_METERS || mc ==MetricsConstants.MILES_AND_METERS) {
return 500.f;
} else {
return 482.0f;
}
}
return super.getProfileDefaultValue(mode);
}
}.makeProfile(); }.makeProfile();
public final OsmandPreference<Boolean> USE_OSM_LIVE_FOR_ROUTING = new BooleanPreference("enable_osmc_routing", true).makeGlobal(); public final OsmandPreference<Boolean> USE_OSM_LIVE_FOR_ROUTING = new BooleanPreference("enable_osmc_routing", true).makeGlobal();

View file

@ -65,7 +65,7 @@ public class RouteCalculationResult {
protected ApplicationMode appMode; protected ApplicationMode appMode;
protected boolean showOriginalRoute = false; protected boolean showOriginalRoute = false;
protected float routeRecalcDistance = 0.f; protected double routeRecalcDistance = 0.d;
public RouteCalculationResult(String errorMessage) { public RouteCalculationResult(String errorMessage) {
this.errorMessage = errorMessage; this.errorMessage = errorMessage;
@ -238,7 +238,7 @@ public class RouteCalculationResult {
} }
} }
public float getRouteRecalcDistance() { public double getRouteRecalcDistance() {
return routeRecalcDistance; return routeRecalcDistance;
} }

View file

@ -42,6 +42,7 @@ public class RoutingHelper {
private static final float POSITION_TOLERANCE = 60; private static final float POSITION_TOLERANCE = 60;
private static final int CACHE_RADIUS = 100000; private static final int CACHE_RADIUS = 100000;
public static final float ALLOWED_DEVIATION = 2;
private List<WeakReference<IRouteInformationListener>> listeners = new LinkedList<>(); private List<WeakReference<IRouteInformationListener>> listeners = new LinkedList<>();
private List<WeakReference<IRoutingDataUpdateListener>> updateListeners = new LinkedList<>(); private List<WeakReference<IRoutingDataUpdateListener>> updateListeners = new LinkedList<>();
@ -398,9 +399,30 @@ public class RoutingHelper {
return getOrthogonalDistance(lastFixedLocation, routeNodes.get(route.currentRoute -1), routeNodes.get(route.currentRoute)); return getOrthogonalDistance(lastFixedLocation, routeNodes.get(route.currentRoute -1), routeNodes.get(route.currentRoute));
} }
public float getPosTolerance(Location currentLocation) {
if(currentLocation.hasAccuracy()) { public static float getDefaultAllowedDeviation(OsmandSettings settings, float posTolerance) {
return POSITION_TOLERANCE / 2 + currentLocation.getAccuracy(); ApplicationMode mode = settings.getApplicationMode();
if (settings.DISABLE_OFFROUTE_RECALC.getModeValue(mode)) {
return -1.0f;
} else if (mode.getRouteService() == RouteService.DIRECT_TO) {
settings.DISABLE_OFFROUTE_RECALC.setModeValue(mode, true);
return -1.0f;
} else if (mode.getRouteService() == RouteService.STRAIGHT) {
OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.getModeValue(mode);
if (mc == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS || mc == OsmandSettings.MetricsConstants.MILES_AND_METERS) {
return 500.f;
} else {
// 1500 ft
return 457.2f;
}
}
return posTolerance * ALLOWED_DEVIATION;
}
public static float getPosTolerance(float accuracy) {
if(accuracy > 0) {
return POSITION_TOLERANCE / 2 + accuracy;
} }
return POSITION_TOLERANCE; return POSITION_TOLERANCE;
} }
@ -420,7 +442,7 @@ public class RoutingHelper {
isDeviatedFromRoute = false; isDeviatedFromRoute = false;
return locationProjection; return locationProjection;
} }
float posTolerance = getPosTolerance(currentLocation); float posTolerance = getPosTolerance(currentLocation.hasAccuracy() ? currentLocation.getAccuracy() : 0);
boolean calculateRoute = false; boolean calculateRoute = false;
synchronized (this) { synchronized (this) {
isDeviatedFromRoute = false; isDeviatedFromRoute = false;
@ -438,10 +460,13 @@ public class RoutingHelper {
} }
List<Location> routeNodes = route.getImmutableAllLocations(); List<Location> routeNodes = route.getImmutableAllLocations();
int currentRoute = route.currentRoute; int currentRoute = route.currentRoute;
double allowableDeviation = route.routeRecalcDistance == 0 ? (2 * posTolerance) : route.routeRecalcDistance; double allowableDeviation = route.getRouteRecalcDistance();
if (allowableDeviation == 0) {
allowableDeviation = getDefaultAllowedDeviation(settings, posTolerance);
}
// 2. Analyze if we need to recalculate route // 2. Analyze if we need to recalculate route
// >100m off current route (sideways) or parameter (for Straight line) // >100m off current route (sideways) or parameter (for Straight line)
if (currentRoute > 0 && route.getRouteRecalcDistance() >= 0.f && !settings.DISABLE_OFFROUTE_RECALC.get()) { if (currentRoute > 0 && allowableDeviation > 0) {
distOrth = getOrthogonalDistance(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute)); distOrth = getOrthogonalDistance(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
if (distOrth > allowableDeviation) { if (distOrth > allowableDeviation) {
log.info("Recalculate route, because correlation : " + distOrth); //$NON-NLS-1$ log.info("Recalculate route, because correlation : " + distOrth); //$NON-NLS-1$
@ -452,7 +477,7 @@ public class RoutingHelper {
// 3. Identify wrong movement direction // 3. Identify wrong movement direction
Location next = route.getNextRouteLocation(); Location next = route.getNextRouteLocation();
boolean wrongMovementDirection = checkWrongMovementDirection(currentLocation, next); boolean wrongMovementDirection = checkWrongMovementDirection(currentLocation, next);
if (!settings.DISABLE_OFFROUTE_RECALC.get() && wrongMovementDirection if (allowableDeviation > 0 && wrongMovementDirection
&& (currentLocation.distanceTo(routeNodes.get(currentRoute)) > allowableDeviation)) { && (currentLocation.distanceTo(routeNodes.get(currentRoute)) > allowableDeviation)) {
log.info("Recalculate route, because wrong movement direction: " + currentLocation.distanceTo(routeNodes.get(currentRoute))); //$NON-NLS-1$ log.info("Recalculate route, because wrong movement direction: " + currentLocation.distanceTo(routeNodes.get(currentRoute))); //$NON-NLS-1$
isDeviatedFromRoute = true; isDeviatedFromRoute = true;
@ -547,7 +572,7 @@ public class RoutingHelper {
return index; return index;
} }
private boolean updateCurrentRouteStatus(Location currentLocation, float posTolerance) { private boolean updateCurrentRouteStatus(Location currentLocation, double posTolerance) {
List<Location> routeNodes = route.getImmutableAllLocations(); List<Location> routeNodes = route.getImmutableAllLocations();
int currentRoute = route.currentRoute; int currentRoute = route.currentRoute;
// 1. Try to proceed to next point using orthogonal distance (finding minimum orthogonal dist) // 1. Try to proceed to next point using orthogonal distance (finding minimum orthogonal dist)
@ -685,7 +710,7 @@ public class RoutingHelper {
} }
private boolean identifyUTurnIsNeeded(Location currentLocation, float posTolerance) { private boolean identifyUTurnIsNeeded(Location currentLocation, double posTolerance) {
if (finalLocation == null || currentLocation == null || !route.isCalculated() || isPublicTransportMode()) { if (finalLocation == null || currentLocation == null || !route.isCalculated() || isPublicTransportMode()) {
return false; return false;
} }

View file

@ -140,16 +140,12 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
ApplicationMode am = getSelectedAppMode(); ApplicationMode am = getSelectedAppMode();
float posTolerance = app.getRoutingHelper().getPosTolerance(new Location("")); float posTolerance = (float) RoutingHelper.getDefaultAllowedDeviation(settings, RoutingHelper.getPosTolerance(0));
if (am.getRouteService() != RouteProvider.RouteService.OSMAND) { if (am.getRouteService() != RouteProvider.RouteService.OSMAND) {
screen.addPreference(fastRoute); screen.addPreference(fastRoute);
if (am.getRouteService() == RouteProvider.RouteService.STRAIGHT) { setupSelectRouteRecalcDistance(screen, posTolerance);
setupSelectRouteRecalcDistance(screen, 8, posTolerance);
} else if (am.getRouteService() == RouteProvider.RouteService.DIRECT_TO) {
setupSelectRouteRecalcDistance(screen, 0, posTolerance);
}
} else { } else {
setupSelectRouteRecalcDistance(screen, 1, posTolerance); setupSelectRouteRecalcDistance(screen, posTolerance);
GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), am); GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), am);
clearParameters(); clearParameters();
if (router != null) { if (router != null) {
@ -238,7 +234,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
} }
} }
private void setupSelectRouteRecalcDistance(PreferenceScreen screen, int defaultValue, float posTolerance) { private void setupSelectRouteRecalcDistance(PreferenceScreen screen, float posTolerance) {
Float[] entryValues; Float[] entryValues;
OsmandSettings settings = app.getSettings(); OsmandSettings settings = app.getSettings();
OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get(); OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get();
@ -250,15 +246,14 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
String[] entries = new String[entryValues.length]; String[] entries = new String[entryValues.length];
entries[0] = getString(R.string.no_recalculation_setting); entries[0] = getString(R.string.no_recalculation_setting);
entries[1] = String.format(getString(R.string.shared_string_app_default_w_val), OsmAndFormatter.getFormattedDistance(posTolerance * 2, app, false)); String defaultDistance = OsmAndFormatter.getFormattedDistance(settings.ROUTE_RECALCULATION_DISTANCE.getProfileDefaultValue(settings.getApplicationMode()),
app, false);
entries[1] = String.format(getString(R.string.shared_string_app_default_w_val), defaultDistance);
for (int i = 2; i < entryValues.length; i++) { for (int i = 2; i < entryValues.length; i++) {
entries[i] = OsmAndFormatter.getFormattedDistance(entryValues[i], app, false); entries[i] = OsmAndFormatter.getFormattedDistance(entryValues[i], app, false);
} }
if (defaultValue != 1) {
entries[defaultValue] = String.format(getString(R.string.shared_string_routing_default_w_val), defaultValue == 0 ? getString(R.string.no_recalculation_setting) : entries[defaultValue]);
}
ListPreferenceEx routeRecalculationDist = createListPreferenceEx(settings.ROUTE_RECALCULATION_DISTANCE.getId(), ListPreferenceEx routeRecalculationDist = createListPreferenceEx(settings.ROUTE_RECALCULATION_DISTANCE.getId(),
entries, entryValues, R.string.route_recalculation_dist_title, R.layout.preference_with_descr); entries, entryValues, R.string.route_recalculation_dist_title, R.layout.preference_with_descr);

View file

@ -1116,9 +1116,9 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
int currentRoute = route == null ? 0 : route.getCurrentRoute(); int currentRoute = route == null ? 0 : route.getCurrentRoute();
Location pointToReturn = null; Location pointToReturn = null;
if (route != null && currentRoute > 0 && route.getRouteRecalcDistance() > 0) { if (route != null && currentRoute > 0 && route.getRouteRecalcDistance() > 0) {
Location currentLoc = helper.getApplication().getLocationProvider().getLastKnownLocation(); // Location currentLoc = helper.getApplication().getLocationProvider().getLastKnownLocation();
final Location from = routeGeometry.locations.get(currentRoute - 1); // final Location from = routeGeometry.locations.get(currentRoute - 1);
final Location to = routeGeometry.locations.get(currentRoute); // final Location to = routeGeometry.locations.get(currentRoute);
// final LatLon projection = MapUtils.getProjection(currentLoc.getLatitude(), // final LatLon projection = MapUtils.getProjection(currentLoc.getLatitude(),
// currentLoc.getLongitude(), from.getLatitude(), from.getLongitude(), // currentLoc.getLongitude(), from.getLatitude(), from.getLongitude(),
// to.getLatitude(), to.getLongitude()); // to.getLatitude(), to.getLongitude());