FeatureInput

Form input for drawing and editing a GeoJSON.Feature. Writes { type: "Feature", geometry, properties } to the form value; preserves properties across edits so attribute data isn't lost when the user reshapes the geometry.

Installation

pnpm dlx shadcn@latest add @shadmin/feature-input

Usage

import { FeatureInput } from "@/components/leaflet";
 
<Create>
  <SimpleForm>
    <FeatureInput source="geom" label="Feature" defaultCenter={[48.85, 2.35]} />
  </SimpleForm>
</Create>;

The default draw tool is the polygon. Set shape to switch:

<FeatureInput source="geom" shape="LineString" />

Props

PropRequiredTypeDefaultDescription
sourceRequiredstring-RHF field to write the Feature to.
shapeOptional"Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon""Polygon"Default geometry type when the user starts drawing.
zoomOptionalnumber13Initial zoom level.
defaultCenterOptional[number, number][0, 0]Initial map center [lat, lng].
heightOptionalnumber | string300Height of the map container.
tileUrlOptionalstringOpenStreetMap tile URLTile layer URL template.
attributionOptionalstringOSM attributionTile attribution string.
pathOptionsOptionalL.PathOptions-Vector styling for the drawn shape.
snappableOptionalbooleantrueEnable Geoman snap-to-vertex.
snapDistanceOptionalnumber20Snap radius in pixels.
labelOptionalReactNode-Label rendered above the map.
helperTextOptionalReactNode-Helper text rendered below the map.
disabledOptionalbooleanfalseDisable editing.
validateOptional(v) => string | undefined-RHF-compatible validator(s).

shape

Determines which Geoman draw tool the toolbar exposes when the user starts a new geometry. The persisted Feature.geometry.type may differ if the user later edits the shape with the cut tool.

Property preservation

FeatureInput reads the previous form value at every persist and copies properties from it onto the new Feature. This means:

  • On hydration, the seeded Feature value is left intact — properties are preserved.
  • After an edit (move/reshape), the new Feature re-uses the prior properties.
  • New geometries drawn from scratch (no prior Feature) start with properties: {}.