diff --git a/src/ui/nehubaContainer/nehubaViewer/nehubaViewer.component.ts b/src/ui/nehubaContainer/nehubaViewer/nehubaViewer.component.ts index 226a18e0f1288dbd0440a648a47b5ed06a8c2add..28a41e61f18a9c4a9873aff725154a14be03dfab 100644 --- a/src/ui/nehubaContainer/nehubaViewer/nehubaViewer.component.ts +++ b/src/ui/nehubaContainer/nehubaViewer/nehubaViewer.component.ts @@ -147,16 +147,25 @@ export class NehubaViewerUnit implements OnDestroy{ /* worker responded with not assembled landmark, no need to act */ return false } - if(!message.data.url){ - /* file url needs to be defined */ - return false - } + /** + * nb url may be undefined + * if undefined, user have removed all user landmarks, and all that needs to be done + * is remove the user landmark layer + * + * message.data.url + */ + return true }), debounceTime(100), map(e => e.data.url) ).subscribe(url => { - this.removeSpatialSearch3DLandmarks() + this.removeuserLandmarks() + + /** + * url may be null if user removes all landmarks + */ + if (!url) return const _ = {} _[this.constantService.ngUserLandmarkLayerName] = { type :'mesh', @@ -471,14 +480,31 @@ export class NehubaViewerUnit implements OnDestroy{ } private filterLayers(l:any,layerObj:any):boolean{ - return Object.keys(layerObj).length == 0 && layerObj.constructor == Object ? - true : - Object.keys(layerObj).every(key=> - !(<Object>l).hasOwnProperty(key) && !l[key] ? - false : - layerObj[key] instanceof RegExp ? - layerObj[key].test(l[key]) : - layerObj[key] == l[key]) + debugger + /** + * if selector is an empty object, select all layers + */ + return layerObj instanceof Object && Object.keys(layerObj).every(key => + /** + * the property described by the selector must exist and ... + */ + !!l[key] && + /** + * if the selector is regex, test layer property + */ + ( layerObj[key] instanceof RegExp + ? layerObj[key].test(l[key]) + /** + * if selector is string, test for strict equality + */ + : typeof layerObj[key] === 'string' + ? layerObj[key] === l[key] + /** + * otherwise do not filter + */ + : false + ) + ) } // TODO single landmark for user landmark @@ -487,7 +513,7 @@ export class NehubaViewerUnit implements OnDestroy{ return this.workerService.worker.postMessage({ type : 'GET_USERLANDMARKS_VTK', - scale: Math.min(...this.dim.map(v => v * 2e-9)), + scale: Math.min(...this.dim.map(v => v * this.constantService.nehubaLandmarkConstant)), landmarks : landmarks.map(lm => lm.position.map(coord => coord * 1e6)) }) } diff --git a/src/util/worker.js b/src/util/worker.js index ba6b1627b9adf00e861f08ba494594118bc0dc2b..293d0908b1b145a0283f8bf51e9370c332854db3 100644 --- a/src/util/worker.js +++ b/src/util/worker.js @@ -205,6 +205,22 @@ const getuserLandmarksVtk = (action) => { const scale = action.scale ? action.scale : 2.8 + + /** + * if userlandmarks vtk is empty, that means user removed all landmarks + * thus, removing revoking URL, and send null as assembled userlandmark vtk + */ + if (landmarks.length === 0) { + + if(userLandmarkVtkUrl) URL.revokeObjectURL(userLandmarkVtkUrl) + + postMessage({ + type: 'ASSEMBLED_USERLANDMARKS_VTK' + }) + + return + } + const vtk = parseLmToVtk(landmarks, scale) if(!vtk) return