---
title: "fill"
description: "Render polygon layers with MaplibreLayer type=\"fill\", controlling fill color and opacity through paint properties, with support for data-driven coloring."
canonical_url: "https://maplibre.mhaibaraai.cn/en/docs/layers/fill"
---
# fill

> Render polygon layers with MaplibreLayer type="fill", controlling fill color and opacity through paint properties, with support for data-driven coloring.

## Introduction

Set `type="fill"` on `MaplibreLayer` to render a polygon layer. `fill-color` and `fill-opacity` control the style; combine with `['get', ...]` expressions to color each feature individually.

> [!NOTE]
> See: /docs/core/layer
> 
> Fill layers are powered by the generic MaplibreLayer component. See its documentation for full Props and events reference.

## Usage

Two polygons colored by their `c` property:

```vue [LayerFillExample.vue]
<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.40, 39.96], [116.40, 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">
    <MaplibreMap :options="{ style: 'https://tiles.openfreemap.org/styles/positron', center: [116.4, 39.92], zoom: 11 }">
      <!-- fill-color 用 ['get'] 读取要素属性，逐要素着色 -->
      <MaplibreLayer
        layer-id="zones"
        type="fill"
        :source="{ type: 'geojson', data }"
        :paint="{ 'fill-color': ['get', 'c'], 'fill-opacity': 0.4 }"
      />
    </MaplibreMap>
  </div>
</template>
```

## API

### Props

```ts
/**
 * Props for the MaplibreLayer component
 */
interface MaplibreLayerProps {
  /**
   * 图层 id，全局唯一；变更需配合 `:key` 重建
   */
  layerId: string;
  /**
   * 图层类型，决定渲染方式与可用的 paint / layout 属性；变更需配合 `:key` 重建
   */
  type: "symbol" | "fill" | "line" | "circle" | "heatmap" | "fill-extrusion" | "raster" | "hillshade" | "color-relief" | "background";
  /**
   * source id 字符串引用，或内联 source 对象（自动创建匿名源并随图层卸载，内容变化时增量更新）；二者之间切换需配合 `:key` 重建
   */
  source?: string | SourceSpecification | undefined;
  /**
   * 矢量瓦片源内的子图层名（source-layer），消费矢量源时必填；变更需配合 `:key` 重建
   */
  sourceLayer?: string | undefined;
  /**
   * 绘制样式属性，响应式变更经 setPaintProperty 增量下发
   */
  paint?: PropBag | undefined;
  /**
   * 布局属性，响应式变更经 setLayoutProperty 增量下发
   */
  layout?: PropBag | undefined;
  /**
   * 过滤表达式，仅渲染匹配的要素
   * @default undefined
   */
  filter?: FilterSpecification | undefined;
  /**
   * 最小缩放级别，低于此级别不渲染
   * @default 0
   */
  minzoom?: number | undefined;
  /**
   * 最大缩放级别，高于此级别不渲染
   * @default 24
   */
  maxzoom?: number | undefined;
  /**
   * 插入到该 id 图层之前；省略则追加到图层栈顶部
   */
  beforeId?: string | undefined;
}
```

## Changelog

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


## Sitemap

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