SegmentDrawAction

require(["esri/views/2d/draw/SegmentDrawAction"], function(SegmentDrawAction) { /* code goes here */ });
Class: esri/views/2d/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.
NameTypeSummaryClass
String

The name of the class.

more details
more detailsAccessor
String

The drawing mode.

more details
more detailsSegmentDrawAction
Number[][]

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

more details
more detailsSegmentDrawAction
MapView

A reference to the MapView.

more details
more detailsDrawAction

Property Details

declaredClassStringreadonly inherited
Since: ArcGIS API for JavaScript 4.7

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

modeString

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

Possible Values:

ValueDescription
freehandVertices are added while the pointer is dragged.
clickVertices are added when the pointer is clicked. SegmentDrawActions are created from 2 vertices.
Default Value:freehand
Example:
draw.create("rectangle", {mode: "click"});
verticesNumber[][]readonly

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

A reference to the MapView.

Method Overview

NameReturn TypeSummaryClass

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

more details
more detailsSegmentDrawAction

Emits an event on the instance.

more details
more detailsDrawAction
Boolean

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

more details
more detailsDrawAction
Object

Registers an event handler on the instance.

more details
more detailsDrawAction

Method Details

complete()

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

emit(type, event)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

The event payload.

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:
TypeDescription
BooleanReturns 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.

Parameters:
type String

The name of event to listen for.

listener Function

The function to call when the event is fired.

Returns:
TypeDescription
ObjectReturns an event handler with a remove() method that can be called to stop listening for the event.
PropertyTypeDescription
removeFunctionWhen called, removes the listener from the event.
See also:
Example:
view.on("click", function(event){
  // event is the event handle returned after the event fires.
  console.log(event.mapPoint);
});

Event Overview

NameTypeSummaryClass
{vertices: Number[][],vertexIndex: Number,preventDefault: Function,defaultPrevented: Boolean,type: String}

Fires after the pointer moves on the view.

more details
more detailsSegmentDrawAction
{vertices: Number[][],preventDefault: Function,defaultPrevented: Boolean,type: String}

Fires after the user has completed drawing a geometry.

more details
more detailsSegmentDrawAction
{vertices: Number[][],vertexIndex: Number,preventDefault: Function,defaultPrevented: Boolean,type: String}

Fires when a vertex is added.

more details
more detailsSegmentDrawAction

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. For this event, the type 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();
  var 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. For this event, the type 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();
  var 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. For this event, the type 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();
  var polygon = new Polygon({
    rings: evt.vertices,
    spatialReference: view.spatialReference
  });
  graphic = createGraphic(polygon);
  view.graphics.add(graphic);
});

API Reference search results

NameTypeModule
Loading...