scene3.js 16 KB

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