Search in sources :

Example 16 with CameraPosition

use of com.mapbox.mapboxsdk.camera.CameraPosition in project mapbox-navigation-android by mapbox.

the class NavigationViewActivity method animateCameraBbox.

private void animateCameraBbox(LatLngBounds bounds, int animationTime, int[] padding) {
    CameraPosition position = mapboxMap.getCameraForLatLngBounds(bounds, padding);
    mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), animationTime);
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition)

Example 17 with CameraPosition

use of com.mapbox.mapboxsdk.camera.CameraPosition 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 18 with CameraPosition

use of com.mapbox.mapboxsdk.camera.CameraPosition 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 19 with CameraPosition

use of com.mapbox.mapboxsdk.camera.CameraPosition 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

CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)19 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)8 MapboxMap (com.mapbox.mapboxsdk.maps.MapboxMap)4 AnimatorSet (android.animation.AnimatorSet)3 Point (com.mapbox.geojson.Point)3 CameraUpdate (com.mapbox.mapboxsdk.camera.CameraUpdate)3 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)3 Camera (com.mapbox.services.android.navigation.v5.navigation.camera.Camera)2 ValueAnimator (android.animation.ValueAnimator)1 Intent (android.content.Intent)1 Handler (android.os.Handler)1 Parcel (android.os.Parcel)1 MotionEvent (android.view.MotionEvent)1 ScaleGestureDetector (android.view.ScaleGestureDetector)1 View (android.view.View)1 LocationEngine (com.mapbox.android.core.location.LocationEngine)1 LocationEngineProvider (com.mapbox.android.core.location.LocationEngineProvider)1 LegStep (com.mapbox.api.directions.v5.models.LegStep)1 Marker (com.mapbox.mapboxsdk.annotations.Marker)1 MapView (com.mapbox.mapboxsdk.maps.MapView)1