scene3.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. import '../scss/index.scss'
  2. import '../scss/page/scene1.scss'
  3. import PhotoSphereViewer from 'photo-sphere-viewer'
  4. import util from './until'
  5. // import Pic from '../img/P3.jpg'
  6. import location from '../img/location.png';
  7. import glass from '../img/glass.png'; //望远镜
  8. import eUrl from '../img/E.png';
  9. var viewer = null
  10. var huntFlag = false
  11. var indexPath = $('body').attr('data-path')
  12. // 进度相关
  13. var progressNum = 0
  14. var allStep = 5
  15. var progressFlag = {
  16. 'bear': false,
  17. 'lynx': false,
  18. 'road': false,
  19. 'lookout': false,
  20. 'fox': false
  21. }
  22. var mp4UrlMap = {
  23. }
  24. var huntV = {
  25. init() {
  26. this.initSnowView()
  27. this.handleReady()
  28. this.getVideoSource()
  29. this.handleNav()
  30. },
  31. initSnowView() {
  32. viewer = new PhotoSphereViewer({
  33. container: 'photosphere',
  34. panorama: 'http://hdzt.duowan.com/s/1806hunter/P3.jpg',
  35. // panorama: Pic,
  36. min_fov: 50,
  37. max_fov: 70,
  38. navbar: false,
  39. time_anim: false,
  40. markers: [
  41. // 野牛
  42. {
  43. id: 'beer-polygon',
  44. polygon_px: [
  45. [4115, 1487], [4115, 1696], [4410, 1696],[4410, 1487]
  46. ],
  47. svgStyle: {
  48. fill: 'rgba(255, 255, 255, 0)'
  49. }
  50. },
  51. {
  52. id: 'location-beer',
  53. x: 4247,
  54. y: 1514,
  55. image: location,
  56. width: 35,
  57. height: 35,
  58. anchor: 'bottom center',
  59. },
  60. // 野猪
  61. {
  62. id: 'lynx-polygon',
  63. polygon_px: [
  64. [2160, 1696], [2160, 1834], [2324, 1834],[2324, 1696]
  65. ],
  66. svgStyle: {
  67. fill: 'rgba(255, 255, 255, 0)'
  68. }
  69. },
  70. {
  71. id: 'location-lynx',
  72. x: 2225,
  73. y: 1726,
  74. image: location,
  75. width: 35,
  76. height: 35,
  77. anchor: 'bottom center',
  78. },
  79. // 狐狸
  80. {
  81. id: 'fox-polygon',
  82. polygon_px: [
  83. [5394, 1470], [5394, 1706], [5614, 1706],[5614, 1470]
  84. ],
  85. svgStyle: {
  86. fill: 'rgba(255, 255, 255, 0)'
  87. }
  88. },
  89. {
  90. id: 'location-fox',
  91. x: 5546,
  92. y: 1514,
  93. image: location,
  94. width: 35,
  95. height: 35,
  96. anchor: 'bottom center',
  97. },
  98. // 望远镜
  99. {
  100. id: 'glass',
  101. x: 310,
  102. y: 1000,
  103. image: glass,
  104. width: 56,
  105. height: 59,
  106. anchor: 'bottom center',
  107. },
  108. // 铁路
  109. {
  110. id: 'location-road',
  111. x: 3506,
  112. y: 1772,
  113. image: location,
  114. width: 35,
  115. height: 35,
  116. anchor: 'bottom center',
  117. },
  118. ]
  119. })
  120. },
  121. handleReady() {
  122. viewer.on('ready', function() {
  123. $('.loading-bg').hide()
  124. viewer.rotate({
  125. x: 0,
  126. y: 0
  127. });
  128. viewer.animate({
  129. x: 4194,
  130. y: 1562
  131. },2000);
  132. });
  133. viewer.on('position-updated', function(position) {
  134. let lgt = position.longitude
  135. let lat = position.latitude
  136. if(lgt < 1.07 && lat < 0.008 && !huntFlag) {
  137. huntFlag = true
  138. $('#hunter-suggest-modal').fadeIn()
  139. $('.nav').fadeIn()
  140. }
  141. })
  142. },
  143. getVideoSource() {
  144. let vids = ['8893041','8892081','8893039','8892073','8892091','8890691','8890693','8890695','8898389','8897805','8897807','8897809']
  145. var videoEls = {
  146. '8892073': 'lookup',
  147. '8892091': 'hunt',
  148. '8893041': 'aim',
  149. '8892081': 'shoot',
  150. '8893039': 'open',
  151. '8890691': 'book-lake',
  152. '8890693': 'book-taiga',
  153. '8890695': 'book-elden',
  154. '8898389': 'picVideo',
  155. '8897805': 'openB',
  156. '8897807': 'aimB',
  157. '8897809': 'shootB'
  158. }
  159. $.ajax({
  160. type: "GET",
  161. dataType: "json",
  162. url: `//video.duowan.com/jsapi/playPageVideoInfo/?vids=${vids.join(',')}`,
  163. success: function(data) {
  164. for(var i in data) {
  165. let resouce = util.deCodeArg(data[i].c).all,
  166. source = resouce.yuanhua || resouce[1300] || resouce[1000] || resouce[350]
  167. let name = videoEls[i]
  168. mp4UrlMap[name] = source.src
  169. }
  170. document.getElementById('open-video').src = mp4UrlMap['open']
  171. document.getElementById('aim-video').src = mp4UrlMap['aim']
  172. document.getElementById('shoot-video').src = mp4UrlMap['shoot']
  173. document.getElementById('open-video-b').src = mp4UrlMap['openB']
  174. document.getElementById('aim-video-b').src = mp4UrlMap['aimB']
  175. document.getElementById('shoot-video-b').src = mp4UrlMap['shootB']
  176. document.getElementById('book-lake-video').src = mp4UrlMap['book-lake']
  177. document.getElementById('book-taiga-video').src = mp4UrlMap['book-taiga']
  178. document.getElementById('book-elden-video').src = mp4UrlMap['book-elden']
  179. huntC.lookoutClick()
  180. huntC.playVideo()
  181. }
  182. })
  183. },
  184. // 导航权限处理
  185. handleNav() {
  186. // 初始化加载时
  187. let permision = localStorage.getItem('hunter_permision')
  188. if(permision < 3) {
  189. window.location.href = indexPath
  190. }
  191. if(permision == 4) {
  192. progressFlag = {
  193. 'bear': true,
  194. 'lynx': true,
  195. 'road': true,
  196. 'lookout': true,
  197. 'fox': true
  198. }
  199. $('#cur-progress').html(5)
  200. }
  201. }
  202. }
  203. var huntC = {
  204. init() {
  205. this.modalShow()
  206. util.bookClick()
  207. util.toolbarClick()
  208. util.shooting()
  209. },
  210. modalShow() {
  211. // 点击显示介绍弹窗
  212. $('.nav').find('.current').click(function() {
  213. $('#hunter-suggest-modal').fadeIn()
  214. })
  215. // 黑熊
  216. function beerModal() {
  217. if($('#hunter-beer-modal').css('display') == 'none') {
  218. $('.pub-modal').hide()
  219. $('#hunter-beer-modal').fadeIn()
  220. viewer.animate({
  221. x: 4194,
  222. y: 1562
  223. },600);
  224. }
  225. if(!progressFlag['bear']){
  226. progressFlag['bear'] = true
  227. $('#cur-progress').html(++progressNum)
  228. progressNum == allStep ? localStorage.setItem('hunter_permision', '4') : ''
  229. progressNum == allStep ? $('.complete-modal').fadeIn() : ''
  230. }
  231. }
  232. $(document).on('click', '#psv-marker-beer-polygon', function() {
  233. beerModal()
  234. })
  235. $(document).on('click', '#psv-marker-location-beer', function() {
  236. beerModal()
  237. })
  238. // lynx
  239. function lynxModal() {
  240. if($('#hunter-lynx-modal').css('display') == 'none') {
  241. $('.pub-modal').hide()
  242. $('#hunter-lynx-modal').fadeIn()
  243. viewer.animate({
  244. x: 2231,
  245. y: 1756
  246. },600);
  247. }
  248. if(!progressFlag['lynx']){
  249. progressFlag['lynx'] = true
  250. $('#cur-progress').html(++progressNum)
  251. progressNum == allStep ? localStorage.setItem('hunter_permision', '4') : ''
  252. progressNum == allStep ? $('.complete-modal').fadeIn() : ''
  253. }
  254. }
  255. $(document).on('click', '#psv-marker-lynx-polygon', function() {
  256. lynxModal()
  257. })
  258. $(document).on('click', '#psv-marker-location-lynx', function() {
  259. lynxModal()
  260. })
  261. // fox
  262. function foxModal() {
  263. if($('#hunter-fox-modal').css('display') == 'none') {
  264. $('.pub-modal').hide()
  265. $('#hunter-fox-modal').fadeIn()
  266. viewer.animate({
  267. x: 5514,
  268. y: 1598
  269. },600);
  270. }
  271. if(!progressFlag['fox']){
  272. progressFlag['fox'] = true
  273. $('#cur-progress').html(++progressNum)
  274. progressNum == allStep ? localStorage.setItem('hunter_permision', '4') : ''
  275. progressNum == allStep ? $('.complete-modal').fadeIn() : ''
  276. }
  277. }
  278. $(document).on('click', '#psv-marker-fox-polygon', function() {
  279. foxModal()
  280. })
  281. $(document).on('click', '#psv-marker-location-fox', function() {
  282. foxModal()
  283. })
  284. $(document).on('click', '#psv-marker-location-road', function() {
  285. if(!$('#p3-road-pic')[0]){
  286. var roadHtml = ` <div class="mod-full-picture" id="p3-road-pic" style="display:none">
  287. <div class="pub-btn go-back">返回</div>
  288. <div class="full-pic-modal small-modal">
  289. <div class="top-bar">
  290. 北欧森林
  291. </div>
  292. <div class="container clearfix">
  293. <p>虽然北欧人最喜欢到地中海度假,享受这里的阳光和沙滩。不过南欧的地中海人也是很羡慕北欧的人口稀少,森林密布的环境,那些难忘的原始森林,河流,湖泊,小动物等等。</p>
  294. <p>米兰·昆德拉说,生活在别处。倘若有一处,萃集了生活的美好,又何必另觅他乡? 冰岛的极光,瑞典的冰雪,目眩神驰的北欧风光里,最让人向往的还是森林里一口深呼吸带来的焕然一新。在这个世界上,还有什么比生命的健康活力更重。</p>
  295. <div class="eyes-btn"></div>
  296. </div>
  297. </div>
  298. <div class="fullscreen-video fullscreen-video-picture" style="display: none">
  299. <video id="picture-video" preload="metadata" width="100%">
  300. <source src="${mp4UrlMap['picVideo']}">
  301. </video>
  302. <div class="close-icon close-full-video"></div>
  303. </div>
  304. </div>`
  305. $('body').append(roadHtml)
  306. util.bgMove($('.mod-full-picture'))
  307. }
  308. $('#p3-road-pic').fadeIn()
  309. if(!progressFlag['road']){
  310. progressFlag['road'] = true
  311. $('#cur-progress').html(++progressNum)
  312. progressNum == allStep ? localStorage.setItem('hunter_permision', '4') : ''
  313. }
  314. })
  315. $(document).on('click', '.eyes-btn', function() {
  316. $('.fullscreen-video-picture').show()
  317. var video = document.getElementById('picture-video')
  318. video.play()
  319. video.addEventListener("ended",function(){
  320. video.load()
  321. $('.fullscreen-video-picture').hide()
  322. })
  323. })
  324. // 完成任务提示弹窗
  325. $(document).on('click', '.go-back', function() {
  326. progressNum == allStep ? $('.complete-modal').fadeIn() : ''
  327. })
  328. $('.complete-success-btn').click(function() {
  329. $('.complete-modal').remove()
  330. $('.book-icon').trigger('click')
  331. })
  332. },
  333. playVideo() {
  334. $('#hunter-video-play').click(function() {
  335. if(!$('#hunter-video-suggest')[0]){
  336. var hunterVideoHtml = `<div class="video-wrapper pub-modal-mask" id="hunter-video-suggest">
  337. <div class="part-screen">
  338. <video controls autoplay id="hunter-video">
  339. <source src="${mp4UrlMap['hunt']}">
  340. </video>
  341. <div class="close-icon close-mask-icon"></div>
  342. </div>
  343. </div>`
  344. $('body').append(hunterVideoHtml)
  345. } else {
  346. $('#hunter-video-suggest').show()
  347. document.getElementById('hunter-video').play()
  348. }
  349. })
  350. },
  351. // 瞭望台
  352. lookoutClick() {
  353. var videoHtml = `<div class="fullscreen-video fullscreen-video-lookout">
  354. <video id="lookout-video" autoplay width="100%">
  355. <source src="${mp4UrlMap['lookup']}">
  356. </video>
  357. <div class="close-icon close-full-video"></div>
  358. </div>`
  359. $(document).on('click', '#psv-marker-glass', function() {
  360. if(!$('#lookout-hunt-pic')[0]){
  361. var lookOutHtml = ` <div class="mod-full-picture" id="lookout-hunt-pic" style="display:none">
  362. <div class="pub-btn go-back">返回</div>
  363. <img class="e-tips" src="${eUrl}" alt="">
  364. </div>`
  365. $('body').append(lookOutHtml)
  366. }
  367. $('#lookout-hunt-pic').fadeIn()
  368. if(!progressFlag['lookout']){
  369. progressFlag['lookout'] = true
  370. $('#cur-progress').html(++progressNum)
  371. progressNum == allStep ? localStorage.setItem('hunter_permision', '4') : ''
  372. }
  373. })
  374. // 监听E键
  375. $(document).on('keyup', function(e) {
  376. var lookVideo = document.getElementById('lookout-video')
  377. var isShow = $('#lookout-hunt-pic').css('display') == 'none' ? false : true;
  378. if(isShow) {
  379. if(e.keyCode == 69) {
  380. if(lookVideo) {
  381. $('#lookout-hunt-pic').find('.fullscreen-video').fadeIn()
  382. lookVideo.play()
  383. } else{
  384. $('#lookout-hunt-pic').append(videoHtml)
  385. lookVideo = document.getElementById('lookout-video')
  386. lookVideo.play()
  387. }
  388. lookVideo.addEventListener("ended",function(){
  389. lookVideo.load()
  390. lookVideo.pause()
  391. $('.fullscreen-video-lookout').hide()
  392. $('#lookout-hunt-pic').hide()
  393. })
  394. }
  395. }
  396. })
  397. },
  398. }
  399. util.animateModal()
  400. util.handleModel()
  401. huntV.init()
  402. huntC.init()