index.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import React, { useEffect, useMemo, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { useParams } from 'react-router-dom'
  4. import { HotSpot, Krpano, Scene, View } from '@dage/krpano'
  5. import { baseURL, myData, otherUrl } from '@/utils/http'
  6. import HotIcon from '@/components/HotIcon'
  7. import Hot2 from '../A2visit/PanoVideo/Hot2'
  8. import history from '@/utils/history'
  9. import FloorHotspotIcon from '@/assets/img/icon-flo-1.png'
  10. import { ArrowLeftOutlined } from '@ant-design/icons'
  11. import FloorBtn from '@/components/FloorBtn'
  12. import { KrpanoMiddleware } from '@/components/KrpanoMiddleware'
  13. import CatVideo from '@/components/CatVideo'
  14. // import { myData } from '@/utils/http'
  15. window.draggbleHotspotEvent = (ath: number, atv: number) => {
  16. console.log(`ath: ${ath}, atv: ${atv}`)
  17. }
  18. function A3banPano() {
  19. // 路由:/banPano/id
  20. const urlObj: any = useParams()
  21. // 0为 第一种模式的热点 其他为第二种
  22. const [acName, setAcName] = useState('')
  23. const [activeIdx, setActiveIdx] = useState(-1)
  24. const [curScene, setCurScene] = useState('')
  25. useEffect(() => {
  26. const id = urlObj.id
  27. setCurScene(id === '2' ? 'pano3' : 'pano4')
  28. // 数据 过滤 2=2楼 3=庭院
  29. // myData.banquet.hot.filter(v=>v.louType===id)
  30. }, [urlObj.id])
  31. const info = useMemo(() => {
  32. let infoRes: any = {}
  33. if (acName) infoRes = myData.banquet.hot.find(v => v.name === acName)
  34. return infoRes
  35. }, [acName])
  36. // 点击观赏庭院 先播放视频
  37. const [videoPlay, setVideoPlay] = useState(false)
  38. return (
  39. <div className={styles.A3banPano}>
  40. <KrpanoMiddleware>
  41. <Krpano className={styles.pano} currentScene={curScene}>
  42. <Scene
  43. name='pano3'
  44. previewUrl={otherUrl + 'pano/pano3.tiles/thumb.jpg'}
  45. imageTagAttributes={{
  46. type: 'cube',
  47. tileSize: 512,
  48. multires: true
  49. }}
  50. images={[
  51. {
  52. tiledImageWidth: 1280,
  53. tiledImageHeight: 1280,
  54. url: otherUrl + 'pano/pano3.tiles/%s/l2/%v/l2_%s_%v_%h.jpg'
  55. },
  56. {
  57. tiledImageWidth: 640,
  58. tiledImageHeight: 640,
  59. url: otherUrl + 'pano/pano3.tiles/%s/l1/%v/l1_%s_%v_%h.jpg'
  60. }
  61. ]}
  62. >
  63. <View hlookat={180} vlookat={0} fovType='MFOV' fov={120} fovMin={70} fovMax={130} />
  64. {/* 自己在的数据里面添加 字段louType 区分热点位置 1=一楼 2=2楼 3=庭院(字符串) */}
  65. {myData.banquet.hot
  66. .filter(c => c.louType === '2')
  67. .map((item, index) => (
  68. // 热点图标
  69. <HotSpot
  70. key={index}
  71. type='text'
  72. name={item.name}
  73. atv={item.atv}
  74. ath={item.ath}
  75. edge='top'
  76. distorted={true}
  77. scale={1}
  78. bg={false}
  79. onOver={() => setActiveIdx(index)}
  80. onOut={() => setActiveIdx(-1)}
  81. onClick={() => setAcName(item.name)}
  82. // @ts-ignore
  83. // onDown='draggable_hotspot()'
  84. >
  85. <HotIcon
  86. isPano
  87. isModel={item.isModel ? true : false}
  88. key={index}
  89. index={index}
  90. isHoverAc={activeIdx === index}
  91. hoverSrc={item.hoverSrc}
  92. />
  93. </HotSpot>
  94. ))}
  95. <HotSpot
  96. name='firstFloor'
  97. type='text'
  98. atv={-11.32}
  99. ath={-18.68}
  100. edge='top'
  101. distorted={true}
  102. scale={0.6}
  103. bg={false}
  104. onClick={() => {
  105. history.push('/banquet?r=ren')
  106. }}
  107. // @ts-ignore
  108. // onDown='draggable_hotspot()'
  109. >
  110. <div className={styles.floorHotspot}>
  111. <img src={FloorHotspotIcon} className={styles.floorHotspotIcon} alt='' />
  112. <span>返回一楼</span>
  113. </div>
  114. </HotSpot>
  115. <HotSpot
  116. name='courtyard'
  117. type='text'
  118. atv={-12.8}
  119. ath={135.43}
  120. edge='top'
  121. distorted={true}
  122. scale={0.6}
  123. bg={false}
  124. onClick={() => {
  125. history.replace('/banPano/3')
  126. setVideoPlay(true)
  127. }}
  128. >
  129. <div className={styles.courtyardHotspot}>
  130. <ArrowLeftOutlined rev={undefined} />
  131. <p>观赏庭院</p>
  132. </div>
  133. </HotSpot>
  134. </Scene>
  135. <Scene
  136. name='pano4'
  137. previewUrl={otherUrl + 'pano/pano4.tiles/thumb.jpg'}
  138. imageTagAttributes={{
  139. type: 'cube',
  140. tileSize: 512,
  141. multires: true
  142. }}
  143. images={[
  144. {
  145. tiledImageWidth: 1280,
  146. tiledImageHeight: 1280,
  147. url: otherUrl + 'pano/pano4.tiles/%s/l2/%v/l2_%s_%v_%h.jpg'
  148. },
  149. {
  150. tiledImageWidth: 640,
  151. tiledImageHeight: 640,
  152. url: otherUrl + 'pano/pano4.tiles/%s/l1/%v/l1_%s_%v_%h.jpg'
  153. }
  154. ]}
  155. >
  156. <View hlookat={75} vlookat={10} fovType='MFOV' fov={120} fovMin={70} fovMax={130} />
  157. <HotSpot
  158. name='indoor'
  159. type='text'
  160. atv={1.58}
  161. ath={58.54}
  162. edge='top'
  163. distorted={true}
  164. scale={0.6}
  165. bg={false}
  166. onClick={() => {
  167. history.replace('/banPano/2')
  168. }}
  169. >
  170. <div className={styles.indoorHotspot}>
  171. <p>返回室内</p>
  172. </div>
  173. </HotSpot>
  174. </Scene>
  175. </Krpano>
  176. </KrpanoMiddleware>
  177. <CatVideo
  178. isShow={videoPlay}
  179. src={baseURL + 'visit2/观赏庭院.mp4'}
  180. noDel={true}
  181. parentFu={() => {
  182. setVideoPlay(false)
  183. }}
  184. />
  185. {/* 右下角按钮 */}
  186. {videoPlay ? null : <FloorBtn />}
  187. {acName && info && info.data ? (
  188. <Hot2 data={info.data} closeFu={() => setAcName('')} name={info.name} />
  189. ) : null}
  190. </div>
  191. )
  192. }
  193. const MemoA3banPano = React.memo(A3banPano)
  194. export default MemoA3banPano