Search in sources :

Example 11 with RouteInformation

use of com.mapbox.services.android.navigation.v5.navigation.camera.RouteInformation 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)

Aggregations

BaseTest (com.mapbox.services.android.navigation.ui.v5.BaseTest)9 RouteInformation (com.mapbox.services.android.navigation.v5.navigation.camera.RouteInformation)9 Test (org.junit.Test)9 Point (com.mapbox.geojson.Point)4 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)2 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)2 Camera (com.mapbox.services.android.navigation.v5.navigation.camera.Camera)2 MapboxMap (com.mapbox.mapboxsdk.maps.MapboxMap)1