# Show a map

> Canonical URL: https://docs.mountaya.com/en/sdks/kotlin/map/
> Last updated: 2026-11-27
> Rules for agents: https://docs.mountaya.com/llms.txt#rules-for-agents

Render a Mountaya map in Compose with MapEngine and MapView, draw itineraries, move the camera, handle clicks, read a point and place waypoints.

`MapEngine` holds what the map shows, on every target. On Android, `MapView` draws it in Compose over MapLibre Native.

## Render the map

```kotlin
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import com.mountaya.client.Mountaya
import com.mountaya.elements.MapEngine
import com.mountaya.elements.MapView

@Composable
fun TrailMap(mountaya: Mountaya) {
    val map = remember { MapEngine(mountaya) }
    LaunchedEffect(map) { map.setTerrain() }
    MapView(map, Modifier.fillMaxSize())
}
```

- `MapEngine(client, style, terrainVariant, camera, labelLanguage, paint, glyphs, geolocation, transformRequest)`: every parameter but the client has a default. The engine and its rules are common code; `MapView` is Android only. On iOS and the jvm, read `map.state` (a `StateFlow<MapState>`) and draw with views of your own, or use `ScriptedMapSurface` in tests.
- `MapView(map, modifier, okHttpClient, readout = true, onReady, onClick, onCameraChange)`. `onReady` hands MapLibre's own `MapLibreMap` once the first style is loaded, for anything the view does not wrap; `mountaya-elements` exposes MapLibre for exactly that. `okHttpClient` is the client MapLibre's requests go through (a cache, a proxy, a pinned certificate).
- `setTerrain()` shows the first terrain of the Tile API's catalogue; `setTerrain("<slug>")` names another, `setTerrainVariant(TileSchema.TerrainVariant.Dark)` the dark variant, `setStyle(url)` a style of your own. Everything drawn is drawn again on a base map a switch brings in.
- Labels speak the engine's `labelLanguage`, else the client's `language`, else the device's.
- MapLibre keeps one HTTP client for the process. Each map's requests to its client's Tile API carry that client's credential; two maps whose clients reach one Tile API under two credentials send the credential of the map attached last, and the `transformRequest` and `okHttpClient` of the map attached last apply to all (a divergence the SDK records: the TypeScript SDK lets each map override its own).
- `map.close()` makes the engine inert; every later command does nothing.

## Draw an itinerary

```kotlin
import com.mountaya.elements.CameraFit
import com.mountaya.elements.MapEngine
import com.mountaya.geo.PixelPadding

suspend fun drawTour(map: MapEngine) {
    map.setItinerary("0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21", fit = CameraFit(padding = PixelPadding(48.0)))
    // The zones of your credential's scope, beside it.
    map.setZones(true)
}
```

Call it from a `LaunchedEffect`. A later call replaces the itinerary.

- Each call draws in a slot of its own: `setItinerary(id, fit)`, `setCollection(id, fit)`, `setItineraries(true)` (every itinerary of the credential's scope), `setZones(true)`, and `setSpecification(specification, name)` for a specification you hold. The latest call for a slot draws; one that answers after a later call answers `false`. Cancelling its coroutine withdraws it and gives the slot back to the call it superseded. `clearItinerary()`, `clearCollection()` and `removeSpecification(name)` clear them.
- An itinerary's restricted stretches are striped in their kind's colour beside its line until `setAccessRestrictionsVisibility(false)`.
- Data API results draw under ids of their own: `addDirections`, `addIsochrones`, `addMatrix`, `addPlaces`, `addSuggestions`, `setPointsOfInterest`, each edited with its `edit…` and removed with `removeAnalysis(id)`. Three geometry slots draw over everything: `GeometrySlot.Preview`, `Emphasis` and `Highlight`, through `setGeometry`.
- `addSource(MapSource(…))` and `addLayer(MapLayer(id, type, source, rank, paint, layout))` draw your own data at a `LayerRank`. `editLayer(id, paint, layout)` merges a patch: a member mapped to `null` is kept as it is (Kotlin's spelling of "keep"), and a member set to `JsonNull` goes back to the style's default (Kotlin's spelling of "clear"). `false`, `0` and `""` are values.
- `addMarker(MapMarker(id, position, color, glyph, label))` stands above everything; `editMarker(id, …)` with a member left `null` keeps it.

## Move the camera

```kotlin
import com.mountaya.elements.CameraFit
import com.mountaya.elements.CameraTarget
import com.mountaya.elements.MapEngine
import com.mountaya.geo.PixelPadding

fun showChamonix(map: MapEngine) {
    // A move states the members it changes; the bearing and the pitch are kept.
    map.ease(CameraTarget(center = listOf(6.8712, 45.9231), zoom = 12.0))
    // The box around Chamonix and Argentière: west, south, east, north.
    map.fitBounds(listOf(6.80, 45.85, 7.00, 46.00), CameraFit(padding = PixelPadding(48.0)))
    map.resetNorth()
}
```

- `jump`, `ease` and `fly` each take a `CameraTarget(center, zoom, bearing, pitch)` and change only what it states. `fitBounds([west, south, east, north], CameraFit(padding, maxZoom, duration))` frames a box facing north at the highest zoom that fits the canvas less its padding. `zoomIn`, `zoomOut` and `resetNorth` (which also turns the pitch back to 0) step.
- `setMaxBounds([west, south, east, north])` holds what the map shows inside a box, `null` lifts it. `setZoomBounds(min = ZoomLimit.Zoom(8.0), max = ZoomLimit.Zoom(17.0))`: a limit left out is kept, `ZoomLimit.Released` goes back to MapLibre's own 0 and 25.5.
- `map.state.value.camera` is the camera now, a `CameraPose` (`center`, `zoom`, `bearing`, `pitch`).
- A camera move a control starts jumps where the reader turned animations off (Android's animator duration scale at 0).
- `locate()` frames the device's position at zoom 16 at most and throws `MapException` with the reason where there is no fix. It never asks for location access: until the app holds `ACCESS_FINE_LOCATION`, a locate is refused as `denied`. `MapView` hands the engine `DeviceGeolocation` unless you pass a `geolocation` of your own; `InertGeolocation()` turns locating off.

## Respond to the user

`onClick` hands you each click and the marker it fell on. `onCameraChange` hands you the camera each time it comes to rest:

```kotlin
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import com.mountaya.elements.MapEngine
import com.mountaya.elements.MapView
import com.mountaya.geo.CameraPose

@Composable
fun PickingMap(map: MapEngine) {
    var picked by remember { mutableStateOf<String?>(null) }
    var camera by remember { mutableStateOf<CameraPose?>(null) }
    MapView(map, onClick = { tap -> picked = tap.marker }, onCameraChange = { camera = it })
    BasicText("Marker ${picked ?: "none"} at zoom ${camera?.zoom}")
}
```

Kotlin names a tap on the map a click: `onClick`, `MapEvent.Click`.

- `onClick` receives a `MapTap` (`position` as `[longitude, latitude]`, `point` as `[x, y]` in dp from the view's top left, `marker` the id of the marker clicked, else null) and shows that marker's label. A double tap zooms and is no click.
- `onCameraChange` receives a `CameraPose` each time the camera comes to rest, after the reader or your code moved it, never frame by frame.
- `map.events()` is a `Flow<MapEvent>` of every kind: `Click` and `LongClick` (each with its `tap`), `FeatureClick` and `FeatureHover` (the `features` under the pointer, with `position`), `AccessRefused` and `AccessRestored`, `Failure`, and `LayersChange` (the catalogue the map holds after it). Collect it in a `LaunchedEffect`; a `when` over an event keeps an `else`.
- Kotlin says Click where the Swift and Dart SDKs say Tap (`MapEvent.Click`, `MapEvent.LongClick`, `onClick`); the type each handler receives is still `MapTap`.
- Point queries answer the features the map itself drew under a point of the view, never its base map's, topmost first: `featuresAt(point)`, `poisAt`, `zonesAt`, `itinerariesAt`, each a `QueriedFeature` with the `layer` that drew it. `project(position)` and `unproject(point)` convert. `elevationAt(position)` asks the Data API for the ground's elevation.
- A feature's id from a GeoJSON source MapLibre fetched by its address reads back as text, as MapLibre Android writes it.

## Hear what the map refuses

A key without the `tiles` scope, or an agreement that does not cover the map, refuses the map's own requests. The engine says so:

```kotlin
import com.mountaya.elements.MapEngine
import com.mountaya.elements.MapEvent

suspend fun printErrors(map: MapEngine) {
    map.events().collect { event ->
        when (event) {
            is MapEvent.AccessRefused -> println("refused: ${event.status} at ${event.url}")
            is MapEvent.Failure -> println("failed: ${event.status} at ${event.url}, ${event.cause}")
            else -> Unit
        }
    }
}
```

`map.state.value.isAccessRequired` stays true while a refusal stands, so a notice you raise on it comes down by itself.

- A refusal is a `401`, `402` or `403` to one of the map's own requests. It stands until a tile of its source loads, or the next style for one that names no source. A `401` or `403` answering a request that left under a credential your client no longer sends (a token since replaced) is told to nobody, and a style refused so is asked for again under the credential your client sends now.
- `MapEvent.Failure` is a failed request: a style that does not load (a `200` MapLibre cannot read among them), after which the map goes back to the style it showed, or a request that never left because the credential could not be read (`cause` is what your token's function threw). The request hook hears every answer of 400 up and every request with no answer, so a failure with no answer is a `Failure` with no `status`; a request MapLibre cancelled is told to nobody.
- A command handed something a map cannot take throws `MapException` whose `kind` says what (`LayerNotFound` among them) and leaves the map as it was.

## Read a point

A long press opens the readout: what the map draws there, the terrain's altitude, slope and aspect, and the coordinates. Turn it off with `readout = false`:

```kotlin
import androidx.compose.runtime.Composable
import com.mountaya.elements.MapEngine
import com.mountaya.elements.MapView

@Composable
fun MapWithoutReadout(map: MapEngine) {
    MapView(map, readout = false)
}
```

- The readout opens at a long press or a secondary click: the point of interest and the zone the map draws there, the band of the classic overlay at any zoom, the terrain's altitude, slope and aspect read off the elevation tiles from zoom 13 (through your client's Tile API), and the coordinates with an action that copies them. Figures are in metric units, degrees and Celsius, in the scope's language; the aspect reads beside its word, `123° · South-East`.
- A moment is written in the device's time zone. While the card is open its moment follows the instant the map pins. A tap or a camera move closes it. The press is told to `events()` as `MapEvent.LongClick` either way.
- The same rules run without a map: `elevationTilesAt`, `terrainFromElevationTiles` and `aspectCardinal` (see [geo](https://docs.mountaya.com/en/sdks/kotlin/geo.md#terrain)).

## Attribution and watermark

The map shows the Mountaya watermark in its top-left corner unless your organization holds white label, and lists its credits, Mountaya first. Keep your own views clear of the watermark's frame:

```kotlin
import com.mountaya.elements.MapEngine
import com.mountaya.geo.isWatermarkKeptClear
import com.mountaya.geo.watermarkClearance

fun clearance(map: MapEngine): String {
    val keepsClear = isWatermarkKeptClear(map.organizationRead.value)
    return "Keep clear: $keepsClear, below $watermarkClearance dp. Credits: ${map.credits}"
}
```

- The map reads its organization once it is drawn, through `postOrganizationLookup` with the publishable key in the body, once per key and Map Studio API origin for the process. Its answer decides one thing: the watermark, drawn unless the organization holds white label, linked to Mountaya's site, and hidden by nothing you pass. Nothing else is read from the organization.
- `map.organizationRead` is a `StateFlow<OrganizationRead>` in five states: `Waiting`, `Answered(whiteLabel)`, `Failed`, `TimedOut` (after one attempt's budget, 35 seconds by default) and `NoKey`. The frame is held from the first draw, while the read waits, and released only once it answers white label. `map.loadOrganization()` reads it yourself.
- The frame: `watermarkWidth` 180 dp, `watermarkHeight` 180 × 58 / 138 dp, `watermarkInset` -4 dp from the corner of the map's safe area, so it ends `watermarkClearance`, about 72 dp, below the safe area's top. The safe area is the window's root insets (system bars, a display cutout, never the keyboard), at the reader's top left in either layout direction.
- The SDK's own controls, panels, readout and a marker's label keep to the safe area and clear of the frame.
- The watermark is a view above MapLibre's canvas: a `MapLibreMap.snapshot` records the canvas without it, and Mountaya's terms of use govern what you do with one.

## Place waypoints

An edit places a waypoint at each click, on the line where the click falls within 40 dp of an active segment. Move one of the Tour du Mont-Blanc's waypoints:

```kotlin
import com.mountaya.elements.MapEngine
import com.mountaya.elements.WaypointEdit

suspend fun startMoving(map: MapEngine, route: List<List<Double>>) {
    map.setItinerary("0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21")
    // The itinerary's line, which a click near it snaps to.
    map.setActiveSegments(listOf(route))
    map.beginWaypointEdit("5f2b8c1e-7a4d-4e9b-b3c6-0d8e1f2a4b67")
}

fun finishMoving(map: MapEngine): WaypointEdit? = map.endWaypointEdit()
```

`MapView` places the waypoint at each click while the edit runs.

- `beginWaypointEdit(id)` starts an edit; each click `MapView` hears calls `placeWaypoint(position, projection)`, which snaps to an active segment within 40 dp (the magnet). A map drawn some other way calls `placeWaypoint` with its own `ScreenProjection`. `endWaypointEdit()` answers the `WaypointEdit` (`waypointId`, `position`, `isSnapped`) or null.
- `setActiveSegments(lines)` names the lines the magnet snaps to; `map.state.value.waypointEdit` is the edit in progress.

## Next steps

- [Controls and panels](https://docs.mountaya.com/en/sdks/kotlin/controls.md): Zoom, layers, points of interest and units.
- [Search](https://docs.mountaya.com/en/sdks/kotlin/search.md): A search box over the map.
