Big News: Socket Selected for OpenAI's Cybersecurity Grant Program.Details
Socket
Book a DemoSign in
Socket

mapbox-gl-draw-freehand-mode

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mapbox-gl-draw-freehand-mode

a free drawing plugin for mapbox-gl-draw

latest
Source
npmnpm
Version
3.0.0
Version published
Weekly downloads
5.7K
-7.6%
Maintainers
1
Weekly downloads
 
Created
Source

Mapbox Freehand Draw Mode

This is a custom mode for @mapbox/mapbox-gl-draw that adds draw functionality to the draw polygon mode.

Demo

https://bemky.github.io/mapbox-gl-draw-freehand-mode/

Dependencies

@mapbox/mapbox-gl-draw

@turf/simplify

Usage

To Install:

npm i mapbox-gl-draw-freehand-mode

To Use:

import FreehandMode from 'mapbox-gl-draw-freehand-mode'

const Draw = new MapboxDraw({
  modes: Object.assign(MapboxDraw.modes, {
    draw_polygon: FreehandMode
  })
});

var map = new mapboxgl.Map({
  container: 'map',
  style: 'mapbox://styles/mapbox/streets-v8',
  center: [40, -74.50],
  zoom: 9
});
map.addControl(Draw)

Configuration

Simplification

By default FreehandMode will simplify. Turf's simplify method takes a polygon and simplifies it based on a tolerance. The tolerance is corelated to meters, so tolerance must change based on the zoom, if not simplification will vary wildly based on zoom level. Thus, FreehandMode's simplify calculates a tolerance based on zoom.

You can configure you're own simplify method by redefing it on the object

Example removing simplification

import FreehandMode from 'mapbox-gl-draw-freehand-mode';

FreehandMode.simplify = function (polygon, zoom) {}

Example with your own tolerance calculation

import FreehandMode from 'mapbox-gl-draw-freehand';

FreehandMode.simplify = function (polygon, zoom) {
    simplify(polygon, {
        mutate: true,
        tolerance: 1 / Math.pow(2, zoom),
        highQuality: true
    });
}

Development

Build or serve the example via Webpack

Build

npm run build

Serve

npm run start

Keywords

mapbox

FAQs

Package last updated on 22 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts