ShapeInput

Edits a GeoJSON value in a form field by drawing on a map: kind says what the field holds and picks the tools the toolbar shows. Each finished drawing, vertex drag, move or removal is written to the field, and a part the editor cannot hold shows read-only and stays in the value. The named inputs (PointInput, PolygonInput, ...) are this component with kind and tools set for you.

Loading preview…

Edits a GeoJSON value in a form field by drawing on a map: kind says what the field holds and picks the tools the toolbar shows. Each finished drawing, vertex drag, move or removal is written to the field, and a part the editor cannot hold shows read-only and stays in the value. The named inputs (PointInput, PolygonInput, ...) are this component with kind and tools set for you.

Installation

import { ShapeInput } from "@chelone/react/maps/draw";

See the maps guide for the subpaths, the optional packages and MapsProvider.

Props

PropTypeDefaultDescription
allowSelfIntersectionboolean—Set to false to flag a shape that crosses itself. Defaults to true, which checks nothing.
aspectRationumber—Width over height of a `BBox` value. The stored box grows around its centre to this ratio and never shrinks, and the rectangle on the map follows it.
classNamestring—
defaultCenterreadonly [number, number]—`[lat, lng]`. The map centre while the field is empty. Defaults to `[0, 0]`.
disabledboolean—Shows the shape and hides the toolbar; pan and zoom still work.
fitBoundsboolean—Frame the first value on the map. The user's own edits never refit. Defaults to true.
heightstring | number—In pixels, or any CSS length. Defaults to 300.
helperTextReactNode—
kindShapeValueKind—The kind of value the field holds, which decides what a drawing writes.
labelReactNode—The legend. A string is translated; `false` renders none.
mapStyleMapStyleInput—Defaults to the style from `MapsProvider`.
maxVerticesnumber—Most vertices the shape may have.
minAreaM2number—Smallest area in square metres a polygon may cover.
minVerticesnumber—Fewest vertices the shape may have; a polygon ring counts its distinct vertices. The shape is stored as drawn and the field is flagged.
onCommit(value: ShapeValue | null) => void—Called with the stored value after each drawing or edit has been written to the form, and again after `refine` writes a changed one.
refine(value: ShapeValue, options: { signal: AbortSignal }) => ShapeValue | Promise<ShapeValue | null> | null—Adjusts the value after the user's own drawing or edit, such as snapping a line to roads. It runs once the edit is in the form, never on load or reset, and a newer edit or an unmount aborts `signal`. A result that is not null and differs is written, unless the field changed meanwhile. A thrown error keeps the value as drawn. A null result is "nothing to change" unless `refineFailedMessage` is set, which a throw also notifies.
refineFailedMessagestring—Message key notified as a warning when `refine` resolves to null or throws (an abort excepted), and the value is kept as drawn. `LineStringInput` sets it for `snapToRoads`.
shapeStyleShapeStyle—Partial over `DEFAULT_SHAPE_STYLE`. Read once.
snapDistancenumber—Pixels within which the pointer grabs a vertex or snaps. Read once. Defaults to 20.
snappableboolean—Snap to existing coordinates and lines. Read once. Defaults to true.
sourceSourceProp<TRecord>—The form field holding the GeoJSON value.
toolsreadonly ToolbarTool[]—The toolbar buttons, in order. Defaults to the tools that suit `kind`.
validateValidator | readonly Validator[]—Runs after the limits below.
zoomnumber—Read once at mount. Defaults to 13.