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);
}
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();
}
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);
}
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);
}
});
}
Aggregations