scene2.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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/P2.jpg'
  6. import location from '../img/location.png';
  7. import glass from '../img/glass.png'; //望远镜
  8. import eUrl from '../img/E.png';
  9. import snowCircle from '../img/snow.png';
  10. var viewer = null
  11. var snowFlag = false
  12. var timer = null
  13. var indexPath = $('body').attr('data-path')
  14. // 进度相关
  15. var progressNum = 0
  16. var allStep = 5
  17. var progressFlag = {
  18. 'bear': false,
  19. 'lynx': false,
  20. 'road': false,
  21. 'bird': false,
  22. 'lookout': false
  23. }
  24. var mp4UrlMap = {
  25. }
  26. var snowV = {
  27. init() {
  28. this.initSnowView()
  29. this.handleReady()
  30. this.getVideoSource()
  31. this.handleNav()
  32. this.snow()
  33. },
  34. initSnowView() {
  35. viewer = new PhotoSphereViewer({
  36. container: 'photosphere',
  37. panorama: 'http://hdzt.duowan.com/s/1806hunter/P2.jpg',
  38. // panorama: pic,
  39. min_fov: 50,
  40. max_fov: 70,
  41. navbar: false,
  42. time_anim: false,
  43. markers: [
  44. // 黑熊
  45. {
  46. id: 'beer-polygon',
  47. polygon_px: [
  48. [3741, 1679], [3741, 2044], [4100, 2044],[4100, 1679]
  49. ],
  50. svgStyle: {
  51. fill: 'rgba(255, 255, 255, 0)'
  52. }
  53. },
  54. {
  55. id: 'location-beer',
  56. x: 3891,
  57. y: 1763,
  58. image: location,
  59. width: 35,
  60. height: 35,
  61. anchor: 'bottom center',
  62. },
  63. // lynx
  64. {
  65. id: 'lynx-polygon',
  66. polygon_px: [
  67. [680, 1972], [680, 2144], [869, 1972],[869, 2144]
  68. ],
  69. svgStyle: {
  70. fill: 'rgba(255, 255, 255, 0)'
  71. }
  72. },
  73. {
  74. id: 'location-lynx',
  75. x: 792,
  76. y: 2020,
  77. image: location,
  78. width: 35,
  79. height: 35,
  80. anchor: 'bottom center',
  81. },
  82. // 大鸟
  83. {
  84. id: 'bird-polygon',
  85. polygon_px: [
  86. [5932, 1296], [6096, 1296], [6096, 1428],[5932, 1428]
  87. ],
  88. svgStyle: {
  89. fill: 'rgba(255, 255, 255, 0)'
  90. }
  91. },
  92. {
  93. id: 'location-bird',
  94. x: 6032,
  95. y: 1360,
  96. image: location,
  97. width: 35,
  98. height: 35,
  99. anchor: 'bottom center',
  100. },
  101. // 望远镜
  102. {
  103. id: 'glass',
  104. x: 6268,
  105. y: 1700,
  106. image: glass,
  107. width: 56,
  108. height: 59,
  109. anchor: 'bottom center',
  110. },
  111. // 铁路
  112. {
  113. id: 'location-road',
  114. x: 1694,
  115. y: 1948,
  116. image: location,
  117. width: 35,
  118. height: 35,
  119. anchor: 'bottom center',
  120. },
  121. ]
  122. })
  123. },
  124. handleReady() {
  125. viewer.on('ready', function() {
  126. $('.loading-bg').hide()
  127. viewer.rotate({
  128. x: 0,
  129. y: 0
  130. });
  131. viewer.animate({
  132. x: 3500,
  133. y: 1900
  134. },2000);
  135. });
  136. viewer.on('position-updated', function(position) {
  137. let lgt = position.longitude
  138. let lat = position.latitude
  139. if(lgt > 6 && lat < 0 && !snowFlag) {
  140. snowFlag = true
  141. $('#snow-suggest-modal').fadeIn()
  142. $('.nav').fadeIn()
  143. }
  144. })
  145. },
  146. // 雪花动画
  147. snow() {
  148. //1、定义一片雪花模板
  149. var flake = $("<img class='snow-circle' src=" + snowCircle + ">").css({
  150. "position": "absolute"
  151. })
  152. //获取页面的宽度,利用这个数来算出,雪花开始时left的值
  153. var documentWidth = $(document).width();
  154. //获取页面的高度 相当于雪花下落结束时Y轴的位置
  155. var documentHieght = $(document).height();
  156. //定义生成一片雪花的毫秒数
  157. var millisec = 200;
  158. //2、设置第一个定时器,周期性定时器,每隔一段时间(millisec)生成一片雪花;
  159. timer = setInterval(function() {
  160. //随机生成雪花下落 开始 时left的值,相当于开始时X轴的位置
  161. var startLeft = Math.random() * documentWidth;
  162. //随机生成雪花下落 结束 时left的值,相当于结束时X轴的位置
  163. var endLeft = Math.random() * documentWidth;
  164. //随机生成雪花大小
  165. var flakeSize = 5 + 20 * Math.random();
  166. //随机生成雪花下落持续时间
  167. var durationTime = 4000 + 7000 * Math.random();
  168. //随机生成雪花下落 开始 时的透明度
  169. var startOpacity = 0.7 + 0.3 * Math.random();
  170. //随机生成雪花下落 结束 时的透明度
  171. var endOpacity = 0.2 + 0.2 * Math.random();
  172. //3、克隆一个雪花模板,定义雪花的初始样式,拼接到页面中
  173. flake.clone().appendTo($("body")).css({
  174. "left": startLeft,
  175. "opacity": startOpacity,
  176. "font-size": flakeSize,
  177. "top": "-25px",
  178. }).animate({ //执行动画
  179. "left": endLeft,
  180. "opacity": endOpacity,
  181. "top": documentHieght
  182. }, durationTime, function() {
  183. //4、当雪花落下后,删除雪花。
  184. $(this).remove();
  185. });
  186. }, millisec);
  187. },
  188. clearTime() {
  189. clearInterval(timer)
  190. },
  191. getVideoSource() {
  192. let vids = ['8893045','8891917','8893043','8891831','8891835','8890691','8890693','8890695','8894969','8897799','8897801','8897803']
  193. var videoEls = {
  194. '8891831': 'lookup',
  195. '8891835': 'snow',
  196. '8893045': 'aim',
  197. '8891917': 'shoot',
  198. '8893043': 'open',
  199. '8890691': 'book-lake',
  200. '8890693': 'book-taiga',
  201. '8890695': 'book-elden',
  202. '8894969': 'picVideo',
  203. '8897799': 'openB',
  204. '8897801': 'aimB',
  205. '8897803': 'shootB',
  206. }
  207. $.ajax({
  208. type: "GET",
  209. dataType: "json",
  210. url: `//video.duowan.com/jsapi/playPageVideoInfo/?vids=${vids.join(',')}`,
  211. success: function(data) {
  212. for(var i in data) {
  213. let resouce = util.deCodeArg(data[i].c).all,
  214. source = resouce.yuanhua || resouce[1300] || resouce[1000] || resouce[350]
  215. let name = videoEls[i]
  216. mp4UrlMap[name] = source.src
  217. }
  218. document.getElementById('open-video').src = mp4UrlMap['open']
  219. document.getElementById('aim-video').src = mp4UrlMap['aim']
  220. document.getElementById('shoot-video').src = mp4UrlMap['shoot']
  221. document.getElementById('open-video-b').src = mp4UrlMap['openB']
  222. document.getElementById('aim-video-b').src = mp4UrlMap['aimB']
  223. document.getElementById('shoot-video-b').src = mp4UrlMap['shootB']
  224. document.getElementById('book-lake-video').src = mp4UrlMap['book-lake']
  225. document.getElementById('book-taiga-video').src = mp4UrlMap['book-taiga']
  226. document.getElementById('book-elden-video').src = mp4UrlMap['book-elden']
  227. snowC.lookoutClick()
  228. snowC.playVideo()
  229. }
  230. })
  231. },
  232. // 导航权限处理
  233. handleNav() {
  234. // 初始化加载时
  235. let permision = localStorage.getItem('hunter_permision')
  236. if(permision == 3 || permision == 4) {
  237. $('#scene-nav3').removeClass('disable')
  238. progressFlag = {
  239. 'bear': true,
  240. 'lynx': true,
  241. 'road': true,
  242. 'bird': true,
  243. 'lookout': true
  244. }
  245. $('#cur-progress').html(5)
  246. } else if(permision < 2) {
  247. window.location.href = indexPath
  248. }
  249. }
  250. }
  251. var snowC = {
  252. init() {
  253. this.modalShow()
  254. util.bookClick()
  255. util.toolbarClick()
  256. util.shooting()
  257. },
  258. modalShow() {
  259. // 点击显示介绍弹窗
  260. $('.nav').find('.current').click(function() {
  261. $('#snow-suggest-modal').fadeIn()
  262. })
  263. // 黑熊
  264. function beerModal() {
  265. if($('#snow-beer-modal').css('display') == 'none') {
  266. $('.pub-modal').hide()
  267. $('#snow-beer-modal').fadeIn()
  268. viewer.animate({
  269. longitude: 0,
  270. latitude: 0.1
  271. },600);
  272. }
  273. if(!progressFlag['bear']){
  274. progressFlag['bear'] = true
  275. $('#cur-progress').html(++progressNum)
  276. progressNum == allStep ? $('#scene-nav3').removeClass('disable') : ''
  277. progressNum == allStep ? localStorage.setItem('hunter_permision', '3') : ''
  278. }
  279. }
  280. $(document).on('click', '#psv-marker-beer-polygon', function() {
  281. beerModal()
  282. })
  283. $(document).on('click', '#psv-marker-location-beer', function() {
  284. beerModal()
  285. })
  286. // lynx
  287. function lynxModal() {
  288. if($('#snow-lynx-modal').css('display') == 'none') {
  289. $('.pub-modal').hide()
  290. $('#snow-lynx-modal').fadeIn()
  291. viewer.animate({
  292. x: 792,
  293. y: 2020
  294. },600);
  295. }
  296. if(!progressFlag['lynx']){
  297. progressFlag['lynx'] = true
  298. $('#cur-progress').html(++progressNum)
  299. progressNum == allStep ? $('#scene-nav3').removeClass('disable') : ''
  300. progressNum == allStep ? localStorage.setItem('hunter_permision', '3') : ''
  301. }
  302. }
  303. $(document).on('click', '#psv-marker-lynx-polygon', function() {
  304. lynxModal()
  305. })
  306. $(document).on('click', '#psv-marker-location-lynx', function() {
  307. lynxModal()
  308. })
  309. // 大鸟
  310. function birdModal() {
  311. if($('#snow-bird-modal').css('display') == 'none') {
  312. $('.pub-modal').hide()
  313. $('#snow-bird-modal').fadeIn()
  314. viewer.animate({
  315. x: 6032,
  316. y: 1340
  317. },600);
  318. }
  319. if(!progressFlag['bird']){
  320. progressFlag['bird'] = true
  321. $('#cur-progress').html(++progressNum)
  322. progressNum == allStep ? $('#scene-nav3').removeClass('disable') : ''
  323. progressNum == allStep ? localStorage.setItem('hunter_permision', '3') : ''
  324. }
  325. }
  326. $(document).on('click', '#psv-marker-bird-polygon', function() {
  327. birdModal()
  328. })
  329. $(document).on('click', '#psv-marker-location-bird', function() {
  330. birdModal()
  331. })
  332. $(document).on('click', '#psv-marker-location-road', function() {
  333. if(!$('#road-pic')[0]){
  334. var roadHtml = ` <div class="mod-full-picture" id="road-pic" style="display:none">
  335. <div class="pub-btn go-back">返回</div>
  336. <div class="full-pic-modal small-modal">
  337. <div class="top-bar">
  338. 西伯利亚铁路
  339. </div>
  340. <div class="container clearfix">
  341. <p>西伯利亚铁路,总长9288公里,从莫斯科到符拉迪沃斯托克跨越8个时区,是世界上最长最壮观的铁路线之一。该铁路修建于1891年到1916年,起点是莫斯科,途中穿过辽阔的松树林、跨过了乌拉尔山脉、穿越了西伯利亚冻土带,最终抵达太平洋。苏联政府为这条世界上最长的铁路投入了大量补贴。全程票价12000卢布,约合465美元。该铁路的修建,不仅让原本荒无人烟的西伯利亚地区逐渐繁荣起来,也给俄罗斯带来巨大的经济效益,成为该国陆地运输的主要通道。至今,由于该路票价提高,能负担这么长行程的火车票的俄罗斯人已经不多了。</p>
  342. <div class="eyes-btn"></div>
  343. </div>
  344. </div>
  345. <div class="fullscreen-video fullscreen-video-picture" style="display: none">
  346. <video id="picture-video" preload="metadata" width="100%">
  347. <source src="${mp4UrlMap['picVideo']}">
  348. </video>
  349. <div class="close-icon close-full-video"></div>
  350. </div>
  351. </div>`
  352. $('body').append(roadHtml)
  353. util.bgMove($('.mod-full-picture'))
  354. }
  355. $('#road-pic').fadeIn()
  356. if(!progressFlag['road']){
  357. progressFlag['road'] = true
  358. $('#cur-progress').html(++progressNum)
  359. progressNum == allStep ? $('#scene-nav3').removeClass('disable') : ''
  360. progressNum == allStep ? localStorage.setItem('hunter_permision', '3') : ''
  361. }
  362. })
  363. $(document).on('click', '.eyes-btn', function() {
  364. $('.fullscreen-video-picture').show()
  365. var video = document.getElementById('picture-video')
  366. video.play()
  367. video.addEventListener("ended",function(){
  368. video.load()
  369. $('.fullscreen-video-picture').hide()
  370. })
  371. })
  372. },
  373. playVideo() {
  374. $('#snow-video-play').click(function() {
  375. if(!$('#snow-video-suggest')[0]){
  376. var snowVideoHtml = `<div class="video-wrapper pub-modal-mask" id="snow-video-suggest">
  377. <div class="part-screen">
  378. <video controls autoplay id="snow-video">
  379. <source src="${mp4UrlMap['snow']}">
  380. </video>
  381. <div class="close-icon close-mask-icon"></div>
  382. </div>
  383. </div>`
  384. $('body').append(snowVideoHtml)
  385. } else {
  386. $('#snow-video-suggest').show()
  387. document.getElementById('snow-video').play()
  388. }
  389. })
  390. },
  391. // 瞭望台
  392. lookoutClick() {
  393. var videoHtml = `<div class="fullscreen-video fullscreen-video-lookout">
  394. <video id="lookout-video" autoplay width="100%">
  395. <source src="${mp4UrlMap['lookup']}">
  396. </video>
  397. <div class="close-icon close-full-video"></div>
  398. </div>`
  399. $(document).on('click', '#psv-marker-glass', function() {
  400. if(!$('#lookout-snow-pic')[0]){
  401. var lookOutHtml = ` <div class="mod-full-picture" id="lookout-snow-pic" style="display:none">
  402. <div class="pub-btn go-back">返回</div>
  403. <img class="e-tips" src="${eUrl}" alt="">
  404. </div>`
  405. $('body').append(lookOutHtml)
  406. }
  407. $('#lookout-snow-pic').fadeIn()
  408. if(!progressFlag['lookout']){
  409. progressFlag['lookout'] = true
  410. $('#cur-progress').html(++progressNum)
  411. progressNum == allStep ? $('#scene-nav3').removeClass('disable') : ''
  412. progressNum == allStep ? localStorage.setItem('hunter_permision', '3') : ''
  413. }
  414. })
  415. // 监听E键
  416. $(document).on('keyup', function(e) {
  417. var lookVideo = document.getElementById('lookout-video')
  418. var isShow = $('#lookout-snow-pic').css('display') == 'none' ? false : true;
  419. if(isShow) {
  420. if(e.keyCode == 69) {
  421. if(lookVideo) {
  422. $('#lookout-snow-pic').find('.fullscreen-video').fadeIn()
  423. lookVideo.play()
  424. } else{
  425. $('#lookout-snow-pic').append(videoHtml)
  426. lookVideo = document.getElementById('lookout-video')
  427. lookVideo.play()
  428. }
  429. lookVideo.addEventListener("ended",function(){
  430. lookVideo.load()
  431. lookVideo.pause()
  432. $('.fullscreen-video-lookout').hide()
  433. $('#lookout-snow-pic').hide()
  434. })
  435. }
  436. }
  437. })
  438. },
  439. }
  440. util.animateModal()
  441. util.handleModel()
  442. snowV.init()
  443. snowC.init()