public class NavigationCamera
extends java.lang.Object
implements android.arch.lifecycle.LifecycleObserver
This class listens to the progress of MapboxNavigation
and moves
the MapboxMap
camera based on the location updates.
Modifier and Type | Class and Description |
---|---|
static interface |
NavigationCamera.TrackingMode |
Modifier and Type | Field and Description |
---|---|
static int |
NAVIGATION_TRACKING_MODE_GPS
Camera tracks the user location, with bearing provided by the location update.
|
static int |
NAVIGATION_TRACKING_MODE_NONE
Camera does not tack the user location.
|
static int |
NAVIGATION_TRACKING_MODE_NORTH
Camera tracks the user location, with bearing always set to north (0).
|
Constructor and Description |
---|
NavigationCamera(com.mapbox.mapboxsdk.maps.MapboxMap mapboxMap,
com.mapbox.mapboxsdk.location.LocationComponent locationComponent)
Creates an instance of
NavigationCamera . |
NavigationCamera(com.mapbox.mapboxsdk.maps.MapboxMap mapboxMap,
com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation navigation,
com.mapbox.mapboxsdk.location.LocationComponent locationComponent)
Creates an instance of
NavigationCamera . |
Modifier and Type | Method and Description |
---|---|
void |
addProgressChangeListener(com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation navigation)
This method can be called if you did not pass an instance of
MapboxNavigation
to the constructor. |
int |
getCameraTrackingMode()
Getter for
NavigationCamera.TrackingMode that's being used when tracking is enabled. |
boolean |
isTrackingEnabled()
Getter for current state of tracking.
|
void |
onStart()
Call in
FragmentActivity.onStart() to properly add the ProgressChangeListener
for the camera and prevent any leaks or further updates. |
void |
onStop()
Call in
FragmentActivity.onStop() to properly remove the ProgressChangeListener
for the camera and prevent any leaks or further updates. |
void |
resetCameraPositionWith(int trackingMode)
Resets the map camera / padding to the last known camera position.
|
void |
resume(android.location.Location location)
Called during rotation to update route information.
|
void |
showRouteOverview(int[] padding)
This method stops the map camera from tracking the current location, and then zooms
out to an overview of the current route being traveled.
|
void |
start(com.mapbox.api.directions.v5.models.DirectionsRoute route)
Called when beginning navigation with a route.
|
void |
updateCameraTrackingMode(int trackingMode)
Updates the
NavigationCamera.TrackingMode that's going to be used when camera tracking is enabled. |
public static final int NAVIGATION_TRACKING_MODE_GPS
Equivalent of the CameraMode.TRACKING_GPS
.
public static final int NAVIGATION_TRACKING_MODE_NORTH
Equivalent of the CameraMode.TRACKING_GPS_NORTH
.
public static final int NAVIGATION_TRACKING_MODE_NONE
Equivalent of the CameraMode.NONE
.
public NavigationCamera(@NonNull com.mapbox.mapboxsdk.maps.MapboxMap mapboxMap, @NonNull com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation navigation, @NonNull com.mapbox.mapboxsdk.location.LocationComponent locationComponent)
NavigationCamera
.mapboxMap
- for moving the cameranavigation
- for listening to location updateslocationComponent
- for managing camera modepublic NavigationCamera(@NonNull com.mapbox.mapboxsdk.maps.MapboxMap mapboxMap, com.mapbox.mapboxsdk.location.LocationComponent locationComponent)
NavigationCamera
.
Camera will start tracking current user location by default.
mapboxMap
- for moving the cameralocationComponent
- for managing camera modepublic void start(com.mapbox.api.directions.v5.models.DirectionsRoute route)
route
- used to update route informationpublic void resume(android.location.Location location)
location
- used to update route informationpublic void updateCameraTrackingMode(int trackingMode)
NavigationCamera.TrackingMode
that's going to be used when camera tracking is enabled.trackingMode
- the tracking modepublic boolean isTrackingEnabled()
public int getCameraTrackingMode()
NavigationCamera.TrackingMode
that's being used when tracking is enabled.public void resetCameraPositionWith(int trackingMode)
You can also specify a tracking mode to reset with. For example if you would like
to reset the camera and continue tracking, you would use NAVIGATION_TRACKING_MODE_GPS
.
trackingMode
- the tracking modepublic void showRouteOverview(int[] padding)
padding
- in pixels around the bounding box of the overview (left, top, right, bottom)public void onStart()
FragmentActivity.onStart()
to properly add the ProgressChangeListener
for the camera and prevent any leaks or further updates.public void onStop()
FragmentActivity.onStop()
to properly remove the ProgressChangeListener
for the camera and prevent any leaks or further updates.public void addProgressChangeListener(com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation navigation)
MapboxNavigation
to the constructor.
The camera will begin listening to progress updates and update the route accordingly.
navigation
- to add the camera progress change listener