# Controls and panels

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

Float zoom, compass, locate, layers, points of interest and preferences controls over a SwiftUI map, with their panels and the time slider.

`MapControls` floats the map's controls in one corner, each driving the map. Its toggles open the layers, points-of-interest and preferences panels.

## Add the control stack

```swift
import MountayaClient
import MountayaElements
import MountayaGeo
import SwiftUI

struct ControlledMap: View {
  let map: MapEngine
  @State private var openPanel: MapPanel?
  @State private var units = UnitPreferences(language: "fr", length: .metric)

  var body: some View {
    MapView(map)
      .ignoresSafeArea()
      .overlay {
        MapControls(map, geolocate: true, pois: true, openPanel: $openPanel, unitPreferences: $units)
      }
  }
}
```

With nothing stated, the zoom pair, the compass, the layers toggle and the preferences toggle show, top right.

- `MapControls(_:zoom:compass:geolocate:layers:pois:preferences:corner:openPanel:unitPreferences:offersTime:thumbnail:strings:content:)`. Each flag is a plain `Bool` at its fixed default: `zoom` true, `compass` true, `geolocate` false, `layers` true, `pois` false, `preferences` true, `offersTime` false. Nothing is read from your organization.
- From the top the stack reads: the zoom pair, the layers, points-of-interest and preferences toggles as one group, your own controls, geolocate, the compass. `corner:` is a `MapCorner` (`.topRight` by default), the corner the reader sees, in a right-to-left layout too.
- A toggle opens its panel in place of any other, so one panel is open at a time, yours included, beside its toggle and inside the map's safe area. `openPanel:` binds which one (`MapPanel.layers`, `.pois`, `.preferences`, or yours).
- The stack and its panels keep clear of the watermark's frame from the map's first drawing, so the stack may sit in the top-left corner too.
- `.disabled(true)` shuts every control. Each control is pressed anywhere in 44 points each way and draws a 2-point `focus-ring` ring while it holds the keyboard's focus. With reduced motion on, every move a control starts lands at once.
- Words come from the scope in SwiftUI's environment (`\.mountayaScope`), colours from `\.mountayaTokens` under the colour scheme in force. `strings:` replaces words for one view: `["controls.zoomIn": "Closer"]`. `MapControls` hands its `strings` to its own controls and panels, and none to yours.

## Pick the control for the job

Add your own controls in the stack's trailing closure:

```swift
import MountayaElements
import SwiftUI

struct ExportingMap: View {
  let map: MapEngine
  @State private var isExporting = false

  var body: some View {
    MapView(map)
      .overlay {
        MapControls(map) {
          DownloadControl { isExporting = true }
          PanelControl("filters", label: "Filters", glyph: "controls") {
            Text("Huts only")
          }
        }
      }
  }
}
```

- Built-in controls, usable in a stack or alone: `ZoomControl(map:)` (zoom in is disabled at the camera's zoom ceiling and zoom out at its floor), `CompassControl(map:)`, `GeolocateControl(map:)`, `DownloadControl(onTap:)` and `DirectionsControl(onTap:)` (both drive nothing of the map's, so their handler is required), and `PanelControl(_:label:glyph:help:content:)`, which opens a `MapPanel` of yours (a string literal names one) showing `content`.
- Every control that drives the map does so unless you hand a handler in its place (`onTap:`, `onZoomInTap:`).
- `GeolocateControl` never asks for location access: it reads the standing permission, says location is blocked while it is refused, and is drawn in the accent until every fix it asked for settles.
- `Glyph(_:in:size:color:label:)` draws one glyph of a `GlyphSet` in SwiftUI, for a control of your own.

## Choose terrains, points of interest and units

The stack's toggles open these panels. Place one yourself where you like:

```swift
import MountayaClient
import MountayaElements
import MountayaGeo
import SwiftUI

struct WaterFilters: View {
  let map: MapEngine
  @State private var units = UnitPreferences(language: "fr", length: .metric)

  var body: some View {
    VStack {
      POIPanel(
        map: map,
        groups: [
          POIPanelGroup(id: "water", label: "Water", keys: ["drinking-water"])
        ])
      PreferencesPanel(preferences: $units, map: map)
    }
  }
}
```

- `LayersPanel(selection:isLocked:offersTime:thumbnail:strings:onLockedTap:)` lists the catalogue as a `LayersSelectionEngine` holds it (`LayersSelectionEngine(map:)`, which drives the map), in the map studio's sections: base maps as picture cards (your `thumbnail` or the name alone), enrichments as switches, classic overlays as cards of one category at a time behind a segmented control, and the time where you offer it. `isLocked` marks a layer behind your own gate and `onLockedTap` hears a tap on it.
- `POIPanel(map:keys:groups:activeGroups:labels:minZoom:showsAllToggle:strings:onToggle:onToggleGroup:onToggleAll:)` offers the point-of-interest concepts the map draws, grouped as you list them. A `POIPanelGroup(id:label:keys:glyph:)` is your own data: its `keys` are the layers catalogue's (the Tile API's), and a row stands where any of them is drawn. The `water` group above is the Mountaya app's own: the `drinking-water` layer key.
- `PreferencesPanel(preferences:map:strings:)` writes your `UnitPreferences` back with one preference changed, and relabels the map for a language.
- In a stack, a panel lays out under a title row, 340 points wide, or the width its corner leaves on a map no wider than 576; its body scrolls once taller than the map allows. Layer cards stand three to a row (pictures 52 points tall, 40 on a narrow map). Outside a stack, a panel taller than 420 points scrolls.
- The panels' rules are Geo's, so a screen of your own reads the same models.

## Move through time

Offer the time slider in the layers panel, to draw the snow depth for another hour:

```swift
import MountayaElements
import SwiftUI

struct ForecastMap: View {
  let map: MapEngine

  var body: some View {
    MapView(map)
      .overlay { MapControls(map, offersTime: true) }
      .task { try? await map.setOverlay("snow-depth") }
  }
}
```

A release pins that instant on the map. Back on now, the map follows the clock again.

- The slider spans the forecast window, 71 hours back to 144 ahead, an hour a stop, ticked every day, labelled two days back, now, and two and five days ahead. Its thumb reads its moment in the device's time zone, and how far it is from now. An arrow key or VoiceOver's adjustment steps it an hour.
- A release pins the instant on the selection and so on the map (`map.setInstant(_:)`, synchronous). Each tile of a stamped overlay asks for that instant; a pin that moves asks again without drawing the overlay anew. `setInstant(nil)` follows the clock.
- A publishable key or a share token is refused a stamped tile asked more than 15 minutes from the present unless your organization's overlay time control allows it, which is why the time is yours to offer.
- The panel lays its track out around the clock in SwiftUI's environment, `\.mountayaClock` (a `WallClock`), the system's unless you state your own, so a replay moves the window with it.
- The slider's rules are Geo's: `timeSliderWindow(now:)`, `timeSliderTicks(_:)`, `timeSliderRelease(_:at:)`, `timeSliderReadout(_:at:)`.

## Next steps

- [Search](https://docs.mountaya.com/en/sdks/swift/search.md): A search box over places, itineraries and zones.
- [Show an elevation profile](https://docs.mountaya.com/en/sdks/swift/elevation-profile.md): The itinerary's curve under the map.
