Add feature to calculate route between rtept
This commit is contained in:
parent
2d548eec46
commit
81daec3e70
8 changed files with 105 additions and 25 deletions
|
@ -9,6 +9,7 @@
|
|||
3. 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
|
||||
-->
|
||||
<string name="use_points_as_intermediates">Calculate route between points</string>
|
||||
<string name="osmo_register_device">Registering device... </string>
|
||||
<string name="osmo_io_error">OSMo connection problem : </string>
|
||||
<string name="osmo_mode_on">Stop OSMo</string>
|
||||
|
|
|
@ -124,6 +124,26 @@ public class GPXUtilities {
|
|||
return "cloudmade".equalsIgnoreCase(author);
|
||||
}
|
||||
|
||||
public boolean hasRtePt() {
|
||||
for(Route r : routes) {
|
||||
if(r.points.size() > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasTrkpt() {
|
||||
for(Track t : tracks) {
|
||||
for (TrkSegment ts : t.segments) {
|
||||
if (ts.points.size() > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void proccessPoints() {
|
||||
List<List<WptPt>> tpoints = new ArrayList<List<WptPt>>();
|
||||
boolean created = false;
|
||||
|
|
|
@ -786,9 +786,10 @@ public class OsmandSettings {
|
|||
public final OsmandPreference<Boolean> SPEAK_SPEED_CAMERA = new BooleanPreference("speak_cameras", true).makeProfile().cache();
|
||||
public final OsmandPreference<Boolean> SPEAK_SPEED_LIMIT = new BooleanPreference("speak_speed_limit", true).makeProfile().cache();
|
||||
|
||||
public final OsmandPreference<Boolean> ROUTE_CALC_OSMAND_PARTS = new BooleanPreference("gpx_routing_calculate_osmand_route", true).makeGlobal().cache();
|
||||
public final OsmandPreference<Boolean> SPEAK_GPX_WPT = new BooleanPreference("speak_gpx_wpt", true).makeGlobal().cache();
|
||||
public final OsmandPreference<Boolean> CALC_GPX_ROUTE = new BooleanPreference("calc_gpx_route", false).makeGlobal().cache();
|
||||
public final OsmandPreference<Boolean> GPX_ROUTE_CALC_OSMAND_PARTS = new BooleanPreference("gpx_routing_calculate_osmand_route", true).makeGlobal().cache();
|
||||
public final OsmandPreference<Boolean> GPX_CALCULATE_RTEPT = new BooleanPreference("gpx_routing_calculate_rtept", true).makeGlobal().cache();
|
||||
public final OsmandPreference<Boolean> GPX_SPEAK_WPT = new BooleanPreference("speak_gpx_wpt", true).makeGlobal().cache();
|
||||
public final OsmandPreference<Boolean> GPX_ROUTE_CALC = new BooleanPreference("calc_gpx_route", false).makeGlobal().cache();
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -473,9 +473,15 @@ public class MapActivityActions implements DialogProvider {
|
|||
} else {
|
||||
GPXRouteParamsBuilder params = new GPXRouteParamsBuilder(result, mapActivity.getMyApplication()
|
||||
.getSettings());
|
||||
params.setCalculateOsmAndRouteParts(settings.ROUTE_CALC_OSMAND_PARTS.get());
|
||||
params.setAnnounceWaypoints(settings.SPEAK_GPX_WPT.get());
|
||||
params.setCalculateOsmAndRoute(settings.CALC_GPX_ROUTE.get());
|
||||
if (result.hasRtePt() && !result.hasTrkpt()) {
|
||||
settings.GPX_CALCULATE_RTEPT.set(true);
|
||||
} else {
|
||||
settings.GPX_CALCULATE_RTEPT.set(false);
|
||||
}
|
||||
params.setCalculateOsmAndRouteParts(settings.GPX_ROUTE_CALC_OSMAND_PARTS.get());
|
||||
params.setAnnounceWaypoints(settings.GPX_SPEAK_WPT.get());
|
||||
params.setUseIntermediatePointsRTE(settings.GPX_CALCULATE_RTEPT.get());
|
||||
params.setCalculateOsmAndRoute(settings.GPX_ROUTE_CALC.get());
|
||||
List<Location> ps = params.getPoints();
|
||||
mapActivity.getRoutingHelper().setGpxParams(params);
|
||||
settings.FOLLOW_THE_GPX_ROUTE.set(result.path);
|
||||
|
|
|
@ -128,13 +128,16 @@ public class FailSafeFuntions {
|
|||
final GPXRouteParamsBuilder gpxRoute;
|
||||
if (result != null) {
|
||||
gpxRoute = new GPXRouteParamsBuilder(result, settings);
|
||||
if (settings.SPEAK_GPX_WPT.get()) {
|
||||
if (settings.GPX_SPEAK_WPT.get()) {
|
||||
gpxRoute.setAnnounceWaypoints(true);
|
||||
}
|
||||
if (settings.ROUTE_CALC_OSMAND_PARTS.get()) {
|
||||
if (settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()) {
|
||||
gpxRoute.setCalculateOsmAndRouteParts(true);
|
||||
}
|
||||
if(settings.CALC_GPX_ROUTE.get()) {
|
||||
if (settings.GPX_CALCULATE_RTEPT.get()) {
|
||||
gpxRoute.setUseIntermediatePointsRTE(true);
|
||||
}
|
||||
if(settings.GPX_ROUTE_CALC.get()) {
|
||||
gpxRoute.setCalculateOsmAndRoute(true);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -119,7 +119,8 @@ public class RouteProvider {
|
|||
private boolean reverse;
|
||||
private boolean leftSide;
|
||||
private boolean passWholeRoute;
|
||||
public boolean calculateOsmAndRouteParts;
|
||||
private boolean calculateOsmAndRouteParts;
|
||||
private boolean useIntermediatePointsRTE;
|
||||
|
||||
public GPXRouteParamsBuilder(GPXFile file, OsmandSettings settings){
|
||||
leftSide = settings.DRIVING_REGION.get().leftHandDriving;
|
||||
|
@ -142,6 +143,14 @@ public class RouteProvider {
|
|||
this.calculateOsmAndRouteParts = calculateOsmAndRouteParts;
|
||||
}
|
||||
|
||||
public void setUseIntermediatePointsRTE(boolean useIntermediatePointsRTE) {
|
||||
this.useIntermediatePointsRTE = useIntermediatePointsRTE;
|
||||
}
|
||||
|
||||
public boolean isUseIntermediatePointsRTE() {
|
||||
return useIntermediatePointsRTE;
|
||||
}
|
||||
|
||||
public boolean isCalculateOsmAndRoute() {
|
||||
return calculateOsmAndRoute;
|
||||
}
|
||||
|
@ -196,6 +205,7 @@ public class RouteProvider {
|
|||
boolean calculateOsmAndRoute;
|
||||
boolean passWholeRoute;
|
||||
boolean calculateOsmAndRouteParts;
|
||||
boolean useIntermediatePointsRTE;
|
||||
|
||||
public List<Location> getPoints() {
|
||||
return points;
|
||||
|
@ -229,8 +239,9 @@ public class RouteProvider {
|
|||
boolean reverse = builder.reverse;
|
||||
passWholeRoute = builder.passWholeRoute;
|
||||
calculateOsmAndRouteParts = builder.calculateOsmAndRouteParts;
|
||||
useIntermediatePointsRTE = builder.useIntermediatePointsRTE;
|
||||
boolean announceWaypoints = builder.announceWaypoints;
|
||||
calculateOsmAndRoute = false; // Disabled temporary builder.calculateOsmAndRoute;
|
||||
builder.calculateOsmAndRoute = false; // Disabled temporary builder.calculateOsmAndRoute;
|
||||
if(file.isCloudmadeRouteFile() || OSMAND_ROUTER.equals(file.author)){
|
||||
directions = parseOsmAndGPXRoute(points, file, OSMAND_ROUTER.equals(file.author), builder.leftSide, 10);
|
||||
if(reverse){
|
||||
|
@ -240,6 +251,7 @@ public class RouteProvider {
|
|||
}
|
||||
} else {
|
||||
// first of all check tracks
|
||||
if (!useIntermediatePointsRTE) {
|
||||
for (Track tr : file.tracks) {
|
||||
for (TrkSegment tkSeg : tr.segments) {
|
||||
for (WptPt pt : tkSeg.points) {
|
||||
|
@ -247,6 +259,7 @@ public class RouteProvider {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (points.isEmpty()) {
|
||||
for (Route rte : file.routes) {
|
||||
for (WptPt pt : rte.points) {
|
||||
|
@ -348,9 +361,13 @@ public class RouteProvider {
|
|||
return res;
|
||||
}
|
||||
|
||||
private RouteCalculationResult calculateGpxRoute(RouteCalculationParams routeParams) {
|
||||
private RouteCalculationResult calculateGpxRoute(RouteCalculationParams routeParams) throws IOException {
|
||||
// get the closest point to start and to end
|
||||
GPXRouteParams gpxParams = routeParams.gpxRoute;
|
||||
if(routeParams.gpxRoute.useIntermediatePointsRTE){
|
||||
final List<Location> intermediates = gpxParams.points;
|
||||
return calculateOsmAndRouteWithIntermediatePoints(routeParams, intermediates);
|
||||
}
|
||||
List<Location> gpxRoute ;
|
||||
int[] startI = new int[]{0};
|
||||
int[] endI = new int[]{gpxParams.points.size()};
|
||||
|
@ -378,6 +395,28 @@ public class RouteProvider {
|
|||
|
||||
|
||||
|
||||
private RouteCalculationResult calculateOsmAndRouteWithIntermediatePoints(RouteCalculationParams routeParams,
|
||||
final List<Location> intermediates) throws IOException {
|
||||
RouteCalculationParams rp = new RouteCalculationParams();
|
||||
rp.calculationProgress = routeParams.calculationProgress;
|
||||
rp.ctx = routeParams.ctx;
|
||||
rp.mode = routeParams.mode;
|
||||
rp.start = routeParams.start;
|
||||
rp.end = routeParams.end;
|
||||
rp.leftSide = routeParams.leftSide;
|
||||
rp.type = routeParams.type;
|
||||
rp.fast = routeParams.fast;
|
||||
rp.previousToRecalculate = routeParams.previousToRecalculate;
|
||||
rp.intermediates = new ArrayList<LatLon>();
|
||||
for(Location w : intermediates) {
|
||||
rp.intermediates.add(new LatLon(w.getLatitude(), w.getLongitude()));
|
||||
}
|
||||
return findVectorMapsRoute(rp, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private List<RouteDirectionInfo> calcDirections(int[] startI, int[] endI,
|
||||
final List<RouteDirectionInfo> inputDirections) {
|
||||
List<RouteDirectionInfo> directions = new ArrayList<RouteDirectionInfo>();
|
||||
|
|
|
@ -757,7 +757,7 @@ public class RoutingHelper {
|
|||
return;
|
||||
}
|
||||
final boolean onlineSourceWithoutInternet = !res.isCalculated() && params.type.isOnline() && !settings.isInternetConnectionAvailable();
|
||||
if (onlineSourceWithoutInternet && settings.ROUTE_CALC_OSMAND_PARTS.get()) {
|
||||
if (onlineSourceWithoutInternet && settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()) {
|
||||
if (params.previousToRecalculate != null && params.previousToRecalculate.isCalculated()) {
|
||||
res = provider.recalculatePartOfflineRoute(res, params);
|
||||
}
|
||||
|
|
|
@ -188,20 +188,23 @@ public class MapRoutePreferencesControl extends MapControls {
|
|||
}
|
||||
} else if (gpxParam.id == R.string.gpx_option_calculate_first_last_segment) {
|
||||
rp.setCalculateOsmAndRouteParts(selected);
|
||||
settings.ROUTE_CALC_OSMAND_PARTS.set(selected);
|
||||
settings.GPX_ROUTE_CALC_OSMAND_PARTS.set(selected);
|
||||
} else if (gpxParam.id == R.string.gpx_option_from_start_point) {
|
||||
rp.setPassWholeRoute(selected);
|
||||
} else if (gpxParam.id == R.string.announce_gpx_waypoints) {
|
||||
settings.SPEAK_GPX_WPT.set(selected);
|
||||
settings.GPX_SPEAK_WPT.set(selected);
|
||||
rp.setAnnounceWaypoints(selected);
|
||||
} else if (gpxParam.id == R.string.use_points_as_intermediates) {
|
||||
settings.GPX_CALCULATE_RTEPT.set(selected);
|
||||
rp.setUseIntermediatePointsRTE(selected);
|
||||
} else if (gpxParam.id == R.string.calculate_osmand_route_gpx) {
|
||||
settings.CALC_GPX_ROUTE.set(selected);
|
||||
settings.GPX_ROUTE_CALC.set(selected);
|
||||
rp.setCalculateOsmAndRoute(selected);
|
||||
updateParameters();
|
||||
}
|
||||
}
|
||||
if (gpxParam.id == R.string.calculate_osmand_route_without_internet) {
|
||||
settings.ROUTE_CALC_OSMAND_PARTS.set(selected);
|
||||
settings.GPX_ROUTE_CALC_OSMAND_PARTS.set(selected);
|
||||
}
|
||||
if (gpxParam.id == R.string.fast_route_mode) {
|
||||
settings.FAST_ROUTE_MODE.set(selected);
|
||||
|
@ -215,18 +218,25 @@ public class MapRoutePreferencesControl extends MapControls {
|
|||
boolean osmandRouter = settings.ROUTER_SERVICE.get() == RouteService.OSMAND ;
|
||||
if(!osmandRouter) {
|
||||
list.add(new OtherLocalRoutingParameter(R.string.calculate_osmand_route_without_internet,
|
||||
getString(R.string.calculate_osmand_route_without_internet), settings.ROUTE_CALC_OSMAND_PARTS.get()));
|
||||
getString(R.string.calculate_osmand_route_without_internet), settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()));
|
||||
list.add(new OtherLocalRoutingParameter(R.string.fast_route_mode,
|
||||
getString(R.string.fast_route_mode), settings.FAST_ROUTE_MODE.get()));
|
||||
return list;
|
||||
}
|
||||
if(rparams != null) {
|
||||
GPXFile fl = rparams.getFile();
|
||||
if (fl.hasRtePt()) {
|
||||
list.add(new OtherLocalRoutingParameter(R.string.use_points_as_intermediates,
|
||||
getString(R.string.use_points_as_intermediates), rparams.isUseIntermediatePointsRTE()));
|
||||
}
|
||||
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route,
|
||||
getString(R.string.gpx_option_reverse_route), rparams.isReverse()));
|
||||
if (!rparams.isUseIntermediatePointsRTE()) {
|
||||
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point,
|
||||
getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute()));
|
||||
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_calculate_first_last_segment,
|
||||
getString(R.string.gpx_option_calculate_first_last_segment), rparams.isCalculateOsmAndRouteParts()));
|
||||
}
|
||||
list.add(new OtherLocalRoutingParameter(R.string.announce_gpx_waypoints,
|
||||
getString(R.string.announce_gpx_waypoints), rparams.isAnnounceWaypoints()));
|
||||
// Temporary disabled
|
||||
|
|
Loading…
Reference in a new issue