MapboxCarMap

class MapboxCarMap

This is the main entry point for controlling the Mapbox car map surface.

You can add the MapboxCarMap to your entire androidx.car.app.Session using the Lifecycle. And then any androidx.car.app.Screen that is using a supported template will automatically show the Mapbox map. You can also, specify a MapboxCarMap for each individual androidx.car.app.Screen by constructing the MapboxCarMap with the screen Lifecycle.

Supported templates include:

Customize your MapboxCarMap with your own implementations of MapboxCarMapObserver. Use the registerObserver and unregisterObserver functions to load and detach the observers.

The internals of this class use AppManager.setSurfaceCallback, which assumes there is a single surface callback. Do not use setSurfaceCallback, and do not create multiple instances of MapboxCarMap.

Since

1.0.0

Constructors

MapboxCarMap
Link copied to clipboard
fun MapboxCarMap()

Functions

clearObservers
Link copied to clipboard
fun clearObservers(): MapboxCarMap

Optional function to clear all observers registered through registerObserver

prepareSurfaceCallback
Link copied to clipboard
fun prepareSurfaceCallback(carContext: CarContext, mapInitOptions: MapInitOptions): SurfaceCallback

Instead of using setup, this function allows you to create your own SurfaceCallback and forward the calls to the returned SurfaceCallback. This makes it possible for you to adopt new api versions or intercept the calls and continue to use the MapboxCarMap as designed.

registerObserver
Link copied to clipboard
fun registerObserver(mapboxCarMapObserver: MapboxCarMapObserver): MapboxCarMap
setGestureHandler
Link copied to clipboard
fun setGestureHandler(gestureHandler: MapboxCarMapGestureHandler?): MapboxCarMap

Override the car gestures with your own implementation. If you would like to build a custom experience for handling gestures, you can implement the MapboxCarMapGestureHandler interface, or override the DefaultMapboxCarMapGestureHandler, or set to null to disable gesture handling.

setup
Link copied to clipboard
fun setup(carContext: CarContext, mapInitOptions: MapInitOptions): MapboxCarMap

Calls AppManager.setSurfaceCallback to give Mapbox access to render the map onto Android Auto head units. You should only call this once per CarContext in a Session.

unregisterObserver
Link copied to clipboard
fun unregisterObserver(mapboxCarMapObserver: MapboxCarMapObserver): MapboxCarMap

Properties

carContext
Link copied to clipboard
val carContext: CarContext

Accessor for the carContext provided to the MapInitOptions. This makes it easier to create screens with the MapboxCarMap in the constructor.

carMapSurface
Link copied to clipboard
val carMapSurface: MapboxCarMapSurface?

Returns the current MapboxCarMapSurface. It is recommended to use registerObserver and MapboxCarMapObserver to attach and detach your customizations.

mapInitOptions
Link copied to clipboard
val mapInitOptions: MapInitOptions

The initial options used to setup the map.

stableArea
Link copied to clipboard
val stableArea: Rect?

Accessor to the stable area calculated by the car library. It is recommended to use the values returned by MapboxCarMapObserver.onStableAreaChanged.

stableEdgeInsets
Link copied to clipboard
val stableEdgeInsets: EdgeInsets?

Accessor to the stableEdgeInsets calculated by the car library. It is recommended to use the values returned by MapboxCarMapObserver.onStableAreaChanged.

visibleArea
Link copied to clipboard
val visibleArea: Rect?

Accessor to the visible area calculated by the car library. It is recommended to use the values returned by MapboxCarMapObserver.onVisibleAreaChanged.

visibleEdgeInsets
Link copied to clipboard
val visibleEdgeInsets: EdgeInsets?

Accessor to the edgeInsets calculated by the car library. It is recommended to use the values returned by MapboxCarMapObserver.onVisibleAreaChanged.