Search in sources :

Example 11 with GPXRouteParamsBuilder

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();
}
Also used : GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) BottomSheetItemWithDescription(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription)

Example 12 with GPXRouteParamsBuilder

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;
}
Also used : GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) ArrayList(java.util.ArrayList) RoutingHelper(net.osmand.plus.routing.RoutingHelper)

Example 13 with GPXRouteParamsBuilder

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;
}
Also used : RoutingParameter(net.osmand.router.GeneralRouter.RoutingParameter) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) GeneralRouter(net.osmand.router.GeneralRouter) RoutingParameter(net.osmand.router.GeneralRouter.RoutingParameter)

Example 14 with GPXRouteParamsBuilder

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");
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) OnlineRoutingHelper(net.osmand.plus.onlinerouting.OnlineRoutingHelper) OnlineRoutingResponse(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine.OnlineRoutingResponse) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) Location(net.osmand.Location)

Example 15 with GPXRouteParamsBuilder

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);
    }
}
Also used : LatLon(net.osmand.data.LatLon) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) Location(net.osmand.Location)

Aggregations

GPXRouteParamsBuilder (net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder)22 OsmandApplication (net.osmand.plus.OsmandApplication)10 File (java.io.File)8 ImageView (android.widget.ImageView)7 TextView (android.widget.TextView)7 MapActivity (net.osmand.plus.activities.MapActivity)7 View (android.view.View)6 GPXFile (net.osmand.GPXUtilities.GPXFile)6 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)6 Location (net.osmand.Location)5 AppCompatImageView (androidx.appcompat.widget.AppCompatImageView)4 LinearLayout (android.widget.LinearLayout)3 AlertDialog (androidx.appcompat.app.AlertDialog)3 LatLon (net.osmand.data.LatLon)3 TargetPointsHelper (net.osmand.plus.helpers.TargetPointsHelper)3 RoutingHelper (net.osmand.plus.routing.RoutingHelper)3 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)3 FrameLayout (android.widget.FrameLayout)2 HorizontalScrollView (android.widget.HorizontalScrollView)2 ArrayList (java.util.ArrayList)2