---
title: "MapboxNavigationControl"
description: "Navigation control that provides zoom buttons and a compass. Use position to set the dock corner and options to pass through to mapbox-gl."
canonical_url: "https://mapbox.mhaibaraai.cn/en/docs/controls/navigation"
---
# MapboxNavigationControl

> Navigation control that provides zoom buttons and a compass. Use position to set the dock corner and options to pass through to mapbox-gl.

## Introduction

`MapboxNavigationControl` mounts zoom buttons and a compass on the map. `position` sets the dock corner (omit to use the map's default), and `options` is forwarded directly to the mapbox-gl `NavigationControl` constructor (`showZoom` / `showCompass` / `visualizePitch`). The control is mounted when the map is ready and automatically removed when the component unmounts.

## Usage

Adjust `position` to change the dock corner:

```vue [NavigationControlExample.vue]
<script setup lang="ts">
import type { ControlPosition } from 'mapbox-gl'

withDefaults(defineProps<{ position?: ControlPosition }>(), {
  position: 'top-right'
})
</script>

<template>
  <div class="h-115 w-full overflow-hidden rounded-(--ui-radius) border border-default">
    <MapboxMap :options="{ style: 'mapbox://styles/mapbox/light-v11', center: [116.39, 39.91], zoom: 10 }">
      <MapboxNavigationControl :position="position" />
    </MapboxMap>
  </div>
</template>
```

## Examples

### Visualize Pitch

Tilt the map and enable `visualizePitch` — the compass tilts along with the pitch angle to indicate the current view:

```vue [NavigationControlPitchExample.vue]
<template>
  <div class="h-115 w-full overflow-hidden rounded-(--ui-radius) border border-default">
    <MapboxMap
      :options="{
        style: 'mapbox://styles/mapbox/streets-v12',
        center: [116.39, 39.91],
        zoom: 11,
        pitch: 55,
        bearing: -25
      }"
    >
      <!-- visualizePitch 让罗盘随俯仰角倾斜，showZoom 保留缩放按钮 -->
      <MapboxNavigationControl
        position="top-right"
        :options="{ visualizePitch: true, showCompass: true, showZoom: true }"
      />
    </MapboxMap>
  </div>
</template>
```

## API

### Props

```ts
/**
 * Props for the MapboxNavigationControl component
 */
interface MapboxNavigationControlProps {
  /**
   * 控件停靠位置；省略用地图默认位置
   */
  position?: mapboxgl.ControlPosition | undefined;
  /**
   * NavigationControl 构造选项
   */
  options?: mapboxgl.NavigationControlOptions | undefined;
}
```

## Changelog

See commit history for [src/runtime/components/controls/NavigationControl.vue](https://github.com/mhaibaraai/movk-mapbox/commits/main/src/runtime/components/controls/NavigationControl.vue).


## Sitemap

See the full [sitemap](https://mapbox.mhaibaraai.cn/sitemap.md) for all pages.
