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

401 lines
9.6 KiB
JavaScript

const options = {
taskMapping: {
progress: "percent",
},
maxRows: 10,
title: {
label: "任务列表",
html: false,
},
row: {
height: 24,
},
times: {
timeZoom: 20,
},
calendar: {
workingDays: [1, 2, 3, 4, 5, 6],
gap: 0,
strokeWidth: 5,
hour: {
display: !1,
},
},
chart: {
progress: {
bar: false,
},
expander: {
display: true,
},
},
taskList: {
expander: {
straight: false,
},
columns: [
{
id: 1,
label: "ID",
value: "id",
width: 40,
},
{
id: 2,
label: "任务名称",
value: "label",
width: 200,
expander: true,
html: true,
},
{
id: 3,
label: "任务工期",
value: "days",
width: 120,
},
{
id: 4,
label: "开始时间",
value: "start",
width: 120,
},
{
id: 5,
label: "结束时间",
value: "end",
width: 120,
},
],
},
locale: {
name: "en",
Now: "当前时间",
"X-Scale": "缩放宽度",
"Y-Scale": "缩放高度",
"Task list width": "列头宽度",
"Before/After": "时间跨度",
"Display task list": "显示列头",
weekdays: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
},
};
const ganttStyle = {
"main-view": {
background: "#06445b81",
"border-top": "1px solid var(--plan-color)",
},
"main-container-wrapper": {
overflow: "hidden",
"border-top": "1px solid var(--plan-color);",
"border-bottom": "1px solid var(--plan-color);",
},
"calendar-row-rect-child": {
"border-right-color": "var(--plan-color)",
},
"task-list": { "border-color": "var(--plan-color)" },
"task-list-header": {
"border-bottom": "1px solid var(--plan-color)",
"border-left": "1px solid var(--plan-color)",
},
"task-list-item": {
"border-top": "1px solid var(--plan-color)",
"border-right": "1px solid var(--plan-color)",
},
"task-list-item-column": {
"border-left": "1px solid var(--plan-color)",
"border-color": "var(--plan-color)",
},
"grid-line-time": {
stroke: "#FF000080",
"stroke-width": 5,
},
"chart-calendar-container": {
"border-right": "1px solid var(--plan-color)",
},
"chart-graph-container": {
"border-right": "1px solid var(--plan-color)",
},
"task-list-header-column": {
"border-left": "1px solid var(--plan-color)",
"box-sizing": "border-box",
display: "flex",
background: "#f3f5f7",
"border-color": "transparent",
},
calendar: {
background: "transparent",
},
"chart-row-text": {
background: "transparent",
"border-radius": "0px",
color: "#fff",
},
"task-list-expander-border": {
fill: "#00f1ff",
stroke: "#003357",
},
"chart-expander-border": {
fill: "#00f1ff",
stroke: "#000000A0",
},
};
function initEngine(that) {
console.log("开始初始化引擎");
window.bim4DApi = new SAPI(
{
serverIP: window.config.serverIP, //服务ip地址
port: window.config.port, //HTTP端口
useHttps: window.config.useHttps, //使用Https
container: "bim4DContainer", //[必须]容器id
secretKey: window.config.secretKey,
openEarth: window.config.openEarth, //[可选]开启Gis场景
bgColor: window.config.bgColor, //[可选]bim场景背景色, 传值即为纯色天空盒
tintColor: window.config.tintColor, //[可选]osgb单体化颜色
sceneTime: window.config.sceneTime, //[可选]分别为当前时间、日出时间、日落时间
cadMode: window.config.cadMode, // 是否是Cad图纸预览模式
},
() => {
that.initSuccess = true;
console.log("初始化成功");
setTimeout(() => {
initLoadModel(that);
}, 10);
let mapOptions = {
imgs: {
// 六面图片
top: "/cdn/bim/sapi/img/top.png",
bottom: "/cdn/bim/sapi/img/under.png",
east: "/cdn/bim/sapi/img/east.png",
south: "/cdn/bim/sapi/img/south.png",
west: "/cdn/bim/sapi/img/west.png",
north: "/cdn/bim/sapi/img/north.png",
},
offset: {
// 屏幕坐标偏移
corner: GLENavigationCube.RightTop,
x: 25,
y: 20,
},
cube: {
hoverColor: "#7193dc", // 立方导航快鼠标移过显示颜色
size: 32, // 导航立方尺寸
hotPointSize: 7, // 导航立方棱角热点区域尺寸
cubeTextColor: "#4c4c4ccc", // cube 各个面文字颜色
cubeStrokeColor: "#374769cc", // cube 各个面边框颜色
cubeFillColor: "#374769cc", // cube 各个面填充颜色
},
zoomRatios: 1, // 缩放倍率
show: true, // 是否显示
showAxes: true, // 是否显示XYZ轴线
};
bim4DApi.Plugin.initNavCube(mapOptions);
}
);
}
function initLoadModel(that) {
that.$api.bim
.listBimModel({
pageNum: 1,
pageSize: 100,
comId: that.selProject.comId,
projectId: that.selProject.id,
})
.then((d) => {
that.models = (d.rows || []).map((it) => {
it.modelId = it.lightweightName;
it.visible = false;
it.checked = true;
it.gis = that.$tryToJson(it.gisJson || "{}", {});
return it;
});
if (that.models.length == 0) {
that.$modal.error("暂无模型,请先关联模型");
} else {
that.models.forEach((item) => {
item.modelId = item.lightweightName;
item.gis = JSON.parse(item.gisJson);
addModel(that, item.lightweightName);
});
}
});
}
function addModel(that, modelId, cb) {
let api = window.bim4DApi;
let url = `${window.config.modelUrl}/Tools/output/model/${modelId}/root.glt`;
console.log(modelId, url);
api.Model.add(
url,
modelId,
() => {},
() => {
cb && cb();
console.log("加载模型成功");
setTimeout(() => {
bim4DApi.Camera.getViewPort((p) => {
that.viewPoint = p;
that.modelLoaded = true;
});
that.initPlay();
}, 1000);
}
);
}
const maxLen = 500;
function showBim(that, index) {
let api = bim4DApi;
if (index <= 0) {
index = getCurrentTaskIndex(that);
}
let showFeatureIds = [];
let currFeatureIds = [];
for (let i = 0; i <= that.taskList.length; i++) {
if (i <= index) {
that.taskList[i].gis.forEach((item) => {
let featureId = item.featureId;
if (!showFeatureIds.includes(featureId)) {
showFeatureIds.push(featureId);
}
});
}
}
if (showFeatureIds.length > 0) {
setFeatueVisible(showFeatureIds, true);
}
setTimeout(() => {
that.lastFeatureIds.forEach((it) => {
api.Feature.setColor(it, "rgba(255,255,255,1)");
});
currFeatureIds = that.taskList[index].gis.map((item) => item.featureId);
if (currFeatureIds.length > 0) {
currFeatureIds.forEach((it) => {
api.Feature.setColor(it, "rgba(255,0,255,1)");
});
}
that.lastFeatureIds = currFeatureIds;
}, 0);
}
function setFeatueVisible(featureIds, show) {
let len = maxLen;
let api = bim4DApi;
let cnt = featureIds.length;
if (cnt == 0) {
return;
}
for (let i = 0; i < cnt; i += len) {
api.Feature.setVisible(featureIds.slice(i, i + len).join("#"), show);
}
}
function getCurrentTaskIndex(that) {
let index = 0;
let taskList = that.taskList;
for (let i = 0; i < taskList.length; i++) {
let task = taskList[i];
if (task.children.length == 0 && that.$dt(task.start) - new Date() >= 0) {
index = i;
break;
}
}
return index;
}
function resetScene(that) {
let api = bim4DApi;
api.Camera.stopImmersiveRoam();
api.Model.location(api.m_model.keys().toArray()[0]);
api.Plugin.deleteMiniMap();
if (that.viewPoint) {
api.Camera.setViewPort(that.viewPoint);
}
}
function original() {
let api = bim4DApi;
for (let modelId in api.m_model) {
api.Model.original(modelId);
}
}
function getFirstFeatureId(that) {
for (let i = 0; i < that.taskList.length; i++) {
let task = that.taskList[i];
if (task.gis.length > 0) {
return task.gis[0].featureId;
}
}
return "";
}
function preparePlay(that) {
let featureId = getFirstFeatureId(that);
if (!featureId) {
return;
}
let api = bim4DApi;
api.Feature.showFeatures(featureId);
api.Feature.setColor(featureId, "rgba(255,255,255,0)");
}
function playStop(that) {
let api = bim4DApi;
that.lastFeatureIds.forEach((it) => {
api.Feature.setColor(it, "rgba(255,255,255,1)");
});
}
function doPLay(that) {
that.playTimer = setInterval(() => {
that.playValue++;
if (that.playValue >= that.taskList.length) {
playStop(that);
that.doStop();
} else {
that.doPlayPan(that.playValue);
}
}, that.playTime);
}
function modelRotate(that) {
let api = bim4DApi;
if(that.isPlay!=0){
return;
}
if (that.models.length > 0) {
api.Model.getCenter(that.models[0].modelId, (data) => {
data.xx = 0.5;
api.Camera.autoRotate({
Speed: 0.5,
Position: data.position,
});
});
}
}
function modelClearRotate() {
let api = window.bim4DApi;
if (api) {
api.Camera.stopAutoRotate();
}
}
export default {
options,
ganttStyle,
initEngine,
initLoadModel,
showBim,
resetScene,
original,
getFirstFeatureId,
preparePlay,
playStop,
getCurrentTaskIndex,
doPLay,
modelRotate,
modelClearRotate,
};