---
title: "symbol"
description: "用 MapboxLayer 的 symbol 类型渲染文字与图标标注，layout 读取要素属性。"
seo_title: "Symbol Layer"
seo_description: "Render text and icon labels with MapboxLayer type=\"symbol\", reading feature properties via text-field and layout expressions."
canonical_url: "https://mapbox.mhaibaraai.cn/docs/layers/symbol"
---
# symbol

> 用 MapboxLayer 的 symbol 类型渲染文字与图标标注，layout 读取要素属性。

## 简介

`MapboxLayer` 设 `type="symbol"` 渲染文字/图标标注：`text-field` 经 `['get', ...]` 读取属性，`text-size` / `text-offset` 等 layout 控制排布（图标需先经 [useMapboxImage](/docs/composables/use-mapbox-image) 注册）。

> \[\!NOTE\]
> See: /docs/core/layer
> 
> symbol 由通用组件 MapboxLayer 承载，完整 Props 与事件见其文档。

## 用法

按属性渲染文字标注，带描边便于深浅底图阅读：

```vue [LayerSymbolExample.vue]
<script setup lang="ts">
import type { FeatureCollection } from 'geojson'

const data: FeatureCollection = {
  type: 'FeatureCollection',
  features: [
    { type: 'Feature', properties: { name: '天安门' }, geometry: { type: 'Point', coordinates: [116.397, 39.908] } },
    { type: 'Feature', properties: { name: '国贸' }, geometry: { type: 'Point', coordinates: [116.461, 39.909] } },
    { type: 'Feature', properties: { name: '中关村' }, geometry: { type: 'Point', coordinates: [116.316, 39.983] } }
  ]
}
</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.39, 39.93], zoom: 11 }">
      <!-- text-field 读取属性渲染文字标注，无需注册图标 -->
      <MapboxLayer
        layer-id="labels"
        type="symbol"
        :source="{ type: 'geojson', data }"
        :layout="{
          'text-field': ['get', 'name'],
          'text-size': 14,
          'text-offset': [0, 0.6],
          'text-anchor': 'top'
        }"
        :paint="{ 'text-color': '#1f2937', 'text-halo-color': '#fff', 'text-halo-width': 1.5 }"
      />
    </MapboxMap>
  </div>
</template>
```

## API

### Props

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

## Changelog

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


## Sitemap

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