edit.js 170 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051
  1. /* var ceshi = '';
  2. // var ceshi = 'http://192.168.0.135:8105';
  3. // var ceshi = 'http://47.107.252.54:8105';
  4. // var token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsInJvbGUiOm51bGwsIm1hbmFnZXIiOm51bGwsImlkIjoxLCJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNTk2NzAxNjAyLCJpYXQiOjE1OTY2MTUyMDIsImp0aSI6Ijk0YjA5YTg1LWViY2ItNDE1Yy04OGVmLWU0MDM1M2UzYmIxYyJ9.Uzi95n0kYXp7bdpY77MdLtTpPL_Fq-jn0tE7gjg6AzA"
  5. var token = window.localStorage.dcj_token
  6. */
  7. var _musicMaxWeight = 8
  8. //M
  9. var cmp = getQueryVariable('cmp') || ''
  10. var _hotNum = 0
  11. function reData(data, type) {
  12. return JSON.stringify(data) == type ? null : data
  13. }
  14. //新编辑界面
  15. var EditTools = function(n) {
  16. //main2018 里面的主要对象
  17. this.n = n;
  18. //当前状态
  19. this.atPanel = null;
  20. //场景信息
  21. this.sceneInformation = new SceneInformation();
  22. //热点
  23. this.hotpoint = new Hotpoint();
  24. //导览
  25. this.editGuide = new EditGuide();
  26. //音乐
  27. this.editMiuse = new EditMiuse();
  28. //初始化界面
  29. //this.init();
  30. this.data = {}
  31. }
  32. EditTools.prototype.loadDone = function(name, data){
  33. this.data[name] = data
  34. if('data' in this.data && 'data2' in this.data){
  35. this.init();
  36. }
  37. }
  38. EditTools.prototype.init = function() {
  39. this.hotpoint.init(/* this.n */);
  40. var that = this;
  41. this.initSaveAll();
  42. this.active();
  43. if(player.mode != 'panorama'){
  44. $(".toolLeft li[data-name=panoVisible]").addClass('unable')
  45. player.once("pano.chosen",()=>{
  46. $(".toolLeft li[data-name=panoVisible]").removeClass('unable')
  47. })
  48. }
  49. that.hotpoint.initTexSelect( this.data.data2.hots);
  50. //创建导览
  51. that.editMiuse.init(this.data.data);
  52. that.sceneInformation.init(this.data.data, this.data.data2)
  53. // fyz 初始化导览需要两部分数据, 其中data2为data.js中的数据
  54. that.editGuide.init(this.data.data, this.data.data2);
  55. $("body").on("click", function() {
  56. $(".DelConfirm").removeClass("active");
  57. })
  58. $(" .MenuOptions li").on("click", (e)=>{
  59. var $elem = $(e.target);
  60. $elem.closest('.MenuOptions').find('li').removeClass("chosen");
  61. $elem.addClass("chosen");
  62. })
  63. }
  64. //点击的时候激活状态
  65. EditTools.prototype.active = function() {
  66. var that = this;
  67. var confirmSnap = $(".confirmSnap.innerBtn");
  68. var snapshotGui = $(".snapshotGui.overlayGui");
  69. $('.toolBottom .toolLeft li').click(function() {
  70. var name = $(this).data("name");
  71. $('.toolLeft li[data-name=' + name + ']').addClass("active").siblings().removeClass("active");
  72. $('.toolRight .' + name).removeClass("hide").siblings().addClass("hide");
  73. if (name == that.atPanel)
  74. return;
  75. console.log(`atPanel ${that.atPanel} name ${name}`)
  76. switch (that.atPanel) {
  77. //退出
  78. case "panoVisible":
  79. VisiSet.finishSetPanoVisible()
  80. break;
  81. case "panoLog":
  82. VisiSet.finishSetPanoLog()
  83. break;
  84. case "screen":
  85. confirmSnap.addClass("hide").removeClass("unable");
  86. snapshotGui.hide();
  87. break;
  88. case "overlay":
  89. EditOverlay.leave()
  90. break;
  91. case "hotpoint":
  92. $("#hotpointDetail").hasClass("atRight") || $("#hotpointDetail a.close").click();
  93. VisiSet.finishSetTagVisible()
  94. break;
  95. }
  96. switch (name) {
  97. case "panoVisible":
  98. $(".toolLeft").addClass("unable")
  99. VisiSet.enterSet(VisiSet.beginSetPanoVisible.bind(VisiSet))
  100. break;
  101. case "panoLog":
  102. $(".toolLeft").addClass("unable")
  103. VisiSet.enterSet(VisiSet.beginSetPanoLog.bind(VisiSet))
  104. break;
  105. case "screen":
  106. confirmSnap.removeClass("hide");
  107. $('#camera-start').text("点此设置为初始画面")
  108. snapshotGui.show();
  109. if (player.modeTran.split("-")[1] != "panorama")
  110. $(".confirmSnap").addClass("unable")
  111. break;
  112. case "overlay":
  113. EditOverlay.enter()
  114. break;
  115. }
  116. that.atPanel = name;
  117. /* if(name != "hotpoint"){
  118. $("#hotpointDetail").hasClass("atRight") || $("#hotpointDetail a.close").click()
  119. } */
  120. })
  121. //滚动阻止事件
  122. $(".toolRight div.content").on("mousewheel", function(event) {
  123. event.stopPropagation()
  124. });
  125. // 输入框阻止事件
  126. $('.toolRight').on('keydown', function(ev) {
  127. ev.stopPropagation();
  128. })
  129. }
  130. //保存按钮
  131. EditTools.prototype.initSaveAll = function() {
  132. var that = this;
  133. $('#save').on('click', function() {
  134. $(".edit-loading").removeClass("hide");
  135. var $shareImages = $(".information .edit-fun-images a.result");
  136. new Promise(function(resolve, reject) {//分享图
  137. upload($shareImages, 'images', resolve)
  138. }).then(function(imgUrls) {
  139. //导览的数据
  140. var guides = that.editGuide.getSavingInfo()/* Array.from($('.tourFolderList ul li')).map(function(dom) {
  141. return dom.data
  142. }) */
  143. var hots = {}
  144. // 热点数据
  145. var hotLength = 0;
  146. for (let i in player.model.hots) {
  147. let hot = player.model.hots[i];
  148. let hotData = {
  149. position: {
  150. x: toPrecision(hot.position.x, 3),
  151. y: toPrecision(hot.position.y, 3),
  152. z: toPrecision(hot.position.z, 3),
  153. },
  154. //有的定制场景代码是旧的,只能使用rotation,所以不输出quaternion :
  155. rotation: new THREE.Euler().setFromQuaternion(hot.quaternion).toObject(),
  156. isSprite: hot.isSprite ? 1 : 0,
  157. noAction: hot.noAction ? 1 : 0,
  158. linkType: hot.linkType,
  159. actionType: hot.actionType,
  160. infoAttribute: hot.infoAttribute,
  161. order: hotLength++//因为热点保存后在hots里的顺序会被修改,所以使用order来记录顺序
  162. }
  163. if (hot.visiblePanos)
  164. hotData.visiblePanos = hot.visiblePanos
  165. if (hot.hotIconScale)
  166. hotData.hotIconScale = hot.hotIconScale
  167. hotData.transformAtPanos = {}
  168. for(let i in hot.transformAtPanos){
  169. hotData.transformAtPanos[i] = {
  170. pos : toPrecision(hot.transformAtPanos[i].pos.toArray(), 3),
  171. }
  172. if(hot.transformAtPanos[i].qua){
  173. hotData.transformAtPanos[i].qua = toPrecision(hot.transformAtPanos[i].qua.toArray(), 5)
  174. }
  175. }
  176. if (hot.infoAttribute) {
  177. delete hot.infoAttribute.position;
  178. delete hot.infoAttribute.quaternion;
  179. delete hot.infoAttribute.rotation;
  180. delete hot.infoAttribute.transformAtPanos
  181. }
  182. hots[i] = hotData
  183. }
  184. var info = {
  185. name: $('#pjtName').val(),
  186. summary: $('#info-summary').val(),
  187. weixinDesc: $('#weixin-summary').val(),
  188. shareImgUrl: imgUrls[0] || '',
  189. backgroundMusic: $('#query-bgm').attr('href'),
  190. bgName: $(".music .audio.mediaUpload .title").text(),
  191. hoticon: JSON.parse($(".hotStyle-item li.active").attr("data-val")),
  192. camera_start: $('#camera-start')[0].data,
  193. loadlogo: $("#loadlogo").is(':checked'),
  194. special: $("#g_specialScene").is(':checked'),
  195. vision_version: $("#twoData").is(':checked') ? "1.1.562.17209" : false,
  196. /************************************** 方奕卓 场景可配置项 ******************************************/
  197. hotImageScale: $("#hotImgScale").is(':checked'),
  198. // 热点图片可放大
  199. hideFloorMarker: $("#hideFloorMarker").is(':checked'),
  200. // 地面标记
  201. hideMouseMarker: $("#hideMouseMarker").is(':checked'),
  202. // 鼠标标记
  203. floorMarkerColor: $('#floorMarkerColor').val(),
  204. // 地面/导览标志颜色
  205. mouseMarkerColor: $('#mouseMarkerColor').val(),
  206. // 鼠标标志颜色
  207. momentTour: $('#tourSwitch input').is(':checked') ? 'black' : 'walk',
  208. // 导览瞬间过渡
  209. showHotListSta: $('#hotListSwitch input').is(':checked'),
  210. // 开启热点列表
  211. hotIconScale: $('#hotIconScale input').val(),
  212. // 热点缩放
  213. supportsVR: $('#VRSwitch input').is(':checked'),
  214. // 开启VR功能
  215. /**************** 陈志广 小地图可配置项 *********** */
  216. cadSignColor: $('#cadSignColor').val(),
  217. cadBorderColor: $('#cadBorderColor').val(),
  218. cadBorderWidth: $('#cad-size').val(),
  219. showCad: $('input[name="show-cad"]').is(':checked'),
  220. }
  221. var overlayInfo = []
  222. player.overlayGroup.children.forEach((overlay)=>{
  223. var info = EditOverlay.getSavingInfo(overlay)
  224. if (info)
  225. overlayInfo.push(info);
  226. }
  227. )
  228. /* console.log("保存数据");
  229. console.log({
  230. guides: reData(guides, '[]'),
  231. info: info,
  232. })
  233. console.log(JSON.stringify(guides) )
  234. debugger; */
  235. let url = cmp ? ('/api/scene/edit/' + cmp) : '/manage/scene/edit'
  236. $.ajax({
  237. method: 'POST',
  238. headers: {
  239. 'Content-Type': 'application/json',
  240. token: token
  241. },
  242. dataType: 'json',
  243. contentType: 'application/json',
  244. url: ceshi + url,
  245. data: JSON.stringify({
  246. sceneCode: number,
  247. hots: reData(hots, '{}'),
  248. name: number,
  249. guides: reData(guides, '[]'),
  250. info: info,
  251. //tourAudio: reData(that.editGuide.getTourAudio(), '{}'),
  252. overlays: reData(overlayInfo, '[]')
  253. }),
  254. success: function(data) {
  255. if (data.code === 0) {
  256. location.reload()
  257. }
  258. if (data.code === 5001) {
  259. alert('请重新登录')
  260. localStorage.dcj_token = ''
  261. location.reload()
  262. }
  263. }
  264. })
  265. });
  266. })
  267. }
  268. //场景信息编辑
  269. var SceneInformation = function() {}
  270. SceneInformation.prototype.init = function(data, data2) {
  271. var $options = $('.hotStyle-item li');
  272. var $loadlogo = $("#loadlogo");
  273. var $hotImageScale = $("#hotImgScale");
  274. var $hideFloorMarker = $("#hideFloorMarker");
  275. var $hideMouseMarker = $("#hideMouseMarker");
  276. var $g_specialScene = $("#g_specialScene");
  277. var $twoData = $("#twoData");
  278. /*******************方奕卓 其他项需要用到data来初始化, 故一并放到这里 ******************/
  279. let momentTour = $('#tourSwitch input');
  280. // 导览瞬间过渡开关
  281. let hotListSwitch = $('#hotListSwitch input');
  282. // 热点列表开关
  283. let hotIconScale = $('#hotIconScale input');
  284. // 热点图标缩放
  285. let VRSwitch = $('#VRSwitch input');
  286. // VR功能开启
  287. /***********************************************************************************/
  288. $(".model-title2").text(data.name);
  289. $('#pjtName').val(data.name);
  290. $('#info-summary').val(data.summary);
  291. //if (data2) $('#weixin-summary').val(data2.weixinDesc);
  292. $('#weixin-summary').val(data.weixinDesc);
  293. for (var i = 0; i < $options.length; i++) {
  294. if ($options.eq(i).attr('data-val') === JSON.stringify(data.hoticon)) {
  295. $options.eq(i).addClass("active").siblings().removeClass("active");
  296. }
  297. }
  298. $('#camera-start')[0].data = data.camera_start;
  299. $(".shotImg.innerBtn").on("click", ()=>{
  300. var EntryInfo = $('#camera-start')[0].data
  301. if (EntryInfo) {
  302. var to = player.model.panos.get(EntryInfo.pano.uuid);
  303. var q = new THREE.Quaternion().fromArray(EntryInfo.camera.quaternion);
  304. var lookAtPoint = new THREE.Vector3(0,0,-1).applyQuaternion(q).add(to.position);
  305. player.flyToPano({
  306. pano: to,
  307. lookAtPoint: lookAtPoint
  308. })
  309. }
  310. }
  311. )
  312. if(data.shareImgUrl){
  313. var imagesHTML = '<div><a class=" result success"><span></span><img src="' + data.shareImgUrl + '"></a></div>'
  314. $(".information .edit-fun-images.list ").html(imagesHTML);
  315. $("#shareImgUpload").addClass("hide")
  316. }
  317. if(data.spotImgUrl){
  318. }
  319. /*************方奕卓 其他项的初始化操作 ************/
  320. initColorElem(data);
  321. addListener();
  322. // 给其他元素绑定事件
  323. if (data.momentTour === 'black') {
  324. momentTour.prop('checked', true);
  325. }
  326. if (data.showHotListSta) {
  327. hotListSwitch.prop('checked', true);
  328. }
  329. if (data.hotIconScale) {
  330. hotIconScale.val(parseFloat(data.hotIconScale));
  331. }
  332. hotIconScale.on('change',(e)=>{
  333. var s = THREE.Math.clamp(parseFloat(e.target.value), 0.1, 1.5)
  334. e.target.value = s
  335. for(let i in player.model.hots){
  336. if(!player.model.hots[i].hotIconScale){
  337. player.model.hots[i].mesh.scale.set(s,s,s)
  338. }
  339. }
  340. })
  341. $('#hotIconScale_2 input').on('change',(e)=>{
  342. var s = THREE.Math.clamp(parseFloat(e.target.value), 0.1, 1.5)
  343. e.target.value = s
  344. editTool.hotpoint.editSpot.mesh.scale.set(s,s,s)
  345. })
  346. if (data.supportsVR) {
  347. VRSwitch.prop('checked', true);
  348. }
  349. /************************************************/
  350. //隐藏公司logo
  351. if (data.loadlogo) {
  352. $loadlogo[0].checked = true
  353. showLogo();
  354. }
  355. // 热点图片放大
  356. if (data.hotImageScale) {
  357. $hotImageScale[0].checked = true
  358. }
  359. // 隐藏地面标记
  360. if (data.hideFloorMarker) {
  361. $hideFloorMarker[0].checked = true
  362. }
  363. // 隐藏鼠标标记
  364. if (data.hideMouseMarker) {
  365. $hideMouseMarker[0].checked = true
  366. }
  367. //特殊大场景
  368. if (data.special) {
  369. $g_specialScene[0].checked = true
  370. }
  371. //启动二代的数据
  372. if (data.vision_version === "1.1.562.17209" || data.vision_version) {
  373. $twoData[0].checked = true
  374. }
  375. }
  376. /**
  377. * 初始化颜色选择的html元素
  378. * @param {*} data
  379. * @param {*} elem
  380. */
  381. function initColorElem(data, elem) {
  382. let $floorMarkerColor = $('#floorMarkerColor');
  383. let $mouseMarkerColor = $('#mouseMarkerColor');
  384. let $floorMarkerColorTex = $('#floorMarkerColorTex');
  385. let $mouseMarkerColorTex = $('#mouseMarkerColorTex');
  386. let $cadSignColor = $('#cadSignColor');
  387. let $cadSignColorTex = $('#cadSignColorTex');
  388. let $cadBorderColor = $('#cadBorderColor');
  389. let $cadBorderColorTex = $('#cadBorderColorTex');
  390. var colorRe = /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/;
  391. // 事件监听
  392. $floorMarkerColor.on('change', function(e) {
  393. $('#floorMarkerColorTex').attr('placeholder', e.target.value)
  394. })
  395. $floorMarkerColorTex.on('blur keydown', function(e) {
  396. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $floorMarkerColor, this);
  397. })
  398. $mouseMarkerColor.on('change', function(e) {
  399. $('#mouseMarkerColorTex').attr('placeholder', e.target.value)
  400. })
  401. $mouseMarkerColorTex.on('blur keydown', function(e) {
  402. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $mouseMarkerColor, this);
  403. })
  404. // 事件监听
  405. $cadSignColor.on('change', function(e) {
  406. $('#cadSignColorTex').attr('placeholder', e.target.value)
  407. })
  408. $cadSignColorTex.on('blur keydown', function(e) {
  409. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $cadSignColor, this);
  410. })
  411. // 事件监听
  412. $cadBorderColor.on('change', function(e) {
  413. $('#cadBorderColorTex').attr('placeholder', e.target.value)
  414. })
  415. $cadBorderColorTex.on('blur keydown', function(e) {
  416. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $cadBorderColor, this);
  417. })
  418. // 设置颜色值
  419. function setColor(e, colorElem, inputElem) {
  420. var isColor = colorRe.test(e.target.value);
  421. isColor && colorElem.val(e.target.value);
  422. // isColor ? colorElem.val(e.target.value): (inputElem.placeholder = colorElem.val());
  423. }
  424. // 判断data中是否有存在的颜色值, 否则设置默认值
  425. data.floorMarkerColor ? $floorMarkerColor.val(data.floorMarkerColor) : $floorMarkerColor.val('#4bcdfc');
  426. data.mouseMarkerColor ? $mouseMarkerColor.val(data.mouseMarkerColor) : $mouseMarkerColor.val('#4bcdfc');
  427. // 判断data中是否有存在的颜色值, 否则设置默认值
  428. data.cadSignColor ? $cadSignColor.val(data.cadSignColor) : $cadSignColor.val('#00c8af');
  429. data.cadBorderColor ? $cadBorderColor.val(data.cadBorderColor) : $cadBorderColor.val('#ffffff');
  430. $('input[name="show-cad"]')[0].checked = !!data.showCad
  431. $('#cad-size > option[value="'+(data.cadBorderWidth ? data.cadBorderWidth : '0.01')+'"]').attr("selected",true);
  432. if (data.showCad) {
  433. $('input[name="show-cad"]').trigger('change')
  434. }
  435. $('#panoIdColor').on('change', function(e) {
  436. $('#panoIdColorTex').val(e.target.value)
  437. VisiSet.changePanoIdColor(e.target.value)
  438. })
  439. $('#panoIdColorTex').on('blur keydown', function(e) {
  440. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $('#panoIdColor'), this);
  441. VisiSet.changePanoIdColor(e.target.value)
  442. })
  443. $('#panoIdColor').val('#c13e3e')//初始颜色
  444. $('#panoIdColorTex').val('#c13e3e')
  445. }
  446. $('input[name="show-cad"]').on('change', function(ev) {
  447. if (!ev.target.checked) {
  448. return $('.cad').hide()
  449. }
  450. let taht = this
  451. if (!taht.floorJSON) {
  452. $.ajax({
  453. url: '//super.4dage.com/data/'+ window.number +'/floor.json',
  454. method: 'GET',
  455. success(res) {
  456. taht.floorJSON = res
  457. loadCAD(taht.floorJSON)
  458. $('#cadSignColor').on('change', function(ev) {
  459. loadCAD()
  460. })
  461. $('#cadBorderColor').on('change', function(ev) {
  462. loadCAD()
  463. })
  464. $('#cad-size').on('change', function(ev) {
  465. loadCAD()
  466. })
  467. },
  468. error() {
  469. alert('当前场景没有小地图floor.json文件,请联系三维部门添加')
  470. ev.target.checked = false
  471. }
  472. })
  473. } else {
  474. console.log('0000000000000000000')
  475. $('.cad').show()
  476. }
  477. })
  478. function loadCAD(data) {
  479. grendCAD(data, $('#player')[0], $('#cadSignColor').val(), $('#cadBorderColor').val(), $('#cad-size').val())
  480. }
  481. function addListener() {}
  482. //设置初始界面
  483. function getSeft(seft) {
  484. $('#camera-start').on('click', function() {
  485. if (VisiSet.setPanoVisible) {
  486. return VisiSet.savePanoVisibles()
  487. } else if (VisiSet.setTagVisible) {
  488. return VisiSet.saveTagVisibles()
  489. }
  490. // 这部分内容需要配合main_2018.js中来进行修改
  491. var snap = JSON.parse("{" + seft.getSnapAngleInfo() + "}")
  492. this.data = {
  493. camera: {
  494. position: snap.metadata.camera_position,
  495. quaternion: snap.metadata.camera_quaternion// 相机朝向
  496. },
  497. pano: {
  498. uuid: snap.metadata.scan_id // 起始点位的id
  499. }
  500. }
  501. var ev = document.createEvent("MouseEvent");
  502. //点击截取视图
  503. g_snapShotWidth = 240 * 4;
  504. g_snapShotHeight = 118 * 4;
  505. window.screenSta = 'startScreen';
  506. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  507. ev.__callback = (imgData,info)=>{
  508. uploadImg(imgData, (rs)=>{
  509. if (rs.code === 0) {
  510. $(".shotImg.innerBtn").css("background-image", "url(" + rs.data + ")")
  511. this.data.thumbImg = rs.data;
  512. }
  513. }
  514. , "thumbImg.jpg")
  515. }
  516. window.dispatchEvent(ev);
  517. });
  518. }
  519. //热点编辑
  520. var Hotpoint = function() {
  521. this.spotList = $(".spotList");
  522. this.hotpointDetail = $("#hotpointDetail");
  523. // fyz 导览编辑页面同样采取热点编辑的样式, 这里确保只查找到热点编辑
  524. }
  525. Hotpoint.prototype.init = function(n) {
  526. var that = this;
  527. this.active();
  528. this.addmedia();
  529. // 添加多媒体
  530. this.addMusicInit();
  531. // 添加音乐
  532. this.addModel();
  533. // 添加模型
  534. this.addwebPack();
  535. // 添加外链
  536. //this.initSaveHot();
  537. // 保存热点
  538. this.hotpointDetail.find(".tail .submit").on('click', this.saveHot.bind(this))
  539. $("#isSprite").on("change", function(e) {
  540. that.editSpot.isSprite = this.checked;
  541. if (this.checked) {
  542. that.editSpot.update(player.camera)
  543. } else {
  544. var curPanoTransform = that.editSpot.transformAtPanos[ getTransformSid()] || {}
  545. that.editSpot.mesh.quaternion.copy(curPanoTransform.qua || that.editSpot.quaternion)
  546. }
  547. })
  548. /* $("#noAction").on("change", function(e) {
  549. that.editSpot.noAction = this.checked;
  550. }) */
  551. let hotIconScale = $('#hotIconScale');
  552. //点击添加热点按钮
  553. $('#addHotSpots').on("click", function() {
  554. //点击添加热点
  555. g_HotStatus = g_HotStatus === "add" ? null : "add";
  556. $("#player").css("cursor", "cell");
  557. });
  558. //点击热点列表弹出按钮
  559. this.spotList.on("click", function(e) {
  560. var target = $(e.target);
  561. let li = searchParent(e.target, { className: 'listItem' }, 7);
  562. if(!li)return;
  563. var hotId = $(li).attr("data-spid");
  564. var hot = player.model.hots[hotId]
  565. if(VisiSet.setTagVisible){
  566. return VisiSet.SetOneTagVisible(hot)
  567. }
  568. if (target.hasClass("del")) {
  569. e.stopPropagation();
  570. target.siblings(".DelConfirm").addClass("active");
  571. that.spotList.find("i").text(that.spotList.find("ul li").length);
  572. } else {
  573. if (target.hasClass("DelConfirm")) {
  574. e.stopPropagation();
  575. that.removeHot(hot, $(li));
  576. } else {
  577. //点击热点列表弹出编辑热点窗口
  578. that.editHot(hot, $(li))
  579. }
  580. }
  581. });
  582. //点击热点编辑窗口右上角的关闭按钮
  583. this.hotpointDetail.find("a.close, button.cancel").on("click", function() {
  584. var spot_id = that.hotpointDetail.attr("data-id");
  585. var hot = player.model.hots[spot_id];
  586. //var info = hot.infoAttribute;
  587. that.styleList.recover()
  588. hot.setFromInfo()
  589. /* if (info) {
  590. info.position && hot.mesh.position.copy(info.position)
  591. info.quaternion && hot.mesh.quaternion.copy(info.quaternion)
  592. hot.isSprite = info.isSprite
  593. hot.noAction = info.noAction
  594. hot.linkOutside = info.linkOutside
  595. } */
  596. that.editSpot = null
  597. that.hotpointDetail.addClass("atRight");
  598. transformControls.detach()
  599. for(let i in player.model.hots){
  600. let hot_ = player.model.hots[i]
  601. hot_.styleImg = hot_.infoAttribute.styleImg.map((e)=>{return {src:e}});
  602. hot_.changeTex() //恢复贴图
  603. }
  604. });
  605. //创建列表
  606. for (let i in player.model.hots) {
  607. this.addHotList(player.model.hots[i]);
  608. }
  609. // 初始话的时候把热点信息添加到对应的热点中 直接使用data2.json的会怎样?
  610. /* $.ajax(g_Prefix + "data/" + window.number + "/hot/js/data.js" + "?" + Date.now(), { dataType: "json" })
  611. .then(function (infos) {
  612. that.infos = infos ;
  613. Object.keys(infos).forEach(function (key) {
  614. //sxm增加热点列表可读性,方便查看删除操作等
  615. that.spotList.find("ul li[data-spid=" + key + "]")[0] && (that.spotList.find("ul li[data-spid=" + key + "]")[0].infoAttribute = infos[key])&& (that.spotList.find("ul li[data-spid=" + key + "] .title").html(infos[key].title));
  616. })
  617. }) */
  618. $("#hotpointDetail .scale .MenuOptions li").on("click", (e)=>{ //更改大小
  619. curr = $(e.target).attr("index")
  620. if (curr == "default") {
  621. $("#userHotScale").addClass("hide")
  622. var s = parseFloat($("#hotIconScale input").val());
  623. editTool.hotpoint.editSpot.mesh.scale.set(s,s,s)
  624. } else {
  625. $("#userHotScale").removeClass("hide")
  626. var s = editTool.hotpoint.editSpot.mesh.scale.x;
  627. $('#hotIconScale_2 input').val(s)
  628. }
  629. })
  630. $("#hotpointDetail .MenuOptions[name='linkType'] li").on("click", (e)=>{ //链接打开方式切换
  631. editTool.hotpoint.editSpot.linkType = $(e.target).attr("index")
  632. $("#hotpointDetail .MenuOptions[name='linkType'] li").removeClass("chosen");
  633. $(e.target).addClass("chosen")
  634. })
  635. $("#hotpointDetail .MenuOptions[name='actionType'] li").on("click", (e)=>{ //
  636. editTool.hotpoint.editSpot.actionType = $(e.target).attr("index")
  637. $("#hotpointDetail .MenuOptions[name='actionType'] li").removeClass("chosen");
  638. $(e.target).addClass("chosen")
  639. })
  640. $('#setHotPosForPano input').on("change", ()=>{
  641. var on = $('#setHotPosForPano input').is(':checked')
  642. if(!on){
  643. delete this.editSpot.transformAtPanos[getTransformSid()]
  644. this.editSpot.mesh.position.copy(this.editSpot.position)
  645. this.editSpot.mesh.quaternion.copy(this.editSpot.quaternion)
  646. //this.editSpot.usingTransformData = false
  647. }
  648. })
  649. }
  650. Hotpoint.prototype.getTransformAtPano = function(type){
  651. var name = getTransformSid()
  652. var info = {
  653. pos : this.editSpot.mesh.position.clone()
  654. }
  655. if(!this.editSpot.isSprite){
  656. info.qua = this.editSpot.mesh.quaternion.clone()
  657. }else{
  658. if(type == 'quaternion')return; //如果恒朝向相机且调整的是quaternion,不要保存position
  659. }
  660. this.editSpot.transformAtPanos[name] = info
  661. //this.editSpot.usingTransformData = true
  662. }
  663. Hotpoint.prototype.updateTransform = function(type){
  664. var on = $('#setHotPosForPano input').is(':checked')
  665. var name = getTransformSid()
  666. if(on){
  667. this.getTransformAtPano(type)
  668. }else{
  669. if(type == 'position'){
  670. this.editSpot.position.copy(this.editSpot.mesh.position)
  671. }else if(type == 'quaternion'){
  672. if(!this.editSpot.isSprite){ //如果恒朝向相机就不保存quaternion
  673. this.editSpot.quaternion.copy(this.editSpot.mesh.quaternion)
  674. }
  675. }
  676. }
  677. }
  678. Hotpoint.prototype.updatePano = function(){
  679. if(!this.editSpot ) return;
  680. $('#setHotPosForPano input').prop('checked', !!this.editSpot.transformAtPanos[getTransformSid()]);
  681. }
  682. var ifSameTex = function(imgs0, imgs1){//是否是相同的图 (两个都是空的不算相同)
  683. return !!(imgs0[0] && imgs1[0] && imgs0[0].src == imgs1[0].src &&
  684. (imgs0[1] ? (imgs1[1] && imgs0[1].src == imgs1[1].src) : !imgs1[1] ))
  685. }
  686. Hotpoint.prototype.findSpotByImgs = (imgs=[])=>{////使用了该贴图的所有热点
  687. var spots = []
  688. for(var i in player.model.hots){
  689. var styleImg = player.model.hots[i].styleImg || [];
  690. if(ifSameTex(styleImg, imgs)){
  691. spots.push(player.model.hots[i])
  692. }
  693. }
  694. return spots
  695. }
  696. Hotpoint.prototype.initTexSelect = function(hots) {//热点样式图列表
  697. var countElem = $("<a></a>").css({"width":'40px','display': 'block', 'color':'#aeaeae', 'white-space':'break-spaces', 'line-height':'25px', 'margin-left':'10px'})
  698. var uploadInput = $('<input type="file" style="display:none" accept="image/*"></input>');
  699. var getListItem = ()=>{
  700. var elem = $('<li><ul class="hotTexUpload"><li class="upload"><div></div><a class="del hasHover"></a></li><li class="upload hide"><div></div><a class="del hasHover"></a></li></ul></li>')
  701. elem[0]._styleImg = []
  702. return elem
  703. }
  704. var editHotStyleInfo = {}
  705. var setImgContent = function($dom, index, src) {
  706. var li = $dom.find('li').eq(index)
  707. var div = li.find('>div');
  708. if (src) {
  709. li.addClass("uploaded")
  710. div.css("background-image", `url(${src})`)
  711. } else {
  712. li.removeClass("uploaded")
  713. div.css("background-image", '')
  714. }
  715. }
  716. var hotIcons = []; // 从所有热点tex中搜集
  717. for(let i in hots){
  718. let imgs = hots[i].infoAttribute.styleImg;
  719. if(imgs && imgs.length){
  720. if(!hotIcons.find(e=>e[0] == imgs[0] && e[1] == imgs[1])){
  721. hotIcons.push(imgs)
  722. }
  723. }
  724. }
  725. hotIcons = hotIcons.map(imgs=>imgs = imgs.map((a)=>{return {src:a}}))
  726. hotIcons.push([])//放末尾用来添加的
  727. var list = hotIcons.map(arr=>{//初始列表
  728. var elem = getListItem()
  729. elem[0]._styleImg = arr //每个li上绑定一个 _styleImg,存储它包含的图, 和热点的styleImg对应
  730. var divs = elem.find("li>div")
  731. arr.forEach((img,i)=>{
  732. setImgContent(elem, i, img.src)
  733. })
  734. arr.length && elem.find("li").eq(1).removeClass('hide')
  735. return elem
  736. })
  737. this.styleList = new ListBox(list, $('#spotTexSelect'), {//列表
  738. selectFun:()=>{//选中时要改变选中项selection缩略图 以及改变热点
  739. if(this.styleList.chosenItem == void 0){
  740. this.styleList.listTitle.find('li').addClass('hide')
  741. }else{
  742. this.styleList.listTitle.find('li').removeClass('hide')
  743. var divs = this.styleList.listTitle.find('li>div')//selection
  744. var imgs = this.styleList.chosenItem[0]._styleImg;
  745. if(imgs[0]){
  746. divs.eq(0).css("background-image", 'url("'+imgs[0].src+'")')
  747. divs.eq(0).parent().removeClass('hide')
  748. }else{
  749. divs.eq(0).parent().addClass('hide')
  750. }
  751. if(imgs[1]){
  752. divs.eq(1).css("background-image", 'url("'+imgs[1].src+'")')
  753. divs.eq(1).parent().removeClass('hide')
  754. }else{
  755. divs.eq(1).parent().addClass('hide')
  756. }
  757. //应用到热点:
  758. this.editSpot.changeTex(imgs)
  759. }
  760. Array.from(this.styleList.listDom.children()).forEach(li=>{//更新一下所有的li的使用的spot
  761. li.sameTexSpots = this.findSpotByImgs(li._styleImg)
  762. })
  763. },
  764. /* delFun: ()=>{
  765. }, */
  766. addFun: ($li)=>{ //列表新增时对li的操作
  767. $li[0].sameTexSpots = this.findSpotByImgs($li[0]._styleImg)
  768. $li.find('li').bind('click', (e)=>{
  769. e.stopPropagation()
  770. var index = $(e.currentTarget).index();
  771. if (e.target.classList.contains("del")) { //删除图片
  772. if ($li[0]._styleImg.length == 2 && index == 0) { //删除第一个 且有第二个的话
  773. setImgContent($li, 0, $li[0]._styleImg[1].src);
  774. setImgContent($li, 1, null);
  775. $li[0]._styleImg = [$li[0]._styleImg[1]]
  776. } else {
  777. setImgContent($li, index, null);
  778. $li[0]._styleImg.pop()
  779. if ($li[0]._styleImg.length == 0) {
  780. $li.find("li").eq(1).addClass("hide");
  781. }
  782. }
  783. $li[0].sameTexSpots.forEach(hot=>{
  784. hot.changeTex($li[0]._styleImg)
  785. })
  786. if($li.hasClass('selected')){//是当前spot的
  787. //this.editSpot.changeTex($li[0]._styleImg)
  788. this.styleList.options.selectFun()
  789. }
  790. } else {
  791. //添加图片
  792. uploadInput.click()
  793. editHotStyleInfo = {
  794. imgs : $li[0]._styleImg, index, $li
  795. };
  796. }
  797. })
  798. $li.bind('mouseover', (e)=>{
  799. this.showTitileSpots = $li[0].sameTexSpots;
  800. this.showTitileSpots.forEach(a=>a.showTitle())
  801. countElem.text("热点个数:"+this.showTitileSpots.length).removeClass('hide')
  802. $li.find("ul").append(countElem)
  803. })
  804. $li.bind('mouseout', (e)=>{
  805. this.showTitileSpots.forEach(a=>a.hideTitle())
  806. this.showTitileSpots = null;
  807. countElem.addClass('hide')
  808. })
  809. },
  810. saveTemp: (list)=>{//编辑热点时保存一份副本
  811. this._styleImgTemp = Array.from(list.listDom.children()).map((li)=>{
  812. return li._styleImg.slice()
  813. })
  814. },
  815. recover : (list)=>{//取消编辑时恢复
  816. Array.from(list.listDom.children()).forEach((li,i)=>{
  817. li._styleImg = this._styleImgTemp[i]
  818. })
  819. },
  820. })
  821. this.styleList.findChosenByImgs = (imgs=[])=>{//找到某图对应的li
  822. var list = Array.from(this.styleList.listDom.children())
  823. var item = list.find(e=>ifSameTex(e._styleImg, imgs ))
  824. return {index: item ? list.indexOf(item) : null, item: item }
  825. }
  826. this.styleList.clearVoid = ()=>{//清理空的
  827. var length = this.styleList.listDom.children().length;
  828. Array.from(this.styleList.listDom.children()).forEach((e, i)=>{
  829. if(i < length-1){
  830. if(e._styleImg.length == 0) this.styleList.removeItem($(e))
  831. }
  832. })
  833. }
  834. this.styleList.addNew = ()=>{//看是否在最后一行增加新的
  835. var lastOne = this.styleList.listDom.children().last();
  836. if(lastOne[0]._styleImg.length != 0){
  837. this.styleList.addItem(getListItem())
  838. }
  839. }
  840. uploadInput.on("change", (e)=>{
  841. inputMedia({
  842. enableTypes: ["photo"],
  843. photoDone: (resultImg)=>{
  844. editHotStyleInfo.imgs[editHotStyleInfo.index] = {file: resultImg.file, needSave:true, src:resultImg.src}//resultImg
  845. setImgContent(editHotStyleInfo.$li, editHotStyleInfo.index, resultImg.src)
  846. if (editHotStyleInfo.index == 0){
  847. editHotStyleInfo.$li.find('li').eq(1).removeClass("hide");
  848. }
  849. //resultImg.needSave = true
  850. editHotStyleInfo.$li[0].sameTexSpots.forEach(hot=>{
  851. hot.changeTex(editHotStyleInfo.$li[0]._styleImg)
  852. })
  853. if(editHotStyleInfo.$li.hasClass('selected')){//是当前spot的
  854. this.styleList.options.selectFun()//更新选中状态
  855. }
  856. this.styleList.addNew()
  857. }
  858. }, "photo", e);
  859. })
  860. $("#hotpointDetail .style .MenuOptions li").on("click", (e)=>{ //切换是默认还是自定义
  861. var currStyle = $(e.target).attr("index")
  862. if (currStyle == "default") {
  863. $("#spotTexSelect").addClass("hide")
  864. $("#hotpointDetail .style label").addClass("hide")
  865. editTool.hotpoint.editSpot.changeTex([])
  866. } else {
  867. this.styleList.options.selectFun()
  868. $("#hotpointDetail .style label").removeClass("hide")
  869. $("#spotTexSelect").removeClass("hide")
  870. }
  871. })
  872. }
  873. Hotpoint.prototype.initStyle = function(hot) { //每次开始编辑热点时更新样式
  874. if (!hot.styleImg)
  875. hot.styleImg = [];
  876. this.styleList.clearVoid();
  877. if(hot.styleImg.length){
  878. var info = this.styleList.findChosenByImgs(hot.styleImg)
  879. var chosenIndex = info.index
  880. this.styleList.selectFromOutSide(chosenIndex)
  881. $("#hotpointDetail .style .MenuOptions li").eq(1).click();
  882. }else{
  883. this.styleList.selectFromOutSide(null)
  884. $("#hotpointDetail .style .MenuOptions li").eq(0).click()
  885. }
  886. this.styleList.saveTemp()
  887. }
  888. /**
  889. * 显示编辑热点的窗口和初始化热点窗口的数据
  890. */
  891. Hotpoint.prototype.editHot = function(hot, $li) {
  892. this.hotpointDetail.removeClass("atRight");
  893. $("#hotpointDetail .audio.mediaUpload").find("input").val('');
  894. // 点击编辑导览清空上一次文件
  895. var playIcon = 'images/play.png';
  896. var $layout = $("#hotpointDetail")[0];
  897. //$layout.targetDOM = target.closest("li")[0];
  898. //closest匹配选择器的第一个祖先元素
  899. //编辑时将热点列表唯一标识带入,以便后期保存使用识别
  900. //var li_id = $li.attr("data-spid");
  901. this.editSpot = hot
  902. this.hotpointDetail.attr("data-id", hot.sid);
  903. var info = this.editSpot.infoAttribute || {}
  904. //$layout.targetDOM.infoAttribute || {}
  905. $(".MenuOptions[name='transform'] li[index='translate']").click()//transformControls.transCtlChangeMode("translate")
  906. // 参数初始化
  907. info.title = info.title || '';
  908. info.content = info.content || '';
  909. info.iframe = info.iframe || [];
  910. info.model = info.model || [];
  911. info.images = info.images || [];
  912. info.video = info.video || [];
  913. info.isSprite = this.editSpot.isSprite
  914. info.actionType = this.editSpot.actionType
  915. info.linkType = this.editSpot.linkType
  916. info.transformAtPanos = {}
  917. for(var i in this.editSpot.transformAtPanos){
  918. info.transformAtPanos[i] = {
  919. pos : this.editSpot.transformAtPanos[i].pos.clone(),
  920. qua : this.editSpot.transformAtPanos[i].qua && this.editSpot.transformAtPanos[i].qua.clone(),
  921. }
  922. }
  923. try {
  924. transformControls.attach(hot.mesh)
  925. if(player.mode == 'panorama'){
  926. hot.examine(player, {
  927. dontOpen: true,
  928. aimDuration : 600,
  929. duration : 600
  930. })
  931. }else{
  932. player.focusPoint({aim: hot.position, radius:hot.position.distanceTo(player.position)})
  933. }
  934. info.position = hot.position.clone()
  935. info.quaternion = hot.quaternion.clone()
  936. } catch (e) {}
  937. this.updatePano()
  938. this.initStyle(hot);
  939. if(hot.infoAttribute.hotIconScale){
  940. $("#hotpointDetail .scale .MenuOptions li[index=user]").click()
  941. }else $("#hotpointDetail .scale .MenuOptions li[index=default]").click()
  942. $("#hotpointDetail .MenuOptions[name='linkType'] li").removeClass("chosen")
  943. $("#hotpointDetail .MenuOptions[name='actionType'] li").removeClass("chosen")
  944. $("#hotpointDetail .MenuOptions[name='linkType'] li[index = " + this.editSpot.linkType+"]").addClass("chosen")
  945. $("#hotpointDetail .MenuOptions[name='actionType'] li[index = " + this.editSpot.actionType+"]").addClass("chosen")
  946. $("#isSprite")[0].checked = this.editSpot.isSprite
  947. //$("#noAction")[0].checked = this.editSpot.noAction
  948. var iframesHTML = info.iframe.map(function(iframe) {
  949. return this.inputList("请填写网页链接", iframe)
  950. }
  951. .bind(this))
  952. var modulesHTML = info.model.map(function(module) {
  953. return this.inputList("请填写网页链接", module)
  954. }
  955. .bind(this))
  956. var imagesHTML = info.images.map(function(image) {
  957. return '<div><a class=" result success" data-type="photo"><span></span><img src="' + image + '" class="bg"></a></div>'
  958. })
  959. var videosHTML = info.video.map(function(ly) {
  960. //var imgDom = (!ly.img || ly.img === "undefined") ? '' : 'success';
  961. //var imgUrl = (!ly.img || ly.img === "undefined") ? playIcon : ly.img;
  962. //return '<div><a class=" result success" data-type="video"><span></span><img class="play-video" videoURL="' + ly.url + '" src="' + imgUrl + '"></a ><span class="upload-thum ' + imgDom + ' result" attr-thum="' + ly.img + '">上传封面<i><input type="file"></i></span></div>'
  963. var thumb = (!ly.img || ly.img === "undefined") ? '' : '<img src='+ ly.img +' class="bg"></img>'
  964. var thumbResult = (!ly.img || ly.img === "undefined") ? '' : 'success';
  965. var dom = '<div><a class=" result success" data-type="video"><span></span>' + thumb + ' <img class="play-video" videoURL="' + ly.url + '" src="' + playIcon + '"></a> <span class="upload-thum ' + thumbResult + ' result" attr-thum="' + ly.img + '">上传封面<i><input type="file" accept="image/*"></i></span></div>'
  966. return dom
  967. })
  968. this.hotpointDetail.find(".name > input").val(info.title);
  969. this.hotpointDetail.find(".editText").val(info.content);
  970. this.hotpointDetail.find(".photo .list").html(imagesHTML);
  971. this.hotpointDetail.find(".video .list").html(videosHTML);
  972. this.hotpointDetail.find(".model .list").html(modulesHTML);
  973. this.hotpointDetail.find(".webPage .list").html(iframesHTML);
  974. let bgName = info.bgName || '热点背景音乐';
  975. if (info.backgroundMusic) {
  976. /* this.hotpointDetail.find(".audio .playBox").removeClass("hide");
  977. this.hotpointDetail.find("#upload-hotBgm").attr('data-hotBgm', info.backgroundMusic)
  978. this.hotpointDetail.find(".audio .playBox a").attr("href", info.backgroundMusic);
  979. this.hotpointDetail.find('#hotBgName')[0].innerHTML = bgName;
  980. this.hotpointDetail.find(".audio .submit").text("替换"); */
  981. this.musicBox.show(this.hotpointDetail.find(".audio.mediaUpload"), bgName, info.backgroundMusic)
  982. } else {
  983. this.musicBox.hide()
  984. /* this.hotpointDetail.find(".audio .playBox").addClass("hide");
  985. this.hotpointDetail.find("#upload-hotBgm").removeAttr('data-hotBgm') */
  986. // 没有背景音乐,则移除该属性, 避免其他热点的干扰
  987. }
  988. // $layout.targetDOM.infoAttribute = info
  989. this.editSpot.infoAttribute = info
  990. }
  991. //添加图片和视频
  992. Hotpoint.prototype.addmedia = function() {
  993. // 视频预览控制
  994. var $videoLayout = $('.fun-view-video')
  995. $videoLayout.find('span').on('click', function() {
  996. $videoLayout.hide();
  997. $videoLayout.find('video').attr('src', '')[0].pause()
  998. });
  999. // 图片加载回调
  1000. function imageSuccess(file) {
  1001. if (!/image\/\w+/.test(file.type)) {
  1002. alert("文件必须为图片!");
  1003. return false;
  1004. }
  1005. if (!restrictedSize(file, 9)) {
  1006. return false;
  1007. }
  1008. var img = new Image()
  1009. img.src = URL.createObjectURL(file);
  1010. img.className = 'bg'
  1011. return img
  1012. }
  1013. // 视频加载回调
  1014. function videoSuccess(file, $elayout) {
  1015. if (!/video\/\w+/.test(file.type)) {
  1016. alert("视频必须为map4格式!");
  1017. return false;
  1018. }
  1019. $elayout.append('<span class="upload-thum">上传封面<i><input type="file" accept="image/*"></i></span>')
  1020. return '<img src="./images/play.png" class="play-video" videoURL="' + URL.createObjectURL(file) + '">'
  1021. }
  1022. // 视频封面回调
  1023. function thumbSuccess(file, $elayout, $seft) {
  1024. if (!/image\/\w+/.test(file.type)) {
  1025. alert("文件必须为图片!");
  1026. return false;
  1027. }
  1028. if (!restrictedSize(file, 2)) {
  1029. return false;
  1030. }
  1031. var img = $seft.closest('div').find('img.bg');
  1032. if(!img[0]){
  1033. img = $("<img class='bg'></img>");
  1034. $seft.closest('div').find('a').append(img)
  1035. }
  1036. img.attr('src', URL.createObjectURL(file));
  1037. $seft.closest('span').removeClass("success")
  1038. }
  1039. // 图片与视频加载
  1040. function fileHandle() {
  1041. var $seft = $(this) //input
  1042. var file = this.files[0];
  1043. var type = this.activeElem ? this.activeElem.attr('data-type') : $seft.parent().attr('data-type');
  1044. var $din = $(document.createElement('div'));
  1045. var fnc = type === 'photo' ? imageSuccess : type === 'video' ? videoSuccess : thumbSuccess //再次传都会是thumSuccess
  1046. var $dom = fnc(file, $din, $seft)
  1047. if (type === 'photo' || type === 'video') {
  1048. if (!$dom)
  1049. return $seft.val('');
  1050. if(!this.activeElem){//创建新的item
  1051. var $layout = $seft.closest("li");
  1052. var $addLayout = $(document.createElement('a'));
  1053. $addLayout.attr("data-type", type)
  1054. var $close = $(document.createElement('span'));
  1055. $addLayout[0].file = file;
  1056. $addLayout.append($close);
  1057. $addLayout.append($dom);
  1058. $addLayout.addClass("result");
  1059. $din.prepend($addLayout);
  1060. $layout.find('.edit-fun-images').append($din);
  1061. }else{//重传
  1062. if (type === 'photo'){
  1063. this.activeElem.find("img.bg").remove();
  1064. }else{
  1065. this.activeElem.find(".play-video").remove();
  1066. }
  1067. this.activeElem.removeClass("success")
  1068. this.activeElem.append($dom)
  1069. this.activeElem[0].file = file;
  1070. this.value = ''
  1071. }
  1072. }
  1073. if (searchParent($seft[0], {
  1074. id: 'shareImgUpload'
  1075. })) {
  1076. //信息页面的分享图片
  1077. $("#shareImgUpload").addClass("hide")
  1078. }else if(searchParent($seft[0], {
  1079. id: 'SpotStyle'
  1080. })){
  1081. $("#SpotStyle").addClass("hide")
  1082. }
  1083. }
  1084. //用于重传的input
  1085. var imgInput = $("<input accept='image/*' type='file'></input>")
  1086. var videoInput = $("<input accept='video/*' type='file'></input>")
  1087. // 图片与视频加载
  1088. $('.upload, .edit-fun-images').on('change', function(ev) {
  1089. if (ev.target.tagName.toUpperCase() === 'INPUT') {
  1090. ev.target.files.length && fileHandle.call(ev.target)
  1091. }
  1092. })
  1093. imgInput.on('change', (ev)=>{fileHandle.call(ev.target)})
  1094. videoInput.on('change', (ev)=>{fileHandle.call(ev.target)})
  1095. $('.edit-fun-images').on('click', function(ev) {//点击item时
  1096. var $tag = $(ev.target)
  1097. var tagName = ev.target.tagName.toUpperCase()
  1098. if (tagName === 'SPAN') {
  1099. if (searchParent($tag[0], {
  1100. className: 'forShareImg'
  1101. })) {
  1102. //信息页面的分享图片
  1103. $("#shareImgUpload").removeClass('hide')
  1104. }else if(searchParent($tag[0], {
  1105. className: 'SpotStyle'
  1106. })){
  1107. $("#SpotStyle").removeClass('hide')
  1108. }
  1109. $tag.parent().parent().remove()
  1110. }else if (tagName === 'IMG' && $tag.hasClass('play-video')) {
  1111. $videoLayout.css('display', 'flex').find('video').attr('src', $tag.attr('videoURL'))[0].play()
  1112. }else{// 替换
  1113. var a = searchParent($tag[0], {
  1114. tagName: 'a'
  1115. })
  1116. if(a) {
  1117. var input
  1118. if(searchParent($tag[0], {
  1119. className: 'video'
  1120. })){
  1121. input = videoInput
  1122. }else{
  1123. input = imgInput
  1124. }
  1125. input[0].activeElem = $(a)
  1126. input.click()
  1127. }
  1128. }
  1129. })
  1130. }
  1131. //选择热点的样式
  1132. Hotpoint.prototype.active = function() {
  1133. $(".hotStyle-item li").on('click', function() {
  1134. $(this).addClass('active').siblings().removeClass('active');
  1135. })
  1136. }
  1137. //当前处于的状态,比如是否是添加热点的状态
  1138. Hotpoint.prototype.state = function(that, Hot) {
  1139. if (g_HotStatus === "add") {
  1140. //console.log(Hot)
  1141. this.addHot(that, Hot, (hot)=>{
  1142. this.addHotList(hot);
  1143. }
  1144. );
  1145. }
  1146. }
  1147. Hotpoint.prototype.updateNumDisplay = function() {
  1148. this.spotList.find("i").text(this.spotList.find("ul li").length);
  1149. }
  1150. //删除热点
  1151. Hotpoint.prototype.removeHot = function(hot, $li ) {
  1152. hot.dispose();
  1153. delete player.model.hots[hot.sid]
  1154. $li.remove();
  1155. this.updateNumDisplay()
  1156. }
  1157. //添加热点模型
  1158. Hotpoint.prototype.addHot = function(that, Hot, fn) {
  1159. if (!window.hotIntersect)
  1160. return;
  1161. // 没有正确的热点位置, return
  1162. var position = hotIntersect.point.toArray();
  1163. //var sid = g_HotMeshes.length > 0 ? "sprite_" + (parseInt(g_HotMeshes[g_HotMeshes.length - 1].name.substring(7)) + 1) : "sprite_" + g_HotMeshes.length;//这么写出bug了。因为当前热点名字不是按照从小到大
  1164. var sid = getRandomSid()
  1165. var hot = new Hot(sid,{
  1166. position: position,
  1167. rotation: [0, 0, 0],
  1168. size: 1.05
  1169. },that.model);
  1170. that.model.hots[sid] = hot;
  1171. if (player.getMouseDirection().angleTo(window.hotIntersect.face.normal) < Math.PI / 2) {
  1172. hot.mesh.lookAt(window.hotIntersect.face.normal.clone().negate().add(hotIntersect.point));
  1173. hot.mesh.position.add(window.hotIntersect.face.normal.clone().negate().multiplyScalar(0.01))
  1174. //avoid mesh crash with chunks 模型的精度可能和floorplan的不一样,所以chunk即使材质经过处理还是会闪烁但是wallmesh不会
  1175. } else {
  1176. hot.mesh.lookAt(window.hotIntersect.face.normal.clone().add(hotIntersect.point));
  1177. hot.mesh.position.add(window.hotIntersect.face.normal.clone().multiplyScalar(0.01))
  1178. }
  1179. hot.quaternion.copy(hot.mesh.quaternion)
  1180. hot.position.copy(hot.mesh.position)
  1181. g_HotStatus = false;
  1182. that.mouseCouldBeClickToMove = false;
  1183. $("#player").css("cursor", "");
  1184. //添加完热点之后的回调函数
  1185. if (g_HotMeshes && g_newHot.length === g_newHot.length++) {
  1186. var thisScene = that;
  1187. //fn && fn.call(this, thisScene);
  1188. fn && fn(hot)
  1189. }
  1190. }
  1191. //添加热点列表
  1192. Hotpoint.prototype.addHotList = function(hot) {
  1193. var li = $("<li class='listItem' data-spid=" + hot.sid + ">" + "<div class=icon></div>" + "<div class=number title=热点>" + (++_hotNum) + "</div>" + "<div class=title title=热点>" + (hot.infoAttribute && hot.infoAttribute.title || "") + "</div>" + "<div class=DelConfirm>确定删除</div>" + "<div class=del></div>" + "</li>");
  1194. li.hot = hot
  1195. $(".spotList ul").append(li);
  1196. this.updateNumDisplay()
  1197. }
  1198. //添加热点音乐
  1199. Hotpoint.prototype.addMusicInit = function() {
  1200. /* var mediaUpload = $("#hotpointDetail .audio.mediaUpload");
  1201. mediaUpload.find("input").on("change", function() {
  1202. var file = this.files[0];
  1203. mediaUpload.find(".innerBtn").text("替换");
  1204. mediaUpload.find(".playBox").removeClass("hide");
  1205. mediaUpload.find(".title").text(file.name);
  1206. mediaUpload.find('#query-bgm').attr('href', URL.createObjectURL(file));
  1207. });
  1208. //删除音乐
  1209. mediaUpload.on("click", ".delete", function() {
  1210. mediaUpload.find('#query-bgm').attr('href', "");
  1211. mediaUpload.find(".playBox").addClass("hide");
  1212. mediaUpload.find(".innerBtn").text("上传");
  1213. mediaUpload.find("input").val("").removeAttr("data-hotbgm");
  1214. }) */
  1215. this.musicBox = musicPlayBoxBind($("#hotpointDetail .audio.mediaUpload"), null )
  1216. }
  1217. //添加热点模型列表dom
  1218. Hotpoint.prototype.inputList = function(text, val) {
  1219. var _val = '';
  1220. if (arguments[1]) {
  1221. _val = 'value=' + val;
  1222. }
  1223. return '<div class="link"> <input class="text" type="text" placeholder=' + text + ' spellcheck="false" ' + _val + ' > </div>'
  1224. }
  1225. //添加热点模型
  1226. Hotpoint.prototype.addModel = function() {
  1227. var text = this.inputList("请填写模型链接");
  1228. this.hotpointDetail.find(".model .add").on('click', function() {
  1229. $(this).closest(".model").find(".list").append(text)
  1230. });
  1231. this.hotpointDetail.find(".model .delete").on('click', function() {
  1232. $(this).closest(".model").find(".list > div:last").remove();
  1233. });
  1234. }
  1235. //添加网页链接
  1236. Hotpoint.prototype.addwebPack = function() {
  1237. var text = this.inputList("请填写网页链接", "");
  1238. this.hotpointDetail.find(".webPage .add").on('click', function() {
  1239. $(this).closest(".webPage").find(".list").append(text)
  1240. });
  1241. this.hotpointDetail.find(".webPage .delete").on('click', function() {
  1242. $(this).closest(".webPage").find(".list > div:last").remove();
  1243. });
  1244. }
  1245. // 保存热点信息
  1246. Hotpoint.prototype.saveHot = function() {
  1247. var $layout = $(".edit-loading");
  1248. var hotpointDetail = this.hotpointDetail;
  1249. var that = this
  1250. //获取唯一标识
  1251. var spot_id = hotpointDetail.attr("data-id");
  1252. var spot = this.spotList.find("li[data-spid=" + spot_id + "]");
  1253. var hot = player.model.hots[spot_id];
  1254. //显示loading
  1255. $layout.removeClass('hide');
  1256. var args = {};
  1257. //热点标题
  1258. var $title = hotpointDetail.find(".info input");
  1259. //热点内容
  1260. var $content = hotpointDetail.find(".info textarea");
  1261. //热点图片
  1262. var $images = hotpointDetail.find(".photo .edit-fun-images a.result");
  1263. //热点视频
  1264. var $videos = hotpointDetail.find(".video .edit-fun-images a.result");
  1265. //热点视频的图片
  1266. var $thums = hotpointDetail.find(".video .edit-fun-images .upload-thum");
  1267. //热点模型
  1268. var $modules = hotpointDetail.find(".model input");
  1269. //热点内嵌网页
  1270. var $iframes = hotpointDetail.find(".webPage input.text");
  1271. //热点音乐
  1272. var $miusc = hotpointDetail.find("#upload-hotBgm");
  1273. let $bgName = hotpointDetail.find('.title');
  1274. var promise = new Promise(function(resolve, reject) {
  1275. //获取图片路径
  1276. upload($images, 'images', resolve)
  1277. }).then(function(imgUrls) {
  1278. args.images = imgUrls
  1279. //获取视频路径
  1280. return new Promise(function(resolve, reject) {
  1281. upload($videos, 'videos', resolve)
  1282. }
  1283. )
  1284. }).then(function(videoUrls) {
  1285. args.video = videoUrls
  1286. //获取视频封面路径
  1287. return new Promise(function(resolve, reject) {
  1288. upload($thums, 'images', resolve)
  1289. }
  1290. )
  1291. }).then(function(thums) {
  1292. args.video = args.video.map(function(video, index) {//整合视频+封面
  1293. return {
  1294. url: video,
  1295. img: thums[index]
  1296. }
  1297. })
  1298. }).then(function() {
  1299. //获取热点音乐所有的路径
  1300. //console.log($miusc)
  1301. if ($miusc[0].files.length > 0) {
  1302. return new Promise(function(resolve) {
  1303. upload($miusc, 'miusc', function(res) {
  1304. resolve(res[0])
  1305. })
  1306. }
  1307. )
  1308. } else {
  1309. return $miusc.attr('data-hotBgm')
  1310. }
  1311. }).then(function(src) {
  1312. if(that.musicBox.hasMusic && !src){
  1313. args.backgroundMusic = hot.infoAttribute.backgroundMusic
  1314. args.bgName = hot.infoAttribute.bgName
  1315. }else{
  1316. args.backgroundMusic = src
  1317. args.bgName = $bgName[0].innerHTML;
  1318. }
  1319. }).then(function() {
  1320. //上传所有热点的style图片
  1321. var a = $.Deferred();
  1322. var doneNum = 0;
  1323. var imgsNeedSave = [];
  1324. Array.from(that.styleList.listDom.children()).forEach(li=>{
  1325. if(li.sameTexSpots.length == 0)return;//没被热点用到就不保存
  1326. li.sameTexSpots.forEach(spot=>spot.styleImg = li._styleImg)//同步下
  1327. li._styleImg.forEach(img=>{
  1328. if(img.needSave && !imgsNeedSave.includes(img)){
  1329. imgsNeedSave.push(img)
  1330. }
  1331. })
  1332. })
  1333. if(imgsNeedSave.length){
  1334. imgsNeedSave.forEach(img=>{
  1335. uploadFile(img.file, 'hot/image', function(rs) {
  1336. if (rs.code === 0) {
  1337. img.needSave = false;
  1338. //img.saveURL = rs.data;
  1339. img.src = rs.data;
  1340. if (++doneNum >= imgsNeedSave.length) {
  1341. a.resolve();
  1342. }
  1343. } else {
  1344. alert("样式图上传失败");
  1345. a.reject();
  1346. }
  1347. })
  1348. })
  1349. return a.promise()
  1350. }else{
  1351. return a.resolve()
  1352. }
  1353. }).then(function() {
  1354. //获取热点标题、内容、内嵌网页、模型网页。
  1355. args.title = $title.val()
  1356. args.content = $content.val()
  1357. var iframes = []
  1358. for (var i = 0; i < $iframes.length; i++) {
  1359. var iframe = $iframes.eq(i).val()
  1360. iframe && iframes.push(iframe)
  1361. }
  1362. args.iframe = iframes
  1363. var modules = []
  1364. for (var i = 0; i < $modules.length; i++) {
  1365. var module = $modules.eq(i).val()
  1366. module && modules.push(module)
  1367. }
  1368. args.model = modules
  1369. if(!hot.isSprite){
  1370. args.quaternion = hot.quaternion.clone()
  1371. //hot.quaternion.copy(hot.mesh.quaternion)
  1372. }
  1373. args.position = hot.position.clone()
  1374. //hot.position.copy(hot.mesh.position)
  1375. return args
  1376. }).then(function(args) {
  1377. console.log(args);
  1378. //把获取的所有信息都保存在对应热点的dom元素里面
  1379. //hotpointDetail[0].targetDOM.infoAttribute = args;
  1380. if($("#hotpointDetail .scale .MenuOptions li.chosen").attr('index') == 'user' ){
  1381. args.hotIconScale = $("#hotIconScale_2 input").val();
  1382. }else{
  1383. delete args.hotIconScale
  1384. }
  1385. hot.infoAttribute = args;
  1386. for(let i in player.model.hots){//修改所有的热点贴图数据
  1387. let hot = player.model.hots[i];
  1388. let li = that.styleList.findChosenByImgs(hot.styleImg).item
  1389. if(li) hot.infoAttribute.styleImg = li._styleImg.map(img=> img.src)//将blob更换成线上链接
  1390. }
  1391. hot.setTitleElem()//更新名称
  1392. $layout.addClass('hide');
  1393. hotpointDetail.addClass("atRight");
  1394. spot.find(".title").html(args.title);
  1395. transformControls.detach()
  1396. that.editSpot = null
  1397. })
  1398. return promise
  1399. }
  1400. //背景音乐
  1401. var EditMiuse = function() {
  1402. this.mediaUpload = $(".music .audio.mediaUpload");
  1403. this.musicBox = musicPlayBoxBind(this.mediaUpload, (file)=>{
  1404. uploadMiuse(file, (rs, file)=>{
  1405. if (rs.code === 0) {
  1406. this.musicBox.show(this.mediaUpload, file.name, rs.data)
  1407. }else{
  1408. this.musicBox.hide()
  1409. }
  1410. })
  1411. }, null)
  1412. /* this.success = function(text, url) {
  1413. this.mediaUpload.find(".innerBtn").text("替换");
  1414. this.mediaUpload.find(".playBox").removeClass("hide");
  1415. this.mediaUpload.find(".title").text(text);
  1416. this.mediaUpload.find('#query-bgm').attr('href', url)
  1417. }
  1418. ;
  1419. this.delete = function() {
  1420. this.mediaUpload.find('#query-bgm').attr('href', "");
  1421. this.mediaUpload.find(".playBox").addClass("hide");
  1422. this.mediaUpload.find(".innerBtn").text("上传");
  1423. this.mediaUpload.find("input").val("");
  1424. }
  1425. ;
  1426. var that = this;
  1427. $('#upload-bgm').on('change', function(e) {
  1428. var file = this.files[0];
  1429. uploadMiuse(file, function(rs, file) {
  1430. if (rs.code === 0) {
  1431. that.success(file.name, rs.data)
  1432. }
  1433. })
  1434. e.target.value = null
  1435. });
  1436. //删除音乐
  1437. this.mediaUpload.on("click", ".delete", function() {
  1438. that.delete();
  1439. }) */
  1440. }
  1441. EditMiuse.prototype.init = function(data) {
  1442. if (!data.backgroundMusic)
  1443. return;
  1444. this.musicBox.show(this.mediaUpload, data.bgName || "backgound", data.backgroundMusic);
  1445. }
  1446. //导览编辑
  1447. var EditGuide = function() {
  1448. this.$list = $('#guide-list')
  1449. //$('#tourItemEdit') = $('#tourItemEdit');
  1450. this.targetTourPoint = null;
  1451. // fyz 记录当前编辑的导览点
  1452. // fyz 导览音乐队列
  1453. //this.tourAudio = {};
  1454. }
  1455. /**
  1456. * @author fyz 2019.07.31
  1457. * @description 新增参数data2, 表示data2.js中的数据
  1458. */
  1459. /* function snapATourView(that, renew) {
  1460. var ev = document.createEvent("MouseEvent");
  1461. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  1462. g_snapShotWidth = 200;
  1463. g_snapShotHeight = 140;
  1464. window.screenSta = 'tour';
  1465. // 记录当前哪个功能截屏, 因为导览截屏需要做额外的校对调整, 初始画面截屏不需要
  1466. ev.__callback = function(imgData, info) {
  1467. that.uploadGuide(imgData, info, renew, that.targetTourPoint)
  1468. }.bind(that);
  1469. window.dispatchEvent(ev);
  1470. } */
  1471. EditGuide.prototype.snapATourView = function(renew, insideFolder){
  1472. var ev = document.createEvent("MouseEvent");
  1473. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  1474. g_snapShotWidth = 200;
  1475. g_snapShotHeight = 140;
  1476. window.screenSta = 'tour';
  1477. // 记录当前哪个功能截屏, 因为导览截屏需要做额外的校对调整, 初始画面截屏不需要
  1478. ev.__callback = (imgData, info)=> {
  1479. this.uploadGuide(imgData, info, renew, insideFolder)
  1480. };
  1481. window.dispatchEvent(ev);
  1482. }
  1483. EditGuide.prototype.init = function(data, data2) {
  1484. this.createDom(data, data2);
  1485. //this.tourAudio = data2.tourAudio || {};
  1486. var that = this;
  1487. //点击添加导览
  1488. $('.addTour .innerBtn').eq(0).on("click", function () {
  1489. this.addFolderDom({name:"区域"+($("#tourList .listItem").length+1) } );//点击增加一段导览
  1490. $("#tourList ul")[0].scrollTop = $("#tourList ul")[0].scrollHeight //scroll to bottom
  1491. }.bind(this));
  1492. $('.addTour .innerBtn').eq(1).on("click", function () {
  1493. this.snapATourView()//点击截取视图
  1494. $("#tourList ul")[0].scrollTop = $("#tourList ul")[0].scrollHeight
  1495. }.bind(this));
  1496. $('.snapATourView .innerBtn').on("click", function() {
  1497. this.snapATourView(null,true);//folder内点击截取视图
  1498. $("#tourItemList ul")[0].scrollTop = $("#tourItemList ul")[0].scrollHeight
  1499. }.bind(this));
  1500. $('#renewTourBtn').on("click", function() { // 重新截取视图
  1501. this.snapATourView(this, !!this.editingFolderLi);
  1502. }.bind(this));
  1503. // 确认并保存导览信息
  1504. $('#tourFolderEdit .tourSubmit').on("click", function() {
  1505. this.completeFolder();
  1506. }.bind(this));
  1507. $('#tourItemEdit .tourSubmit').on("click", function() {
  1508. this.completeItem();
  1509. }.bind(this));
  1510. //点击导览编辑窗口右上角的关闭按钮
  1511. /* $("#tourItemEdit a.close, button.cancel").on("click", function() {
  1512. that.targetTourPoint[0].musicSta = true; ///??????????
  1513. // 取消操作, 重置状态
  1514. that.tourDetail.addClass("atRight");
  1515. }); */
  1516. //导览目录
  1517. $("#tourList").on("click", function(e) {
  1518. var target = $(e.target);
  1519. let folder = searchParent(e.target, { className: 'listItem' }, 7);
  1520. if(!folder)return;//可能点到了item
  1521. if (target.hasClass("del")) {
  1522. e.stopPropagation();
  1523. target.siblings(".DelConfirm").addClass("active");
  1524. } else {
  1525. if (target.hasClass("DelConfirm")) {
  1526. e.stopPropagation();
  1527. $(folder).remove()
  1528. //that.removeFolder(folder);//删除
  1529. } else {
  1530. if (target.hasClass("title") || target.hasClass("icon")) {
  1531. that.editFolder(folder)//编辑
  1532. }
  1533. }
  1534. }
  1535. });
  1536. //编辑item
  1537. $('.tourList ul').on('click', function(e) {
  1538. var target = $(e.target);
  1539. let itemDom = searchParent(e.target, { className: 'guideItem' }, 7);
  1540. if(!itemDom)return;//可能点到了folder
  1541. if(searchParent(e.target, { className: 'preview' })){
  1542. var choice = confirm("你确定删除吗?");
  1543. if (choice) {
  1544. var ul = searchParent(e.target, { className: 'tourList' })
  1545. target.closest('li').remove();
  1546. reIndexTourList(ul)
  1547. } else {
  1548. return false
  1549. }
  1550. }else{
  1551. that.editItem(itemDom);
  1552. }
  1553. })
  1554. //fyz 拖拽以改变顺序
  1555. let tourListNode = $("#tourList>ul")[0];
  1556. let tourItemListNode = $("#tourItemList>ul")[0];
  1557. let draging = null;
  1558. let dragStart = (event)=> {
  1559. event.dataTransfer.setData("te", event.target.innerText); //不能使用text,firefox会打开新tab
  1560. draging = event.target;
  1561. }
  1562. let dragOver = (event)=>{
  1563. event.preventDefault();
  1564. let target = searchParent(event.target, { tagName: 'LI' }, 7); //event.target.parentNode.parentNode;
  1565. // 判断dragover是否发生在LI元素上
  1566. if ((target.classList.contains('guideItem') || target.classList.contains('listItem')) && target !== draging ) {
  1567. let dragingIndex = $(draging).index()//draging.querySelector('#index');
  1568. let targetIndex = $(target).index()//target.querySelector('#index');
  1569. var targetRect = target.getBoundingClientRect();
  1570. var dragingRect = draging.getBoundingClientRect();
  1571. if (target && target.animated) {
  1572. return;
  1573. }
  1574. let ulElem = target.parentNode;
  1575. // 寻找到 ul节点
  1576. if (getIndex(draging) < getIndex(target)) {
  1577. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
  1578. // 交换两个节点的序号
  1579. if(event.clientY<targetRect.top+targetRect.height*0.3)return
  1580. ulElem.insertBefore(draging, target.nextSibling);
  1581. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];// 交换两个节点的序号
  1582. } else {
  1583. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
  1584. if(event.clientY>targetRect.bottom-targetRect.height*0.3)return
  1585. ulElem.insertBefore(draging, target);
  1586. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
  1587. }
  1588. _animate(dragingRect, draging);
  1589. _animate(targetRect, target);
  1590. var ul = searchParent(event.target, { className: 'tourList' })
  1591. reIndexTourList(ul)
  1592. }
  1593. }
  1594. tourListNode.ondragstart = dragStart
  1595. tourItemListNode.ondragstart = dragStart
  1596. tourListNode.ondragover = dragOver
  1597. tourItemListNode.ondragover = dragOver
  1598. //音乐
  1599. this.musicBox = musicPlayBoxBind($(".snapTour .audio.mediaUpload"), null, ()=>{
  1600. (that.editingFolderLi || that.editingItemLi).tourData.musicInfo = {}//直接删除 不可逆
  1601. })
  1602. /*
  1603. var mediaUpload = $(".snapTour .audio.mediaUpload");
  1604. var that = this;
  1605. mediaUpload.find("input").on("change", function(e) {
  1606. if(!e.target.files.length) return;
  1607. var mediaDom = $(searchParent(e.target, { className: 'mediaUpload' }));
  1608. var file = e.target.files[0];
  1609. mediaDom.find(".innerBtn").text("替换");
  1610. mediaDom.find(".playBox").removeClass("hide");
  1611. mediaDom.find(".title").text(file.name);
  1612. mediaDom.find('#query-bgm').attr('href', URL.createObjectURL(file));
  1613. //that.editingFolderLi.musicSta = true;
  1614. });
  1615. mediaUpload.find("input").on("click", function() {
  1616. mediaUpload
  1617. });
  1618. //删除音乐
  1619. mediaUpload.on("click", ".delete", function(e) {
  1620. var mediaDom = $(searchParent(e.target, { className: '.mediaUpload' }));
  1621. mediaDom.find('#query-bgm').attr('href', "");
  1622. mediaDom.find(".playBox").addClass("hide");
  1623. mediaDom.find(".innerBtn").text("上传");
  1624. mediaDom.find("input").val("")//.removeAttr("data-hotbgm");
  1625. //that.editingFolderLi.musicSta = false;
  1626. (that.editingFolderLi || that.editingItemLi).data.musicInfo = {}//直接删除 不可逆
  1627. }) */
  1628. }
  1629. function musicPlayBoxBind($dom, addCallback, delCallback){
  1630. var musicBox = {
  1631. hasMusic:false,
  1632. show: function(mediaDom, name, url){
  1633. mediaDom = mediaDom || $dom
  1634. mediaDom.find(".innerBtn").text("替换");
  1635. mediaDom.find(".playBox").removeClass("hide");
  1636. mediaDom.find(".title").text(name);
  1637. mediaDom.find('#query-bgm').attr('href', url);
  1638. musicBox.hasMusic = true
  1639. },
  1640. addMusic : function(e) {
  1641. if(!e.target.files.length) return;
  1642. var file = e.target.files[0];
  1643. if (!/audio\/\w+/.test(file.type)) {
  1644. alert("文件必须为音乐!");
  1645. return false;
  1646. }
  1647. //限制大小不大于8m
  1648. if (!restrictedSize(file, _musicMaxWeight)) {
  1649. return false
  1650. }
  1651. var mediaDom = $(searchParent(e.target, { className: 'mediaUpload' }));
  1652. musicBox.show(mediaDom, file.name, URL.createObjectURL(file))
  1653. addCallback && addCallback(file)
  1654. },
  1655. hide : function(e) {
  1656. var mediaDom = e ? $(searchParent(e.target, { className: 'mediaUpload' })) : $dom
  1657. mediaDom.find('#query-bgm').attr('href', "");
  1658. mediaDom.find(".playBox").addClass("hide");
  1659. mediaDom.find(".innerBtn").text("上传");
  1660. mediaDom.find("input").val("")//.removeAttr("data-hotbgm");
  1661. musicBox.hasMusic = false
  1662. delCallback && delCallback()
  1663. }
  1664. }
  1665. $dom.find("input").on("change", musicBox.addMusic)
  1666. /* $dom.find("input").on("click", function() {
  1667. mediaUpload
  1668. }); */
  1669. //删除音乐
  1670. $dom.on("click", ".delete", musicBox.hide)
  1671. return musicBox;
  1672. }
  1673. function reIndexTourList(ul) {
  1674. Array.from($(ul).find('li.guideItem')).forEach((li,index)=>{
  1675. $(li).find("div:first-child span").text(index + 1);
  1676. })
  1677. }
  1678. EditGuide.prototype.addFolderDom = function( tourData){
  1679. var $folder = $("<li class='listItem' draggable='true'>" + "<div class=icon></div>" + "<div class=title >" + (tourData.name || "") + "</div>" + "<div class=DelConfirm>确定删除</div>" + "<div class=del></div>" + "</li>");
  1680. $folder[0].tourItemDoms = [] //记录所有item的li dom
  1681. $folder[0].tourData = tourData //注: data中的locations不会更新,保存时直接读取li
  1682. $("#tourList ul").append($folder);
  1683. return $folder
  1684. }
  1685. EditGuide.prototype.getItemDom = function(title, img) {
  1686. return '<li draggable="true" class="guideItem">' + '<div>' + '<span id="index"></span>' + '<div class="line"></div>' + '</div>' + '<div>' + '<span class="guide-name" >' + title + '</span>' + '<input maxlength="14" class="hide" data-oper=tour-input>' + '</div>' + '<div class="preview" >' + '<div id="tourBg" style="background-image: url(' + img + ');" >' + '</div>' + '</div>' + '</li >';
  1687. }
  1688. EditGuide.prototype.createDom = function(data, data2) {
  1689. var that = this;
  1690. var tourAudio = data2.tourAudio || {};
  1691. data.model.images.forEach((Info,index)=>{
  1692. if(Info.locations){//是folder
  1693. var $folder = this.addFolderDom(Info)
  1694. // 音频链接
  1695. Info.locations = Info.locations.filter(e=>e)
  1696. Info.locations.forEach(function(info, index) {
  1697. if (info.thumbnail_signed_src) {
  1698. var $li = $(that.getItemDom( info.name, info.thumbnail_signed_src));
  1699. $li[0].tourData = info
  1700. $folder[0].tourItemDoms.push($li[0])
  1701. }
  1702. })
  1703. }else{//是散落在外的item
  1704. if (Info.thumbnail_signed_src) {
  1705. var $li = $(that.getItemDom(Info.name, Info.thumbnail_signed_src));
  1706. $li[0].tourData = Info
  1707. // 音频链接
  1708. $li[0].tourData.musicInfo = $li[0].tourData.musicInfo || tourAudio[Info.sid] || {}//新的music数据统一写在每个info下
  1709. $("#tourList ul").append($li)
  1710. /* if (Info.sid in tourAudio && tourAudio[info.sid].music && tourAudio[info.sid].music !== '') {
  1711. //$li[0].musicUrl = tourAudio[info.sid].music;
  1712. $li[0].musicInfo = tourAudio[info.sid]
  1713. } */
  1714. }
  1715. }
  1716. })
  1717. reIndexTourList($("#tourList")[0])
  1718. }
  1719. //暂时不实时更新左侧场景,所以信息全写在UI上,不保存data
  1720. EditGuide.prototype.editFolder = function(folderDom){
  1721. this.editingFolderLi = folderDom;
  1722. $("#tourFolderEdit").removeClass('atRight');
  1723. $("#tourFolderEdit .tourName input").val( $(folderDom).find('.title').text()||'');
  1724. //$("#folderTourSwitch input").prop('checked', folderDom.tourData.momentTour === 'black');
  1725. var momentTour = folderDom.tourData.momentTour || "default"
  1726. $("#folderTourSwitch li").removeClass('chosen')
  1727. $("#folderTourSwitch li[index="+ momentTour +"]").addClass('chosen');
  1728. folderDom.tourItemDoms.forEach(li=>{
  1729. $("#tourItemList>ul").append(li)
  1730. })
  1731. reIndexTourList($("#tourItemList>ul")[0])
  1732. //判断当前点是否有导览音频
  1733. //target[0].musicSta = true;
  1734. //var audio = this.tourAudio[target.closest('li')[0].data.sid];
  1735. var musicInfo = this.editingFolderLi.tourData.musicInfo //audio ? audio.music : null;
  1736. if (musicInfo && musicInfo.music) { // 判断改导览点是否已经已有音乐
  1737. var musicName = musicInfo.name || '导览音频.mp3' // 获取音频的文件名
  1738. /* $('#tourFolderEdit').find(".audio .playBox").removeClass("hide");
  1739. $('#tourFolderEdit').find(".audio .playBox a").attr("href", "//" + musicInfo.music);
  1740. $('#tourFolderEdit').find(".audio .submit").text("替换");
  1741. $('#tourFolderEdit').find(".title").text(musicName); */
  1742. this.musicBox.show($('#tourFolderEdit .mediaUpload'), musicName, "//" + musicInfo.music)
  1743. } else {
  1744. /* $('#tourFolderEdit').find(".audio .playBox").addClass("hide");
  1745. $('#tourFolderEdit').find(".audio .submit").text("上传"); */
  1746. this.musicBox.hide()
  1747. }
  1748. }
  1749. /**
  1750. * @author fyz 编辑单个导览item
  1751. * @param {any} target 所点击的导览点
  1752. */
  1753. EditGuide.prototype.editItem = function(li) {
  1754. //this.targetTourPoint = target;
  1755. this.editingItemLi = li
  1756. // 记录当前编辑的导览点
  1757. var that = this;
  1758. $('#tourItemEdit').removeClass('atRight');
  1759. $('#tourItemEdit .tourName input').val( $(li).find('.guide-name').text() );
  1760. var momentTour = li.tourData.momentTour || "default"
  1761. $("#tourSwitch_Slice li").removeClass('chosen')
  1762. $("#tourSwitch_Slice li[index="+ momentTour +"]").addClass('chosen');
  1763. var metadata = JSON.parse(li.tourData.metadata);
  1764. if(metadata.scan_id != 'outside'){
  1765. var pano = player.model.panos.index[metadata.scan_id]
  1766. if(pano){
  1767. var q = new THREE.Quaternion().copy(metadata.camera_quaternion);
  1768. player.flyToPano({
  1769. pano: pano,
  1770. quaternion: q,
  1771. zoomLevel: metadata.zoom
  1772. })
  1773. }
  1774. }
  1775. if(!this.editingFolderLi){//在外的item, 可以上传音乐
  1776. $('#tourItemEdit .mediaUpload').removeClass('hide')
  1777. var musicInfo = li.tourData.musicInfo //audio ? audio.music : null;
  1778. if (musicInfo && musicInfo.music) { // 判断改导览点是否已经已有音乐
  1779. var musicName = musicInfo.name || '导览音频.mp3' // 获取音频的文件名
  1780. /* $('#tourItemEdit').find(".audio .playBox").removeClass("hide");
  1781. $('#tourItemEdit').find(".audio .playBox a").attr("href", "//" + musicInfo.music);
  1782. $('#tourItemEdit').find(".audio .submit").text("替换");
  1783. $('#tourItemEdit').find(".title").text(musicName); */
  1784. this.musicBox.show($('#tourItemEdit .mediaUpload'), musicName, "//" + musicInfo.music)
  1785. } else {
  1786. this.musicBox.hide()
  1787. /* $('#tourItemEdit').find(".audio .playBox").addClass("hide");
  1788. $('#tourItemEdit').find(".audio .submit").text("上传"); */
  1789. }
  1790. }else{
  1791. $('#tourItemEdit .mediaUpload').addClass('hide')
  1792. }
  1793. }
  1794. EditGuide.prototype.completeFolder = function(){//点击完成
  1795. var tourName = $('#tourFolderEdit .tourName input').val() //|| this.targetTourPoint.context.innerText;
  1796. $(this.editingFolderLi).find(".title").text(tourName)
  1797. //this.editingFolderLi.tourData.momentTour = $("#folderTourSwitch input").is(':checked') ? "black" : 'walk'
  1798. var momentTour = $("#folderTourSwitch li.chosen").attr("index");
  1799. this.editingFolderLi.tourData.momentTour = momentTour != 'default' ? momentTour : null;
  1800. this.editingFolderLi.tourItemDoms = Array.from($('#tourItemList ul li'));
  1801. var done = ()=>{
  1802. $("#tourFolderEdit .audio.mediaUpload").find("input").val(''); // 清空 文件
  1803. this.editingFolderLi = null
  1804. $("#tourFolderEdit").addClass('atRight');
  1805. $(".edit-loading").addClass('hide');
  1806. $("#tourItemList>ul").html('')
  1807. }
  1808. //save导览音乐
  1809. var tourAudio = $('#tourFolderEdit .mediaUpload input');
  1810. // 记录音频名称
  1811. //判断当前编辑的导览点位是否已上传音乐
  1812. if (tourAudio[0].files.length > 0/* && this.targetTourPoint[0].musicSta */) { //有input文件
  1813. $(".edit-loading").removeClass('hide');
  1814. var musicName = $('#tourFolderEdit .mediaUpload .title').text();
  1815. new Promise( (resolve, reject)=> {
  1816. uploadMiuse(tourAudio[0].files[0], function(res) {
  1817. resolve(res.data);
  1818. })
  1819. } ).then( (src)=>{
  1820. var audio = new Audio();
  1821. audio.src = src;
  1822. audio.onloadedmetadata = ()=>{
  1823. var srcArr = src.split('/'); // 对返回的src进行处理, 去掉前面域名, 尽量避免修改main.js
  1824. srcArr[0] = '';
  1825. src = srcArr.join('/');
  1826. //var sid = this.editingFolderLi.data.sid
  1827. //that.tourAudio[sid] = {
  1828. this.editingFolderLi.tourData.musicInfo = {
  1829. "name": musicName,
  1830. "music": '/' + src,
  1831. "time": Math.round(audio.duration * 1000 + 1000)
  1832. }
  1833. done()
  1834. }
  1835. })
  1836. }else done()
  1837. }
  1838. EditGuide.prototype.completeItem = function() {//点击完成
  1839. var done = ()=>{
  1840. $("#tourItemEdit .audio.mediaUpload").find("input").val(''); // 清空 文件
  1841. this.editingItemLi = null
  1842. $("#tourItemEdit").addClass('atRight');
  1843. $(".edit-loading").addClass('hide');
  1844. }
  1845. var tourName = $('#tourItemEdit .tourName input').val()
  1846. $(this.editingItemLi).find('.guide-name').text(tourName)
  1847. var momentTour = $("#tourSwitch_Slice li.chosen").attr("index");
  1848. this.editingItemLi.tourData.momentTour = momentTour != 'default' ? momentTour : null;
  1849. //save导览音乐
  1850. var tourAudio = $('#tourItemEdit .mediaUpload input');
  1851. //判断当前编辑的导览点位是否已上传音乐
  1852. if (!this.editingFolderLi && tourAudio[0].files.length > 0) { //有input文件
  1853. $(".edit-loading").removeClass('hide');
  1854. var musicName = $('#tourItemEdit .mediaUpload .title').text();
  1855. new Promise( (resolve, reject)=>{
  1856. uploadMiuse(tourAudio[0].files[0], function(res) {
  1857. resolve(res.data);
  1858. })
  1859. } ).then( (src)=>{
  1860. var audio = new Audio();
  1861. audio.src = src;
  1862. audio.onloadedmetadata = ()=>{
  1863. var srcArr = src.split('/'); // 对返回的src进行处理, 去掉前面域名, 尽量避免修改main.js
  1864. srcArr[0] = '';
  1865. src = srcArr.join('/');
  1866. //that.tourAudio[sid] = {
  1867. this.editingItemLi.tourData.musicInfo = {
  1868. "name": musicName,
  1869. "music": '/' + src,
  1870. "time": Math.round(audio.duration * 1000 + 1000)
  1871. }
  1872. done()
  1873. }
  1874. })
  1875. }else done()
  1876. }
  1877. /**
  1878. * @author fyz 2019.07.31
  1879. * @description uploadGuide方法新增参数renew状态码, 表示是否重新录制当前导览, 新增targetTourPoint, 记录当前的导览点元素
  1880. */
  1881. EditGuide.prototype.uploadGuide = function(urlData, guide, renew, insideFolder) {
  1882. var that = this;
  1883. uploadImg(urlData, function(rs) {
  1884. if (rs.code === 0) {
  1885. //var editGuide = new EditGuide();
  1886. var sid = rs.data.substring(rs.data.lastIndexOf('/') + 1, rs.data.lastIndexOf('.'));
  1887. var thumbnail_signed_src = rs.data;
  1888. var args = JSON.parse("{" + guide + "}");
  1889. args.sid = sid;
  1890. args.name = '';
  1891. args.thumbnail_signed_src = thumbnail_signed_src;
  1892. args.metadata = JSON.stringify({
  1893. camera_mode: args.metadata.camera_mode,
  1894. camera_position: {
  1895. x: args.metadata.camera_position[0],
  1896. y: args.metadata.camera_position[1],
  1897. z: args.metadata.camera_position[2]
  1898. },
  1899. camera_quaternion: {
  1900. x: args.metadata.camera_quaternion[0],
  1901. y: args.metadata.camera_quaternion[1],
  1902. z: args.metadata.camera_quaternion[2],
  1903. w: args.metadata.camera_quaternion[3]
  1904. },
  1905. ortho_zoom: args.metadata.ortho_zoom,
  1906. scan_id: args.metadata.scan_id || "outside",
  1907. //这个"outside"不能随便改成别的
  1908. /* final_angle: 110,
  1909. is_ortho: false, */
  1910. zoom: args.metadata.zoom // fyz zoom是内部计算的zoomLevel, 乘以系数1.06才是实际缩放倍数
  1911. })
  1912. if (renew/* && target */) { // 重新录制导览
  1913. // 更新数据
  1914. var musicInfo = insideFolder || that.editingItemLi.tourData.musicInfo;
  1915. musicInfo && (args.musicInfo = musicInfo);
  1916. $(that.editingItemLi).find('#tourBg')[0].style.backgroundImage = 'url(' + args.thumbnail_signed_src + ')';
  1917. //args.name = insideFolder $('#tourItemEdit').find('#tourNameInput').val()
  1918. /* var oldId = target.closest('li')[0].data.sid;
  1919. that.tourAudio[args.sid] = that.tourAudio[oldId];
  1920. // 新生成的id指向以前的导览音频
  1921. delete that.tourAudio[oldId];
  1922. // 删除导览音频中的旧导览id */
  1923. that.editingItemLi.tourData = args;
  1924. //target.text(args.name); // 更新导览列表中的导览名称 //不改名字
  1925. //$('#tourItemEdit').find('#tourNameInput').val(args.name); // 修改输入框内容
  1926. } else {
  1927. var $li = $(that.getItemDom(args.name, args.thumbnail_signed_src));
  1928. $li[0].tourData = args;
  1929. var $ul = insideFolder ? $("#tourItemList>ul") : $("#tourList>ul")
  1930. $ul.append($li);
  1931. reIndexTourList($ul[0])
  1932. }
  1933. }
  1934. })
  1935. }
  1936. EditGuide.prototype.getSavingInfo = function(){
  1937. var data = []
  1938. Array.from($("#tourList ul li")).forEach(dom=>{
  1939. if(dom.classList.contains("guideItem")){//item
  1940. dom.tourData.name = $(dom).find('.guide-name').text()
  1941. data.push(dom.tourData)
  1942. }else{//folder
  1943. var dataFolder = dom.tourData;
  1944. dataFolder.name = $(dom).find('.title').text()
  1945. dataFolder.locations = dom.tourItemDoms.map(li => li.tourData )
  1946. data.push(dataFolder)
  1947. }
  1948. })
  1949. return data
  1950. }
  1951. /* -- 以下是一些公用的方法 -- */
  1952. //限制大小
  1953. var restrictedSize = function(file, _size) {
  1954. //限制大小不大于8m
  1955. var fileSize = 0;
  1956. var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  1957. if (isIE && !file) {
  1958. var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
  1959. var _file = fileSystem.GetFile(filepath);
  1960. fileSize = _file.Size;
  1961. } else {
  1962. fileSize = file.size;
  1963. }
  1964. var size = fileSize / 1024;
  1965. var RSize = _size * 1024;
  1966. if (size > RSize) {
  1967. alert("文件不能大于" + _size + "M");
  1968. return false;
  1969. }
  1970. if (size <= 0) {
  1971. alert("文件大小不能为0M!");
  1972. return false;
  1973. }
  1974. return true
  1975. }
  1976. //上传音乐
  1977. var uploadMiuse = function(file, callback) {
  1978. uploadFile(file, 'audio', callback);
  1979. }
  1980. $(".toolRight .music .itemTitle span").text(`背景音乐 (<${_musicMaxWeight}M)`)
  1981. //上传图片
  1982. function uploadImg(urlData, callback, fileName) {
  1983. //console.log('urlData',urlData);
  1984. if(!fileName)fileName = getRandomSid() + '.jpg'
  1985. var bytes = window.atob(urlData.split(',')[1]);
  1986. //去掉url的头,并转换为byte
  1987. //处理异常,将ascii码小于0的转换为大于0
  1988. var ab = new ArrayBuffer(bytes.length);
  1989. var ia = new Uint8Array(ab);
  1990. for (var i = 0; i < bytes.length; i++) {
  1991. ia[i] = bytes.charCodeAt(i);
  1992. }
  1993. var blob = new Blob([ab],{
  1994. type: 'image/jpeg',
  1995. });
  1996. uploadFile(blob, 'hot/images', callback, fileName);
  1997. }
  1998. //上传文件
  1999. function uploadFile(file, type, callback, fileName) {
  2000. $(".edit-loading").removeClass("hide");
  2001. var formData = new FormData()
  2002. formData.append('name', number)
  2003. formData.append('dir', type)
  2004. formData.append('random', true)
  2005. //formData.append('file', file)
  2006. formData.append("file", file, fileName);
  2007. let url = cmp ? ('/api/scene/upload/' + number) : ('/manage/scene/upload/' + number)
  2008. $.ajax({
  2009. url: ceshi + url,
  2010. data: formData,
  2011. headers: {
  2012. token: token
  2013. },
  2014. dataType: 'json',
  2015. type: 'POST',
  2016. cache: false,
  2017. //上传文件无需缓存
  2018. processData: false,
  2019. //用于对data参数进行序列化处理 这里必须false
  2020. contentType: false,
  2021. //必须
  2022. success: function(rs) {
  2023. if (rs.code === 5001) {
  2024. alert('请重新登录')
  2025. localStorage.dcj_token = ''
  2026. location.reload()
  2027. }
  2028. callback(rs, file);
  2029. $(".edit-loading").addClass("hide");
  2030. }
  2031. })
  2032. }
  2033. function _animate(prevRect, target) {
  2034. var ms = 300;
  2035. if (ms) {
  2036. var currentRect = target.getBoundingClientRect();
  2037. if (prevRect.nodeType === 1) {
  2038. prevRect = prevRect.getBoundingClientRect();
  2039. }
  2040. _css(target, 'transition', 'none');
  2041. _css(target, 'transform', 'translate3d(' + (prevRect.left - currentRect.left) + 'px,' + (prevRect.top - currentRect.top) + 'px,0)');
  2042. target.offsetWidth;
  2043. // 触发重绘
  2044. //放在timeout里面也可以
  2045. // setTimeout(function() {
  2046. // _css(target, 'transition', 'all ' + ms + 'ms');
  2047. // _css(target, 'transform', 'translate3d(0,0,0)');
  2048. // }, 0);
  2049. _css(target, 'transition', 'all ' + ms + 'ms');
  2050. _css(target, 'transform', 'translate3d(0,0,0)');
  2051. clearTimeout(target.animated);
  2052. target.animated = setTimeout(function() {
  2053. _css(target, 'transition', '');
  2054. _css(target, 'transform', '');
  2055. target.animated = false;
  2056. }, ms);
  2057. }
  2058. }
  2059. //给元素添加style
  2060. function _css(el, prop, val) {
  2061. var style = el && el.style;
  2062. if (style) {
  2063. if (val === void 0) {
  2064. if (document.defaultView && document.defaultView.getComputedStyle) {
  2065. val = document.defaultView.getComputedStyle(el, '');
  2066. } else if (el.currentStyle) {
  2067. val = el.currentStyle;
  2068. }
  2069. return prop === void 0 ? val : val[prop];
  2070. } else {
  2071. if (!(prop in style)) {
  2072. prop = '-webkit-' + prop;
  2073. }
  2074. style[prop] = val + (typeof val === 'string' ? '' : 'px');
  2075. }
  2076. }
  2077. }
  2078. function upload($files, type, cb) {
  2079. var length = $files.length
  2080. var rcount = 0
  2081. var result = []
  2082. Array.from($files).forEach(function(dFile, index) {
  2083. //a 标签的success 是用来判断是否是已经上传过的文件
  2084. //attr-thum 属性是视频的图片
  2085. //videoURL 是判断是否有视频
  2086. var $file = $(dFile)
  2087. var $image = type == 'videos' ? $file.find('img.play-video') : $file.find('img')
  2088. if ($file.hasClass('success')) {//已经上传过,有链接
  2089. if ($file.attr('attr-thum')) {//视频的封面
  2090. result[index] = $file.attr('attr-thum')
  2091. } else if ($image.attr('videoURL')) {//视频
  2092. result[index] = $image.attr('videoURL')
  2093. } else {
  2094. result[index] = $image.attr('src')
  2095. }
  2096. return success(++rcount);
  2097. } else {
  2098. switch ($file[0].localName) {
  2099. case "input":
  2100. dFile = $file[0]
  2101. break;
  2102. case "span"://封面
  2103. dFile = $file.find('input')[0];
  2104. break;
  2105. case "a"://重传的图or视频
  2106. dFile = {files:[$file[0].file]}
  2107. //dFile = $file.find('input')[0];
  2108. break;
  2109. default:
  2110. dFile = $file.closest("li").find('.upload input')[0];
  2111. break;
  2112. }
  2113. // dFile = $file[0].localName === "input" ? $file[0] : $file[0].localName === "span" ? $file.find('input')[0] : $file.closest("li").find('.upload input')[0];
  2114. }
  2115. var file = (dFile.files && dFile.files[0]) || '';
  2116. if (!file)
  2117. return success(++rcount);
  2118. uploadFile(file, 'hot/' + type, function(rs) {
  2119. //似乎所有图保存路径都是这个hot/前缀。图地址 :"场景id/edit/重新生成的文件名.原后缀", 展示页面也是。
  2120. if (rs.code === 0) {
  2121. result[index] = rs.data
  2122. }
  2123. ;success(++rcount);
  2124. })
  2125. })
  2126. //判断当前队列元素是否处理成功
  2127. function success() {
  2128. if (rcount === length) {
  2129. cb(result)
  2130. }
  2131. }
  2132. success()
  2133. }
  2134. function getIndex(el) {
  2135. let index = 0;
  2136. if (!el || !el.parentNode) {
  2137. return -1;
  2138. }
  2139. while (el && (el = el.previousElementSibling)) {
  2140. index++;
  2141. }
  2142. return index;
  2143. }
  2144. dataURLtoBlob = function(dataurl) {
  2145. //将base64转换blob
  2146. var arr = dataurl.split(',')
  2147. , mime = arr[0].match(/:(.*?);/)[1]
  2148. , bstr = atob(arr[1])
  2149. , n = bstr.length
  2150. , u8arr = new Uint8Array(n);
  2151. while (n--) {
  2152. u8arr[n] = bstr.charCodeAt(n);
  2153. }
  2154. return new Blob([u8arr],{
  2155. type: mime
  2156. });
  2157. }
  2158. ;
  2159. //=========================
  2160. var eachMaxWeights = {
  2161. //大小限制
  2162. "photo": 10,
  2163. "video": 1000,//50, expand size for overlayVideo
  2164. //20,
  2165. "audio": 10 //5
  2166. }
  2167. var supportTypes = {
  2168. //支持后缀
  2169. "photo": ["jpg", "png", "jpeg", "bmp", "gif"],
  2170. "audio": ["mp3", "aac", "ogg", "wav"/* , "m4a" */
  2171. ],
  2172. "video": ["mp4", "mov"/* ,"webm", "rmvb", "wmv" */
  2173. ]//ios:mov
  2174. }
  2175. function getExt(name) {
  2176. //后缀
  2177. if (name.indexOf('.') > -1) {
  2178. var a = name.split(".");
  2179. return a.pop();
  2180. } else {
  2181. return '';
  2182. }
  2183. }
  2184. function detectType(fileName) {
  2185. //检测文件后缀类型
  2186. console.log("名:" + fileName)
  2187. var ext = getExt(fileName);
  2188. console.log("后缀:" + ext)
  2189. //不一定所有浏览器都可以
  2190. var type;
  2191. //仅能根据后缀判断类型,尽管后缀可能被修改。 其他方法如file.type和base64开头的字符串均是根据后缀。
  2192. for (var i in supportTypes) {
  2193. if (supportTypes[i].indexOf(ext.toLowerCase()) > -1) {
  2194. type = i;
  2195. break;
  2196. }
  2197. }
  2198. if (type) {
  2199. return type;
  2200. } else {
  2201. return false;
  2202. }
  2203. }
  2204. //手机上的相片会不会太大?
  2205. var detectWeights = function(file, type) {
  2206. //检测大小
  2207. var size = file.size / 1024 / 1024;
  2208. console.log("weight" + size)
  2209. var over;
  2210. if (size > eachMaxWeights[type]) {
  2211. over = Math.ceil(size * 100) / 100;
  2212. }
  2213. return over;
  2214. }
  2215. var exitUpload = function(input) {
  2216. $('.waiting').removeClass('showloading');
  2217. input.value = "";
  2218. }
  2219. var inputMedia = function(options, type, e) {
  2220. var input = e.target;
  2221. if (!window.FileReader) {
  2222. alert('您的浏览器不支持上传文件');
  2223. exitUpload(input);
  2224. return;
  2225. } else if (e.target.files.length === 0) {
  2226. /* exitUpload(input); */
  2227. return;
  2228. }
  2229. $('.waiting').addClass('showloading');
  2230. var file = e.target.files[0];
  2231. var elemType = type;
  2232. var inputType = detectType(file.name);
  2233. var chType = {
  2234. "photo": '图片',
  2235. "video": '视频',
  2236. "audio": '音乐'
  2237. }
  2238. var overWeight = detectWeights(file, inputType);
  2239. if (elemType) {
  2240. //有指定其中一种类型
  2241. if (inputType != elemType) {
  2242. alert("您选择的不是浏览器支持的" + chType[elemType] + '文件,请重新选择');
  2243. exitUpload(e.target);
  2244. return;
  2245. }
  2246. } else {
  2247. if (!options.enableTypes.includes(inputType)) {
  2248. var text = "";
  2249. options.enableTypes.forEach((type,index)=>{
  2250. text += ((index != 0 ? " / " : "") + chType[elemType])
  2251. }
  2252. )
  2253. alert("您选择的不是浏览器支持的" + text + '文件,请重新选择');
  2254. exitUpload(e.target);
  2255. return;
  2256. }
  2257. }
  2258. if (overWeight) {
  2259. alert(`文件过大(${overWeight}兆),不能大于${eachMaxWeights[inputType]} 兆`)
  2260. exitUpload(e.target);
  2261. return;
  2262. }
  2263. var loadError = function() {
  2264. exitUpload(e.target);
  2265. alert(`文件出错, 无法加载此${chType[inputType]}文件。 文件可能损坏,或者浏览器不支持,或者后缀与文件不匹配。建议在IE以外的浏览器上传`)
  2266. }
  2267. deal();
  2268. function deal(fi) {
  2269. console.log('开始deal文件')
  2270. var reader = new FileReader();
  2271. //reader.name = file.name;
  2272. file = fi || file;
  2273. reader.readAsDataURL(file);
  2274. reader.onload = function(evt) {
  2275. var blob = dataURLtoBlob(evt.target.result);
  2276. var blobSrc = window.URL.createObjectURL(blob);
  2277. if (inputType == "photo") {
  2278. /* EXIF.getData(file, function () {
  2279. //获取相片旋转
  2280. EXIF.getAllTags(this);
  2281. var orient = EXIF.getTag(this, 'Orientation');
  2282. var img = new Image();
  2283. img.src = evt.target.result;
  2284. img.onload = function (e) { //这时img才有宽高,才能赋予texture宽高
  2285. var smallerImg = CompressImg(e.target, {
  2286. weight: blob.size,
  2287. maxWeight: 0.5 * 1024 * 1024,
  2288. maxSize: 1480
  2289. });
  2290. //最大500k
  2291. smallerImg.onload = function () {
  2292. var f = function (resultImg) {//处理结束回调
  2293. options.photoDone(resultImg)
  2294. $('.waiting').removeClass('showloading');
  2295. }
  2296. Rotate(smallerImg, orient, f)
  2297. window.URL.revokeObjectURL(blobSrc);
  2298. }
  2299. }
  2300. .bind(this)
  2301. img.onerror = loadError;
  2302. }); */
  2303. var img = new Image();
  2304. img.src = blobSrc;
  2305. img.base64Src = evt.target.result;
  2306. img.file = file;
  2307. img.onload = function(e) {
  2308. options.photoDone(img)
  2309. $('.waiting').removeClass('showloading');
  2310. }
  2311. } else if (inputType == "video") {
  2312. var video = $('<video controls="controls" x5-playsinline="" webkit-playsinline="true" playsinline="true" controlslist="nodownload"></video>')[0]
  2313. video.setAttribute("crossOrigin", 'Anonymous')
  2314. //要在src设置好前解决跨域
  2315. $(video).on('contextmenu', function() {
  2316. return false;
  2317. });
  2318. //禁止右键点击出现选项(尤其是下载选项)
  2319. $(video).attr('src', blobSrc);
  2320. //华为无法使用blobSrc,否则加载不出来
  2321. //$(video).attr('src', evt.target.result);
  2322. video.base64Src = evt.target.result;
  2323. var hasload = false;
  2324. var error = false;
  2325. var up = function() {
  2326. if (hasload)
  2327. return;
  2328. hasload = true;
  2329. options.videoDone(file, video)
  2330. $('.waiting').removeClass('showloading');
  2331. }
  2332. video.addEventListener('loadeddata', function(e) {
  2333. up()
  2334. })
  2335. //video.onerror = loadError;
  2336. video.onerror = function(e) {
  2337. console.log('error')
  2338. error = true;
  2339. loadError();
  2340. //将mp4改成mov后缀会error
  2341. }
  2342. } else if (inputType == "audio") {
  2343. //林俊波 new Howl For IE&Safari:
  2344. var sound = new Howl({
  2345. src: [blobSrc],
  2346. format: ["mp3"]
  2347. });
  2348. // Clear listener after first call.
  2349. sound.once('load', function() {
  2350. console.log('loaded sound')
  2351. sound.unload()
  2352. console.log("audio.onloadeddata");
  2353. var audio = new Audio;
  2354. audio.controls = "controls";
  2355. audio.src = blobSrc;
  2356. audio.base64Src = evt.target.result;
  2357. options.audioDone(file, audio)
  2358. $('.waiting').removeClass('showloading');
  2359. //}
  2360. });
  2361. sound.once('loaderror', function() {
  2362. loadError.apply(this, arguments)
  2363. console.log('loaderror sound')
  2364. });
  2365. // Fires when the sound finishes playing.
  2366. sound.on('end', function() {
  2367. console.log('Finished sound');
  2368. });
  2369. }
  2370. }
  2371. }
  2372. e.target.value = "";
  2373. //更改value会触发change
  2374. }
  2375. .bind(player)
  2376. //滑动条控件
  2377. var SlideBar = function(o) {
  2378. var scope = this;
  2379. this.name = o.name;
  2380. this.value = o.value;
  2381. //初始值
  2382. this.min = o.min != void 0 ? o.min : 0;
  2383. this.max = this.oriMax = o.max != void 0 ? o.max : 100;
  2384. this.noValue = o.noValue;
  2385. //是否数值输入
  2386. this.precision = o.precision;
  2387. //精度 保留几位小数
  2388. var div = $('<div><div class="Main"><div class="scrollBar"><div class="scroll_Track"></div><div class="scroll_Thumb"></div></div>' + (o.noValue ? '' : '<div class="BarTxt"><input class="scrollBarTxt"></div></div>'))
  2389. div.addClass('slider')
  2390. if (o.unitStr) {
  2391. div.find(".BarTxt").append($('<span>' + o.unitStr + '</span>'));
  2392. }
  2393. o.root.append(div);
  2394. this.line = $(".scrollBar", div);
  2395. this.knot = $(".scroll_Thumb", div);
  2396. o.noValue || (this.textArea = $(".scrollBarTxt", div));
  2397. this.track = $(".scroll_Track", div);
  2398. this.unitStr = o.unitStr;
  2399. //unitStr是单位字符串,比如角度的°。不能是数字
  2400. this.onchange = o.onchange;
  2401. this.percent = null;
  2402. this.dragStart = false;
  2403. this.offsetToBody = null;
  2404. this.getOffset();
  2405. this.checkError();
  2406. this.percent = this.getPercent();
  2407. o.noValue || this.displayValue();
  2408. this.moveKnot();
  2409. this.knotWidth = 0;
  2410. this.lineWidth = 0;
  2411. //this.waitValue;//等待要触发事件的值,防止崩溃
  2412. this.avoidCrash = o.avoidCrash;
  2413. this.realMax = !this.noValue ? o.realMax : null;
  2414. //如果传入realMax,代表可以通过输入数字修改最大值范围,最大值不可以超过realMax。
  2415. this.scrollUnit = (scope.max - scope.min) * 0.001;
  2416. if (this.precision != void 0) {
  2417. var prec = Math.pow(10, -this.precision);
  2418. this.scrollUnit < prec && (this.scrollUnit = prec);
  2419. } else {
  2420. //默认化为整数
  2421. this.scrollUnit < 1 && (this.scrollUnit = 1);
  2422. }
  2423. this.dragStartEvent = o.dragStartEvent;
  2424. this.line.on("mousedown touchstart", function(event) {
  2425. scope.dragStart = true;
  2426. scope.dragChange(event);
  2427. if (scope.dragStartEvent)
  2428. scope.dragStartEvent()
  2429. //if(o.avoidCrash && isMobile)scope.dealInterval();
  2430. });
  2431. !window.isMobile && this.line.on("mousewheel DOMMouseScroll wheel", function(event) {
  2432. event.preventDefault();
  2433. var v = event.originalEvent.deltaY > 0 ? -scope.scrollUnit : scope.scrollUnit;
  2434. scope.setValue(scope.value + v);
  2435. });
  2436. this.dragEndEvent = o.dragEndEvent;
  2437. var stop = function() {
  2438. if (scope.dragStart) {
  2439. scope.dragStart = false;
  2440. if (scope.dragEndEvent)
  2441. scope.dragEndEvent()
  2442. }
  2443. }
  2444. $(document).on("mouseup touchend", stop)
  2445. /* isMobile || */
  2446. $("#player").on("mouseup", stop)
  2447. var lastChangeTime = 0;
  2448. $(document).on("mousemove touchmove", function() {
  2449. if (scope.dragStart) {
  2450. /* if(isMobile && o.avoidCrash){
  2451. scope.lastDragEvent = event;
  2452. }else */
  2453. scope.dragChange(event);
  2454. }
  2455. })
  2456. o.noValue || this.textArea.on("change", function() {
  2457. var v = parseFloat(scope.textArea.val());
  2458. if (v != v)
  2459. //NaN
  2460. return;
  2461. scope.setValueFromOutside(v);
  2462. });
  2463. window.addEventListener("resize",()=>{
  2464. if(this.line[0].clientWidth){
  2465. this.getOffset()
  2466. this.moveKnot();
  2467. }
  2468. })
  2469. }
  2470. SlideBar.prototype.dealInterval = function() {
  2471. this.interval = setInterval(function() {
  2472. this.lastDragEvent && this.dragChange(this.lastDragEvent);
  2473. this.lastDragEvent = null
  2474. if (!this.dragStart)
  2475. clearInterval(this.interval)
  2476. }
  2477. .bind(this), 90)
  2478. }
  2479. SlideBar.prototype.changeLimit = function(o) {
  2480. if (o.min)
  2481. this.min = o.min;
  2482. if (o.max)
  2483. this.max = o.max;
  2484. }
  2485. SlideBar.prototype.getOffset = function() {
  2486. //为了检测鼠标位置需要获得相对body的offset
  2487. var left = this.line[0].offsetLeft;
  2488. var element = this.line[0];
  2489. while (element = element.offsetParent) {
  2490. left += element.offsetLeft;
  2491. }
  2492. this.offsetToBody = (left == 0) ? (this.offsetToBody || 0) : left;
  2493. //如果left为0,很可能是它不可见,那么最好使用旧的offsetToBody
  2494. }
  2495. SlideBar.prototype.InitOffset = function() {
  2496. //如果一开始scroller没有显示,要在显示时获取一下offset
  2497. this.getOffset();
  2498. this.getWidth();
  2499. this.moveKnot();
  2500. }
  2501. SlideBar.prototype.checkError = function() {
  2502. if (this.min >= this.max) {
  2503. console.log("scrollbar值有误 " + name);
  2504. return;
  2505. }
  2506. }
  2507. SlideBar.prototype.getPercent = function() {
  2508. return (this.value - this.min) / (this.max - this.min);
  2509. }
  2510. SlideBar.prototype.displayValue = function(value) {
  2511. //this.textArea.val(this.value + (this.unitStr ? " " + this.unitStr : ""));
  2512. if (value != void 0)
  2513. this.value = value;
  2514. this.textArea.val(this.value)
  2515. }
  2516. SlideBar.prototype.getWidth = function() {
  2517. this.knotWidth = this.knot.width();
  2518. this.lineWidth = this.line.width() - this.knotWidth
  2519. }
  2520. SlideBar.prototype.moveKnot = function() {
  2521. //this.getWidth();
  2522. var width = this.percent * this.lineWidth;
  2523. this.knot.css('left', width + "px")
  2524. if (this.track)
  2525. this.track.css('width', (width + this.knotWidth / 2) + "px")
  2526. }
  2527. SlideBar.prototype.bind = function(f) {
  2528. this.onchange = f;
  2529. }
  2530. SlideBar.prototype.setValue = function(v, noEvent, changeMax) {
  2531. //设置数值并改变knot位置 noEvent为true的话就可以不触发回调函数,仅仅改变显示
  2532. //if(this.value==v)return; //因为换选材质需要执行后面onchange才会带动preview的改变,所以这里一样还是执行,而拉动滑动条的部分值不变就不执行
  2533. if (this.precision != void 0) {
  2534. this.value = parseFloat(v.toFixed(this.precision))
  2535. } else {
  2536. //默认化为整数
  2537. this.value = Math.round(v);
  2538. }
  2539. if (changeMax && this.realMax != void 0) {
  2540. if (this.value > this.oriMax) {
  2541. this.value = Math.min(this.value, this.realMax);
  2542. this.changeLimit({
  2543. max: this.value
  2544. })
  2545. } else {
  2546. this.changeLimit({
  2547. max: this.oriMax
  2548. })
  2549. }
  2550. }
  2551. this.percent = this.getPercent();
  2552. var makeit = true;
  2553. if (this.onchange && !noEvent) {
  2554. var result = this.onchange(this.value);
  2555. //如果执行的函数不允许这个值,就不能变
  2556. if (result === false) {
  2557. makeit = false;
  2558. }
  2559. }
  2560. if (makeit) {
  2561. this.moveKnot();
  2562. //console.log("SlideBarV-"+this.name + " : "+this.value)
  2563. this.noValue || this.displayValue();
  2564. }
  2565. }
  2566. SlideBar.prototype.dragChange = function(event) {
  2567. //拖动时触发 计算数值
  2568. //this.getWidth();
  2569. //if(!this.offsetToBody || isNaN(this.offsetToBody)this.getOffset();
  2570. if (event.clientX != void 0) {
  2571. this.percent = (event.clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
  2572. } else {
  2573. if (event.touches != void 0) {
  2574. this.percent = (event.touches[0].clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
  2575. } else
  2576. this.percent = (event.originalEvent.touches[0].clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
  2577. }
  2578. if (this.percent < 0)
  2579. this.percent = 0;
  2580. else if (this.percent > 1)
  2581. this.percent = 1;
  2582. //var v = this.percent * this.max;
  2583. var v = this.percent * (this.max - this.min) + this.min;
  2584. //var v = Math.round(this.percent * this.max * 10)/10; //精度为0.1
  2585. if (this.value == v)
  2586. return;
  2587. this.setValue(v);
  2588. }
  2589. SlideBar.prototype.setValueFromOutside = function(v) {
  2590. //外面的事件触发的
  2591. if (this.line.width() == 0)
  2592. return;
  2593. //不可见就不执行。
  2594. //v = Math.round(v*10)/10;
  2595. if (this.realMax != void 0) {
  2596. v = THREE.Math.clamp(v, this.min, this.realMax);
  2597. if (v > this.max)
  2598. this.changeLimit({
  2599. max: v
  2600. });
  2601. } else
  2602. v = THREE.Math.clamp(v, this.min, this.max);
  2603. this.setValue(v);
  2604. }
  2605. //-----------------------------------------------------
  2606. var LineDraw = {
  2607. createLine: function(posArr, o) {
  2608. var e = new THREE.BufferGeometry
  2609. , p = new Float32Array(6);
  2610. e.addAttribute("position", new THREE.BufferAttribute(p,3));
  2611. //这句新旧版写法不同 旧版这样:e.addAttribute("position",Float32Array,2,3);
  2612. var p = e.attributes.position.array;
  2613. for (var i = 0; i < 2; i++) {
  2614. p[i * 3] = posArr[i].x;
  2615. p[i * 3 + 1] = posArr[i].y;
  2616. p[i * 3 + 2] = posArr[i].z;
  2617. }
  2618. var mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"]({
  2619. linewidth: o.width || 1,
  2620. //windows无效。 似乎mac/ios上粗细有效 ?
  2621. color: o.color || defaultColor,
  2622. transparent: o.dontAlwaysSeen ? false : true,
  2623. depthTest: o.dontAlwaysSeen ? true : false
  2624. })
  2625. var line = new THREE.Line(e,mat);
  2626. line.renderOrder = o.renderOrder || 4
  2627. //同tagStem; //如果不加高,可能会部分被model遮住
  2628. return line;
  2629. }
  2630. }
  2631. var toPrecision = function(e, t) {
  2632. function i(e, t) {
  2633. var i = Math.pow(10, t);
  2634. return Math.round(e * i) / i
  2635. }
  2636. if (e instanceof Array) {
  2637. for (var n = 0; n < e.length; n++)
  2638. e[n] = i(e[n], t);
  2639. return e
  2640. }
  2641. return i(e, t)
  2642. }
  2643. var transformControls;
  2644. var initTransformCtl = function(THREE) {
  2645. TransformControls.init(THREE)
  2646. TransformControls.prototype.transCtlChangeMode = function(mode) {
  2647. //if(!this.editing)return;
  2648. if (mode && this.mode != mode) {
  2649. this.mode = mode;
  2650. }
  2651. }
  2652. ,
  2653. transformControls = new TransformControls(player.camera,player.domElement,{
  2654. player: player,
  2655. dontHideWhenFaceCamera: true,
  2656. scaleAxis: ["x", "y"],
  2657. //隐藏了z轴。虽然参数没用上
  2658. NoScaleZ: true //整体缩放时只缩放xy轴。
  2659. });
  2660. transformControls.space = 'local'//为了在当前方向上平移
  2661. transformControls.setSize(1.5)
  2662. player.model.add(transformControls)
  2663. $(".MenuOptions[name='transform'] li").on("click", (e)=>{
  2664. transformControls.transCtlChangeMode($(e.target).attr("index"))
  2665. })
  2666. }
  2667. var EditOverlay = {
  2668. editing: false,
  2669. overlayMaxCount: 10,
  2670. scroller: {
  2671. videoDepth: new SlideBar({
  2672. root: $('#videoDepth').eq(0),
  2673. value: settings.overlay.depth * 100,
  2674. min: 0 * 100,
  2675. max: 1 * 100,
  2676. name: "videoDepth",
  2677. unitStr: "cm",
  2678. avoidCrash: true,
  2679. onchange: function(s) {
  2680. if (s == 0) {
  2681. EditOverlay.editPlane.addBox(false)
  2682. } else {
  2683. EditOverlay.editPlane.addBox(true)
  2684. EditOverlay.editPlane.scale.z = s / 100 / settings.overlay.depth;
  2685. }
  2686. },
  2687. dragEndEvent: function() {
  2688. }
  2689. })
  2690. },
  2691. panoPosSwitch : $('#setOverlayPosForPano input') // 当前漫游点独立调整位置开关
  2692. ,
  2693. init: function(THREE) {
  2694. var mat = new THREE.MeshBasicMaterial({
  2695. wireframe: true,
  2696. opacity: 0.5,
  2697. color: "#57e4f3",
  2698. transparent: true
  2699. })
  2700. var wireframeModel = this.wireframeModel = new THREE.Object3D;
  2701. wireframeModel.name = 'wireframeModel'
  2702. player.model.chunks.forEach((mesh)=>{
  2703. var chunk = mesh.clone();
  2704. chunk.material = mat;
  2705. wireframeModel.add(chunk)
  2706. }
  2707. )
  2708. wireframeModel.visible = false
  2709. player.model.add(wireframeModel)
  2710. //------------------------------
  2711. this.panoPosSwitch.on("change", this.panoPosSwitchOnChange.bind(this))
  2712. $('.overlay .addBtn button').on("click", this.beginToAddPlane.bind(this))
  2713. $("#overlayProp a.close").on("click", ()=>{
  2714. this.closeOverlayPanel("cancel")
  2715. }
  2716. )
  2717. $("#overlayProp button.submit").on("click", (e)=>{
  2718. this.SaveOverlay()
  2719. }
  2720. )
  2721. $("#overlayProp button.delete").on("click", (e)=>{
  2722. this.DeleteOverlay();
  2723. }
  2724. )
  2725. $('#overlayUpload [name="useImgRatio"] button').on("click", this.useImgRatio.bind(this));
  2726. var uploadInputs = {
  2727. video : $('<input type="file" style="display:none" accept="video/*"></input>'),
  2728. photo : $('<input type="file" style="display:none" accept="image/*"></input>')
  2729. }
  2730. $('#overlayUpload [name="upload"] button').on('click', ()=>{
  2731. uploadInputs[this.editType].click()
  2732. })
  2733. uploadInputs.video.on("change", (e)=>{
  2734. inputMedia({
  2735. enableTypes: [this.editType ],
  2736. videoDone: (file,video)=>{
  2737. var plane = this.editPlane.plane
  2738. $(video).css('width', '100%')
  2739. $(video).css('height', '100%')
  2740. plane.material.map = new THREE.VideoTexture(video);
  2741. plane.material.map.image.play();
  2742. plane.material.map.minFilter = THREE.LinearFilter;
  2743. this.editPlane.overlayType = "video";
  2744. $('#overlayUpload .preview video').remove();
  2745. //$('#overlayUpload .preview').css('background-image',"").append($(video));
  2746. video.autoplay = true;
  2747. video.loop = true;
  2748. video.volume = 0
  2749. video.muted = true
  2750. this.useImgRatio()
  2751. //自适应比例
  2752. this.editPlane.file = file;
  2753. plane.material.opacity = 1;
  2754. plane.material.color = new THREE.Color(1,1,1)
  2755. plane.material.needsUpdate = true;
  2756. }
  2757. }, "video", e);
  2758. }
  2759. )
  2760. uploadInputs.photo.on("change", (e)=>{
  2761. inputMedia({
  2762. enableTypes: [this.editType ],
  2763. photoDone: (photo)=>{
  2764. var plane = this.editPlane.plane
  2765. /* $(video).css('width', '100%')
  2766. $(video).css('height', '100%') */
  2767. plane.material.map = new THREE.Texture();
  2768. plane.material.map.image = photo
  2769. plane.material.map.needsUpdate = !0
  2770. plane.material.map.minFilter = THREE.LinearFilter;
  2771. this.editPlane.overlayType = "photo";
  2772. $('#overlayUpload .preview video').remove();
  2773. //$('#overlayUpload .preview').css('background-image',"").append($(video));
  2774. this.useImgRatio()
  2775. //自适应比例
  2776. this.editPlane.file = photo.file;
  2777. plane.material.opacity = 1;
  2778. plane.material.color = new THREE.Color(1,1,1)
  2779. plane.material.needsUpdate = true;
  2780. }
  2781. }, "photo", e);
  2782. }
  2783. )
  2784. player.overlayGroup.children.forEach((overlay)=>{
  2785. if(!overlay.plane.material.map || !overlay.plane.material.map.image){
  2786. overlay._loadDones = [()=>{this.getOverlayInfo(overlay)}]
  2787. }
  2788. else {
  2789. this.getOverlayInfo(overlay)
  2790. }
  2791. this.addToList(overlay)
  2792. }
  2793. )
  2794. },
  2795. enter: function() {
  2796. this.editing = true;
  2797. this.wireframeModel.visible = true;
  2798. },
  2799. leave: function() {
  2800. if (!this.editing)
  2801. return;
  2802. this.editing = false
  2803. $("#overlayProp a.close").click();
  2804. this.endAddPlane();
  2805. this.wireframeModel.visible = false;
  2806. },
  2807. switchEditType : function(type){
  2808. this.editType = type;
  2809. $('#overlayUpload [name="upload"] button').text(type == 'video' ? "上传视频" : "上传图片")
  2810. $('#overlayUpload .preview span').text(type == 'video' ? "支持MP4、MOV等,<20M" : "支持jpg、png等,<20M");
  2811. },
  2812. beginToAddPlane: function(event) {
  2813. this.switchEditType($(event.target).attr("data-type"))
  2814. player.reticule.visible = false;
  2815. this.objCursorType = 'overlay';
  2816. player.currentCursor = 'url(images/edit/box_video.png), auto'
  2817. $('#player').css('cursor', player.currentCursor)
  2818. $('.overlay .addBtn button').addClass("unable")
  2819. //可以加多个视频时的按钮
  2820. },
  2821. endAddPlane: function() {
  2822. this.objCursorType = null;
  2823. player.currentCursor = '';
  2824. $('#player').css('cursor', '')
  2825. $('.overlay .addBtn button').removeClass("unable")
  2826. player.reticule.visible = true
  2827. },
  2828. addPlane: function(o) {
  2829. if(!o.intersect)return;
  2830. var pos = o.intersect.point;
  2831. var overlay = new Overlay({
  2832. sid: new Date().getTime() + ""
  2833. })
  2834. overlay.hasRequestLoad = true
  2835. overlay.position.copy(pos);
  2836. if (player.getMouseDirection().angleTo(o.intersect.face.normal) < Math.PI / 2) {
  2837. overlay.lookAt(o.intersect.face.normal.clone().negate().add(pos));
  2838. overlay.position.add(o.intersect.face.normal.clone().negate().multiplyScalar(0.01))
  2839. //avoid mesh crash with chunks 模型的精度可能和floorplan的不一样,所以chunk即使材质经过处理还是会闪烁但是wallmesh不会
  2840. } else {
  2841. overlay.lookAt(o.intersect.face.normal.clone().add(pos));
  2842. overlay.position.add(o.intersect.face.normal.clone().multiplyScalar(0.01))
  2843. }
  2844. overlay.posCustom = overlay.position.clone();
  2845. overlay.quaCustom = overlay.quaternion.clone();
  2846. overlay.widthCustom = overlay.width;
  2847. overlay.heightCustom = overlay.height;
  2848. overlay.isNew = true
  2849. player.clickOverlay(overlay)
  2850. transformControls.transCtlChangeMode("translate")
  2851. this.addToList(overlay)
  2852. },
  2853. updateOverlayScaleDisplay: function() {
  2854. var overlay = this.editPlane;
  2855. var maxWidth = 193
  2856. , maxHeight = maxWidth
  2857. //maxWidth/2;
  2858. var ratioW = Math.abs(overlay.width) / maxWidth;
  2859. var ratioH = Math.abs(overlay.height) / maxHeight;
  2860. var ratio = 1 / Math.max(ratioW, ratioH);
  2861. //缩放比例
  2862. var w = Math.round(Math.abs(overlay.width) * ratio)
  2863. var h = Math.round(Math.abs(overlay.height) * ratio)
  2864. $('#overlayUpload .preview').css({
  2865. "width": w + 'px',
  2866. "height": h + 'px',
  2867. });
  2868. $('#overlayUpload .preview [attr-type="width"]').text(toPrecision(overlay.width, 2))
  2869. $('#overlayUpload .preview [attr-type="height"]').text(toPrecision(overlay.height, 2))
  2870. },
  2871. updateOverlayPanel: function(overlay) {
  2872. this.editPlane = overlay;
  2873. overlay.requestDownload()
  2874. if(overlay._loadDones){
  2875. $('.waiting').addClass('showloading');
  2876. overlay._loadDones.push(()=>{
  2877. $('.waiting').removeClass('showloading');
  2878. })
  2879. }
  2880. var plane = overlay.plane
  2881. var src = plane.material.map && (plane.material.map.image ? plane.material.map.image.src : overlay.fileSrc );
  2882. $('#overlayUpload .preview video').remove();
  2883. overlay.overlayType && this.switchEditType(overlay.overlayType)
  2884. if (overlay.overlayType == "video") {
  2885. var video = plane.material.map.image
  2886. $('#overlayUpload .preview').css({'background-image':"", 'background-size':""}).append(video);
  2887. } else if(overlay.overlayType == "photo" || overlay.overlayType == "text"){
  2888. $('#overlayUpload .preview').css({
  2889. 'background-image': src ? ("url(" + src + ")") : "",
  2890. 'background-size': "contain"
  2891. })
  2892. }else{
  2893. $('#overlayUpload .preview').css({
  2894. 'background-image': "",
  2895. 'background-size': ""
  2896. })
  2897. }
  2898. if (overlay.overlayType) {
  2899. $('#overlayUpload [name="useImgRatio"]').removeClass("hide")
  2900. $('#overlayUpload .preview').addClass('uploaded')
  2901. } else {
  2902. $('#overlayUpload [name="useImgRatio"]').addClass("hide")
  2903. $('#overlayUpload .preview').removeClass('uploaded')
  2904. }
  2905. this.updateOverlayScaleDisplay()
  2906. if (overlay.hasBox) {
  2907. this.scroller.videoDepth.setValue(overlay.scale.z * settings.overlay.depth * 100, true)
  2908. } else {
  2909. this.scroller.videoDepth.setValue(0, true)
  2910. }
  2911. setTimeout(()=>{
  2912. this.scroller.videoDepth.InitOffset()
  2913. }
  2914. , 201)
  2915. this.updatePano()
  2916. },
  2917. //----------------------------
  2918. panoPosSwitchOnChange : function(){
  2919. var on = this.panoPosSwitch.is(':checked')
  2920. if(!on){
  2921. delete this.editPlane.transformAtPanos[getTransformSid()]
  2922. this.editPlane.position.copy(this.editPlane.posCustom)
  2923. this.editPlane.quaternion.copy(this.editPlane.quaCustom)
  2924. var scale = this.editPlane.getScaleBySize(this.editPlane.widthCustom, this.editPlane.heightCustom)
  2925. this.editPlane.scale.set(scale.x, scale.y, this.editPlane.scale.z)
  2926. //this.editPlane.usingTransformData = false
  2927. }
  2928. }
  2929. ,
  2930. getTransformAtPano : function(){
  2931. var name = getTransformSid()
  2932. this.editPlane.transformAtPanos[name] = {
  2933. pos : this.editPlane.position.clone(),
  2934. qua : this.editPlane.quaternion.clone(),
  2935. width : this.editPlane.width,
  2936. height : this.editPlane.height,
  2937. }
  2938. //this.editPlane.usingTransformData = true
  2939. },
  2940. updatePosition:function(){
  2941. var on = this.panoPosSwitch.is(':checked')
  2942. if(on){
  2943. this.getTransformAtPano()
  2944. }else{
  2945. this.editPlane.posCustom.copy(this.editPlane.position)
  2946. }
  2947. },
  2948. updateScale : function(){
  2949. var on = this.panoPosSwitch.is(':checked')
  2950. var size = this.editPlane.getSizeByScale( )
  2951. this.editPlane.width = size.width
  2952. this.editPlane.height = size.height
  2953. if(on){
  2954. this.getTransformAtPano()
  2955. }else{
  2956. this.editPlane.widthCustom = this.editPlane.width
  2957. this.editPlane.heightCustom = this.editPlane.height
  2958. }
  2959. this.updateOverlayScaleDisplay()
  2960. }
  2961. ,
  2962. updateQua : function(){
  2963. var on = this.panoPosSwitch.is(':checked')
  2964. if(on){
  2965. this.getTransformAtPano()
  2966. }else{
  2967. this.editPlane.quaCustom.copy(this.editPlane.quaternion)
  2968. }
  2969. }
  2970. ,
  2971. updatePano:function(){
  2972. if(!EditOverlay.editPlane ) return;
  2973. this.panoPosSwitch.prop('checked', !!EditOverlay.editPlane.transformAtPanos[ getTransformSid()]);
  2974. },
  2975. //------------------------------
  2976. closeOverlayPanel: function(type) {
  2977. if (!this.editPlane)
  2978. return;
  2979. if (type == 'cancel') {
  2980. if (!this.editPlane.isNew && !this.editPlane.needDelete)
  2981. this.editPlane.setFromInfo(this.editPlane.info)
  2982. //this.setOverlayFromInfo(this.editPlane, this.editPlane.info);//恢复
  2983. else
  2984. this.disposeOverlay(this.editPlane);
  2985. //删除
  2986. }
  2987. this.editPlane = null;
  2988. transformControls.detach()
  2989. $("#overlayProp").addClass("atRight");
  2990. //if(player.model.overlayPlanes.length < this.overlayMaxCount) this.beginToAddPlane()
  2991. },
  2992. useImgRatio: function(o) {
  2993. var plane = this.editPlane.plane;
  2994. if (!plane.material.map)
  2995. return;
  2996. var img = plane.material.map.image;
  2997. var mintranRatio = 200;
  2998. //default is 200 , 防止图片太小时在墙上依旧很大
  2999. var width = this.editPlane.overlayType == "video" ? img.videoWidth : img.width;
  3000. var height = this.editPlane.overlayType == "video" ? img.videoHeight : img.height;
  3001. if (o == "suitSize") {
  3002. var boundWidth = Math.min(Math.max(width, height) / mintranRatio, 1)
  3003. if (width > height) {
  3004. var w = boundWidth;
  3005. var h = boundWidth * height / width
  3006. } else {
  3007. var h = boundWidth;
  3008. var w = boundWidth * width / height;
  3009. }
  3010. } else {
  3011. //假设不变总面积
  3012. var k = Math.sqrt(Math.abs(this.editPlane.width * this.editPlane.height) / (width * height))
  3013. var w = k * width * (this.editPlane.width < 0 ? -1 : 1);
  3014. var h = k * height * (this.editPlane.height < 0 ? -1 : 1);
  3015. }
  3016. this.editPlane.scale.setX(w / settings.overlay.width)
  3017. this.editPlane.scale.setY(h / settings.overlay.height)
  3018. this.editPlane.width = w;
  3019. this.editPlane.height = h;
  3020. this.updateScale()
  3021. this.updateOverlayPanel(this.editPlane)
  3022. },
  3023. getOverlayInfo: function(overlay) {
  3024. //2 编辑前, 从当前状态获取info
  3025. var plane = overlay.plane;
  3026. var transformAtPanos = {}
  3027. for(var i in overlay.transformAtPanos){
  3028. transformAtPanos[i] = {
  3029. width : overlay.transformAtPanos[i].width,
  3030. height : overlay.transformAtPanos[i].height,
  3031. pos : overlay.transformAtPanos[i].pos.clone(),
  3032. qua : overlay.transformAtPanos[i].qua.clone(),
  3033. }
  3034. }
  3035. overlay.info = {
  3036. width: overlay.widthCustom,
  3037. height: overlay.heightCustom,
  3038. depth: settings.overlay.depth * overlay.scale.z,
  3039. pos: overlay.posCustom.clone(),
  3040. qua: overlay.quaCustom.clone(),
  3041. media: plane.material.map.image,
  3042. file: overlay.file,
  3043. type: overlay.overlayType,
  3044. hasBox: overlay.hasBox,
  3045. transformAtPanos: transformAtPanos
  3046. }
  3047. },
  3048. getSavingInfo: function(overlay) {
  3049. if (!overlay.file && (!overlay.plane.material.map || !overlay.plane.material.map.image)) {
  3050. return;
  3051. }
  3052. var transformAtPanos = {}
  3053. for(var i in overlay.transformAtPanos){
  3054. transformAtPanos[i] = {
  3055. width : toPrecision(overlay.transformAtPanos[i].width, 4),
  3056. height : toPrecision(overlay.transformAtPanos[i].height, 4),
  3057. pos : toPrecision(overlay.transformAtPanos[i].pos.toArray(), 3),
  3058. qua : toPrecision(overlay.transformAtPanos[i].qua.toArray(), 5)
  3059. }
  3060. }
  3061. var info = {
  3062. width: toPrecision(overlay.widthCustom, 4),
  3063. height: toPrecision(overlay.heightCustom, 4),
  3064. depth: toPrecision(settings.overlay.depth * overlay.scale.z, 4),
  3065. pos: toPrecision(overlay.posCustom.toArray(), 3),
  3066. qua: toPrecision(overlay.quaCustom.toArray(), 5),
  3067. sid: overlay.sid,
  3068. hasBox: overlay.hasBox ? 1 : 0,
  3069. media: [overlay.overlayType],
  3070. file: overlay.fileSrc || overlay.plane.material.map.image.src,
  3071. transformAtPanos : transformAtPanos
  3072. }
  3073. return info
  3074. },
  3075. SaveOverlay: function() {
  3076. var overlay = this.editPlane;
  3077. if (!overlay.file && (!overlay.plane.material.map || !overlay.plane.material.map.image)) {
  3078. this.editType == "video" ? alert("请上传视频") : alert("请上传图片");
  3079. return;
  3080. }
  3081. var saveInfo = ()=>{
  3082. //overlay.savingInfo = JSON.stringify(info)//准备写入的info
  3083. //saveDone:
  3084. overlay.isNew = false;
  3085. overlay.getVisiblePanos()
  3086. this.getOverlayInfo(overlay);
  3087. this.closeOverlayPanel()
  3088. $('.waiting').removeClass('showloading');
  3089. }
  3090. if (!overlay.info || overlay.file != overlay.info.file) {
  3091. $('.waiting').addClass('showloading');
  3092. uploadFile(overlay.file, 'overlay', function(rs) {
  3093. if (rs.code === 0) {
  3094. overlay.fileSrc = rs.data;
  3095. saveInfo()
  3096. }
  3097. ;
  3098. })
  3099. } else
  3100. saveInfo();
  3101. },
  3102. disposeOverlay: function(overlay) {
  3103. var plane = overlay.plane
  3104. if (overlay == player.hoveringPlane) {
  3105. player.hoverOverlay(null, "soon");
  3106. }
  3107. if (plane.material.map) {//删除视频src
  3108. //overlay.info && common.destroyBlob(overlay.info.media.src)
  3109. //common.destroyBlob(plane.material.map.image.src)
  3110. }
  3111. plane.material.dispose();
  3112. overlay.parent.remove(overlay);
  3113. this.removeFromList(overlay)
  3114. //this.beginToAddPlane()
  3115. },
  3116. DeleteOverlay: function() {
  3117. var overlay = this.editPlane;
  3118. if (!overlay.isNew) {
  3119. if (confirm(overlay.overlayType== "photo" ? "确定删除该图片?" : "确定删除该视频?")) {
  3120. overlay.needDelete = true;
  3121. $("#overlayProp a.close").click()
  3122. //this.closeOverlayPanel()
  3123. }
  3124. } else {
  3125. //刚创建时的删除按钮等同于取消按钮
  3126. $("#overlayProp a.close").click()
  3127. //this.closeOverlayPanel()
  3128. }
  3129. },
  3130. addToList: function(overlay) {
  3131. var li = $(`<li class='listItem'><div class="icon"></div><div class="title">${(overlay.overlayType == "video" ? "视频 ":"图片 ")+ overlay.sid}</div></li>`)
  3132. $(".overlayList ul").append(li);
  3133. li.on("click", ()=>{
  3134. player.clickOverlay(overlay)
  3135. player.focusPoint({aim: overlay.position})
  3136. })
  3137. overlay.domLi = li;
  3138. },
  3139. removeFromList: function(overlay) {
  3140. overlay.domLi.remove();
  3141. }
  3142. }
  3143. //----------------漫游可见性---------------------------------
  3144. var VisiSet = {
  3145. setPanoVisible: false,
  3146. setTagVisible: false,
  3147. panoVLines: {},
  3148. //线条
  3149. panoVTemp: {},
  3150. //修改后还没保存的临时数据
  3151. tagVsetting: null,
  3152. //正在设置的热点中心点
  3153. tagsVLines: {},
  3154. //线条
  3155. //tagVTemp //修改后还没保存的临时数据
  3156. $confirmSnap: $("#camera-start"),
  3157. changeBtn : $(".toolMid .midBottom #midBtns>button").eq(1),
  3158. colors: {
  3159. green: "#00c8ae"
  3160. },
  3161. init: function() {
  3162. this.footIconSizeRatio = Math.max(player.model.size.x, player.model.size.z) / 30;
  3163. this.meshGroup = new THREE.Object3D;
  3164. this.meshGroup.name = "setVisible-group"
  3165. player.model.add(this.meshGroup)
  3166. $("#hotVisible").on("click", ()=>{
  3167. VisiSet.enterSet(VisiSet.beginSetTagVisible.bind(VisiSet))
  3168. })
  3169. this.changeBtn.on("click",()=>{//隐藏与显示该点
  3170. if(this.changeBtn.attr("function") == "hide"){
  3171. for(let i in this.panoVLines){
  3172. this.panoVLines[i].visible && this.dealPanoVisible(i);
  3173. }
  3174. }else{
  3175. //显示该点时,显示周围一定距离内、到该点没有遮挡的pano
  3176. //?????
  3177. var list = player.model.panos.sortByScore([e=>e.isAligned()], [(pano)=>{return -pano.position.distanceTo(this.panoVsetting.position)}])
  3178. if(list.length == 1){
  3179. console.log('仅有一个漫游点')
  3180. return;
  3181. }
  3182. var ifBlock = function(panoA, panoB ){
  3183. var A = panoA.position.clone();
  3184. var B = panoB.position.clone();
  3185. return convertTool.ifIntersectChunks(A, B, {})
  3186. }
  3187. var okList
  3188. var s = Math.max(-list[1].score*2, 4); //i==1的一定显示
  3189. for(var i=1;i<list.length;i++){
  3190. if(-list[i].score < s){
  3191. if(ifBlock(this.panoVsetting, list[i].pano)){
  3192. list[i].block = true //有阻挡
  3193. }
  3194. list[i].good = true
  3195. }else{
  3196. okList || (okList = list.filter(e=>e.good && !e.block));//绝对可以使用的
  3197. if(okList.length <2 ){
  3198. if(!ifBlock(this.panoVsetting, list[i].pano)){
  3199. if(okList.length == 0){
  3200. okList.push(list[i])
  3201. }else{//1
  3202. var lastPos = okList[0].pano.position.clone().sub(this.panoVsetting.position).setY(0);
  3203. var thisPos = list[i].pano.position.clone().sub(this.panoVsetting.position).setY(0);
  3204. if(lastPos.angleTo(thisPos) > Math.PI / 2){
  3205. console.log('再加一个 角度'+THREE.Math.radToDeg(lastPos.angleTo(thisPos)))
  3206. break;
  3207. }
  3208. }
  3209. }
  3210. }else{
  3211. break;
  3212. }
  3213. }
  3214. }
  3215. if(okList.length==0){//如果length为0,至少加一个pano, 虽然是遮挡的
  3216. okList.push(list[0].pano)
  3217. }
  3218. okList.forEach(e=>this.dealPanoVisible(e.pano.id))
  3219. console.log(okList)
  3220. }
  3221. })
  3222. },
  3223. enterSet: function(fun) {
  3224. var enter = function() {
  3225. if (player.modeTran.split('-')[1] != "floorplan") {
  3226. setTimeout(fun, 300)
  3227. //提前一点出现
  3228. }
  3229. player.flyToMode("floorplan", fun);
  3230. }
  3231. permitTranMode(false)
  3232. if (!player.modeTran) {
  3233. player.afterCModeFuc = ()=>{
  3234. enter()
  3235. }
  3236. } else
  3237. enter()
  3238. },
  3239. beginSetPanoLog: function() {
  3240. player.flying || $(".toolLeft").removeClass("unable")
  3241. if (this.setPanoLog)
  3242. return;
  3243. this.setPanoLog = true
  3244. this.panosSelect = []
  3245. this.updateFootIconSize()
  3246. this.showFootIcons(null, true);
  3247. for(let i in player.model.hots){
  3248. player.model.hots[i].visi_ = player.model.hots[i].mesh.visible;
  3249. player.model.hots[i].mesh.visible = false
  3250. }
  3251. player.model.panos.forEach(e=>{
  3252. e.addTextSprite(e.id, $('#panoIdColorTex').val())
  3253. })
  3254. },
  3255. finishSetPanoLog: function() {
  3256. //结束 退出这个设置
  3257. if (!this.setPanoLog)
  3258. return;
  3259. //否则会加多个侦听
  3260. this.setPanoLog = false;
  3261. this.hideFootIcons();
  3262. this.recoverAllState2();
  3263. this.panosSelect = null
  3264. player.flyoutType = null
  3265. permitTranMode(true)
  3266. for(let i in player.model.hots){
  3267. player.model.hots[i].mesh.visible = player.model.hots[i].visi_
  3268. }
  3269. $("#panosIdShow").val('')
  3270. player.model.panos.forEach(e=>{
  3271. e.removeTextSprite()
  3272. })
  3273. },
  3274. dealPanoLogClick: function(id) {
  3275. var panos = player.model.panos;
  3276. var index = this.panosSelect.indexOf(id)
  3277. if (index==-1) {
  3278. this.changeFIconState(panos.index[id].footIcon, "linked" )
  3279. this.panosSelect.push(id)
  3280. }else{
  3281. this.changeFIconState(panos.index[id].footIcon, false)
  3282. this.panosSelect.splice(index,1)
  3283. }
  3284. $("#panosIdShow").val(this.panosSelect.join(', '));
  3285. }
  3286. ,
  3287. changePanoIdColor:function(color){
  3288. player.model.panos.forEach(e=>{
  3289. e.removeTextSprite();
  3290. e.addTextSprite(e.id,color)
  3291. })
  3292. }
  3293. ,
  3294. beginSetPanoVisible: function() {
  3295. player.flying || $(".toolLeft").removeClass("unable")
  3296. if (this.setPanoVisible)
  3297. return;
  3298. this.setPanoVisible = true;
  3299. this.panoVTemp = {};
  3300. this.SetOnePanoVisible(player.currentPano)
  3301. //先设置currentPano
  3302. this.$confirmSnap.text('保存当前设置').removeClass("hide")
  3303. //objects.tagManager.hideAllTags();
  3304. this.setDisplay(true)
  3305. this.updateFootIconSize()
  3306. //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
  3307. for(let i in player.model.hots){
  3308. player.model.hots[i].visi_ = player.model.hots[i].mesh.visible;
  3309. player.model.hots[i].mesh.visible = false
  3310. }
  3311. },
  3312. SetOnePanoVisible: function(pano) {
  3313. //点击某个pano后就对该pano点进行设置
  3314. if (this.panoVsetting == pano)
  3315. return;
  3316. //if (this.panoVsetting) saveLastPanoVi(this.panoVsetting);
  3317. this.panoVsetting = pano;
  3318. //记录正在修改的
  3319. this.delVisibleLines();
  3320. //删除线
  3321. this.showFootIcons(pano, true);
  3322. this.createPanoVisiLines(pano);
  3323. //创线
  3324. this.changeBtn.removeClass('hide')
  3325. },
  3326. saveLastPanoVi: function() {
  3327. //保存刚设置过的pano
  3328. var change = [];
  3329. for (var r in this.panoVLines) {
  3330. var line = this.panoVLines[r];
  3331. if (line.name.indexOf("new") > -1 && line.visible) {
  3332. //新设置为visible且没有取消
  3333. change.push({
  3334. type: "add",
  3335. id: r
  3336. })
  3337. } else if (line.name.indexOf("new") == -1 && !line.visible) {
  3338. //旧的且已经取消
  3339. change.push({
  3340. type: "sub",
  3341. id: r
  3342. })
  3343. }
  3344. }
  3345. if (change.length) {
  3346. //添加双向的neighbour:
  3347. var self = this.searchNeib(this.panoVsetting.id)
  3348. //var seeMarkers_self = self.seeMarkers;
  3349. var neighbourUUIDs_self = self.neighbourUUIDs
  3350. var neighbourPanos_self = self.neighbourPanos;
  3351. for (var i = 0; i < change.length; i++) {
  3352. var other = this.searchNeib(change[i].id)
  3353. //var seeMarkers = other.seeMarkers;
  3354. var neighbourUUIDs = other.neighbourUUIDs;
  3355. var neighbourPanos = other.neighbourPanos;
  3356. if (change[i].type == "add") {
  3357. //seeMarkers.push(this.panoVsetting.id);
  3358. neighbourUUIDs.push(this.panoVsetting.id);
  3359. neighbourPanos[this.panoVsetting.id] = true;
  3360. //seeMarkers_self.push(change[i].id);
  3361. neighbourUUIDs_self.push(change[i].id);
  3362. neighbourPanos_self[change[i].id] = true;
  3363. } else {
  3364. //var index = seeMarkers.indexOf(this.panoVsetting.id);
  3365. //index > -1 && seeMarkers.splice(index, 1);
  3366. var index = neighbourUUIDs.indexOf(this.panoVsetting.id);
  3367. index > -1 && neighbourUUIDs.splice(index, 1);
  3368. neighbourPanos[this.panoVsetting.id] = false;
  3369. //var index = seeMarkers_self.indexOf(change[i].id);
  3370. //index > -1 && seeMarkers_self.splice(index, 1);
  3371. var index = neighbourUUIDs_self.indexOf(change[i].id);
  3372. index > -1 && neighbourUUIDs_self.splice(index, 1);
  3373. neighbourPanos_self[change[i].id] = false;
  3374. }
  3375. this.panoVTemp[change[i].id] = {
  3376. //后面两个是作为保存到后台的数据存储,临时需要用到的是第一个
  3377. neighbourPanos: neighbourPanos,
  3378. //seeMarkers: seeMarkers,
  3379. neighbourUUIDs: neighbourUUIDs
  3380. }
  3381. }
  3382. this.panoVTemp[this.panoVsetting.id] = {
  3383. //加上自己
  3384. neighbourPanos: neighbourPanos_self,
  3385. //seeMarkers: seeMarkers_self,
  3386. neighbourUUIDs: neighbourUUIDs_self
  3387. }
  3388. }
  3389. },
  3390. pauseSetPanoVisible: function(type) {
  3391. //暂停 因为点击了保存设置 但没有退出设置
  3392. if (!this.setPanoVisible)
  3393. return;
  3394. if (type == "unsaved") {
  3395. //中途点击pano从而停止一个热点的设置
  3396. this.saveLastPanoVi();
  3397. } else {
  3398. this.panoVTemp = {};
  3399. //清空数据
  3400. }
  3401. this.delVisibleLines();
  3402. this.showFootIcons();
  3403. //清空选择
  3404. var lastPanoSetting = this.panoVsetting;
  3405. this.panoVsetting = null;
  3406. lastPanoSetting && this.changeFIconState2(lastPanoSetting.footIcon, this.checkHasNeighbor(lastPanoSetting))
  3407. //这句要放在this.panoVsetting = null后。 根据可见性更改透明度
  3408. this.changeBtn.addClass('hide')
  3409. },
  3410. //按理说改变了neighbourPano,tag的初始visible也要改。但是这样还要考虑已经改过的tag。。很麻烦
  3411. finishSetPanoVisible: function() {
  3412. //结束 退出这个设置
  3413. if (!this.setPanoVisible)
  3414. return;
  3415. //否则会加多个侦听
  3416. this.setPanoVisible = false;
  3417. this.hideFootIcons();
  3418. this.delVisibleLines();
  3419. //objects.tagManager.showAllTags();
  3420. this.recoverAllState2();
  3421. this.panoVsetting = null;
  3422. this.panoVTemp = {};
  3423. player.flyoutType = null
  3424. this.$confirmSnap.addClass("hide")
  3425. permitTranMode(true)
  3426. this.setDisplay(false)
  3427. for(let i in player.model.hots){
  3428. player.model.hots[i].mesh.visible = player.model.hots[i].visi_
  3429. }
  3430. },
  3431. changeVisiBtnState: function(state){
  3432. this.changeBtn.attr("function", state ? "hide" : "show")
  3433. this.changeBtn.html(state ? "隐藏该点位置":"显示该点位置")
  3434. },
  3435. recoverAllState2: function() {
  3436. //为了热点可视恢复成pano全部可见
  3437. if(!this.footIcons)return;
  3438. for (var i = 0; i < this.footIcons.length; i++) {
  3439. this.footIcons[i].material.uniforms.opacity.value = 1;
  3440. this.footIcons[i].material.uniforms.map.value = footTex1;
  3441. }
  3442. },
  3443. afterSavePanoVisibles: function() {
  3444. //实施:
  3445. var panos = player.model.panos;
  3446. for (var i in this.panoVTemp) {
  3447. var pano = panos.index[i];
  3448. //pano.seeMarkers = this.panoVTemp[i].seeMarkers;
  3449. pano.neighbourUUIDs = this.panoVTemp[i].neighbourUUIDs;
  3450. pano.neighbourPanos = this.panoVTemp[i].neighbourPanos;
  3451. }
  3452. if (!this.checkHasNeighbor(player.currentPano)) {
  3453. //currentPano变为孤立点 就要换一个防止飞入
  3454. var list = panos.sortByScore([pano=>{
  3455. return this.checkHasNeighbor(pano)
  3456. }
  3457. ], [function(pano) {
  3458. return -pano.position.distanceTo(player.currentPano.position)
  3459. }
  3460. ])
  3461. if (list && list.length) {
  3462. player.currentPano = list[0].pano;
  3463. //找最近的一非孤立点
  3464. //this.noPanoHasNeighbor = false; //更新状态
  3465. } else {//this.noPanoHasNeighbor = true; //更新状态
  3466. }
  3467. } else {//this.noPanoHasNeighbor = false; //更新状态
  3468. }
  3469. //dataDeal.done();
  3470. //暂时:
  3471. this.pauseSetPanoVisible()
  3472. this.updateFootIconSize()
  3473. //更新一下center大小 写在最后
  3474. },
  3475. //最佳推荐操作顺序: 先设置pano可见性 再创建热点 这样热点的visible正确些,否则之后再设置热点可见性会改更多
  3476. savePanoVisibles: function() {
  3477. //保存
  3478. if (this.panoVsetting)
  3479. this.saveLastPanoVi(this.panoVsetting);
  3480. //获取最后设置的那个热点的改动
  3481. var PanoData = [];
  3482. for (var i in this.panoVTemp) {
  3483. PanoData.push({
  3484. //希望算法部不会更改index排序,或者更改后能将visible信息一并更改
  3485. panoID: i,
  3486. //visibles: this.turnToPanoIndex(this.panoVTemp[i].seeMarkers),
  3487. visibles3: this.turnToPanoIndex(this.panoVTemp[i].neighbourUUIDs)
  3488. })
  3489. }
  3490. if (PanoData.length == 0) {
  3491. //没改变
  3492. alert("保存成功")
  3493. return;
  3494. }
  3495. /* this.afterSavePanoVisibles()
  3496. alert("保存成功")
  3497. console.log(JSON.stringify(PanoData)) */
  3498. let url = cmp ? ('/api/scene/roamViable/' + cmp) : '/manage/scene/roamViable'
  3499. $.ajax({
  3500. method: 'POST',
  3501. url: ceshi + url,
  3502. headers: {
  3503. 'Content-Type': 'application/json',
  3504. token: token
  3505. },
  3506. contentType: 'application/json',
  3507. data: JSON.stringify({
  3508. data: JSON.stringify(PanoData),
  3509. sceneCode: window.number
  3510. }),
  3511. success: (data)=>{
  3512. if (data.code === 0) {
  3513. this.afterSavePanoVisibles()
  3514. alert("保存漫游可行成功")
  3515. } else
  3516. alert("保存漫游可行失败")
  3517. if (data.code === 5001) {
  3518. alert('请重新登录')
  3519. localStorage.dcj_token = ''
  3520. location.reload()
  3521. }
  3522. }
  3523. ,
  3524. fail: function() {
  3525. alert("保存漫游可行失败")
  3526. }
  3527. })
  3528. /* var o = {
  3529. name_t: "panoVisible",
  3530. f: this.pauseSetPanoVisible,
  3531. url: Config.prefixEditProPCApi+"/saveLinkPano",
  3532. dialog: i18n.get('设置'),
  3533. data: { data: JSON.stringify(PanoData) }
  3534. }
  3535. var dataDeal = uploadsSaving.saveFucforPC(o);
  3536. dataDeal.group[0] = function () {
  3537. //实施:
  3538. for (var i in player.panoVTemp) {
  3539. var pano = player.model.panos.index[i];
  3540. pano.seeMarkers = player.panoVTemp[i].seeMarkers;
  3541. pano.neighbourUUIDs = player.panoVTemp[i].neighbourUUIDs;
  3542. pano.neighbourPanos = player.panoVTemp[i].neighbourPanos;
  3543. }
  3544. if(!player.model.checkHasNeighbor(player.currentPano)){//currentPano变为孤立点 就要换一个防止飞入
  3545. var list = player.model.panos.sortByScore([function(pano){return player.model.checkHasNeighbor(pano)}],
  3546. [function(pano){return -pano.position.distanceTo(player.currentPano.position)}])
  3547. if(list && list.length){
  3548. player.currentPano = list[0].pano;//找最近的一非孤立点
  3549. player.model.noPanoHasNeighbor = false; //更新状态
  3550. }else{
  3551. player.model.noPanoHasNeighbor = true; //更新状态
  3552. }
  3553. }else{
  3554. player.model.noPanoHasNeighbor = false; //更新状态
  3555. }
  3556. dataDeal.done();
  3557. player.model.updateFootIconSize(player.cameraControls.activeControl)//更新一下center大小 写在最后
  3558. } */
  3559. },
  3560. searchNeib: function(panoId) {
  3561. //寻找某pano的相关neighbour 可能是修改过的
  3562. var panos = player.model.panos;
  3563. var o = {};
  3564. if (this.panoVTemp[panoId]) {
  3565. //o.seeMarkers = this.panoVTemp[panoId].seeMarkers;
  3566. o.neighbourUUIDs = this.panoVTemp[panoId].neighbourUUIDs;
  3567. o.neighbourPanos = this.panoVTemp[panoId].neighbourPanos;
  3568. } else {
  3569. //o.seeMarkers = panos.index[panoId].seeMarkers.slice(0);
  3570. o.neighbourUUIDs = panos.index[panoId].neighbourUUIDs.slice(0);
  3571. o.neighbourPanos = CloneObject(panos.index[panoId].neighbourPanos);
  3572. }
  3573. return o;
  3574. },
  3575. turnToPanoIndex: function(panoArr) {
  3576. var panos = player.model.panos;
  3577. var array = [];
  3578. for (var i = 0; i < panoArr.length; i++) {
  3579. var pano = panos.index[panoArr[i]];
  3580. var index = panos.list.indexOf(pano)
  3581. array.push(index);
  3582. }
  3583. return array;
  3584. },
  3585. setDisplay: function(state) {
  3586. var panos = player.model.panos;
  3587. if (state) {
  3588. this.$confirmSnap.text('保存当前设置');
  3589. this.$confirmSnap.removeClass('hide');
  3590. } else {
  3591. this.$confirmSnap.addClass('hide');
  3592. this.changeBtn.addClass('hide')
  3593. }
  3594. player.path.currentPanoMarker.mesh.visible = !state;
  3595. player.overlayGroup.visible = !state;
  3596. player.reticule.visible = !state;
  3597. },
  3598. delVisibleLines: function() {
  3599. //xzw add 所有线都删除
  3600. for (var i in this.tagsVLines) {
  3601. this.tagsVLines[i].geometry.dispose();
  3602. this.tagsVLines[i].material.dispose();
  3603. this.meshGroup.remove(this.tagsVLines[i]);
  3604. delete this.tagsVLines[i];
  3605. }
  3606. for (var i in this.panoVLines) {
  3607. this.panoVLines[i].geometry.dispose();
  3608. this.panoVLines[i].material.dispose();
  3609. this.meshGroup.remove(this.panoVLines[i]);
  3610. delete this.panoVLines[i];
  3611. }
  3612. },
  3613. //--------panoVisible
  3614. createPanoVisiLines: function(pano) {
  3615. // pano可见性线条
  3616. var neighbours = this.panoVTemp[pano.id] && this.panoVTemp[pano.id].neighbourPanos || pano.neighbourPanos;
  3617. for (var r in neighbours) {
  3618. if (neighbours[r] && r != pano.id) {
  3619. this.createPanoSingleLine(pano, "old", r)
  3620. }
  3621. }
  3622. },
  3623. createPanoSingleLine: function(pano, type, id) {
  3624. //pano是中心
  3625. var panos = player.model.panos;
  3626. var p2 = panos.index[id].floorPosition.clone()
  3627. /* .sub(player.model.position) */
  3628. var line = LineDraw.createLine([pano.floorPosition.clone()/* .sub(this.position) */
  3629. , p2], {
  3630. color: this.colors.green
  3631. });
  3632. this.meshGroup.add(line);
  3633. line.name = "PanoVL-" + type + "-" + id;
  3634. this.panoVLines[id] = line;
  3635. this.changeFIconState(panos.index[id].footIcon, "linked")
  3636. },
  3637. dealPanoVisible: function(id) {
  3638. //外部调用
  3639. var panos = player.model.panos;
  3640. if (this.panoVsetting) {
  3641. if (id == this.panoVsetting.id) {
  3642. //关闭当前pano设置
  3643. this.pauseSetPanoVisible('unsaved')
  3644. } else {
  3645. var link;
  3646. //结果是否连接
  3647. if (this.panoVLines[id]) {
  3648. this.panoVLines[id].visible = !this.panoVLines[id].visible;
  3649. link = this.panoVLines[id].visible;
  3650. this.changeFIconState(panos.index[id].footIcon, this.panoVLines[id].visible ? "linked" : false)
  3651. } else {
  3652. this.createPanoSingleLine(this.panoVsetting, "new", id)
  3653. link = true;
  3654. }
  3655. if (link) {
  3656. //如果连接上了,直接判断该点是可见的(有附近点),(不能通过checkHasNeighbor来判断,因为新增的线条可能不在它的neighbour中
  3657. this.changeFIconState2(panos.index[id].footIcon, true)
  3658. this.changeFIconState2(panos.index[this.panoVsetting.id].footIcon, true)
  3659. } else {
  3660. //否则需要checkHasNeighbor
  3661. this.changeFIconState2(panos.index[id].footIcon, this.checkHasNeighbor(panos.index[id]))
  3662. this.changeFIconState2(panos.index[this.panoVsetting.id].footIcon, this.checkHasNeighbor(this.panoVsetting))
  3663. }
  3664. /* if(window.routeArray){
  3665. if(this.panoVLines[id].visible)window.routeArray.push(id)
  3666. else{
  3667. let index = window.routeArray.indexOf(id)
  3668. index > -1 && routeArray.splice(index, 1)
  3669. }
  3670. } */
  3671. }
  3672. } else {
  3673. //点击开始设置要设置的pano
  3674. this.SetOnePanoVisible(panos.index[id])
  3675. }
  3676. this.updateFootIconSize()
  3677. },
  3678. showFootIcons: function(pano, isPanovisible) {
  3679. if (!this.footIcons) {
  3680. footTex1 = Texture.load("images/edit/End_128.png");
  3681. //Store.FootIcon);
  3682. footTex2 = Texture.load("images/edit/End_unable_128.png");
  3683. //Store.FootIcon_unable);
  3684. this.footIcons = [];
  3685. var scale = 0.4;
  3686. scale *= 40 / Math.sqrt(Math.min($("#player").width(), $("#player").height()));
  3687. //屏幕越小,放得越大
  3688. scale = THREE.Math.clamp(scale, 0.3, 0.7)
  3689. //console.log("scale"+scale)
  3690. var geo = new THREE.PlaneGeometry(scale,scale,1,1)
  3691. var panos = player.model.panos;
  3692. for (var r in panos.index) {
  3693. if (!panos.index[r].isAligned())
  3694. continue;
  3695. var t = THREE.UniformsUtils.clone(shaders.waypoint.uniforms);
  3696. t.map.value = footTex1
  3697. t.color.value.set("#ffffff");
  3698. var mat = new THREE.RawShaderMaterial({
  3699. vertexShader: shaders.waypoint.vertexShader,
  3700. fragmentShader: shaders.waypoint.fragmentShader,
  3701. uniforms: t,
  3702. side: THREE.DoubleSide,
  3703. transparent: !0,
  3704. depthWrite: !1,
  3705. depthTest: false,
  3706. name: "footIcon"
  3707. })
  3708. var foot = new THREE.Mesh(geo,mat)
  3709. foot.position.copy(panos.index[r].floorPosition.clone()/* .sub(player.model.position) */
  3710. )
  3711. foot.lookAt(foot.position.clone().add(new THREE.Vector3(0,1,0)));
  3712. foot.name = panos.index[r].id;
  3713. foot.visible = false;
  3714. foot.renderOrder = 6,
  3715. panos.index[r].footIcon = foot;
  3716. this.meshGroup.add(foot);
  3717. this.footIcons.push(foot)
  3718. }
  3719. }
  3720. for (var i = 0; i < this.footIcons.length; i++) {
  3721. this.footIcons[i].visible = true;
  3722. this.changeFIconState(this.footIcons[i], false)
  3723. var panos = player.model.panos;
  3724. if (isPanovisible) {
  3725. this.changeFIconState2(this.footIcons[i], this.checkHasNeighbor(panos.index[this.footIcons[i].name], "showFoot"))
  3726. }
  3727. if (pano && (this.footIcons[i].name == pano.id)) {
  3728. //pano为中心 或者 currentPano 所以放大一点
  3729. this.footIcons[i].oriScale = new THREE.Vector3(1.5,1.5,1.5)
  3730. if (isPanovisible) {
  3731. //currentPano特殊些:
  3732. this.changeFIconState(this.footIcons[i], "center")
  3733. //this.footIcons[i].Unclick = true;//不让点击和hover
  3734. }
  3735. } else {
  3736. this.footIcons[i].oriScale = new THREE.Vector3(1,1,1)
  3737. }
  3738. }
  3739. },
  3740. checkHasNeighbor: function(pano, state) {
  3741. //检查当前状态pano点是否有可通行点
  3742. var neighbours = /* this.panoVTemp && */
  3743. this.panoVTemp[pano.id] ? this.panoVTemp[pano.id].neighbourPanos : pano.neighbourPanos;
  3744. if (state != "showFoot" && pano == this.panoVsetting) {
  3745. //是中心点的话。state == "showFoot"代表是showFootIcon时, 这时候线还没创建,无法用线判断中心点有几个相邻点,直接用neighbourPanos
  3746. for (var i in this.panoVLines) {
  3747. if (this.panoVLines[i].visible) {
  3748. return true;
  3749. //有一条线即可
  3750. }
  3751. }
  3752. return;
  3753. }
  3754. for (var i in neighbours) {
  3755. if (i == pano.id)
  3756. continue;
  3757. if (neighbours[i]) {
  3758. if (this.panoVsetting && this.panoVsetting.id == i && this.panoVLines[pano.id] && !this.panoVLines[pano.id].visible)
  3759. continue;
  3760. return true;
  3761. }
  3762. }
  3763. return false;
  3764. },
  3765. /* ifAllPanoNoNeighbor : function(){//检查是否全是孤立点
  3766. var panos = player.model.panos;
  3767. for(var i in panos.index){
  3768. if(this.checkHasNeighbor(panos.index[i])){
  3769. return false;
  3770. }
  3771. }
  3772. this.noPanoHasNeighbor = true;
  3773. return true;//是全部没有neighbour
  3774. }, */
  3775. changeFIconState: function(footIcon, state) {
  3776. var color = state == "linked" ? this.colors.green : (state == "center" ? /* "#d7f244" */
  3777. "#d5f12e" : "#ffffff");
  3778. footIcon.material.uniforms.color.value.set(color)
  3779. },
  3780. changeFIconState2: function(footIcon, state) {
  3781. //是可见点还是不可见点
  3782. if (state) {
  3783. footIcon.material.uniforms.map.value = footTex1;
  3784. if (this.panoVsetting) {
  3785. if (this.panoVsetting.id != footIcon.name) {
  3786. footIcon.material.uniforms.opacity.value = 1;
  3787. } else {
  3788. this.changeVisiBtnState(true)
  3789. }
  3790. }
  3791. } else {
  3792. //不可见
  3793. footIcon.material.uniforms.map.value = footTex2;
  3794. if (!this.panoVsetting || this.panoVsetting.id != footIcon.name) {
  3795. //非中心点时
  3796. footIcon.material.uniforms.opacity.value = 0.5;
  3797. } else {
  3798. //变为中心点时
  3799. footIcon.material.uniforms.opacity.value = 1;
  3800. this.changeVisiBtnState(false)
  3801. }
  3802. }
  3803. },
  3804. hideFootIcons: function() {
  3805. if (!this.footIcons)
  3806. return;
  3807. for (var i = 0; i < this.footIcons.length; i++) {
  3808. this.footIcons[i].visible = false;
  3809. }
  3810. },
  3811. updateFootIconSize: function() {
  3812. //根据相机位置 改变footIcon大小,使在范围内看到的热点大小一致,防止太小点击不到
  3813. if (!this.footIcons)
  3814. return;
  3815. var s = player.cameraControls.controls.floorplan.absoluteScale * 2.8
  3816. s = THREE.Math.clamp(s, 0.5 * this.footIconSizeRatio, 1.4 * this.footIconSizeRatio);
  3817. this.footIcons.forEach(function(f) {
  3818. try {
  3819. f.scale.copy(f.oriScale).multiplyScalar(s);
  3820. } catch (e) {
  3821. console.log(e)
  3822. }
  3823. })
  3824. }
  3825. //========热点可见性==============
  3826. ,
  3827. beginSetTagVisible: function() {
  3828. if (this.setTagVisible)
  3829. return;
  3830. $(".toolTop").addClass("unable")
  3831. $("#hotVisible").addClass("unable")
  3832. this.setTagVisible = true;
  3833. this.tagVTemp = {};
  3834. this.$confirmSnap.text('完成设置').removeClass("hide")
  3835. //objects.tagManager.hideAllTags();
  3836. for (let i in player.model.hots) {
  3837. player.model.hots[i]._isSprite = player.model.hots[i].isSprite;
  3838. player.model.hots[i].isSprite = true;
  3839. player.model.hots[i].mesh.material.depthTest = false;
  3840. }
  3841. this.setDisplay(true)
  3842. this.updateFootIconSize()
  3843. //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
  3844. },
  3845. SetOneTagVisible: function(tag) {
  3846. //点击某个热点后就对该热点进行设置,或者在热点修改时对其进行设置
  3847. if (this.tagVsetting == tag)
  3848. return;
  3849. if (this.tagVsetting) {
  3850. this.saveLastTagVi(this.tagVsetting);
  3851. //this.tagVsetting.setElemType(this.tagVsetting.style, this.tagVsetting.styleImageURL);
  3852. }
  3853. this.tagVsetting = tag;
  3854. //记录正在修改的
  3855. this.delVisibleLines();
  3856. //删除线
  3857. this.showFootIcons(player.currentPano);
  3858. this.createTagVisiLines(tag);
  3859. //创线
  3860. this.updateFootIconSize()
  3861. //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
  3862. },
  3863. saveLastTagVi: function() {
  3864. //保存刚设置过的tag
  3865. var change = false;
  3866. var newVPs = this.tagVTemp[this.tagVsetting.sid] || this.tagVsetting.visiblePanos.slice(0);
  3867. for (var r in this.tagsVLines) {
  3868. var line = this.tagsVLines[r];
  3869. if (line.name.indexOf("new") > -1 && line.visible) {
  3870. //新设置为visible且没有取消
  3871. newVPs.push(r)
  3872. change = true;
  3873. //console.log("add: "+r)
  3874. } else if (line.name.indexOf("new") == -1 && !line.visible) {
  3875. //旧的且已经取消
  3876. var i = newVPs.indexOf(r);
  3877. if (i == -1) {
  3878. console.log("visiblePanos删除error");
  3879. continue;
  3880. }
  3881. newVPs.splice(i, 1);
  3882. change = true;
  3883. //console.log("sub: "+r)
  3884. }
  3885. }
  3886. if (change) {
  3887. this.tagVTemp[this.tagVsetting.sid] = newVPs;
  3888. }
  3889. },
  3890. pauseSetTagVisible: function() {
  3891. //pc保存后删除连线 但还在继续设置 点选热点即开始
  3892. if (!this.setTagVisible || !this.tagVsetting)
  3893. return;
  3894. //this.tagVsetting.setElemType(this.tagVsetting.style, this.tagVsetting.styleImageURL );
  3895. this.delVisibleLines();
  3896. this.hideFootIcons();
  3897. this.tagVTemp = {};
  3898. this.tagVsetting = null;
  3899. },
  3900. finishSetTagVisible: function() {
  3901. if (!this.setTagVisible)
  3902. return;
  3903. $(".toolTop").removeClass("unable")
  3904. $("#hotVisible").removeClass("unable")
  3905. this.pauseSetTagVisible();
  3906. this.setTagVisible = false;
  3907. this.setDisplay(false)
  3908. this.$confirmSnap.addClass("hide")
  3909. permitTranMode(true)
  3910. /* for (var r in objects.tagManager.tags) {
  3911. if(objects.tagManager.tags[r].state == "videoPanoFlag")continue;
  3912. objects.tagManager.tags[r].disc.visible = false;
  3913. objects.tagManager.tags[r].disc.material.depthTest = true;
  3914. } */
  3915. for (let i in player.model.hots) {
  3916. player.model.hots[i].isSprite = player.model.hots[i]._isSprite;
  3917. player.model.hots[i].isSprite || player.model.hots[i].mesh.quaternion.copy(player.model.hots[i].quaternion)
  3918. player.model.hots[i].mesh.material.depthTest = true;
  3919. }
  3920. },
  3921. /* saveTagVisibles : function () { //保存到服务器
  3922. if (this.tagVsetting) this.saveLastTagVi(this.tagVsetting); //获取最后设置的那个热点的改动
  3923. //可能出现数据没变但保存的情况。比如先改变了然后切换别的热点但切换回来时又改回来。
  3924. var tags = [];
  3925. for (var i in this.tagVTemp) {
  3926. tags.push({
  3927. sid: i,
  3928. value: this.tagVTemp[i]//turnToPanoIndex(this.tagVTemp[i])
  3929. })
  3930. }
  3931. if (tags.length == 0) {//没有需要保存的改动
  3932. this.finishSetTagVisible()
  3933. return;
  3934. }
  3935. return tags;
  3936. } */
  3937. //afterSaveTagVisibles : function(){
  3938. saveTagVisibles: function() {
  3939. if (this.tagVsetting)
  3940. this.saveLastTagVi(this.tagVsetting);
  3941. for (var i in this.tagVTemp) {
  3942. //保持成功于是生效
  3943. player.model.hots[i].visiblePanos = this.tagVTemp[i];
  3944. }
  3945. this.finishSetTagVisible()
  3946. //还是保存完直接结束吧,因为现在热点可视不放在单独的设置页面了
  3947. },
  3948. createTagVisiLines: function(tag) {
  3949. // 热点可见性线条
  3950. var panos = player.model.panos;
  3951. tag.visiblePanos || tag.setVisiblePanos("get")
  3952. var visibleList = this.tagVTemp[tag.sid] || tag.visiblePanos;
  3953. //如果是刚在设置的要读取设置过的数据
  3954. for (var r = 0; r < visibleList.length; r++) {
  3955. var pano = panos.index[visibleList[r]];
  3956. this.createTagSingleLine(pano, "old", tag)
  3957. }
  3958. },
  3959. createTagSingleLine: function(pano, type, tag) {
  3960. var panos = player.model.panos;
  3961. var line = LineDraw.createLine([pano.floorPosition.clone()/* .sub(this.position) */
  3962. , tag.mesh.position.clone()], {
  3963. color: this.colors.green
  3964. });
  3965. this.meshGroup.add(line);
  3966. line.name = "tagVL-" + type + "-" + pano.id;
  3967. this.tagsVLines[pano.id] = line;
  3968. this.changeFIconState(panos.index[pano.id].footIcon, "linked")
  3969. },
  3970. dealTagVisible: function(tag, panoName) {
  3971. //外部调用
  3972. var panos = player.model.panos;
  3973. if (this.tagsVLines[panoName]) {
  3974. this.tagsVLines[panoName].visible = !this.tagsVLines[panoName].visible;
  3975. this.changeFIconState(panos.index[panoName].footIcon, this.tagsVLines[panoName].visible ? "linked" : false)
  3976. } else {
  3977. this.createTagSingleLine(panos.index[panoName], "new", tag)
  3978. }
  3979. },
  3980. delVisibleLines: function() {
  3981. //xzw add 所有线都删除
  3982. for (var i in this.tagsVLines) {
  3983. this.tagsVLines[i].geometry.dispose();
  3984. this.tagsVLines[i].material.dispose();
  3985. this.meshGroup.remove(this.tagsVLines[i]);
  3986. delete this.tagsVLines[i];
  3987. }
  3988. for (var i in this.panoVLines) {
  3989. this.panoVLines[i].geometry.dispose();
  3990. this.panoVLines[i].material.dispose();
  3991. this.meshGroup.remove(this.panoVLines[i]);
  3992. delete this.panoVLines[i];
  3993. }
  3994. }
  3995. }
  3996. function permitTranMode(state) {
  3997. state ? $(".pinBottom.left").removeClass('hide') : $(".pinBottom.left").addClass('hide');
  3998. }
  3999. CloneObject = function(copyObj, result, isSimpleCopy) {
  4000. //isSimpleCopy只复制最外层
  4001. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  4002. result = result || {};
  4003. if (copyObj instanceof Array) {
  4004. if (copyObj[0]instanceof Object) {
  4005. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  4006. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  4007. }
  4008. return copyObj.slice(0);
  4009. //如果是数组,直接复制返回(排除数组内是object
  4010. }
  4011. for (var key in copyObj) {
  4012. if (copyObj[key]instanceof Object && !isSimpleCopy)
  4013. result[key] = CloneObject(copyObj[key]);
  4014. else
  4015. result[key] = copyObj[key];
  4016. //如果是函数类同基本数据,即复制引用
  4017. }
  4018. return result;
  4019. }
  4020. ;
  4021. function randomWord(randomFlag, min, max) {
  4022. //随机字符串
  4023. var str = ""
  4024. , range = min
  4025. , arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
  4026. if (randomFlag) {
  4027. // 随机长度
  4028. range = Math.round(Math.random() * (max - min)) + min;
  4029. }
  4030. for (var i = 0; i < range; i++) {
  4031. var pos = Math.round(Math.random() * (arr.length - 1));
  4032. str += arr[pos];
  4033. }
  4034. return str;
  4035. }
  4036. function getRandomSid() {
  4037. //5-7位随机字符串 + 6位时间 为热点准备
  4038. var pre = randomWord(true, 5, 7);
  4039. var post = new Date().getTime() + "";
  4040. var len = post.length;
  4041. post = post.substring(len - 8, len - 5) + post.substring(len - 3, len)
  4042. //其实还是有可能重复的....
  4043. return pre + post;
  4044. }
  4045. function searchParent(searchArea, o, maxTimes) {
  4046. //是否是某种元素的下级,并找出该元素
  4047. maxTimes = maxTimes || 20;
  4048. var count = 0
  4049. var f = function(dom) {
  4050. if (o.id && o.id == dom.id)
  4051. return dom
  4052. else if (o.className && dom.classList && dom.classList.contains(o.className))
  4053. return dom
  4054. else if (o.tagName && dom.tagName && o.tagName.toUpperCase() == dom.tagName.toUpperCase())
  4055. return dom
  4056. }
  4057. var find;
  4058. while (searchArea && count < maxTimes) {
  4059. if (find = f(searchArea))
  4060. return find
  4061. searchArea = searchArea.parentNode;
  4062. count++;
  4063. }
  4064. }
  4065. class ListBox{//下拉列表
  4066. //elemArr:初始的列表,内含每项的dom.
  4067. constructor(elemArr, $rootDom, options={}){
  4068. this.listDom = $rootDom.find('ul.list')
  4069. this.listTitle = $rootDom.find('.selection')
  4070. this.chosenItem = null
  4071. this.options = options;
  4072. this.bindEvents()
  4073. elemArr.forEach(($dom, i)=>{
  4074. this.addItem($dom)
  4075. })
  4076. }
  4077. updateSelectDisplay(){
  4078. this.listDom.children().removeClass('selected')
  4079. this.chosenItem && this.chosenItem.addClass("selected")
  4080. this.options.selectFun(this.chosenIndex)
  4081. }
  4082. selectFromOutSide(index ){
  4083. this.chosenIndex = index;
  4084. this.chosenItem = index == void 0 ? null : this.listDom.children().eq(index)
  4085. this.updateSelectDisplay()
  4086. }
  4087. addItem($dom){
  4088. this.listDom.append($dom)
  4089. if(this.options.addFun){
  4090. this.options.addFun($dom)
  4091. }
  4092. $dom.on('click',()=>{
  4093. this.chosenItem = $dom;
  4094. this.chosenIndex = $dom.index();
  4095. this.updateSelectDisplay()
  4096. })
  4097. }
  4098. removeItem($dom){
  4099. $dom.remove()
  4100. if(this.options.delFun){
  4101. this.options.delFun($dom)
  4102. }
  4103. }
  4104. saveTemp(){//编辑热点时保存一份副本
  4105. this.temp = Array.from(this.listDom.children()).map((li)=>{
  4106. return li.outerHTML
  4107. })
  4108. this.options.saveTemp && this.options.saveTemp(this)
  4109. }
  4110. recover(){//取消编辑时恢复
  4111. this.listDom.html('')
  4112. this.temp.forEach(html=>{
  4113. this.addItem($(html));
  4114. })
  4115. this.options.recover && this.options.recover(this)
  4116. this.selectFromOutSide(this.chosenIndex)
  4117. }
  4118. bindEvents(){
  4119. this.listTitle.on('click',(e)=>{
  4120. e.stopPropagation()
  4121. this.listDom.toggleClass('hide')
  4122. })
  4123. document.addEventListener('click',()=>{
  4124. this.listDom.addClass('hide')
  4125. })
  4126. }
  4127. }