How to add control on the map
Amazon Location Service allows you to add multiple controls to the map, including navigation, geolocation, fullscreen, scale, and attribution controls.
-
Navigation control: Contains zoom buttons and a compass.
-
Geolocate control: Provides a button that uses the browser's geolocation API to locate the user on the map.
-
Fullscreen control: Contains a button for toggling the map in and out of fullscreen mode.
-
Scale control: Displays the ratio of a distance on the map to the corresponding distance on the ground.
-
Attribution control: Presents the map's attribution information. By default, the attribution control is expanded (regardless of map width).
You can add the controls to any corner of the map: top-left, bottom-left, bottom-right, or top-right.
Adding map controls
In the following example, you'll add the map controls listed above.
Developer tips
new maplibregl.NavigationControl({ showCompass: true, // show or hide compass (default: true) showZoom: true // show or hide zoom controls (default: true) });
new maplibregl.GeolocateControl({ positionOptions: { enableHighAccuracy: true }, // default: false trackUserLocation: true // default: false });
new maplibregl.AttributionControl({ compact: true, // compact (collapsed) mode (default: false) });
new maplibregl.ScaleControl({ maxWidth: 100, // width of the scale (default: 50) unit: 'imperial' // imperial or metric (default: metric) });
map.addControl(new maplibregl.FullscreenControl({ container: document.querySelector('body') // container for fullscreen mode }));