diff --git a/bats_ai/core/views/grts_cells.py b/bats_ai/core/views/grts_cells.py index 95a3c078..67e578a3 100644 --- a/bats_ai/core/views/grts_cells.py +++ b/bats_ai/core/views/grts_cells.py @@ -81,3 +81,39 @@ def custom_sort_key(cell): return JsonResponse({'latitude': center_latitude, 'longitude': center_longitude}) except GRTSCells.DoesNotExist: return JsonResponse({'error': f'Cell with cellId={id} does not exist'}, status=200) + + +@router.get('/{id}/bbox') +def get_grts_cell_bbox(request: HttpRequest, id: int): + try: + cells = GRTSCells.objects.filter(grts_cell_id=id) + custom_order = GRTSCells.sort_order() + + def custom_sort_key(cell): + return custom_order.index(cell.sample_frame_id) + + sorted_cells = sorted(cells, key=custom_sort_key) + cell = sorted_cells[0] + geom = cell.geom_4326 + + min_x, min_y, max_x, max_y = geom.extent + + geojson = { + 'type': 'Feature', + 'geometry': { + 'type': 'Polygon', + 'coordinates': [ + [min_x, min_y], + [min_x, max_y], + [max_x, max_y], + [max_x, min_y], + ], + }, + 'properties': { + 'grts_cell_id': id, + 'annotationType': 'rectangle', + }, + } + return JsonResponse(geojson) + except (GRTSCells.DoesNotExist, IndexError): + return JsonResponse({'error': f'Cell with id {id} does not exist'}, status=200) diff --git a/client/src/api/api.ts b/client/src/api/api.ts index 246ce16d..4faae6f5 100644 --- a/client/src/api/api.ts +++ b/client/src/api/api.ts @@ -258,6 +258,18 @@ interface GRTSCellCenter { error?: string; } +interface GRTSCellBbox { + type: string; + geometry: { + type: string; + coordinates: number[][]; + }; + properties: { + grts_cell_id: number; + annotationType: string; + }; +} + export interface RecordingTag { id: number; text: string; @@ -367,6 +379,11 @@ async function getOtherUserAnnotations(recordingId: string) { async function getCellLocation(cellId: number, quadrant?: "SW" | "NE" | "NW" | "SE") { return axiosInstance.get(`/grts/${cellId}`, { params: { quadrant } }); } + +async function getCellBbox(cellId: number) { + return await axiosInstance.get(`/grts/${cellId}/bbox`); +} + async function getFileAnnotations(recordingId: number) { return axiosInstance.get(`recording/${recordingId}/recording-annotations`); } @@ -539,6 +556,7 @@ export { deleteAnnotation, deleteSequenceAnnotation, getCellLocation, + getCellBbox, getCellfromLocation, getGuanoMetadata, getFileAnnotations, diff --git a/client/src/components/MapLocation.vue b/client/src/components/MapLocation.vue index d23d04d5..3da9499f 100644 --- a/client/src/components/MapLocation.vue +++ b/client/src/components/MapLocation.vue @@ -2,6 +2,7 @@