Search in sources :

Example 6 with TargetPointsHelper

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

the class DirectionsDialogs method addWaypointDialogAndLaunchMap.

public static void addWaypointDialogAndLaunchMap(final AppCompatActivity act, final double lat, final double lon, final PointDescription name) {
    final TargetPointsHelper targetPointsHelper = ((OsmandApplication) act.getApplication()).getTargetPointsHelper();
    if (targetPointsHelper.getPointToNavigate() != null) {
        Bundle args = new Bundle();
        args.putDouble(AddWaypointBottomSheetDialogFragment.LAT_KEY, lat);
        args.putDouble(AddWaypointBottomSheetDialogFragment.LON_KEY, lon);
        args.putString(AddWaypointBottomSheetDialogFragment.POINT_DESCRIPTION_KEY, PointDescription.serializeToString(name));
        AddWaypointBottomSheetDialogFragment fragment = new AddWaypointBottomSheetDialogFragment();
        fragment.setArguments(args);
        fragment.show(act.getSupportFragmentManager(), AddWaypointBottomSheetDialogFragment.TAG);
    } else {
        targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
        closeContextMenu(act);
        MapActivity.launchMapActivityMoveToTop(act);
    }
}
Also used : LatLon(net.osmand.data.LatLon) OsmandApplication(net.osmand.plus.OsmandApplication) Bundle(android.os.Bundle) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper)

Example 7 with TargetPointsHelper

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

the class MapActions method recalculateRoute.

public void recalculateRoute(boolean showDialog) {
    settings.USE_INTERMEDIATE_POINTS_NAVIGATION.set(true);
    TargetPointsHelper targets = app.getTargetPointsHelper();
    ApplicationMode mode = getRouteMode();
    // app.getSettings().setApplicationMode(mode, false);
    app.getRoutingHelper().setAppMode(mode);
    // Test for #2810: No need to init player here?
    // app.initVoiceCommandPlayer(mapActivity, true, null, false, false);
    // save application mode controls
    settings.FOLLOW_THE_ROUTE.set(false);
    app.getRoutingHelper().setFollowingMode(false);
    app.getRoutingHelper().setRoutePlanningMode(true);
    // reset start point
    targets.setStartPoint(null, false, null);
    // then update start and destination point
    targets.updateRouteAndRefresh(true);
    app.getMapViewTrackingUtilities().switchToRoutePlanningMode();
    app.getOsmandMap().refreshMap(true);
    if (targets.hasTooLongDistanceToNavigate()) {
        app.showToastMessage(R.string.route_is_too_long_v2);
    }
}
Also used : ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper)

Example 8 with TargetPointsHelper

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

the class MapActions method enterRoutePlanningModeGivenGpx.

public void enterRoutePlanningModeGivenGpx(GPXFile gpxFile, ApplicationMode appMode, LatLon from, PointDescription fromName, boolean useIntermediatePointsByDefault, boolean showMenu, int menuState) {
    settings.USE_INTERMEDIATE_POINTS_NAVIGATION.set(useIntermediatePointsByDefault);
    TargetPointsHelper targets = app.getTargetPointsHelper();
    ApplicationMode mode = appMode != null ? appMode : getRouteMode();
    app.getSettings().setApplicationMode(mode, false);
    app.getRoutingHelper().setAppMode(mode);
    initVoiceCommandPlayer(mode, showMenu);
    // save application mode controls
    settings.FOLLOW_THE_ROUTE.set(false);
    app.getRoutingHelper().setFollowingMode(false);
    app.getRoutingHelper().setRoutePlanningMode(true);
    // reset start point
    targets.setStartPoint(from, false, fromName);
    // then set gpx
    setGPXRouteParams(gpxFile);
    // then update start and destination point
    targets.updateRouteAndRefresh(true);
    app.getMapViewTrackingUtilities().switchToRoutePlanningMode();
    app.getOsmandMap().refreshMap(true);
    if (targets.hasTooLongDistanceToNavigate()) {
        app.showToastMessage(R.string.route_is_too_long_v2);
    }
}
Also used : ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper)

Example 9 with TargetPointsHelper

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

the class RoutingHelper method updateCurrentRouteStatus.

private boolean updateCurrentRouteStatus(Location currentLocation, double posTolerance) {
    List<Location> routeNodes = route.getImmutableAllLocations();
    int currentRoute = route.currentRoute;
    // 1. Try to proceed to next point using orthogonal distance (finding minimum orthogonal dist)
    while (currentRoute + 1 < routeNodes.size()) {
        double dist = currentLocation.distanceTo(routeNodes.get(currentRoute));
        if (currentRoute > 0) {
            dist = RoutingHelperUtils.getOrthogonalDistance(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
        }
        boolean processed = false;
        // if we are still too far try to proceed many points
        // if not then look ahead only 3 in order to catch sharp turns
        boolean longDistance = dist >= 250;
        int newCurrentRoute = RoutingHelperUtils.lookAheadFindMinOrthogonalDistance(currentLocation, routeNodes, currentRoute, longDistance ? 15 : 8);
        double newDist = RoutingHelperUtils.getOrthogonalDistance(currentLocation, routeNodes.get(newCurrentRoute), routeNodes.get(newCurrentRoute + 1));
        if (longDistance) {
            if (newDist < dist) {
                if (log.isDebugEnabled()) {
                    // $NON-NLS-1$//$NON-NLS-2$
                    log.debug("Processed by distance : (new) " + newDist + " (old) " + dist);
                }
                processed = true;
            }
        } else if (newDist < dist || newDist < posTolerance / 8) {
            // newDist < posTolerance / 8 - 4-8 m (avoid distance 0 till next turn)
            if (dist > posTolerance) {
                processed = true;
                if (log.isDebugEnabled()) {
                    // $NON-NLS-1$//$NON-NLS-2$
                    log.debug("Processed by distance : " + newDist + " " + dist);
                }
            } else {
                // but you have not yet turned (could be checked bearing)
                if (currentLocation.hasBearing() || lastFixedLocation != null) {
                    float bearingToRoute = currentLocation.bearingTo(routeNodes.get(currentRoute));
                    float bearingRouteNext = routeNodes.get(newCurrentRoute).bearingTo(routeNodes.get(newCurrentRoute + 1));
                    float bearingMotion = currentLocation.hasBearing() ? currentLocation.getBearing() : lastFixedLocation.bearingTo(currentLocation);
                    double diff = Math.abs(MapUtils.degreesDiff(bearingMotion, bearingToRoute));
                    double diffToNext = Math.abs(MapUtils.degreesDiff(bearingMotion, bearingRouteNext));
                    if (diff > diffToNext) {
                        if (log.isDebugEnabled()) {
                            log.debug("Processed point bearing deltas : " + diff + " " + diffToNext);
                        }
                        processed = true;
                    }
                }
            }
        }
        if (processed) {
            // that node already passed
            route.updateCurrentRoute(newCurrentRoute + 1);
            currentRoute = newCurrentRoute + 1;
            app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION);
            fireRoutingDataUpdateEvent();
        } else {
            break;
        }
    }
    // 2. check if intermediate found
    if (route.getIntermediatePointsToPass() > 0 && route.getDistanceToNextIntermediate(lastFixedLocation) < voiceRouter.getArrivalDistance() && !isRoutePlanningMode) {
        showMessage(app.getString(R.string.arrived_at_intermediate_point));
        route.passIntermediatePoint();
        TargetPointsHelper targets = app.getTargetPointsHelper();
        String name = "";
        if (intermediatePoints != null && !intermediatePoints.isEmpty()) {
            LatLon rm = intermediatePoints.remove(0);
            List<TargetPoint> ll = targets.getIntermediatePointsNavigation();
            int ind = -1;
            for (int i = 0; i < ll.size(); i++) {
                if (ll.get(i).point != null && MapUtils.getDistance(ll.get(i).point, rm) < 5) {
                    name = ll.get(i).getOnlyName();
                    ind = i;
                    break;
                }
            }
            if (ind >= 0) {
                targets.removeWayPoint(false, ind);
            }
        }
        if (isFollowingMode) {
            voiceRouter.arrivedIntermediatePoint(name);
        }
        // double check
        while (intermediatePoints != null && route.getIntermediatePointsToPass() < intermediatePoints.size()) {
            intermediatePoints.remove(0);
        }
    }
    // 3. check if destination found
    Location lastPoint = routeNodes.get(routeNodes.size() - 1);
    if (currentRoute > routeNodes.size() - 3 && currentLocation.distanceTo(lastPoint) < voiceRouter.getArrivalDistance() && !isRoutePlanningMode) {
        // showMessage(app.getString(R.string.arrived_at_destination));
        TargetPointsHelper targets = app.getTargetPointsHelper();
        TargetPoint tp = targets.getPointToNavigate();
        String description = tp == null ? "" : tp.getOnlyName();
        if (isFollowingMode) {
            voiceRouter.arrivedDestinationPoint(description);
        }
        boolean onDestinationReached = true;
        if (onDestinationReached) {
            clearCurrentRoute(null, null);
            setRoutePlanningMode(false);
            app.runInUIThread(new Runnable() {

                @Override
                public void run() {
                    settings.LAST_ROUTING_APPLICATION_MODE = settings.APPLICATION_MODE.get();
                // settings.setApplicationMode(settings.DEFAULT_APPLICATION_MODE.get());
                }
            });
            finishCurrentRoute();
            // targets.clearPointToNavigate(false);
            return true;
        }
    }
    // 4. update angle point
    if (route.getRouteVisibleAngle() > 0) {
        // proceed to the next point with min acceptable bearing
        double ANGLE_TO_DECLINE = route.getRouteVisibleAngle();
        int nextPoint = route.currentRoute;
        for (; nextPoint < routeNodes.size() - 1; nextPoint++) {
            float bearingTo = currentLocation.bearingTo(routeNodes.get(nextPoint));
            float bearingTo2 = routeNodes.get(nextPoint).bearingTo(routeNodes.get(nextPoint + 1));
            if (Math.abs(MapUtils.degreesDiff(bearingTo2, bearingTo)) <= ANGLE_TO_DECLINE) {
                break;
            }
        }
        if (nextPoint > 0) {
            Location next = routeNodes.get(nextPoint);
            Location prev = routeNodes.get(nextPoint - 1);
            float bearing = prev.bearingTo(next);
            double bearingTo = Math.abs(MapUtils.degreesDiff(bearing, currentLocation.bearingTo(next)));
            double bearingPrev = Math.abs(MapUtils.degreesDiff(bearing, currentLocation.bearingTo(prev)));
            while (true) {
                Location mp = MapUtils.calculateMidPoint(prev, next);
                if (mp.distanceTo(next) <= 100) {
                    break;
                }
                double bearingMid = Math.abs(MapUtils.degreesDiff(bearing, currentLocation.bearingTo(mp)));
                if (bearingPrev < ANGLE_TO_DECLINE) {
                    next = mp;
                    bearingTo = bearingMid;
                } else if (bearingTo < ANGLE_TO_DECLINE) {
                    prev = mp;
                    bearingPrev = bearingMid;
                } else {
                    break;
                }
            }
            route.updateNextVisiblePoint(nextPoint, next);
        }
    }
    // 5. Update car navigation
    NavigationSession carNavigationSession = app.getCarNavigationSession();
    NavigationService navigationService = app.getNavigationService();
    if (carNavigationSession != null && navigationService != null && System.currentTimeMillis() - lastCarNavUpdateTime > 1000) {
        lastCarNavUpdateTime = System.currentTimeMillis();
        app.runInUIThread(navigationService::updateCarNavigation);
    }
    return false;
}
Also used : TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) GpxPoint(net.osmand.router.RoutePlannerFrontEnd.GpxPoint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) NavigationService(net.osmand.plus.NavigationService) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) NavigationSession(net.osmand.plus.auto.NavigationSession) Location(net.osmand.Location)

Example 10 with TargetPointsHelper

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

the class NavigationHistorySettingsFragment method updateHistoryItems.

@Override
protected void updateHistoryItems() {
    clearItems();
    List<SearchResult> searchResults = getNavigationHistoryResults(app);
    sortSearchResults(searchResults);
    TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
    TargetPoint startBackup = targetPointsHelper.getPointToStartBackup();
    if (startBackup == null) {
        startBackup = targetPointsHelper.getMyLocationToStart();
    }
    TargetPoint destinationBackup = targetPointsHelper.getPointToNavigateBackup();
    if (startBackup != null && destinationBackup != null) {
        items.add(PREVIOUS_ROUTE_HEADER);
        items.add(destinationBackup);
        itemsGroups.put(PREVIOUS_ROUTE_HEADER, new ArrayList<>(Collections.singleton(destinationBackup)));
    }
    Map<Integer, List<SearchResult>> historyGroups = new HashMap<>();
    List<Pair<Long, SearchResult>> pairs = createHistoryPairsByDate(searchResults);
    HistoryAdapter.createHistoryGroups(pairs, historyGroups, items);
    for (Map.Entry<Integer, List<SearchResult>> entry : historyGroups.entrySet()) {
        itemsGroups.put(entry.getKey(), new ArrayList<>(entry.getValue()));
    }
}
Also used : HashMap(java.util.HashMap) SearchResult(net.osmand.search.core.SearchResult) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) ArrayList(java.util.ArrayList) List(java.util.List) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) HashMap(java.util.HashMap) Map(java.util.Map) Pair(android.util.Pair)

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