How EditControl and FeatureGroup work together
masterThe EditControl component must be wrapped inside a FeatureGroup component from react-leaflet.
Mental Model:
- The
FeatureGroupacts as the container for all drawable elements. - When you draw a new shape, it is automatically added to this
FeatureGrouplayer. - When you enter 'edit mode', only the items contained within that specific
FeatureGroupwill be available for editing.
import { Map, TileLayer, FeatureGroup, Circle } from 'react-leaflet';
import { EditControl } from "react-leaflet-draw"
const Component = () => (
<FeatureGroup>
<EditControl
position='topright'
onEdited={this._onEditPath}
onCreated={this._onCreate}
onDeleted={this._onDeleted}
draw={{
rectangle: false
}}
/>
<Circle center={[51.51, -0.06]} radius={200} />
</FeatureGroup>
);