---
title: "MapboxBuildingLayer"
description: "3D 建筑图层，挤出官方样式的 composite/building 矢量源，可调颜色、透明度与起始缩放。"
seo_title: "MapboxBuildingLayer Component"
seo_description: "MapboxBuildingLayer extrudes the official composite/building vector source into 3D buildings with configurable color, opacity and minzoom."
canonical_url: "https://mapbox.mhaibaraai.cn/docs/layers/building"
---
# MapboxBuildingLayer

> 3D 建筑图层，挤出官方样式的 composite/building 矢量源，可调颜色、透明度与起始缩放。

## 简介

`MapboxBuildingLayer` 把 Mapbox 官方样式自带的 `composite` / `building` 矢量源挤出为 3D 建筑，封装好高度表达式，开放 `color` / `opacity` / `minzoom` 快捷设置。

> \[\!NOTE\]
> 
> 依赖官方样式的 
> 
> composite/building
> 
>  源，天地图等空样式下无效；需地图 
> 
> pitch
> 
>  与较高 
> 
> zoom
> 
> （默认 minzoom 15）才能看到建筑。

## 用法

俯仰视角下渲染城市 3D 建筑：

```vue [BuildingLayerExample.vue]
<script setup lang="ts">
// MapboxBuildingLayer 默认消费官方样式的 composite/building 矢量源
</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.461, 39.909], zoom: 15.5, pitch: 60, bearing: -20 }">
      <MapboxBuildingLayer color="#94a3b8" :opacity="0.85" />
    </MapboxMap>
  </div>
</template>
```

## API

### Props

```ts
/**
 * Props for the MapboxBuildingLayer component
 */
interface MapboxBuildingLayerProps {
  /**
   * 图层 id；省略时自动生成
   */
  layerId?: string | undefined;
  /**
   * 矢量数据源 id
   */
  source?: string | undefined;
  /**
   * 数据源图层名
   */
  sourceLayer?: string | undefined;
  /**
   * 建筑颜色
   */
  color?: string | undefined;
  /**
   * 整体透明度
   */
  opacity?: number | undefined;
  /**
   * 显示建筑的最小缩放级别
   */
  minzoom?: number | undefined;
  /**
   * 整体覆盖 paint（提供时忽略 color/opacity 预设）
   */
  paint?: Record<string, unknown> | undefined;
  /**
   * 插入到该图层之前
   */
  beforeId?: string | undefined;
}
```

## Changelog

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


## Sitemap

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