@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
110 lines (107 loc) • 4.46 kB
TypeScript
import type CursorUpdateEvent from "./CursorUpdateEvent.js";
import type DrawAction from "./DrawAction.js";
import type DrawCompleteEvent from "./DrawCompleteEvent.js";
import type { DrawActionProperties } from "./DrawAction.js";
export interface PointDrawActionProperties extends DrawActionProperties {}
export interface PointDrawActionEvents {
/**
* 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.
*
* @example
* action.on("cursor-update", function (evt) {
* view.graphics.removeAll();
* let point = new Point({
* x: evt.coordinates[0],
* y: evt.coordinates[1],
* spatialReference: view.spatialReference
* });
* let graphic = createGraphic(point);
* view.graphics.add(graphic);
* });
*/
"cursor-update": CursorUpdateEvent;
/**
* 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.
*
* @example
* action.on("draw-complete", function (evt) {
* view.graphics.removeAll();
* let point = new Point({
* x: evt.coordinates[0],
* y: evt.coordinates[1],
* spatialReference: view.spatialReference
* });
* let graphic = createGraphic(point);
* view.graphics.add(graphic);
* });
*/
"draw-complete": DrawCompleteEvent;
}
/**
* This class uses the view events to generate a set of coordinates to create a new [Point](https://developers.arcgis.com/javascript/latest/references/core/geometry/Point/)
* geometry using [Draw](https://developers.arcgis.com/javascript/latest/references/core/views/draw/Draw/). When the [draw.create("point")](https://developers.arcgis.com/javascript/latest/references/core/views/draw/Draw/#create)
* method is called, a reference to PointDrawAction is returned. Listen to PointDrawAction's
* [@cursor-update](https://developers.arcgis.com/javascript/latest/references/core/views/draw/PointDrawAction/#event-cursor-update) and the [@draw-complete](https://developers.arcgis.com/javascript/latest/references/core/views/draw/PointDrawAction/#event-draw-complete) events to handle the creation of the
* point geometry.
*
* @since 4.5
* @see [Sample - Prevent drawing a self-intersecting line](https://developers.arcgis.com/javascript/latest/sample-code/draw-line/)
* @example
* function enableCreatePoint(draw, view) {
* let 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 the "Enter" key.
* action.on("draw-complete", function (evt) {
* createPointGraphic(evt.coordinates);
* });
* }
*
* function createPointGraphic(coordinates){
* view.graphics.removeAll();
* let point = {
* type: "point", // autocasts as /Point
* x: coordinates[0],
* y: coordinates[1],
* spatialReference: view.spatialReference
* };
*
* let 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);
* }
*/
export default class PointDrawAction extends DrawAction {
/**
* @deprecated
* Do not directly reference this property.
* Use EventNames and EventTypes helpers from \@arcgis/core/Evented
*/
"@eventTypes": PointDrawActionEvents;
constructor(properties?: PointDrawActionProperties);
/**
* Completes drawing the [Point](https://developers.arcgis.com/javascript/latest/references/core/geometry/Point/) geometry and fires the [@draw-complete](https://developers.arcgis.com/javascript/latest/references/core/views/draw/PointDrawAction/#event-draw-complete) event.
* Call this method if the drawing logic needs to be completed other than by double-clicking or pressing the "Enter" key.
*/
complete(): void;
}