Skip to content
Snippets Groups Projects
Unverified Commit b2a72358 authored by xgui3783's avatar xgui3783 Committed by GitHub
Browse files

Merge pull request #1368 from FZJ-INM1-BDA/fix_loadAnnotationLayer

fix: api addAnnotation
parents d22fd890 fd0dc79b
No related branches found
No related tags found
No related merge requests found
import { BehaviorSubject, Observable } from "rxjs";
import { distinctUntilChanged } from "rxjs/operators";
import { getUuid } from "src/util/fn";
import { PeriodicSvc } from "src/util/periodic.service";
export type TNgAnnotationEv = {
pickedAnnotationId: string
......@@ -38,6 +39,7 @@ type _AnnotationSpec = Omit<AnnotationSpec, 'type'> & { type: number }
type AnnotationRef = Record<string, unknown>
interface NgAnnotationLayer {
isReady: () => boolean
layer: {
localAnnotations: {
references: {
......@@ -124,16 +126,23 @@ export class AnnotationLayer {
}
}
addAnnotation(spec: AnnotationSpec){
async addAnnotation(spec: AnnotationSpec){
if (!this.nglayer) {
throw new Error(`layer has already been disposed`)
}
const localAnnotations = this.nglayer.layer.localAnnotations
this.idset.add(spec.id)
const annSpec = this.parseNgSpecType(spec)
localAnnotations.add(
annSpec
)
PeriodicSvc.AddToQueue(() => {
if (this.nglayer.isReady()) {
const localAnnotations = this.nglayer.layer.localAnnotations
this.idset.add(spec.id)
const annSpec = this.parseNgSpecType(spec)
localAnnotations.add(
annSpec
)
return true
}
return false
})
}
removeAnnotation(spec: { id: string }) {
if (!this.nglayer) return
......@@ -145,7 +154,7 @@ export class AnnotationLayer {
localAnnotations.references.delete(spec.id)
}
}
updateAnnotation(spec: AnnotationSpec) {
async updateAnnotation(spec: AnnotationSpec) {
const localAnnotations = this.nglayer?.layer?.localAnnotations
if (!localAnnotations) return
const ref = localAnnotations.references.get(spec.id)
......
......@@ -21,7 +21,7 @@ export const useViewer = {
} as const
export const SIIBRA_API_VERSION_HEADER_KEY='x-siibra-api-version'
export const EXPECTED_SIIBRA_API_VERSION = '0.3.8'
export const EXPECTED_SIIBRA_API_VERSION = '0.3.9'
let BS_ENDPOINT_CACHED_VALUE: Observable<string> = null
......
......@@ -5,11 +5,16 @@ import { wait } from "./fn";
providedIn: 'root'
})
export class PeriodicSvc{
async addToQueue(callback: () => boolean) {
return await PeriodicSvc.AddToQueue(callback)
}
/**
* @description retry a callback until it succeeds
* @param callback
*/
async addToQueue(callback: () => boolean) {
static async AddToQueue(callback: () => boolean) {
// eslint-disable-next-line no-constant-condition
while (true) {
if (callback()) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment