Map Controls¶
The mapControls block in your project's settings.json adds MapLibre's built-in controls to the map's corners: zoom buttons, a "locate me" button, fullscreen, a scale bar, a globe toggle and a terrain toggle. They're separate from the kit's floating widgets, though both can share the same corners.
Include a control's key to add it, and leave the key out to skip it. Without a mapControls block there are no built-in controls.
"mapControls": {
"navigation": { "position": "top-left" },
"geolocate": { "position": "top-right", "trackUserLocation": true },
"globe": { "position": "top-right" }
}
Controls¶
| Key | Control | Default position |
|---|---|---|
navigation |
Zoom +/− buttons and a compass | top-left |
geolocate |
"Locate me" button (browser geolocation) | top-left |
fullscreen |
Toggles browser fullscreen on the map | top-right |
scale |
A distance scale bar | bottom-left |
globe |
Switches between globe and flat (mercator) | top-right |
terrain |
Toggles 3D terrain | top-right |
zoomLevel |
Shows the current zoom, e.g. z 12.4 |
bottom-left |
All seven take an optional position: "top-left" | "top-right" | "bottom-left" | "bottom-right", and an optional order (default 0) that sets their place in the corner: lower comes first. Controls with the same order keep the kit's own order (navigation, geolocate, fullscreen, globe, scale, zoom level, terrain). See Ordering a corner.
Per-control options¶
navigation¶
| Field | Type | Default | Description |
|---|---|---|---|
position |
string |
top-left |
Corner |
showZoom |
boolean |
true |
Show the +/− zoom buttons |
showCompass |
boolean |
true |
Show the compass |
visualizePitch |
boolean |
true |
The compass tilts with the map, and one click on it returns to a flat, north-up view. false gives MapLibre's plain compass, where a click only turns north (MapLibre's own default is false) |
geolocate¶
| Field | Type | Default | Description |
|---|---|---|---|
position |
string |
top-left |
Corner |
trackUserLocation |
boolean |
false |
Keep following the user as they move |
showUserLocation |
boolean |
true |
Show the location dot |
showUserHeading |
boolean |
false |
Show a heading cone |
showAccuracyCircle |
boolean |
true |
Show the accuracy halo |
scale¶
| Field | Type | Default | Description |
|---|---|---|---|
position |
string |
bottom-left |
Corner |
unit |
"metric" \| "imperial" \| "nautical" |
"metric" |
Distance unit |
maxWidth |
number |
none | Max bar width in pixels |
fullscreen and globe¶
Both take only position.
zoomLevel¶
A small read-only readout of the current zoom (z 12.4), updating as the map zooms. Handy when picking a layer's minZoom / maxZoom. It follows the theme and never takes clicks from the map. In the bottom-left corner it stacks above the scale bar.
| Field | Type | Default | Description |
|---|---|---|---|
position |
string |
bottom-left |
Corner |
precision |
number |
1 |
Decimal places shown |
terrain¶
| Field | Type | Default | Description |
|---|---|---|---|
position |
string |
top-right |
Corner |
exaggeration |
number |
1 |
Elevation multiplier. Higher values make terrain more dramatic |
source |
object | AWS terrain tiles | Use a different elevation source (below) |
source.tiles |
string[] |
none | Raster-DEM tile URL templates |
source.url |
string |
none | A TileJSON URL, instead of tiles |
source.encoding |
"terrarium" \| "mapbox" \| "custom" |
"terrarium" |
DEM tile encoding |
source.tileSize |
number |
256 |
Tile size in pixels |
source.maxzoom |
number |
15 |
Highest zoom with real tiles. Past it, MapLibre stretches the last tiles instead of requesting more |
Leave out source to use AWS's public Terrain Tiles (terrarium encoding).
Attribution¶
The map's credits button is always shown, since the data and tile licenses require it; you can't add or remove it, only move it. It starts expanded and collapses once the user pans the map; the "ⓘ" button expands it again.
| Field | Type | Default | Description |
|---|---|---|---|
position |
string |
bottom-right |
Corner |
order |
number |
1000 |
Place in its corner. The high default keeps it at the corner's edge, below (or after) everything else there |
Ordering a corner¶
The built-in controls and the kit's floating widgets share the four map corners, and both take an order on one scale: lower stacks first, from the top in a top corner and from the top of the stack in a bottom one. Everything defaults to 0 except the credits button (1000), and ties keep the controls first, then the floating widgets. Give a floating widget a negative order to lift it above the controls (the demo's search widget does this; see Building a Custom Widget), or give a control a higher one to push it below a widget.