MapViewDelegate

interface MapViewDelegate

Delegate interface for MapView operations that require app-specific ViewModel access.

The SDK's SurfaceCallback manages the MapView lifecycle (creation, VirtualDisplay, Presentation, gestures, cleanup) but cannot directly access the app's MapViewModel or its extension functions (MapView.init(), MapView.update()). This delegate bridges that gap by letting the app provide the MapView initialization and state synchronization logic.

Why this exists

The MSDK's MapView.init() and MapView.update() are extension functions defined in the app's maps_presentation module, not methods on the MSDK's MapView class. They require the app's MapViewModel which contains map state (style, camera, POIs, traffic, road restrictions). The SDK cannot depend on app modules, so this interface abstracts those operations behind app-implemented callbacks.

Usage

Implement this interface with your app's MapViewModel:

class MyMapViewDelegate(private val mapViewModel: MyMapViewModel) : MapViewDelegate {
override fun initializeMapView(mapView: MapView) {
mapView.init(mapViewModel) // Your app's init extension
}

override fun startMapStateObservation(mapView: MapView, scope: CoroutineScope): Job {
return scope.launch {
mapViewModel.uiStateSharedFlow.collect { updater ->
mapView.update(updater, mapViewModel)
}
}
}

override fun applyDarkModeStyle(isDark: Boolean) {
val style = if (isDark) "Night" else "Day"
mapViewModel.setExternalMapStyleOverride(style)
}

override fun getDefaultZoomLevel(): Double {
return mapViewModel.uiState.mapCameraState.zoomLevel
}
}

Then set it on the AndroidAutoSurfaceHolder:

surfaceHolder.setMapViewDelegate(myDelegate)

See also

Functions

Link copied to clipboard
abstract fun applyDarkModeStyle(isDark: Boolean)

Apply the map's dark/light mode to the map style.

Link copied to clipboard
abstract fun getDefaultZoomLevel(): Double

Get the default zoom level for initial camera centering.

Link copied to clipboard
abstract fun initializeMapView(mapView: MapView)

Initialize the MapView with app-specific state.

Link copied to clipboard
abstract fun startMapStateObservation(mapView: MapView, scope: CoroutineScope): Job

Start observing the app's map state and applying changes to the MapView.