LatLngInput

Form input that renders a draggable Leaflet marker. Clicking the map or dragging the marker writes to two React Hook Form fields (latSource and lngSource).

Installation

pnpm dlx shadcn@latest add @shadmin/lat-lng-input

Usage

import { LatLngInput } from "@/components/leaflet";
 
<Create>
  <SimpleForm>
    <LatLngInput
      latSource="lat"
      lngSource="lng"
      defaultPosition={[48.85, 2.35]}
      height={300}
      label="Location"
      helperText="Click or drag the marker to set a location."
    />
  </SimpleForm>
</Create>;

Both latSource and lngSource must exist as fields in your form (add them as hidden inputs or populate them via defaultValues if needed).

Props

PropRequiredTypeDefaultDescription
latSourceRequiredstring-RHF field name for latitude.
lngSourceRequiredstring-RHF field name for longitude.
defaultPositionOptional[number, number][0, 0]Initial map center [lat, lng] when no form value is present.
zoomOptionalnumber13Initial zoom level.
heightOptionalnumber | string300Height of the map container (px or CSS unit).
tileUrlOptionalstringOpenStreetMap tile URLTile layer URL template.
attributionOptionalstringOpenStreetMap attributionHTML attribution string.
labelOptionalReactNode-Label rendered above the map.
helperTextOptionalReactNode-Helper text rendered below the map.