myTwice.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. let time = -1
  2. let time2 = -1
  3. let time2Num = 0
  4. // 小人移位函数
  5. const renMoveFu = () => {
  6. // 底部左侧小人logo和上箭头的dom,拿到dom元素的时候在执行下面的代码
  7. const bottomClickDom = document.querySelector('.play-control')
  8. if (bottomClickDom) {
  9. // 展开导览列表和隐藏导览列表
  10. const isActiveDom = document.querySelector('.tour-btn .icon-pull-down')
  11. bottomClickDom.addEventListener('click', () => {
  12. const flag = isActiveDom.className.includes('active')
  13. const carListDomAll = document.querySelector('.carList')
  14. carListDomAll.style.bottom = flag ? '180px' : '100px'
  15. })
  16. clearInterval(time2)
  17. }
  18. }
  19. time = setInterval(() => {
  20. console.log('定时器执行,获取完所有dom,页面准备完毕');
  21. if (__sdk && __sdk.Camera && __sdk.Camera.getPose && __sdk.Camera.getPose() && __sdk.Camera.getPose().panoId) {
  22. clearInterval(time)
  23. // 整个的小人box
  24. const carListDomAll = document.querySelector('.carList')
  25. carListDomAll.style.display = 'block'
  26. renMoveFu()
  27. time2 = window.setInterval(() => {
  28. renMoveFu()
  29. time2Num++
  30. console.log('小人移位功能准备完毕,或者没有导览');
  31. if (time2Num >= 5) {
  32. clearInterval(time2)
  33. }
  34. }, 500);
  35. // 小人和列表的切换
  36. const carList1Dom = document.querySelector('.carList1')
  37. const carList2Dom = document.querySelector('.carList2')
  38. const carList1_2Dom = document.querySelector('.carList1_2')
  39. const carList2_2Dom = document.querySelector('.carList2_2')
  40. carList1_2Dom.onclick = () => {
  41. carList1Dom.style.display = 'none'
  42. carList2Dom.style.display = 'block'
  43. carList2_2Dom.scrollTop = 0
  44. }
  45. const carList2_2BackDom = document.querySelector('.carList2_2Back')
  46. carList2_2BackDom.onclick = () => {
  47. carList1Dom.style.display = 'flex'
  48. carList2Dom.style.display = 'none'
  49. }
  50. // 动态渲染列表
  51. let temp1 = ''
  52. myData.forEach(v1 => {
  53. let temp2 = ''
  54. v1.son.forEach(v2 => {
  55. temp2 += `<div class="c_boxTxt" id=${v2.panoId} _x=${v2.x} _y=${v2.y} _z=${v2.z} _w=${v2.w}>
  56. <p>
  57. ${v2.name}
  58. </p>
  59. </div>`
  60. })
  61. temp1 += `<div class="c_box"><div class="c_boxTit">${v1.name}</div>${temp2}</div>`
  62. })
  63. const carList2_2MainDom = document.querySelector('.carList2_2Main')
  64. carList2_2MainDom.innerHTML = temp1
  65. const c_boxTxtArr = document.querySelectorAll('.c_boxTxt')
  66. c_boxTxtArr.forEach(v => {
  67. v.onclick = () => {
  68. const id = v.attributes['id'].nodeValue
  69. const _x = v.attributes['_x'].nodeValue
  70. const _y = v.attributes['_y'].nodeValue
  71. const _z = v.attributes['_z'].nodeValue
  72. const _w = v.attributes['_w'].nodeValue
  73. const obj = {
  74. currentScale: 1,
  75. flying: false,
  76. mode: "panorama",
  77. modeTran: "panorama-panorama",
  78. panoId: id,
  79. quaternion: { isQuaternion: true, _x, _y, _z, _w }
  80. }
  81. // 移动到视角
  82. __sdk.Camera.setPose(obj)
  83. // 移动到点位
  84. __sdk.Camera.flyToPano(id)
  85. // 隐藏展示卡
  86. const carList1Dom = document.querySelector('.carList1')
  87. const carList2Dom = document.querySelector('.carList2')
  88. carList1Dom.style.display = 'flex'
  89. carList2Dom.style.display = 'none'
  90. }
  91. })
  92. __sdk.Camera.on('flying.started', (pano) => {
  93. classAddFu(pano.panoId)
  94. })
  95. // 初始判断点位id,来高亮
  96. const baseId = __sdk.Camera.getPose().panoId
  97. classAddFu(baseId)
  98. }
  99. }, 500);
  100. // 添加和删除class的方法
  101. const classAddFu = (oldId) => {
  102. const c_boxTxtArr = document.querySelectorAll('.c_boxTxt')
  103. c_boxTxtArr.forEach(v => {
  104. const id = v.attributes['id'].nodeValue
  105. if (oldId == id) v.classList.add('c_boxTxtAc')
  106. else v.classList.remove('c_boxTxtAc')
  107. })
  108. }