Search in sources :

Example 26 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class RouteProvider method createOsmandRouterGPX.

public GPXFile createOsmandRouterGPX(RouteCalculationResult route, OsmandApplication ctx, String name) {
    TargetPointsHelper helper = ctx.getTargetPointsHelper();
    List<WptPt> points = new ArrayList<>();
    List<TargetPoint> ps = helper.getIntermediatePointsWithTarget();
    for (int k = 0; k < ps.size(); k++) {
        WptPt pt = new WptPt();
        pt.lat = ps.get(k).getLatitude();
        pt.lon = ps.get(k).getLongitude();
        if (k < ps.size()) {
            pt.name = ps.get(k).getOnlyName() + "";
            if (k == ps.size() - 1) {
                String target = ctx.getString(R.string.destination_point, "");
                if (pt.name.startsWith(target)) {
                    pt.name = ctx.getString(R.string.destination_point, pt.name);
                }
            } else {
                String prefix = (k + 1) + ". ";
                if (Algorithms.isEmpty(pt.name)) {
                    pt.name = ctx.getString(R.string.target_point, pt.name);
                }
                if (pt.name.startsWith(prefix)) {
                    pt.name = prefix + pt.name;
                }
            }
            pt.desc = pt.name;
        }
        points.add(pt);
    }
    List<Location> locations = route.getImmutableAllLocations();
    List<RouteSegmentResult> originalRoute = route.getOriginalRoute();
    RouteExporter exporter = new RouteExporter(name, originalRoute, locations, points);
    return exporter.exportRoute();
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) ArrayList(java.util.ArrayList) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) GpxPoint(net.osmand.router.RoutePlannerFrontEnd.GpxPoint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) RouteExporter(net.osmand.router.RouteExporter) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) RouteSegmentResult(net.osmand.router.RouteSegmentResult) Location(net.osmand.Location)

Example 27 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper 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)

Example 28 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class WaypointsFragment method applyPointsChanges.

private void applyPointsChanges() {
    OsmandApplication app = getMyApplication();
    if (app == null) {
        return;
    }
    app.runInUIThread(new Runnable() {

        @Override
        public void run() {
            OsmandApplication app = getMyApplication();
            if (app == null || !isVisible()) {
                return;
            }
            List<TargetPoint> allTargets = new ArrayList<>();
            TargetPoint start = null;
            List<Object> items = listAdapter.getActiveObjects();
            if (items != null) {
                for (Object obj : items) {
                    if (obj instanceof LocationPointWrapper) {
                        LocationPointWrapper p = (LocationPointWrapper) obj;
                        if (p.getPoint() instanceof TargetPoint) {
                            TargetPoint t = (TargetPoint) p.getPoint();
                            if (t.start) {
                                start = t;
                            } else {
                                t.intermediate = true;
                            }
                            allTargets.add(t);
                        }
                    }
                }
                if (allTargets.size() > 0) {
                    allTargets.get(allTargets.size() - 1).intermediate = false;
                }
            }
            TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
            if (start != null) {
                int startInd = allTargets.indexOf(start);
                TargetPoint first = allTargets.remove(0);
                if (startInd != 0) {
                    start.start = false;
                    start.intermediate = startInd != allTargets.size() - 1;
                    if (targetPointsHelper.getPointToStart() == null) {
                        start.getOriginalPointDescription().setName(PointDescription.getLocationNamePlain(getMyApplication(), start.getLatitude(), start.getLongitude()));
                    }
                    first.start = true;
                    first.intermediate = false;
                    targetPointsHelper.setStartPoint(new LatLon(first.getLatitude(), first.getLongitude()), false, first.getPointDescription(getMyApplication()));
                }
            }
            targetPointsHelper.reorderAllTargetPoints(allTargets, false);
            newRouteIsCalculated(false, new ValueHolder<Boolean>());
            targetPointsHelper.updateRouteAndRefresh(true);
        }
    }, 50);
}
Also used : LatLon(net.osmand.data.LatLon) OsmandApplication(net.osmand.plus.OsmandApplication) LocationPointWrapper(net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper) List(java.util.List) ArrayList(java.util.ArrayList) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) ValueHolder(net.osmand.data.ValueHolder) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper)

Example 29 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class PreviousRouteCard method updateContent.

@Override
protected void updateContent() {
    final TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
    TextView startTitle = view.findViewById(R.id.start_title);
    TextView destinationTitle = view.findViewById(R.id.destination_title);
    TargetPoint startPoint = targetPointsHelper.getPointToStartBackup();
    boolean myLocation = false;
    if (startPoint == null) {
        myLocation = true;
        startPoint = targetPointsHelper.getMyLocationToStart();
    }
    StringBuilder startText = new StringBuilder(myLocation ? mapActivity.getText(R.string.my_location) : "");
    if (startPoint != null) {
        String descr = getPointName(app, startPoint);
        if (!Algorithms.isEmpty(descr)) {
            if (startText.length() > 0) {
                startText.append(" — ");
            }
            startText.append(descr);
        }
    }
    startTitle.setText(startText.toString());
    TargetPoint destinationPoint = targetPointsHelper.getPointToNavigateBackup();
    String destinationName = "";
    destinationName = getPointName(app, destinationPoint);
    destinationTitle.setText(destinationName);
    View button = view.findViewById(R.id.card_button);
    button.setOnClickListener(v -> notifyButtonPressed(0));
}
Also used : TextView(android.widget.TextView) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) TextView(android.widget.TextView) View(android.view.View)

Example 30 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class MapControlsLayer method addDestination.

public void addDestination(@NonNull LatLon latLon, @Nullable PointDescription pointDescription) {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity != null && !OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
        requestedLatLon = latLon;
        ActivityCompat.requestPermissions(mapActivity, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION_FOR_ADD_DESTINATION_PERMISSION);
    } else {
        if (pointDescription == null) {
            pointDescription = getPointDescriptionForTarget(latLon, null);
        }
        if (mapActivity != null) {
            mapActivity.getContextMenu().close();
        }
        final TargetPointsHelper targets = app.getTargetPointsHelper();
        RoutingHelper routingHelper = app.getRoutingHelper();
        if (routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode()) {
            targets.navigateToPoint(latLon, true, targets.getIntermediatePoints().size() + 1, pointDescription);
        } else if (targets.getIntermediatePoints().isEmpty()) {
            startRoutePlanningWithDestination(latLon, pointDescription, targets);
        }
    }
}
Also used : RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

TargetPointsHelper (net.osmand.plus.helpers.TargetPointsHelper)42 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)24 LatLon (net.osmand.data.LatLon)22 OsmandApplication (net.osmand.plus.OsmandApplication)19 MapActivity (net.osmand.plus.activities.MapActivity)14 View (android.view.View)11 RoutingHelper (net.osmand.plus.routing.RoutingHelper)11 TextView (android.widget.TextView)10 PointDescription (net.osmand.data.PointDescription)9 ImageView (android.widget.ImageView)8 ArrayList (java.util.ArrayList)8 Location (net.osmand.Location)8 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)7 Bundle (android.os.Bundle)4 OnClickListener (android.view.View.OnClickListener)4 FavouritePoint (net.osmand.data.FavouritePoint)4 DialogInterface (android.content.DialogInterface)3 HorizontalScrollView (android.widget.HorizontalScrollView)3 ImageButton (android.widget.ImageButton)3 LinearLayout (android.widget.LinearLayout)3