diff --git a/src/atlasComponents/annotations/annotation.service.ts b/src/atlasComponents/annotations/annotation.service.ts index f0a63f7aa298c0cad46efcd96a1dfbe452f1098b..543271a3a11ac766c9f194152d06b3c497a26a4f 100644 --- a/src/atlasComponents/annotations/annotation.service.ts +++ b/src/atlasComponents/annotations/annotation.service.ts @@ -1,6 +1,7 @@ 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) diff --git a/src/atlasComponents/sapi/sapi.service.ts b/src/atlasComponents/sapi/sapi.service.ts index e1648fcc7c99cc8b263ef532fc9ea01e7363fb72..b5aaf5bc4a03501f57dda3e3312240f67b800343 100644 --- a/src/atlasComponents/sapi/sapi.service.ts +++ b/src/atlasComponents/sapi/sapi.service.ts @@ -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 diff --git a/src/util/periodic.service.ts b/src/util/periodic.service.ts index d32637ced9f44e3db18dd5a4de9d80767cac5b64..f73f640769fdd91f89ec6086d167061eb7ba59a1 100644 --- a/src/util/periodic.service.ts +++ b/src/util/periodic.service.ts @@ -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()) {