Skip to content
import Draw from "@arcgis/core/views/draw/Draw.js";
Inheritance:
DrawAccessor
Since
ArcGIS Maps SDK for JavaScript 4.5

The Draw class provides advanced drawing capabilities for developers who need complete control over creating temporary graphics with different geometries. For example, if you want to prevent users from drawing graphics with self-intersecting lines or overlapping polygons, then you can use this class to implement these rules. The draw experience is built upon draw actions, which use the view events to generate a set of coordinates for creating new geometries. Each geometry type has a corresponding draw action class.

This class provides a simple interface for interacting with draw actions. After initializing a Draw instance, you can call create() to return a reference to the relevant draw action. This draw action may then be used to create new geometries of the specified type.

Pointer and keyboard gestures

Pointer and keyboard gestures for drawing points, polylines, and polygons are described in the tables below.

Drawing points

GestureAction
Left-clickAdds a point at the pointer location.
EnterAdds a point at the pointer location.

Drawing polylines and polygons

GestureAction
Left-clickAdds a vertex at the pointer location.
Left-dragAdds a vertex for each pointer move.
Enter or Double-clickCompletes the polyline or polygon.
FAdds a vertex to the polyline or polygon.
ZIncrementally undos actions recorded in the stack.
RIncrementally redos actions recorded in the stack.

To provide users with a simpler drawing experience, then use SketchViewModel class.

See also
Example
// create a new instance of draw
let draw = new Draw({
view: view
});
// create an instance of draw polyline action
// the polyline vertices will be only added when
// the pointer is clicked on the view
let action = draw.create("polyline", {mode: "click"});
// fires when a vertex is added
action.on("vertex-add", function (evt) {
measureLine(evt.vertices);
});
// fires when the pointer moves
action.on("cursor-update", function (evt) {
measureLine(evt.vertices);
});
// fires when the drawing is completed
action.on("draw-complete", function (evt) {
measureLine(evt.vertices);
});
// fires when a vertex is removed
action.on("vertex-remove", function (evt) {
measureLine(evt.vertices);
});
function measureLine(vertices) {
view.graphics.removeAll();
let line = createLine(vertices);
let lineLength = geometryEngine.geodesicLength(line, "miles");
let graphic = createGraphic(line);
view.graphics.add(graphic);
}
function createLine(vertices) {
let polyline = {
type: "polyline", // autocasts as new Polyline()
paths: vertices,
spatialReference: view.spatialReference
}
return polyline;
}

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
properties
See the properties table for a list of all the properties that may be passed into the constructor.
Example
// Typical usage
let draw = new Draw({
view: view
});

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.

activeAction

Property
Type
DrawAction | null | undefined

A reference to the active draw action. An instance of the draw action is created when create() method is called.

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor
Since
ArcGIS Maps SDK for JavaScript 4.7

The name of the class. The declared class name is formatted as esri.folder.className.

view

Property
Type
MapViewOrSceneView

The view in which geometries will be drawn by the user.

Methods

MethodSignatureClass
complete(): void
create(drawAction: ToolType, drawOptions?: DrawOptions): DrawAction
reset(): void

complete

Method
Signature
complete (): void
Since
ArcGIS Maps SDK for JavaScript 4.7

Complete the current active drawing.

Returns
void

create

Method
Signature
create (drawAction: ToolType, drawOptions?: DrawOptions): DrawAction

Creates an instance of the requested draw action.

Parameters
ParameterTypeDescriptionRequired
drawAction

Name of the draw action to create. See the table below for a list of possible values and type of draw action it creates.

Possible Values

Geometry typeDraw action instance
pointPointDrawAction
multipointMultipointDrawAction (only supported in MapView)
polylinePolylineDrawAction
polygonPolygonDrawAction
rectangle, circle, ellipseSegmentDrawAction
drawOptions

Object of the drawing options for the geometry to be created.

Returns
DrawAction

Returns an instance of the requested draw action.

Example
let pointAction = draw.create("point");

reset

Method
Signature
reset (): void
Since
ArcGIS Maps SDK for JavaScript 4.6

Resets the drawing by clearing the active action.

Returns
void

Type definitions

ToolType

Type definition
Type
"point" | "polygon" | "polyline" | "multipoint" | "rectangle" | "circle" | "ellipse" | "triangle"