lixiaojun
2024-10-29 7c4fde84af5d666236c85b784bf13c9295bcb605
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//自定义标签
 
//业务计算自定义标签id列表
let _logicCalcuCustomLabelIds = new Set();
 
//设置业务计算自定义标签
function setLogicCalcuCustomLabels(obj) {
    initialDrawableContainer();
    clearLogicCalcuCustomLabels();
    if (obj == null || obj.length < 1) {
        return;
    }
    obj.forEach(item => {
        addLogicCalcuCustomLabel(item);
    });
}
 
//添加业务计算自定义标签项
function addLogicCalcuCustomLabel(item) {
    let content = document.createElement('div');
    content.className = 'w-fit rounded-md space-y-1.5 text-nowrap flex flex-col';
    content.style.color = 'white';
    content.style.backgroundColor = '#32d3a6';
    content.style.padding = '5px';
    content.style.fontSize = '10px';
    content.innerHTML = getLogicCalcuTdHtml(item.data);
 
    let config = new Glodon.Bimface.Plugins.Drawable.CustomItemConfig();
    config.content = content;
    config.viewer = _viewer;
    config.opacity = 1;
    config.objectId = item.id;
    config.id = "LogicCalcuCustomLabel" + item.id;
    _logicCalcuCustomLabelIds.add(config.id);
 
    let boundingBox = _modeler.getBoundingBoxById(item.id);
    let boundingBoxMin = boundingBox.min;
    let boundingBoxMax = boundingBox.max;
    config.worldPosition = {
        x: (boundingBoxMin.x + boundingBoxMax.x) / 2,
        y: (boundingBoxMin.y + boundingBoxMax.y) / 2,
        z: (boundingBoxMin.z + boundingBoxMax.z) / 2
    };
 
    let customItem = new Glodon.Bimface.Plugins.Drawable.CustomItem(config);
    _drawableContainer.addItem(customItem);
    customItem.setVisibleDistance(item.distance);
}
 
//获取业务计算数据内容html
function getLogicCalcuTdHtml(data) {
    if (data == null || data.length < 1) {
        return '';
    }
    let html = '';
    data.forEach((d) => {
        html += `
        <div class="flex justify-between  items-center">
        <span>${d.name}</span>
        <span class="p-x-8">${d.value}</span>
        <span>${d.unit}</span>
        </div>`;
    });
    return html;
}
 
//清除业务计算自定义标签
function clearLogicCalcuCustomLabels() {
    if (_drawableContainer == null) {
        return;
    }
    if (_logicCalcuCustomLabelIds.size > 0) {
        _logicCalcuCustomLabelIds.forEach(x => _drawableContainer.removeItemById(x));
        _logicCalcuCustomLabelIds.clear();
    }
}