Get started
Kotlin SDK
Show a map

Controls and panels

Controls and panels

MapControls floats the map's controls in one of its corners, inside the map's safe area and clear of the watermark. Each control drives the map unless you hand it a handler.

Add the control stack

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.mountaya.elements.MapControls
import com.mountaya.elements.MapEngine
import com.mountaya.elements.MapView

@Composable
fun MapWithControls(map: MapEngine) {
    Box(Modifier.fillMaxSize()) {
        MapView(map, Modifier.fillMaxSize())
        // Zoom, compass, layers and preferences show by default.
        MapControls(map, pois = true, geolocate = true)
    }
}

Pick the control for the job

Put your own controls in the stack's trailing block, beside the built-in ones:

import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import com.mountaya.elements.DownloadControl
import com.mountaya.elements.MapControls
import com.mountaya.elements.MapEngine
import com.mountaya.elements.MapPanel
import com.mountaya.elements.PanelControl

@Composable
fun StackWithExtras(map: MapEngine, onDownload: () -> Unit) {
    MapControls(map) {
        DownloadControl(onClick = onDownload)
        PanelControl(MapPanel("filters"), label = "Filters", glyph = "preferences", help = "Huts only") {
            BasicText("Huts only")
        }
    }
}

Choose terrains, points of interest and units

The stack opens three panels. Each can also stand on its own:

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import com.mountaya.elements.LayersPanel
import com.mountaya.elements.MapEngine
import com.mountaya.elements.PoiPanel
import com.mountaya.elements.PreferencesPanel
import com.mountaya.client.generated.RestSchema
import com.mountaya.geo.LayersSelectionEngine
import com.mountaya.geo.PoiPanelGroup
import com.mountaya.geo.UnitPreferences

@Composable
fun SidePanels(map: MapEngine) {
    val scope = rememberCoroutineScope()
    val selection = remember(map) { LayersSelectionEngine(scope, map) }
    var units by remember { mutableStateOf(UnitPreferences("fr", length = RestSchema.UnitLength.Metric)) }
    LayersPanel(selection)
    // The Mountaya app's own water group, one row over the drinking-water layer.
    PoiPanel(map, groups = listOf(PoiPanelGroup("water", "Water", listOf("drinking-water"))))
    PreferencesPanel(units, onPreferencesChange = { units = it }, map = map)
}

Move through time

Show the snow depth, and offer the time slider in the layers panel. The map draws the overlay for the instant the reader picks:

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import com.mountaya.elements.MapControls
import com.mountaya.elements.MapEngine

@Composable
fun SnowDepthControls(map: MapEngine) {
    LaunchedEffect(map) { map.setOverlay("snow-depth") }
    MapControls(map, offersTime = true)
}

map.setInstant(instant) pins an instant from your own code, and null goes back to now.

Next steps

Last updated