Create polygon on leaflet map like Paint[brush]! Choose your brush size and draw ! Or erase... Mobile and desktop compatible, based on turf.js.
Turf packages are already included in dist js.
L.control.paintPolygon().addTo(map)
options: {
position: 'topright', // position of the control
radius: 30, // radius on start (pixel)
minRadius: 10, // min radius (pixel)
maxRadius: 50, // max radius (pixel)
drawOptions: { // path style on draw (see: https://leafletjs.com/reference-1.3.0.html#path-option)
weight: 1
},
eraseOptions: { // path style on erase (see: https://leafletjs.com/reference-1.3.0.html#path-option)
color: '#ff324a',
weight: 1
},
menu: { // Customize menu, set to false to prevent adding control UI on map, you need to build your own UI (on map or not)
drawErase: true,
size: true,
eraseAll: true
}
}
Add menu: false
in options object to prevent UI creation and bind your own UI to controls methods. See below for API and this example.
setRadius(radius)
: set radius of circle (in pixel)startDraw()
: start drawingstartErase()
: start erasingstop()
: stop drawing or erasingeraseAll()
: erase all...getData()
: return feature as GeoJSONsetData(data)
: set the feature as GeoJSONgetLayer()
: return GeoJSON layer