SimplifyInput

Form-aware control that simplifies a GeoJSON shape stored in the form value using @turf/simplify (Douglas-Peucker). Renders a Leaflet preview of the simplified result, a tolerance slider, and a quality toggle.

Installation

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

The original geometry is captured on mount; every slider/quality change re-simplifies from that snapshot, so sliding tolerance back to 0 restores the original.

Usage

import { SimplifyInput } from "@/components/leaflet";
 
<Edit>
  <SimpleForm>
    <SimplifyInput
      source="area"
      label="Simplify"
      helperText="Adjust slider to lower the vertex count"
      defaultCenter={[48.85, 2.35]}
    />
  </SimpleForm>
</Edit>;

The source value must be a GeoJSON.Geometry, GeoJSON.Feature, GeoJSON.FeatureCollection, or null. Anything else throws.

Props

PropRequiredTypeDefaultDescription
sourceRequiredstring-RHF field that holds the GeoJSON value.
toleranceOptionalnumber0.01Initial slider value (Douglas-Peucker tolerance).
minToleranceOptionalnumber0Minimum slider value.
maxToleranceOptionalnumber0.05Maximum slider value.
stepOptionalnumber0.001Slider step.
qualityOptional"Default" | "High""Default""High" maps to simplify's highQuality: true.
zoomOptionalnumber13Initial zoom level.
defaultCenterOptional[number, number][0, 0]Initial map center [lat, lng].
heightOptionalnumber | string400Height of the map container.
tileUrlOptionalstringOpenStreetMap tile URLTile layer URL template.
attributionOptionalstringOSM attributionTile attribution string.
pathOptionsOptionalL.PathOptions{ color: "#3388ff" }Vector styling for the preview layer.
labelOptionalReactNode-Label rendered above the map.
helperTextOptionalReactNode-Helper text rendered below the controls.

tolerance

The Douglas-Peucker tolerance (in the same units as the input coordinates — degrees for lat/lng). Higher tolerance → fewer vertices.

quality

"High" enables simplify-js's more expensive but more accurate algorithm. Use for finishing passes when interactivity matters less than fidelity.