DrawControl
Example
Example Source Code
tsx
import React, { useState } from 'react'
import ReactDOM from 'react-dom'
import { MbDrawControl, MbMap, MbTiandituLayer } from '@mapbox-react/core'
const App = () => {
const [mapCenter] = useState([116.38745, 39.91266])
const [zoom, setZoom] = useState(2)
return (
<div className="map-wrapper">
<MbMap center={mapCenter} zoom={zoom}>
<MbTiandituLayer types={['vec']} />
<MbDrawControl position="top-right" />
</MbMap>
</div>
)
}
ReactDOM.render(<App />, document.querySelector('#root'))
API
PROPS
Name | Description | Type | Default |
---|---|---|---|
functions | Functions | array("point", "polyline", "polygon", "trash") | ["point", "polyline", "polygon", "trash"] |
position | Position | string('top-left' , 'top-right' , 'bottom-left' ,'bottom-right') | top-right |
EVENTS
Name | Description | Parameters |
---|---|---|
onCreated | Map initialization completed event | - |
onDrawCreated | Drawing completed event | features: AnyArr |
onDrawDelete | Delete element(s) event | features: AnyArr |
onDrawUpdate | Drawing element(s) updated event | object — Contains action property and features |
METHODS
Name | Description | Definition |
---|---|---|
add | Returns: Array — featureIds | geojson: object — geojson |
get | Returns: object — feature geojson | featureId: string |
getSelectedIds | Gets the IDs of the currently selected features | () => string[] |
getSelected | Gets the currently selected features in GeoJSON format (as a FeatureCollection) | () => object — featureCollection |
getAll | Gets all drawn features in GeoJSON format (as a FeatureCollection) | () => object — geojson featureCollection |
delete | Deletes features based on their IDs | (ids: string[]) => void |
deleteAll | Deletes all drawn features | () => void |