WemapMapComposeSDK

Jetpack Compose support for the Wemap Map SDK.

Overview

WemapMapComposeSDK adds a single composable, WemapMap, over WemapMapSDK's WemapMapView. It is a separate artifact on purpose: @Composable declarations in WemapMapSDK would force the Compose runtime onto every consumer, View-based apps included.

Everything the SDK offers is reached through the map view handed to onLoaded — the composable adds no parallel API surface of its own. The SDK's own Flows are collected directly with collectAsStateWithLifecycle, so there are no wrapper parameters for focused building, navigation info and the like.

import com.getwemap.sdk.map.compose.WemapMap

@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) }
)

val building by (mapView?.buildingManager?.focusedBuildings ?: emptyFlow())
.collectAsStateWithLifecycle(null)

building?.let { BuildingBanner(it) }
}

The session is network-loaded and cannot be put in a Bundle, so hoist it into a ViewModel rather than a remember — otherwise a configuration change drops it. Call session.deinit() from that owner (ViewModel.onCleared(), or a DisposableEffect) when the screen is done; the map view itself is torn down automatically when it leaves composition.

A host without a ViewTreeLifecycleOwner — a plain ComposeView in a Dialog, for example — leaves the map unable to discover the lifecycle that drives MapLibre. The view logs a warning in that case; set a lifecycle owner on the view tree, or assign mapView.lifecycle yourself.

Packages

Link copied to clipboard