Display a map using Jetpack Compose.
Android Jetpack Compose is designed to be more efficient and performant than XML layouts. It allows you to define UI in a more declarative and composable way. Compose is also designed to work seamlessly with Kotlin. Visit the Android doc, why adopt Compose? to learn more.
Run the sample to view the map. Pan and zoom to navigate the map.
- Create a custom
@Composable
function to wrap theMapView
- Use
AndroidView
to wrap a classic Android view in a Compose UI. - Set its
Modifier
to define the MapView layout parameters - Use its
factory
parameter to provide context and createMapView(context)
- Add the
MapView
to the lifecycle observer - Add the composable content to the Activity using
setContent { }
- ArcGISMap
- BasemapStyle
- MapView
This sample uses the GeoCompose Toolkit module to be able to implement a Composable MapView.
basemap, compose, geocompose, jetpack, map, toolkit