lixiaojun
2024-09-24 efa99a6d5d1f6868969a02e772f77cd17de3ea83
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
 
let _drawableContainer = null;
 
//设置自定义标签
function setCustomLabels(obj) {
    // 初始化DrawableContainer
    if (_drawableContainer == null) {
        let drawableConfig = new Glodon.Bimface.Plugins.Drawable.DrawableContainerConfig();
        drawableConfig.viewer = _viewer;
        _drawableContainer = new Glodon.Bimface.Plugins.Drawable.DrawableContainer(drawableConfig);
    }
    else {
        _drawableContainer.clear();
    }
    if (obj == null || obj.length < 1) {
        return;
    }
    obj.forEach(item => {
        addCustomLabelItem(item);
    });
}
 
//添加自定义标签项
function addCustomLabelItem(item) {
    let content = document.createElement('div');
    content.style.width = '110px';
    content.style.height = 'auto';
    content.style.border = 'solid';
    content.style.borderColor = '#FFFFFF';
    content.style.padding = '2px';
    content.style.borderWidth = '1px';
    content.style.borderRadius = '3px';
    content.style.background = color;
    content.innerHTML = getTdHtml(item.data);
    content.style.color = '#FFFFFF';
    content.style.fontSize = '10px';
    //content.style.textAlign = 'center';
    content.style.lineHeight = '14px';
 
    let config = new Glodon.Bimface.Plugins.Drawable.CustomItemConfig();
    config.content = content;
    config.viewer = _viewer;
    config.opacity = 1;
    config.worldPosition = item.position;
 
    let customLabelItem = new Glodon.Bimface.Plugins.Drawable.CustomItem(config);
    _drawableContainer.addItem(customLabelItem);
}
 
//清除自定义标签
function clearCustomLabels() {
    if (_drawableContainer == null) {
        return;
    }
    _drawableContainer.clear();
}
 
//获取数据内容html
function getTdHtml(data) {
    if (data == null || data.length < 1) {
        return '';
    }
    let html = '<table>'
    data.forEach(d => {
        html += '<tr><td style="width:50px">' + d.name + '</td><td style="width:40px">' + d.value + '</td><td>' + d.unit + '</td></tr>'
    })
    return html += '</table>'
}