---
title: "MapboxBufferPolygon"
description: "多边形缓冲区，向外扩展或负值向内收缩指定米宽。"
seo_title: "MapboxBufferPolygon Component"
seo_description: "MapboxBufferPolygon expands (or shrinks with negative width) a polygon by a meter distance, rendered as fill and line layers via Turf.js."
canonical_url: "https://mapbox.mhaibaraai.cn/docs/layers/buffer-polygon"
---
# MapboxBufferPolygon

> 多边形缓冲区，向外扩展或负值向内收缩指定米宽。

## 简介

`MapboxBufferPolygon` 把面要素向外扩展 `width` 米（负值向内收缩），`polygon` 接受面要素、几何或外环坐标数组。

## 用法

拖动滑块在扩展与收缩间切换：

```vue [BufferPolygonExample.vue]
<script setup lang="ts">
const polygon: [number, number][] = [
  [116.38, 39.94],
  [116.44, 39.94],
  [116.44, 39.89],
  [116.38, 39.89],
  [116.38, 39.94]
]
const width = ref(800)
</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.41, 39.915], zoom: 11 }">
      <div class="absolute left-3 top-3 z-10 flex items-center gap-2 rounded-(--ui-radius) border border-default bg-default/80 px-3 py-1.5 backdrop-blur">
        <span class="text-sm text-muted">宽度 {{ width }}m</span>
        <USlider v-model="width" :min="-400" :max="1500" :step="100" class="w-32" />
      </div>
      <!-- 正值向外扩展、负值向内收缩 -->
      <MapboxBufferPolygon :polygon="polygon" :width="width" color="#8b5cf6" />
    </MapboxMap>
  </div>
</template>
```

## API

### Props

```ts
/**
 * Props for the MapboxBufferPolygon component
 */
interface MapboxBufferPolygonProps {
  /**
   * 面要素、几何或外环坐标数组
   */
  polygon: GeoJSON.Polygon | GeoJSON.Feature<GeoJSON.Polygon, GeoJSON.GeoJsonProperties> | [number, number][];
  /**
   * 缓冲宽度（米），负值向内收缩
   */
  width: number;
  /**
   * 图层 id 前缀；省略时自动生成
   */
  layerId?: string | undefined;
  /**
   * 主色（快捷样式）
   */
  color?: string | undefined;
  /**
   * 整体覆盖填充 paint
   */
  fillPaint?: Record<string, unknown> | undefined;
  /**
   * 整体覆盖描边 paint
   */
  linePaint?: Record<string, unknown> | undefined;
  /**
   * 插入到该图层之前
   */
  beforeId?: string | undefined;
}
```

## Changelog

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


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
