-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add layer toggles for ms, KHz, species
- Loading branch information
1 parent
22c1809
commit f67988d
Showing
6 changed files
with
222 additions
and
24 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
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,120 @@ | ||
/* eslint-disable class-methods-use-this */ | ||
import { SpectrogramAnnotation } from "../../../api/api"; | ||
import { SpectroInfo, spectroToGeoJSon } from "../geoJSUtils"; | ||
import { LayerStyle } from "./types"; | ||
|
||
interface TextData { | ||
text: string; | ||
x: number; | ||
y: number; | ||
offsetY?: number; | ||
offsetX?: number; | ||
} | ||
|
||
export default class SpeciesLayer { | ||
|
||
textData: TextData[]; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
textLayer: any; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
geoViewerRef: any; | ||
|
||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
event: (name: string, data: any) => void; | ||
|
||
spectroInfo: SpectroInfo; | ||
|
||
textStyle: LayerStyle<TextData>; | ||
|
||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
constructor( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
geoViewerRef: any, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
event: (name: string, data: any) => void, | ||
spectroInfo: SpectroInfo | ||
) { | ||
this.geoViewerRef = geoViewerRef; | ||
this.spectroInfo = spectroInfo; | ||
this.textData = []; | ||
this.event = event; | ||
//Only initialize once, prevents recreating Layer each edit | ||
const layer = this.geoViewerRef.createLayer("feature", { | ||
features: ["text"], | ||
}); | ||
this.textLayer = layer | ||
.createFeature("text") | ||
.text((data: TextData) => data.text) | ||
.position((data: TextData) => ({ x: data.x, y: data.y })); | ||
|
||
|
||
this.textStyle = this.createTextStyle(); | ||
} | ||
|
||
|
||
formatData(annotationData: SpectrogramAnnotation[]) { | ||
this.textData = []; | ||
annotationData.forEach((annotation: SpectrogramAnnotation) => { | ||
const polygon = spectroToGeoJSon(annotation, this.spectroInfo); | ||
const [xmin, ymin] = polygon.coordinates[0][0]; | ||
const [xmax, ymax] = polygon.coordinates[0][2]; | ||
// For the compressed view we need to filter out default or NaN numbers | ||
if (Number.isNaN(xmax) || Number.isNaN(xmin) || Number.isNaN(ymax) || Number.isNaN(ymin)) { | ||
return; | ||
} | ||
if (xmax === -1 && ymin === -1 && ymax === -1 && xmin === -1) { | ||
return; | ||
} | ||
let textOffset = 0; | ||
const species = annotation.species; | ||
if (species) { | ||
for (let i =0; i< species.length; i += 1) { | ||
const specie = species[i]; | ||
this.textData.push({ | ||
text: `${specie.common_name}`, | ||
x: xmin + (xmax-xmin) /2.0, | ||
y: ymax , | ||
offsetX:0, | ||
offsetY: -5 + textOffset, | ||
}); | ||
textOffset -= 15; | ||
|
||
} | ||
} | ||
}); | ||
} | ||
|
||
redraw() { | ||
// add some styles | ||
this.textLayer.data(this.textData).style(this.createTextStyle()).draw(); | ||
} | ||
|
||
disable() { | ||
this.textLayer.data([]).draw(); | ||
} | ||
|
||
|
||
createTextStyle(): LayerStyle<TextData> { | ||
return { | ||
...{ | ||
strokeColor: "yellow", | ||
strokeWidth: 2.0, | ||
antialiasing: 0, | ||
stroke: true, | ||
uniformPolygon: true, | ||
fill: false, | ||
}, | ||
color: () => { | ||
return "white"; | ||
}, | ||
offset: (data) => ({ | ||
x: data.offsetX || 0, | ||
y: data.offsetY || 0, | ||
}), | ||
textAlign: 'center', | ||
}; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,15 +1,32 @@ | ||
import { ref, Ref } from 'vue'; | ||
import { cloneDeep } from 'lodash'; | ||
|
||
const annotationState: Ref<AnnotationState> = ref(''); | ||
type LayersVis = 'time' | 'freq' | 'species' |'grid'; | ||
const layerVisibility: Ref<LayersVis[]> = ref([]); | ||
|
||
type AnnotationState = '' | 'editing' | 'creating'; | ||
export default function useState() { | ||
const setAnnotationState = (state: AnnotationState) => { | ||
annotationState.value = state; | ||
}; | ||
return { | ||
function toggleLayerVisibility(value: LayersVis) { | ||
const index = layerVisibility.value.indexOf(value); | ||
const clone = cloneDeep(layerVisibility.value); | ||
if (index === -1) { | ||
// If the value is not present, add it | ||
clone.push(value); | ||
} else { | ||
// If the value is present, remove it | ||
clone.splice(index, 1); | ||
} | ||
layerVisibility.value = clone; | ||
} | ||
return { | ||
annotationState, | ||
setAnnotationState, | ||
toggleLayerVisibility, | ||
layerVisibility, | ||
}; | ||
} | ||
|
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