Skip to content

Commit

Permalink
adding legend capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
BryonLewis committed Jan 25, 2024
1 parent b506734 commit baf0916
Show file tree
Hide file tree
Showing 6 changed files with 359 additions and 2 deletions.
6 changes: 6 additions & 0 deletions client/src/components/SpectrogramViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export default defineComponent({
recordingId: {
type: String as PropType<string | null>,
required: true,
},
grid: {
type: Boolean,
default: true,
}
},
emits: ['update:annotation', 'create:annotation', 'selected', 'geoViewerRef'],
Expand Down Expand Up @@ -63,6 +67,7 @@ export default defineComponent({
};
return {
containerRef,
geoViewerRef: geoJS.getGeoViewer(),
Expand All @@ -87,6 +92,7 @@ export default defineComponent({
:spectro-info="spectroInfo"
:annotations="annotations"
:selected-id="selectedId"
:grid="grid"
@selected="$emit('selected',$event)"
@update:annotation="updateAnnotation($event)"
@create:annotation="createAnnotation($event)"
Expand Down
1 change: 1 addition & 0 deletions client/src/components/ThumbnailViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export default defineComponent({
:spectro-info="spectroInfo"
:annotations="annotations"
:selected-id="selectedId"
thumbnail
@selected="$emit('selected',$event)"
/>
</div>
Expand Down
23 changes: 23 additions & 0 deletions client/src/components/geoJS/LayerManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SpectrogramAnnotation } from "../../api/api";
import { geojsonToSpectro, SpectroInfo } from "./geoJSUtils";
import EditAnnotationLayer from "./layers/editAnnotationLayer";
import RectangleLayer from "./layers/rectangleLayer";
import LegendLayer from "./layers/legendLayer";
import { cloneDeep } from "lodash";
import useState from "../../use/useState";
export default defineComponent({
Expand All @@ -26,6 +27,14 @@ export default defineComponent({
type: Number as PropType<number | null>,
default: null,
},
thumbnail: {
type: Boolean,
default: false,
},
grid: {
type: Boolean,
default: true,
}
},
emits: ['selected', 'update:annotation', 'create:annotation'],
setup(props, { emit }) {
Expand All @@ -37,6 +46,7 @@ export default defineComponent({
const editingAnnotation: Ref<null | SpectrogramAnnotation> = ref(null);
let rectAnnotationLayer: RectangleLayer;
let editAnnotationLayer: EditAnnotationLayer;
let legendLayer: LegendLayer;
const displayError = ref(false);
const errorMsg = ref('');
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -161,6 +171,9 @@ export default defineComponent({
rectAnnotationLayer.formatData(localAnnotations.value, selectedAnnotationId.value);
rectAnnotationLayer.redraw();
}
if (!props.thumbnail) {
legendLayer.redraw();
}
if (editing.value && editingAnnotation.value) {
setTimeout(() => {
editAnnotationLayer.changeData(editingAnnotation.value);
Expand All @@ -185,6 +198,16 @@ export default defineComponent({
editAnnotationLayer = new EditAnnotationLayer(props.geoViewerRef, event, props.spectroInfo);
rectAnnotationLayer.formatData(localAnnotations.value, selectedAnnotationId.value);
rectAnnotationLayer.redraw();
if (!props.thumbnail) {
legendLayer = new LegendLayer(props.geoViewerRef, event, props.spectroInfo);
legendLayer.redraw();
}
}
});
watch(() => props.grid, () => {
if (!props.thumbnail && legendLayer) {
legendLayer.setGridEnabled(props.grid);
triggerUpdate();
}
});
watch(
Expand Down
7 changes: 6 additions & 1 deletion client/src/components/geoJS/geoJSUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ const useGeoJS = () => {
const { width: mapWidth } = geoViewer.value.camera().viewport;

const bounds = !thumbnail.value
? { left: 0, top: 0, right: mapWidth, bottom: originalBounds.bottom }
? {
left: -125, // Making sure the legend is on the screen
top: 0,
right: mapWidth,
bottom: originalBounds.bottom,
}
: originalBounds;
const zoomAndCenter = geoViewer.value.zoomAndCenterFromBounds(bounds, 0);
geoViewer.value.zoom(zoomAndCenter.zoom);
Expand Down
Loading

0 comments on commit baf0916

Please sign in to comment.