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
26 changes: 25 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 @@ -118,6 +119,26 @@ 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: ${distance.toLocaleString()}m`;
nmcharlton marked this conversation as resolved.
Show resolved Hide resolved
}

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

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

<Box mt={1}>
Expand Down
9 changes: 4 additions & 5 deletions src/context/VerifyContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,10 @@ 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 clickCapture = (payload) => {
Expand Down