---
title: "MaplibreBuildingLayer"
description: "3D 建筑图层，按要素高度属性挤出矢量瓦片或 GeoJSON 建筑面，可调颜色、透明度与起始缩放。"
canonical_url: "https://maplibre.mhaibaraai.cn/docs/layers/building"
---
# MaplibreBuildingLayer

> 3D 建筑图层，按要素高度属性挤出矢量瓦片或 GeoJSON 建筑面，可调颜色、透明度与起始缩放。

## 简介

`MaplibreBuildingLayer` 把 `source`（及矢量瓦片的 `sourceLayer`）中的建筑面挤出为 3D 建筑，封装好高度表达式，开放 `color` / `opacity` / `minzoom` 快捷设置。高度字段默认对齐 OpenMapTiles 规范的 `render_height` / `render_min_height`，可经 `heightProperty` / `baseProperty` 调整。

> [!NOTE]
> 
> 需提供含建筑高度属性的数据源（示例使用 OpenFreeMap 样式自带的 
> 
> openmaptiles
> 
>  源）；需地图 
> 
> pitch
> 
>  与较高 
> 
> zoom
> 
> （默认 minzoom 15）才能看到建筑。

## 用法

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

```vue [BuildingLayerExample.vue]
<script setup lang="ts">
// OpenFreeMap 样式自带 openmaptiles 矢量源，建筑高度字段为 render_height
</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.461, 39.909], zoom: 15.5, pitch: 60, bearing: -20 }">
      <MaplibreBuildingLayer source="openmaptiles" source-layer="building" color="#94a3b8" :opacity="0.85" />
    </MaplibreMap>
  </div>
</template>
```

## API

### Props

```ts
/**
 * Props for the MaplibreBuildingLayer component
 */
interface MaplibreBuildingLayerProps {
  /**
   * 数据源 id（需已由 MaplibreSource 或样式声明）
   */
  source: string;
  /**
   * 矢量瓦片中的图层名（如 OpenMapTiles 的 'building'）；GeoJSON 源省略
   */
  sourceLayer?: string | undefined;
  /**
   * 建筑高度属性名
   * @default 'render_height'
   */
  heightProperty?: string | undefined;
  /**
   * 建筑底面高度属性名
   * @default 'render_min_height'
   */
  baseProperty?: string | undefined;
  /**
   * 图层 id；省略时自动生成，变更需配合 `:key` 重建
   */
  layerId?: string | undefined;
  /**
   * 建筑颜色
   * @default '#aaa'
   */
  color?: string | undefined;
  /**
   * 整体透明度
   * @default 0.8
   */
  opacity?: number | undefined;
  /**
   * 显示建筑的最小缩放级别
   * @default 15
   */
  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-maplibre/commits/main/src/runtime/components/layers/BuildingLayer.vue).


## Sitemap

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