React component for leaflet-draw
npm install react-leaflet-drawReact component build on top of React-Leaflet that integrate leaflet-draw feature.
```
npm install react-leaflet-draw
First, include leaflet & leaflet-draw styles in your project
`html``
or by including`
node_modules/leaflet/dist/leaflet.css
node_modules/leaflet-draw/dist/leaflet.draw.css
You might need to add one more rule missing in the current css:
`css`
.sr-only {
display: none;
}
It's important to wrap EditControl component into FeatureGroup component from react-leaflet.
The elements you draw will be added to this FeatureGroup layer, when you hit edit button only items in this layer will be edited.
`jsx
import { Map, TileLayer, FeatureGroup, Circle } from 'react-leaflet';
import { EditControl } from "react-leaflet-draw"
const Component = () => (
onEdited={this._onEditPath}
onCreated={this._onCreate}
onDeleted={this._onDeleted}
draw={{
rectangle: false
}}
/>
);
`
For more details on how to use this plugin check out the examples example.
- yarn example:class to compile the class exampleyarn example:hooks
- to compile and run the hooks example
You can pass more options on draw object, this informations can be found here
#### Props
|name |type |description |
|----------------|----------------------------|------------------------------------------------------|
|position |string |control group position |
|draw |object
|edit |object
|onEdited |function |hook to leaflet-draw's draw:edited event |draw:created
|onCreated |function |hook to leaflet-draw's event |draw:deleted
|onDeleted |function |hook to leaflet-draw's event |draw:mounted
|onMounted |function |hook to leaflet-draw's event |draw:editstart
|onEditStart |function |hook to leaflet-draw's event |draw:editstop
|onEditStop |function |hook to leaflet-draw's event |draw:deletestart
|onDeleteStart |function |hook to leaflet-draw's event |draw:deletestop
|onDeleteStop |function |hook to leaflet-draw's event |draw:drawstart
|onDrawStart |function |hook to leaflet-draw's event |draw:drawstop
|onDrawStop |function |hook to leaflet-draw's event |draw:drawvertex
|onDrawVertex |function |hook to leaflet-draw's event |draw:editmove
|onEditMove |function |hook to leaflet-draw's event |draw:editresize
|onEditResize |function |hook to leaflet-draw's event |draw:editvertex` event |
|onEditVertex |function |hook to leaflet-draw's
#### Links to docs
* Control position options
* DrawOptions
* EditPolyOptions
* Draw events