PolylineDrawAction
require(["esri/views/2d/draw/PolylineDrawAction"], function(PolylineDrawAction) { /* code goes here */ });
esri/views/2d/draw/PolylineDrawAction
This class uses different events to generate a set of vertices to create a new Polyline geometry using Draw. When draw.create("polyline") is called, a reference to this class is returned. You can listen to events on the PolylineDrawAction instance, which allows users to create polylines that meet criteria specified by the developer.
function enableCreatePolyline(draw, view) {
var action = draw.create("polyline");
// listen to PolylineDrawAction.vertex-add
// Fires when the user clicks, or presses the "F" key
// Can also fire when the "R" key is pressed to redo.
action.on("vertex-add", function (evt) {
createPolylineGraphic(evt.vertices);
});
// listen to PolylineDrawAction.vertex-remove
// Fires when the "Z" key is pressed to undo the
// last added vertex
action.on("vertex-remove", function (evt) {
createPolylineGraphic(evt.vertices);
});
// listen to PolylineDrawAction.cursor-update
// fires when the pointer moves over the view
action.on("cursor-update", function (evt) {
createPolylineGraphic(evt.vertices);
});
// listen to PolylineDrawAction.draw-complete
// event to create a graphic when user double-clicks
// on the view or presses the "C" key
action.on("draw-complete", function (evt) {
createPolylineGraphic(evt.vertices);
});
}
function createPolylineGraphic(vertices){
view.graphics.removeAll();
var polyline = {
type: "polyline", // autocasts as Polyline
paths: vertices,
spatialReference: view.spatialReference
};
var graphic = new Graphic({
geometry: polyline,
symbol: {
type: "simple-line", // autocasts as SimpleLineSymbol
color: [4, 90, 141],
width: 3,
cap: "round",
join: "round"
}
});
view.graphic.add(graphic);
}
Constructors
- new PolylineDrawAction(properties)
- Parameter:properties 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 | more details | Accessor | |
String | The drawing mode. more details | more details | PolylineDrawAction | |
Number[][] | Two-dimensional array of numbers representing the coordinates of each vertex that comprising the drawn geometry. more details | more details | PolylineDrawAction | |
MapView | A reference to the MapView. more details | more details | DrawAction |
Property Details
- Since: ArcGIS API for JavaScript 4.7
The name of the class. The declared class name is formatted as
esri.folder.className
.
- modeStringSince: ArcGIS API for JavaScript 4.7
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 hybrid Vertices are added while the pointer is clicked or dragged. freehand Vertices are added while the pointer is dragged. click Vertices are added when the pointer is clicked. - Default Value:hybrid
Example:draw.create("polyline", {mode: "freehand"});
- verticesNumber[][]readonly
Two-dimensional array of numbers representing the coordinates of each vertex that comprising the drawn geometry.
A reference to the MapView.
Method Overview
Name | Return Type | Summary | Class | |
---|---|---|---|---|
Boolean | Indicates if the redo() method can be called on the action instance. more details | more details | DrawAction | |
Boolean | Indicates if the undo() method can be called on the action instance. more details | more details | DrawAction | |
Completes drawing the polyline geometry and fires the draw-complete event. more details | more details | PolylineDrawAction | ||
Emits an event on the instance. more details | more details | DrawAction | ||
Boolean | Indicates whether there is an event listener on the instance that matches the provided event name. more details | more details | DrawAction | |
Object | Registers an event handler on the instance. more details | more details | DrawAction | |
Incrementally redo actions recorded in the stack. more details | more details | DrawAction | ||
Incrementally undo actions recorded in the stack. more details | more details | DrawAction |
Method Details
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.
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 polyline geometry and fires the draw-complete event. Call this method if the drawing logic needs to be completed other than by double-clicking or pressing the "C" key.
- emit(type, event)inherited
Emits an event on the instance. This method should only be used when creating subclasses of this class.
Parameters:type StringThe name of the event.
event ObjectThe event payload.
Indicates whether there is an event listener on the instance that matches the provided event name.
Parameter:type StringThe name of the event.
Returns:Type Description Boolean Returns true if the class supports the input event.
Registers an event handler on the instance. Call this method to hook an event with a listener.
Parameters:type StringThe name of event to listen for.
listener FunctionThe function to call when the event is fired.
Returns:Type Description Object Returns an event handler with a remove()
method that can be called to stop listening for the event.Property Type Description remove Function When 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); });
- 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(); }
- 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: String} | Fires after the pointer moves on the view. more details | more details | PolylineDrawAction | |
{vertices: Number[][],preventDefault: Function,defaultPrevented: Boolean,type: String} | Fires after the user has completed drawing a polyline. more details | more details | PolylineDrawAction | |
{vertices: Number[][],vertexIndex: Number,preventDefault: Function,defaultPrevented: Boolean,type: String} | Fires in response to redo action or when redo() is called. more details | more details | PolylineDrawAction | |
{vertices: Number[][],vertexIndex: Number,preventDefault: Function,defaultPrevented: Boolean,type: String} | Fires in response to undo action or when undo() is called. more details | more details | PolylineDrawAction | |
{vertices: Number[][],vertexIndex: Number,preventDefault: Function,defaultPrevented: Boolean,type: String} | Fires when a vertex is added. more details | more details | PolylineDrawAction | |
{vertices: Number[][],vertexIndex: Number,preventDefault: Function,defaultPrevented: Boolean,type: String} | Fires when a vertex is removed. more details | more details | PolylineDrawAction |
Event Details
- cursor-update
Fires after the pointer moves on the view.
- Properties:
- vertices Number[][]
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. For this event, the type is always
cursor-update
.
Example:// Give a visual feedback to the user as the pointer moves on the view. action.on("cursor-update", function (evt) { view.graphics.removeAll(); var polyline = new Polyline({ paths: evt.vertices, spatialReference: view.spatialReference }); var graphic = createGraphic(polyline); view.graphics.add(graphic); });
- draw-complete
Fires after the user has completed drawing a polyline.
- Properties:
- vertices Number[][]
Two-dimensional array of numbers representing the coordinates of each vertex that make 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. For this event, the type is always
draw-complete
.
Example:// listen to PolylineDrawAction.draw-complete // add the graphic representing the completed // polyline to the view action.on("draw-complete", function (evt) { removeGraphic(graphic); var polyline = new Polyline({ paths: evt.vertices, spatialReference: view.spatialReference }); graphic = createGraphic(polyline); view.graphics.add(graphic); });
- redoSince: ArcGIS API for JavaScript 4.7
Fires in response to redo action or when redo() is called.
- Properties:
- vertices Number[][]
Two-dimensional array of numbers representing the coordinates of each vertex that make the geometry.
vertexIndex NumberIndex of the vertex where
redo
was applied.preventDefault FunctionPrevents event propagation bubbling up the event chain.
defaultPrevented BooleanSet to true when
preventDefault()
is called.type StringThe type of the event. For this event, the type the event that was redone. For instance, the type would be
vertex-add
if a vertex was added as a result ofredo
.
Example:// Update the graphic on the view as the last action was redone action.on("redo", function (evt) { view.graphics.removeAll(); var polyline = new Polyline({ paths: evt.vertices, spatialReference: view.spatialReference }); var graphic = createGraphic(polyline); view.graphics.add(graphic); });
- undoSince: ArcGIS API for JavaScript 4.7
Fires in response to undo action or when undo() is called.
- Properties:
- vertices Number[][]
Two-dimensional array of numbers representing the coordinates of each vertex that make the geometry.
vertexIndex NumberIndex of the vertex where
undo
was applied.preventDefault FunctionPrevents event propagation bubbling up the event chain.
defaultPrevented BooleanSet to true when
preventDefault()
is called.type StringThe type of the event. For this event, the type the event that was undone. For instance, the type would be
vertex-remove
if a vertex was removed as a result ofundo
.
Example:// Update the graphic on the view as the last action was undone action.on("undo", function (evt) { view.graphics.removeAll(); var polyline = new Polyline({ paths: evt.vertices, spatialReference: view.spatialReference }); var graphic = createGraphic(polyline); view.graphics.add(graphic); });
- vertex-add
Fires when a vertex is added.
- Properties:
- vertices Number[][]
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. For this event, the type is always
vertex-add
.
Example:// fires when a vertex is added. action.on("vertex-add", function (evt) { view.graphics.removeAll(); var polyline = new Polyline({ paths: evt.vertices, spatialReference: view.spatialReference }); var graphic = createGraphic(polyline); view.graphics.add(graphic); });
- vertex-remove
Fires when a vertex is removed.
- Properties:
- vertices Number[][]
Two-dimensional array of numbers representing the coordinates of each vertex that make the geometry.
vertexIndex NumberIndex of the vertex removed from 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. For this event, the type is always
vertex-remove
.
Example:// Update the graphic on the view as vertex is removed action.on("vertex-remove", function (evt) { view.graphics.removeAll(); var polyline = new Polyline({ paths: evt.vertices, spatialReference: view.spatialReference }); var graphic = createGraphic(polyline); view.graphics.add(graphic); });