//自定义标签
|
|
//业务计算自定义标签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 text-nowrap flex';
|
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;
|
config.visibleDistance = item.distance;
|
_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 = '';
|
// 单元格高
|
const cellHeight = 18;
|
// 中间的值列与两边间距
|
const middleOffset = 2;
|
|
const nameColListHtml = data
|
.map((item) => `<span class="flex-items-center justify-start" style="height: ${cellHeight}px">${item.name}</span>`)
|
.join('');
|
// 名称列
|
const nameColHtml = `
|
<div class="flex flex-col">
|
${nameColListHtml}
|
</div>
|
`;
|
|
const valueColListHtml = data
|
.map((item) => `<span class="flex-items-center justify-center" style="height: ${cellHeight}px">${item.value}</span>`)
|
.join('');
|
// 值列,值列需要与两边有间距
|
const valueColHtml = `
|
<div class="flex flex-col" style="margin-left: ${middleOffset}px; margin-right: ${middleOffset}px">
|
${valueColListHtml}
|
</div>
|
`;
|
|
const unitColListHtml = data
|
.map((item) => `<span class="flex-items-center justify-end" style="height: ${cellHeight}px">${item.unit}</span>`)
|
.join('');
|
// 单位列
|
const unitColHtml = `
|
<div class="flex flex-col">
|
${unitColListHtml}
|
</div>
|
`;
|
|
html += `${nameColHtml}${valueColHtml}${unitColHtml}`;
|
return html;
|
}
|
|
//清除业务计算自定义标签
|
function clearLogicCalcuCustomLabels() {
|
if (_drawableContainer == null) {
|
return;
|
}
|
if (_logicCalcuCustomLabelIds.size > 0) {
|
_logicCalcuCustomLabelIds.forEach(x => _drawableContainer.removeItemById(x));
|
_logicCalcuCustomLabelIds.clear();
|
}
|
}
|