scene2.js 18 KB

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