

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# マップにコントロールを追加する方法
<a name="how-to-add-control-on-map"></a>

Amazon Location Service では、ナビゲーション、位置情報、全画面表示、スケール、属性など、複数のコントロールをマップに追加できます。
+ **ナビゲーションコントロール**: ズームボタンとコンパスが含まれています。
+ **Geolocate コントロール**: ブラウザの geolocation API を使用してマップ上のユーザーを見つけるボタンを提供します。
+ **全画面コントロール**: マップを全画面モードで切り替えるボタンが含まれています。
+ **スケールコントロール**: マップ上の距離と地面上の対応する距離の比率を表示します。
+ **属性コントロール**: マップの属性情報を表示します。デフォルトでは、属性コントロールが展開されます (マップ幅に関係なく)。

コントロールは、左上、左下、右下、または右上のマップの任意の隅に追加できます。

## マップコントロールの追加
<a name="add-map-controls"></a>

次の例では、前述のマップコントロールを追加します。

### マップコントロールコードの例
<a name="web-code-example"></a>

------
#### [ index.html ]

```
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Map Controls</title>
        <meta property="og:description" content="Initialize a map in an HTML element with MapLibre GL JS." />
        <meta charset='utf-8'>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel='stylesheet' href='https://unpkg.com/maplibre-gl@5.x/dist/maplibre-gl.css' />
        <link rel='stylesheet' href='style.css' />
        <script src='https://unpkg.com/maplibre-gl@5.x/dist/maplibre-gl.js'></script>
    </head>
    <body>
        <!-- Map container -->
        <div id="map"></div>
        <script>
            const apiKey = "<API_KEY>";
            const mapStyle = "Standard"; // e.g., Standard, Monochrome, Hybrid, Satellite
            const awsRegion = "eu-central-1"; // e.g., us-east-2, us-east-1, us-west-2, etc.
            const styleUrl = `https://maps.geo.${awsRegion}.amazonaws.com/v2/styles/${mapStyle}/descriptor?key=${apiKey}`;

            const map = new maplibregl.Map({
                container: 'map', // container id
                style: styleUrl, // style URL
                center: [-123.13203602550998, 49.28726257639254], // starting position [lng, lat]
                zoom: 10, // starting zoom
                attributionControl: false, // hide default attributionControl in bottom left
            });

            // Adding controls to the map
            map.addControl(new maplibregl.NavigationControl()); // Zoom and rotation controls
            map.addControl(new maplibregl.FullscreenControl()); // Fullscreen control
            map.addControl(new maplibregl.GeolocateControl()); // Geolocation control
            map.addControl(new maplibregl.AttributionControl(), 'bottom-left'); // Attribution in bottom-left
            map.addControl(new maplibregl.ScaleControl(), 'bottom-right'); // Scale control in bottom-right
        </script>
    </body>
</html>
```

------
#### [ style.css ]

```
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
```

------

## デベロッパー向けのヒント
<a name="developer-tips"></a>

### ナビゲーションコントロールのオプション
<a name="navigationcontrol-options"></a>

```
new maplibregl.NavigationControl({ 
    showCompass: true, // show or hide compass (default: true)
    showZoom: true // show or hide zoom controls (default: true)
});
```

### Geolocate コントロールのオプション
<a name="geolocatecontrol-options"></a>

```
new maplibregl.GeolocateControl({ 
    positionOptions: { enableHighAccuracy: true }, // default: false
    trackUserLocation: true // default: false
});
```

### 属性コントロールのオプション
<a name="attributioncontrol-options"></a>

```
new maplibregl.AttributionControl({
    compact: true, // compact (collapsed) mode (default: false)
});
```

### スケールコントロールのオプション
<a name="scalecontrol-options"></a>

```
new maplibregl.ScaleControl({ 
    maxWidth: 100, // width of the scale (default: 50)
    unit: 'imperial' // imperial or metric (default: metric)
});
```

### 全画面コントロールのオプション
<a name="fullscreencontrol-options"></a>

```
map.addControl(new maplibregl.FullscreenControl({
    container: document.querySelector('body') // container for fullscreen mode
}));
```