```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My first BIMFACE app</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
}
#domId {
height: 100%;
}
html,
body {
height: 100%;
}
.main {
display: flex;
flex-direction: column;
overflow: hidden;
height: 100%;
width: 100%;
}
.model {
flex: 1;
}
.buttons {
font-size: 0;
}
</style>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
</head>
<body>
<!-- 模态框1 -->
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">火警详情</h4>
</div>
<div class="modal-body">
<table class="table table-hover">
<tr>
<th>名称</th>
<th>信息</th>
</tr>
<tr>
<td>传感器Id</td>
<td>168</td>
</tr>
<tr>
<td>传感器名称</td>
<td>火灾消防</td>
</tr>
<tr>
<td>监测值</td>
<td>345</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<!-- 模态框2 -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">室内CO详情</h4>
</div>
<div class="modal-body">
<table class="table table-hover">
<tr>
<th>名称</th>
<th>信息</th>
</tr>
<tr>
<td>传感器Id</td>
<td>167</td>
</tr>
<tr>
<td>传感器名称</td>
<td>CO浓度检测</td>
</tr>
<tr>
<td>监测值</td>
<td>305</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<!-- 模态框3 -->
<div class="modal fade" id="myModal3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">室内CO2详情</h4>
</div>
<div class="modal-body">
<table class="table table-hover">
<tr>
<th>名称</th>
<th>信息</th>
</tr>
<tr>
<td>传感器Id</td>
<td>166</td>
</tr>
<tr>
<td>传感器名称</td>
<td>CO浓度检测</td>
</tr>
<tr>
<td>监测值</td>
<td>300</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class='main'>
<!-- 定义DOM元素,用于在该DOM元素中显示模型或图纸 -->
<div class='main' id="bimface">
<div class='buttons'>
<button type="button" class="btn btn-primary" id="btnOverrideComponentsColorByObjectId"
@click="overrideComponentsColorById()">给传感器着色</button>
<button class="btn btn-primary" id="btnBlink" @click="blink()">传感器闪烁</button>
<button type="button" class="btn btn-primary" id="btnHideComponentsByObjectId"
@click="hideComponentsById()">隐藏传感器</button>
</div>
<!-- 定义DOM元素,用于在该DOM元素中显示模型或图纸 -->
<div class='model' id="domId"></div>
</div>
<script src="https://static.bimface.com/api/BimfaceSDKLoader/BimfaceSDKLoader@latest-release.js"></script>
<script>
var vm = new Vue({
el:'#bimface',
data:{
viewer3D:'',
app:null,
cameraState:'{"name":"persp","position":{"x":-15290.504153609158,"y":-11705.98598911822,"z":6547.152792941356},"target":{"x":35869.08012166626,"y":23950.30963410126,"z":-9486.25721153848},"up":{"x":0,"y":-0.0000036732050934432307,"z":0.9999999999932538},"fov":45,"version":1}',
viewToken: '5d71e07f75bf44108b797fbc21f55a4c',
loaderConfig:new BimfaceSDKLoaderConfig(),
isOverrideComponentsColorByIdActivated:false,
isHideComponentsByIdActivated:false,
isBlinkComponentsActivated:false
},
created:function(){
const _this = this;
_this.loaderConfig.viewToken = _this.viewToken;
BimfaceSDKLoader.load(_this.loaderConfig, _this.successCallback,_this.failureCallback);
},
methods:{
successCallback:function(viewMetaData) {
const _this = this;
if (viewMetaData.viewType == "3DView") {
// ======== 判断是否为3D模型 ========
// 获取DOM元素
var dom4Show = document.getElementById('domId');
var webAppConfig = new Glodon.Bimface.Application.WebApplication3DConfig();
webAppConfig.domElement = dom4Show;
// 创建WebApplication
var app = new Glodon.Bimface.Application.WebApplication3D(webAppConfig);
// 添加待显示的模型
app.addView(viewMetaData.viewToken);
// 从WebApplication获取viewer3D对象
var viewer3D = app.getViewer();
_this.viewer3D = viewer3D;
// 监听添加view完成的事件
_this.viewer3D.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.ViewAdded, function () {
_this.setCameraStatus();
//自适应屏幕大小
window.onresize = function () {
_this.viewer3D.resize(document.documentElement.clientWidth, document.documentElement
.clientHeight);
}
});
// 添加view点击构件的监听事件
_this.viewer3D.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.MouseClicked, _this.getData);
}
},
failureCallback:function(error) {
console.log(error);
},
setCameraStatus:function() {
const _this = this;
_this.viewer3D.setCameraStatus(_this.cameraState);
},
//********************根据Id给构件着色*********************
overrideComponentsColorById:function() {
const _this = this;
var color = new Glodon.Web.Graphics.Color("#EE799F", 0.8);
if (!_this.isOverrideComponentsColorByIdActivated) {
// 根据Id修改构件颜色及透明度
_this.viewer3D.overrideComponentsColorById(["168", "162", "156", "166","160","154","167","161","155","169","163","157","170","164","171","165","159","158"], color);
// 根据Id修改构件透明度
// viewer3D.overrideComponentsOpacityById(["307240"], 0.8);
_this.viewer3D.render();
_this.setButtonText("btnOverrideComponentsColorByObjectId", "恢复颜色");
} else {
//恢复颜色
_this.viewer3D.restoreComponentsColorById(["307240", "168", "162", "156", "166","160","154","167","161","155","169","163","157","170","164","171","165","159","158"]);
_this.viewer3D.render();
_this.setButtonText("btnOverrideComponentsColorByObjectId", "给传感器着色");
}
_this.isOverrideComponentsColorByIdActivated = !_this.isOverrideComponentsColorByIdActivated;
},
// *********************** 按钮文字 ***********************
setButtonText:function(btnId, text) {
var dom = document.getElementById(btnId);
if (dom != null && dom.nodeName == "BUTTON") {
dom.innerText = text;
}
},
//********************根据Id隐藏构件*********************
hideComponentsById:function() {
const _this = this;
if (!_this.isHideComponentsByIdActivated) {
_this.viewer3D.hideComponentsById(["168", "162", "156", "166","160","154","167","161","155","169","163","157","170","164","171","165","159","158"]);
_this.viewer3D.render();
_this.setButtonText("btnHideComponentsByObjectId", "显示构件");
} else {
//取消隐藏
_this.viewer3D.showComponentsById(["168", "162", "156", "166","160","154","167","161","155","169","163","157","170","164","171","165","159","158"]);
_this.viewer3D.render();
_this.setButtonText("btnHideComponentsByObjectId", "隐藏构件");
}
_this.isHideComponentsByIdActivated = !_this.isHideComponentsByIdActivated;
},
// *************** 根据Id闪烁 ***************
blink:function(){
const _this = this;
if (!_this.isBlinkComponentsActivated) {
// 构件闪烁
_this.viewer3D.addBlinkComponentsById(["168", "162", "156", "166","160","154","167","161","155","169","163","157","170","164","171","165","159","158"]);
_this.viewer3D.setBlinkColor(new Glodon.Web.Graphics.Color("#32D3A6", 0.8));
_this.viewer3D.enableBlinkComponents(true);
_this.viewer3D.setBlinkIntervalTime(500);
_this.viewer3D.render();
_this.setButtonText("btnBlink", "关闭闪烁效果");
} else {
// 取消闪烁
_this.viewer3D.clearAllBlinkComponents();
_this.viewer3D.render();
_this.setButtonText("btnBlink", "传感器闪烁");
}
_this.isBlinkComponentsActivated = !_this.isBlinkComponentsActivated;
},
getData:function(data) {
const _this = this;
//获取构件属性
// var Data = JSON.stringify(data);
if(data.objectId=="168"){
$("#myModal1").modal({
backdrop: "static"
});
}
if(data.objectId=="162"){
$("#myModal2").modal({
backdrop: "static"
});
}
if(data.objectId=="156"){
$("#myModal3").modal({
backdrop: "static"
});
}
}
}
})
</script>
</body>
</html>
效果图