fill-extrusion

View source
用 MapboxLayer 的 fill-extrusion 类型把面挤出为 3D 体块,高度可数据驱动。

简介

MapboxLayertype="fill-extrusion" 把面挤出为 3D 体块,fill-extrusion-height['get', ...] 读取属性逐要素设高;需给地图设 pitch 才能看出立体效果。3D 城市建筑见 building

fill-extrusion 由通用组件 MapboxLayer 承载,完整 Props 与事件见其文档。

用法

两个体块按属性 height 挤出,地图俯仰 55°:

<script setup lang="ts">
import type { FeatureCollection } from 'geojson'

const data: FeatureCollection = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      properties: { height: 800 },
      geometry: {
        type: 'Polygon',
        coordinates: [
          [
            [116.38, 39.92],
            [116.4, 39.92],
            [116.4, 39.9],
            [116.38, 39.9],
            [116.38, 39.92]
          ]
        ]
      }
    },
    {
      type: 'Feature',
      properties: { height: 1600 },
      geometry: {
        type: 'Polygon',
        coordinates: [
          [
            [116.41, 39.93],
            [116.43, 39.93],
            [116.43, 39.91],
            [116.41, 39.91],
            [116.41, 39.93]
          ]
        ]
      }
    }
  ]
}
</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.91],
        zoom: 13,
        pitch: 55
      }"
    >
      <!-- fill-extrusion-height 读取属性挤出 3D 体块 -->
      <MapboxLayer
        layer-id="prisms"
        type="fill-extrusion"
        :source="{ type: 'geojson', data }"
        :paint="{
          'fill-extrusion-color': '#3b82f6',
          'fill-extrusion-height': ['get', 'height'],
          'fill-extrusion-opacity': 0.8
        }"
      />
    </MapboxMap>
  </div>
</template>

API

Props

Prop Default Type
layerIdstring

图层 id,全局唯一

type"symbol" | "fill" | "line" | "circle" | "heatmap" | "fill-extrusion" | "building" | "raster" | "raster-particle" | "hillshade" | "model" | "background" | "sky" | "slot" | "clip"

图层类型,决定渲染方式与可用的 paint / layout 属性

sourcestring | mapboxgl.VectorSourceSpecification | mapboxgl.RasterSourceSpecification | mapboxgl.RasterDEMSourceSpecification | mapboxgl.RasterArraySourceSpecification | mapboxgl.GeoJSONSourceSpecification | mapboxgl.VideoSourceSpecification | mapboxgl.ImageSourceSpecification | mapboxgl.ModelSourceSpecification

source id 字符串引用,或内联 source 对象(自动创建匿名源并随图层卸载)

sourceLayerstring

矢量瓦片源内的子图层名(source-layer),消费矢量源时必填

paintPropBag

绘制样式属性,响应式变更经 setPaintProperty 增量下发

layoutPropBag

布局属性,响应式变更经 setLayoutProperty 增量下发

filtermapboxgl.ExpressionSpecification | ["has", string] | ["!has", string] | ["==", string, string | number | boolean] | ["!=", string, string | number | boolean] | [">", string, string | number | boolean] | [">=", string, string | number | boolean] | ["<", string, string | number | boolean] | ["<=", string, string | number | boolean] | (string | mapboxgl.FilterSpecification)[]

过滤表达式,仅渲染匹配的要素

minzoom0number

最小缩放级别,低于此级别不渲染

maxzoom24number

最大缩放级别,高于此级别不渲染

beforeIdstring

插入到该 id 图层之前;省略则追加到图层栈顶部

Changelog

No recent changes
Copyright © 2026 - 2026 YiXuan - MIT License