Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marcosci/mapbox-gl-draw-circle
https://github.com/marcosci/mapbox-gl-draw-circle
Last synced: 28 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/marcosci/mapbox-gl-draw-circle
- Owner: marcosci
- Created: 2024-03-07T15:26:27.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-03-12T07:18:15.000Z (10 months ago)
- Last Synced: 2024-10-24T00:23:08.825Z (2 months ago)
- Language: JavaScript
- Homepage: https://mapbox-gl-draw-circle.vercel.app
- Size: 1.51 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mapbox-gl-draw-circle-mode
[![npm version](https://badge.fury.io/js/mapbox-gl-draw-circle-mode.svg)](https://badge.fury.io/js/mapbox-gl-draw-circle-mode)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)A custom mode for Mapbox GL Draw that enables users to draw circles and see live updates of the circle's diameter.
## Installation
You can install the package via npm:
```bash
npm install mapbox-gl-draw-circle-mode
```## Usage
To use `mapbox-gl-draw-circle-mode`, you need to integrate it with Mapbox GL Draw. Here's a basic example of how to set it up:
```javascript
import mapboxgl from "mapbox-gl";
import MapboxDraw from "@mapbox/mapbox-gl-draw";
import CircleMode, { drawStyles } from "mapbox-gl-draw-circle-mode";mapboxgl.accessToken = "YOUR_MAPBOX_ACCESS_TOKEN";
const map = new mapboxgl.Map({
container: "map",
style: "mapbox://styles/mapbox/streets-v11",
center: [0, 0],
zoom: 2,
});const draw = new MapboxDraw({
modes: {
...MapboxDraw.modes,
draw_circle: CircleMode.CircleMode,
},
displayControlsDefault: false,
controls: {},
styles: drawStyles,
userProperties: true,
});map.addControl(draw);
// Listen for draw.create event to get circle data
map.on("draw.create", function (event) {
if (event.features[0].geometry.type === "circle") {
const circle = event.features[0];
console.log("Circle center:", circle.geometry.coordinates);
console.log("Circle radius:", circle.properties.radius);
}
});
```## Extented Draw Bar
If you are looking for inspiration of how to