ypano.js 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674
  1. var settings = {};
  2. settings["onstart"] = "trace('on start...')";
  3. settings["view.hlookat"] = 30;
  4. const house ={
  5. // curr_id:2,
  6. idx:0,
  7. // direction:'D4',
  8. nextId:null,
  9. isLoading:false,
  10. numLoaded:0,
  11. mode:'menu',
  12. is_auto_play:false,
  13. texture:{
  14. id:-1,
  15. curr:null,
  16. next:null,
  17. isloading:false,
  18. },
  19. config:{
  20. lat_step:10,
  21. lon_step:10,
  22. },
  23. title:"瑶里景区",
  24. src:[
  25. {id:1,name:"guzhen",title:'千年古镇',view:{lat: -1.7857185363769528,lon: -25.542864990234374},
  26. direction:[
  27. {id:2,name:'F',angle:{lat: -10, lon: 16.3},offset:180},
  28. {id:3,name:'R',angle:{lat: -13.7, lon: 75.3},offset:-70},
  29. {id:6,name:'B',angle:{lat: -13.7, lon: 75.3},offset:-70},
  30. {id:7,name:'L',angle:{lat: -13.7, lon: 75.3},offset:-70}
  31. ],
  32. // D1:{id:2,angle:{lat: -10, lon: 16.3},offset:180},
  33. // D2:{id:3,angle:{lat: -13.7, lon: 75.3},offset:-70},
  34. // D3:{id:6,angle:{lat: -13.7, lon: 75.3},offset:-70},
  35. // D4:{id:7,angle:{lat: -13.7, lon: 75.3},offset:-70},
  36. spots:[
  37. {name:'按1跳转至仿明清古桥',position:{x:135.02634001646553,y: -18.541531481188343,z: -256},rotation:{x:0,y:0,z:0}},
  38. {name:'按2跳转至服务区',position:{x: 255.99999999999997, y: -2.243401100489121, z: 40.86223734613961},rotation:{x:Math.PI/2,y:-Math.PI/3,z:Math.PI/2}},
  39. {name:'按3跳转至古城墙',position:{x: -256, y: -28.249801117197098, z: -1.42468348463467},rotation:{x:Math.PI/2,y:-Math.PI/6,z:Math.PI/2}},
  40. {name:'按4跳转至古树',position:{x: -79.95672966662912, y: -44.97558105439687, z: 256},rotation:{x:0,y:0,z:0}}
  41. ]
  42. },
  43. {id:2,name:"fangmingqingguqiao",title:'仿明清古桥',parent:1,view:{lat:-4.907144165039063,lon: 188.2071454},
  44. direction:[
  45. {id:null,name:'F'},
  46. {id:null,name:'B'},
  47. {id:null,name:'L'},
  48. {id:null,name:'R'}
  49. ],
  50. spots:[
  51. ]
  52. },
  53. {id:3,name:"fuwuqu",title:'服务区',parent:1,view:{lat: -7.47857208 ,lon: 172.3500193},
  54. direction:[
  55. {id:4,name:'F',angle:{lat: -13.6, lon: 54},offset:180},
  56. {id:2,name:'B',angle:{lat: 2.7, lon: 16.7},offset:90},
  57. {id:null,name:'L'},
  58. {id:null,name:'R'}
  59. ],
  60. spots:[
  61. // {positio}
  62. {name:'按1跳转至程氏祠堂',position:{x: 255.99999999999997, y: -23.59033674128833, z: -13.384937948055738},rotation:{x:Math.PI/2,y:-Math.PI/6,z:Math.PI/2}},
  63. {name:'按2跳转至仿明清古桥',position:{x: -256, y: -28.566268036285038, z: -8.3744418975616},rotation:{x:Math.PI/2,y:-Math.PI/6,z:Math.PI/2}}
  64. ]
  65. },
  66. {id:4,name:"chengshicitang",title:'程氏祠堂',parent:3,view:{lat: -5.6571446 ,lon: 181.8857138},
  67. // D1:{id:5,angle:{lat: 0, lon: 13.5},offset:0},
  68. direction:[
  69. {id:5,name:'F',angle:{lat: 0, lon: 13.5},offset:0},
  70. {id:null,name:'B'},
  71. {id:null,name:'L'},
  72. {id:null,name:'R'}
  73. ],
  74. spots:[
  75. {name:'按1跳转至陈毅居',position:{x: -255.99999999999997, y: -118.98430403698123, z: 4.6933538825472105},rotation:{x:Math.PI/2,y:-Math.PI/6,z:Math.PI/2}}
  76. ]
  77. },
  78. {id:5,name:"chenyiju",title:'陈毅居',parent:4,view:{lat: -14.0142883 ,lon:12.064304},
  79. direction:[
  80. {id:null,name:'F'},
  81. {id:null,name:'B'},
  82. {id:null,name:'L'},
  83. {id:null,name:'R'}
  84. ],
  85. spots:[
  86. ]
  87. },
  88. {id:6,name:"guchengqiang",title:'古城墙',parent:1,view:{lat: -3.7285663 ,lon: -122.8285818},
  89. direction:[
  90. {id:null,name:'F'},
  91. {id:null,name:'B'},
  92. {id:null,name:'L'},
  93. {id:null,name:'R'}
  94. ],
  95. spots:[
  96. ]
  97. },
  98. {id:7,name:"gushu",title:'古树',parent:1,view:{lat: -5.22857 ,lon:136.4571441},
  99. direction:[
  100. {id:null,name:'F'},
  101. {id:null,name:'B'},
  102. {id:null,name:'L'},
  103. {id:null,name:'R'}
  104. ],
  105. spots:[
  106. ]
  107. },
  108. {id:8,name:"shoupiaochu",title:'售票处',view:{lat: -3.1928558 ,lon: 166.885716},
  109. // D1:{id:9,angle:{lat: -4.5, lon: -48},offset:-90},
  110. direction:[
  111. {id:9,name:'F',angle:{lat: -4.5, lon: -48},offset:-90},
  112. {id:null,name:'B'},
  113. {id:null,name:'L'},
  114. {id:null,name:'R'}
  115. ],
  116. spots:[
  117. // {positio}
  118. {name:'按1跳转至仙人桥',position:{x: 32.05692316713218, y: -35.18905393081038, z: 256},rotation:{x:Math.PI/3,y:0,z:0}}
  119. ]
  120. },
  121. {id:9,name:"xianrenqiao",title:'仙人桥',parent:8,view:{lat: -18.621429 ,lon: 113.74286},
  122. // D1:{id:10,angle:{lat: 3.8, lon: -15},offset:-90},
  123. // D2:{id:11,angle:{lat: 3.8, lon: -15},offset:-90},
  124. direction:[
  125. {id:10,name:'F',angle:{lat: 3.8, lon: -15},offset:-90},
  126. {id:11,name:'B',angle:{lat: 3.8, lon: -15},offset:-90},
  127. {id:null,name:'L'},
  128. {id:null,name:'R'}
  129. ],
  130. spots:[
  131. {name:'按1跳转至南山瀑布',position:{x: -199.9938263054937, y: -59.49100505623731, z: 255.99999999999},rotation:{x:0,y:0,z:0}},
  132. {name:'按2跳转至仙女潭',position:{x: 130.25832756640813, y: -50.445126890140514, z: -256},rotation:{x:0,y:0,z:0}}
  133. ]
  134. },
  135. {id:10,name:"nanshanpubu",title:'南山瀑布',parent:9,view:{lat: -17.6571424484 ,lon: 163.35000},
  136. direction:[
  137. {id:null,name:'F'},
  138. {id:null,name:'B'},
  139. {id:null,name:'L'},
  140. {id:null,name:'R'}
  141. ],
  142. spots:[
  143. ]
  144. },
  145. {id:11,name:"xiannvtan",title:'仙女潭',parent:9,view:{lat: -19.157145 ,lon: 40.564288},
  146. // D1:{id:12,angle:{lat: -2.8, lon: 17},offset:180},
  147. direction:[
  148. {id:12,name:'F',angle:{lat: -2.8, lon: 17},offset:180},
  149. {id:null,name:'B'},
  150. {id:null,name:'L'},
  151. {id:null,name:'R'}
  152. ],
  153. spots:[
  154. {name:'按1跳转至开天辟地',position:{x: -209.73725040251847, y: -61.80104200737105, z: 256},rotation:{x:0,y:0,z:0}}
  155. ]
  156. },
  157. {id:12,name:"kaitianpidi",title:'开天辟地',parent:11,view:{lat: -14.9785 ,lon:214.242847},
  158. direction:[
  159. {id:null,name:'F'},
  160. {id:null,name:'B'},
  161. {id:null,name:'L'},
  162. {id:null,name:'R'}
  163. ],
  164. spots:[
  165. ]
  166. },
  167. {id:13,name:"yaolihangpai",title:'瑶里航拍',view:{lat: -20.12143 ,lon: 121.24286255},
  168. // D1:{id:14,angle:{lat: 1.4, lon: 80},offset:180},
  169. // D2:{id:15,angle:{lat: 1.4, lon: 80},offset:180},
  170. // D3:{id:16,angle:{lat: 1.4, lon: 80},offset:180},
  171. // D4:{id:17,angle:{lat: 1.4, lon: 80},offset:180},
  172. direction:[
  173. {id:14,name:'F',angle:{lat: 1.4, lon: 80},offset:180},
  174. {id:15,name:'B',angle:{lat: 1.4, lon: 80},offset:180},
  175. {id:16,name:'L',angle:{lat: 1.4, lon: 80},offset:180},
  176. {id:17,name:'R',angle:{lat: 1.4, lon: 80},offset:180}
  177. ],
  178. spots:[
  179. {name:'按1跳转至瑶里航拍1',position:{x: -139.41044044624903, y: -68.33152420782919, z: 256},rotation:{x:0,y:0,z:0}},
  180. {name:'按2跳转至瑶里航拍2',position:{x: -256, y: -12.727990822231067, z: -110.34632793606},rotation:{x:Math.PI/2,y:-Math.PI/2,z:Math.PI/2}},
  181. {name:'按3跳转至瑶里航拍3',position:{x: 77.52461071027368, y: -31.160905545817563, z: -255.9999},rotation:{x:0,y:0,z:0}},
  182. {name:'按4跳转至瑶里航拍4',position:{x: 256, y: -46.42406470850259, z: 145.978111780317},rotation:{x:0,y:Math.PI/2,z:0}}
  183. ]
  184. },
  185. {id:14,name:"yaolihangpai1",title:'瑶里航拍1',parent:13,view:{lat: -11.442856979 ,lon: 110.1},
  186. direction:[
  187. {id:null,name:'F'},
  188. {id:null,name:'B'},
  189. {id:null,name:'L'},
  190. {id:null,name:'R'}
  191. ],
  192. spots:[
  193. ]
  194. },
  195. {id:15,name:"yaolihangpai2",title:'瑶里航拍2',parent:13,view:{lat: -8.55 ,lon: 245.52856979},
  196. direction:[
  197. {id:null,name:'F'},
  198. {id:null,name:'B'},
  199. {id:null,name:'L'},
  200. {id:null,name:'R'}
  201. ],
  202. spots:[
  203. ]
  204. },
  205. {id:16,name:"yaolihangpai3",title:'瑶里航拍3',parent:13,view:{lat:-18.407143 ,lon: 319.1357},
  206. direction:[
  207. {id:null,name:'F'},
  208. {id:null,name:'B'},
  209. {id:null,name:'L'},
  210. {id:null,name:'R'}
  211. ],
  212. spots:[
  213. ]
  214. },
  215. {id:17,name:"yaolihangpai4",title:'瑶里航拍4',parent:13,view:{lat:-25.15764 ,lon: 39},
  216. direction:[
  217. {id:null,name:'F'},
  218. {id:null,name:'B'},
  219. {id:null,name:'L'},
  220. {id:null,name:'R'}
  221. ],
  222. spots:[
  223. ]
  224. },
  225. ],
  226. direction:[
  227. {id:1,name:"F",at:{x:0,y:0,z:-1}},
  228. {id:2,name:"B",at:{x:0,y:0,z:1}},
  229. {id:3,name:"L",at:{x:-1,y:0,z:0}},
  230. {id:4,name:"R",at:{x:1,y:0,z:0}}
  231. ],
  232. playList:{
  233. idx:0,
  234. orders:[
  235. {id:1},{id:2},{id:3},{id:4},{id:5},{id:6},{id:7},{id:8},{id:9},{id:10},{id:11},{id:12},
  236. {id:13},{id:14},{id:15},{id:16},{id:17}
  237. ]
  238. },
  239. menuList:[
  240. {id:1},{id:2},{id:3},{id:4},{id:5},{id:6},{id:7},{id:8},{id:9},{id:10},{id:11},{id:12},{id:13}
  241. ],
  242. menu_control_select:-1,
  243. zoom:{
  244. direction:0,
  245. step:30,
  246. is_selected:false,
  247. factor:1,
  248. status:'x0.9'
  249. },
  250. rotation:{
  251. is_auto:false,
  252. }
  253. }
  254. embedpano({ id: "krpanoSWFObject_",swf:"lib/tour.swf", xml:"js/tour.xml", target:"pano", html5:"auto", mobilescale:1.0,
  255. passQueryParameters:true, onready: krpanoReady, vars:settings});
  256. function krpanoReady(krpano){
  257. // var krpano = document.getElementById('krpanoSWFObject_');
  258. window.krpano = krpano
  259. changeTourMode()
  260. }
  261. function changeTourMode(){
  262. if(house.mode==='menu'){
  263. }else{
  264. }
  265. }
  266. function onKeyEvent(e){
  267. console.log('dccc')
  268. console.log(e)
  269. }
  270. init();
  271. animate();
  272. function init() {
  273. const queryString = window.location.search;
  274. const urlParams = new URLSearchParams(queryString);
  275. const panoId = urlParams.get('id')?urlParams.get('id'):0
  276. house.idx = panoId
  277. const backurl = urlParams.get('backurl')?urlParams.get('backurl'):'yaoli.html'
  278. house.backurl = backurl
  279. const scene_name = 'scene_' + house.src[house.idx ].name
  280. changeScene(scene_name)
  281. initMenu()
  282. document.addEventListener('mousedown', onPointerStart, false);
  283. document.addEventListener('mousemove', onPointerMove, false);
  284. document.addEventListener('mouseup', onPointerUp, false);
  285. document.addEventListener('wheel', onDocumentMouseWheel, false);
  286. document.addEventListener('touchstart', onPointerStart, false);
  287. document.addEventListener('touchmove', onPointerMove, false);
  288. document.addEventListener('touchend', onPointerUp, false);
  289. }
  290. // function updateDirection(){
  291. // for(let d of house.src[house.idx].direction){
  292. // switch(d.name){
  293. // case 'F':
  294. // if(d.id!=null){
  295. // document.getElementById("directionTop").innerHTML = house.src[d.id-1].title
  296. // // document.getElementById("directionTop").style.visibility = true
  297. // document.getElementById("direct_top").style.color = '#ffffff'
  298. // document.getElementById("direct_top_img").src = './yaoimages/direction_top.png'
  299. // }else{
  300. // document.getElementById("directionTop").innerHTML = ''
  301. // // document.getElementById("directionTop").style.visibility = false
  302. // document.getElementById("direct_top").style.color = '#c1c1c1'
  303. // document.getElementById("direct_top_img").src = './yaoimages/direction_top_disable.png'
  304. // }
  305. // break
  306. // case 'B':
  307. // if(d.id!=null){
  308. // document.getElementById("directionLeft").innerHTML = house.src[d.id-1].title
  309. // document.getElementById("direct_left").style.color = '#ffffff'
  310. // document.getElementById("direct_left_img").src = './yaoimages/direction_left.png'
  311. // }else{
  312. // document.getElementById("directionLeft").innerHTML = ''
  313. // document.getElementById("direct_left").style.color = '#c1c1c1'
  314. // document.getElementById("direct_left_img").src = './yaoimages/direction_left_disable.png'
  315. // }
  316. // break
  317. // case 'L':
  318. // if(d.id!=null){
  319. // document.getElementById("directionBottom").innerHTML = house.src[d.id-1].title
  320. // document.getElementById("direct_bottom").style.color = '#ffffff'
  321. // document.getElementById("direct_bottom_img").src = './yaoimages/direction_bottom.png'
  322. // }else{
  323. // document.getElementById("directionBottom").innerHTML = ''
  324. // document.getElementById("direct_bottom").style.color = '#c1c1c1'
  325. // document.getElementById("direct_bottom_img").src = './yaoimages/direction_bottom_disable.png'
  326. // }
  327. // break
  328. // case 'R':
  329. // if(d.id!=null){
  330. // document.getElementById("directionRight").innerHTML = house.src[d.id-1].title
  331. // document.getElementById("direct_right").style.color = '#ffffff'
  332. // document.getElementById("direct_right_img").src = './yaoimages/direction_right.png'
  333. // }else{
  334. // document.getElementById("directionRight").innerHTML = ''
  335. // document.getElementById("direct_right").style.color = '#c1c1c1'
  336. // document.getElementById("direct_right_img").src = './yaoimages/direction_right_disable.png'
  337. // }
  338. // break
  339. // default:
  340. // break
  341. // }
  342. // }
  343. // // }
  344. // changeSpots()
  345. // }
  346. // function directionBack(){
  347. // const parent_id = house.src[house.idx].parent
  348. // if(parent_id){
  349. // const idx = getIdxFromId(parent_id)
  350. // changeTexture(idx)
  351. // }
  352. // }
  353. // function createText(textWord){
  354. // let canvas = document.getElementById('textCanvas')
  355. // // let canvas = document.createElement('canvas')
  356. // canvas.width = 320
  357. // canvas.height = 60
  358. // let ctx = canvas.getContext('2d')
  359. // ctx.fillStyle = "#fffff0";
  360. // // // ctx.font = 'normal 24pt "Microsoft Yahei"'
  361. // // // // const name = clientZhou.country[clientZhou.idx].name
  362. // // // ctx.fillText(name, 120, 60)
  363. // // // let textWord = clientZhou.country[clientZhou.idx].description
  364. // ctx.font = 'normal 24pt "Microsoft Yahei"'
  365. // let len = parseInt(textWord.length / 35)
  366. // const offset = (320 - 30*parseInt(textWord.length))/2
  367. // for (let i = 0; i < (len + 1); i++) {
  368. // let space = (320 - 40*parseInt(textWord.length))/2
  369. // if (i === len) {
  370. // space = textWord.length - len * 35
  371. // }
  372. // let word = textWord.substr(i * 20, space)
  373. // ctx.fillText(word, offset, 15+35*(i+1))
  374. // }
  375. // let url = canvas.toDataURL('image/png')
  376. // let texture = new THREE.TextureLoader().load( url);
  377. // const tmaterial = new THREE.SpriteMaterial( {map:texture,transparent : true,opacity:1, side: THREE.DoubleSide} );
  378. // let text_plane2 = new THREE.Sprite( tmaterial );
  379. // text_plane2.scale.set(32,10,1);
  380. // // text_plane.position.set(30,30,30)
  381. // return text_plane2;
  382. // }
  383. function initMenu(){
  384. var menu=document.getElementById("menu");
  385. while (menu.firstChild) {
  386. menu.removeChild(menu.firstChild);
  387. }
  388. let mid = 0
  389. for(let item of house.menuList){
  390. const dpano = document.createElement("div");
  391. dpano.className = 'pano'
  392. // dpano.attr({'data-id':item.id})
  393. for(let i in house.src){
  394. if(house.src[i].id===item.id){
  395. mid = i
  396. break
  397. }
  398. }
  399. dpano.setAttribute('data-id',mid);
  400. const title = document.createElement("div");
  401. title.className = 'title'
  402. title.innerHTML = house.src[mid].title
  403. const thumb = document.createElement("div");
  404. thumb.className = 'thumb'
  405. // thumb.innerHTML = house.src[i].name
  406. const img=document.createElement("img");
  407. img.src= './thumb1k/'+house.src[mid].name + '1k_f.jpg';
  408. thumb.appendChild(img);
  409. dpano.appendChild(title);
  410. dpano.appendChild(thumb);
  411. menu.appendChild(dpano);
  412. }
  413. const ddiv = document.createElement("div");
  414. ddiv.innerHTML='-'
  415. ddiv.className = 'panoEnd'
  416. menu.appendChild(ddiv);
  417. var menuTitle=document.getElementById("menuTitle");
  418. menuTitle.innerHTML = house.title
  419. displayMenuNone()
  420. // house.menu_control_select = 0
  421. // const firstChild = document.getElementById('menu').firstChild
  422. // firstChild.className = 'panoSelect'
  423. // document.getElementById('menu').scrollLeft = 0
  424. }
  425. function displayMenu(){
  426. house.mode = 'menu'
  427. document.getElementById("menu").style.display='flex';
  428. //
  429. document.getElementById("menuTitle").style.display='flex';
  430. document.getElementById("menuControl").style.display='flex';
  431. document.getElementById("wholeDirection").style.display='none';
  432. const control = krpano.get("control");
  433. control.keybaccelerate =0
  434. krpano.set("control",control);
  435. }
  436. function displayMenuNone(){
  437. house.mode = 'full'
  438. document.getElementById("menu").style.display='none';
  439. // document.getElementById("menuTip").style.display='none';
  440. document.getElementById("menuTitle").style.display='none';
  441. document.getElementById("menuControl").style.display='none';
  442. document.getElementById("wholeDirection").style.display='flex';
  443. document.getElementById("menuTip").style.display='flex';
  444. setTimeout( function(){
  445. document.getElementById("menuTip").style.display='none';
  446. }, 5000 );
  447. house.zoom.is_selected = false
  448. house.zoom.status = 'zoom'
  449. document.getElementById('zoom').src="./yaoimages/zoomin.png"
  450. document.getElementById('zoom_title').innerHTML='放大'
  451. const control = krpano.get("control");
  452. control.keybaccelerate =0.5
  453. krpano.set("control",control);
  454. }
  455. // function doubleDelay(doubleCallback,callback,p){
  456. // timeId = setTimeout( function(){
  457. // if(Date.now()-delta<400){
  458. // for(let i in timeIds){
  459. // clearTimeout(timeIds[i])
  460. // }
  461. // // walkOn(d)
  462. // if(doubleCallback){
  463. // // doubleCallback()
  464. // }
  465. // }else{
  466. // // lookDirection(2)
  467. // callback(p)
  468. // }
  469. // }, 400 );
  470. // timeIds.push(timeId)
  471. // }
  472. function onKeyDown(e){
  473. // key_down_frequency++
  474. // delta = Date.now()
  475. // if(key_down_frequency>LONG_PRESS_TIMES){
  476. // switch(e.keyCode){
  477. // case 38://ArrowUp
  478. // lat +=1.5
  479. // break
  480. // case 40: //ArrowDown
  481. // lat -=1.5
  482. // break
  483. // case 37: //ArrowLeft
  484. // lon -= 1.5
  485. // break
  486. // case 39://ArrowRight
  487. // lon += 1.5
  488. // break
  489. // case 13://Enter
  490. // house.is_auto_play = true
  491. // break
  492. // default:
  493. // break
  494. // }
  495. // }
  496. }
  497. function arrowUp(){
  498. if(house.mode==='full'){
  499. // doubleDelay(walkingCamera,lookDirection,2)
  500. }else if(house.mode==='menu'){
  501. const nodess = document.getElementById("menu").childNodes;
  502. for(let i =0;i<nodess.length-1;i++){
  503. if(nodess[i].className==='panoSelect'){
  504. nodess[i].className = 'pano'
  505. }
  506. }
  507. switch(house.menu_control_select){
  508. case -1:
  509. case 0:
  510. // zoom
  511. house.menu_control_select = 1
  512. house.zoom.status = 'x1'
  513. house.zoom.is_selected = true
  514. document.getElementById('zoom').src="./yaoimages/zoomin_click.png"
  515. document.getElementById('zoom_title').innerHTML='x1'
  516. break
  517. case 1:
  518. // rotation
  519. console.log('house.zoom.status=',house.zoom.status)
  520. if(house.zoom.status==='zoom'||house.zoom.status==='x1'||house.zoom.status==='x0.9'){
  521. house.menu_control_select = 2
  522. house.rotation.is_auto = true
  523. document.getElementById('auto_rotation').src="./yaoimages/auto_rotation_click.png"
  524. house.zoom.is_selected = false
  525. house.zoom.status = 'zoom'
  526. document.getElementById('zoom').src="./yaoimages/zoomin.png"
  527. document.getElementById('zoom_title').innerHTML='放大'
  528. }
  529. break
  530. default:
  531. break
  532. }
  533. }
  534. }
  535. function arrowDown(){
  536. if(house.mode==='full'){
  537. // doubleDelay(null,lookDirection,1)
  538. }else if(house.mode==='menu'){
  539. if(house.rotation.is_auto==true){
  540. house.rotation.is_auto==false
  541. document.getElementById('auto_rotation').src="./yaoimages/auto_rotation.png"
  542. }
  543. const nodess = document.getElementById("menu").childNodes;
  544. for(let i =0;i<nodess.length-1;i++){
  545. if(nodess[i].className==='panoSelect'){
  546. nodess[i].className = 'pano'
  547. }
  548. }
  549. switch(house.menu_control_select){
  550. case -1:
  551. case 1:
  552. // menu
  553. if(house.zoom.status==='zoom'||house.zoom.status==='x0.9'||house.zoom.status==='x1'){
  554. house.menu_control_select = 0
  555. const firstChild = document.getElementById('menu').firstChild
  556. firstChild.className = 'panoSelect'
  557. document.getElementById('menu').scrollLeft = 0
  558. house.zoom.is_selected = false
  559. house.zoom.status = 'zoom'
  560. document.getElementById('zoom').src="./yaoimages/zoomin.png"
  561. document.getElementById('zoom_title').innerHTML='放大'
  562. }
  563. break
  564. case 2:
  565. // zoom
  566. house.menu_control_select = 1
  567. house.zoom.is_selected = true
  568. house.zoom.status = 'x1'
  569. document.getElementById('zoom').src="./yaoimages/zoomin_click.png"
  570. document.getElementById('zoom_title').innerHTML='x1'
  571. break
  572. default:
  573. break
  574. }
  575. }
  576. }
  577. function arrowLeft(){
  578. if(house.mode==='full'){
  579. }else if(house.mode==='menu'){
  580. let pano_select = -1
  581. const nodess = document.getElementById("menu").childNodes;
  582. for(let i =0;i<nodess.length-1;i++){
  583. if(nodess[i].className==='panoSelect'){
  584. pano_select=i===0?nodess.length -2:i-1
  585. nodess[i].className = 'pano'
  586. nodess[pano_select].className = 'panoSelect'
  587. const fromLeft = document.getElementById('menu').scrollLeft
  588. const toLeft = 270*pano_select;
  589. const coords = {x: fromLeft, y: 0} // Start at (0, 0)
  590. const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
  591. .to({x: toLeft, y: 200}, 1000) // Move to (300, 200) in 1 second.
  592. .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
  593. .onUpdate(() => {
  594. // Called after tween.js updates 'coords'.
  595. // Move 'box' to the position described by 'coords' with a CSS translation.
  596. document.getElementById('menu').scrollLeft = coords.x
  597. })
  598. .start() // Start the tween immediately.
  599. i = nodess.length
  600. }
  601. }
  602. }
  603. }
  604. function arrowRight(){
  605. if(house.mode==='full'){
  606. }else if(house.mode==='menu'){
  607. let pano_select = -1
  608. const nodess = document.getElementById("menu").childNodes;
  609. for(let i =0;i<nodess.length-1;i++){
  610. if(nodess[i].className==='panoSelect'){
  611. pano_select=nodess.length-2===i?0:i+1
  612. // document.getElementById('menu').scrollLeft =270*pano_select;
  613. const fromLeft = document.getElementById('menu').scrollLeft
  614. const toLeft = 270*pano_select;
  615. const coords = {x: fromLeft, y: 0} // Start at (0, 0)
  616. const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
  617. .to({x: toLeft, y: 200}, 1000) // Move to (300, 200) in 1 second.
  618. .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
  619. .onUpdate(() => {
  620. // Called after tween.js updates 'coords'.
  621. // Move 'box' to the position described by 'coords' with a CSS translation.
  622. document.getElementById('menu').scrollLeft = coords.x
  623. })
  624. .start() // Start the tween immediately.
  625. nodess[i].className = 'pano'
  626. nodess[pano_select].className = 'panoSelect'
  627. i = nodess.length
  628. }
  629. }
  630. }
  631. }
  632. window.onMenuEvent= function(){
  633. changeMode()
  634. // if(model==='full'){
  635. // }else if(model==='menu'){
  636. // }
  637. }
  638. function onKeyUp(e){
  639. // if(key_down_frequency<LONG_PRESS_TIMES){
  640. // }
  641. // key_down_frequency = 0
  642. }
  643. function onPointerStart(event) {
  644. // isUserInteracting = true;
  645. // if(is_pc){
  646. // // pauseEvent(event)
  647. // }
  648. // var clientX = event.clientX || event.touches[0].clientX;
  649. // var clientY = event.clientY || event.touches[0].clientY;
  650. // onMouseDownMouseX = clientX;
  651. // onMouseDownMouseY = clientY;
  652. // onMouseDownLon = lon;
  653. // onMouseDownLat = lat;
  654. }
  655. function onPointerMove(event) {
  656. // if (isUserInteracting === true) {
  657. // var clientX = event.clientX || (typeof(event.touches)!=='undefined'?event.touches[0].clientX:0);
  658. // var clientY = event.clientY || (typeof(event.touches)!=='undefined'?event.touches[0].clientY:0);
  659. // // lon = (onMouseDownMouseX - clientX) * 0.1 + onMouseDownLon;
  660. // // lat = (clientY - onMouseDownMouseY) * 0.1 + onMouseDownLat;
  661. // if(model==='full'){
  662. // lon = (onMouseDownMouseX - clientX) * 0.075 + onMouseDownLon;
  663. // lat = (clientY - onMouseDownMouseY) * 0.075 + onMouseDownLat;
  664. // }else if(model==='menu'){
  665. // const deltaX = (onMouseDownMouseX - clientX) * 0.031
  666. // const fromLeft = document.getElementById('menu').scrollLeft
  667. // const toLeft = fromLeft + deltaX
  668. // document.getElementById('menu').scrollLeft = toLeft
  669. // }
  670. // }
  671. }
  672. function onPointerUp() {
  673. // isUserInteracting = false;
  674. // mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
  675. // mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
  676. // onRay()
  677. }
  678. function onRay() {
  679. // update the picking ray with the camera and mouse position
  680. // raycaster.setFromCamera( mouse, camera );
  681. // // calculate objects intersecting the picking ray
  682. // const intersects = raycaster.intersectObjects( scene.children );
  683. // if(intersects.length>0){
  684. // // console.log(intersects[0])
  685. // }
  686. }
  687. function onDocumentMouseWheel(event) {
  688. // var fov = camera.fov + event.deltaY * 0.05;
  689. // camera.fov = THREE.MathUtils.clamp(fov, 15, 75);
  690. // camera.updateProjectionMatrix();
  691. }
  692. function IsPC(){
  693. var userAgentInfo = navigator.userAgent;
  694. var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
  695. var flag = true;
  696. for (var v = 0; v < Agents.length; v++) {
  697. if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }
  698. }
  699. return flag;
  700. }
  701. //------------------------------------------
  702. function walkOn(d){
  703. // // const arr = ['F','B','L','R']
  704. // let next_d = d
  705. // if(typeof(d) == 'string'){
  706. // for(let dd of house.src[house.idx].direction){
  707. // if(dd.name===d){
  708. // next_d = dd
  709. // break
  710. // }
  711. // }
  712. // }
  713. // const nextId = next_d
  714. // if(nextId&&!house.isLoading){
  715. // const idx = getIdxFromId(nextId.id)
  716. // // changeTexture(idx)
  717. // preChangeTexture(idx)
  718. // }else{
  719. // moveNull()
  720. // }
  721. }
  722. //------------------------------------------------------
  723. function preChangeTexture(idx){
  724. // if(idx>=0){
  725. // for(let i=spotGroup.children.length-1;i>=0;i--){
  726. // spotGroup.remove(spotGroup.children[i])
  727. // }
  728. // house.numLoaded = 0
  729. // house.isLoading = true
  730. // // document.getElementById('tip').style.display = 'flex'
  731. // preUpdateFaceTexture(idx,'f')
  732. // preUpdateFaceTexture(idx,'b')
  733. // preUpdateFaceTexture(idx,'l')
  734. // preUpdateFaceTexture(idx,'r')
  735. // preUpdateFaceTexture(idx,'u')
  736. // preUpdateFaceTexture(idx,'d')
  737. // }
  738. }
  739. function preUpdateFaceTexture(idx, face){
  740. // const imgPath = house.src[idx].name +"1k_"+face+'.jpg'
  741. // // load a resource
  742. // loader.load(
  743. // // resource URL
  744. // imgPath,
  745. // // onLoad callback
  746. // function ( texture ) {
  747. // house.numLoaded++
  748. // updateFaceMaterial(texture,face)
  749. // if(house.numLoaded===mesh.material.length){
  750. // house.numLoaded = 0
  751. // // updateFaceCamera(texture,idx,face)
  752. // // changeTexture(idx)
  753. // changeTexture2k(idx)
  754. // }
  755. // },
  756. // // onProgress callback currently not supported
  757. // undefined,
  758. // // onError callback
  759. // function ( err ) {
  760. // console.error( 'An error happened.' );
  761. // }
  762. // );
  763. }
  764. function changeTexture2k(idx){
  765. // for(let i=spotGroup.children.length-1;i>=0;i--){
  766. // spotGroup.remove(spotGroup.children[i])
  767. // }
  768. // house.numLoaded = 0
  769. // house.isLoading = true
  770. // // document.getElementById('tip').style.display = 'flex'
  771. // updateFaceTexture2k(idx,'f')
  772. // updateFaceTexture2k(idx,'b')
  773. // updateFaceTexture2k(idx,'l')
  774. // updateFaceTexture2k(idx,'r')
  775. // updateFaceTexture2k(idx,'u')
  776. // updateFaceTexture2k(idx,'d')
  777. }
  778. function updateFaceTexture2k(idx, face){
  779. // const imgPath = house.src[idx].name +"2k_"+face+'.jpg'
  780. // // load a resource
  781. // loader.load(
  782. // // resource URL
  783. // imgPath,
  784. // // onLoad callback
  785. // function ( texture ) {
  786. // house.numLoaded++
  787. // updateFaceMaterial(texture,face)
  788. // if(house.numLoaded===mesh.material.length){
  789. // house.numLoaded=0
  790. // // updateFaceCamera(texture,idx,face)
  791. // changeTexture(idx)
  792. // }
  793. // },
  794. // // onProgress callback currently not supported
  795. // undefined,
  796. // // onError callback
  797. // function ( err ) {
  798. // console.error( 'An error happened.' );
  799. // }
  800. // );
  801. }
  802. function changeTexture(idx){
  803. // for(let i=spotGroup.children.length-1;i>=0;i--){
  804. // spotGroup.remove(spotGroup.children[i])
  805. // }
  806. // house.numLoaded = 0
  807. // house.isLoading = true
  808. // // document.getElementById('tip').style.display = 'flex'
  809. // updateFaceTexture(idx,'f')
  810. // updateFaceTexture(idx,'b')
  811. // updateFaceTexture(idx,'l')
  812. // updateFaceTexture(idx,'r')
  813. // updateFaceTexture(idx,'u')
  814. // updateFaceTexture(idx,'d')
  815. }
  816. function updateFaceTexture(idx, face){
  817. // const imgPath = house.src[idx].name +"8k_"+face+'.jpg'
  818. // // load a resource
  819. // loader.load(
  820. // // resource URL
  821. // imgPath,
  822. // // onLoad callback
  823. // function ( texture ) {
  824. // house.numLoaded++
  825. // updateFaceMaterial(texture,face)
  826. // if(house.numLoaded===mesh.material.length){
  827. // updateFaceCamera(texture,idx,face)
  828. // }
  829. // },
  830. // // onProgress callback currently not supported
  831. // undefined,
  832. // // onError callback
  833. // function ( err ) {
  834. // console.error( 'An error happened.' );
  835. // }
  836. // );
  837. }
  838. function updateFaceMaterial(texture,face){
  839. // for(let i=0;i<mesh.material.length;i++){
  840. // if(mesh.material[i].name===face){
  841. // mesh.material[i].map.dispose()
  842. // mesh.material[i].map = texture
  843. // mesh.material[i].map.needsUpdate = true;
  844. // i=mesh.material.length
  845. // }
  846. // }
  847. }
  848. function range360(a){
  849. while(a>180){
  850. a -=360
  851. }
  852. while(a<-180){
  853. a +=360
  854. }
  855. return a
  856. }
  857. function moveNull(){
  858. // const coords = {x: camera.fov, y: 0} // Start at (0, 0)
  859. // const fov = camera.fov-5
  860. // const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
  861. // .to({x:fov,y:0}, 400) // Move to (300, 200) in 1 second.
  862. // .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
  863. // .onUpdate((e,t) => {
  864. // camera.fov = coords.x
  865. // camera.updateProjectionMatrix();
  866. // })
  867. // .onComplete(()=>{
  868. // moveNullBack()
  869. // })
  870. // .start() // Start the tween immediately.
  871. }
  872. function moveNullBack(){
  873. // lookZoom(5,400)
  874. }
  875. function lookZoom(z=5,t=600){
  876. // const fromX = camera.fov
  877. // const coords = {x: fromX, y: 0} // Start at (0, 0)
  878. // const toX = camera.fov + z
  879. // const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
  880. // .to({x:toX,y:0}, t) // Move to (300, 200) in 1 second.
  881. // .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
  882. // .onUpdate((e,t) => {
  883. // camera.fov = coords.x
  884. // camera.updateProjectionMatrix();
  885. // })
  886. // .start() // Start the tween immediately.
  887. }
  888. // direction 1/up 2/down 3/left 4/right
  889. function lookDirection(d=1){
  890. // const fromX = d===1||d===2?lat:lon
  891. // const coords = {x: fromX, y: 0} // Start at (0, 0)
  892. // const toX = d===1?lat-house.config.lat_step:d===2?lat+house.config.lat_step:d===3?lon-house.config.lon_step:lon+house.config.lon_step
  893. // const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
  894. // .to({x:toX,y:0}, 600) // Move to (300, 200) in 1 second.
  895. // .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
  896. // .onUpdate((e,t) => {
  897. // if(d===1||d===2){
  898. // lat = coords.x
  899. // }else{
  900. // lon = coords.x
  901. // }
  902. // })
  903. // .start() // Start the tween immediately.
  904. }
  905. function updateMapPoint(){
  906. // const idx = house.idx
  907. // let id = -1
  908. // var points=document.getElementById("redPoints");
  909. // while (points.firstChild) {
  910. // points.removeChild(points.firstChild);
  911. // }
  912. // // points.remove();
  913. // if(house.src[idx].D1){
  914. // id = house.src[idx].D1.id - 1
  915. // createMapPoint(id)
  916. // }
  917. // if(house.src[idx].D2){
  918. // id = house.src[idx].D2.id - 1
  919. // createMapPoint(id)
  920. // }
  921. // if(house.src[idx].D3){
  922. // id = house.src[idx].D3.id - 1
  923. // createMapPoint(id)
  924. // }
  925. // if(house.src[idx].D4){
  926. // id = house.src[idx].D4.id - 1
  927. // createMapPoint(id)
  928. // }
  929. }
  930. function createMapPoint(id){
  931. // const top = house.src[id].home.T
  932. // const right = house.src[id].home.D2
  933. // const img=document.createElement("img");
  934. // img.src="panos/redPoint.png";
  935. // img.style.position = 'absolute'
  936. // img.style.top = top +15+ 'px';
  937. // img.style.right = right-5+ 'px';
  938. // img.style.width = 8+ 'px';
  939. // img.style.height = 8+ 'px';
  940. // const points=document.getElementById("redPoints");
  941. // points.appendChild(img);
  942. }
  943. function getIdxFromId(id){
  944. let idx = -1
  945. for(const item in house.src){
  946. if(house.src[item].id===id){
  947. idx = item
  948. break
  949. }
  950. }
  951. return idx
  952. }
  953. function animate() {
  954. requestAnimationFrame(animate);
  955. TWEEN.update()
  956. // update();
  957. }
  958. function update() {
  959. // // controls.update();
  960. // if (isUserInteracting === false) {
  961. // // lon += 0.1;
  962. // }
  963. // if(house.is_auto_play){
  964. // // if(lon>360&&!house.texture.isloading){
  965. // if(lon>360&&!house.isloading){
  966. // lon = 0
  967. // // house.idx++
  968. // // if(house.idx>=house.src.length){
  969. // // house.idx = 0
  970. // // }
  971. // house.playList.idx++
  972. // if(house.playList.idx>=house.playList.orders.length){
  973. // house.playList.idx = 0
  974. // }
  975. // for(let i in house.src){
  976. // if(house.src[i].id===house.playList.orders[house.playList.idx].id){
  977. // house.idx = i
  978. // break
  979. // }
  980. // }
  981. // // house.idx = house.playList.orders[house.playList.idx].id-1
  982. // autoUpdateMaterial(house.idx)
  983. // }else{
  984. // lon += 0.2;
  985. // }
  986. // }
  987. // lat = Math.max(-85, Math.min(85, lat));
  988. // phi = THREE.MathUtils.degToRad(90 - lat);
  989. // theta = THREE.MathUtils.degToRad(lon);
  990. // camera.target.x = 512 * Math.sin(phi) * Math.cos(theta);
  991. // camera.target.y = 512 * Math.cos(phi);
  992. // camera.target.z = 512 * Math.sin(phi) * Math.sin(theta);
  993. // // updateHome()
  994. // camera.lookAt(camera.target);
  995. // renderer.render(scene, camera);
  996. }
  997. window.onBackEvent= function(){
  998. }
  999. var btn = new tvSysBtnBind({
  1000. id: "Jdoc",
  1001. className: "ctrlBtn",
  1002. currentClass: "current",
  1003. keyRemoveDefault: false,
  1004. effect: "base",
  1005. currentIndex: 0,
  1006. onLoad: function(e) {
  1007. // console.log(e);
  1008. },
  1009. onPress:function() {
  1010. var keyCode = this.event.keyCode;
  1011. // console.log('keyCode:'+keyCode)
  1012. switch (keyCode) {
  1013. case 37: // left
  1014. // reloadData();
  1015. arrowLeft()
  1016. break;
  1017. case 39: // right
  1018. arrowRight()
  1019. break;
  1020. case 38: //up
  1021. arrowUp()
  1022. break;
  1023. case 40: //down
  1024. arrowDown()
  1025. break;
  1026. // case 13: //enter
  1027. // break;
  1028. case 33: //chanel +
  1029. break;
  1030. case 34: //chanel -
  1031. break;
  1032. case 48: //0
  1033. // console.log('ddddd')
  1034. // displayMenu()
  1035. break;
  1036. case 49://1
  1037. walkingOn('F')
  1038. break
  1039. case 50://2
  1040. walkingOn('B')
  1041. break
  1042. case 51://3
  1043. walkingOn('L')
  1044. break
  1045. case 52://4
  1046. walkingOn('R')
  1047. case 52: //4
  1048. break;
  1049. case 53: //5
  1050. break;
  1051. case 54: //6
  1052. break;
  1053. case 55: //7
  1054. break;
  1055. case 57: //9
  1056. changeMode()
  1057. break;
  1058. default:
  1059. break;
  1060. }
  1061. playAudio()
  1062. },
  1063. onEnterPress: function() {
  1064. changeMode()
  1065. },
  1066. onBack: function() {
  1067. if(house.is_auto_play){
  1068. house.is_auto_play = false
  1069. }else{
  1070. if(house.mode==='menu'){
  1071. displayMenuNone()
  1072. }else{
  1073. // window.location.href="index2.html?id="+house.idx
  1074. const url = "index.html?id="+house.idx +"&backurl="+house.backurl
  1075. window.location.href = url
  1076. // VrBrowserToJS.vrBrowerExit()
  1077. }
  1078. }
  1079. }
  1080. });
  1081. //----------------------------------------------
  1082. function makeZoom(tfov){
  1083. var fov = Number( krpano.get("view.fov") );
  1084. const t_fov = tfov
  1085. // krpano.set("view.fov", fov);
  1086. console.log('fov',fov,'tfov',tfov)
  1087. const coords= {x:fov}
  1088. const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
  1089. .to({x:t_fov}, 500) // Move to (300, 200) in 1 second.
  1090. .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
  1091. .onUpdate((e,t) => {
  1092. // camera.fov = coords.x
  1093. // camera.updateProjectionMatrix();
  1094. krpano.set("view.fov", coords.x);
  1095. })
  1096. .onComplete(()=>{
  1097. })
  1098. .start() // Start the tween immediately.
  1099. }
  1100. // function zoomOut(){
  1101. // makeZoom(75)
  1102. // }
  1103. // function zoomIn(){
  1104. // makeZoom(30)
  1105. // }
  1106. function makeRotationAuto(is_auto){
  1107. krpano.set('autorotate.enabled',is_auto)
  1108. }
  1109. function changeScene(scene_name){
  1110. krpano.call("loadscene("+scene_name+",null,MERGE,BLEND(1));");
  1111. updateDirection()
  1112. changeAudio()
  1113. }
  1114. function changeMode(){
  1115. if(house.mode==='full'){
  1116. fullMode()
  1117. }else{
  1118. menuMode()
  1119. }
  1120. }
  1121. function menuMode(){
  1122. if(house.mode=='menu'){
  1123. if(house.menu_control_select==0||house.menu_control_select == -1){
  1124. displayMenuNone()
  1125. let pano_select = -1
  1126. const nodess = document.getElementById("menu").childNodes;
  1127. for(let i =0;i<nodess.length;i++){
  1128. if(nodess[i].className==='panoSelect'){
  1129. pano_select=nodess[i].getAttribute('data-id')
  1130. i = nodess.length
  1131. house.idx = pano_select
  1132. }
  1133. }
  1134. // autoUpdateMaterial(house.idx)
  1135. const scene_name = 'scene_'+house.src[house.idx].name
  1136. changeScene(scene_name)
  1137. }else if(house.menu_control_select==1){ // zoom
  1138. let zoom_title = 0
  1139. let zoom_image = 0
  1140. switch(house.zoom.status){
  1141. case 'zoom':
  1142. zoom_title = '放大'
  1143. house.zoom.status = 'x0.9'
  1144. house.zoom.direction = 1
  1145. house.zoom.factor = 1 // 1.5
  1146. zoom_image="./yaoimages/zoomin.png"
  1147. house.menu_control_select=0
  1148. break
  1149. case 'x0.9':
  1150. zoom_title = 'x1'
  1151. house.zoom.status = 'x1'
  1152. house.zoom.direction = 1
  1153. house.zoom.factor = 1 // 1.5
  1154. zoom_image="./yaoimages/zoomin_click.png"
  1155. break
  1156. case 'x1':
  1157. zoom_title = 'x1.5'
  1158. house.zoom.status = 'x1.5'
  1159. house.zoom.direction = 1
  1160. house.zoom.factor = 1.5 // 1.5
  1161. zoom_image="./yaoimages/zoomin_click.png"
  1162. break
  1163. case 'x1.5':
  1164. zoom_title = 'x2'
  1165. house.zoom.status = 'x2'
  1166. house.zoom.direction = 1
  1167. house.zoom.factor = 2
  1168. house.zoom.is_selected = false // 1
  1169. zoom_image="./yaoimages/zoomout_click.png"
  1170. break
  1171. case 'x2':
  1172. zoom_title = 'x1.5'
  1173. house.zoom.status = 'x-1.5'
  1174. house.zoom.direction = -1
  1175. house.zoom.factor = 1.5
  1176. house.zoom.is_selected = false // 1
  1177. zoom_image="./yaoimages/zoomout_click.png"
  1178. break
  1179. case 'x-1.5':
  1180. zoom_title = 'x1'
  1181. house.zoom.status = 'zoom'
  1182. house.zoom.direction = -1
  1183. house.zoom.factor = 1
  1184. house.zoom.is_selected = false // 1
  1185. zoom_image="./yaoimages/zoomout_click.png"
  1186. break
  1187. case 'x-1':
  1188. zoom_title = 'zoom'
  1189. house.zoom.status = 'zoom'
  1190. house.zoom.direction = 0
  1191. house.zoom.factor = 1
  1192. house.zoom.is_selected = false // 1
  1193. zoom_image="./yaoimages/zoomout_click.png"
  1194. break
  1195. default:
  1196. break
  1197. }
  1198. document.getElementById('zoom_title').innerHTML=zoom_title
  1199. document.getElementById('zoom').src=zoom_image
  1200. let fov = house.zoom.factor==1?120:house.zoom.factor==2?30:75
  1201. console.log('fov',fov)
  1202. makeZoom(fov)
  1203. }else if(house.menu_control_select==2){ //rotation
  1204. displayMenuNone()
  1205. house.is_auto_play = true
  1206. house.menu_control_select=0
  1207. makeRotationAuto(true)
  1208. }else{
  1209. }
  1210. }
  1211. }
  1212. function fullMode(){
  1213. if(house.is_auto_play){
  1214. house.is_auto_play = false
  1215. if(house.rotation.is_auto==true){
  1216. house.rotation.is_auto==false
  1217. document.getElementById('auto_rotation').src="./yaoimages/auto_rotation.png"
  1218. }
  1219. makeRotationAuto(false)
  1220. }
  1221. const nodess = document.getElementById("menu").childNodes;
  1222. for(let i =0;i<nodess.length-1;i++){
  1223. if(nodess[i].getAttribute('data-id')===house.idx){
  1224. nodess[i].className = 'panoSelect'
  1225. const fromLeft = document.getElementById('menu').scrollLeft
  1226. const toLeft = 270*i;
  1227. const coords = {x: fromLeft, y: 0} // Start at (0, 0)
  1228. const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
  1229. .to({x: toLeft, y: 200}, 1000) // Move to (300, 200) in 1 second.
  1230. .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
  1231. .onUpdate(() => {
  1232. // Called after tween.js updates 'coords'.
  1233. // Move 'box' to the position described by 'coords' with a CSS translation.
  1234. document.getElementById('menu').scrollLeft = coords.x
  1235. })
  1236. .start() // Start the tween immediately.
  1237. } else{
  1238. nodess[i].className = 'pano'
  1239. }
  1240. }
  1241. displayMenu()
  1242. }
  1243. function updateDirection(){
  1244. for(let d of house.src[house.idx].direction){
  1245. switch(d.name){
  1246. case 'F':
  1247. if(d.id!=null){
  1248. document.getElementById("directionTop").innerHTML = house.src[d.id-1].title
  1249. document.getElementById("direct_top").style.color = '#ffffff'
  1250. document.getElementById("direct_top_img").src = './yaoimages/direction_top.png'
  1251. }else{
  1252. document.getElementById("directionTop").innerHTML = ''
  1253. document.getElementById("direct_top").style.color = '#c1c1c1'
  1254. document.getElementById("direct_top_img").src = './yaoimages/direction_top_disable.png'
  1255. }
  1256. break
  1257. case 'B':
  1258. if(d.id!=null){
  1259. document.getElementById("directionLeft").innerHTML = house.src[d.id-1].title
  1260. document.getElementById("direct_left").style.color = '#ffffff'
  1261. document.getElementById("direct_left_img").src = './yaoimages/direction_left.png'
  1262. }else{
  1263. document.getElementById("directionLeft").innerHTML = ''
  1264. document.getElementById("direct_left").style.color = '#c1c1c1'
  1265. document.getElementById("direct_left_img").src = './yaoimages/direction_left_disable.png'
  1266. }
  1267. break
  1268. case 'L':
  1269. if(d.id!=null){
  1270. document.getElementById("directionBottom").innerHTML = house.src[d.id-1].title
  1271. document.getElementById("direct_bottom").style.color = '#ffffff'
  1272. document.getElementById("direct_bottom_img").src = './yaoimages/direction_bottom.png'
  1273. }else{
  1274. document.getElementById("directionBottom").innerHTML = ''
  1275. document.getElementById("direct_bottom").style.color = '#c1c1c1'
  1276. document.getElementById("direct_bottom_img").src = './yaoimages/direction_bottom_disable.png'
  1277. }
  1278. break
  1279. case 'R':
  1280. if(d.id!=null){
  1281. document.getElementById("directionRight").innerHTML = house.src[d.id-1].title
  1282. document.getElementById("direct_right").style.color = '#ffffff'
  1283. document.getElementById("direct_right_img").src = './yaoimages/direction_right.png'
  1284. }else{
  1285. document.getElementById("directionRight").innerHTML = ''
  1286. document.getElementById("direct_right").style.color = '#c1c1c1'
  1287. document.getElementById("direct_right_img").src = './yaoimages/direction_right_disable.png'
  1288. }
  1289. break
  1290. default:
  1291. break
  1292. }
  1293. }
  1294. // }
  1295. }
  1296. function walkingOn(d){
  1297. let next_d = d
  1298. if(typeof(d) == 'string'){
  1299. for(let dd of house.src[house.idx].direction){
  1300. if(dd.name===d){
  1301. next_d = dd
  1302. break
  1303. }
  1304. }
  1305. }
  1306. if(next_d&&typeof(next_d.id)!='undefined'&&next_d.id){
  1307. house.idx = next_d.id - 1
  1308. const scene_name = 'scene_' + house.src[house.idx].name
  1309. changeScene(scene_name)
  1310. }else{
  1311. console.log('no walking')
  1312. }
  1313. }
  1314. function changeAudio(){
  1315. const bgAudio = document.getElementById('bgAudio')
  1316. switch(house.src[house.idx].name){
  1317. case 'fangmingqingguqiao':
  1318. bgAudio.src="./audio/fangmingqingshigongqiao.mp3"
  1319. break
  1320. case 'chengshicitang':
  1321. bgAudio.src="./audio/chenshizongci.mp3"
  1322. break
  1323. default:
  1324. bgAudio.src="./audio/bg.mp3"
  1325. break
  1326. }
  1327. }
  1328. function playAudio(){
  1329. const bgAudio = document.getElementById('bgAudio')
  1330. if(bgAudio.paused){
  1331. bgAudio.play()
  1332. }
  1333. }