Skip to content

BufferCircleLayer

Supports drag-and-drop to change position, drag-and-drop to resize, real-time radius display, and other features.

TIP

  • The MbBufferCircleLayerV2 component uses a planar pixel algorithm to draw circles, which solves the circle distortion problem in coordinate systems such as 4490 and 4326.
  • The MbBufferCircleLayer component uses turf.circle to draw circles. It can still be used in the 3857 coordinate system.

Example

Example Source Code
tsx
import React, { useEffect, useRef, useState } from 'react'
import ReactDOM from 'react-dom'
import { MbBufferCircleLayer, MbMap, MbTiandituLayer } from '@mapbox-react/core'

const App = () => {
  const [mapCenter] = useState([116.10381, 39.92155464])
  const [zoom, setZoom] = useState(10)

  return (
    <div className="map-wrapper">
      <MbMap
        center={mapCenter}
        zoom={zoom}
        glyphs="https://mapbox-web.github.io/mapbox-react/fonts/{fontstack}/{range}.pbf"
        sprite="https://mapbox-web.github.io/mapbox-react/sprites/sprite"
      >
        <MbTiandituLayer types={['vec']} />
        <MbBufferCircleLayer
          center={mapCenter}
          radius={8}
          borderColor="blue"
          borderOpacity={0.5}
          backgroundColor="blue"
          centerColor="black"
          resizerColor="blue"
          backgroundOpacity={0.1}
          closable={true}
          countable={true}
          draggable={true}
          resizable={true}
        />
      </MbMap>
    </div>
  )
}

ReactDOM.render(<App />, document.querySelector('#root'))

EPSG:4490(CGCS2000)

Example Source Code
tsx
import React, { useEffect, useRef, useState } from 'react'
import ReactDOM from 'react-dom'
import {
  MbBufferCircleLayer,
  MbBufferCircleLayerV2,
  MbMap,
  MbTiandituLayer,
} from '@mapbox-react/core'

const App = () => {
  const [mapCenter] = useState([116.10381, 39.92155464])
  const [zoom, setZoom] = useState(10)

  return (
    <div className="map-wrapper">
      <MbMap
        center={mapCenter}
        zoom={zoom}
        crs="EPSG:4490"
        glyphs="https://mapbox-web.github.io/mapbox-react/fonts/{fontstack}/{range}.pbf"
        sprite="https://mapbox-web.github.io/mapbox-react/sprites/sprite"
      >
        <MbTiandituLayer types={['vec']} />
        <MbBufferCircleLayer
          center={mapCenter}
          radius={8}
          borderColor="blue"
          borderOpacity={0.5}
          backgroundColor="blue"
          centerColor="black"
          resizerColor="blue"
          backgroundOpacity={0.1}
          closable={true}
          countable={true}
          draggable={true}
          resizable={true}
        />
        <MbBufferCircleLayerV2
          center={mapCenter}
          radius={8}
          borderColor="blue"
          borderOpacity={0.5}
          backgroundColor="blue"
          centerColor="black"
          resizerColor="blue"
          backgroundOpacity={0.1}
          closable={true}
          countable={true}
          draggable={true}
          resizable={true}
        />
      </MbMap>
    </div>
  )
}

ReactDOM.render(<App />, document.querySelector('#root'))

API

PROPS

NameDescriptionTypeDefault
idLayer IDstring-
centerBuffer center pointnumber[]-
radiusBuffer radius, in kilometersnumber10
borderColorBorder colorstringblue
borderOpacityBorder opacitynumber0.5
borderWidthBorder widthnumber5
backgroundColorBackground colorstringblue
backgroundOpacityBackground opacitynumber0.1
resizerColorResizer icon colorstringblack
centerColorCenter point icon colorstringred
closableWhether to display the close iconbooleanfalse
countableWhether to display the radius value as text. You need to load Mapbox font filesbooleanfalse
resizableWhether to display the resizer iconbooleanfalse
draggableWhether the buffer is draggablebooleanfalse
visibleWhether to display the bufferbooleantrue
resizerRadiusResizer icon circle radiusnumber8
centerRadiusCenter point icon circle radiusnumber8
textFontsFont settings for countable textstring[]['Open Sans Regular']
textColorColor of the countable text.string#000000
textSizeSize of the countable textnumber16
formatterFormatter for the countable textfunction(radius) => string
closeSizeScaling factor for the close iconnumber0.7
closeOffsetOffset of the close iconnumber[][70, 0]
closeIconUrlURL of a custom close iconstring-

EVENTS

NameDescriptionParameters
onUpdateTriggered when the buffer is changedParameters:{center,radius}
onCloseTriggered when the close operation is clickedMapMouseEvent
onMouseEnterTriggered when the mouse enters the buffer-
onMouseLeaveTriggered when the mouse leaves the buffer-

METHODS

NameDescriptionDefinition