Skip to main content

UseDraw

What useDraw returns.

This is an interface exported by @mapcairn/map, checked against version 0.2.0.

Signature​

import type { UseDraw } from "@mapcairn/map";

interface UseDraw

Properties​

addPoint​

readonly addPoint: (at: LatLng) => void;

Adds a point, or starts a shape, at a position.

cancel​

readonly cancel: () => void;

Drops the shape being drawn.

canRedo​

readonly canRedo: boolean;

Whether there is an undone change to reapply.

canUndo​

readonly canUndo: boolean;

Whether there is a change to revert.

clear​

readonly clear: () => void;

Removes every shape.

readonly copyLink: () => Promise<void>;

Copies a link with the shapes in it, built from the current address.

deleteSelected​

readonly deleteSelected: () => void;

Removes the selected shape.

deleteShape​

readonly deleteShape: (shapeId: string) => void;

Removes the shape with this id, whether it is selected or not.

deselect​

readonly deselect: () => void;

Clears the selected shape and vertex.

discardDraft​

readonly discardDraft: () => void;

Removes the shape being drawn without a word, when Done closes the tool.

draft​

readonly draft: DrawShape | null;

The shape being drawn, or null.

exportCsv​

readonly exportCsv: () => Promise<void>;

Saves the shapes as a CSV file through the file saver, and sets feedback to say how it went.

exportGeoJson​

readonly exportGeoJson: () => Promise<void>;

Saves the shapes as a GeoJSON file through the file saver, and sets feedback to say how it went.

exportWkt​

readonly exportWkt: () => Promise<void>;

Saves the shapes as a WKT file through the file saver, and sets feedback to say how it went.

feedback​

readonly feedback: DrawFeedback | null;

The outcome of the last export or copy, until the shapes change.

finish​

readonly finish: () => void;

Ends the shape being drawn.

handles​

readonly handles: readonly MapEditHandle[];

The handles to give the map adapter: those of the selected shape while the tool is open.

hoveredHandle​

readonly hoveredHandle: string | null;

The handle a mouse is over, or null.

importFeedback​

readonly importFeedback: DrawFeedback | null;

What the last import added or why it added nothing, until the shapes change again.

importFile​

readonly importFile: () => Promise<Bounds | null>;

Asks the person for a GeoJSON, CSV or WKT file and adds its shapes as one undo step. Call it straight from a press, so the browser shows the picker.

Returns: The box holding the shapes it added, for the map to fit, or null when it added none, including when the host has no file opener.

insertAtCentre​

readonly insertAtCentre: () => void;

Adds a vertex at the map centre after the selected one.

issue​

readonly issue: DrawIssue | null;

Why the selected shape is not valid after an edit, or null.

issueMessage​

readonly issueMessage: string;

What to do about UseDraw, or an empty string.

keyCommand​

readonly keyCommand: (event: DrawKeyEvent) => boolean;

Runs a key press as a draw command. Returns true when it was one, so the caller can stop the key.

measure​

readonly measure: string;

The measures of the shape being drawn or selected, such as "1.2 ha · 480 m". Empty when none.

mode​

readonly mode: DrawKind;

The kind of shape the next tap starts: point, line, polygon or circle.

moveSelectedTo​

readonly moveSelectedTo: (at: LatLng) => void;

Moves the selected vertex to a position.

nudge​

readonly nudge: (dx: number, dy: number) => void;

Moves the selected vertex by screen pixels (positive x is right, positive y is down).

onHandleDrag​

readonly onHandleDrag: (drag: MapHandleDrag) => void;

A step of a press on an edit handle, from the adapter.

onHandleHover​

readonly onHandleHover: (id: string | null) => void;

Records the edit handle a mouse is over, or null when it leaves, so it can be drawn larger.

onMapClick​

readonly onMapClick: (event: Pick<MapClickEvent, "latlng" | "point">) => void;

A click or tap on the map. Starts, extends or selects a shape.

placeAtCentre​

readonly placeAtCentre: () => void;

Adds a point at the map centre, or moves the selected vertex there.

redo​

readonly redo: () => void;

Reapplies the last undone change. Does nothing when canRedo is false.

removeVertex​

readonly removeVertex: () => void;

Removes the selected vertex.

rereadImport​

readonly rereadImport: (order: WktAxisOrder) => Bounds | null;

Reads the file whose import offered DrawFeedback again in order, and keeps order as the WKT axis order.

Returns: The box holding the shapes it added, as UseDraw does, or null when it added none or there is no such file.

scaleRadius​

readonly scaleRadius: (factor: number) => void;

Multiplies the selected circle's radius.

select​

readonly select: (shapeId: string, vertex?: number | null) => void;

Selects a shape, and a vertex of it when vertex is a number. Without vertex, a point or a circle selects its one vertex, so the arrow keys and Move to map centre work on it; any other shape selects as a whole.

selected​

readonly selected: DrawShape | null;

The selected shape, or null.

selection​

readonly selection: DrawSelection | null;

The selected shape and, when there is one, its selected vertex, or null.

setMode​

readonly setMode: (kind: DrawKind) => void;

Chooses the kind of shape the next tap starts.

setRadiusToCentre​

readonly setRadiusToCentre: () => void;

Sets the selected circle's radius to its distance from the map centre.

setWktAxisOrder​

readonly setWktAxisOrder: (order: WktAxisOrder) => void;

Chooses the order by hand. An offer to read the last file the other way, and the file it kept, are dropped.

shapes​

readonly shapes: readonly DrawShape[];

Every shape, in the order drawn. The last may be unfinished.

state​

readonly state: DrawState;

The draw state as the reducer holds it: the shapes, the mode, the selection and the undo history.

status​

readonly status: string;

A line for the toolbar, such as "Polygon 1, 3 points", or "Nothing drawn yet".

stepVertex​

readonly stepVertex: (delta: 1 | -1) => void;

Moves the selection to the next (1) or previous (-1) vertex of the selected shape.

undo​

readonly undo: () => void;

Reverts the last change to the shapes. Does nothing when canUndo is false.

wktAxisOrder​

readonly wktAxisOrder: WktAxisOrder;

The order of the two numbers in a WKT position that an import reads: longitude first until changed. Kept for the session only.

See also​

Source: packages/map/src/tools/DrawToolbar/useDraw.ts:133