scene2.js 18 KB

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