UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

100 lines (96 loc) 3.72 kB
import type CursorUpdateEvent from "./CursorUpdateEvent.js"; import type DrawAction from "./DrawAction.js"; import type DrawCompleteEvent from "./DrawCompleteEvent.js"; import type VertexAddEvent from "./VertexAddEvent.js"; import type { DrawActionProperties } from "./DrawAction.js"; export interface SegmentDrawActionProperties extends DrawActionProperties, Partial<Pick<SegmentDrawAction, "mode">> {} export type SegmentDrawActionMode = "click" | "freehand"; export interface SegmentDrawActionEvents { /** * Fires when a vertex is added. * * @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); * }); */ "vertex-add": VertexAddEvent; /** * Fires after the pointer moves on the view. * * @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); * }); */ "cursor-update": CursorUpdateEvent; /** * Fires after the user has completed drawing a geometry. * * @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); * }); */ "draw-complete": DrawCompleteEvent; } /** * This class uses different [events](https://developers.arcgis.com/javascript/latest/references/core/views/draw/SegmentDrawAction/#SegmentDrawActionEvents) to generate a set of vertices to create a geometry with [drag mode](https://developers.arcgis.com/javascript/latest/references/core/views/draw/SegmentDrawAction/#mode) or with two clicks. * * @since 4.7 * @see [Sample - Prevent drawing a self-intersecting line](https://developers.arcgis.com/javascript/latest/sample-code/draw-line/) */ export default class SegmentDrawAction extends DrawAction { /** * @deprecated * Do not directly reference this property. * Use EventNames and EventTypes helpers from \@arcgis/core/Evented */ "@eventTypes": SegmentDrawActionEvents; constructor(properties?: SegmentDrawActionProperties); /** * 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. * * @default "freehand" * @since 4.7 * @example draw.create("rectangle", {mode: "click"}); */ accessor mode: SegmentDrawActionMode; /** Completes drawing the polygon geometry and fires the [@draw-complete](https://developers.arcgis.com/javascript/latest/references/core/views/draw/SegmentDrawAction/#event-draw-complete) event. */ complete(): void; }