@cniot/mapbox-gl-draw-circle

中文文档
1.2.0发布于 2025/05/12MITCommonJS近 30 天下载 1805

A module to draw a circle using mapbox-gl-draw, support vite

原始使用文档
文档目录5 节
  1. Demo
  2. Usage
  3. Installation
  4. Changelog
  5. v1.1.0

mapbox-gl-draw-circle

Adds support for drawing and editing a circle feature using mapbox-gl-draw library.

Demo

Circle mode

Circle Mode Demo

Drag Circle mode

Drag Circle Mode Demo

Usage

Installation

npm install mapbox-gl-draw-circle
import {
    CircleMode,
    DragCircleMode,
    DirectMode,
    SimpleSelectMode
} from 'mapbox-gl-draw-circle';


// userProperties has to be enabled
const draw = new MapboxDraw({
  defaultMode: "draw_circle",
  userProperties: true,
  modes: {
    ...MapboxDraw.modes,
    draw_circle  : CircleMode,
    drag_circle  : DragCircleMode,
    direct_select: DirectMode,
    simple_select: SimpleSelectMode
  }
});

// Add this draw object to the map when map loads
map.addControl(draw);

The default radius units are in kilometers and initial radius is 2km.

// Provide the default radius as an option to CircleMode
draw.changeMode('draw_circle', { initialRadiusInKm: 0.5 });

It fires the same events as the mapbox-gl-draw library. For more information follow this link.

Sample feature object returned in draw.create event

{
  "id": "e184898e58feaa5c2c56f20a178ffe2c",
  "type": "Feature",
  "properties": {
    "isCircle": true,
    "center": [
      -0.2472604947478203,
      51.53200220026099
    ],
    "radiusInKm": 2
  },
  "geometry": {
    "coordinates": [], // populated with 64 vertices used to render the circle
    "type": "Polygon"
  }
}

Changelog

v1.1.0

  • Added a new DragCircle mode.
  • Fixed issue (#5), where the polygon mode was not working when used along with CircleMode.

版本与发布记录

@cniot/mapbox-gl-draw-circle 共发布 1 个版本,首次发布于 2025/05/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.0latest2025/05/121.5 年前

关于 @cniot/mapbox-gl-draw-circle 的常见问题

@cniot/mapbox-gl-draw-circle 是什么?

A module to draw a circle using mapbox-gl-draw, support vite

如何安装 @cniot/mapbox-gl-draw-circle?

在项目目录运行 npm install @cniot/mapbox-gl-draw-circle,或使用 pnpm add / yarn add / bun add。

@cniot/mapbox-gl-draw-circle 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/cniot__mapbox-gl-draw-circle 是否存在。

@cniot/mapbox-gl-draw-circle 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cniot/mapbox-gl-draw-circle 可以商用吗?

@cniot/mapbox-gl-draw-circle 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cniot/mapbox-gl-draw-circle 的下载量有多少?

根据 npm 官方下载统计,@cniot/mapbox-gl-draw-circle 在 2026/10/10 – 2026/11/08 这 30 天内被下载 1,805 次,日均约 60 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cniot/mapbox-gl-draw-circle 还在维护吗?

最新版本 1.2.0 发布于 2025/05/12(1.5 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/05/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。