# Controls and panels

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

Float MapControls over a Flutter map, compose zoom, compass, geolocate and panel controls, and offer terrains, points of interest, units and the time slider.

`MapControls` floats the map's controls in one of its corners. Each control drives the map it is handed, and each panel opens beside its toggle.

## Add the control stack

```dart
import 'package:flutter/widgets.dart';
import 'package:mountaya_client/mountaya_client.dart';
import 'package:mountaya_elements_flutter/mountaya_elements_flutter.dart';

class TrailMap extends StatefulWidget {
  const TrailMap({super.key, required this.mountaya});

  final Mountaya mountaya;

  @override
  State<TrailMap> createState() => _TrailMapState();
}

class _TrailMapState extends State<TrailMap> {
  late final MapEngine map = MapEngine(widget.mountaya);

  @override
  void dispose() {
    map.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) => Stack(
    children: [
      MapView(engine: map),
      // Zoom, compass, layers and preferences show unless you turn them off.
      MapControls(map: map, geolocate: true, pois: true),
    ],
  );
}
```

A panel opens in the nearest `Overlay`. A `Navigator` provides one; under a bare `WidgetsApp`, wrap your screen in an `Overlay` as Trail does.

- `MapControls({MapEngine? map, bool zoom = true, bool compass = true, bool geolocate = false, bool layers = true, thumbnail, bool offersTime = false, bool pois = false, bool preferences = true, MapCorner corner = MapCorner.topRight, MapPanel? openPanel, onOpenPanelChanged, UnitPreferences? unitPreferences, onUnitPreferencesChanged, bool enabled = true, Map<String, String>? strings, List<Widget> children = const []})`. Each flag is a plain `bool` with a fixed default, the set a new organization's embed shows; nothing is read from your organization.
- From the top: the zoom pair, the layers, points-of-interest and preferences toggles as one group, your own `children`, geolocate and the compass.
- `corner` is visual: `MapCorner.topRight` is the top right in a right-to-left layout too, leaving the top left to the watermark. The stack keeps to the map's safe area and moves clear of the watermark's frame by the smallest move, so one in the top-left corner starts below it.
- One panel is open at a time, yours included. `openPanel` and `onOpenPanelChanged` hoist which one; `MapPanel.layers`, `MapPanel.pois`, `MapPanel.preferences`, or `MapPanel('<yours>')`. An open panel is a popup: a screen reader announces it by its toggle's name, the focus moves into it, Escape and the platform's back close it, and the focus returns to its toggle.
- `enabled: false` shuts every control, yours among them.
- Every button is the platform's touch target (48 dp on Android, 44 pt on iOS), and is pressed from a hardware keyboard too, a 2-pixel `focus-ring` drawn while the keyboard's focus stands there.
- Without an `Overlay` above it, a panel is drawn under its toggle inside the stack.

## Pick the control for the job

Compose a control on its own to answer a press your own way:

```dart
import 'package:flutter/widgets.dart';
import 'package:mountaya_client/mountaya_client.dart';
import 'package:mountaya_elements_flutter/mountaya_elements_flutter.dart';

class TrailMap extends StatefulWidget {
  const TrailMap({super.key, required this.mountaya});

  final Mountaya mountaya;

  @override
  State<TrailMap> createState() => _TrailMapState();
}

class _TrailMapState extends State<TrailMap> {
  late final MapEngine map = MapEngine(widget.mountaya);
  bool _exporting = false;

  @override
  void dispose() {
    map.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) => Stack(
    children: [
      MapView(engine: map),
      Positioned(
        top: 16,
        right: 16,
        child: Column(
          children: [
            ZoomControl(map: map),
            CompassControl(map: map),
            GeolocateControl(map: map),
            DownloadControl(
              enabled: !_exporting,
              onTap: () => setState(() => _exporting = true),
            ),
            const PanelControl(
              panel: MapPanel('filters'),
              label: 'Filters',
              glyph: 'preferences',
              help: 'Huts only',
              child: Text('Huts only'),
            ),
          ],
        ),
      ),
    ],
  );
}
```

- `ZoomControl` (`onZoomInTap`, `onZoomOutTap`), `CompassControl` (`onTap`), `GeolocateControl` (`onTap`, `onError`, `isLocating`) each take their handler in place of the map. Zoom in is disabled at the camera's zoom ceiling and zoom out at its floor.
- `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. Its fix is a `Future` (`GeolocateControlEngine.locate()`), and its failure goes to `onError`, where Swift and Kotlin hand it to a callback.
- `DownloadControl` and `DirectionsControl` drive nothing of the map's, so their `onTap` is required.
- `PanelControl(panel:, label:, glyph:, help:, child:)` opens your own panel; inside `MapControls` it takes part in the one-open-panel rule.
- Each widget takes its own `strings`, which replace the scope's words by their path.

## Choose terrains, points of interest and units

The panels the stack opens are widgets too, so you can place one where you like:

```dart
import 'package:flutter/widgets.dart';
import 'package:mountaya_client/mountaya_client.dart';
import 'package:mountaya_client/rest_schema.dart' as rest_schema;
import 'package:mountaya_elements_flutter/mountaya_elements_flutter.dart';
import 'package:mountaya_geo/mountaya_geo.dart';

class TrailMap extends StatefulWidget {
  const TrailMap({super.key, required this.mountaya});

  final Mountaya mountaya;

  @override
  State<TrailMap> createState() => _TrailMapState();
}

class _TrailMapState extends State<TrailMap> {
  late final MapEngine map = MapEngine(widget.mountaya);
  // The selection drives the map; the State that makes it closes it.
  late final LayersSelectionEngine selection = LayersSelectionEngine(map: map);
  UnitPreferences _units = const UnitPreferences(
    language: 'fr',
    length: rest_schema.UnitLength.metric,
  );

  @override
  void dispose() {
    selection.close();
    map.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) => Column(
    children: [
      LayersPanel(
        selection: selection,
        thumbnail: (choice, slug) => AssetImage('assets/layers/$slug.webp'),
      ),
      PoiPanel(
        map: map,
        groups: [
          PoiPanelGroup(id: 'water', label: 'Water', keys: const ['drinking-water']),
        ],
      ),
      PreferencesPanel(
        preferences: _units,
        onPreferencesChanged: (next) => setState(() => _units = next),
        map: map,
      ),
    ],
  );
}
```

- `LayersPanel({required LayersSelectionEngine selection, isLocked, onLockedTap, thumbnail, bool offersTime = false, strings})` lists the catalogue in the map studio's four sections: base maps as picture cards, enrichments as switches, points of interest left to their own panel, and classic overlays as picture cards one category at a time behind a segmented control. A card shows the picture `thumbnail` hands for it, its name alone where it hands none; a press on an entry `isLocked` answers `true` for goes to `onLockedTap`.
- `LayersSelectionEngine({LayersSelectionTarget? map})`: `setTerrain(slug)`, `setOverlay(slug)`, `toggleEnrichment(slug)`, `setInstant(instant)`; it is an `Engine`, closed by whoever made it.
- A `PoiPanelGroup(id:, label:, keys:, glyph:)` is the app's own data, not a published taxonomy: `id` and `label` are yours, and `keys` are the layers catalogue's (`map.loadLayers()`), a row standing where any of them is drawn. The group `water` here holds `drinking-water`, the layer key the Mountaya app's own water group draws.
- `PoiPanel({map, keys, groups, activeGroups, labels, minZoom, showsAllToggle, onToggled, onGroupToggled, onAllToggled, strings})` offers the concepts the map draws. `PreferencesPanel({required preferences, required onPreferencesChanged, map, strings})` hands your `UnitPreferences` back with one preference changed, and relabels the map for a language.
- Engine commands behind the panels: `map.loadLayers()` (the catalogue, read once and shared), `setOverlay(slug)`, `clearOverlay()`, `addEnrichment(slug)`, `removeEnrichment(slug)`, `setLayerVisibility(id, visible:)`, `setKeyVisibility(key, visible:)`.
- A panel is laid out against the map's size, opens toward the inside of the screen, and scrolls past 420 logical pixels or the window's height.
- The widgets read their words, glyph sets and colours from the `MountayaScope` above them (`MountayaScope(statement: ElementsScopeStatement(language:, locale:), tokens:, scheme:, child:)`), under the platform's brightness unless the scope states a scheme. No widget reads a Material or Cupertino theme.
- Callbacks are past tense in Dart (`onPreferencesChanged`, `onToggled`, `onSelected`) where Swift and Kotlin use their own platform's words.

## Move through time

A forecast overlay, such as `snow-depth`, is drawn for the instant you pin. Offer the time slider in the layers panel:

```dart
import 'dart:async';

import 'package:flutter/widgets.dart';
import 'package:mountaya_client/mountaya_client.dart';
import 'package:mountaya_elements_flutter/mountaya_elements_flutter.dart';

class TrailMap extends StatefulWidget {
  const TrailMap({super.key, required this.mountaya});

  final Mountaya mountaya;

  @override
  State<TrailMap> createState() => _TrailMapState();
}

class _TrailMapState extends State<TrailMap> {
  late final MapEngine map = MapEngine(widget.mountaya);

  @override
  void initState() {
    super.initState();
    unawaited(map.setOverlay('snow-depth'));
  }

  @override
  void dispose() {
    map.close();
    super.dispose();
  }

  // The layers panel offers the time slider over the snow-depth forecast.
  @override
  Widget build(BuildContext context) => Stack(
    children: [
      MapView(engine: map),
      MapControls(map: map, offersTime: true),
    ],
  );
}
```

Offer the time only where your organization's overlay time control allows it.

- The slider spans the forecast window an hour a stop, 71 hours back to 144 ahead, laid out around `package:clock`'s `clock` each time the panel draws. Its ticks mark every day, two days back, now, two and five days ahead labelled; a line above it reads the thumb's moment in the device's time zone and its distance from now. Letting go pins that moment on the selection, which asks the map for it; a release on now pins none, so the map follows the clock again. It moves an hour under each arrow key and reads as an adjustable value to assistive technologies.
- `map.setInstant(DateTime.utc(2026, 3, 14, 9))` pins an instant yourself: it draws a stamped classic overlay for that instant, again as the pin moves and across a base-map switch; `null` draws the present. An enrichment is never stamped. `map.instant` holds the pin.
- The Tile API refuses a publishable key or a share token a stamped tile asked more than 15 minutes from the moment it arrives, unless the organization's overlay time control allows it, so a slider without it pins instants that draw nothing.
- The slider's rules are Geo's (`timeSliderWindow`, `timeSliderTicks`, `timeSliderReadout`, `timeSliderRelease`), for a slider of your own.

## Next steps

- [Search](https://docs.mountaya.com/en/sdks/dart/search.md): A search box over the map.
- [Show an elevation profile](https://docs.mountaya.com/en/sdks/dart/elevation-profile.md): The itinerary's elevation, linked to the map.
