SegmentDrawAction

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

This class uses different events to generate a set of vertices to create a geometry with drag mode or with two clicks.

See also:

Constructors

new SegmentDrawAction(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
Stringmore details

The name of the class.

more detailsAccessor
Booleanmore details

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

more detailsDrawAction
Stringmore details

The drawing mode.

more detailsSegmentDrawAction
Number[][]more details

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

more detailsDrawAction
MapViewmore details

A reference to the MapView.

more detailsDrawAction

Property Details

declaredClass Stringreadonly inherited

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

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

Default Value:true
mode String

The drawing mode. It is only relevant when the action is first created. Its value cannot be changed during the action lifecycle.

Possible Values

Value Description
freehand Vertices are added while the pointer is dragged.
click Vertices are added when the pointer is clicked. SegmentDrawActions are created from 2 vertices.

Possible Values:"freehand"|"click"

Default Value:freehand
Example:
draw.create("rectangle", {mode: "click"});
vertices Number[][]readonly inherited

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

A reference to the MapView.

Method Overview

Show inherited methods Hide inherited methods
Name Return Type Summary Class
Booleanmore details

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

more detailsDrawAction
Booleanmore details

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

more detailsDrawAction
more details

Completes drawing the polygon geometry and fires the draw-complete event.

more detailsSegmentDrawAction
Booleanmore details

Emits an event on the instance.

more detailsDrawAction
FromScreenPointResult|nullmore details

Maps the given screen point to a map point.

more detailsDrawAction
Number[]|nullmore details

Maps the given screen point to a map point.

more detailsDrawAction
Booleanmore details

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

more detailsDrawAction
Objectmore details

Registers an event handler on the instance.

more detailsDrawAction
more details

Incrementally redo actions recorded in the stack.

more detailsDrawAction
Point|nullmore details

Maps the given screen point to a map point.

more detailsDrawAction
more details

Incrementally undo actions recorded in the stack.

more detailsDrawAction

Method Details

canRedo(){Boolean}inherited

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(){Boolean}inherited

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.
complete()

Completes drawing the polygon geometry and fires the draw-complete event.

emit(type, event){Boolean}inherited

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(screenPoint){FromScreenPointResult|null}inherited

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(screenPoint){Number[]|null}inherited

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(type){Boolean}inherited

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.
on(type, listener){Object}inherited

Registers an event handler on the instance. Call this method to hook an event with a listener. See the Events summary table for a list of supported events.

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()inherited

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();
}
screenToMap(screenPoint){Point|null}inherited

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()inherited

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();
}

Event Overview

Name Type Summary Class
{vertices: Number[][],vertexIndex: Number,preventDefault: Function,defaultPrevented: Boolean,type: "cursor-update"}
more details

Fires after the pointer moves on the view.

more details SegmentDrawAction
{vertices: Number[][],preventDefault: Function,defaultPrevented: Boolean,type: "draw-complete"}
more details

Fires after the user has completed drawing a geometry.

more details SegmentDrawAction
{vertices: Number[][],vertexIndex: Number,preventDefault: Function,defaultPrevented: Boolean,type: "vertex-add"}
more details

Fires when a vertex is added.

more details SegmentDrawAction

Event Details

cursor-update

Fires after the pointer moves on the view.

Properties:
vertices Number[][]

A two-dimensional array of numbers representing the coordinates of each vertex that comprise the geometry.

vertexIndex Number

Index of the last vertex added to the vertices array.

preventDefault Function

Prevents event propagation bubbling up the event chain.

defaultPrevented Boolean

Set to true when preventDefault() is called.

type String

The type of the event.

The value is always "cursor-update".

Example:
// listen to SegmentDrawAction.cursor-update
// give a visual feedback to the user on the view
// as user moving the pointer.
action.on("cursor-update", function (evt) {
  view.graphics.removeAll();
  let polygon = new Polygon({
    rings: evt.vertices,
    spatialReference: view.spatialReference
  });
  graphic = createGraphic(polygon);
  view.graphics.add(graphic);
});
draw-complete

Fires after the user has completed drawing a geometry.

Properties:
vertices Number[][]

A two-dimensional array of numbers representing the coordinates of each vertex that comprise the geometry.

preventDefault Function

Prevents event propagation bubbling up the event chain.

defaultPrevented Boolean

Set to true when preventDefault() is called.

type String

The type of the event.

The value is always "draw-complete".

Example:
// listen to SegmentDrawAction.draw-complete
// add the graphic representing the completed
// polygon to the view
action.on("draw-complete", function (evt) {
  view.graphics.removeAll();
  let polygon = new Polygon({
    rings: evt.vertices,
    spatialReference: view.spatialReference
  });
  graphic = createGraphic(polygon);
  view.graphics.add(graphic);
});
vertex-add

Fires when a vertex is added.

Properties:
vertices Number[][]

A two-dimensional array of numbers representing the coordinates of each vertex that make the geometry.

vertexIndex Number

Index of the last vertex added to the vertices array.

preventDefault Function

Prevents event propagation bubbling up the event chain.

defaultPrevented Boolean

Set to true when preventDefault() is called.

type String

The type of the event.

The value is always "vertex-add".

Example:
// listen to SegmentDrawAction.vertex-add
// give a visual feedback to the user on the view
// as user moving the pointer.
action.on("vertex-add", function (evt) {
  view.graphics.removeAll();
  let polygon = new Polygon({
    rings: evt.vertices,
    spatialReference: view.spatialReference
  });
  graphic = createGraphic(polygon);
  view.graphics.add(graphic);
});

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