Search in sources :

Example 66 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class NavigationViewActivity method boundCameraToRoute.

public void boundCameraToRoute() {
    if (route != null) {
        List<Point> routeCoords = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6).coordinates();
        List<LatLng> bboxPoints = new ArrayList<>();
        for (Point point : routeCoords) {
            bboxPoints.add(new LatLng(point.latitude(), point.longitude()));
        }
        if (bboxPoints.size() > 1) {
            try {
                LatLngBounds bounds = new LatLngBounds.Builder().includes(bboxPoints).build();
                // left, top, right, bottom
                int topPadding = launchBtnFrame.getHeight() * 2;
                animateCameraBbox(bounds, CAMERA_ANIMATION_DURATION, new int[] { 50, topPadding, 50, 100 });
            } catch (InvalidLatLngBoundsException exception) {
                Toast.makeText(this, R.string.error_valid_route_not_found, Toast.LENGTH_SHORT).show();
            }
        }
    }
}
Also used : InvalidLatLngBoundsException(com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException) ArrayList(java.util.ArrayList) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) Point(com.mapbox.geojson.Point) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Point(com.mapbox.geojson.Point)

Example 67 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class DynamicCamera method createCameraPosition.

/**
 * Creates a camera position with the current location and upcoming maneuver location.
 * <p>
 * Using {@link MapboxMap#getCameraForLatLngBounds(LatLngBounds, int[])} with a {@link LatLngBounds}
 * that includes the current location and upcoming maneuver location.
 *
 * @param location      for current location
 * @param routeProgress for upcoming maneuver location
 * @return camera position that encompasses both locations
 */
private CameraPosition createCameraPosition(Location location, RouteProgress routeProgress) {
    LegStep upComingStep = routeProgress.currentLegProgress().upComingStep();
    if (upComingStep != null) {
        Point stepManeuverPoint = upComingStep.maneuver().location();
        List<LatLng> latLngs = new ArrayList<>();
        LatLng currentLatLng = new LatLng(location);
        LatLng maneuverLatLng = new LatLng(stepManeuverPoint.latitude(), stepManeuverPoint.longitude());
        latLngs.add(currentLatLng);
        latLngs.add(maneuverLatLng);
        if (latLngs.size() < 1 || currentLatLng.equals(maneuverLatLng)) {
            return mapboxMap.getCameraPosition();
        }
        LatLngBounds cameraBounds = new LatLngBounds.Builder().includes(latLngs).build();
        int[] padding = { 0, 0, 0, 0 };
        CameraPosition positionForLatLngBounds = mapboxMap.getCameraForLatLngBounds(cameraBounds, padding);
        if (positionForLatLngBounds != null) {
            return positionForLatLngBounds;
        }
    }
    return mapboxMap.getCameraPosition();
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) ArrayList(java.util.ArrayList) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) Point(com.mapbox.geojson.Point) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) LegStep(com.mapbox.api.directions.v5.models.LegStep)

Example 68 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class NavigationCamera method animateCameraFromLocation.

/**
 * Creates an animation with the given {@link RouteInformation#location()}.
 * <p>
 * This animation that fires for new progress update.
 *
 * @param routeInformation with location data
 */
private void animateCameraFromLocation(RouteInformation routeInformation) {
    Camera cameraEngine = navigation.getCameraEngine();
    Point targetPoint = cameraEngine.target(routeInformation);
    LatLng target = new LatLng(targetPoint.latitude(), targetPoint.longitude());
    double bearing = cameraEngine.bearing(routeInformation);
    float tilt = (float) cameraEngine.tilt(routeInformation);
    double zoom = cameraEngine.zoom(routeInformation);
    CameraPosition position = new CameraPosition.Builder().target(target).bearing(bearing).tilt(tilt).zoom(zoom).build();
    easeMapCameraPosition(position);
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) Camera(com.mapbox.services.android.navigation.v5.navigation.camera.Camera) Point(com.mapbox.geojson.Point) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 69 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class NavigationCamera method animateCameraFromRoute.

/**
 * Creates an initial animation with the given {@link RouteInformation#route()}.
 * <p>
 * This is the first animation that fires prior to receiving progress updates.
 * <p>
 * If a user interacts with the {@link MapboxMap} while the animation is in progress,
 * the animation will be cancelled.  So it's important to add the {@link ProgressChangeListener}
 * in both onCancel() and onFinish() scenarios.
 *
 * @param routeInformation with route data
 */
private void animateCameraFromRoute(RouteInformation routeInformation) {
    Camera cameraEngine = navigation.getCameraEngine();
    Point targetPoint = cameraEngine.target(routeInformation);
    LatLng targetLatLng = new LatLng(targetPoint.latitude(), targetPoint.longitude());
    double bearing = cameraEngine.bearing(routeInformation);
    double zoom = cameraEngine.zoom(routeInformation);
    CameraPosition position = new CameraPosition.Builder().target(targetLatLng).bearing(bearing).zoom(zoom).build();
    updateMapCameraPosition(position, new MapboxMap.CancelableCallback() {

        @Override
        public void onCancel() {
            navigation.addProgressChangeListener(progressChangeListener);
        }

        @Override
        public void onFinish() {
            navigation.addProgressChangeListener(progressChangeListener);
        }
    });
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) Camera(com.mapbox.services.android.navigation.v5.navigation.camera.Camera) Point(com.mapbox.geojson.Point) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap)

Example 70 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class NavigationLauncher method extractCoordinates.

/**
 * Used to extract the origin and position coordinates used to launch
 * the drop-in UI.
 * <p>
 * A {@link HashMap} is used to ensure the correct coordinate is
 * extracted in the {@link NavigationView} with the defined constants.
 *
 * @param context to retrieve {@link SharedPreferences}
 * @return map with both origin and destination coordinates
 */
static HashMap<String, Point> extractCoordinates(Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    double originLng = Double.longBitsToDouble(preferences.getLong(NavigationConstants.NAVIGATION_VIEW_ORIGIN_LNG_KEY, 0));
    double originLat = Double.longBitsToDouble(preferences.getLong(NavigationConstants.NAVIGATION_VIEW_ORIGIN_LAT_KEY, 0));
    double destinationLng = Double.longBitsToDouble(preferences.getLong(NavigationConstants.NAVIGATION_VIEW_DESTINATION_LNG_KEY, 0));
    double destinationLat = Double.longBitsToDouble(preferences.getLong(NavigationConstants.NAVIGATION_VIEW_DESTINATION_LAT_KEY, 0));
    Point origin = Point.fromLngLat(originLng, originLat);
    Point destination = Point.fromLngLat(destinationLng, destinationLat);
    HashMap<String, Point> coordinates = new HashMap<>();
    coordinates.put(NavigationConstants.NAVIGATION_VIEW_ORIGIN, origin);
    coordinates.put(NavigationConstants.NAVIGATION_VIEW_DESTINATION, destination);
    return coordinates;
}
Also used : SharedPreferences(android.content.SharedPreferences) HashMap(java.util.HashMap) Point(com.mapbox.geojson.Point)

Aggregations

Point (com.mapbox.geojson.Point)72 Test (org.junit.Test)31 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)29 Location (android.location.Location)18 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)17 LineString (com.mapbox.geojson.LineString)15 ArrayList (java.util.ArrayList)10 LegStep (com.mapbox.api.directions.v5.models.LegStep)9 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)7 Feature (com.mapbox.geojson.Feature)4 NavigationRoute (com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)4 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)3 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)3 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)3 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 RouteOptions (com.mapbox.api.directions.v5.models.RouteOptions)2 MarkerOptions (com.mapbox.mapboxsdk.annotations.MarkerOptions)2 BaseTest (com.mapbox.services.android.navigation.ui.v5.BaseTest)2