use of net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder in project Osmand by osmandapp.
the class RouteOptionsBottomSheet method createGpxRoutingItem.
private BaseBottomSheetItem createGpxRoutingItem(final LocalRoutingParameter optionsItem) {
GPXRouteParamsBuilder routeParamsBuilder = mapActivity.getRoutingHelper().getCurrentGPXRoute();
String description = null;
int descriptionColorId;
if (routeParamsBuilder == null) {
descriptionColorId = ColorUtilities.getSecondaryTextColorId(nightMode);
description = mapActivity.getString(R.string.follow_track_descr);
} else {
descriptionColorId = ColorUtilities.getActiveColorId(nightMode);
GPXFile gpxFile = routeParamsBuilder.getFile();
if (!Algorithms.isEmpty(gpxFile.path)) {
description = new File(gpxFile.path).getName();
} else if (!Algorithms.isEmpty(gpxFile.tracks)) {
description = gpxFile.tracks.get(0).name;
}
}
return new BottomSheetItemWithDescription.Builder().setDescription(description).setDescriptionColorId(descriptionColorId).setIcon(getContentIcon(optionsItem.getActiveIconId())).setTitle(getString(R.string.follow_track)).setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MapRouteInfoMenu mapRouteInfoMenu = mapActivity.getMapRouteInfoMenu();
mapRouteInfoMenu.hide();
mapRouteInfoMenu.selectTrack();
dismiss();
}
}).create();
}
use of net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder in project Osmand by osmandapp.
the class RoutingOptionsHelper method getGpxRouterParameters.
public List<LocalRoutingParameter> getGpxRouterParameters(ApplicationMode am) {
RoutingHelper routingHelper = app.getRoutingHelper();
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
GPXRouteParamsBuilder rparams = routingHelper.getCurrentGPXRoute();
boolean osmandRouter = am.getRouteService() == RouteService.OSMAND;
if (rparams != null && osmandRouter) {
if (!routingHelper.isCurrentGPXRouteV2()) {
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route, app.getString(R.string.gpx_option_reverse_route), rparams.isReverse()));
}
if (!rparams.useIntermediateRtePoints()) {
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point, app.getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute()));
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_calculate_first_last_segment, app.getString(R.string.gpx_option_calculate_first_last_segment), rparams.isCalculateOsmAndRouteParts()));
}
}
return list;
}
use of net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder in project Osmand by osmandapp.
the class RoutingOptionsHelper method getRoutingParameterInnerById.
public LocalRoutingParameter getRoutingParameterInnerById(ApplicationMode am, String parameterId) {
GPXRouteParamsBuilder rparams = app.getRoutingHelper().getCurrentGPXRoute();
GeneralRouter rm = app.getRouter(am);
if (rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute()) && !rparams.getFile().hasRtePt()) {
return null;
}
LocalRoutingParameter rp;
Map<String, GeneralRouter.RoutingParameter> parameters = rm.getParameters();
GeneralRouter.RoutingParameter routingParameter = parameters.get(parameterId);
if (routingParameter != null) {
rp = new LocalRoutingParameter(am);
rp.routingParameter = routingParameter;
} else {
LocalRoutingParameterGroup rpg = null;
for (GeneralRouter.RoutingParameter r : rm.getParameters().values()) {
if (r.getType() == GeneralRouter.RoutingParameterType.BOOLEAN && !Algorithms.isEmpty(r.getGroup()) && r.getGroup().equals(parameterId)) {
if (rpg == null) {
rpg = new LocalRoutingParameterGroup(am, r.getGroup());
}
rpg.addRoutingParameter(r);
}
}
return rpg;
}
return rp;
}
use of net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder in project Osmand by osmandapp.
the class RouteProvider method findOnlineRoute.
private RouteCalculationResult findOnlineRoute(RouteCalculationParams params) throws IOException, JSONException {
OsmandApplication app = params.ctx;
OnlineRoutingHelper helper = app.getOnlineRoutingHelper();
OsmandSettings settings = app.getSettings();
String engineKey = params.mode.getRoutingProfile();
OnlineRoutingResponse response = helper.calculateRouteOnline(engineKey, getPathFromParams(params), params.start.hasBearing() ? params.start.getBearing() : null, params.leftSide, params.initialCalculation);
if (response != null) {
if (response.getGpxFile() != null) {
GPXRouteParamsBuilder builder = new GPXRouteParamsBuilder(response.getGpxFile(), settings);
builder.setCalculatedRouteTimeSpeed(response.hasCalculatedTimeSpeed());
params.gpxRoute = builder.build(app);
return calculateGpxRoute(params);
}
List<Location> route = response.getRoute();
List<RouteDirectionInfo> directions = response.getDirections();
if (!Algorithms.isEmpty(route) && !Algorithms.isEmpty(directions)) {
params.intermediates = null;
return new RouteCalculationResult(route, directions, params, null, false);
}
} else {
params.initialCalculation = false;
}
return new RouteCalculationResult("Route is empty");
}
use of net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder in project Osmand by osmandapp.
the class RoutingOptionsHelper method updateGpxRoutingParameter.
public void updateGpxRoutingParameter(OtherLocalRoutingParameter gpxParam) {
GPXRouteParamsBuilder rp = app.getRoutingHelper().getCurrentGPXRoute();
final OsmandSettings settings = app.getSettings();
boolean selected = gpxParam.isSelected(settings);
if (rp != null) {
if (gpxParam.id == R.string.gpx_option_reverse_route) {
rp.setReverse(selected);
TargetPointsHelper tg = app.getTargetPointsHelper();
List<Location> ps = rp.getPoints(app);
if (ps.size() > 0) {
Location firstLoc = ps.get(0);
Location lastLoc = ps.get(ps.size() - 1);
TargetPoint pointToStart = tg.getPointToStart();
TargetPoint pointToNavigate = tg.getPointToNavigate();
if (rp.getFile().hasRoute()) {
LatLon firstLatLon = new LatLon(firstLoc.getLatitude(), firstLoc.getLongitude());
LatLon endLocation = pointToStart != null ? pointToStart.point : new LatLon(lastLoc.getLatitude(), lastLoc.getLongitude());
LatLon startLocation = pointToNavigate != null ? pointToNavigate.point : firstLatLon;
tg.navigateToPoint(endLocation, false, -1);
if (pointToStart != null) {
tg.setStartPoint(startLocation, false, null);
}
tg.updateRouteAndRefresh(true);
} else {
boolean update = false;
if (pointToNavigate == null || MapUtils.getDistance(pointToNavigate.point, new LatLon(firstLoc.getLatitude(), firstLoc.getLongitude())) < 10) {
tg.navigateToPoint(new LatLon(lastLoc.getLatitude(), lastLoc.getLongitude()), false, -1);
update = true;
}
if (pointToStart != null && MapUtils.getDistance(pointToStart.point, new LatLon(lastLoc.getLatitude(), lastLoc.getLongitude())) < 10) {
tg.setStartPoint(new LatLon(firstLoc.getLatitude(), firstLoc.getLongitude()), false, null);
update = true;
}
if (update) {
tg.updateRouteAndRefresh(true);
}
}
}
} else if (gpxParam.id == R.string.gpx_option_calculate_first_last_segment) {
rp.setCalculateOsmAndRouteParts(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.calculate_osmand_route_gpx) {
settings.GPX_ROUTE_CALC.set(selected);
rp.setCalculateOsmAndRoute(selected);
} else if (gpxParam.id == R.string.connect_track_points_as) {
rp.setConnectPointStraightly(selected);
}
}
if (gpxParam.id == R.string.calculate_osmand_route_without_internet) {
settings.GPX_ROUTE_CALC_OSMAND_PARTS.set(selected);
}
if (gpxParam.id == R.string.fast_route_mode) {
settings.FAST_ROUTE_MODE.set(selected);
}
if (gpxParam.id == R.string.speak_favorites) {
settings.ANNOUNCE_NEARBY_FAVORITES.set(selected);
}
}
Aggregations