Class: Draw

ol/interaction/Draw~Draw


import Draw from 'ol/interaction/Draw';

Interaction for drawing feature geometries.

new Draw(options)

interaction/Draw.js, line 183
Name Type Description
options

Options.

Name Type Default Description
type module:ol/geom/GeometryType

Geometry type of the geometries being drawn with this instance.

clickTolerance number 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 module:ol/Collection~Collection.<module:ol/Feature~Feature>

Destination collection for the drawn features.

source module:ol/source/Vector~VectorSource

Destination source for the drawn features.

dragVertexDelay number 500

Delay in milliseconds after pointerdown before the current vertex can be dragged to its exact position.

snapTolerance number 12

Pixel distance for snapping to the drawing finish.

stopClick boolean false

Stop click, singleclick, and doubleclick events from firing during drawing.

maxPoints number

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

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 module:ol/events/condition~Condition

A function that takes an module:ol/MapBrowserEvent~MapBrowserEvent and returns a boolean to indicate whether the drawing can be finished.

style module:ol/style/Style~StyleLike

Style for sketch features.

geometryFunction GeometryFunction

Function that is called when a geometry's coordinates are updated.

geometryName string

Geometry name to use for features created by the draw interaction.

condition module:ol/events/condition~Condition

A function that takes an module:ol/MapBrowserEvent~MapBrowserEvent and returns a boolean to indicate whether that event should be handled. By default module:ol/events/condition~noModifierKeys, i.e. a click, adds a vertex or deactivates freehand drawing.

freehand boolean 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 module:ol/events/condition~Condition

Condition that activates freehand drawing for lines and polygons. This function takes an module:ol/MapBrowserEvent~MapBrowserEvent and returns a boolean to indicate whether that event should be handled. The default is module:ol/events/condition~shiftKeyOnly, meaning that the Shift key activates freehand drawing.

wrapX boolean false

Wrap the world horizontally on the sketch overlay.

Fires:

Extends

Observable Properties

Name Type Settable ol/Object.ObjectEvent type Description
active boolean yes change:active

true if the interaction is active, false otherwise.

Methods

extend(feature)

interaction/Draw.js, line 905

Extend an existing geometry by adding 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.

Name Type Description
feature module:ol/Feature~Feature

Feature to be extended.

finishDrawing()

interaction/Draw.js, line 842

Stop drawing and add the sketch feature to the target layer. The module:ol/interaction/Draw~DrawEventType.DRAWEND event is dispatched before inserting the feature.

getOverlay(){module:ol/layer/Vector~VectorLayer}

interaction/Draw.js, line 471

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

Returns:
Overlay layer.

handleEvent() inherited

interaction/Pointer.js, line 120

Handles the map browser event and may call into other functions, if event sequences like e.g. 'drag' or 'down-up' etc. are detected.

removeLastPoint()

interaction/Draw.js, line 806

Remove last point of the feature currently being drawn.