| title |
|---|
Draw Polygon |
Polygon Mode allows you to create polygons on the map by clicking to add vertices and closing the shape.
You can enable Draw Polygon Mode like this:
map.gm.enableDraw('polygon');
map.gm.disableDraw();
map.gm.toggleDraw('polygon');
map.gm.drawEnabled('polygon');
// Or like this:
map.gm.enableMode('draw', 'polygon');
map.gm.disableMode('draw', 'polygon');
map.gm.toggleMode('draw', 'polygon');
map.gm.isModeEnabled('draw', 'polygon');The following events are available on a map instance:
| Event | Params | Description | Output |
|---|---|---|---|
gm:drawstart |
event |
Fired when polygon drawing starts. | map, shape |
gm:create |
event |
Fired when a polygon is created. | map, shape, feature |
gm:drawend |
event |
Fired when polygon drawing is completed. | map, shape |
Polygon drawing operates by:
- Clicking on the map to place the first vertex
- Moving the mouse to see a preview of the polygon segment
- Clicking to add additional vertices
- Closing the polygon by clicking on the first vertex
import BrowserOnlyGmMap from '../../src/components/map/BrowserOnlyGmMap'; import { drawPolygonOptions } from '../../src/components/examples/mode-options';