PointDrawAction
require(["esri/views/2d/draw/PointDrawAction"], function(PointDrawAction) { /* code goes here */ });
esri/views/2d/draw/PointDrawAction
This class uses the view events to generate a set of coordinates to create a new Point geometry using Draw. When the draw.create("point") method is called, a reference to PointDrawAction is returned. Listen to PointDrawAction's cursor-update and the draw-complete events to handle the creation of the point geometry.
function enableCreatePoint(draw, view) {
var action = draw.create("point");
// PointDrawAction.cursor-update
// Give a visual feedback to users as they move the pointer over the view
action.on("cursor-update", function (evt) {
createPointGraphic(evt.coordinates);
});
// PointDrawAction.draw-complete
// Create a point when user clicks on the view or presses "C" key.
action.on("draw-complete", function (evt) {
createPointGraphic(evt.coordinates);
});
}
function createPointGraphic(coordinates){
view.graphics.removeAll();
var point = {
type: "point", // autocasts as /Point
x: coordinates[0],
y: coordinates[1],
spatialReference: view.spatialReference
};
var graphic = new Graphic({
geometry: point,
symbol: {
type: "simple-marker", // autocasts as SimpleMarkerSymbol
style: "square",
color: "red",
size: "16px",
outline: { // autocasts as SimpleLineSymbol
color: [255, 255, 0],
width: 3
}
}
});
view.graphics.add(graphic);
}
Constructors
- new PointDrawAction(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 | |
---|---|---|---|---|
Number[] | An array of x,y coordinates for the point geometry. more details | more details | PointDrawAction | |
String | The name of the class. more details | more details | Accessor | |
MapView | A reference to the MapView. more details | more details | DrawAction |
Property Details
- coordinatesNumber[]readonlySince: ArcGIS API for JavaScript 4.6
An array of x,y coordinates for the point geometry.
- Since: ArcGIS API for JavaScript 4.7
The name of the class. The declared class name is formatted as
esri.folder.className
.
A reference to the MapView.
Method Overview
Name | Return Type | Summary | Class | |
---|---|---|---|---|
Completes drawing the point geometry and fires the draw-complete event. more details | more details | PointDrawAction | ||
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 |
Method Details
- complete()
Completes drawing the point 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); });
Event Overview
Name | Type | Summary | Class | |
---|---|---|---|---|
{coordinates: Number[],preventDefault: Function,defaultPrevented: Boolean,type: String} | Fires after the pointer moves on the view. more details | more details | PointDrawAction | |
{coordinates: Number[],preventDefault: Function,defaultPrevented: Boolean,type: String} | Fires after when the user has completed drawing a point. more details | more details | PointDrawAction |
Event Details
- cursor-update
Fires after the pointer moves on the view. It returns the location of the pointer on the view as an array of numbers representing an x,y coordinate pair in the spatial reference of the view.
- Properties:
- coordinates Number[]
An array of numbers representing an x,y coordinate pair in the spatial reference of the view.
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:action.on("cursor-update", function (evt) { view.graphics.removeAll(); var point = new Point({ x: evt.coordinates[0], y: evt.coordinates[1], spatialReference: view.spatialReference }); var graphic = createGraphic(point); view.graphics.add(graphic); });
- draw-complete
Fires after when the user has completed drawing a point. It returns the location of the pointer on the view as an array of numbers representing an x,y coordinate pair in the spatial reference of the view.
- Properties:
- coordinates Number[]
An array of numbers representing an x,y coordinate pair in the spatial reference of the view.
preventDefault FunctionPrevents event propagation bubbling up the event chain.
defaultPrevented BooleanSet to
true
whenpreventDefault()
is called.type StringThe type of the event. For this event, the type is always
draw-complete
.
Example:action.on("draw-complete", function (evt) { view.graphics.removeAll(); var point = new Point({ x: evt.coordinates[0], y: evt.coordinates[1], spatialReference: view.spatialReference }); var graphic = createGraphic(point); view.graphics.add(graphic); });