fix annotation hierarchy loading

This commit is contained in:
m-schuetz 2019-11-09 20:03:14 +01:00
parent 411ae82f11
commit ca971137a7
2 changed files with 57 additions and 45 deletions

View File

@ -190,24 +190,61 @@ function loadAnnotations(viewer, data){
return;
}
const {items, hierarchy} = data;
const findDuplicate = (item) => {
const existingAnnotations = [];
viewer.scene.annotations.traverseDescendants(annotation => {
existingAnnotations.push(annotation);
});
let duplicate = null;
for(const item of items){
viewer.scene.annotations.traverse( a => {
if(a.uuid === item.uuid){
duplicate = a;
}
});
const duplicate = existingAnnotations.find(ann => ann.uuid === item.uuid);
return duplicate;
};
const traverse = (item, parent) => {
const duplicate = findDuplicate(item);
if(duplicate){
continue;
return;
}
const annotation = loadAnnotationItem(item);
viewer.scene.annotations.add(annotation);
for(const childItem of item.children){
traverse(childItem, annotation);
}
parent.add(annotation);
};
for(const item of data){
traverse(item, viewer.scene.annotations);
// viewer.scene.annotations.add(annotation);
}
// const {items, hierarchy} = data;
// const existingAnnotations = [];
// viewer.scene.annotations.traverseDescendants(annotation => {
// existingAnnotations.push(annotation);
// });
// for(const item of items){
// const duplicate = existingAnnotations.find(ann => ann.uuid === item.uuid);
// if(duplicate){
// continue;
// }
// const annotation = loadAnnotationItem(item);
// viewer.scene.annotations.add(annotation);
// }
}
function loadProfile(viewer, data){

View File

@ -107,10 +107,11 @@ function createAnnotationData(annotation){
const data = {
uuid: annotation.uuid,
title: annotation.title,
title: annotation.title.toString(),
description: annotation.description,
position: annotation.position.toArray(),
offset: annotation.offset.toArray(),
children: [],
};
if(annotation.cameraPosition){
@ -130,50 +131,24 @@ function createAnnotationData(annotation){
function createAnnotationsData(viewer){
const annotations = [];
const annMap = new Map();
const map = new Map();
viewer.scene.annotations.traverseDescendants(a => {
annotations.push(a);
const aData = createAnnotationData(a);
annMap.set(a, annMap.size);
map.set(a, aData);
});
const root = {};
const stack = [
{
from: viewer.scene.annotations,
to: root,
}
];
const hierarchy = {}
const mapping = new Map();
mapping.set(viewer.scene.annotations, hierarchy);
while(stack.length > 0){
const entry = stack.shift();
for (let child of entry.from.children) {
let id = annMap.get(child);
entry.to[id] = {
from: child,
to: {},
};
const node = {};
mapping.set(child, node);
mapping.get(entry.from)[id] = node;
stack.push(entry.to[id]);
for(const [annotation, data] of map){
for(const child of annotation.children){
const childData = map.get(child);
data.children.push(childData);
}
}
const annotations = viewer.scene.annotations.children.map(a => map.get(a));
return {
items: annotations.map(createAnnotationData),
hierarchy: hierarchy,
};
return annotations;
}
function createSettingsData(viewer){