Fix string values and add option for optimal/non-optimal route calculation
This commit is contained in:
parent
f086a523ed
commit
0ef5d7ba6e
11 changed files with 187 additions and 116 deletions
|
@ -11,6 +11,8 @@
|
||||||
<ToggleButton android:contentDescription="@string/app_mode_pedestrian" android:textOn="" android:textOff="" android:id="@+id/PedestrianButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:background="@drawable/pedestrian_icon"/>
|
<ToggleButton android:contentDescription="@string/app_mode_pedestrian" android:textOn="" android:textOff="" android:id="@+id/PedestrianButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:background="@drawable/pedestrian_icon"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<CheckBox android:id="@+id/OptimalCheckox" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/non_optimal_route_calculation"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<?xml version='1.0' encoding='utf-8'?>
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
<resources><string name="download_link_and_local_description">Загрузите или обновите локальные данные.
|
<resources>
|
||||||
|
<string name="non_optimal_route_calculation">Рассчитать неоптимальный (возможно) маршрут на длинные дистанции</string>
|
||||||
|
<string name="download_link_and_local_description">Загрузите или обновите локальные данные.
|
||||||
\nЧтобы получить дополнительную информацию о карте, выделите её в списке. Удерживайте карту, если вы хотите удалить или деактивировать.
|
\nЧтобы получить дополнительную информацию о карте, выделите её в списке. Удерживайте карту, если вы хотите удалить или деактивировать.
|
||||||
\nДанные на устройстве (%1$s свободно):</string>
|
\nДанные на устройстве (%1$s свободно):</string>
|
||||||
<string name="tip_recent_changes_0_8_3_t">"Изменения в 0.8.3:
|
<string name="tip_recent_changes_0_8_3_t">"Изменения в 0.8.3:
|
||||||
|
@ -735,7 +737,7 @@
|
||||||
<string name="navigate_point_format_D">ГГГ.ГГГГ</string>
|
<string name="navigate_point_format_D">ГГГ.ГГГГ</string>
|
||||||
<string name="navigate_point_format_DM">ГГГ ММ.МММММ</string>
|
<string name="navigate_point_format_DM">ГГГ ММ.МММММ</string>
|
||||||
<string name="navigate_point_format_DMS">ГГГ ММ СС.ССССС</string>
|
<string name="navigate_point_format_DMS">ГГГ ММ СС.ССССС</string>
|
||||||
<string name="search_shown_on_map">Отобразить на карте</string>
|
<string name="search_shown_on_map">Показать</string>
|
||||||
<string name="navigate_point_cancel">Отмена</string>
|
<string name="navigate_point_cancel">Отмена</string>
|
||||||
<string name="search_address_top_text">Выберите адрес</string>
|
<string name="search_address_top_text">Выберите адрес</string>
|
||||||
<string name="search_address_region">Регион</string>
|
<string name="search_address_region">Регион</string>
|
||||||
|
|
|
@ -9,7 +9,9 @@
|
||||||
1. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
1. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||||
-->
|
-->
|
||||||
|
<string name="non_optimal_route_calculation">Calculate possibly non-optimal route over long distances</string>
|
||||||
<string name="tip_recent_changes_0_8_4_t">Changes in 0.8.4 :
|
<string name="tip_recent_changes_0_8_4_t">Changes in 0.8.4 :
|
||||||
|
Updated
|
||||||
</string>
|
</string>
|
||||||
<string name="tip_recent_changes_0_8_3_t">Changes in 0.8.3 :
|
<string name="tip_recent_changes_0_8_3_t">Changes in 0.8.3 :
|
||||||
\n\t* Waypoints
|
\n\t* Waypoints
|
||||||
|
|
|
@ -59,6 +59,8 @@ public class OsmandSettings {
|
||||||
|
|
||||||
boolean set(T obj);
|
boolean set(T obj);
|
||||||
|
|
||||||
|
boolean setModeValue(ApplicationMode m, T obj);
|
||||||
|
|
||||||
T getModeValue(ApplicationMode m);
|
T getModeValue(ApplicationMode m);
|
||||||
|
|
||||||
String getId();
|
String getId();
|
||||||
|
@ -144,6 +146,11 @@ public class OsmandSettings {
|
||||||
public ApplicationMode getModeValue(ApplicationMode m) {
|
public ApplicationMode getModeValue(ApplicationMode m) {
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setModeValue(ApplicationMode m, ApplicationMode obj) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public ApplicationMode getApplicationMode(){
|
public ApplicationMode getApplicationMode(){
|
||||||
|
@ -241,6 +248,14 @@ public class OsmandSettings {
|
||||||
defaultValues.put(mode, defValue);
|
defaultValues.put(mode, defValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setModeValue(ApplicationMode mode, T obj){
|
||||||
|
if(global) {
|
||||||
|
return set(obj);
|
||||||
|
}
|
||||||
|
return setValue(getProfilePreferences(mode), obj);
|
||||||
|
}
|
||||||
|
|
||||||
public T getProfileDefaultValue(){
|
public T getProfileDefaultValue(){
|
||||||
if(global){
|
if(global){
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
@ -596,6 +611,7 @@ public class OsmandSettings {
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
public final OsmandPreference<Boolean> FAST_ROUTE_MODE = new BooleanPreference("fast_route_mode", true).makeProfile();
|
public final OsmandPreference<Boolean> FAST_ROUTE_MODE = new BooleanPreference("fast_route_mode", true).makeProfile();
|
||||||
|
public final OsmandPreference<Boolean> OPTIMAL_ROUTE_MODE = new BooleanPreference("optimal_route_mode", true).makeProfile();
|
||||||
|
|
||||||
public final OsmandPreference<Boolean> SHOW_SPEED_LIMITS = new BooleanPreference("show_speed_limits", true).makeGlobal().cache();
|
public final OsmandPreference<Boolean> SHOW_SPEED_LIMITS = new BooleanPreference("show_speed_limits", true).makeGlobal().cache();
|
||||||
public final OsmandPreference<Boolean> SHOW_CAMERAS = new BooleanPreference("show_cameras", true).makeGlobal().cache();
|
public final OsmandPreference<Boolean> SHOW_CAMERAS = new BooleanPreference("show_cameras", true).makeGlobal().cache();
|
||||||
|
|
|
@ -134,7 +134,7 @@ public class MainMenuActivity extends Activity {
|
||||||
SharedPreferences prefs = activity.getApplicationContext().getSharedPreferences("net.osmand.settings", MODE_WORLD_READABLE);
|
SharedPreferences prefs = activity.getApplicationContext().getSharedPreferences("net.osmand.settings", MODE_WORLD_READABLE);
|
||||||
|
|
||||||
// only one commit should be with contribution version flag
|
// only one commit should be with contribution version flag
|
||||||
// prefs.edit().putBoolean(CONTRIBUTION_VERSION_FLAG, true).commit();
|
prefs.edit().putBoolean(CONTRIBUTION_VERSION_FLAG, true).commit();
|
||||||
if (prefs.contains(CONTRIBUTION_VERSION_FLAG)) {
|
if (prefs.contains(CONTRIBUTION_VERSION_FLAG)) {
|
||||||
SpannableString content = new SpannableString(textVersion);
|
SpannableString content = new SpannableString(textVersion);
|
||||||
content.setSpan(new ClickableSpan() {
|
content.setSpan(new ClickableSpan() {
|
||||||
|
|
|
@ -292,7 +292,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
|
||||||
Object toShow = settings.getAndClearObjectToShow();
|
Object toShow = settings.getAndClearObjectToShow();
|
||||||
if(settings.isRouteToPointNavigateAndClear()){
|
if(settings.isRouteToPointNavigateAndClear()){
|
||||||
// always enable and follow and let calculate it (GPS is not accessible in garage)
|
// always enable and follow and let calculate it (GPS is not accessible in garage)
|
||||||
mapActions.getDirections(getLastKnownLocation(), false);
|
mapActions.getDirections(null, null, false);
|
||||||
}
|
}
|
||||||
if(mapLabelToShow != null && latLonToShow != null){
|
if(mapLabelToShow != null && latLonToShow != null){
|
||||||
mapLayers.getContextMenuLayer().setSelectedObject(toShow);
|
mapLayers.getContextMenuLayer().setSelectedObject(toShow);
|
||||||
|
|
|
@ -407,13 +407,14 @@ public class MapActivityActions implements DialogProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void getDirections(final Location from, boolean gpxRouteEnabled) {
|
public void getDirections(final Location fromOrCurrent, final LatLon to, boolean gpxRouteEnabled) {
|
||||||
|
|
||||||
final RoutingHelper routingHelper = mapActivity.getRoutingHelper();
|
final RoutingHelper routingHelper = mapActivity.getRoutingHelper();
|
||||||
|
|
||||||
Builder builder = new AlertDialog.Builder(mapActivity);
|
Builder builder = new AlertDialog.Builder(mapActivity);
|
||||||
|
|
||||||
View view = mapActivity.getLayoutInflater().inflate(R.layout.calculate_route, null);
|
View view = mapActivity.getLayoutInflater().inflate(R.layout.calculate_route, null);
|
||||||
|
final CheckBox optimal = (CheckBox) view.findViewById(R.id.OptimalCheckox);
|
||||||
final ToggleButton[] buttons = new ToggleButton[ApplicationMode.values().length];
|
final ToggleButton[] buttons = new ToggleButton[ApplicationMode.values().length];
|
||||||
buttons[ApplicationMode.CAR.ordinal()] = (ToggleButton) view.findViewById(R.id.CarButton);
|
buttons[ApplicationMode.CAR.ordinal()] = (ToggleButton) view.findViewById(R.id.CarButton);
|
||||||
buttons[ApplicationMode.BICYCLE.ordinal()] = (ToggleButton) view.findViewById(R.id.BicycleButton);
|
buttons[ApplicationMode.BICYCLE.ordinal()] = (ToggleButton) view.findViewById(R.id.BicycleButton);
|
||||||
|
@ -426,11 +427,16 @@ public class MapActivityActions implements DialogProvider {
|
||||||
if (buttons[i] != null) {
|
if (buttons[i] != null) {
|
||||||
final int ind = i;
|
final int ind = i;
|
||||||
ToggleButton b = buttons[i];
|
ToggleButton b = buttons[i];
|
||||||
b.setChecked(appMode == ApplicationMode.values()[i]);
|
final ApplicationMode buttonAppMode = ApplicationMode.values()[i];
|
||||||
|
b.setChecked(appMode == buttonAppMode);
|
||||||
|
if(b.isChecked()) {
|
||||||
|
optimal.setChecked(settings.OPTIMAL_ROUTE_MODE.getModeValue(buttonAppMode));
|
||||||
|
}
|
||||||
b.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
b.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
|
optimal.setChecked(settings.OPTIMAL_ROUTE_MODE.getModeValue(buttonAppMode));
|
||||||
for (int j = 0; j < buttons.length; j++) {
|
for (int j = 0; j < buttons.length; j++) {
|
||||||
if (buttons[j] != null) {
|
if (buttons[j] != null) {
|
||||||
if (buttons[j].isChecked() != (ind == j)) {
|
if (buttons[j].isChecked() != (ind == j)) {
|
||||||
|
@ -461,15 +467,23 @@ public class MapActivityActions implements DialogProvider {
|
||||||
DialogInterface.OnClickListener onlyShowCall = new DialogInterface.OnClickListener() {
|
DialogInterface.OnClickListener onlyShowCall = new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
if(to != null) {
|
||||||
|
mapActivity.navigateToPoint(to, false, -1);
|
||||||
|
}
|
||||||
if (!checkPointToNavigate()) {
|
if (!checkPointToNavigate()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Location from = fromOrCurrent;
|
||||||
|
if(from == null) {
|
||||||
|
from = mapActivity.getLastKnownLocation();
|
||||||
|
}
|
||||||
if (from == null) {
|
if (from == null) {
|
||||||
AccessibleToast.makeText(mapActivity, R.string.unknown_from_location, Toast.LENGTH_LONG).show();
|
AccessibleToast.makeText(mapActivity, R.string.unknown_from_location, Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ApplicationMode mode = getAppMode(buttons, settings);
|
ApplicationMode mode = getAppMode(buttons, settings);
|
||||||
routingHelper.setAppMode(mode);
|
routingHelper.setAppMode(mode);
|
||||||
|
settings.OPTIMAL_ROUTE_MODE.setModeValue(mode, optimal.isChecked());
|
||||||
settings.FOLLOW_THE_ROUTE.set(false);
|
settings.FOLLOW_THE_ROUTE.set(false);
|
||||||
settings.FOLLOW_THE_GPX_ROUTE.set(null);
|
settings.FOLLOW_THE_GPX_ROUTE.set(null);
|
||||||
routingHelper.setFollowingMode(false);
|
routingHelper.setFollowingMode(false);
|
||||||
|
@ -481,12 +495,19 @@ public class MapActivityActions implements DialogProvider {
|
||||||
DialogInterface.OnClickListener followCall = new DialogInterface.OnClickListener() {
|
DialogInterface.OnClickListener followCall = new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
if(to != null) {
|
||||||
|
mapActivity.navigateToPoint(to, false, -1);
|
||||||
|
}
|
||||||
if (!checkPointToNavigate()) {
|
if (!checkPointToNavigate()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean msg = true;
|
boolean msg = true;
|
||||||
Location current = from;
|
Location current = fromOrCurrent;
|
||||||
if (!mapActivity.isPointAccurateForRouting(from)) {
|
if(current == null) {
|
||||||
|
current = mapActivity.getLastKnownLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mapActivity.isPointAccurateForRouting(current)) {
|
||||||
current = null;
|
current = null;
|
||||||
}
|
}
|
||||||
Location lastKnownLocation = mapActivity.getLastKnownLocation();
|
Location lastKnownLocation = mapActivity.getLastKnownLocation();
|
||||||
|
@ -507,6 +528,9 @@ public class MapActivityActions implements DialogProvider {
|
||||||
DialogInterface.OnClickListener useGpxNavigation = new DialogInterface.OnClickListener() {
|
DialogInterface.OnClickListener useGpxNavigation = new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
if(to != null) {
|
||||||
|
mapActivity.navigateToPoint(to, false, -1);
|
||||||
|
}
|
||||||
ApplicationMode mode = getAppMode(buttons, settings);
|
ApplicationMode mode = getAppMode(buttons, settings);
|
||||||
navigateUsingGPX(mode);
|
navigateUsingGPX(mode);
|
||||||
}
|
}
|
||||||
|
@ -734,16 +758,14 @@ public class MapActivityActions implements DialogProvider {
|
||||||
} else if (standardId == R.string.context_menu_item_navigate_point) {
|
} else if (standardId == R.string.context_menu_item_navigate_point) {
|
||||||
mapActivity.navigateToPoint(new LatLon(latitude, longitude), true, -1);
|
mapActivity.navigateToPoint(new LatLon(latitude, longitude), true, -1);
|
||||||
} else if (standardId == R.string.context_menu_item_directions) {
|
} else if (standardId == R.string.context_menu_item_directions) {
|
||||||
Location loc = mapActivity.getLastKnownLocation();
|
|
||||||
mapActivity.navigateToPoint(new LatLon(latitude, longitude), false, -1);
|
|
||||||
// always enable and follow and let calculate it (GPS is not accessible in garage)
|
// always enable and follow and let calculate it (GPS is not accessible in garage)
|
||||||
getDirections(loc, true);
|
getDirections(null, new LatLon(latitude, longitude), true);
|
||||||
} else if (standardId == R.string.context_menu_item_show_route) {
|
} else if (standardId == R.string.context_menu_item_show_route) {
|
||||||
if (checkPointToNavigate()) {
|
if (checkPointToNavigate()) {
|
||||||
Location loc = new Location("map");
|
Location loc = new Location("map");
|
||||||
loc.setLatitude(latitude);
|
loc.setLatitude(latitude);
|
||||||
loc.setLongitude(longitude);
|
loc.setLongitude(longitude);
|
||||||
getDirections(loc, true);
|
getDirections(loc, null, true);
|
||||||
}
|
}
|
||||||
} else if (standardId == R.string.context_menu_item_intermediate_point) {
|
} else if (standardId == R.string.context_menu_item_intermediate_point) {
|
||||||
mapActivity.navigateToPoint(new LatLon(latitude, longitude), true, mapActivity.getIntermediatePoints().size());
|
mapActivity.navigateToPoint(new LatLon(latitude, longitude), true, mapActivity.getIntermediatePoints().size());
|
||||||
|
@ -957,8 +979,7 @@ public class MapActivityActions implements DialogProvider {
|
||||||
if (routingHelper.isRouteCalculated()) {
|
if (routingHelper.isRouteCalculated()) {
|
||||||
aboutRoute();
|
aboutRoute();
|
||||||
} else {
|
} else {
|
||||||
Location loc = mapActivity.getLastKnownLocation();
|
getDirections(null, null, true);
|
||||||
getDirections(loc, true);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,8 @@ import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
|
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.AlertDialog.Builder;
|
import android.app.AlertDialog.Builder;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationManager;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package net.osmand.plus.routing;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.osmand.osm.LatLon;
|
||||||
|
import net.osmand.plus.activities.ApplicationMode;
|
||||||
|
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
|
||||||
|
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||||
|
import net.osmand.router.Interruptable;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.location.Location;
|
||||||
|
|
||||||
|
public class RouteCalcuationParams {
|
||||||
|
|
||||||
|
public Location start;
|
||||||
|
public LatLon end;
|
||||||
|
public List<LatLon> intermediates;
|
||||||
|
|
||||||
|
public Context ctx;
|
||||||
|
public ApplicationMode mode;
|
||||||
|
public RouteService type;
|
||||||
|
public GPXRouteParams gpxRoute;
|
||||||
|
public RouteCalculationResult previousToRecalculate;
|
||||||
|
public boolean fast;
|
||||||
|
public boolean optimal;
|
||||||
|
public boolean leftSide;
|
||||||
|
public Interruptable interruptable;
|
||||||
|
}
|
|
@ -27,7 +27,6 @@ import net.osmand.GPXUtilities.Track;
|
||||||
import net.osmand.GPXUtilities.TrkSegment;
|
import net.osmand.GPXUtilities.TrkSegment;
|
||||||
import net.osmand.GPXUtilities.WptPt;
|
import net.osmand.GPXUtilities.WptPt;
|
||||||
import net.osmand.LogUtil;
|
import net.osmand.LogUtil;
|
||||||
import net.osmand.access.AccessibleToast;
|
|
||||||
import net.osmand.binary.BinaryMapIndexReader;
|
import net.osmand.binary.BinaryMapIndexReader;
|
||||||
import net.osmand.osm.LatLon;
|
import net.osmand.osm.LatLon;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
@ -40,7 +39,6 @@ import net.osmand.router.BinaryRoutePlanner;
|
||||||
import net.osmand.router.BinaryRoutePlanner.RouteSegment;
|
import net.osmand.router.BinaryRoutePlanner.RouteSegment;
|
||||||
import net.osmand.router.GeneralRouter;
|
import net.osmand.router.GeneralRouter;
|
||||||
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
||||||
import net.osmand.router.Interruptable;
|
|
||||||
import net.osmand.router.RouteSegmentResult;
|
import net.osmand.router.RouteSegmentResult;
|
||||||
import net.osmand.router.RoutingConfiguration;
|
import net.osmand.router.RoutingConfiguration;
|
||||||
import net.osmand.router.RoutingContext;
|
import net.osmand.router.RoutingContext;
|
||||||
|
@ -53,10 +51,8 @@ import org.w3c.dom.NodeList;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
public class RouteProvider {
|
public class RouteProvider {
|
||||||
private static final org.apache.commons.logging.Log log = LogUtil.getLog(RouteProvider.class);
|
private static final org.apache.commons.logging.Log log = LogUtil.getLog(RouteProvider.class);
|
||||||
|
@ -150,29 +146,25 @@ public class RouteProvider {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public RouteCalculationResult calculateRouteImpl(Location start, LatLon end, List<LatLon> intermediates, ApplicationMode mode, RouteService type, Context ctx,
|
public RouteCalculationResult calculateRouteImpl(RouteCalcuationParams params){
|
||||||
GPXRouteParams gpxRoute, RouteCalculationResult previousToRecalculate, boolean fast, boolean leftSide, Interruptable interruptable){
|
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
if (start != null && end != null) {
|
if (params.start != null && params.end != null) {
|
||||||
if(log.isInfoEnabled()){
|
if(log.isInfoEnabled()){
|
||||||
log.info("Start finding route from " + start + " to " + end +" using " + type.getName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
log.info("Start finding route from " + params.start + " to " + params.end +" using " +
|
||||||
|
params.type.getName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
RouteCalculationResult res;
|
RouteCalculationResult res;
|
||||||
if(gpxRoute != null && !gpxRoute.points.isEmpty()){
|
if(params.gpxRoute != null && !params.gpxRoute.points.isEmpty()){
|
||||||
res = calculateGpxRoute(start, end, gpxRoute, ctx, leftSide);
|
res = calculateGpxRoute(params);
|
||||||
} else if (type == RouteService.YOURS) {
|
} else if (params.type == RouteService.YOURS) {
|
||||||
res = findYOURSRoute(start, end, mode, fast, ctx, leftSide);
|
res = findYOURSRoute(params);
|
||||||
} else if (type == RouteService.ORS) {
|
} else if (params.type == RouteService.ORS) {
|
||||||
res = findORSRoute(start, end, mode, fast, ctx, leftSide);
|
res = findORSRoute(params);
|
||||||
} else if (type == RouteService.OSMAND) {
|
} else if (params.type == RouteService.OSMAND) {
|
||||||
List<RouteSegmentResult> originalRoute = null;
|
res = findVectorMapsRoute(params);
|
||||||
if(previousToRecalculate != null) {
|
|
||||||
originalRoute = previousToRecalculate.getOriginalRoute();
|
|
||||||
}
|
|
||||||
res = findVectorMapsRoute(start, end, intermediates, mode, (OsmandApplication)ctx.getApplicationContext(), originalRoute, leftSide, interruptable);
|
|
||||||
} else {
|
} else {
|
||||||
res = findCloudMadeRoute(start, end, intermediates, mode, ctx, fast, leftSide);
|
res = findCloudMadeRoute(params);
|
||||||
}
|
}
|
||||||
if(log.isInfoEnabled() ){
|
if(log.isInfoEnabled() ){
|
||||||
log.info("Finding route contained " + res.getImmutableLocations().size() + " points for " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
log.info("Finding route contained " + res.getImmutableLocations().size() + " points for " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
|
@ -189,27 +181,29 @@ public class RouteProvider {
|
||||||
return new RouteCalculationResult(null);
|
return new RouteCalculationResult(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RouteCalculationResult calculateGpxRoute(Location start, LatLon end, GPXRouteParams params, Context ctx, boolean leftSide) {
|
|
||||||
|
private RouteCalculationResult calculateGpxRoute(RouteCalcuationParams pars) {
|
||||||
RouteCalculationResult res;
|
RouteCalculationResult res;
|
||||||
// get the closest point to start and to end
|
// get the closest point to start and to end
|
||||||
float minDist = Integer.MAX_VALUE;
|
float minDist = Integer.MAX_VALUE;
|
||||||
int startI = 0;
|
int startI = 0;
|
||||||
|
GPXRouteParams params = pars.gpxRoute;
|
||||||
List<Location> gpxRoute = params.points;
|
List<Location> gpxRoute = params.points;
|
||||||
int endI = gpxRoute.size();
|
int endI = gpxRoute.size();
|
||||||
if (start != null) {
|
if (pars.start != null) {
|
||||||
for (int i = 0; i < gpxRoute.size(); i++) {
|
for (int i = 0; i < gpxRoute.size(); i++) {
|
||||||
float d = gpxRoute.get(i).distanceTo(start);
|
float d = gpxRoute.get(i).distanceTo(pars.start);
|
||||||
if (d < minDist) {
|
if (d < minDist) {
|
||||||
startI = i;
|
startI = i;
|
||||||
minDist = d;
|
minDist = d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
start = gpxRoute.get(0);
|
pars.start = gpxRoute.get(0);
|
||||||
}
|
}
|
||||||
Location l = new Location("temp"); //$NON-NLS-1$
|
Location l = new Location("temp"); //$NON-NLS-1$
|
||||||
l.setLatitude(end.getLatitude());
|
l.setLatitude(pars.end.getLatitude());
|
||||||
l.setLongitude(end.getLongitude());
|
l.setLongitude(pars.end.getLongitude());
|
||||||
minDist = Integer.MAX_VALUE;
|
minDist = Integer.MAX_VALUE;
|
||||||
// get in reverse order taking into account ways with cycle
|
// get in reverse order taking into account ways with cycle
|
||||||
for (int i = gpxRoute.size() - 1; i >= startI; i--) {
|
for (int i = gpxRoute.size() - 1; i >= startI; i--) {
|
||||||
|
@ -222,7 +216,8 @@ public class RouteProvider {
|
||||||
}
|
}
|
||||||
ArrayList<Location> sublist = new ArrayList<Location>(gpxRoute.subList(startI, endI));
|
ArrayList<Location> sublist = new ArrayList<Location>(gpxRoute.subList(startI, endI));
|
||||||
if(params.directions == null){
|
if(params.directions == null){
|
||||||
res = new RouteCalculationResult(sublist, params.directions, start, end, null, null, ctx, leftSide, true);
|
res = new RouteCalculationResult(sublist, params.directions, pars.start, pars.end, null, null,
|
||||||
|
pars.ctx, pars.leftSide, true);
|
||||||
} else {
|
} else {
|
||||||
List<RouteDirectionInfo> subdirections = new ArrayList<RouteDirectionInfo>();
|
List<RouteDirectionInfo> subdirections = new ArrayList<RouteDirectionInfo>();
|
||||||
for (RouteDirectionInfo info : params.directions) {
|
for (RouteDirectionInfo info : params.directions) {
|
||||||
|
@ -237,7 +232,8 @@ public class RouteProvider {
|
||||||
subdirections.add(ch);
|
subdirections.add(ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res = new RouteCalculationResult(sublist, subdirections, start, end, null, null, ctx, leftSide, true);
|
res = new RouteCalculationResult(sublist, subdirections, pars.start, pars.end, null, null,
|
||||||
|
pars.ctx, pars.leftSide, true);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -252,23 +248,23 @@ public class RouteProvider {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected RouteCalculationResult findYOURSRoute(Location start, LatLon end, ApplicationMode mode, boolean fast, Context ctx, boolean leftSide) throws MalformedURLException, IOException,
|
protected RouteCalculationResult findYOURSRoute(RouteCalcuationParams params) throws MalformedURLException, IOException,
|
||||||
ParserConfigurationException, FactoryConfigurationError, SAXException {
|
ParserConfigurationException, FactoryConfigurationError, SAXException {
|
||||||
List<Location> res = new ArrayList<Location>();
|
List<Location> res = new ArrayList<Location>();
|
||||||
StringBuilder uri = new StringBuilder();
|
StringBuilder uri = new StringBuilder();
|
||||||
uri.append("http://www.yournavigation.org/api/1.0/gosmore.php?format=kml"); //$NON-NLS-1$
|
uri.append("http://www.yournavigation.org/api/1.0/gosmore.php?format=kml"); //$NON-NLS-1$
|
||||||
uri.append("&flat=").append(start.getLatitude()); //$NON-NLS-1$
|
uri.append("&flat=").append(params.start.getLatitude()); //$NON-NLS-1$
|
||||||
uri.append("&flon=").append(start.getLongitude()); //$NON-NLS-1$
|
uri.append("&flon=").append(params.start.getLongitude()); //$NON-NLS-1$
|
||||||
uri.append("&tlat=").append(end.getLatitude()); //$NON-NLS-1$
|
uri.append("&tlat=").append(params.end.getLatitude()); //$NON-NLS-1$
|
||||||
uri.append("&tlon=").append(end.getLongitude()); //$NON-NLS-1$
|
uri.append("&tlon=").append(params.end.getLongitude()); //$NON-NLS-1$
|
||||||
if(ApplicationMode.PEDESTRIAN == mode){
|
if(ApplicationMode.PEDESTRIAN == params.mode){
|
||||||
uri.append("&v=foot") ; //$NON-NLS-1$
|
uri.append("&v=foot") ; //$NON-NLS-1$
|
||||||
} else if(ApplicationMode.BICYCLE == mode){
|
} else if(ApplicationMode.BICYCLE == params.mode){
|
||||||
uri.append("&v=bicycle") ; //$NON-NLS-1$
|
uri.append("&v=bicycle") ; //$NON-NLS-1$
|
||||||
} else {
|
} else {
|
||||||
uri.append("&v=motorcar"); //$NON-NLS-1$
|
uri.append("&v=motorcar"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
uri.append("&fast=").append(fast ? "1" : "0").append("&layer=mapnik"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
uri.append("&fast=").append(params.fast ? "1" : "0").append("&layer=mapnik"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||||
log.info("URL route " + uri);
|
log.info("URL route " + uri);
|
||||||
URL url = new URL(uri.toString());
|
URL url = new URL(uri.toString());
|
||||||
URLConnection connection = url.openConnection();
|
URLConnection connection = url.openConnection();
|
||||||
|
@ -307,12 +303,12 @@ public class RouteProvider {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new RouteCalculationResult(res, null, start, end, null, null, ctx, leftSide, true);
|
return new RouteCalculationResult(res, null, params.start, params.end, null, null,
|
||||||
|
params.ctx, params.leftSide, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RouteCalculationResult findVectorMapsRoute(Location start, LatLon end, List<LatLon> intermediates, ApplicationMode mode, OsmandApplication app,
|
protected RouteCalculationResult findVectorMapsRoute(RouteCalcuationParams params) throws IOException {
|
||||||
List<RouteSegmentResult> previousRoute,
|
OsmandApplication app = (OsmandApplication) params.ctx.getApplicationContext();
|
||||||
boolean leftSide, Interruptable interruptable) throws IOException {
|
|
||||||
BinaryMapIndexReader[] files = app.getResourceManager().getRoutingMapFiles();
|
BinaryMapIndexReader[] files = app.getResourceManager().getRoutingMapFiles();
|
||||||
BinaryRoutePlanner router = new BinaryRoutePlanner();
|
BinaryRoutePlanner router = new BinaryRoutePlanner();
|
||||||
File routingXml = app.getSettings().extendOsmandPath(ResourceManager.ROUTING_XML);
|
File routingXml = app.getSettings().extendOsmandPath(ResourceManager.ROUTING_XML);
|
||||||
|
@ -328,9 +324,9 @@ public class RouteProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
GeneralRouterProfile p ;
|
GeneralRouterProfile p ;
|
||||||
if (mode == ApplicationMode.BICYCLE) {
|
if (params.mode == ApplicationMode.BICYCLE) {
|
||||||
p = GeneralRouterProfile.BICYCLE;
|
p = GeneralRouterProfile.BICYCLE;
|
||||||
} else if (mode == ApplicationMode.PEDESTRIAN) {
|
} else if (params.mode == ApplicationMode.PEDESTRIAN) {
|
||||||
p = GeneralRouterProfile.PEDESTRIAN;
|
p = GeneralRouterProfile.PEDESTRIAN;
|
||||||
} else {
|
} else {
|
||||||
p = GeneralRouterProfile.CAR;
|
p = GeneralRouterProfile.CAR;
|
||||||
|
@ -355,26 +351,33 @@ public class RouteProvider {
|
||||||
float mb = (1 << 20);
|
float mb = (1 << 20);
|
||||||
Runtime rt = Runtime.getRuntime();
|
Runtime rt = Runtime.getRuntime();
|
||||||
// make visible
|
// make visible
|
||||||
int memoryLimit = (int) (0.9 * ((rt.maxMemory() - rt.totalMemory()) + rt.freeMemory()) / mb);
|
int memoryLimit = (int) (0.95 * ((rt.maxMemory() - rt.totalMemory()) + rt.freeMemory()) / mb);
|
||||||
log.warn("Use " + memoryLimit + " MB Free " + rt.freeMemory() / mb + " of " + rt.totalMemory() / mb + " max " + rt.maxMemory() / mb);
|
log.warn("Use " + memoryLimit + " MB Free " + rt.freeMemory() / mb + " of " + rt.totalMemory() / mb + " max " + rt.maxMemory() / mb);
|
||||||
|
|
||||||
RoutingConfiguration cf = config.build(p.name().toLowerCase(), start.hasBearing() ? start.getBearing() / 180d * Math.PI : null,
|
RoutingConfiguration cf = config.build(p.name().toLowerCase(), params.start.hasBearing() ?
|
||||||
|
params.start.getBearing() / 180d * Math.PI : null,
|
||||||
memoryLimit, specialization);
|
memoryLimit, specialization);
|
||||||
|
if(!params.optimal){
|
||||||
|
cf.heuristicCoefficient *= 1.5;
|
||||||
|
}
|
||||||
RoutingContext ctx = new RoutingContext(cf, NativeOsmandLibrary.getLoadedLibrary(), files);
|
RoutingContext ctx = new RoutingContext(cf, NativeOsmandLibrary.getLoadedLibrary(), files);
|
||||||
ctx.interruptable = interruptable;
|
ctx.interruptable = params.interruptable;
|
||||||
ctx.previouslyCalculatedRoute = previousRoute;
|
if(params.previousToRecalculate != null) {
|
||||||
RouteSegment st= router.findRouteSegment(start.getLatitude(), start.getLongitude(), ctx);
|
ctx.previouslyCalculatedRoute = params.previousToRecalculate.getOriginalRoute();
|
||||||
|
}
|
||||||
|
RouteSegment st= router.findRouteSegment(params.start.getLatitude(), params.start.getLongitude(), ctx);
|
||||||
if (st == null) {
|
if (st == null) {
|
||||||
return new RouteCalculationResult(app.getString(R.string.starting_point_too_far));
|
return new RouteCalculationResult(app.getString(R.string.starting_point_too_far));
|
||||||
}
|
}
|
||||||
RouteSegment en = router.findRouteSegment(end.getLatitude(), end.getLongitude(), ctx);
|
RouteSegment en = router.findRouteSegment(params.end.getLatitude(),
|
||||||
|
params.end.getLongitude(), ctx);
|
||||||
if (en == null) {
|
if (en == null) {
|
||||||
return new RouteCalculationResult(app.getString(R.string.ending_point_too_far));
|
return new RouteCalculationResult(app.getString(R.string.ending_point_too_far));
|
||||||
}
|
}
|
||||||
List<RouteSegment> inters = new ArrayList<BinaryRoutePlanner.RouteSegment>();
|
List<RouteSegment> inters = new ArrayList<BinaryRoutePlanner.RouteSegment>();
|
||||||
if (intermediates != null) {
|
if (params.intermediates != null) {
|
||||||
int ind = 1;
|
int ind = 1;
|
||||||
for (LatLon il : intermediates) {
|
for (LatLon il : params.intermediates) {
|
||||||
RouteSegment is = router.findRouteSegment(il.getLatitude(), il.getLongitude(), ctx);
|
RouteSegment is = router.findRouteSegment(il.getLatitude(), il.getLongitude(), ctx);
|
||||||
if (is == null) {
|
if (is == null) {
|
||||||
return new RouteCalculationResult(app.getString(R.string.intermediate_point_too_far, "'" + ind + "'"));
|
return new RouteCalculationResult(app.getString(R.string.intermediate_point_too_far, "'" + ind + "'"));
|
||||||
|
@ -386,15 +389,16 @@ public class RouteProvider {
|
||||||
try {
|
try {
|
||||||
List<RouteSegmentResult> result;
|
List<RouteSegmentResult> result;
|
||||||
if(inters.size() > 0){
|
if(inters.size() > 0){
|
||||||
result = router.searchRoute(ctx, st, en, inters, leftSide);
|
result = router.searchRoute(ctx, st, en, inters, params.leftSide);
|
||||||
} else {
|
} else {
|
||||||
result = router.searchRoute(ctx, st, en, leftSide);
|
result = router.searchRoute(ctx, st, en, params.leftSide);
|
||||||
}
|
}
|
||||||
if(result == null || result.isEmpty()) {
|
if(result == null || result.isEmpty()) {
|
||||||
// something really strange better to see that message on the scren
|
// something really strange better to see that message on the scren
|
||||||
return new RouteCalculationResult("Empty result");
|
return new RouteCalculationResult("Empty result");
|
||||||
} else {
|
} else {
|
||||||
return new RouteCalculationResult(result, start, end, intermediates, app, leftSide);
|
return new RouteCalculationResult(result, params.start, params.end,
|
||||||
|
params.intermediates, app, params.leftSide);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
return new RouteCalculationResult("Route calculation was interrupted");
|
return new RouteCalculationResult("Route calculation was interrupted");
|
||||||
|
@ -411,19 +415,19 @@ public class RouteProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected RouteCalculationResult findCloudMadeRoute(Location start, LatLon end, List<LatLon> intermediates, ApplicationMode mode, Context ctx, boolean fast, boolean leftSide)
|
protected RouteCalculationResult findCloudMadeRoute(RouteCalcuationParams params)
|
||||||
throws MalformedURLException, IOException, ParserConfigurationException, FactoryConfigurationError, SAXException {
|
throws MalformedURLException, IOException, ParserConfigurationException, FactoryConfigurationError, SAXException {
|
||||||
List<Location> res = new ArrayList<Location>();
|
List<Location> res = new ArrayList<Location>();
|
||||||
List<RouteDirectionInfo> directions = null;
|
List<RouteDirectionInfo> directions = null;
|
||||||
StringBuilder uri = new StringBuilder();
|
StringBuilder uri = new StringBuilder();
|
||||||
// possibly hide that API key because it is privacy of osmand
|
// possibly hide that API key because it is privacy of osmand
|
||||||
uri.append("http://routes.cloudmade.com/A6421860EBB04234AB5EF2D049F2CD8F/api/0.3/"); //$NON-NLS-1$
|
uri.append("http://routes.cloudmade.com/A6421860EBB04234AB5EF2D049F2CD8F/api/0.3/"); //$NON-NLS-1$
|
||||||
uri.append(start.getLatitude() + "").append(","); //$NON-NLS-1$ //$NON-NLS-2$
|
uri.append(params.start.getLatitude() + "").append(","); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
uri.append(start.getLongitude() + "").append(","); //$NON-NLS-1$ //$NON-NLS-2$
|
uri.append(params.start.getLongitude() + "").append(","); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
if(intermediates != null && intermediates.size() > 0) {
|
if(params.intermediates != null && params.intermediates.size() > 0) {
|
||||||
uri.append("[");
|
uri.append("[");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for(LatLon il : intermediates) {
|
for(LatLon il : params.intermediates) {
|
||||||
if(!first){
|
if(!first){
|
||||||
uri.append(",");
|
uri.append(",");
|
||||||
} else {
|
} else {
|
||||||
|
@ -434,18 +438,18 @@ public class RouteProvider {
|
||||||
}
|
}
|
||||||
uri.append("],");
|
uri.append("],");
|
||||||
}
|
}
|
||||||
uri.append(end.getLatitude() + "").append(","); //$NON-NLS-1$//$NON-NLS-2$
|
uri.append(params.end.getLatitude() + "").append(","); //$NON-NLS-1$//$NON-NLS-2$
|
||||||
uri.append(end.getLongitude() + "").append("/"); //$NON-NLS-1$ //$NON-NLS-2$
|
uri.append(params.end.getLongitude() + "").append("/"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
float speed = 1.5f;
|
float speed = 1.5f;
|
||||||
if (ApplicationMode.PEDESTRIAN == mode) {
|
if (ApplicationMode.PEDESTRIAN == params.mode) {
|
||||||
uri.append("foot.gpx"); //$NON-NLS-1$
|
uri.append("foot.gpx"); //$NON-NLS-1$
|
||||||
} else if (ApplicationMode.BICYCLE == mode) {
|
} else if (ApplicationMode.BICYCLE == params.mode) {
|
||||||
speed = 5.5f;
|
speed = 5.5f;
|
||||||
uri.append("bicycle.gpx"); //$NON-NLS-1$
|
uri.append("bicycle.gpx"); //$NON-NLS-1$
|
||||||
} else {
|
} else {
|
||||||
speed = 15.3f;
|
speed = 15.3f;
|
||||||
if (fast) {
|
if (params.fast) {
|
||||||
uri.append("car.gpx"); //$NON-NLS-1$
|
uri.append("car.gpx"); //$NON-NLS-1$
|
||||||
} else {
|
} else {
|
||||||
uri.append("car/shortest.gpx"); //$NON-NLS-1$
|
uri.append("car/shortest.gpx"); //$NON-NLS-1$
|
||||||
|
@ -455,10 +459,11 @@ public class RouteProvider {
|
||||||
log.info("URL route " + uri);
|
log.info("URL route " + uri);
|
||||||
URL url = new URL(uri.toString());
|
URL url = new URL(uri.toString());
|
||||||
URLConnection connection = url.openConnection();
|
URLConnection connection = url.openConnection();
|
||||||
GPXFile gpxFile = GPXUtilities.loadGPXFile(ctx, connection.getInputStream(), false);
|
GPXFile gpxFile = GPXUtilities.loadGPXFile(params.ctx, connection.getInputStream(), false);
|
||||||
directions = parseCloudmadeRoute(res, gpxFile, false, leftSide, speed);
|
directions = parseCloudmadeRoute(res, gpxFile, false, params.leftSide, speed);
|
||||||
|
|
||||||
return new RouteCalculationResult(res, directions, start, end, intermediates, null, ctx, leftSide, true);
|
return new RouteCalculationResult(res, directions, params.start, params.end, params.intermediates,
|
||||||
|
null, params.ctx, params.leftSide, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<RouteDirectionInfo> parseCloudmadeRoute(List<Location> res, GPXFile gpxFile, boolean osmandRouter,
|
private static List<RouteDirectionInfo> parseCloudmadeRoute(List<Location> res, GPXFile gpxFile, boolean osmandRouter,
|
||||||
|
@ -577,15 +582,14 @@ public class RouteProvider {
|
||||||
return directions;
|
return directions;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RouteCalculationResult findORSRoute(Location start, LatLon end, ApplicationMode mode, boolean fast, Context ctx,
|
protected RouteCalculationResult findORSRoute(RouteCalcuationParams params) throws MalformedURLException, IOException, ParserConfigurationException, FactoryConfigurationError,
|
||||||
boolean leftSide) throws MalformedURLException, IOException, ParserConfigurationException, FactoryConfigurationError,
|
|
||||||
SAXException {
|
SAXException {
|
||||||
List<Location> res = new ArrayList<Location>();
|
List<Location> res = new ArrayList<Location>();
|
||||||
|
|
||||||
String rpref = "Fastest";
|
String rpref = "Fastest";
|
||||||
if (ApplicationMode.PEDESTRIAN == mode) {
|
if (ApplicationMode.PEDESTRIAN == params.mode) {
|
||||||
rpref = "Pedestrian";
|
rpref = "Pedestrian";
|
||||||
} else if (ApplicationMode.BICYCLE == mode) {
|
} else if (ApplicationMode.BICYCLE == params.mode) {
|
||||||
rpref = "Bicycle";
|
rpref = "Bicycle";
|
||||||
// } else if (ApplicationMode.LOWTRAFFIC == mode) {
|
// } else if (ApplicationMode.LOWTRAFFIC == mode) {
|
||||||
// rpref = "BicycleSafety";
|
// rpref = "BicycleSafety";
|
||||||
|
@ -595,13 +599,13 @@ public class RouteProvider {
|
||||||
// rpref = "BicycleRoute";
|
// rpref = "BicycleRoute";
|
||||||
// } else if (ApplicationMode.MTBIKE == mode) {
|
// } else if (ApplicationMode.MTBIKE == mode) {
|
||||||
// rpref = "BicycleMTB";
|
// rpref = "BicycleMTB";
|
||||||
} else if (!fast) {
|
} else if (!params.fast) {
|
||||||
rpref = "Shortest";
|
rpref = "Shortest";
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder request = new StringBuilder();
|
StringBuilder request = new StringBuilder();
|
||||||
request.append("http://openls.geog.uni-heidelberg.de/osm/eu/routing?").append("start=").append(start.getLongitude()).append(',')
|
request.append("http://openls.geog.uni-heidelberg.de/osm/eu/routing?").append("start=").append(params.start.getLongitude()).append(',')
|
||||||
.append(start.getLatitude()).append("&end=").append(end.getLongitude()).append(',').append(end.getLatitude())
|
.append(params.start.getLatitude()).append("&end=").append(params.end.getLongitude()).append(',').append(params.end.getLatitude())
|
||||||
.append("&preference=").append(rpref);
|
.append("&preference=").append(rpref);
|
||||||
// TODO if we would get instructions from the service, we could use this language setting
|
// TODO if we would get instructions from the service, we could use this language setting
|
||||||
// .append("&language=").append(Locale.getDefault().getLanguage());
|
// .append("&language=").append(Locale.getDefault().getLanguage());
|
||||||
|
@ -637,7 +641,7 @@ public class RouteProvider {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new RouteCalculationResult(res, null, start, end, null, null, ctx, leftSide, true);
|
return new RouteCalculationResult(res, null, params.start, params.end, null, null, params.ctx, params.leftSide, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GPXFile createOsmandRouterGPX(RouteCalculationResult srcRoute){
|
public GPXFile createOsmandRouterGPX(RouteCalculationResult srcRoute){
|
||||||
|
|
|
@ -254,8 +254,8 @@ public class RoutingHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (calculateRoute) {
|
if (calculateRoute) {
|
||||||
recalculateRouteInBackground(currentLocation, finalLocation, intermediatePoints, currentGPXRoute,
|
recalculateRouteInBackground(currentLocation, finalLocation, intermediatePoints, currentGPXRoute, route.isCalculated() ? route
|
||||||
route.isCalculated()? route : null);
|
: null);
|
||||||
}
|
}
|
||||||
double projectDist = mode == ApplicationMode.CAR ? posTolerance : posTolerance / 2;
|
double projectDist = mode == ApplicationMode.CAR ? posTolerance : posTolerance / 2;
|
||||||
if(returnUpdatedLocation && locationProjection != null && currentLocation.distanceTo(locationProjection) < projectDist) {
|
if(returnUpdatedLocation && locationProjection != null && currentLocation.distanceTo(locationProjection) < projectDist) {
|
||||||
|
@ -569,26 +569,15 @@ public class RoutingHelper {
|
||||||
|
|
||||||
private class RouteRecalculationThread extends Thread implements Interruptable {
|
private class RouteRecalculationThread extends Thread implements Interruptable {
|
||||||
|
|
||||||
private final Location start;
|
|
||||||
private final LatLon end;
|
|
||||||
private final GPXRouteParams gpxRoute;
|
|
||||||
private final RouteCalculationResult previousRoute;
|
|
||||||
private RouteService service;
|
|
||||||
private boolean interrupted = false;
|
private boolean interrupted = false;
|
||||||
private final List<LatLon> intermediates;
|
private final RouteCalcuationParams params;
|
||||||
|
|
||||||
public RouteRecalculationThread(String name,
|
public RouteRecalculationThread(String name, RouteCalcuationParams params) {
|
||||||
Location start, LatLon end, List<LatLon> intermediates, GPXRouteParams gpxRoute, RouteCalculationResult previousRoute){
|
|
||||||
super(name);
|
super(name);
|
||||||
this.start = start;
|
this.params = params;
|
||||||
this.end = end;
|
params.interruptable = this;
|
||||||
this.intermediates = intermediates;
|
|
||||||
this.gpxRoute = gpxRoute;
|
|
||||||
this.previousRoute = previousRoute;
|
|
||||||
service = settings.ROUTER_SERVICE.getModeValue(mode);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopCalculation(){
|
public void stopCalculation(){
|
||||||
interrupted = true;
|
interrupted = true;
|
||||||
}
|
}
|
||||||
|
@ -600,10 +589,8 @@ public class RoutingHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean leftSide = settings.LEFT_SIDE_NAVIGATION.get();
|
|
||||||
boolean fastRoute = settings.FAST_ROUTE_MODE.get();
|
RouteCalculationResult res = provider.calculateRouteImpl(params);
|
||||||
RouteCalculationResult res = provider.calculateRouteImpl(start, end, intermediates, mode, service, app, gpxRoute, previousRoute, fastRoute,
|
|
||||||
leftSide, this);
|
|
||||||
if (interrupted) {
|
if (interrupted) {
|
||||||
currentRunningJob = null;
|
currentRunningJob = null;
|
||||||
return;
|
return;
|
||||||
|
@ -611,7 +598,7 @@ public class RoutingHelper {
|
||||||
|
|
||||||
synchronized (RoutingHelper.this) {
|
synchronized (RoutingHelper.this) {
|
||||||
if (res.isCalculated()) {
|
if (res.isCalculated()) {
|
||||||
setNewRoute(res, start);
|
setNewRoute(res, params.start);
|
||||||
} else {
|
} else {
|
||||||
evalWaitInterval = evalWaitInterval * 3 / 2;
|
evalWaitInterval = evalWaitInterval * 3 / 2;
|
||||||
evalWaitInterval = Math.min(evalWaitInterval, 120000);
|
evalWaitInterval = Math.min(evalWaitInterval, 120000);
|
||||||
|
@ -622,7 +609,7 @@ public class RoutingHelper {
|
||||||
if (res.isCalculated()) {
|
if (res.isCalculated()) {
|
||||||
showMessage(app.getString(R.string.new_route_calculated_dist)
|
showMessage(app.getString(R.string.new_route_calculated_dist)
|
||||||
+ ": " + OsmAndFormatter.getFormattedDistance(res.getWholeDistance(), app)); //$NON-NLS-1$
|
+ ": " + OsmAndFormatter.getFormattedDistance(res.getWholeDistance(), app)); //$NON-NLS-1$
|
||||||
} else if (service != RouteService.OSMAND && !settings.isInternetConnectionAvailable()) {
|
} else if (params.type != RouteService.OSMAND && !settings.isInternetConnectionAvailable()) {
|
||||||
showMessage(app.getString(R.string.error_calculating_route)
|
showMessage(app.getString(R.string.error_calculating_route)
|
||||||
+ ":\n" + app.getString(R.string.internet_connection_required_for_online_route), Toast.LENGTH_LONG); //$NON-NLS-1$
|
+ ":\n" + app.getString(R.string.internet_connection_required_for_online_route), Toast.LENGTH_LONG); //$NON-NLS-1$
|
||||||
} else {
|
} else {
|
||||||
|
@ -644,8 +631,19 @@ public class RoutingHelper {
|
||||||
if(currentRunningJob == null){
|
if(currentRunningJob == null){
|
||||||
// do not evaluate very often
|
// do not evaluate very often
|
||||||
if (System.currentTimeMillis() - lastTimeEvaluatedRoute > evalWaitInterval) {
|
if (System.currentTimeMillis() - lastTimeEvaluatedRoute > evalWaitInterval) {
|
||||||
|
RouteCalcuationParams params = new RouteCalcuationParams();
|
||||||
|
params.start = start;
|
||||||
|
params.end = end;
|
||||||
|
params.intermediates = intermediates;
|
||||||
|
params.gpxRoute = gpxRoute;
|
||||||
|
params.previousToRecalculate = previousRoute;
|
||||||
|
params.leftSide = settings.LEFT_SIDE_NAVIGATION.get();
|
||||||
|
params.optimal = settings.OPTIMAL_ROUTE_MODE.get();
|
||||||
|
params.fast = settings.FAST_ROUTE_MODE.get();
|
||||||
|
params.type = settings.ROUTER_SERVICE.getModeValue(mode);
|
||||||
|
params.mode = mode;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
currentRunningJob = new RouteRecalculationThread("Calculating route", start, end, intermediates, gpxRoute, previousRoute); //$NON-NLS-1$
|
currentRunningJob = new RouteRecalculationThread("Calculating route", params); //$NON-NLS-1$
|
||||||
currentRunningJob.start();
|
currentRunningJob.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue