# Controls and panels

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

Put the zoom, compass, layers and preferences controls over a Mountaya map, open its panels, and let the reader move through time.

`MapControls` is the floating stack over the map. Zoom, compass, layers and preferences show by default. The Props tab lists [every control](https://docs.mountaya.com/en/sdks/typescript/reference/components.md#elements-react) and prop.

## Add the control stack

Place the stack inside `MapView`, and switch controls on or off by name:

```tsx
import { MapControls, MapView } from "@mountaya/elements-react";

<MapView client={client}>
  <MapControls geolocate pois position="top-left" preferences={false} />
</MapView>;
```

Children join the same stack, spacing and focus order. Leave `openPanel` unset and the stack opens its own panels. Set it to control them yourself:

```tsx
<MapControls
  disabled={agentIsDriving}
  onClosePanel={() => setPanel(null)}
  onTogglePanel={(next) => setPanel((current) => (current === next ? null : next))}
  openPanel={panel}
/>;
```

- Flags and their defaults: `zoom` `true`, `compass` `true`, `layers` `true`, `preferences` `true`, `geolocate` `false`, `pois` `false`. A flag set to `false` drops that control. `<MapControls />` alone draws zoom, compass, layers and preferences.
- `openPanel` names one of the built-in panels (`layers`, `pois`, `preferences`) or the `kind` of a `PanelControl` composed in `children`, or `null` for none. Set, the stack only reads it, and asks for a change through `onTogglePanel` and `onClosePanel`. A press inside the open panel, or on its toggle, never dismisses it.
- `disabled` is read once and threaded to every control in the stack. Every control renders disabled until a map resolves.
- `position` is `top-left`, `top-right` (the default), `bottom-left` or `bottom-right`. The stack opens its tooltips and panels over the map from that corner: toward the map's centre line from a left stack, upward from a bottom one.
- `<MapControls>` is positioned absolutely against the nearest positioned ancestor: inside `MapView`, the map's container. Beside `MapView`, wrap both in one element that is sized and `position: relative`.
- Children render between the panel cluster and the geolocate and compass pair. An application that needs its own handler per control leaves every flag off and composes `ZoomControl`, `CompassControl`, `GeolocateControl` and `PanelControl` in `children`, keeping the positioning, the token block and the dismiss-on-press.
- Every control is published twice, on the stack and flat: `MapControls.Zoom` and `ZoomControl` are the same component (also `Compass`, `Geolocate`, `Panel`, `Search`, `StreetView`, `Download`, `Directions`).

### Handlers replace the default

Left unset, a control drives the map itself. Set an `on*` handler and yours runs instead:

```tsx
<ZoomControl />;                        // zooms the map
<ZoomControl onZoomIn={bus.zoomIn} />;  // calls you, and does not zoom
```

`DownloadControl` and `DirectionsControl` require their `onClick`, because only your app knows what to open:

```tsx
<MapControls>
  <DownloadControl onClick={() => setExportOpen(true)} />
  <DirectionsControl onClick={() => setDirectionsOpen(true)} />
</MapControls>
```

- Setting an optional `on*` handler suppresses the element's own default and makes it presentational; the two never both fire. The two halves of the zoom pair are gated separately: a stack that overrides zoom-in keeps no live zoom-out whose default it never wired.
- The handler names are a vocabulary:

  | Shape | Means |
  | --- | --- |
  | `onClick`, `on<Noun>Click` | A press the element cannot act on itself |
  | `on<Verb>` | Overrides that imperative action |
  | `onToggle`, `onToggle<Scope>` | Overrides a visibility flip |
  | `on<Noun>Change(next)` | Reports a new value |
  | `onSelect(item)` | Reports a choice |
  | `onReady`, `onError`, `onAccessRequired`, `onDestroy`, `onUnavailable`, `onLockedClick` | Lifecycle and reports: additive, never suppressing |
  | `onHover` | Takes the cursor, and the map marker the element would have pinned with it |
- `onHover` reads like lifecycle and is not: on the elevation profile and the segment table it subscribes to the cursor, and setting it suppresses the marker the element would pin on the map.
- `DownloadControl` and `DirectionsControl` stay live while the map is still loading: they act on an itinerary you hold, not on the canvas.

## Pick the control for the job

| You want to | Reach for |
| --- | --- |
| Zoom in and out | `zoom`, or `ZoomControl` |
| Reset the bearing to north | `compass`, or `CompassControl` |
| Center on the reader's position | `geolocate`, or `GeolocateControl` |
| Switch terrain and overlays | `layers`, which opens `LayersPanel` |
| Toggle what the POI overlay draws | `pois`, which opens `PoiPanel` |
| Change units and map language | `preferences`, which opens `PreferencesPanel` |
| Open a floating panel of your own | `PanelControl` |
| Search places, itineraries and zones | `SearchControl`, on [search](https://docs.mountaya.com/en/sdks/typescript/search.md) |
| Look around a street | `StreetViewControl` |
| Export what the map shows | `DownloadControl` |
| Open directions for what the map shows | `DirectionsControl` |
| Add a button that matches the built-ins | `ControlButton` |

`CompassRose` is the needle `CompassControl` draws, for a compass of your own. `StudioControls` belongs to the [studio chrome](https://docs.mountaya.com/en/sdks/typescript/studio/chrome.md).

- `ZoomControl` follows the map's zoom window: zoom in is disabled while the camera stands at the ceiling, and zoom out at the floor, as `constraints` or a later `setConstraints` set them. It follows the camera through a pinch, and a window that moves while the camera stands still (`zoomlimitschange`). A window of one zoom disables both. `disabled` disables both whatever the window, and a handler of yours is disabled at the limit too, since the camera would move nowhere.
- `GeolocateControl` reads the device through the map's `geolocation`; the browser asks the reader first.

### Look around with Street View

`StreetViewControl` is a handle the reader drags onto the map. The imagery is Google's, so it needs your Google Maps API key and the `@googlemaps/js-api-loader` package.

```tsx
<MapControls>
  <MapControls.StreetView
    bounds={streetViewBounds}
    googleMapsApiKey={googleMapsApiKey}
    minZoom={14}
    onOpen={(lngLat) => openPanorama(lngLat)}
    onUnavailable={notify}
  />
</MapControls>;
```

- Pass exactly one of `onOpen` and `onDrop`: the props are a union, so both is a type error. `onOpen` keeps the default pipeline (unproject, corridor gate, coverage check) and takes the point that survived it. `onDrop` replaces that pipeline; return `false` to bounce the handle.
- Coverage is a per-point request to Google; `bounds` and `minZoom` are the cheap gates in front of it. The coverage layer shows while a drag is live.
- A press that does not drag, or Enter or Space on the focused handle, opens Street View at the map's centre through the same gates. Escape while the handle is held ends the drag with no drop.
- Given neither a key nor an `onDrop`, it renders nothing. `@googlemaps/js-api-loader` is an optional peer reached through a dynamic import: an app that never mounts the control never installs it. A drop with a key and no loader installed is refused like a drop where Google holds no imagery; `onError` names the install.
- `checkStreetViewCoverage([lng, lat], key)` asks the coverage question for a part of your own; `loadStreetViewLibrary(key)` configures the Maps JavaScript API once before you draw a panorama yourself.

### Build a control of your own

Five primitives make a control indistinguishable from the built-ins: `ControlButton`, `ControlGroup`, `ControlTooltip`, `Glyph` and `OptionRow`.

```tsx
import { ControlButton, MapControls } from "@mountaya/elements-react";

<MapControls>
  <ControlButton glyph="download" label="Print" onClick={() => window.print()} />
</MapControls>;
```

Icons, strings and colours come from the provider: see [Customize the elements](https://docs.mountaya.com/en/sdks/typescript/customize.md).

- `ControlButton` is the square chip; `ControlGroup` joins adjacent chips into one raised group; `ControlTooltip` draws the control's name and the dimmed line under it; `Glyph` renders one icon from the provider's set; `OptionRow` is a selectable line in a panel.
- A control of your own reads the camera through `useCamera()`, `useBearing()`, `useZoom()` or `useZoomAtLeast(threshold)` ([hooks](https://docs.mountaya.com/en/sdks/typescript/reference/hooks.md#elements-react-headless)).

## Choose terrains, points of interest and units

Three panels open from the stack. Each takes its options through a prop named after it:

```tsx
import { useState } from "react";
import { defaultUnits, type UnitFormatOptions } from "@mountaya/elements/profile";
import { MapControls } from "@mountaya/elements-react";

// One row for water, drawn by the drinking-water points of interest.
const water = [{ id: "water", keys: ["drinking-water"], label: "Water" }];

export const Controls = () => {
  const [units, setUnits] = useState<UnitFormatOptions>({ ...defaultUnits, length: "metric" });

  return (
    <MapControls
      layersPanel={{ thumbnail: (kind, slug) => `/layers/${kind}/${slug}.webp` }}
      poiPanel={{ groups: water, minZoom: 12 }}
      pois
      preferencesPanel={{ onPreferencesChange: setUnits, preferences: units }}
    />
  );
};
```

The points-of-interest panel offers one `water` row, and the units start metric. Mount a panel on its own when it belongs in a sidebar or a settings drawer.

- `LayersPanel` picks the base map and the overlays above it, in four sections: the base maps as picture cards, the enrichments as switches, the classic overlays as picture cards one category at a time behind a category switch, and the time where `offersTime` is set. Base maps replace one another, classic overlays replace one another across every category, and enrichments stack. The sections are `layersPanelSections` of `@mountaya/elements/layers`.
- `thumbnail(kind, slug)` answers a card's picture URL, called with `"terrain"` or `"overlay"` and the catalogue slug. The package ships no picture. A layer with none, or whose picture fails to load, draws a neutral placeholder. An enrichment is a switch and draws none.
- `isLocked(slug)` on `layersPanel` marks what the viewer's agreement does not include, and is display only: the Tile API answers `403` whatever a picker shows. It lets an app that knows the viewer's agreement say so before the press; `onLockedClick` hears a locked card pressed.
- Every word is in the provider's language: each terrain, category and overlay by the catalogue's name for that language, then English, then the slug.
- `useMountayaLayers()` is the selection behind the panel, for a picker of your own: the manifest, the terrains, the categories, the selected `terrain`, `overlay`, `enrichments` and `instant`, the last `error`, and `setTerrain`, `setOverlay` (the slug already selected clears it), `toggleEnrichment` and `setInstant`. One selection per map, shared by every caller under it, and kept while a panel closes and opens.
- `PoiPanel` toggles what the points-of-interest overlay draws. A group is data: `groups` stands one row (`id`, `label`, `keys`, optional `glyph`) for one or more manifest keys, and `elements-react` publishes no built-in group. The `water` group above is the studio's own (`POI_GROUPS` of `@mountaya/studio`: `water` is drawn by the manifest key `drinking-water`; the others are `toilets`, `parking`, `health`, `lodging`, `food`, `viewpoints`). `keys` shows fewer rows without grouping, `labels` names a key, `activeGroups` with `onToggleGroup` owns the state, `minZoom` names the zoom below which the overlay draws nothing, and `showAllToggle` adds a master row.
- `PreferencesPanel` requires `onPreferencesChange`; where the units live (a profile row, a cookie, a store) is yours. Seed from `defaultUnits` (`@mountaya/elements/profile`): every field of `UnitFormatOptions` is required, and a partial value round-tripped through storage reverts the reader's units without saying so.
- A stack holds what it is not handed: with `preferences` and no `preferencesPanel` it keeps the preference set itself, starting from `defaultUnits` in the provider's language, and shares it with nothing else. Pass `preferencesPanel` with your own value for the profile and the tables to read the same units.

## Move through time

Weather overlays change with the hour. Draw the `snow-depth` overlay, and `offersTime` adds a time slider to the layers panel:

```tsx
import { MapControls, MapView } from "@mountaya/elements-react";

<MapView client={client} onReady={(map) => void map.setOverlay("snow-depth")}>
  <MapControls layersPanel={{ offersTime: true }} />
</MapView>;
```

The map then draws the snow depth for the hour the reader picks. Back on now, it follows the clock again.

- The slider runs over the hours from three days back to six days ahead of the provider's `clock`, with a tick every day. Its release pins that hour's instant on the layers selection; a release on now pins none. The readout states the moment and its offset from now, in the device's time zone.
- Offer it only where your organization's agreement includes the Tile API's time control. Without it the API refuses every tile asked for more than 15 minutes from now, and the map reports each refusal through `onAccessRequired`.
- `offersTime` defaults to `false`. Only the classic overlay whose time the server resolves (`capabilities.server.timestamp` in the catalogue) is asked for the pinned instant; an enrichment and a client-timed overlay draw as the manifest writes them.
- For a time control of your own, `useMountayaLayers()` answers `instant` (`Date | null`) and `setInstant(date | null)`; on a map you hold, `await map.setInstant(date)` and `map.getInstant()`. `null`, or an Invalid Date, pins none, and the map draws the server's present.

## Next steps

- [Search](https://docs.mountaya.com/en/sdks/typescript/search.md): Places, itineraries and zones in one box.
- [Customize the elements](https://docs.mountaya.com/en/sdks/typescript/customize.md): Icons, strings and theme tokens.
- [Show a map](https://docs.mountaya.com/en/sdks/typescript/map.md): The map under the stack.
- [Tile API](https://docs.mountaya.com/en/apis/tiles.md): The terrains and overlays these panels switch.
