LineStringInput

Form input for drawing a GeoJSON.LineString. Optionally snaps drawn lines to the OSM road network via OSRM.

Installation

pnpm dlx shadcn@latest add @shadmin/line-string-input

Usage

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

When snapToRoads is set, the input watches the form value and replaces it with an OSRM match result whenever the line has two or more points.

Props

PropRequiredTypeDefaultDescription
sourceRequiredstring-RHF field to write the geometry to.
snapToRoadsOptionalbooleanfalseSnap drawn line to OSM roads using OSRM match.
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 line.
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).