在index.html中加入代码
<script src="//static.bimface.com/api/BimfaceSDKLoader/BimfaceSDKLoader@latest-release.js" charset="utf-8"></script>
初始化
show1() {
var BimfaceLoaderConfig = new BimfaceSDKLoaderConfig();
BimfaceLoaderConfig.viewToken = this.view_token;
BimfaceSDKLoader.load(
BimfaceLoaderConfig,
this.successCallback,
this.failureCallback
);
},
成功回调
successCallback(viewMetaData) {
let that = this
that.domShow = document.getElementById("bimface");
//创建WebApplication3DConfig
that.webAppConfig = new Glodon.Bimface.Application.WebApplicationDrawingConfig();
//设置创建WebApplication3DConfig的dom元素值
that.webAppConfig.domElement = that.domShow;
that.webAppConfig.Toolbars = ['MainToolbar'];
//创建WebApplication3D
that.app = new Glodon.Bimface.Application.WebApplicationDrawing(that.webAppConfig);
// //添加待显示的模型
// this.app.addView(this.token);
//获取viewer2D对象
that.viewer2D = that.app.getViewer();
// 加载图纸
that.viewer2D.loadDrawing({
viewToken: that.view_token
});
that.viewer2D.addEventListener(Glodon.Bimface.Viewer.ViewerDrawingEvent.MouseClicked, function (objectdata) {
// 调用viewerDrawing对象的Method,可以继续扩展功能
console.log("objectId : " + JSON.stringify(objectdata.objectId) + "\n" + "worldPosition : " + JSON.stringify(objectdata.worldPosition));
that.infoVisible = false
});
//获取缩放级别
that.viewer2D.addEventListener(Glodon.Bimface.Viewer.ViewerDrawingEvent.ZoomFactorChanged, function (objectdata) {
// console.log(objectdata)
});
that.viewer2D.addEventListener(Glodon.Bimface.Viewer.ViewerDrawingEvent.Loaded, function (data) {
// 创建标签容器配置
let drawableContainerConfig = new Glodon.Bimface.Plugins.Drawable.DrawableContainerConfig();
// 设置容器配置匹配的对象
drawableContainerConfig.viewer = that.viewer2D;
// 创建标签容器
that.cunstomItemContainer = new Glodon.Bimface.Plugins.Drawable.DrawableContainer(drawableContainerConfig);
that.addPoint(); //在cad加载完毕之后,创建图片
//左下角到右上角
//margin可自定义,margin值越大则边缘留白范围越大
that.viewer2D.zoomToBoundingBox([[518452.5516821312, 4374772.383192343], [532475.6239589079, 4384617.828124176]], 0);
that.viewer2D.setDisplayMode(1)
that.viewer2D.render();
});
},
注意!!挂载的dom一定要有高度 height:800px 不能写100%!!!!