myTwice.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. var isShowCard = false
  20. time = setInterval(() => {
  21. console.log('定时器执行,获取完所有dom,页面准备完毕');
  22. if (__sdk && __sdk.Camera && __sdk.Camera.getPose && __sdk.Camera.getPose() && __sdk.Camera.getPose().panoId) {
  23. clearInterval(time)
  24. // 整个的小人box
  25. const carListDomAll = document.querySelector('.carList')
  26. carListDomAll.style.display = 'block'
  27. renMoveFu()
  28. time2 = window.setInterval(() => {
  29. renMoveFu()
  30. time2Num++
  31. console.log('小人移位功能准备完毕,或者没有导览');
  32. if (time2Num >= 5) {
  33. clearInterval(time2)
  34. }
  35. }, 500);
  36. // 小人和列表的切换
  37. const carList1Dom = document.querySelector('.carList1')
  38. const carList2Dom = document.querySelector('.carList2')
  39. const carList1_2Dom = document.querySelector('.carList1_2')
  40. const carList2_2Dom = document.querySelector('.carList2_2')
  41. carList1_2Dom.onclick = () => {
  42. carList1Dom.style.display = 'none'
  43. carList2Dom.style.display = 'block'
  44. carList2_2Dom.scrollTop = 0
  45. carList2_2Dom.addEventListener('mouseover', () => {
  46. isShowCard = true
  47. })
  48. carList2_2Dom.addEventListener('mouseout', () => {
  49. isShowCard = false
  50. })
  51. }
  52. const carList2_2BackDom = document.querySelector('.carList2_2Back')
  53. carList2_2BackDom.onclick = () => {
  54. carList1Dom.style.display = 'flex'
  55. carList2Dom.style.display = 'none'
  56. }
  57. // 动态渲染列表
  58. let temp1 = ''
  59. myData.forEach(v1 => {
  60. let temp2 = ''
  61. v1.son.forEach(v2 => {
  62. temp2 += `<div class="c_boxTxt" id=${v2.panoId} _x=${v2.x} _y=${v2.y} _z=${v2.z} _w=${v2.w}>
  63. <p>
  64. ${v2.name}
  65. </p>
  66. </div>`
  67. })
  68. temp1 += `<div class="c_box"><div class="c_boxTit">${v1.name}</div>${temp2}</div>`
  69. })
  70. const carList2_2MainDom = document.querySelector('.carList2_2Main')
  71. carList2_2MainDom.innerHTML = temp1
  72. const c_boxTxtArr = document.querySelectorAll('.c_boxTxt')
  73. c_boxTxtArr.forEach(v => {
  74. v.onclick = () => {
  75. const id = v.attributes['id'].nodeValue
  76. const _x = v.attributes['_x'].nodeValue
  77. const _y = v.attributes['_y'].nodeValue
  78. const _z = v.attributes['_z'].nodeValue
  79. const _w = v.attributes['_w'].nodeValue
  80. const obj = {
  81. currentScale: 1,
  82. flying: false,
  83. mode: "panorama",
  84. modeTran: "panorama-panorama",
  85. panoId: id,
  86. quaternion: { isQuaternion: true, _x, _y, _z, _w }
  87. }
  88. // 移动到视角
  89. __sdk.Camera.setPose(obj)
  90. // 移动到点位
  91. __sdk.Camera.flyToPano(id)
  92. let timerId = setInterval(() => {
  93. console.log(isShowCard)
  94. if (!isShowCard) {
  95. // 隐藏展示卡
  96. const carList1Dom = document.querySelector('.carList1')
  97. const carList2Dom = document.querySelector('.carList2')
  98. carList1Dom.style.display = 'flex'
  99. carList2Dom.style.display = 'none'
  100. clearInterval(timerId)
  101. }
  102. }, 100)
  103. }
  104. })
  105. __sdk.Camera.on('flying.started', (pano) => {
  106. classAddFu(pano.panoId)
  107. })
  108. // 初始判断点位id,来高亮
  109. const baseId = __sdk.Camera.getPose().panoId
  110. classAddFu(baseId)
  111. }
  112. }, 500);
  113. // 添加和删除class的方法
  114. const classAddFu = (oldId) => {
  115. const c_boxTxtArr = document.querySelectorAll('.c_boxTxt')
  116. c_boxTxtArr.forEach(v => {
  117. const id = v.attributes['id'].nodeValue
  118. if (oldId == id) v.classList.add('c_boxTxtAc')
  119. else v.classList.remove('c_boxTxtAc')
  120. })
  121. }