Skip to content

Commit

Permalink
adding map component and update recording
Browse files Browse the repository at this point in the history
  • Loading branch information
BryonLewis committed Feb 2, 2024
1 parent 75477e1 commit f9ffb82
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.DS_Store
/**/*.shp
/**/*.shx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
('core', '0004_spectrogram'),
]
Expand All @@ -14,6 +13,8 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='recording',
name='recording_location',
field=django.contrib.gis.db.models.fields.GeometryField(blank=True, null=True, srid=4326),
field=django.contrib.gis.db.models.fields.GeometryField(
blank=True, null=True, srid=4326
),
),
]
3 changes: 3 additions & 0 deletions bats_ai/core/views/recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def update_recording(request: HttpRequest, id: int, recording_data: RecordingUpl
recording.recorded_date = converted_date
if recording_data.publicVal is not None and recording_data.publicVal != recording.public:
recording.public = recording_data.publicVal
if recording_data.latitude and recording_data.longitude:
point = Point(recording_data.longitude, recording_data.latitude)
recording.recording_location = point

recording.save()

Expand Down
2 changes: 1 addition & 1 deletion client/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface Recording {
recorded_date: string;
equipment?: string,
comments?: string;
recording_location?: null | [number, number],
recording_location?: null | GeoJSON.Point,
grts_cell_id?: null | number;
grts_cell?: null | number;
public: boolean;
Expand Down
95 changes: 95 additions & 0 deletions client/src/components/MapLocation.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!-- eslint-disable @typescript-eslint/no-explicit-any -->
<script lang="ts">
import { defineComponent, PropType, Ref, ref } from "vue";
import useState from "../use/useState";

Check warning on line 4 in client/src/components/MapLocation.vue

View workflow job for this annotation

GitHub Actions / Lint [eslint]

'useState' is defined but never used
import { watch } from "vue";
import geo, { GeoEvent } from "geojs";

export default defineComponent({
name: "MapLocation",
components: {},
props: {
editor: {
type: Boolean,
default: true,
},
size: {
type: Object as PropType<{ width: number; height: number }>,
default: () => ({ width: 300, height: 300 }),
},
location: {
type: Object as PropType<{ x?: number; y?: number } | undefined>,
default: () => undefined,
},
},
emits: ['location'],
setup(props, { emit }) {
const mapRef: Ref<HTMLDivElement | null> = ref(null);
const map: Ref<any> = ref();
const mapLayer: Ref<any> = ref();
const markerLayer: Ref<any> = ref();
const markerFeature: Ref<any> = ref();
const markerLocation: Ref<{ x: number; y: number } | null> = ref(null);
watch(mapRef, () => {
if (mapRef.value) {
const usCenter = { x: -90.5855, y: 39.8333 };
const centerPoint = props.location && props.location.x && props.location.y ? props.location : usCenter;
const zoomLevel = props.location && props.location.x && props.location.y ? 6 : 3;
map.value = geo.map({ node: mapRef.value, center: centerPoint, zoom: zoomLevel });
mapLayer.value = map.value.createLayer("osm");
markerLayer.value = map.value.createLayer("feature", { features: ["marker"] });
markerFeature.value = markerLayer.value.createFeature("marker");
if (props.location?.x && props.location?.y) {
markerLocation.value = { x: props.location?.x, y: props.location.y };
markerFeature.value
.data([markerLocation.value])
.style({
symbol: geo.markerFeature.symbols.drop,
symbolValue: 1 / 3,
rotation: -Math.PI / 2,
radius: 30,
strokeWidth: 5,
strokeColor: "blue",
fillColor: "yellow",
rotateWithMap: false,
})
.draw();
}
if (props.editor) {
mapLayer.value.geoOn(geo.event.mouseclick, (e: GeoEvent) => {
// Place a marker at the point
const { x, y } = e.geo;
markerLocation.value = { x, y };
markerFeature.value
.data([markerLocation.value])
.style({
symbol: geo.markerFeature.symbols.drop,
symbolValue: 1 / 3,
rotation: -Math.PI / 2,
radius: 30,
strokeWidth: 5,
strokeColor: "blue",
fillColor: "yellow",
rotateWithMap: false,
})
.draw();
emit('location', { lon: x, lat:y });

});
}
}
});
return {
mapRef,
};
},
});
</script>

<template>
<v-card class="pa-0 ma-0">
<div ref="mapRef" :style="`width:${size.width}px; height:${size.height}px`" />

Check warning on line 91 in client/src/components/MapLocation.vue

View workflow job for this annotation

GitHub Actions / Lint [eslint]

':style' should be on a new line
</v-card>
</template>

<style lang="scss" scoped></style>
29 changes: 24 additions & 5 deletions client/src/components/UploadRecording.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import { RecordingMimeTypes } from '../constants';
import useRequest from '../use/useRequest';
import { UploadLocation, uploadRecordingFile, patchRecording } from '../api/api';
import { VDatePicker } from 'vuetify/labs/VDatePicker';
import MapLocation from './MapLocation.vue';
export interface EditingRecording {
id: number,
name: string,
date: string,
equipment: string,
comments: string,
public: boolean;
location?: { lat: number, lon: number },
}
export default defineComponent({
components: {
VDatePicker,
MapLocation,
},
props: {
editing: {
Expand All @@ -36,8 +38,8 @@ export default defineComponent({
const equipment = ref(props.editing ? props.editing.equipment : '');
const comments = ref(props.editing ? props.editing.comments : '');
const validForm = ref(false);
const latitude: Ref<number | undefined> = ref();
const longitude: Ref<number | undefined> = ref();
const latitude: Ref<number | undefined> = ref(props.editing?.location?.lat ? props.editing.location.lat : undefined);
const longitude: Ref<number | undefined> = ref(props.editing?.location?.lon ? props.editing.location.lon : undefined);
const gridCellId: Ref<number | undefined> = ref();
const publicVal = ref(props.editing ? props.editing.public : false);
const readFile = (e: Event) => {
Expand Down Expand Up @@ -110,6 +112,11 @@ export default defineComponent({
recordedDate.value = new Date(time as string).toISOString().split('T')[0];
};
const setLocation = ({lat, lon}: {lat: number, lon: number}) => {
latitude.value = lat;
longitude.value = lon;
};
return {
errorText,
fileModel,
Expand All @@ -131,6 +138,7 @@ export default defineComponent({
readFile,
handleSubmit,
updateTime,
setLocation,
};
},
});
Expand Down Expand Up @@ -250,24 +258,35 @@ export default defineComponent({
<v-expansion-panel>
<v-expansion-panel-title>Location</v-expansion-panel-title>
<v-expansion-panel-text>
<v-row>
<v-row class="mt-2">
<v-text-field
v-model="latitude"
type="number"
label="LAT:"
class="mx-4"
/>
<v-text-field
v-model="longitude"
type="number"
label="LON:"
class="mx-4"
/>
</v-row>
<v-row>
<v-text-field
v-model="gridCellId"
type="number"
label="NABat Gird Cell"
label="NABat Grid Cell"
/>
</v-row>
<v-row>
<v-spacer />
<map-location
:size="{width: 600, height: 400}"
:location="{ x: latitude, y: longitude}"
@location="setLocation($event)"
/>
<v-spacer />
</v-row>
</v-expansion-panel-text>
</v-expansion-panel>
Expand Down
64 changes: 61 additions & 3 deletions client/src/views/Recordings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import {
VDataTable,
} from "vuetify/labs/VDataTable";
import UploadRecording, { EditingRecording } from '../components/UploadRecording.vue';
import MapLocation from '../components/MapLocation.vue';
export default defineComponent({
components: {
VDataTable,
UploadRecording,
MapLocation,
},
setup() {
const itemsPerPage = ref(-1);
Expand Down Expand Up @@ -40,7 +42,10 @@ export default defineComponent({
title:'Public',
key:'public',
},
{
title: 'Location',
key:'recording_location'
},
{
title:'Equipment',
key:'equipment',
Expand Down Expand Up @@ -72,7 +77,10 @@ export default defineComponent({
title:'Public',
key:'public',
},
{
title: 'Location',
key:'recording_location'
},
{
title:'Equipment',
key:'equipment',
Expand Down Expand Up @@ -110,6 +118,10 @@ export default defineComponent({
public: item.public,
id: item.id,
};
if (item.recording_location) {
const [ lat, lon ] = item.recording_location.coordinates;
editingRecording.value['location'] = {lat, lon};
}
uploadDialog.value = true;
};
Expand Down Expand Up @@ -165,6 +177,29 @@ export default defineComponent({
{{ item.raw.name }}
</router-link>
</template>
<template #item.recording_location="{ item }">
<v-menu
v-if="item.raw.recording_location"
open-on-hover
>
<template #activator="{ props }">
<v-icon v-bind="props">
mdi-map
</v-icon>
</template>
<v-card>
<map-location
:editor="false"
:size="{width: 400, height: 400}"
:location="{ x: item.raw.recording_location.coordinates[0], y: item.raw.recording_location.coordinates[1]}"
/>
</v-card>
</v-menu>
<v-icon v-else color="error">

Check warning on line 198 in client/src/views/Recordings.vue

View workflow job for this annotation

GitHub Actions / Lint [eslint]

'color' should be on a new line
mdi-close
</v-icon>
</template>

<template #item.public="{ item }">
<v-icon
v-if="item.raw.public"
Expand All @@ -183,7 +218,7 @@ export default defineComponent({
</v-card-text>
<v-dialog
v-model="uploadDialog"
width="400"
width="700"
>
<upload-recording
:editing="editingRecording"
Expand Down Expand Up @@ -229,6 +264,29 @@ export default defineComponent({
mdi-close
</v-icon>
</template>
<template #item.recording_location="{ item }">
<v-menu
v-if="item.raw.recording_location"
open-on-hover
>
<template #activator="{ props }">
<v-icon v-bind="props">
mdi-map
</v-icon>
</template>
<v-card>
<map-location
:editor="false"
:size="{width: 400, height: 400}"
:location="{ x: item.raw.recording_location.coordinates[0], y: item.raw.recording_location.coordinates[1]}"
/>
</v-card>
</v-menu>
<v-icon v-else color="error">

Check warning on line 285 in client/src/views/Recordings.vue

View workflow job for this annotation

GitHub Actions / Lint [eslint]

'color' should be on a new line
mdi-close
</v-icon>
</template>

<template #item.userMadeAnnotations="{ item }">
<v-icon
v-if="item.raw.userMadeAnnotations"
Expand Down
Loading

0 comments on commit f9ffb82

Please sign in to comment.