import React, { useState } from "react";
import { LatLng } from "leaflet";
import { ConvertDDToDMS, DDToDDM, latLngToMGRS, latLngToUTM, zeroAppend } from "../../other/utils";
export function OlLocation(props: { location: LatLng; className?: string; referenceSystem?: string; onClick?: () => void; onRefSystemChange?: (refSystem: string) => any }) {
const [referenceSystem, setReferenceSystem] = props.referenceSystem ? [props.referenceSystem, () => {}] : useState("LatLngDec");
const MGRS = latLngToMGRS(props.location.lat, props.location.lng, 6);
if (referenceSystem === "MGRS") {
return (
{
setReferenceSystem("LatLngDec");
props.onRefSystemChange ? props.onRefSystemChange("LatLngDec") : null;
ev.stopPropagation();
}
}
>
MGRS
{MGRS ? MGRS.string : "Error"}
);
} else if (referenceSystem === "LatLngDec") {
return (
{
setReferenceSystem("LatLngDMS");
props.onRefSystemChange ? props.onRefSystemChange("LatLngDMS") : null;
ev.stopPropagation();
}
}
>
{props.location.lat >= 0 ? "N" : "S"}
{zeroAppend(props.location.lat, 3, true, 6)}°
{props.location.lng >= 0 ? "E" : "W"}
{zeroAppend(props.location.lng, 3, true, 6)}°
);
} else if (referenceSystem === "LatLngDMS") {
return (
{
setReferenceSystem("LatLngDDM");
props.onRefSystemChange ? props.onRefSystemChange("LatLngDDM") : null;
ev.stopPropagation();
}
}
>
{props.location.lat >= 0 ? "N" : "S"}
{ConvertDDToDMS(props.location.lat, false)}
{props.location.lng >= 0 ? "E" : "W"}
{ConvertDDToDMS(props.location.lng, false)}
);
} else if (referenceSystem === "LatLngDDM") {
return (
{
setReferenceSystem("MGRS");
props.onRefSystemChange ? props.onRefSystemChange("MGRS") : null;
ev.stopPropagation();
}
}
>
{props.location.lat >= 0 ? "N" : "S"}
{DDToDDM(props.location.lat)}
{props.location.lng >= 0 ? "E" : "W"}
{DDToDDM(props.location.lng)}
);
} else {
}
}