Fix settings
This commit is contained in:
parent
a3dc78c8cd
commit
116673f081
5 changed files with 46 additions and 43 deletions
|
@ -3283,23 +3283,6 @@ public class OsmandSettings {
|
|||
}
|
||||
|
||||
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();
|
||||
|
||||
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 showOriginalRoute = false;
|
||||
protected float routeRecalcDistance = 0.f;
|
||||
protected double routeRecalcDistance = 0.d;
|
||||
|
||||
public RouteCalculationResult(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
|
@ -238,7 +238,7 @@ public class RouteCalculationResult {
|
|||
}
|
||||
}
|
||||
|
||||
public float getRouteRecalcDistance() {
|
||||
public double getRouteRecalcDistance() {
|
||||
return routeRecalcDistance;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ public class RoutingHelper {
|
|||
|
||||
private static final float POSITION_TOLERANCE = 60;
|
||||
private static final int CACHE_RADIUS = 100000;
|
||||
public static final float ALLOWED_DEVIATION = 2;
|
||||
|
||||
private List<WeakReference<IRouteInformationListener>> listeners = 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));
|
||||
}
|
||||
|
||||
public float getPosTolerance(Location currentLocation) {
|
||||
if(currentLocation.hasAccuracy()) {
|
||||
return POSITION_TOLERANCE / 2 + currentLocation.getAccuracy();
|
||||
|
||||
public static float getDefaultAllowedDeviation(OsmandSettings settings, float posTolerance) {
|
||||
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;
|
||||
}
|
||||
|
@ -420,7 +442,7 @@ public class RoutingHelper {
|
|||
isDeviatedFromRoute = false;
|
||||
return locationProjection;
|
||||
}
|
||||
float posTolerance = getPosTolerance(currentLocation);
|
||||
float posTolerance = getPosTolerance(currentLocation.hasAccuracy() ? currentLocation.getAccuracy() : 0);
|
||||
boolean calculateRoute = false;
|
||||
synchronized (this) {
|
||||
isDeviatedFromRoute = false;
|
||||
|
@ -438,10 +460,13 @@ public class RoutingHelper {
|
|||
}
|
||||
List<Location> routeNodes = route.getImmutableAllLocations();
|
||||
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
|
||||
// >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));
|
||||
if (distOrth > allowableDeviation) {
|
||||
log.info("Recalculate route, because correlation : " + distOrth); //$NON-NLS-1$
|
||||
|
@ -452,7 +477,7 @@ public class RoutingHelper {
|
|||
// 3. Identify wrong movement direction
|
||||
Location next = route.getNextRouteLocation();
|
||||
boolean wrongMovementDirection = checkWrongMovementDirection(currentLocation, next);
|
||||
if (!settings.DISABLE_OFFROUTE_RECALC.get() && wrongMovementDirection
|
||||
if (allowableDeviation > 0 && wrongMovementDirection
|
||||
&& (currentLocation.distanceTo(routeNodes.get(currentRoute)) > allowableDeviation)) {
|
||||
log.info("Recalculate route, because wrong movement direction: " + currentLocation.distanceTo(routeNodes.get(currentRoute))); //$NON-NLS-1$
|
||||
isDeviatedFromRoute = true;
|
||||
|
@ -547,7 +572,7 @@ public class RoutingHelper {
|
|||
return index;
|
||||
}
|
||||
|
||||
private boolean updateCurrentRouteStatus(Location currentLocation, float posTolerance) {
|
||||
private boolean updateCurrentRouteStatus(Location currentLocation, double posTolerance) {
|
||||
List<Location> routeNodes = route.getImmutableAllLocations();
|
||||
int currentRoute = route.currentRoute;
|
||||
// 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()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -140,16 +140,12 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
|||
|
||||
|
||||
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) {
|
||||
screen.addPreference(fastRoute);
|
||||
if (am.getRouteService() == RouteProvider.RouteService.STRAIGHT) {
|
||||
setupSelectRouteRecalcDistance(screen, 8, posTolerance);
|
||||
} else if (am.getRouteService() == RouteProvider.RouteService.DIRECT_TO) {
|
||||
setupSelectRouteRecalcDistance(screen, 0, posTolerance);
|
||||
}
|
||||
setupSelectRouteRecalcDistance(screen, posTolerance);
|
||||
} else {
|
||||
setupSelectRouteRecalcDistance(screen, 1, posTolerance);
|
||||
setupSelectRouteRecalcDistance(screen, posTolerance);
|
||||
GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), am);
|
||||
clearParameters();
|
||||
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;
|
||||
OsmandSettings settings = app.getSettings();
|
||||
OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get();
|
||||
|
@ -250,15 +246,14 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
|||
|
||||
String[] entries = new String[entryValues.length];
|
||||
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++) {
|
||||
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(),
|
||||
entries, entryValues, R.string.route_recalculation_dist_title, R.layout.preference_with_descr);
|
||||
|
|
|
@ -1116,9 +1116,9 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
|
|||
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);
|
||||
final Location to = routeGeometry.locations.get(currentRoute);
|
||||
// Location currentLoc = helper.getApplication().getLocationProvider().getLastKnownLocation();
|
||||
// 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());
|
||||
|
|
Loading…
Reference in a new issue