BBoxInput

Form input for drawing an axis-aligned bounding box. The drawn rectangle is converted on save to a GeoJSON.BBox tuple ([west, south, east, north]), and existing bbox values are hydrated back into a rectangle layer for editing.

Installation

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

Pass aspectRatio to lock the stored bbox to a given width / height ratio. The drawn rectangle is resized around its centre before persistence — the on-screen layer keeps the freely-drawn extent until next hydration.

Usage

import { BBoxInput } from "@/components/leaflet";
 
<Create>
  <SimpleForm>
    <BBoxInput
      source="bb"
      label="Area of interest"
      defaultCenter={[48.85, 2.35]}
    />
  </SimpleForm>
</Create>;

Props

PropRequiredTypeDefaultDescription
sourceRequiredstring-RHF field to write the geometry to.
minBBoxArea_m2Optionalnumber-Reserved (validator hook). Not enforced yet.
aspectRatioOptionalnumber-Lock stored bbox to width / height = ratio.
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 rectangle.
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).