Search in sources :

Example 11 with MapboxMap

use of com.mapbox.mapboxsdk.maps.MapboxMap 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

MapboxMap (com.mapbox.mapboxsdk.maps.MapboxMap)11 OnMapReadyCallback (com.mapbox.mapboxsdk.maps.OnMapReadyCallback)7 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)6 NonNull (android.support.annotation.NonNull)4 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)4 MultiLocationEngine (cl.smartcities.isci.transportinspector.map.engine.MultiLocationEngine)3 Marker (com.mapbox.mapboxsdk.annotations.Marker)3 UserPlugin (cl.smartcities.isci.transportinspector.map.plugin.userPlugin.UserPlugin)2 MapView (com.mapbox.mapboxsdk.maps.MapView)2 ValueAnimator (android.animation.ValueAnimator)1 Location (android.location.Location)1 Handler (android.os.Handler)1 MotionEvent (android.view.MotionEvent)1 ScaleGestureDetector (android.view.ScaleGestureDetector)1 View (android.view.View)1 OnBusEngine (cl.smartcities.isci.transportinspector.map.engine.OnBusEngine)1 BusStopPlugin (cl.smartcities.isci.transportinspector.map.plugin.busStopPlugin.BusStopPlugin)1 RouterPlugin (cl.smartcities.isci.transportinspector.map.plugin.routerPlugin.RouterPlugin)1 SearchPlugin (cl.smartcities.isci.transportinspector.map.plugin.searchPlugin.SearchPlugin)1 BusUserPlugin (cl.smartcities.isci.transportinspector.map.plugin.userPlugin.BusUserPlugin)1