# Module: ol/interaction/Draw

This documentation is for OpenLayers v10.9.0. The latest is v.

## ol/interaction/Draw

### Classes

DrawEvent
Draw

### Functions

#### createBox(){GeometryFunction}

interaction/Draw.js, line 1602

      import {createBox} from 'ol/interaction/Draw';

  Create a `geometryFunction` that will create a box-shaped polygon (aligned with the coordinate system axes). Use this with the draw interaction and `type: 'Circle'` to return a box instead of a circle geometry.

  ##### Returns:

  Function that draws a box-shaped polygon.

#### createRegularPolygon(sides, angle){GeometryFunction}

interaction/Draw.js, line 1561

      import {createRegularPolygon} from 'ol/interaction/Draw';

  Create a `geometryFunction` for `type: 'Circle'` that will create a regular polygon with a user specified number of sides and start angle instead of a `Circle` geometry.

  Name | Type | Description
  --- | --- | ---
  `sides` | number | undefined | Number of sides of the regular polygon. Default is 32.
  `angle` | number | undefined | Angle of the first point in counter-clockwise radians. 0 means East. Default is the angle defined by the heading from the center of the regular polygon to the current pointer position.

  ##### Returns:

  Function that draws a polygon.

### Type Definitions

#### GeometryFunction()

interaction/Draw.js, line 139

  Function that takes an array of coordinates and an optional existing geometry and a projection as arguments, and returns a geometry. The optional existing geometry is the geometry that is returned when the function is called without a second argument.

#### LineCoordType{module:interaction/tracing~LineCoordType}

#### Mode{'Point'} {'LineString'} {'Polygon'} {'Circle'}

  Draw mode. This collapses multi-part geometry types with their single-part cousins.

#### Options{Object}

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `type` | Type | Geometry type of the geometries being drawn with this instance.
  `clickTolerance` | number (defaults to 6) | The maximum distance in pixels between "down" and "up" for a "up" event to be considered a "click" event and actually add a point/vertex to the geometry being drawn. The default of `6` was chosen for the draw interaction to behave correctly on mouse as well as on touch devices.
  `features` | Collection<Feature> | undefined | Destination collection for the drawn features.
  `source` | VectorSource | undefined | Destination source for the drawn features.
  `dragVertexDelay` | number (defaults to 500) | Delay in milliseconds after pointerdown before the current vertex can be dragged to its exact position.
  `snapTolerance` | number (defaults to 12) | Pixel distance for snapping to the drawing finish. Must be greater than `0`.
  `stopClick` | boolean (defaults to false) | Stop click, singleclick, and doubleclick events from firing during drawing.
  `maxPoints` | number | undefined | The number of points that can be drawn before a polygon ring or line string is finished. By default there is no restriction.
  `minPoints` | number | undefined | The number of points that must be drawn before a polygon ring or line string can be finished. Default is `3` for polygon rings and `2` for line strings.
  `finishCondition` | Condition | undefined | A function that takes a `MapBrowserEvent` and returns a boolean to indicate whether the drawing can be finished. Not used when drawing POINT or MULTI_POINT geometries.
  `style` | StyleLike | FlatStyleLike | undefined | Style for sketch features. The draw interaction can have up to three sketch features, depending on the mode. It will always contain a feature with a `Point` geometry that corresponds to the current cursor position. If the mode is `LineString` or `Polygon`, and there is at least one drawn point, it will also contain a feature with a `LineString` geometry that corresponds to the line between the already drawn points and the current cursor position. If the mode is `Polygon`, and there is at least one drawn point, it will also contain a feature with a `Polygon` geometry that corresponds to the polygon between the already drawn points and the current cursor position (note that this polygon has only two points if only one point is drawn). If the mode is `Circle`, and there is one point drawn, it will also contain a feature with a `Circle` geometry whose center is the drawn point and the radius is determined by the distance between the drawn point and the cursor.
  `geometryFunction` | GeometryFunction | undefined | Function that is called when a geometry's coordinates are updated.
  `geometryName` | string | undefined | Geometry name to use for features created by the draw interaction.
  `condition` | Condition | undefined | A function that takes a `MapBrowserEvent` and returns a boolean to indicate whether that event should be handled. By default `noModifierKeys`, i.e. a click, adds a vertex or deactivates freehand drawing.
  `freehand` | boolean (defaults to false) | Operate in freehand mode for lines, polygons, and circles. This makes the interaction always operate in freehand mode and takes precedence over any `freehandCondition` option.
  `freehandCondition` | Condition | undefined | Condition that activates freehand drawing for lines and polygons. This function takes a `MapBrowserEvent` and returns a boolean to indicate whether that event should be handled. The default is `shiftKeyOnly`, meaning that the Shift key activates freehand drawing.
  `trace` | boolean | Condition (defaults to false) | Trace a portion of another geometry. Ignored when in freehand mode.
  `traceSource` | VectorSource | undefined | Source for features to trace. If tracing is active and a `traceSource` is not provided, the interaction's `source` will be used. Tracing requires that the interaction is configured with either a `traceSource` or a `source`.
  `wrapX` | boolean (defaults to false) | Wrap the world horizontally on the sketch overlay.
  `geometryLayout` | GeometryLayout (defaults to 'XY') | Layout of the feature geometries created by the draw interaction.

#### PointCoordType{Coordinate}

  Coordinate type when drawing points.

#### PolyCoordType{Array<Array<Coordinate>>}

  Coordinate type when drawing polygons.

#### SketchCoordType{PointCoordType} {LineCoordType} {PolyCoordType}

  Types used for drawing coordinates.

#### TraceState{module:interaction/tracing~TraceState}

#### TraceTarget{module:interaction/tracing~TraceTarget}