Shuxia Ning
2024-11-25 d4898c5d7e1bbbbba384a0e29f29c066d6f502a7
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//引线标签
 
//id列表
let _logicMarkLeadLabelIds = new Set();
 
//设置
function setLogicMarkLeadLabels(obj) {
    initialDrawableContainer();
    clearLogicMarkLeadLabels();
    if (obj == null || obj.length < 1) {
        return;
    }
    obj.forEach(item => {
        addLogicMarkLeadLabel(item);
    });
}
 
//更新
function updateLogicMarkLeadLabel(item) {
    if (_drawableContainer == null) {
        return;
    }
    if (_logicMarkLeadLabelIds.size > 0) {
        let leadLabelId = getLogicMarkLeadLabelId(item.id);
        let leadLabel = _drawableContainer.getItemById(leadLabelId);
        leadLabel.setText(item.text);
    }
}
 
//更新列表
function updateLogicMarkLeadLabels(data) {
    if (data != null && data.length > 0) {
        data.forEach(x => {
            updateLogicMarkLeadLabel(x);
        });
    }
}
 
//添加
function addLogicMarkLeadLabel(item) {
    if (_drawableContainer == null) {
        return;
    }
    let leadLabel = createLogicMarkLeadLabel(item);
    var leadLabelId = getLogicMarkLeadLabelId(item.id);
    _logicMarkLeadLabelIds.add(leadLabelId);
    _drawableContainer.addItem(leadLabel);
}
 
//创建
function createLogicMarkLeadLabel(item) {
    //引线标签的配置类
    let leadLabelConfig = new Glodon.Bimface.Plugins.Drawable.LeadLabelConfig();
    //引线折点的相对位置
    leadLabelConfig.offset = { x: 27, y: -47 };
    //引线标签的内容
    leadLabelConfig.text = item.text;
    //引线标签关联的构件
    leadLabelConfig.objectId = item.id;
    if (!isEmpty(item.distance)) {
        leadLabelConfig.visibleDistance = item.distance;
    }
    var leadLabelId = getLogicMarkLeadLabelId(item.id);
    leadLabelConfig.id = leadLabelId;
    let boundingBox = _modeler.getBoundingBoxById(item.id);
    let boundingBoxMin = boundingBox.min;
    let boundingBoxMax = boundingBox.max;
    //引线标签的世界坐标
    leadLabelConfig.worldPosition = {
        x: (boundingBoxMin.x + boundingBoxMax.x) / 2,
        y: (boundingBoxMin.y + boundingBoxMax.y) / 2,
        z: (boundingBoxMin.z + boundingBoxMax.z) / 2
    };
    //引线标签是否可拖拽
    leadLabelConfig.draggable = false;
    //引线标签的视图
    leadLabelConfig.viewer = _viewer;
    //文本自适应
    leadLabelConfig.width = null;
 
    let leadLabel = new Glodon.Bimface.Plugins.Drawable.LeadLabel(leadLabelConfig);
    return leadLabel;
}
 
//清除
function clearLogicMarkLeadLabels() {
    if (_drawableContainer == null) {
        return;
    }
    if (_logicMarkLeadLabelIds.size > 0) {
        _logicMarkLeadLabelIds.forEach(x => _drawableContainer.removeItemById(x));
        _logicMarkLeadLabelIds.clear();
    }
}
 
//获取id
function getLogicMarkLeadLabelId(id) {
    return "LogicMarkLeadLabel" + id;
}