YZProjectCloud/yanzhu-bigscreen/src/views/bim/briefingTools.js

179 lines
5.1 KiB
JavaScript
Raw Normal View History

2025-06-19 17:11:30 +08:00
function groupData(data) {
let tmps = [];
let obj = {};
data.forEach((item) => {
let setName = item.propertySetName;
if (!obj[setName]) {
obj[setName] = [];
}
obj[setName].push(item);
});
for (let key in obj) {
tmps.push({
name: key,
data: obj[key],
});
}
return tmps;
}
2025-06-19 18:34:49 +08:00
//清除选中构件样式
function clearSelectFeature(that) {
let api = bimBriefingApi;
if (that.selFeatureId) {
let modelId = that.selFeatureId.split("^")[0];
api.Feature.setColor(that.selFeatureId, "rgba(255,255,255,1)", modelId);
that.selFeatureId = "";
}
}
//查询构件属性信息
2025-06-19 17:11:30 +08:00
function dataFiltering(that, id) {
const gild = id.split("^");
let modelName = "";
that.models.forEach((item) => {
if (item.gis?.lightweightName == gild[0]) {
modelName = item.gis.name;
}
});
if (!modelName || !gild[1]) {
return false;
}
let featureId = gild[1].split("_")[0];
that.$api.bim.modelPropertyByExternalId(gild[0], featureId).then((d) => {
let tmps = d.data || [];
that.propertyAttr = groupData(tmps.filter((d) => d.propertyTypeName == "properties"));
that.propertyType = groupData(tmps.filter((d) => d.propertyTypeName != "properties"));
that.propertyLoad = "end";
});
}
/**
* 获取构件属性信息
*/
2025-06-19 18:34:49 +08:00
function getProperty(that) {
2025-06-19 17:11:30 +08:00
let api = bimBriefingApi;
api.Feature.getByEvent(true, (n) => {
console.log(n);
if (n && n["id"]) {
let featureId = n.id;
if (featureId.split("^")[1]) {
let modelId = featureId.split("^")[0];
2025-06-19 18:34:49 +08:00
clearSelectFeature(that);
2025-06-19 17:11:30 +08:00
api.Feature.setColor(featureId, "rgba(255,0,255,1)", modelId);
that.selFeatureId = featureId;
dataFiltering(that, featureId);
that.propertyLoad = "start";
that.attributeInformation = "查询中,请稍候~";
}
} else {
that.attributeInformation = "未选中构件";
}
});
}
2025-06-23 12:04:37 +08:00
function getModelUnit(that, modelId) {
let find = that.models.find((d) => d.modelId == modelId);
return find ? find.unit || 1.0 : 1.0;
}
2025-06-19 17:11:30 +08:00
/**
* 获取构件尺寸信息
*/
2025-06-19 18:34:49 +08:00
function subFeatureSize(that) {
2025-06-19 17:11:30 +08:00
let api = bimBriefingApi;
2025-06-23 12:04:37 +08:00
let result = [
{ name: "构建尺寸", data: [] },
{ name: "构建表面积", data: [] },
{ name: "构建体积", data: [] },
];
2025-06-19 18:34:49 +08:00
that.info = [];
api.Public.clearHandler();
api.Measurement.clearAllTrace();
2025-06-19 17:11:30 +08:00
api.Feature.getByEvent(true, (n) => {
if (n && n["id"]) {
let featureId = n.id;
2025-06-19 18:34:49 +08:00
let modelId = featureId.split("^")[0];
2025-06-23 12:04:37 +08:00
let unit = getModelUnit(that, modelId);
2025-06-19 18:34:49 +08:00
clearSelectFeature(that);
2025-06-19 17:11:30 +08:00
api.Feature.getGeometrySizeById(featureId, (res) => {
2025-06-19 18:34:49 +08:00
let size = res.size || {};
2025-06-23 12:04:37 +08:00
let x = (size.x || 0) * unit * 1.0;
let y = (size.y || 0) * unit * 1.0;
let z = (size.z || 0) * unit * 1.0;
result[0].data = [
{ name: "长", value: x.toFixed(2) + "" },
{ name: "宽", value: y.toFixed(2) + "" },
{ name: "高", value: z.toFixed(2) + "" },
2025-06-19 18:34:49 +08:00
];
2025-06-23 12:04:37 +08:00
result[1].data = [{ name: "面积", value: (x * y).toFixed(2) + "" }];
result[2].data = [{ name: "体积", value: (x * y * z).toFixed(2) }];
2025-06-19 18:34:49 +08:00
api.Feature.setColor(featureId, "rgba(255,0,255,1)", modelId);
that.selFeatureId = featureId;
2025-06-23 12:04:37 +08:00
that.info = result;
// api.Measurement.featureArea(featureId, (res) => {
// result[1].data = [{ name: "面积", value: ((+res || 0) * unit * unit * 1.0).toFixed(2) + "" }];
// api.Measurement.featureVolume(featureId, (res) => {
// result[2].data = [{ name: "体积", value: ((+res || 0) * unit * unit * unit * 1.0).toFixed(2) }];
// api.Feature.setColor(featureId, "rgba(255,0,255,1)", modelId);
// that.selFeatureId = featureId;
// that.info=result
// });
// });
2025-06-19 17:11:30 +08:00
});
}
});
}
2025-06-19 18:34:49 +08:00
//构件面积
2025-06-21 16:18:49 +08:00
function measurementArea(that) {
2025-06-23 12:04:37 +08:00
let api = bimBriefingApi;
2025-06-21 16:18:49 +08:00
that.info = [];
api.Public.clearHandler(), api.Measurement.clearAllTrace();
api.Feature.getByEvent(true, (n) => {
console.log(n);
if (n && n["id"]) {
let featureId = n.id;
let modelId = featureId.split("^")[0];
clearSelectFeature(that);
api.Measurement.featureArea(featureId, (res) => {
2025-06-23 12:04:37 +08:00
that.info = [{ name: "面积", value: (+res || 0).toFixed(2) + "" }];
2025-06-21 16:18:49 +08:00
api.Feature.setColor(featureId, "rgba(255,0,255,1)", modelId);
that.selFeatureId = featureId;
});
}
});
}
2025-06-19 18:34:49 +08:00
//构件体积
2025-06-23 12:04:37 +08:00
function measuringVolume(that) {}
2025-06-19 18:34:49 +08:00
//构件距离
function distance(that) {
let api = bimBriefingApi;
that.info = [];
api.Public.clearHandler();
api.Measurement.clearAllTrace();
//开始测量,左键选点
api.Measurement.distance(true, (data) => {
console.log(data);
});
//右键结束测量
api.Public.event("RIGHT_CLICK", (res) => {
api.Measurement.distance(false);
});
}
2025-06-19 18:34:49 +08:00
//剖切
2025-06-23 12:04:37 +08:00
function initClipping(that) {}
2025-06-19 18:34:49 +08:00
//构件隐藏
2025-06-23 12:04:37 +08:00
function actorVisible() {}
2025-06-19 18:34:49 +08:00
export default {
measurementArea,
clearSelectFeature,
getProperty,
subFeatureSize,
measuringVolume,
distance,
initClipping,
actorVisible,
};