require(["esri/views/draw/SegmentDrawAction"], (SegmentDrawAction) => { /* code goes here */ });
import SegmentDrawAction from "@arcgis/core/views/draw/SegmentDrawAction.js";
esri/views/draw/SegmentDrawAction
This class uses different events to generate a set of vertices to create a geometry with drag mode or with two clicks.
Constructors
-
new SegmentDrawAction(properties)
-
Parameterproperties Objectoptional
See the properties for a list of all the properties that may be passed into the constructor.
Property Overview
Name | Type | Summary | Class |
---|---|---|---|
String | The name of the class. more details | Accessor | |
Boolean | Controls whether the created geometry will have z coordinates or not. more details | DrawAction | |
String | The drawing mode. more details | SegmentDrawAction | |
Number[][] | Two-dimensional array of numbers representing the coordinates of each vertex comprising the geometry being drawn. more details | DrawAction | |
MapView | A reference to the MapView. more details | DrawAction |
Property Details
-
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
Exampledraw.create("rectangle", {mode: "click"});
-
Two-dimensional array of numbers representing the coordinates of each vertex comprising the geometry being drawn.
-
A reference to the MapView.
Method Overview
Name | Return Type | Summary | Class |
---|---|---|---|
Adds one or more handles which are to be tied to the lifecycle of the object. more details | Accessor | ||
Boolean | Indicates if the redo() method can be called on the action instance. more details | DrawAction | |
Boolean | Indicates if the undo() method can be called on the action instance. more details | DrawAction | |
Completes drawing the polygon geometry and fires the draw-complete event. more details | SegmentDrawAction | ||
Boolean | Emits an event on the instance. more details | DrawAction | |
FromScreenPointResult|null | Maps the given screen point to a map point. more details | DrawAction | |
Number[]|null | Maps the given screen point to a map point. more details | DrawAction | |
Boolean | Indicates whether there is an event listener on the instance that matches the provided event name. more details | DrawAction | |
Boolean | Returns true if a named group of handles exist. more details | Accessor | |
Object | Registers an event handler on the instance. more details | DrawAction | |
Incrementally redo actions recorded in the stack. more details | DrawAction | ||
Removes a group of handles owned by the object. more details | Accessor | ||
Point|null | Maps the given screen point to a map point. more details | DrawAction | |
Incrementally undo actions recorded in the stack. more details | DrawAction |
Method Details
-
addHandles(handleOrHandles, groupKey)inheritedSince: ArcGIS Maps SDK for JavaScript 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();
ParametershandleOrHandles WatchHandle|WatchHandle[]Handles marked for removal once the object is destroyed.
groupKey *optionalKey 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.
-
Indicates if the redo() method can be called on the action instance.
ReturnsType Description Boolean Returns true
if the redo() method can be called.
-
Indicates if the undo() method can be called on the action instance.
ReturnsType Description Boolean Returns true
if the undo() method can be called.
-
complete()
-
Completes drawing the polygon geometry and fires the draw-complete event.
-
Emits an event on the instance. This method should only be used when creating subclasses of this class.
Parameterstype StringThe name of the event.
event ObjectoptionalThe event payload.
ReturnsType Description Boolean true
if a listener was notified
-
-
Maps the given screen point to a map point.
ParameterscreenPoint ScreenPointThe location on the screen.
ReturnsType Description FromScreenPointResult | null The result object containing, or null
if the screen point could not be mapped.
-
Maps the given screen point to a map point.
ParameterscreenPoint ScreenPointThe location on the screen.
ReturnsType 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.
-
Indicates whether there is an event listener on the instance that matches the provided event name.
Parametertype StringThe name of the event.
ReturnsType Description Boolean Returns true if the class supports the input event.
-
Since: ArcGIS Maps SDK for JavaScript 4.25
-
Returns true if a named group of handles exist.
ParametergroupKey *optionalA group key.
ReturnsType 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"); }
-
Registers an event handler on the instance. Call this method to hook an event with a listener.
ParametersAn event or an array of events to listen for.
listener FunctionThe function to call when the event fires.
ReturnsType 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. Exampleview.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.
Exampleif (action.canRedo()) { action.redo(); }
-
removeHandles(groupKey)inheritedSince: ArcGIS Maps SDK for JavaScript 4.25
-
Removes a group of handles owned by the object.
ParametergroupKey *optionalA group key or an array or collection of group keys to remove.
Exampleobj.removeHandles(); // removes handles from default group obj.removeHandles("handle-group"); obj.removeHandles("other-handle-group");
-
Maps the given screen point to a map point.
ParameterscreenPoint ScreenPointThe location on the screen.
ReturnsType 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.
Exampleif (action.canUndo()) { action.undo(); }
Event Overview
Name | Type | Summary | Class |
---|---|---|---|
{vertices: Number[][],vertexIndex: Number,preventDefault: Function,defaultPrevented: Boolean,type: "cursor-update"} |
Fires after the pointer moves on the view. more details |
SegmentDrawAction | |
{vertices: Number[][],preventDefault: Function,defaultPrevented: Boolean,type: "draw-complete"} |
Fires after the user has completed drawing a geometry. more details |
SegmentDrawAction | |
{vertices: Number[][],vertexIndex: Number,preventDefault: Function,defaultPrevented: Boolean,type: "vertex-add"} |
Fires when a vertex is added. more details |
SegmentDrawAction |
Event Details
-
cursor-update
-
Fires after the pointer moves on the view.
- Properties
-
A two-dimensional array of numbers representing the coordinates of each vertex that comprise the geometry.
vertexIndex NumberIndex of the last vertex added to the vertices array.
preventDefault FunctionPrevents event propagation bubbling up the event chain.
defaultPrevented BooleanSet to true when
preventDefault()
is called.type StringThe 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
-
A two-dimensional array of numbers representing the coordinates of each vertex that comprise the geometry.
preventDefault FunctionPrevents event propagation bubbling up the event chain.
defaultPrevented BooleanSet to true when
preventDefault()
is called.type StringThe 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
-
A two-dimensional array of numbers representing the coordinates of each vertex that make the geometry.
vertexIndex NumberIndex of the last vertex added to the vertices array.
preventDefault FunctionPrevents event propagation bubbling up the event chain.
defaultPrevented BooleanSet to true when
preventDefault()
is called.type StringThe 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); });