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/flightplan rotation #400

Merged
merged 6 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -291,42 +291,43 @@ const DescriptionBox = () => {
</Button>
</div>
)}
{taskAssetsInformation?.state === 'IMAGE_PROCESSING_FAILED' && (
<div className="naxatw-flex naxatw-flex-col naxatw-gap-1 naxatw-pb-4">
<Label>
<p className="naxatw-text-[0.875rem] naxatw-font-semibold naxatw-leading-normal naxatw-tracking-[0.0175rem] naxatw-text-[#D73F3F]">
Upload Images
{taskAssetsInformation?.state === 'IMAGE_PROCESSING_FAILED' ||
(taskAssetsInformation?.state === 'IMAGE_UPLOADED' && (
<div className="naxatw-flex naxatw-flex-col naxatw-gap-1 naxatw-pb-4">
<Label>
<p className="naxatw-text-[0.875rem] naxatw-font-semibold naxatw-leading-normal naxatw-tracking-[0.0175rem] naxatw-text-[#D73F3F]">
Upload Images
</p>
</Label>
<SwitchTab
options={[
{
name: 'image-upload-for',
value: 'add',
label: 'Add to existing',
},
{
name: 'image-upload-for',
value: 'replace',
label: 'Replace existing',
},
]}
valueKey="value"
selectedValue={uploadedImageType}
activeClassName="naxatw-bg-red naxatw-text-white"
onChange={(selected: Record<string, any>) => {
dispatch(setUploadedImagesType(selected.value));
}}
/>
<p className="naxatw-px-1 naxatw-py-1 naxatw-text-xs">
Note:{' '}
{uploadedImageType === 'add'
? 'Uploaded images will be added with the existing images.'
: 'Uploaded images will be replaced with all the existing images and starts processing.'}
</p>
</Label>
<SwitchTab
options={[
{
name: 'image-upload-for',
value: 'add',
label: 'Add to existing',
},
{
name: 'image-upload-for',
value: 'replace',
label: 'Replace existing',
},
]}
valueKey="value"
selectedValue={uploadedImageType}
activeClassName="naxatw-bg-red naxatw-text-white"
onChange={(selected: Record<string, any>) => {
dispatch(setUploadedImagesType(selected.value));
}}
/>
<p className="naxatw-px-1 naxatw-py-1 naxatw-text-xs">
Note:{' '}
{uploadedImageType === 'add'
? 'Uploaded images will be added with the existing images.'
: 'Uploaded images will be replaced with all the existing images and starts processing.'}
</p>
<UploadsBox label="" />
</div>
)}
<UploadsBox label="" />
</div>
))}
</div>
)}
</>
Expand Down
34 changes: 31 additions & 3 deletions src/frontend/src/components/DroneOperatorTask/MapSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import LocateUser from '@Components/common/MapLibreComponents/LocateUser';
import MapContainer from '@Components/common/MapLibreComponents/MapContainer';
import { GeojsonType } from '@Components/common/MapLibreComponents/types';
import { Button } from '@Components/RadixComponents/Button';
import { postTaskWaypoint } from '@Services/tasks';
import { postRotatedTaskWayPoint, postTaskWaypoint } from '@Services/tasks';
import AsyncPopup from '@Components/common/MapLibreComponents/NewAsyncPopup';
import { toggleModal } from '@Store/actions/common';
import {
Expand Down Expand Up @@ -480,6 +480,31 @@ const MapSection = ({ className }: { className?: string }) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dragging, isMapLoaded, map]);

const { mutate: postRotatedFlightPlan, isLoading: flighplanIsUpdating } =
useMutation({
mutationFn: postRotatedTaskWayPoint,
onSuccess: () => {
toast.success('Flight plan rotated successfully');
queryClient.invalidateQueries(['task-waypoints']);
},
onError: (err: any) => {
toast.error(err?.response?.data?.detail || err.message);
},
});

function handeSaveRotatedFlightPlan() {
if (!map || !isMapLoaded) return;
const pointsSource = map.getSource('waypoint-points');

if (pointsSource && pointsSource instanceof GeoJSONSource) {
const pointsData = pointsSource?._data;
postRotatedFlightPlan({
taskId,
data: JSON.stringify(pointsData),
});
}
}

return (
<>
<div
Expand Down Expand Up @@ -634,14 +659,17 @@ const MapSection = ({ className }: { className?: string }) => {
withLoader
leftIcon="save"
className="naxatw-w-[10.8rem] naxatw-bg-red"
isLoading={flighplanIsUpdating}
disabled={rotationAngle === 0}
onClick={() => handeSaveRotatedFlightPlan()}
>
<FlexColumn className="naxatw-gap-1">
<p className="naxatw-leading-3 naxatw-tracking-wide">
Save Rotated Flight Plan
</p>
{/* <p className="naxatw-font-normal naxatw-leading-3">
Rotated: {rotationAngle.toFixed(2)}Β°
</p> */}
Rotated: {rotationAngle.toFixed(2)}Β°
</p> */}
</FlexColumn>
</Button>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/frontend/src/constants/createProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,3 @@ export const demFileOptions = [
},
{ name: 'Upload DEM File', label: 'Upload DEM File', value: 'manual' },
];

7 changes: 7 additions & 0 deletions src/frontend/src/services/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ export const getTaskAssetsInfo = (projectId: string, taskId: string) =>

export const postProcessImagery = (projectId: string, taskId: string) =>
authenticated(api).post(`/projects/process_imagery/${projectId}/${taskId}/`);

export const postRotatedTaskWayPoint = (payload: Record<string, any>) => {
const { taskId, data } = payload;
return authenticated(api).post(`/waypoint/${taskId}/generate-kmz/`, data, {
headers: { 'Content-Type': 'application/json' },
});
};
Loading