DrawAction

AMD: require(["esri/views/draw/DrawAction"], (DrawAction) => { /* code goes here */ });
ESM: import DrawAction from "@arcgis/core/views/draw/DrawAction.js";
Class: esri/views/draw/DrawAction
Inheritance: DrawAction Accessor
Since: ArcGIS Maps SDK for JavaScript 4.7

DrawAction is the base class for all draw actions. DrawActions use the view events to generate a set of coordinates to create new geometries. Each serves a different purpose, allowing you to create a different type geometry such as point, multipoint, polyline, and polygon.

When the draw.create("type of geometry") method is called, an instance of the relevant draw action is returned. You can then listen to its events to create a new geometry that meets criteria specified by the application.

See also

Constructors

DrawAction

Constructor
new DrawAction(properties)
Parameter
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
Show inherited properties Hide inherited properties
Name Type Summary Class
String

The name of the class.

Accessor
Boolean

Controls whether the created geometry will have z coordinates or not.

DrawAction
Number[][]

Two-dimensional array of numbers representing the coordinates of each vertex comprising the geometry being drawn.

DrawAction
MapView

A reference to the MapView.

DrawAction

Property Details

declaredClass

Inherited
Property
declaredClass Stringreadonly
Inherited from Accessor

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

hasZ

Property
hasZ Boolean

Controls whether the created geometry will have z coordinates or not.

Default Value:true

vertices

Property
vertices Number[][]readonly

Two-dimensional array of numbers representing the coordinates of each vertex comprising the geometry being drawn.

view

Property
view MapView

A reference to the MapView.

Method Overview

Show inherited methods Hide inherited methods
Name Return Type Summary Class

Adds one or more handles which are to be tied to the lifecycle of the object.

Accessor
Boolean

Indicates if the redo() method can be called on the action instance.

DrawAction
Boolean

Indicates if the undo() method can be called on the action instance.

DrawAction
Boolean

Emits an event on the instance.

DrawAction
FromScreenPointResult|null

Maps the given screen point to a map point.

DrawAction
Number[]|null

Maps the given screen point to a map point.

DrawAction
Boolean

Indicates whether there is an event listener on the instance that matches the provided event name.

DrawAction
Boolean

Returns true if a named group of handles exist.

Accessor
Object

Registers an event handler on the instance.

DrawAction

Incrementally redo actions recorded in the stack.

DrawAction

Removes a group of handles owned by the object.

Accessor
Point|null

Maps the given screen point to a map point.

DrawAction

Incrementally undo actions recorded in the stack.

DrawAction

Method Details

addHandles

Inherited
Method
addHandles(handleOrHandles, groupKey)
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, addHandles added at 4.25.

Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.

// Manually manage handles
const handle = reactiveUtils.when(
  () => !view.updating,
  () => {
    wkidSelect.disabled = false;
  },
  { once: true }
);

this.addHandles(handle);

// Destroy the object
this.destroy();
Parameters
handleOrHandles WatchHandle|WatchHandle[]

Handles marked for removal once the object is destroyed.

groupKey *
optional

Key identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.

canRedo

Method
canRedo(){Boolean}

Indicates if the redo() method can be called on the action instance.

Returns
Type Description
Boolean Returns true if the redo() method can be called.

canUndo

Method
canUndo(){Boolean}

Indicates if the undo() method can be called on the action instance.

Returns
Type Description
Boolean Returns true if the undo() method can be called.

emit

Method
emit(type, event){Boolean}

Emits an event on the instance. This method should only be used when creating subclasses of this class.

Parameters
type String

The name of the event.

event Object
optional

The event payload.

Returns
Type Description
Boolean true if a listener was notified

getCoordsAndPointFromScreenPoint

Method
getCoordsAndPointFromScreenPoint(screenPoint){FromScreenPointResult|null}

Maps the given screen point to a map point.

Parameter
screenPoint ScreenPoint

The location on the screen.

Returns
Type Description
FromScreenPointResult | null The result object containing, or null if the screen point could not be mapped.

getCoordsFromScreenPoint

Method
getCoordsFromScreenPoint(screenPoint){Number[]|null}

Maps the given screen point to a map point.

Parameter
screenPoint ScreenPoint

The location on the screen.

Returns
Type Description
Number[] | null Array of x,y and z component (if hasZ is enabled) of the point associated with the given screen point or null if screen point could not be mapped.

hasEventListener

Method
hasEventListener(type){Boolean}

Indicates whether there is an event listener on the instance that matches the provided event name.

Parameter
type String

The name of the event.

Returns
Type Description
Boolean Returns true if the class supports the input event.

hasHandles

Inherited
Method
hasHandles(groupKey){Boolean}
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, hasHandles added at 4.25.

Returns true if a named group of handles exist.

Parameter
groupKey *
optional

A group key.

Returns
Type Description
Boolean Returns true if a named group of handles exist.
Example
// Remove a named group of handles if they exist.
if (obj.hasHandles("watch-view-updates")) {
  obj.removeHandles("watch-view-updates");
}

on

Method
on(type, listener){Object}

Registers an event handler on the instance. Call this method to hook an event with a listener.

Parameters

An event or an array of events to listen for.

listener Function

The function to call when the event fires.

Returns
Type Description
Object Returns an event handler with a remove() method that should be called to stop listening for the event(s).
Property Type Description
remove Function When called, removes the listener from the event.
Example
view.on("click", function(event){
  // event is the event handle returned after the event fires.
  console.log(event.mapPoint);
});

redo

Method
redo()

Incrementally redo actions recorded in the stack. Call canRedo() prior to calling this method to check if this method can be called on the action instance. Calling this method will fire the vertex-add or vertex-remove events depending on the last action.

Example
if (action.canRedo()) {
  action.redo();
}

removeHandles

Inherited
Method
removeHandles(groupKey)
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, removeHandles added at 4.25.

Removes a group of handles owned by the object.

Parameter
groupKey *
optional

A group key or an array or collection of group keys to remove.

Example
obj.removeHandles(); // removes handles from default group

obj.removeHandles("handle-group");
obj.removeHandles("other-handle-group");

screenToMap

Method
screenToMap(screenPoint){Point|null}

Maps the given screen point to a map point.

Parameter
screenPoint ScreenPoint

The location on the screen.

Returns
Type Description
Point | null MapPoint associated with the given screen point or null if screen point could not be mapped.

undo

Method
undo()

Incrementally undo actions recorded in the stack. Call canUndo() prior to calling this method to check if this method can be called on the action instance. Calling this method will fire the vertex-add or vertex-remove events depending on the last action.

Example
if (action.canUndo()) {
  action.undo();
}

Type Definitions

FromScreenPointResult

Type Definition
FromScreenPointResult

The result object of the getCoordsAndPointFromScreenPoint() method. See the table below for more details on each property.

Properties
vertex Number[]

Array of x, y, and z component (if hasZ is enabled).

mapPoint Point

The map point of the point associated with the given screen point.

ScreenPoint

Type Definition
ScreenPoint

An object representing a point on the screen.

Properties
x Number

The x coordinate.

y Number

The y coordinate.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.