Showing Map Controls
By default, a dynamic map has no controls. You can add zoom buttons, a fullscreen button, a scale bar, or a button to find the visitor's location, by switching them on in the mapOptions parameter.
const options = {
'mapOptions': {
'navigationControl': true,
'fullscreenControl': true,
'scaleControl': true,
'geolocateControl': true
}
};
const map = mapbox.map(locations, options);
Include only the controls you want. Each one is off unless you switch it on.
| Option | Control |
|---|---|
navigationControl | Zoom buttons and a compass. (options (opens new window)) |
fullscreenControl | A button to view the map in fullscreen. (options (opens new window)) |
scaleControl | A scale bar. (options (opens new window)) |
geolocateControl | A button to find the visitor's location. (options (opens new window)) |
# Customizing a Control
Instead of true, you can pass an object of that control's options. Add a position to move it to a different corner of the map (top-left, top-right, bottom-left, or bottom-right).
const options = {
'mapOptions': {
'navigationControl': {
'showCompass': false,
'position': 'top-left'
}
}
};