# Class: Draw

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

## ol/interaction/Draw~Draw

    import Draw from 'ol/interaction/Draw.js';

Interaction for drawing feature geometries.

#### new Draw(options)

interaction/Draw.js, line 218

  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.

  ##### Fires:

  - `change` (BaseEvent) - Generic change event. Triggered when the revision counter is increased.
  - `change:active` (ObjectEvent)
  - `drawabort` (DrawEvent) - Triggered upon feature draw abortion
  - `drawend` (DrawEvent) - Triggered upon feature draw end
  - `drawstart` (DrawEvent) - Triggered upon feature draw start
  - `error` (BaseEvent) - Generic error event. Triggered when an error occurs.
  - `propertychange` (ObjectEvent) - Triggered when a property is changed.

### Extends

- PointerInteraction

### Observable Properties

Name | Type | Settable | ObjectEvent type | Description
--- | --- | --- | --- | ---
`active` | boolean | yes | `change:active` | `true` if the interaction is active, `false` otherwise.

### Methods

#### abortDrawing()

interaction/Draw.js, line 1425

  Stop drawing without adding the sketch feature to the target layer.

#### appendCoordinates(coordinates)

interaction/Draw.js, line 1441

  Append coordinates to the end of the geometry that is currently being drawn. This can be used when drawing LineStrings or Polygons. Coordinates will either be appended to the current LineString or the outer ring of the current Polygon. If no geometry is being drawn, a new one will be created.

  Name | Type | Description
  --- | --- | ---
  `coordinates` | LineCoordType | Linear coordinates to be appended to the coordinate array.

#### changed() inherited

Observable.js, line 68

  Increases the revision counter and dispatches a 'change' event.

#### dispatchEvent(event){boolean | undefined} inherited

events/Target.js, line 85

  Dispatches an event and calls all listeners listening for events of this type. The event parameter can either be a string or an Object with a `type` property.

  Name | Type | Description
  --- | --- | ---
  `event` | BaseEvent | string | Event object.

  ##### Returns:

  `false` if anyone called preventDefault on the event object or if any of the listeners returned false.

#### extend(feature)

interaction/Draw.js, line 1490

  Initiate draw mode by starting from an existing geometry which will receive new additional points. This only works on features with `LineString` geometries, where the interaction will extend lines by adding points to the end of the coordinates array. This will change the original feature, instead of drawing a copy.

  The function will dispatch a `drawstart` event.

  Name | Type | Description
  --- | --- | ---
  `feature` | Feature<LineString> | Feature to be extended.

#### finishDrawing(){Feature<SimpleGeometry> | null}

interaction/Draw.js, line 1358

  Stop drawing and add the sketch feature to the target layer. The `DRAWEND` event is dispatched before inserting the feature.

  ##### Returns:

  The drawn feature.

#### get(key){*} inherited

Object.js, line 136

  Gets a value.

  Name | Type | Description
  --- | --- | ---
  `key` | string | Key name.

  ##### Returns:

  Value.

#### getActive(){boolean} inherited

interaction/Interaction.js, line 82

  Return whether the interaction is currently active.

  ##### Returns:

  `true` if the interaction is active, `false` otherwise.

#### getFreehand(){boolean}

interaction/Draw.js, line 646

  Get if this interaction is in freehand mode.

  ##### Returns:

  Freehand drawing.

#### getKeys(){Array.<string>} inherited

Object.js, line 149

  Get a list of object property names.

  ##### Returns:

  List of property names.

#### getMap(){Map | null} inherited

interaction/Interaction.js, line 91

  Get the map associated with this interaction.

  ##### Returns:

  Map.

#### getOverlay(){VectorLayer}

interaction/Draw.js, line 637

  Get the overlay layer that this interaction renders sketch features to.

  ##### Returns:

  Overlay layer.

#### getPointerCount(){number} inherited

interaction/Pointer.js, line 95

  Returns the current number of pointers involved in the interaction, e.g. `2` when two fingers are used.

  ##### Returns:

  The number of pointers.

#### getProperties(){NoInfer.<Properties>} inherited

Object.js, line 158

  Get an object of all property names and values.

  ##### Returns:

  Object.

#### getRevision(){number} inherited

Observable.js, line 79

  Get the version number for this object. Each time the object is modified, its version number will be incremented.

  ##### Returns:

  Revision.

#### handleEvent(event){boolean}

interaction/Draw.js, line 657

  Handles the `map browser event` and may actually draw or finish the drawing.

  Name | Type | Description
  --- | --- | ---
  `event` | MapBrowserEvent<PointerEvent> | Map browser event.

  ##### Returns:

  `false` to stop event propagation.

#### on(type, listener){EventsKey | Array<EventsKey>} inherited

Observable.js, line 152

  Listen for a certain type of event.

  Name | Type | Description
  --- | --- | ---
  `type` | string | Array.<string> | The event type or array of event types.
  `listener` | function | The listener function.

  ##### Returns:

  Unique key for the listener. If called with an array of event types as the first argument, the return will be an array of keys.

#### once(type, listener){EventsKey | Array<EventsKey>} inherited

Observable.js, line 164

  Listen once for a certain type of event.

  Name | Type | Description
  --- | --- | ---
  `type` | string | Array.<string> | The event type or array of event types.
  `listener` | function | The listener function.

  ##### Returns:

  Unique key for the listener. If called with an array of event types as the first argument, the return will be an array of keys.

#### removeLastPoint()

interaction/Draw.js, line 1347

  Remove last point of the feature currently being drawn. Does not do anything when drawing POINT or MULTI_POINT geometries.

#### set(key, value, silent) inherited

Object.js, line 218

  Sets a value.

  Name | Type | Description
  --- | --- | ---
  `key` | string | Key name.
  `value` | * | Value.
  `silent` | boolean | undefined | Update without triggering an event.

#### setActive(active) inherited

interaction/Interaction.js, line 111

  Activate or deactivate the interaction.

  Name | Type | Description
  --- | --- | ---
  `active` | boolean | Active.

#### setFreehand(freehand)

interaction/Draw.js, line 620

  Set whether the drawing is done in freehand mode.

  Name | Type | Description
  --- | --- | ---
  `freehand` | boolean | Freehand drawing.

#### setProperties(values, silent) inherited

Object.js, line 238

  Sets a collection of key-value pairs. Note that this changes any existing properties and adds new ones (it does not remove any existing properties).

  Name | Type | Description
  --- | --- | ---
  `values` | Partial.<NoInfer.<Properties>> | Values.
  `silent` | boolean | undefined | Update without triggering an event.

#### un(type, listener) inherited

Observable.js, line 173

  Unlisten for a certain type of event.

  Name | Type | Description
  --- | --- | ---
  `type` | string | Array.<string> | The event type or array of event types.
  `listener` | function | The listener function.

#### unset(key, silent) inherited

Object.js, line 262

  Unsets a property.

  Name | Type | Description
  --- | --- | ---
  `key` | string | Key name.
  `silent` | boolean | undefined | Unset without triggering an event.