v2: pin responds to input fields

This commit is contained in:
Ben Mitchinson 2025-10-06 23:32:54 -07:00
parent 8e3b848015
commit 799f7b39bd
2 changed files with 27 additions and 7 deletions

View File

@ -37,6 +37,16 @@ const LocationMarker = (props: MarkerProps) => {
map.locate();
}, []);
// Keep marker and map in sync with external position updates
useEffect(() => {
if (props.position) {
setPosition(props.position);
map.setView(props.position);
} else {
setPosition(undefined);
}
}, [props.position, map]);
return position === undefined ? null : <Marker position={position} icon={markerIcon}></Marker>;
};

View File

@ -35,13 +35,23 @@ const LocationSelector = (props: Props) => {
const [popoverOpen, setPopoverOpen] = useState<boolean>(false);
useEffect(() => {
setState((state) => ({
...state,
placeholder: props.location?.placeholder || "",
position: new LatLng(props.location?.latitude || 0, props.location?.longitude || 0),
latInput: String(props.location?.latitude ?? 0),
lngInput: String(props.location?.longitude ?? 0),
}));
if (props.location) {
setState((state) => ({
...state,
placeholder: props.location.placeholder || "",
position: new LatLng(props.location.latitude, props.location.longitude),
latInput: String(props.location.latitude),
lngInput: String(props.location.longitude),
}));
} else {
setState((state) => ({
...state,
placeholder: "",
position: undefined,
latInput: "",
lngInput: "",
}));
}
}, [props.location]);
useEffect(() => {