scene1.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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 imgUrl from '../img/P1.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 lakeFlag = false
  11. var indexPath = $('body').attr('data-path')
  12. // 进度相关
  13. var progressNum = 0
  14. var progressFlag = {
  15. 'foot': false,
  16. 'deer': false,
  17. 'rabbit': false,
  18. 'lake': false,
  19. 'lookout': false
  20. }
  21. var videoMap = {
  22. 'lookup': '8884585',
  23. 'lake': '8887637',
  24. 'aim': '8887375',
  25. 'shoot': '8887379',
  26. 'open': '8887381'
  27. }
  28. var mp4UrlMap = {
  29. }
  30. var lakeV = {
  31. init() {
  32. this.initLakeView()
  33. this.handleReady()
  34. this.getVideoSource()
  35. this.handleNav()
  36. },
  37. initLakeView() {
  38. viewer = new PhotoSphereViewer({
  39. container: 'photosphere',
  40. panorama: imgUrl,
  41. min_fov: 50,
  42. max_fov: 70,
  43. navbar: false,
  44. time_anim: false,
  45. markers: [
  46. // 多边形
  47. {
  48. id: 'deer-polygon',
  49. polygon_px: [
  50. [3660, 1544], [4060, 1544], [4060, 1968],[3660, 1968]
  51. ],
  52. svgStyle: {
  53. fill: 'rgba(0, 0, 0, 0)',
  54. }
  55. },
  56. {
  57. id: 'location-deer',
  58. x: 3844,
  59. y: 1781,
  60. image: location,
  61. width: 35,
  62. height: 35,
  63. anchor: 'bottom center',
  64. },
  65. // 脚印
  66. {
  67. id: 'foot-polygon',
  68. polygon_px: [
  69. [120, 2094], [120, 2382], [500, 2382],[500, 2094]
  70. ],
  71. svgStyle: {
  72. fill: 'rgba(255, 255, 255, 0)'
  73. }
  74. },
  75. {
  76. id: 'location-foot',
  77. x: 286,
  78. y: 2228,
  79. image: location,
  80. width: 35,
  81. height: 35,
  82. anchor: 'bottom center',
  83. },
  84. // 兔子
  85. {
  86. id: 'rabit-polygon',
  87. polygon_px: [
  88. [2026, 1808], [2026, 1930], [2138, 1930],[2138, 1808]
  89. ],
  90. svgStyle: {
  91. fill: 'rgba(255, 255, 255, 0)'
  92. }
  93. },
  94. {
  95. id: 'location-rabit',
  96. x: 2080,
  97. y: 1860,
  98. image: location,
  99. width: 35,
  100. height: 35,
  101. anchor: 'bottom center',
  102. },
  103. //望远镜
  104. {
  105. id: 'glass',
  106. x: 3641,
  107. y: 1500,
  108. image: glass,
  109. width: 56,
  110. height: 59,
  111. anchor: 'bottom center',
  112. },
  113. // 湖
  114. {
  115. id: 'location-lake',
  116. x: 150,
  117. y: 1965,
  118. image: location,
  119. width: 35,
  120. height: 35,
  121. anchor: 'bottom center',
  122. },
  123. ],
  124. })
  125. },
  126. handleReady() {
  127. viewer.on('ready', function() {
  128. $('.loading-bg').hide()
  129. viewer.rotate({
  130. x: 0,
  131. y: 0
  132. });
  133. viewer.animate({
  134. x: 3500,
  135. y: 1900
  136. },2000);
  137. });
  138. viewer.on('position-updated', function(position) {
  139. let lgt = position.longitude
  140. let lat = position.latitude
  141. if(lgt > 6 && lat < 0 && !lakeFlag) {
  142. lakeFlag = true
  143. $('#lake-suggest-modal').fadeIn()
  144. $('.nav').fadeIn()
  145. }
  146. })
  147. },
  148. getVideoSource() {
  149. let vids = ['8892551', '8887637', '8887375', '8887379', '8887381','8890691','8890693','8890695','8892913']
  150. // let videoEls = ['lookup', 'lake', 'aim', 'shoot', 'open']
  151. var videoEls = {
  152. '8892551': 'lookup',
  153. '8887637': 'lake',
  154. '8887375': 'aim',
  155. '8887379': 'shoot',
  156. '8887381': 'open',
  157. '8890691': 'book-lake',
  158. '8890693': 'book-taiga',
  159. '8890695': 'book-elden',
  160. '8892913': 'picVideo'
  161. }
  162. $.ajax({
  163. type: "GET",
  164. dataType: "json",
  165. url: `//video.duowan.com/jsapi/playPageVideoInfo/?vids=${vids.join(',')}`,
  166. success: function(data) {
  167. for(var i in data) {
  168. let resouce = util.deCodeArg(data[i].c).all,
  169. source = resouce.yuanhua || resouce[1300] || resouce[1000] || resouce[350]
  170. let name = videoEls[i]
  171. mp4UrlMap[name] = source.src
  172. }
  173. document.getElementById('open-video').src = mp4UrlMap['open']
  174. document.getElementById('aim-video').src = mp4UrlMap['aim']
  175. document.getElementById('shoot-video').src = mp4UrlMap['shoot']
  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. lakeC.lookoutClick()
  180. lakeC.playVideo()
  181. }
  182. })
  183. },
  184. // 导航权限处理
  185. handleNav() {
  186. // 初始化加载时
  187. let permision = localStorage.getItem('hunter_permision')
  188. if(permision) {
  189. progressFlag = {
  190. 'foot': true,
  191. 'deer': true,
  192. 'rabbit': true,
  193. 'lake': true,
  194. 'lookout': true
  195. }
  196. $('#cur-progress').html(5)
  197. if(permision == 2) {
  198. $('#scene-nav2').removeClass('disable')
  199. } else if(permision == 3 || permision == 4){
  200. $('#scene-nav2').removeClass('disable')
  201. $('#scene-nav3').removeClass('disable')
  202. }
  203. }
  204. }
  205. }
  206. var lakeC = {
  207. init() {
  208. this.modalShow()
  209. util.shooting()
  210. util.bookClick()
  211. util.toolbarClick()
  212. },
  213. modalShow() {
  214. // 点击显示介绍弹窗
  215. $('.nav').find('.current').click(function() {
  216. $('#lake-suggest-modal').fadeIn()
  217. })
  218. // 脚印
  219. function footModal() {
  220. if($('#lake-foot-modal').css('display') == 'none') {
  221. $('.pub-modal').hide()
  222. $('#lake-foot-modal').fadeIn()
  223. viewer.animate({
  224. longitude: 3.2,
  225. latitude: -0.27
  226. },600);
  227. }
  228. if(!progressFlag['foot']){
  229. progressFlag['foot'] = true
  230. $('#cur-progress').html(++progressNum)
  231. progressNum == 5 ? $('#scene-nav2').removeClass('disable') : ''
  232. progressNum == 5 ? localStorage.setItem('hunter_permision', '2') : ''
  233. }
  234. }
  235. $(document).on('click', '#psv-marker-foot-polygon', function() {
  236. footModal()
  237. })
  238. $(document).on('click', '#psv-marker-location-foot', function() {
  239. footModal()
  240. })
  241. // 鹿
  242. function deerModal() {
  243. if($('#lake-deer-modal').css('display') == 'none') {
  244. $('.pub-modal').hide()
  245. $('#lake-deer-modal').fadeIn()
  246. viewer.animate({
  247. longitude: 0.1,
  248. latitude: -0.05
  249. },600);
  250. }
  251. if(!progressFlag['deer']){
  252. progressFlag['deer'] = true
  253. $('#cur-progress').html(++progressNum)
  254. progressNum == 5 ? $('#scene-nav2').removeClass('disable') : ''
  255. progressNum == 5 ? localStorage.setItem('hunter_permision', '2') : ''
  256. }
  257. }
  258. $(document).on('click', '#psv-marker-deer-polygon', function(e) {
  259. deerModal()
  260. })
  261. $(document).on('click', '#psv-marker-location-deer', function() {
  262. deerModal()
  263. })
  264. // 野兔
  265. function rabitModal() {
  266. if($('#lake-rabbit-modal').css('display') == 'none') {
  267. $('.pub-modal').hide()
  268. $('#lake-rabbit-modal').fadeIn()
  269. viewer.animate({
  270. longitude: 4.87,
  271. latitude: -0.07
  272. },600);
  273. }
  274. if(!progressFlag['rabbit']){
  275. progressFlag['rabbit'] = true
  276. $('#cur-progress').html(++progressNum)
  277. progressNum == 5 ? $('#scene-nav2').removeClass('disable') : ''
  278. progressNum == 5 ? localStorage.setItem('hunter_permision', '2') : ''
  279. }
  280. }
  281. $(document).on('click', '#psv-marker-rabit-polygon', function(e) {
  282. rabitModal()
  283. })
  284. $(document).on('click', '#psv-marker-location-rabit', function() {
  285. rabitModal()
  286. })
  287. // 开始狩猎
  288. $('.hunt-btn').click(function(){
  289. $('#lake-deer-modal').hide()
  290. $('#equit-modal').show()
  291. })
  292. $('.nav-item-wrap').click(function() {
  293. $('.nav-item-wrap').removeClass('active')
  294. $(this).parents('.container').find('.main').hide()
  295. $(this).addClass('active')
  296. var ind = $(this).attr('data-ind')
  297. if(ind == 1){
  298. $('#weapon-modal').show()
  299. }
  300. if(ind == 2){
  301. $('#fodder-modal').show()
  302. }
  303. if(ind == 3){
  304. $('#aim-modal').show()
  305. }
  306. })
  307. //湖
  308. $(document).on('click', '#psv-marker-location-lake', function() {
  309. if(!$('#lake-pic')[0]){
  310. var lakeHtml = ` <div class="mod-full-picture" id="lake-pic" style="display:none">
  311. <div class="pub-btn go-back">返回</div>
  312. <div class="full-pic-modal small-modal">
  313. <div class="top-bar">
  314. 莱顿湖
  315. </div>
  316. <div class="container clearfix">
  317. <p>地球上湖泊总面积为270万平方公里,占陆地面积的1.8%,面积大于5000平方公里的湖</p>
  318. <p>青海湖泊有35个。芬兰的湖泊最多,被称为“万湖之国”,拥有大小湖泊6万多个。</p>
  319. <p>湖泊一旦形成,就受到外部自然因素和内部各种过程的持续作用而不断演变。入湖河流携带的大量泥沙和生物残骸年复一年在湖内沉积,湖盆逐渐淤浅,变成陆地,或随着沿岸带水生植物的发展,逐渐变成沼泽。</p>
  320. <div class="eyes-btn"></div>
  321. </div>
  322. </div>
  323. <div class="fullscreen-video fullscreen-video-picture" style="display: none">
  324. <video id="picture-video" preload="metadata" width="100%">
  325. <source src="${mp4UrlMap['picVideo']}">
  326. </video>
  327. <div class="close-icon close-full-video"></div>
  328. </div>
  329. </div>`
  330. $('body').append(lakeHtml)
  331. util.bgMove($('.mod-full-picture'))
  332. }
  333. $('#lake-pic').fadeIn()
  334. if(!progressFlag['lake']){
  335. progressFlag['lake'] = true
  336. $('#cur-progress').html(++progressNum)
  337. progressNum == 5 ? $('#scene-nav2').removeClass('disable') : ''
  338. progressNum == 5 ? localStorage.setItem('hunter_permision', '2') : ''
  339. }
  340. })
  341. $(document).on('click', '.eyes-btn', function() {
  342. $('.fullscreen-video-picture').show()
  343. var video = document.getElementById('picture-video')
  344. video.play()
  345. video.addEventListener("ended",function(){
  346. video.load()
  347. $('.fullscreen-video-picture').hide()
  348. })
  349. })
  350. },
  351. playVideo() {
  352. $('#rabbit-video-play').click(function() {
  353. if(!$('#lake-video-suggest')[0]){
  354. var lakeVideoHtml = `<div class="video-wrapper pub-modal-mask" id="lake-video-suggest">
  355. <div class="part-screen">
  356. <video controls autoplay id="lake-video">
  357. <source src="${mp4UrlMap['lake']}">
  358. </video>
  359. <div class="close-icon close-mask-icon"></div>
  360. </div>
  361. </div>`
  362. $('body').append(lakeVideoHtml)
  363. } else {
  364. $('#lake-video-suggest').show()
  365. document.getElementById('lake-video').play()
  366. }
  367. })
  368. },
  369. // 瞭望台
  370. lookoutClick() {
  371. var videoHtml = `<div class="fullscreen-video fullscreen-video-lookout">
  372. <video id="lookout-video" autoplay width="100%">
  373. <source src="${mp4UrlMap['lookup']}">
  374. </video>
  375. <div class="close-icon close-full-video"></div>
  376. </div>`
  377. $(document).on('click', '#psv-marker-glass', function() {
  378. if(!$('#lookout-pic')[0]){
  379. var lookOutHtml = ` <div class="mod-full-picture" id="lookout-pic" style="display:none">
  380. <div class="pub-btn go-back">返回</div>
  381. <img class="e-tips" src="${eUrl}" alt="">
  382. </div>`
  383. $('body').append(lookOutHtml)
  384. }
  385. $('#lookout-pic').fadeIn()
  386. if(!progressFlag['lookout']){
  387. progressFlag['lookout'] = true
  388. $('#cur-progress').html(++progressNum)
  389. progressNum == 5 ? $('#scene-nav2').removeClass('disable') : ''
  390. progressNum == 5 ? localStorage.setItem('hunter_permision', '2') : ''
  391. }
  392. })
  393. // 监听E键
  394. $(document).on('keyup', function(e) {
  395. var lookVideo = document.getElementById('lookout-video')
  396. var isShow = $('#lookout-pic').css('display') == 'none' ? false : true;
  397. if(isShow) {
  398. if(e.keyCode == 69) {
  399. if(lookVideo) {
  400. $('#lookout-pic').find('.fullscreen-video').fadeIn()
  401. lookVideo.play()
  402. } else{
  403. $('#lookout-pic').append(videoHtml)
  404. lookVideo = document.getElementById('lookout-video')
  405. lookVideo.play()
  406. }
  407. lookVideo.addEventListener("ended",function(){
  408. lookVideo.load()
  409. lookVideo.pause()
  410. $('.fullscreen-video-lookout').hide()
  411. $('#lookout-pic').hide()
  412. })
  413. }
  414. }
  415. })
  416. },
  417. }
  418. let entry = localStorage.getItem('entry')
  419. if(entry == 'index') {
  420. util.animateModal()
  421. util.handleModel()
  422. lakeV.init()
  423. lakeC.init()
  424. } else {
  425. window.location.href = indexPath
  426. }