---
title: "MaplibreNavigationControl"
description: "导航控件，提供缩放按钮与指北罗盘，position 控制停靠角，options 透传至 maplibre-gl。"
canonical_url: "https://maplibre.mhaibaraai.cn/docs/controls/navigation"
---
# MaplibreNavigationControl

> 导航控件，提供缩放按钮与指北罗盘，position 控制停靠角，options 透传至 maplibre-gl。

## 简介

`MaplibreNavigationControl` 在地图上挂载缩放按钮与指北罗盘。`position` 指定停靠角（省略用地图默认位置），`options` 直通 maplibre-gl 的 `NavigationControl` 构造选项（`showZoom` / `showCompass` / `visualizePitch`）。控件在地图就绪后挂载，组件卸载时自动移除。

## 用法

调整 `position` 切换停靠角：

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

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

<template>
  <div class="h-115 w-full overflow-hidden rounded-(--ui-radius) border border-default">
    <MaplibreMap :options="{ style: 'https://tiles.openfreemap.org/styles/positron', center: [116.39, 39.91], zoom: 10 }">
      <MaplibreNavigationControl :position="position" />
    </MaplibreMap>
  </div>
</template>
```

## 示例

### 可视化俯仰角

倾斜底图后开启 `visualizePitch`，罗盘随俯仰角倾斜以指示视角：

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

## API

### Props

```ts
/**
 * Props for the MaplibreNavigationControl component
 */
interface MaplibreNavigationControlProps {
  /**
   * 控件停靠位置；省略用地图默认位置
   */
  position?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | undefined;
  /**
   * NavigationControl 构造选项
   */
  options?: NavigationControlOptions | undefined;
}
```

## Changelog

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


## Sitemap

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