public class NavigationMapboxMap
extends java.lang.Object
MapboxMap
.
This class initializes various map-related components and plugins that are useful for providing a navigation-driven map experience.
These APIs include drawing a route line, camera animations, and more.
Constructor and Description |
---|
NavigationMapboxMap(com.mapbox.mapboxsdk.maps.MapView mapView,
com.mapbox.mapboxsdk.maps.MapboxMap mapboxMap)
Constructor that can be used once
OnMapReadyCallback
has been called via MapView.getMapAsync(OnMapReadyCallback) . |
Modifier and Type | Method and Description |
---|---|
void |
addMarker(android.content.Context context,
com.mapbox.geojson.Point position)
Adds a marker icon on the map at the given position.
|
void |
addOnCameraTrackingChangedListener(com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener listener)
Add a
OnCameraTrackingChangedListener to the LocationComponent that is
wrapped within this class. |
boolean |
addOnWayNameChangedListener(OnWayNameChangedListener listener)
Add a
OnWayNameChangedListener for listening to updates
to the way name shown on the map below the location icon. |
void |
addProgressChangeListener(com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation navigation)
Can be used to automatically drive the map camera / route updates and arrow
once navigation has started.
|
void |
adjustLocationIconWith(int[] customPadding)
Use this method to position the location icon on the map.
|
void |
clearMarkers()
Clears all markers on the map that have been added by this class.
|
void |
drawRoute(com.mapbox.api.directions.v5.models.DirectionsRoute route)
Will draw the given
DirectionsRoute on the map using the colors defined
in your given style. |
void |
drawRoutes(java.util.List<com.mapbox.api.directions.v5.models.DirectionsRoute> routes)
Will draw the given list of
DirectionsRoute on the map using the colors defined
in your given style. |
boolean |
isIncidentsVisible()
Returns true if the map has incidents layers and they are visible and
will return false otherwise.
|
boolean |
isTrafficVisible()
Returns true if the map has traffic layers and they are visible and
will return false otherwise.
|
void |
onStart()
Should be used in
FragmentActivity.onStart() to ensure proper
accounting for the lifecycle. |
void |
onStop()
Should be used in
FragmentActivity.onStop() to ensure proper
accounting for the lifecycle. |
void |
removeOnCameraTrackingChangedListener(com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener listener)
Remove a
OnCameraTrackingChangedListener from the LocationComponent that is
wrapped within this class. |
boolean |
removeOnWayNameChangedListener(OnWayNameChangedListener listener)
Remove a
OnWayNameChangedListener for listening to updates
to the way name shown on the map below the location icon. |
void |
removeRoute()
Will remove the drawn route displayed on the map.
|
void |
resetCameraPositionWith(int trackingCameraMode)
Resets the map camera / padding to the last known camera position.
|
void |
resetPadding()
This method resets the map padding to the default padding that is
generated when navigation begins (location icon moved to lower half of the screen) or
the custom padding that was last passed via
MapPaddingAdjustor.adjustLocationIconWith(int[]) . |
void |
restoreFrom(NavigationMapboxMapInstanceState instanceState)
Can be used to restore a
NavigationMapboxMap after it has been initialized. |
void |
resumeCamera(android.location.Location location)
Centers the map camera around the provided
Location . |
NavigationCamera |
retrieveCamera()
Provides the camera being used to animate the map camera positions
along the route, driven by the progress change listener.
|
com.mapbox.mapboxsdk.maps.MapboxMap |
retrieveMap()
Provides the
MapboxMap originally given in the constructor. |
void |
saveStateWith(java.lang.String key,
android.os.Bundle outState)
Can be used to store the current state of the map in
Activity.onSaveInstanceState(Bundle, PersistableBundle) . |
void |
setOnRouteSelectionChangeListener(OnRouteSelectionChangeListener listener)
Set a
OnRouteSelectionChangeListener to know which route the user has currently
selected as their primary route. |
void |
showAlternativeRoutes(boolean alternativesVisible)
Toggle whether or not you'd like the map to display the alternative routes.
|
void |
showRouteOverview(int[] padding)
Adjusts the map camera to
DirectionsRoute being traveled along. |
void |
startCamera(com.mapbox.api.directions.v5.models.DirectionsRoute directionsRoute)
Centers the map camera to the beginning of the provided
DirectionsRoute . |
void |
takeScreenshot(NavigationSnapshotReadyCallback navigationSnapshotReadyCallback) |
void |
updateCameraTrackingMode(int trackingMode)
Updates the
NavigationCamera.TrackingMode that will be used when camera tracking is enabled. |
void |
updateIncidentsVisibility(boolean isVisible)
Updates the visibility of incidents layers on the map (if any exist).
|
void |
updateLocation(android.location.Location location)
Updates the location icon on the map and way name data (if found)
for the given
Location . |
void |
updateLocationLayerRenderMode(int renderMode)
Updates how the user location is shown on the map.
|
void |
updateLocationVisibilityTo(boolean isVisible)
Hide or show the location icon on the map.
|
void |
updateMapFpsThrottle(int maxFpsThreshold)
The maximum preferred frames per second at which to render the map.
|
void |
updateMapFpsThrottleEnabled(boolean isEnabled)
Enabled by default, the navigation map will throttle frames per second when the application has
limited resources, such as when the device is running on battery power.
|
void |
updateTrafficVisibility(boolean isVisible)
Updates the visibility of traffic layers on the map (if any exist).
|
void |
updateWaynameQueryMap(boolean isEnabled)
Enables or disables the way name chip underneath the location icon.
|
public NavigationMapboxMap(@NonNull com.mapbox.mapboxsdk.maps.MapView mapView, @NonNull com.mapbox.mapboxsdk.maps.MapboxMap mapboxMap)
OnMapReadyCallback
has been called via MapView.getMapAsync(OnMapReadyCallback)
.mapView
- for map size and ContextmapboxMap
- for APIs to interact with the mappublic void addMarker(android.content.Context context, com.mapbox.geojson.Point position)
The icon used for this method can be defined in your theme with the attribute navigationViewDestinationMarker.
context
- to retrieve the icon drawable from the themeposition
- the point at which the marker will be placedpublic void clearMarkers()
This will not clear all markers from the map entirely. Does nothing if no markers have been added.
public void updateLocation(android.location.Location location)
Location
.location
- to update the icon and query the mappublic void updateMapFpsThrottle(int maxFpsThreshold)
This property only takes effect when the application has limited resources, such as when the device is running on battery power. By default, this is set to 20fps.
Throttling will also only take effect when the camera is currently tracking the user location.
maxFpsThreshold
- to be used to limit map frames per secondpublic void updateMapFpsThrottleEnabled(boolean isEnabled)
Throttling will also only take effect when the camera is currently tracking the user location.
isEnabled
- true to enable (default), false to render at device abilitypublic void updateLocationLayerRenderMode(int renderMode)
RenderMode.NORMAL
: Shows user location, bearing ignoredRenderMode.COMPASS
: Shows user location with bearing considered from compassRenderMode.GPS
: Shows user location with bearing considered from locationrenderMode
- GPS, NORMAL, or COMPASSpublic void addProgressChangeListener(com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation navigation)
These will automatically be removed in MapboxNavigation.onDestroy()
.
navigation
- to add the progress listenerspublic void saveStateWith(java.lang.String key, android.os.Bundle outState)
Activity.onSaveInstanceState(Bundle, PersistableBundle)
.
This method uses NavigationMapboxMapInstanceState
, stored with the provided key. This key
can also later be used to extract the NavigationMapboxMapInstanceState
.
key
- used to store the stateoutState
- to store state variablespublic void restoreFrom(NavigationMapboxMapInstanceState instanceState)
NavigationMapboxMap
after it has been initialized.
This cannot be called in Activity.onRestoreInstanceState(Bundle)
because we cannot guarantee the map is re-initialized at that point.
You can extract the NavigationMapboxMapInstanceState
in onRestoreInstanceState and then
restore the map once it's ready.
instanceState
- to extract state variablespublic void drawRoute(@NonNull com.mapbox.api.directions.v5.models.DirectionsRoute route)
DirectionsRoute
on the map using the colors defined
in your given style.route
- to be drawnpublic void drawRoutes(@NonNull java.util.List<com.mapbox.api.directions.v5.models.DirectionsRoute> routes)
DirectionsRoute
on the map using the colors defined
in your given style.
The primary route will default to the first route in the directions route list. All other routes in the list will be drawn on the map using the alternative route style.
routes
- to be drawnpublic void setOnRouteSelectionChangeListener(@NonNull OnRouteSelectionChangeListener listener)
OnRouteSelectionChangeListener
to know which route the user has currently
selected as their primary route.listener
- a listener which lets you know when the user has changed
the primary route and provides the current direction
route which the user has selectedpublic void showAlternativeRoutes(boolean alternativesVisible)
alternativesVisible
- true if you'd like alternative routes to be displayed on the map,
else falsepublic void removeRoute()
public NavigationCamera retrieveCamera()
public void updateCameraTrackingMode(int trackingMode)
NavigationCamera.TrackingMode
that will be used when camera tracking is enabled.trackingMode
- the tracking modepublic void startCamera(@NonNull com.mapbox.api.directions.v5.models.DirectionsRoute directionsRoute)
DirectionsRoute
.directionsRoute
- to update the camera positionpublic void resumeCamera(@NonNull android.location.Location location)
Location
.location
- to update the camera positionpublic void resetCameraPositionWith(int trackingCameraMode)
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 NavigationCamera.NAVIGATION_TRACKING_MODE_GPS
.
trackingCameraMode
- the tracking modepublic void resetPadding()
MapPaddingAdjustor.adjustLocationIconWith(int[])
.
The custom padding will be used if it exists, otherwise the default will be used.
public void showRouteOverview(int[] padding)
DirectionsRoute
being traveled along.
Also includes the given padding.
padding
- for creating the overview camera positionpublic void updateWaynameQueryMap(boolean isEnabled)
isEnabled
- true to enable, false to disablepublic void onStart()
FragmentActivity.onStart()
to ensure proper
accounting for the lifecycle.public void onStop()
FragmentActivity.onStop()
to ensure proper
accounting for the lifecycle.public void updateLocationVisibilityTo(boolean isVisible)
isVisible
- true to show, false to hidepublic com.mapbox.mapboxsdk.maps.MapboxMap retrieveMap()
MapboxMap
originally given in the constructor.
This method gives access to all map-related APIs.
public void updateIncidentsVisibility(boolean isVisible)
isVisible
- true if incidents should be visible, false otherwisepublic boolean isIncidentsVisible()
public void updateTrafficVisibility(boolean isVisible)
isVisible
- true if traffic should be visible, false otherwisepublic boolean isTrafficVisible()
public void addOnCameraTrackingChangedListener(com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener listener)
OnCameraTrackingChangedListener
to the LocationComponent
that is
wrapped within this class.
This listener will fire any time camera tracking is dismissed or the camera mode is updated.
listener
- to be addedpublic void removeOnCameraTrackingChangedListener(com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener listener)
OnCameraTrackingChangedListener
from the LocationComponent
that is
wrapped within this class.listener
- to be removedpublic boolean addOnWayNameChangedListener(OnWayNameChangedListener listener)
OnWayNameChangedListener
for listening to updates
to the way name shown on the map below the location icon.listener
- to be addedpublic boolean removeOnWayNameChangedListener(OnWayNameChangedListener listener)
OnWayNameChangedListener
for listening to updates
to the way name shown on the map below the location icon.listener
- to be removedpublic void adjustLocationIconWith(int[] customPadding)
For example, to position the icon in the center of the map, you can pass {0, 0, 0, 0} which eliminates the default padding we provide when navigation begins.
customPadding
- true if should be centered on the map, false to position above the bottom viewpublic void takeScreenshot(NavigationSnapshotReadyCallback navigationSnapshotReadyCallback)