MultipointDrawAction

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

This class uses the view events to generate a set of coordinates to create a new Multipoint geometry using Draw. When the draw.create("multipoint") method is called, a reference to MultipointDrawAction is returned. You can listen to events on the MultipointDrawAction instance, which allows users to create a multipoint that meets criteria specified by the application.

Known Limitations

Currently the MultipointDrawAction is only supported in a MapView.

See also
Example
function enableCreateMultipoint(draw, view) {
  let action = draw.create("multipoint");

  // Give a visual feedback to users as they move the pointer over the view
  action.on("cursor-update", function (evt) {
    createMultipointGraphic(evt.vertices);
  });

  // Fires when the user clicks, or presses the "F" key on the view
  // Can also fire when the "R" key is pressed to redo.
  action.on("vertex-add", function (evt) {
    createMultipointGraphic(evt.vertices);
  });

  // Fires when the "Z" key is pressed to undo the last added point
  action.on("vertex-remove", function (evt) {
    createMultipointGraphic(evt.vertices);
  });

  // Create a point when user clicks on the view or presses "C" key.
  action.on("draw-complete", function (evt) {
    createMultipointGraphic(evt.vertices);
  });
}

function createMultipointGraphic(vertices) {
  view.graphics.removeAll();

  let multipoint = new Multipoint({
    points: vertices,
    spatialReference: view.spatialReference
  });

  graphic = new Graphic({
    geometry: multipoint,
    symbol: {
      type: "simple-marker",
      style: "square",
      color: "red",
      size: "16px",
      outline: {
        color: [255, 255, 0],
        width: 3
      }
    }
  });
  view.graphics.add(graphic);
}

Constructors

new MultipointDrawAction(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.

more details
Accessor
Boolean

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

more details
DrawAction
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

declaredClass Stringreadonly inherited
Since: ArcGIS API for JavaScript 4.7

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
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

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 multipoint geometry and fires the draw-complete event.

more details
MultipointDrawAction
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)inherited
Since: ArcGIS API 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 }
);

// Handle gets removed when the object is destroyed.
this.addHandles(handle);
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(){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 multipoint 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){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.
hasHandles(groupKey){Boolean}inherited
Since: ArcGIS API for JavaScript 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(type, listener){Object}inherited

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()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();
}
removeHandles(groupKey)inherited
Since: ArcGIS API for JavaScript 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(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"}

Fires after the pointer moves on the view.

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

Fires after the user has completed drawing a multipoint.

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

Fires in response to redo action or when redo() is called.

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

Fires in response to undo action or when undo() is called.

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

Fires when a point is added to the multipoint.

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

Fires when a point is removed from the multipoint.

more details
MultipointDrawAction

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 comprises the drawn 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
// fires when the pointer moves on the view.
action.on("cursor-update", function (evt) {
  view.graphics.removeAll();
  let multipoint = new Multipoint({
    points: evt.vertices,
    spatialReference: view.spatialReference
  });
  let graphic = createGraphic(multipoint);
  view.graphics.add(graphic);
});
draw-complete

Fires after the user has completed drawing a multipoint.

Properties
vertices Number[][]

Two-dimensional array of numbers representing the coordinates of each vertex that comprises the drawn 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
// fires when completed drawing the multipoint.
action.on("draw-complete", function (evt) {
  view.graphics.removeAll();
  let multipoint = new Multipoint({
    points: evt.vertices,
    spatialReference: view.spatialReference
  });
  let graphic = createGraphic(multipoint);
  view.graphics.add(graphic);
});
redo
Since: 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 Number

Index of the vertex where redo was applied.

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 the event that was redone. For instance, the type would be vertex-add if a vertex was added as a result of redo.

Example
// Update the graphic on the view as the last action was redone
action.on("redo", function (evt) {
  view.graphics.removeAll();
  let multipoint = new Multipoint({
    points: evt.vertices,
    spatialReference: view.spatialReference
  });
  let graphic = createGraphic(multipoint);
  view.graphics.add(graphic);
});
undo
Since: 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 Number

Index of the vertex where undo was applied.

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 the event that was undone. For instance, the type would be vertex-remove if a vertex was removed as a result of undo.

Example
// Update the graphic on the view as the last action was undone
action.on("undo", function (evt) {
  view.graphics.removeAll();
  let multipoint = new Multipoint({
    points: evt.vertices,
    spatialReference: view.spatialReference
  });
  let graphic = createGraphic(multipoint);
  view.graphics.add(graphic);
});
vertex-add

Fires when a point is added to the multipoint.

Properties
vertices Number[][]

Two-dimensional array of numbers representing the coordinates of each vertex that comprises the drawn 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
// fires when a point is added to the multipoint.
action.on("vertex-add", function (evt) {
  view.graphics.removeAll();
  let multipoint = new Multipoint({
    points: evt.vertices,
    spatialReference: view.spatialReference
  });
  let graphic = createGraphic(multipoint);
  view.graphics.add(graphic);
});
vertex-remove

Fires when a point is removed from the multipoint.

Properties
vertices Number[][]

Two-dimensional array of numbers representing the coordinates of each vertex that comprises the drawn geometry.

vertexIndex Number

Index of the vertex removed from 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-remove".

Example
// fires when a point is removed from multipoint.
action.on("vertex-remove", function (evt) {
  view.graphics.removeAll();
  let multipoint = new Multipoint({
    points: evt.vertices,
    spatialReference: view.spatialReference
  });
  let graphic = createGraphic(multipoint);
  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.