//引线标签 //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; }