MapboxRouteArrowApi

class MapboxRouteArrowApi

Responsible for displaying a maneuver arrow representing the next maneuver. The maneuver arrow is calculated based on the route progress and the data returned should be rendered on the map using the MapboxRouteArrowView class. Generally this class should be called on each route progress update in order to ensure the arrow displayed is kept consistent with the state of navigation.

The two principal classes for the maneuver arrow are the MapboxRouteArrowApi and the MapboxRouteArrowView.

Like the route line components the MapboxRouteArrowApi consumes data from the Navigation SDK, specifically the RouteProgress, and produces data for rendering on the map by the MapboxRouteArrowView. Simple usage of the maneuver arrows would look like:

RouteArrowOptions routeArrowOptions = new RouteArrowOptions.Builder(context)
.withAboveLayerId(RouteLayerConstants.TOP_LEVEL_ROUTE_LINE_LAYER_ID)
.build()
MapboxRouteArrowApi routeArrow = new MapboxRouteArrowApi()
MapboxRouteArrowView routeArrowView = new MapboxRouteArrowView(routeArrowOptions)

or

val routeArrowOptions = RouteArrowOptions.Builder(context)
.withAboveLayerId(RouteLayerConstants.TOP_LEVEL_ROUTE_LINE_LAYER_ID)
.build()
val routeArrow = MapboxRouteArrowApi()
val routeArrowView = MapboxRouteArrowView(routeArrowOptions)

NOTE: the above example is setting the layer above which the arrow(s) should be located. This constant is a good starting point but you may have a use case that requires setting the layer elevation for the arrows differently. In addition, if using this constant it is important that the route line related layers be initialized before any rendering of the arrows is done. The route line related layers can be created either by calling MapboxRouteLineView.initializeLayers or by calling one of the render methods on MapboxRouteLineView. In most cases it is not necessary to explicitly call MapboxRouteLineView.initializeLayers as calling any of the render methods of MapboxRouteLineView will initialize the layers and typically a route line will be drawn before a maneuver arrow.

In order for the MapboxRouteArrowApi to function it needs route progress updates. An application should register a RouteProgressObserver with the MapboxNavigation class instance and pass the route progress updates to the MapboxRouteArrowApi class. Be sure to unregister this listener appropriately according to the lifecycle of your activity or Fragment in order to prevent resource leaks.

At a minimum an application should do the following with route progress updates:

override fun onRouteProgressChanged(routeProgress: RouteProgress) {
val updateState = routeArrow.updateUpcomingManeuverArrow(routeProgress)
routeArrowView.render(mapboxMap.getStyle(), updateState)
}

Constructors

MapboxRouteArrowApi
Link copied to clipboard
fun MapboxRouteArrowApi()

Functions

addArrow
Link copied to clipboard
fun addArrow(arrow: ManeuverArrow): Expected<InvalidPointError, ArrowAddedValue>
Adds an arrow to the map.
addUpcomingManeuverArrow
Link copied to clipboard
fun addUpcomingManeuverArrow(routeProgress: RouteProgress): Expected<InvalidPointError, UpdateManeuverArrowValue>
Calculates a maneuver arrow based on the route progress and returns a state that can be used to render the arrow on the map.
clearArrows
Link copied to clipboard
fun clearArrows(): ClearArrowsValue
Clears all arrows from the map.
equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
getArrows
Link copied to clipboard
fun getArrows(): List<ManeuverArrow>
hashCode
Link copied to clipboard
open fun hashCode(): Int
hideManeuverArrow
Link copied to clipboard
fun hideManeuverArrow(): ArrowVisibilityChangeValue
Returns a state containing visibility modifications for hiding the maneuver arrow.
redraw
Link copied to clipboard
fun redraw(): ArrowAddedValue
Returns the data necessary to re-render or redraw the arrow(s).
removeArrow
Link copied to clipboard
fun removeArrow(arrow: ManeuverArrow): RemoveArrowValue
Will remove the arrow and return updated data for rendering the arrows.
showManeuverArrow
Link copied to clipboard
fun showManeuverArrow(): ArrowVisibilityChangeValue
Returns a state containing visibility modifications for showing the maneuver arrow.
toString
Link copied to clipboard
open fun toString(): String