Search in sources :

Example 31 with TargetPointsHelper

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

the class OsmandAidlApi method startNavigation.

private void startNavigation(MapActivity mapActivity, GPXFile gpx, LatLon from, PointDescription fromDesc, LatLon to, PointDescription toDesc, ApplicationMode mode) {
    OsmandApplication app = mapActivity.getMyApplication();
    RoutingHelper routingHelper = app.getRoutingHelper();
    if (gpx == null) {
        app.getSettings().APPLICATION_MODE.set(mode);
        final TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper();
        targets.removeAllWayPoints(false, true);
        targets.navigateToPoint(to, true, -1, toDesc);
    }
    mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpx, from, fromDesc, true, false);
    if (!app.getTargetPointsHelper().checkPointToNavigateShort()) {
        mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().show();
    } else {
        if (app.getSettings().APPLICATION_MODE.get() != routingHelper.getAppMode()) {
            app.getSettings().APPLICATION_MODE.set(routingHelper.getAppMode());
        }
        mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
        app.getSettings().FOLLOW_THE_ROUTE.set(true);
        routingHelper.setFollowingMode(true);
        routingHelper.setRoutePlanningMode(false);
        mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
        app.getRoutingHelper().notifyIfRouteIsCalculated();
        routingHelper.setCurrentLocation(app.getLocationProvider().getLastKnownLocation(), false);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPointsHelper(net.osmand.plus.TargetPointsHelper)

Example 32 with TargetPointsHelper

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

the class RouteProvider method createOsmandRouterGPX.

public GPXFile createOsmandRouterGPX(RouteCalculationResult srcRoute, OsmandApplication ctx) {
    TargetPointsHelper helper = ctx.getTargetPointsHelper();
    int currentRoute = srcRoute.currentRoute;
    List<Location> routeNodes = srcRoute.getImmutableAllLocations();
    List<RouteDirectionInfo> directionInfo = srcRoute.getImmutableAllDirections();
    int currentDirectionInfo = srcRoute.currentDirectionInfo;
    GPXFile gpx = new GPXFile();
    gpx.author = OSMAND_ROUTER;
    Track track = new Track();
    gpx.tracks.add(track);
    TrkSegment trkSegment = new TrkSegment();
    track.segments.add(trkSegment);
    int cRoute = currentRoute;
    int cDirInfo = currentDirectionInfo;
    // Save the start point to gpx file's trkpt section unless already contained
    WptPt startpoint = new WptPt();
    TargetPoint sc = helper.getPointToStart();
    int routePointOffsetAdjusted = 0;
    if (sc != null && ((float) sc.getLatitude() != (float) routeNodes.get(cRoute).getLatitude() || (float) sc.getLongitude() != (float) routeNodes.get(cRoute).getLongitude())) {
        startpoint.lat = sc.getLatitude();
        startpoint.lon = sc.getLongitude();
        trkSegment.points.add(startpoint);
        if (directionInfo != null && !directionInfo.isEmpty()) {
            for (RouteDirectionInfo i : directionInfo) {
                i.routePointOffset++;
            }
        }
        routePointOffsetAdjusted = 1;
    }
    for (int i = cRoute; i < routeNodes.size(); i++) {
        Location loc = routeNodes.get(i);
        WptPt pt = new WptPt();
        pt.lat = loc.getLatitude();
        pt.lon = loc.getLongitude();
        if (loc.hasSpeed()) {
            pt.speed = loc.getSpeed();
        }
        if (loc.hasAltitude()) {
            pt.ele = loc.getAltitude();
        }
        if (loc.hasAccuracy()) {
            pt.hdop = loc.getAccuracy();
        }
        trkSegment.points.add(pt);
    }
    Route route = new Route();
    gpx.routes.add(route);
    for (int i = cDirInfo; i < directionInfo.size(); i++) {
        RouteDirectionInfo dirInfo = directionInfo.get(i);
        if (dirInfo.routePointOffset - routePointOffsetAdjusted >= cRoute) {
            if (dirInfo.getTurnType() != null && !dirInfo.getTurnType().isSkipToSpeak() && dirInfo.routePointOffset - routePointOffsetAdjusted < routeNodes.size()) {
                Location loc = routeNodes.get(dirInfo.routePointOffset - routePointOffsetAdjusted);
                WptPt pt = new WptPt();
                pt.lat = loc.getLatitude();
                pt.lon = loc.getLongitude();
                // Collect distances and times for subsequent suppressed turns
                int collectedDistance = 0;
                int collectedTime = 0;
                for (int j = i + 1; j < directionInfo.size(); j++) {
                    if (directionInfo.get(j).getTurnType() != null && directionInfo.get(j).getTurnType().isSkipToSpeak()) {
                        collectedDistance += directionInfo.get(j).getDistance();
                        collectedTime += directionInfo.get(j).getExpectedTime();
                    } else {
                        break;
                    }
                }
                pt.desc = dirInfo.getDescriptionRoute(ctx, collectedDistance + dirInfo.getDistance());
                Map<String, String> extensions = pt.getExtensionsToWrite();
                extensions.put("time", (collectedTime + dirInfo.getExpectedTime()) + "");
                int turnType = dirInfo.getTurnType().getValue();
                if (TurnType.C != turnType) {
                    extensions.put("turn", dirInfo.getTurnType().toXmlString());
                    extensions.put("turn-angle", dirInfo.getTurnType().getTurnAngle() + "");
                }
                extensions.put("offset", (dirInfo.routePointOffset - cRoute) + "");
                // Issue #2894
                if (dirInfo.getRef() != null && !"null".equals(dirInfo.getRef())) {
                    extensions.put("ref", dirInfo.getRef() + "");
                }
                if (dirInfo.getStreetName() != null && !"null".equals(dirInfo.getStreetName())) {
                    extensions.put("street-name", dirInfo.getStreetName() + "");
                }
                if (dirInfo.getDestinationName() != null && !"null".equals(dirInfo.getDestinationName())) {
                    extensions.put("dest", dirInfo.getDestinationName() + "");
                }
                route.points.add(pt);
            }
        }
    }
    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;
        }
        gpx.addPoint(pt);
    }
    return gpx;
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) Track(net.osmand.plus.GPXUtilities.Track) Route(net.osmand.plus.GPXUtilities.Route) Location(net.osmand.Location)

Example 33 with TargetPointsHelper

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

the class MapControlsLayer method addFirstIntermediate.

public void addFirstIntermediate(LatLon latLon) {
    if (latLon != null) {
        RoutingHelper routingHelper = mapActivity.getMyApplication().getRoutingHelper();
        if (routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode()) {
            PointDescription pointDescription = getPointDescriptionForTarget(latLon);
            mapActivity.getContextMenu().close();
            final TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper();
            if (routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode()) {
                targets.navigateToPoint(latLon, true, 0, pointDescription);
            } else if (targets.getIntermediatePoints().isEmpty()) {
                startRoutePlanningWithDestination(latLon, pointDescription, targets);
            }
        } else {
            addDestination(latLon);
        }
    }
}
Also used : PointDescription(net.osmand.data.PointDescription) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPointsHelper(net.osmand.plus.TargetPointsHelper)

Example 34 with TargetPointsHelper

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

the class MapControlsLayer method navigateButton.

public void navigateButton() {
    if (!OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
        ActivityCompat.requestPermissions(mapActivity, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION_FOR_NAVIGATION_FAB_PERMISSION);
    } else {
        final MapContextMenu menu = mapActivity.getContextMenu();
        final LatLon latLon = menu.getLatLon();
        final PointDescription pointDescription = menu.getPointDescriptionForTarget();
        menu.hide();
        final TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper();
        RoutingHelper routingHelper = mapActivity.getMyApplication().getRoutingHelper();
        if (routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode()) {
            DirectionsDialogs.addWaypointDialogAndLaunchMap(mapActivity, latLon.getLatitude(), latLon.getLongitude(), pointDescription);
        } else if (targets.getIntermediatePoints().isEmpty()) {
            startRoutePlanningWithDestination(latLon, pointDescription, targets);
            menu.close();
        } else {
            AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity);
            bld.setTitle(R.string.new_directions_point_dialog);
            final int[] defaultVls = new int[] { 0 };
            bld.setSingleChoiceItems(new String[] { mapActivity.getString(R.string.clear_intermediate_points), mapActivity.getString(R.string.keep_intermediate_points) }, 0, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    defaultVls[0] = which;
                }
            });
            bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (defaultVls[0] == 0) {
                        targets.removeAllWayPoints(false, true);
                        targets.navigateToPoint(latLon, true, -1, pointDescription);
                        mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true, true);
                        menu.close();
                    } else {
                        targets.navigateToPoint(latLon, true, -1, pointDescription);
                        mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true, true);
                        menu.close();
                    }
                }
            });
            bld.setNegativeButton(R.string.shared_string_cancel, null);
            bld.show();
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) LatLon(net.osmand.data.LatLon) DialogInterface(android.content.DialogInterface) PointDescription(net.osmand.data.PointDescription) OnClickListener(android.view.View.OnClickListener) MapContextMenu(net.osmand.plus.mapcontextmenu.MapContextMenu) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPointsHelper(net.osmand.plus.TargetPointsHelper)

Example 35 with TargetPointsHelper

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

the class PointNavigationLayer method onDraw.

@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
    if (tb.getZoom() < 3) {
        return;
    }
    TargetPointsHelper targetPoints = map.getMyApplication().getTargetPointsHelper();
    TargetPoint pointToStart = targetPoints.getPointToStart();
    if (pointToStart != null) {
        if (isLocationVisible(tb, pointToStart)) {
            int marginX = mStartPoint.getWidth() / 6;
            int marginY = mStartPoint.getHeight();
            float locationX = getPointX(tb, pointToStart);
            float locationY = getPointY(tb, pointToStart);
            canvas.rotate(-tb.getRotate(), locationX, locationY);
            canvas.drawBitmap(mStartPoint, locationX - marginX, locationY - marginY, mBitmapPaint);
            canvas.rotate(tb.getRotate(), locationX, locationY);
        }
    }
    int index = 0;
    for (TargetPoint ip : targetPoints.getIntermediatePoints()) {
        index++;
        if (isLocationVisible(tb, ip)) {
            int marginX = mIntermediatePoint.getWidth() / 6;
            int marginY = mIntermediatePoint.getHeight();
            float locationX = getPointX(tb, ip);
            float locationY = getPointY(tb, ip);
            canvas.rotate(-tb.getRotate(), locationX, locationY);
            canvas.drawBitmap(mIntermediatePoint, locationX - marginX, locationY - marginY, mBitmapPaint);
            marginX = mIntermediatePoint.getWidth() / 3;
            canvas.drawText(index + "", locationX + marginX, locationY - 3 * marginY / 5, mTextPaint);
            canvas.rotate(tb.getRotate(), locationX, locationY);
        }
    }
    TargetPoint pointToNavigate = targetPoints.getPointToNavigate();
    if (isLocationVisible(tb, pointToNavigate)) {
        int marginX = mTargetPoint.getWidth() / 6;
        int marginY = mTargetPoint.getHeight();
        float locationX = getPointX(tb, pointToNavigate);
        float locationY = getPointY(tb, pointToNavigate);
        canvas.rotate(-tb.getRotate(), locationX, locationY);
        canvas.drawBitmap(mTargetPoint, locationX - marginX, locationY - marginY, mBitmapPaint);
        canvas.rotate(tb.getRotate(), locationX, locationY);
    }
}
Also used : TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Paint(android.graphics.Paint)

Aggregations

TargetPointsHelper (net.osmand.plus.TargetPointsHelper)36 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)19 LatLon (net.osmand.data.LatLon)18 PointDescription (net.osmand.data.PointDescription)11 TextView (android.widget.TextView)8 OsmandApplication (net.osmand.plus.OsmandApplication)8 RoutingHelper (net.osmand.plus.routing.RoutingHelper)8 View (android.view.View)7 Location (net.osmand.Location)7 ImageView (android.widget.ImageView)5 DialogInterface (android.content.DialogInterface)4 AlertDialog (android.support.v7.app.AlertDialog)4 AdapterView (android.widget.AdapterView)4 ArrayList (java.util.ArrayList)4 ApplicationMode (net.osmand.plus.ApplicationMode)4 Paint (android.graphics.Paint)3 Bundle (android.os.Bundle)3 ImageButton (android.widget.ImageButton)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2