inspectRoute.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <meta name="renderer" content="webkit">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>自定义关键帧</title>
  8. <style media="screen">
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. }
  13. html,
  14. body {
  15. height: 100%;
  16. }
  17. .main {
  18. display: flex;
  19. flex-direction: column;
  20. overflow: hidden;
  21. height: 100%;
  22. width: 100%;
  23. }
  24. .model {
  25. flex: 1;
  26. }
  27. .buttons {
  28. font-size: 0;
  29. }
  30. .button {
  31. margin: 5px 0 5px 5px;
  32. width: 100px;
  33. height: 30px;
  34. background: #11DAB7;
  35. color: #FFFFFF;
  36. border-radius: 3px;
  37. border: none;
  38. cursor: pointer;
  39. }
  40. </style>
  41. <!-- 引用BIMFACE的JavaScript显示组件库 -->
  42. <script src="https://static.bimface.com/api/BimfaceSDKLoader/BimfaceSDKLoader@latest-release.js" charset="utf-8">
  43. </script>
  44. </head>
  45. <body>
  46. <div class='main'>
  47. <div class='buttons'>
  48. <button type="button" class="button" onclick="playkey(20)">开始巡检</button>
  49. <button type="button" class="button" onclick="pause()">暂停</button>
  50. </div>
  51. <!-- 定义DOM元素,用于在该DOM元素中显示模型或图纸 -->
  52. <div class='model' id="domId"></div>
  53. </div>
  54. <script type="text/javascript">
  55. var viewToken = '9e7c778c517f4dfc841dfd860bdfb032';
  56. var wt;
  57. var viewer;
  58. var color;
  59. // 初始化显示组件
  60. var options = new BimfaceSDKLoaderConfig();
  61. options.viewToken = viewToken;
  62. BimfaceSDKLoader.load(options, successCallback, failureCallback);
  63. function successCallback(viewMetaData) {
  64. if (viewMetaData.viewType == "3DView") {
  65. color = new Glodon.Web.Graphics.Color("#32D3A6", 0.8);
  66. // ======== 判断是否为3D模型 ========
  67. // 获取DOM元素
  68. var dom4Show = document.getElementById('domId');
  69. var webAppConfig = new Glodon.Bimface.Application.WebApplication3DConfig();
  70. webAppConfig.domElement = dom4Show;
  71. // 创建WebApplication
  72. var app = new Glodon.Bimface.Application.WebApplication3D(webAppConfig);
  73. // 添加待显示的模型
  74. app.addView(viewToken);
  75. // 从WebApplication获取viewer对象
  76. viewer = app.getViewer();
  77. //标签类的设置
  78. var drawableConfig = new Glodon.Bimface.Plugins.Drawable.DrawableContainerConfig();
  79. drawableConfig.viewer = viewer;
  80. //容器
  81. drawableContainer = new Glodon.Bimface.Plugins.Drawable.DrawableContainer(drawableConfig);
  82. var config = new Glodon.Bimface.Plugins.Walkthrough.WalkthroughConfig();
  83. config.viewer = viewer;
  84. wt = new Glodon.Bimface.Plugins.Walkthrough.Walkthrough(config);
  85. // 监听添加view完成的事件
  86. viewer.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.ViewAdded, function() {
  87. //自适应屏幕大小
  88. window.onresize = function() {
  89. viewer3D.resize(document.documentElement.clientWidth, document.documentElement
  90. .clientHeight - 40);
  91. }
  92. //add key frames
  93. var keyFrames = [];
  94. keyFrames.push({
  95. id: "21124876-8436-4a7e-8f3f-50f30876baeb",
  96. position:{
  97. "x":54338.30618321142,
  98. "y": 24823.562037428845,
  99. "z": 19009.247486006847
  100. },
  101. target:{
  102. "x": 138966.22492577098,
  103. "y": -343576.4725266925,
  104. "z": 47971.612488661136
  105. },
  106. "coordinateSystem":"world",
  107. });
  108. keyFrames.push({
  109. id: "86f4dd8e-8a43-4d4d-8aa5-cf5e3cdf16a1",
  110. position: {
  111. "x": 55392.23266330976,
  112. "y": 19177.558474637684,
  113. "z": 17950.4500522592
  114. },
  115. target:{
  116. "x": 237925.633560422,
  117. "y": -311824.03024018207,
  118. "z": 60086.961114641
  119. },
  120. "coordinateSystem":"world",
  121. });
  122. keyFrames.push({
  123. id: "d1d3d7bb-684a-4ce6-8b02-e41657ee83d5",
  124. position:{
  125. "x": 60458.92777828335,
  126. "y": 12369.261934180973,
  127. "z": 19647.874306033493
  128. },
  129. target:{
  130. "x": 206252.83091484627,
  131. "y": -336377.9684782245,
  132. "z": 59147.34131520492
  133. },
  134. "coordinateSystem":"world",
  135. });
  136. keyFrames.push({
  137. id: "69e3cae8-3b20-481d-9a42-2fe176ca56ea",
  138. position:{
  139. "x": 65011.509756267376,
  140. "y": -7770.007557460343,
  141. "z": 19279.4542151404
  142. },
  143. target:{
  144. "x": 378613.74215948314,
  145. "y": -218801.00165745476,
  146. "z": 50839.57258962678
  147. },
  148. "coordinateSystem":"world",
  149. });
  150. keyFrames.push({
  151. id: "5475b7eb-2589-483b-85f8-83d24543d6d8",
  152. position:{
  153. "x": 94393.5467001607,
  154. "y": -10041.437121392693,
  155. "z": 19279.445871713728
  156. },
  157. target:{
  158. "x": 428914.31778981985,
  159. "y": -186042.26938381407,
  160. "z": 56045.09022472101
  161. },
  162. "coordinateSystem":"world",
  163. });
  164. wt.setKeyFrames(keyFrames);
  165. });
  166. }
  167. }
  168. function failureCallback(error) {
  169. console.log(error);
  170. };
  171. //播放
  172. function playkey(time) {
  173. //wt.play(time);
  174. //播放到关键帧的时候促发回调事件
  175. wt.setKeyFrameCallback(keyFrameCallback);
  176. wt.setWalkthroughTime(time);
  177. wt.play();
  178. }
  179. //回调事件
  180. function keyFrameCallback(idx) {
  181. console.log("Current key frame index is " + idx);
  182. switch (idx) {
  183. case 0:
  184. action_0();
  185. break;
  186. case 1:
  187. action_1();
  188. break;
  189. case 2:
  190. action_2();
  191. break;
  192. case 3:
  193. action_3();
  194. break;
  195. case 4:
  196. action_4();
  197. break;
  198. default:
  199. break;
  200. }
  201. }
  202. //关键帧0的回调事件
  203. function action_0() {
  204. console.log("Action 1");
  205. var position1 = new Object();
  206. position1 = {
  207. "x": 59026.898499509276,
  208. "y": 16027.630284457171,
  209. "z": 18568.508610052737
  210. };
  211. addcustomitem(position1)
  212. viewer.enableBlinkComponents(true);
  213. viewer.setBlinkColor(color);
  214. var objectIds = ["1477311584420352.3805100"];
  215. viewer.setBlinkComponentsById(objectIds);
  216. }
  217. //关键帧1的回调事件
  218. function action_1() {
  219. console.log("Action 2");
  220. var position2 = new Object();
  221. position2 = {
  222. "x": 61277.39289979506,
  223. "y": 8167.548450051833,
  224. "z": 19070.83564545811
  225. };
  226. addcustomitem(position2);
  227. var objectIds = ["1477311584420352.3855400"];
  228. viewer.enableBlinkComponents(true);
  229. viewer.overrideComponentsColorById(objectIds, color);
  230. viewer.enableBlinkComponents(false);
  231. }
  232. //关键帧2的回调事件
  233. function action_2() {
  234. console.log("Action 3");
  235. var position2 = new Object();
  236. position2 = {
  237. "x": 70852.81623884341,
  238. "y": -4461.765783049294,
  239. "z": 17585.47922510225
  240. };
  241. addcustomitem(position2);
  242. var objectIds = ["1477311240716800.2366702"];
  243. viewer.enableBlinkComponents(true);
  244. viewer.overrideComponentsColorById(objectIds, color);
  245. viewer.enableBlinkComponents(false);
  246. }
  247. //关键帧3的回调事件
  248. function action_3() {
  249. console.log("Action 4");
  250. var position3 = new Object();
  251. position3 = {
  252. "x": 73670.83334490952,
  253. "y": -9370.809278067574,
  254. "z": 20825.000144211066
  255. };
  256. addcustomitem(position3);
  257. var objectIds = ["1477311584420352.3686915", "1477311584420352.4245712", "1477311584420352.3686916"];
  258. viewer.enableBlinkComponents(true);
  259. viewer.overrideComponentsColorById(objectIds, color);
  260. viewer.enableBlinkComponents(false);
  261. }
  262. //关键帧4的回调事件
  263. function action_4() {
  264. console.log("Action 5");
  265. var position4 = new Object();
  266. position4 = {
  267. "x": 102627.00303460653,
  268. "y": -15454.954320614783,
  269. "z": 18565.96119331755
  270. };
  271. addcustomitem(position4);
  272. var objectIds = ["1477311584420352.3821577"];
  273. viewer.enableBlinkComponents(true);
  274. viewer.overrideComponentsColorById(objectIds, color);
  275. viewer.enableBlinkComponents(false);
  276. }
  277. //自定义二维标签
  278. function addcustomitem(position) {
  279. var config = new Glodon.Bimface.Plugins.Drawable.CustomItemConfig();
  280. var circle = document.createElement('div');
  281. //自定义样式,支持Html的任意dom元素
  282. circle.style.width = '220px';
  283. circle.style.height = '32px';
  284. circle.style.borderRadius = '20%';
  285. circle.style.background = '#fff';
  286. var problemname = '例行安全巡检,未发现隐患';
  287. circle.innerHTML = '<p style="padding:6px 12px">' + problemname +'</p>';
  288. config.content = circle;
  289. config.viewer = viewer;
  290. config.worldPosition = position;
  291. //生成customItem实例
  292. var customItem = new Glodon.Bimface.Plugins.Drawable.CustomItem(config);
  293. // 添加自定义标签
  294. drawableContainer.addItem(customItem);
  295. //设置Tip的样式
  296. customItem.setTooltipStyle({
  297. border: '1px'
  298. });
  299. }
  300. function pause() {
  301. wt.pause();
  302. }
  303. </script>
  304. </body>
  305. </html>