Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: duplicate capture v1: display distance between two selected captures #863

Merged
merged 7 commits into from
Oct 4, 2022
29 changes: 28 additions & 1 deletion src/components/SidePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import Species from './Species';
import CaptureTags from './CaptureTags';
import { VerifyContext } from 'context/VerifyContext';
import { getDistance } from 'geolib';

const SIDE_PANEL_WIDTH = 315;
const CAP_APP_TAG = [
Expand Down Expand Up @@ -87,6 +88,7 @@ function SidePanel(props) {
const classes = useStyles(props);
const verifyContext = useContext(VerifyContext);
const captureSelected = verifyContext.getCaptureSelectedArr();
const captureIdSelected = verifyContext.getCaptureSelectedIdArr();
const [switchApprove, setSwitchApprove] = useState(DEFAULT_SWITCH_APPROVE);
const [morphology, setMorphology] = useState(DEFAULT_MORPHOLOGY);
const [age, setAge] = useState(DEFAULT_AGE);
Expand Down Expand Up @@ -118,6 +120,28 @@ function SidePanel(props) {
}
}

function calculateLatLonDistance(capture1Id, capture2Id) {
let obj1 = verifyContext.captureImages.filter(
(capture) => capture.id == capture1Id
)[0];
let obj2 = verifyContext.captureImages.filter(
(capture) => capture.id == capture2Id
)[0];
const distance = getDistance(
{
latitude: Number(obj1.lat),
longitude: Number(obj1.lon),
},
{
latitude: Number(obj2.lat),
longitude: Number(obj2.lon),
}
);
return `Distance bewteen selected captures: ${(
Math.round(distance * 10) / 10
).toLocaleString()}m`;
}

async function handleSubmit() {
const approveAction =
switchApprove === 0
Expand Down Expand Up @@ -207,7 +231,10 @@ function SidePanel(props) {
Select None
</Button>
</Box>

<Typography className={classes.subtitle}>
{captureIdSelected?.length == 2 &&
calculateLatLonDistance(captureIdSelected[0], captureIdSelected[1])}
</Typography>
<Divider />

<Box mt={1}>
Expand Down
17 changes: 12 additions & 5 deletions src/context/VerifyContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const VerifyContext = createContext({
setCurrentPage: () => {},
setCaptureImagesSelected: () => {},
getCaptureSelectedArr: () => {},
getCaptureSelectedIdArr: () => {},
});

export function VerifyProvider(props) {
Expand Down Expand Up @@ -155,11 +156,16 @@ export function VerifyProvider(props) {
};

const getCaptureSelectedArr = () => {
return Object.keys(captureImagesSelected)
.filter((captureId) => {
return captureImagesSelected[captureId] === true;
})
.map((captureId) => parseInt(captureId));
return Object.keys(captureImagesSelected).filter((captureId) => {
return captureImagesSelected[captureId] === true;
});
// .map((captureId) => parseInt(captureId));
};

const getCaptureSelectedIdArr = () => {
return Object.keys(captureImagesSelected).filter((captureId) => {
return captureImagesSelected[captureId] === true;
});
};

const clickCapture = (payload) => {
Expand Down Expand Up @@ -333,6 +339,7 @@ export function VerifyProvider(props) {
setCurrentPage,
setCaptureImagesSelected,
getCaptureSelectedArr,
getCaptureSelectedIdArr,
};

return (
Expand Down