fill
用 MapboxLayer 的 fill 类型渲染面图层,经 paint 控制填充色与透明度,支持数据驱动着色。
简介
MapboxLayer 设 type="fill" 渲染面图层,fill-color / fill-opacity 控制样式,配合 ['get', ...] 表达式可逐要素着色。
用法
两个多边形按属性 c 取色:
<script setup lang="ts">
import type { FeatureCollection } from 'geojson'
const data: FeatureCollection = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: { c: '#3b82f6' },
geometry: {
type: 'Polygon',
coordinates: [
[
[116.34, 39.96],
[116.4, 39.96],
[116.4, 39.91],
[116.34, 39.91],
[116.34, 39.96]
]
]
}
},
{
type: 'Feature',
properties: { c: '#f59e0b' },
geometry: {
type: 'Polygon',
coordinates: [
[
[116.41, 39.94],
[116.47, 39.94],
[116.47, 39.89],
[116.41, 39.89],
[116.41, 39.94]
]
]
}
}
]
}
</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.4, 39.92], zoom: 11 }"
>
<!-- fill-color 用 ['get'] 读取要素属性,逐要素着色 -->
<MapboxLayer
layer-id="zones"
type="fill"
:source="{ type: 'geojson', data }"
:paint="{ 'fill-color': ['get', 'c'], 'fill-opacity': 0.4 }"
/>
</MapboxMap>
</div>
</template>
API
Props
| Prop | Default | Type |
|---|---|---|
layerId | string图层 id,全局唯一 | |
type | "symbol" | "fill" | "line" | "circle" | "heatmap" | "fill-extrusion" | "building" | "raster" | "raster-particle" | "hillshade" | "model" | "background" | "sky" | "slot" | "clip"图层类型,决定渲染方式与可用的 paint / layout 属性 | |
source | string | mapboxgl.VectorSourceSpecification | mapboxgl.RasterSourceSpecification | mapboxgl.RasterDEMSourceSpecification | mapboxgl.RasterArraySourceSpecification | mapboxgl.GeoJSONSourceSpecification | mapboxgl.VideoSourceSpecification | mapboxgl.ImageSourceSpecification | mapboxgl.ModelSourceSpecificationsource id 字符串引用,或内联 source 对象(自动创建匿名源并随图层卸载) | |
sourceLayer | string矢量瓦片源内的子图层名(source-layer),消费矢量源时必填 | |
paint | PropBag绘制样式属性,响应式变更经 setPaintProperty 增量下发 | |
layout | PropBag布局属性,响应式变更经 setLayoutProperty 增量下发 | |
filter | mapboxgl.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)[]过滤表达式,仅渲染匹配的要素 | |
minzoom | 0 | number最小缩放级别,低于此级别不渲染 |
maxzoom | 24 | number最大缩放级别,高于此级别不渲染 |
beforeId | string插入到该 id 图层之前;省略则追加到图层栈顶部 |
Changelog
No recent changes