diff --git a/neuroglancer/src/neuroglancer/ui/annotations.ts b/neuroglancer/src/neuroglancer/ui/annotations.ts index abe2e28..e1a3cad 100644 --- a/neuroglancer/src/neuroglancer/ui/annotations.ts +++ b/neuroglancer/src/neuroglancer/ui/annotations.ts @@ -2147,6 +2147,11 @@ export function updateVolumeRef(ref_id: string) { volume_ref_id = ref_id; } +export function getVolumeRef() { + return volume_ref_id; +} + + let volume_tool_mode: ToolMode = ToolMode.NOOP; export function updateGlobalVolumeMode(mode: ToolMode) { @@ -2181,6 +2186,7 @@ export class PlaceVolumeTool extends PlaceCollectionAnnotationTool { if(restore_from_firebase && urlParams.multiUserMode) { this.mode = volume_tool_mode; + has_volume_tool = true; } this.childTool = this.mode == ToolMode.NOOP ? undefined : new PlacePolygonTool(layer, {...options, parent: this}, this.mode); @@ -2200,6 +2206,10 @@ export class PlaceVolumeTool extends PlaceCollectionAnnotationTool { return } + if(restore_from_firebase) { + volume_ref_id = getVolumeRef(); + } + //@ts-ignore let volume_annotation = this.annotationLayer.source.annotationMap.get(volume_ref_id); diff --git a/neuroglancer/src/neuroglancer/ui/url_hash_binding.ts b/neuroglancer/src/neuroglancer/ui/url_hash_binding.ts index 8b2dcb2..735b42a 100644 --- a/neuroglancer/src/neuroglancer/ui/url_hash_binding.ts +++ b/neuroglancer/src/neuroglancer/ui/url_hash_binding.ts @@ -26,7 +26,7 @@ import { State } from 'neuroglancer/services/state'; import { database, dbRef } from 'neuroglancer/services/firebase'; import { child, get, onValue, ref, update } from "firebase/database"; import { User, getUser } from 'neuroglancer/services/user_loader'; -import { updateGlobalCellSession, updateGlobalCellMode, updateGlobalComSession, updateGlobalComMode, updateGlobalVolumeMode, getInProgressAnnotation, getVolumeToolUsed, clearVolumeToolUsed } from 'neuroglancer/ui/annotations'; +import { updateGlobalCellSession, updateGlobalCellMode, updateGlobalComSession, updateGlobalComMode, updateGlobalVolumeMode, getInProgressAnnotation, getVolumeToolUsed, clearVolumeToolUsed, updateVolumeRef } from 'neuroglancer/ui/annotations'; /** * @file Implements a binding between a Trackable value and the URL hash state. @@ -217,6 +217,13 @@ export class UrlHashBinding extends RefCounted { updateGlobalVolumeMode(snapshot.val()); }); + const stateRefVolumeRef = ref(database, `/test_annotations_tool/volume_ref/${this.stateID}`); + onValue(stateRefVolumeRef, (snapshot) => { + if (getInProgressAnnotation()) { + return; + } + updateVolumeRef(snapshot.val()); + }); /* const stateRefComSession = ref(database, `/test_annotations_tool/volume_session/${this.stateID}`); diff --git a/neuroglancer/src/neuroglancer/ui/volume_session.ts b/neuroglancer/src/neuroglancer/ui/volume_session.ts index 9c8101a..40681fe 100644 --- a/neuroglancer/src/neuroglancer/ui/volume_session.ts +++ b/neuroglancer/src/neuroglancer/ui/volume_session.ts @@ -126,18 +126,28 @@ import { displayWidgets } from '../services/display_widgets'; return } updateVolumeRef(reference.id); - } - if(urlParams.multiUserMode) { - const updates: any = {}; - updates[`/test_annotations_tool/volume_mode/${urlParams.stateID}`] = ToolMode.DRAW; - update(ref(database), updates) - .then(() => { - console.log('Successfully Published Volume Mode State to Firebase'); - }) - .catch((error) => { - console.error(error); - }); + if(urlParams.multiUserMode) { + const updates: any = {}; + updates[`/test_annotations_tool/volume_mode/${urlParams.stateID}`] = ToolMode.DRAW; + update(ref(database), updates) + .then(() => { + console.log('Successfully Published Volume Mode State to Firebase'); + }) + .catch((error) => { + console.error(error); + }); + + updates[`/test_annotations_tool/volume_ref/${urlParams.stateID}`] = reference.id; + update(ref(database), updates) + .then(() => { + console.log('Successfully Published Volume Session State to Firebase'); + }) + .catch((error) => { + console.error(error); + }); + } + } this.dispose();