-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from hotosm/feat/way-points
- Loading branch information
Showing
13 changed files
with
217 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
import { getTaskWaypoint } from '@Services/tasks'; | ||
import { useQuery, UseQueryOptions } from '@tanstack/react-query'; | ||
|
||
export const useGetTaskWaypointQuery = ( | ||
projectId: string, | ||
taskId: string, | ||
queryOptions?: Partial<UseQueryOptions>, | ||
) => { | ||
return useQuery({ | ||
queryKey: ['task-description'], | ||
enabled: !!(projectId && taskId), | ||
queryFn: () => getTaskWaypoint(projectId, taskId), | ||
select: (res: any) => res.data, | ||
...queryOptions, | ||
}); | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 153 additions & 3 deletions
156
src/frontend/src/components/DroneOperatorTask/MapSection/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,159 @@ | ||
const DroneOperatorMapBox = () => { | ||
/* eslint-disable react/no-array-index-key */ | ||
import { useEffect } from 'react'; | ||
import { LngLatBoundsLike, Map } from 'maplibre-gl'; | ||
import { useParams } from 'react-router-dom'; | ||
import { FeatureCollection } from 'geojson'; | ||
import { useGetTaskWaypointQuery } from '@Api/tasks'; | ||
import getBbox from '@turf/bbox'; | ||
import { useMapLibreGLMap } from '@Components/common/MapLibreComponents'; | ||
import BaseLayerSwitcher from '@Components/common/MapLibreComponents/BaseLayerSwitcher'; | ||
import VectorLayer from '@Components/common/MapLibreComponents/Layers/VectorLayer'; | ||
import MapContainer from '@Components/common/MapLibreComponents/MapContainer'; | ||
import { GeojsonType } from '@Components/common/MapLibreComponents/types'; | ||
import right from '@Assets/images/rightArrow.png'; | ||
|
||
const MapSection = () => { | ||
const { projectId, taskId } = useParams(); | ||
const { map, isMapLoaded } = useMapLibreGLMap({ | ||
containerId: 'dashboard-map', | ||
mapOptions: { | ||
zoom: 5, | ||
center: [84.124, 28.3949], | ||
maxZoom: 19, | ||
}, | ||
disableRotation: true, | ||
}); | ||
|
||
const { data: taskWayPoints }: any = useGetTaskWaypointQuery( | ||
projectId as string, | ||
taskId as string, | ||
{ | ||
select: (data: any) => { | ||
// refine data and return geojson points and single line string | ||
const refinedData = data?.data?.reduce( | ||
(acc: any, curr: any) => { | ||
return { | ||
...acc, | ||
geojsonListOfPoint: [ | ||
...acc.geojsonListOfPoint, | ||
{ | ||
type: 'FeatureCollection', | ||
features: [ | ||
{ | ||
type: 'Feature', | ||
properties: { | ||
angle: curr?.angle, | ||
gimbal_angle: curr.gimbal_angle, | ||
}, | ||
geometry: { | ||
type: 'Point', | ||
coordinates: curr?.coordinates, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
combinedCoordinates: [ | ||
...acc.combinedCoordinates, | ||
curr?.coordinates, | ||
], | ||
}; | ||
}, | ||
{ | ||
combinedCoordinates: [], | ||
geojsonListOfPoint: [], | ||
}, | ||
); | ||
const { geojsonListOfPoint, combinedCoordinates } = refinedData; | ||
return { | ||
geojsonListOfPoint, | ||
geojsonAsLineString: { | ||
type: 'FeatureCollection', | ||
features: [ | ||
{ | ||
type: 'Feature', | ||
properties: {}, | ||
geometry: { | ||
type: 'LineString', | ||
coordinates: combinedCoordinates, | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
}, | ||
}, | ||
); | ||
|
||
// zoom to task | ||
useEffect(() => { | ||
if (!taskWayPoints?.geojsonAsLineString) return; | ||
const { geojsonAsLineString } = taskWayPoints; | ||
const bbox = getBbox(geojsonAsLineString as FeatureCollection); | ||
map?.fitBounds(bbox as LngLatBoundsLike, { padding: 25 }); | ||
}, [map, taskWayPoints]); | ||
|
||
return ( | ||
<> | ||
<div className="naxatw-h-[70vh] naxatw-w-full naxatw-rounded-xl naxatw-bg-gray-200" /> | ||
<div className="naxatw-h-[70vh] naxatw-w-full naxatw-rounded-xl naxatw-bg-gray-200"> | ||
<MapContainer | ||
map={map} | ||
isMapLoaded={isMapLoaded} | ||
containerId="dashboard-map" | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
}} | ||
> | ||
{taskWayPoints && ( | ||
<> | ||
<VectorLayer | ||
map={map as Map} | ||
isMapLoaded={isMapLoaded} | ||
id="waypoint-line" | ||
geojson={taskWayPoints?.geojsonAsLineString as GeojsonType} | ||
visibleOnMap={!!taskWayPoints} | ||
layerOptions={{ | ||
type: 'line', | ||
paint: { | ||
'line-color': '#000000', | ||
'line-width': 1, | ||
'line-dasharray': [6, 3], | ||
}, | ||
}} | ||
hasImage | ||
image={right} | ||
symbolPlacement="line" | ||
/> | ||
{taskWayPoints?.geojsonListOfPoint?.map( | ||
(point: any, index: number) => { | ||
return ( | ||
<VectorLayer | ||
key={`waypoint-points-vtLayer-${index}`} | ||
map={map as Map} | ||
isMapLoaded={isMapLoaded} | ||
id={`waypoint-directions-${index}`} | ||
geojson={point as GeojsonType} | ||
visibleOnMap={!!taskWayPoints} | ||
layerOptions={{ | ||
type: 'circle', | ||
paint: { | ||
'circle-color': index === 0 ? 'red' : '#176149', | ||
'circle-opacity': 0.8, | ||
'circle-radius': index === 0 ? 9 : 6, | ||
}, | ||
}} | ||
/> | ||
); | ||
}, | ||
)} | ||
</> | ||
)} | ||
<BaseLayerSwitcher /> | ||
</MapContainer> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default DroneOperatorMapBox; | ||
export default MapSection; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/frontend/src/components/Projects/MapSection/VectorLayerWithCluster.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
import { api, authenticated } from '.'; | ||
|
||
export const getTaskWaypoint = (projectId: string, taskId: string) => | ||
authenticated(api).get( | ||
`/waypoint/task/${taskId}/?project_id=${projectId}&download=false`, | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import DroneOperatorDescriptionBox from '@Components/DroneOperatorTask/DescriptionSection'; | ||
import DroneOperatorTaskHeader from '@Components/DroneOperatorTask/Header'; | ||
import MapSection from '@Components/DroneOperatorTask/MapSection'; | ||
|
||
const TaskDescription = () => { | ||
return ( | ||
<> | ||
<div className="naxatw-min-h-[calc(100vh-99px)]"> | ||
<div className="naxatw-mx-auto naxatw-w-11/12 naxatw-max-w-[90rem] naxatw-px-8 naxatw-pb-[2.9375rem] naxatw-pt-3"> | ||
<div className="naxatw-flex naxatw-flex-col naxatw-gap-3"> | ||
<DroneOperatorTaskHeader /> | ||
<div className="naxatw-grid naxatw-grid-cols-[30%_70%] naxatw-gap-5"> | ||
<DroneOperatorDescriptionBox /> | ||
<MapSection /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default TaskDescription; |