MapSDK with Jetpack Compose
WemapMapComposeSDK adds one composable, WemapMap, over WemapMapSDK's WemapMapView. It is the Compose
counterpart of Map in the iOS SDK's SwiftUI layer.
For the View-based API — and for creating a session, which is identical either way — see MapSDK Getting Started.
Installation
Compose support is a separate artifact, so View-based apps are never made to depend on the Compose runtime:
implementation("com.getwemap.sdk:map-compose:<version>")
It brings com.getwemap.sdk:map with it. Requirements beyond the Map SDK's own: a Compose BOM of
2026.09.00 or newer. No compileSdk or AGP bump is needed.
The shape of the API
There is one composable and no parallel Compose API. WemapMap hands you the loaded WemapMapView,
and every manager, the camera, navigation and POI selection are reached through it exactly as in a View-based
app:
@Composable
fun MapScreen(session: MapSession) {
var mapView by remember { mutableStateOf<WemapMapView?>(null) }
WemapMap(
session = session,
modifier = Modifier.fillMaxSize(),
onLoaded = { mapView = it },
onFailed = { error -> Log.e("Map", "Failed to load the map", error) }
)
Button(onClick = { mapView?.pointOfInterestManager?.hideAllPois() }) {
Text("Hide all POIs")
}
}
Callbacks are parameters, not modifiers — that is the Compose idiom. One consequence to know: a parameter
is single-valued, so unlike the iOS .onLoaded { } modifier there is no multicast. A wrapper composable that
needs to add its own handler composes the lambdas by hand.
Parameters
| Parameter | Purpose |
|---|---|
session | The session this map renders. Required. |
modifier | Standard Compose modifier. |
config | Rendering configuration. Read once, at creation. |
initialCameraPosition | The MapCameraPosition the map opens at, instead of framing the map data. Read once, at creation. |
cameraPositionState | What the camera should do, in both directions. See below. |
cameraChangeFrequency | How often onCameraChange fires — OnEnd (default) or Continuous. |
proxyUpdateFrequency | How often onProxyUpdate fires — OnEnd (default) or Continuous. |
onLoaded | Invoked with the loaded map view. Its managers are available from here on. |
onFailed | Invoked with the loading error. |
onPhaseChange | Every LoadPhase transition, including the initial Loading. Drive a spinner with it. |
onTouch | Taps that selected no POI, as a point in the map's coordinate system. |
onCameraChange | The MapCameraState, whenever the camera changes. How to read the camera. |
onProxyUpdate | A read-only MapProxy onto the camera and geometry, whenever the camera changes. |
factory | Builds the view, for integrators with a WemapMapView subclass. Do not call configure in it. |
There are no parameters for things that are already flows
The SDK's manager callbacks are Flows, and Compose reads a flow directly — so there is deliberately no
focusedBuilding or navigationInfo parameter:
val building by (mapView?.buildingManager?.focusedBuildings ?: emptyFlow())
.collectAsStateWithLifecycle(null)
The camera
cameraPositionState holds a MapCameraPosition: what the camera should do, not where it is. Set a position and
the map carries it out:
| Position | What the map does |
|---|---|
MapCameraPosition.Automatic | frames the map data, as it does when it opens — the default |
MapCameraPosition.Camera(state) | moves to that camera |
MapCameraPosition.Fit(bounds, padding) | frames those bounds, clear of the padding |
MapCameraPosition.FollowUser(bearing) | follows the user until something else moves the camera |
MapCameraPosition.Idle | nothing: the camera stays where it is |
val positionState = rememberMapCameraPositionState()
val scope = rememberCoroutineScope()
WemapMap(session = session, cameraPositionState = positionState)
Button(onClick = { positionState.position = MapCameraPosition.Camera(MapCameraState(entrance, zoom = 18.0)) }) {
Text("Show the entrance")
}
Button(onClick = { scope.launch { positionState.animate(MapCameraPosition.FollowUser()) } }) {
Text("Locate me")
}
Setting position moves the camera at once. animate(position, duration) animates it, and suspends until the
camera gets there or the animation is interrupted.
The map writes into the state only when the position itself changes, never to report where the camera is:
Idlewhen something other than the position moves the camera — the user's gesture, an interrupted animation, a level change while following, or code moving the camera through the map view or a widget. The camera stays where that left it.FollowUserwhen the SDK starts following the user on its own, asstartNavigationdoes.
So a position you set again after Idle moves the map back — that is how a "recenter" button works — while
setting the same position twice in a row does nothing. A follow button reads and writes the same state:
val following = positionState.position is MapCameraPosition.FollowUser
Button(onClick = {
positionState.position = if (following) MapCameraPosition.Idle else MapCameraPosition.FollowUser()
}) {
Text(if (following) "Stop following" else "Follow me")
}
To read the camera — to show it, or keep it and restore it later — use onCameraChange:
// `MapCameraState` is `Parcelable`, so `rememberSaveable` keeps it with no saver of your own
var camera by rememberSaveable { mutableStateOf<MapCameraState?>(null) }
WemapMap(
session = session,
initialCameraPosition = camera?.let { MapCameraPosition.Camera(it) },
onCameraChange = { camera = it }
)
rememberMapCameraPositionState is rememberSaveable-backed, so the position survives configuration changes
and process death — after a pan that is Idle, which reopens the map on its data. Save the camera from
onCameraChange when the user's camera is what should come back, as above. When the state carries a position it
is also the map's opening position, and it wins over initialCameraPosition.
MapCameraState equality is exact and ignores lastChangeReason. A camera the map reports after you applied one
differs from it by float noise, so compare positions, not cameras, to know what the map is doing.
Prefer the default cameraChangeFrequency. MapUpdateFrequency.Continuous delivers on every frame of every
gesture, so a handler that writes state recomposes with it.
Session ownership
Hoist the session into a ViewModel, never a remember. It is network-loaded and cannot go into a
Bundle, so a remember drops it on rotation. Call session.deinit() from that owner:
class MapScreenViewModel : ViewModel() {
var session: MapSession? = null
override fun onCleared() { session?.deinit() }
}
One session per screen, shared with the screen's GeoARView and location sources — that shared instance is
what keeps navigation, POI selection and user location consistent.
Passing a different session tears the map down and builds a new one, because a view's session is set once. The map view is also destroyed automatically when it leaves composition.
Lifecycle
You forward nothing. WemapMapView discovers the ViewTreeLifecycleOwner when it attaches and drives
MapLibre's lifecycle itself, and leaving composition tears it down.
The one case that needs attention is a host with no lifecycle owner on the view tree — a plain ComposeView
inside a Dialog, for instance. The view logs a warning; set a lifecycle owner on the view tree, or assign
mapView.lifecycle yourself.
Two things that will bite you
onLoaded is not replayed
Supply the callbacks from the first composition. A handler first passed after loading already settled is
not invoked retroactively — the subscription is established once per view instance and reads the handlers
indirectly, which is what stops onLoaded firing again on every recomposition. For the current state at any
time, read mapView.loadPhase or collect loadPhases.
Mirroring an event flow into state
Flows that carry discrete events (activeLevelChanges, selectionUpdates, touchedPois, every
errors) replay nothing to a new collector, so rendering from one means mirroring it into state and seeding
that state from somewhere else. Use produceState, and be careful not to reach for a keyed remember plus
a LaunchedEffect:
// ✅ one state object; the producer re-seeds it when a key changes
val activeLevel by produceState<Level?>(building?.activeLevel, building, buildingManager) {
value = building?.activeLevel
buildingManager.activeLevelChanges.collect { (_, level) -> value = level }
}
// ❌ silently stale: the keyed `remember` hands out a NEW MutableState when `building` changes, while the
// effect keeps writing to the one it captured on its first pass. The map switches levels, the UI does not.
var activeLevel by remember(building) { mutableStateOf(building?.activeLevel) }
LaunchedEffect(buildingManager) {
buildingManager.activeLevelChanges.collect { (_, level) -> activeLevel = level }
}
StateFlow-backed values (focusedBuildings, loadPhases, VPS states) do not have this problem — they
replay, so collectAsStateWithLifecycle() is all they need.
A complete sample
The map app of the public sample apps has a
Compose screen:
compose/ComposeMapScreen.kt— the map withWemapMapandrememberMapCameraPositionState, a follow button and a "frame the map" button that animate the camera position, a readout of the camera fromonCameraChangeand of the user's position read off the loaded view as a flow, and permission handling viarememberLauncherForActivityResult.fragments/ComposeMapFragment.kt— a thinComposeViewhost, present only because that app navigates with a nav graph.
The other sample screens in the same app are still View-based, so the two can be compared side by side.