---
title: "circle"
description: "Render circle layers with MapboxLayer type=\"circle\", using an inline GeoJSON source and paint properties to control radius, color, and stroke."
canonical_url: "https://mapbox.mhaibaraai.cn/en/docs/layers/circle"
---
# circle

> Render circle layers with MapboxLayer type="circle", using an inline GeoJSON source and paint properties to control radius, color, and stroke.

## Introduction

Set `type="circle"` on `MapboxLayer` to render a circle layer. The example below passes GeoJSON via an inline `source` and controls radius, color, and stroke through `paint`. When controls are adjusted, reactive `paint` changes only trigger `setPaintProperty` incremental updates.

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

## Usage

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

const props = withDefaults(defineProps<{
  radius?: number
  color?: string
}>(), {
  radius: 10,
  color: '#f43f5e'
})

const data: FeatureCollection = {
  type: 'FeatureCollection',
  features: [
    { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [116.397, 39.908] } },
    { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [116.45, 39.93] } },
    { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [116.35, 39.88] } }
  ]
}

// paint 随 props 响应：仅触发 setPaintProperty 增量更新，不重建图层
const paint = computed(() => ({
  'circle-radius': props.radius,
  'circle-color': props.color,
  'circle-stroke-width': 2,
  'circle-stroke-color': '#fff'
}))
</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.9], zoom: 11 }">
      <MapboxLayer
        layer-id="points"
        type="circle"
        :source="{ type: 'geojson', data }"
        :paint="paint"
      />
    </MapboxMap>
  </div>
</template>
```

## Examples

### Data-driven Styling

Use expressions in `paint` to map feature properties to radius and color tiers, enabling data-driven styling:

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

// 每个点带 value 属性，paint 用表达式按属性分级映射半径与颜色
const data: FeatureCollection = {
  type: 'FeatureCollection',
  features: Array.from({ length: 40 }, (_, i) => ({
    type: 'Feature',
    properties: { value: (i * 37) % 100 },
    geometry: {
      type: 'Point',
      coordinates: [116.2 + ((i * 13) % 40) / 100, 39.8 + ((i * 29) % 25) / 100]
    }
  }))
}

const paint = {
  'circle-radius': ['interpolate', ['linear'], ['get', 'value'], 0, 4, 100, 20],
  'circle-color': ['interpolate', ['linear'], ['get', 'value'], 0, '#3b82f6', 50, '#f59e0b', 100, '#ef4444'],
  'circle-opacity': 0.85
}
</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.9], zoom: 10 }">
      <MapboxLayer
        layer-id="graduated"
        type="circle"
        :source="{ type: 'geojson', data }"
        :paint="paint"
      />
    </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](https://mapbox.mhaibaraai.cn/sitemap.md) for all pages.
