12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970 |
- var pi = Math.PI / 180;
- function toRadian(d) {
- return d * pi;
- }
- function wrap(n, min, max) {
- if (n === max || n === min) {
- return n;
- }
- var d = max - min;
- var w = ((n - min) % d + d) % d + min;
- return w;
- }
- function isString(obj) {
- if (isNil(obj)) {
- return false;
- }
- return typeof obj === 'string' || obj.constructor !== null && obj.constructor === String;
- }
- function isInteger(n) {
- return (n | 0) === n;
- }
- var hasOwnProperty = Object.prototype.hasOwnProperty;
- function hasOwn(obj, key) {
- return hasOwnProperty.call(obj, key);
- }
- function extend(dest) {
- for (var i = 1; i < arguments.length; i++) {
- var src = arguments[i];
- for (var k in src) {
- dest[k] = src[k];
- }
- }
- return dest;
- }
- function parseJSON(str) {
- if (!str || !isString(str)) {
- return str;
- }
- return JSON.parse(str);
- }
- function pushIn(dest) {
- for (var i = 1; i < arguments.length; i++) {
- var src = arguments[i];
- if (src) {
- for (var ii = 0, ll = src.length; ii < ll; ii++) {
- dest.push(src[ii]);
- }
- }
- }
- return dest.length;
- }
- function isNil(obj) {
- return obj == null;
- }
- function isArrayHasData(obj) {
- return Array.isArray(obj) && obj.length > 0;
- }
- function _inheritsLoose(subClass, superClass) {
- subClass.prototype = superClass ? Object.create(superClass.prototype) : {};
- subClass.prototype.constructor = subClass;
- subClass.__proto__ = superClass;
- }
- function isNumber(val) {
- return typeof val === 'number' && !isNaN(val);
- }
- function isObject(obj) {
- return typeof obj === 'object' && !!obj;
- }
- function isFunction(obj) {
- if (isNil(obj)) {
- return false;
- }
- return typeof obj === 'function' || obj.constructor !== null && obj.constructor === Function;
- }
- var Common = {
- project: function project() { },
- unproject: function unproject() { },
- projectCoords: function projectCoords(coordinates) {
- var _this = this;
- if (!coordinates) {
- return [];
- }
- if (!Array.isArray(coordinates)) {
- return this.project(coordinates);
- }
- if (coordinates.length === 0) {
- return [];
- }
- if (!this.isSphere()) {
- return forEachCoord(coordinates, this.project, this);
- }
- if (Array.isArray(coordinates[0])) {
- return coordinates.map(function (coords) {
- return _this.projectCoords(coords);
- });
- } else {
- var circum = this.getCircum();
- var extent = this.getSphereExtent(),
- sx = extent.sx,
- sy = extent.sy;
- var wrapX, wrapY;
- var pre = coordinates[0],
- current,
- dx,
- dy,
- p;
- var prj = [this.project(pre)];
- for (var i = 1, l = coordinates.length; i < l; i++) {
- current = coordinates[i];
- dx = current.x - pre.x;
- dy = current.y - pre.y;
- p = this.project(current);
- if (Math.abs(dx) > 180) {
- if (wrapX === undefined) {
- wrapX = current.x < pre.x;
- }
- if (wrapX) {
- p._add(-circum.x * sign(dx) * sx, 0);
- current._add(-360 * sign(dx), 0);
- }
- }
- if (Math.abs(dy) > 90) {
- if (wrapY === undefined) {
- wrapY = current.y < pre.y;
- }
- if (wrapY) {
- p._add(0, -circum.y * sign(dy) * sy);
- current._add(0, -180 * sign(dy));
- }
- }
- pre = current;
- prj.push(p);
- }
- return prj;
- }
- },
- unprojectCoords: function unprojectCoords(projCoords) {
- if (!projCoords) {
- return [];
- }
- if (!Array.isArray(projCoords)) {
- return this.unproject(projCoords);
- }
- return forEachCoord(projCoords, this.unproject, this);
- },
- isSphere: function isSphere() {
- return !!this.sphere;
- },
- isOutSphere: function isOutSphere(pcoord) {
- if (!this.isSphere()) {
- return false;
- }
- var extent = this.getSphereExtent();
- return !extent.contains(pcoord);
- },
- wrapCoord: function wrapCoord(pcoord) {
- if (!this.isSphere()) {
- return pcoord;
- }
- var extent = this.getSphereExtent();
- var wrapped = new Coordinate(pcoord);
- if (!extent.contains(wrapped)) {
- wrapped.x = wrap(pcoord.x, extent.xmin, extent.xmax);
- wrapped.y = wrap(pcoord.y, extent.ymin, extent.ymax);
- }
- return wrapped;
- },
- getCircum: function getCircum() {
- if (!this.circum && this.isSphere()) {
- var extent = this.getSphereExtent();
- this.circum = {
- x: extent.getWidth(),
- y: extent.getHeight()
- };
- }
- return this.circum;
- },
- getSphereExtent: function getSphereExtent() {
- if (!this.extent && this.isSphere()) {
- var max = this.project(new Coordinate(180, 90)),
- min = this.project(new Coordinate(-180, -90));
- this.extent = new Extent(min, max, this);
- this.extent.sx = max.x > min.x ? 1 : -1;
- this.extent.sy = max.y > min.y ? 1 : -1;
- }
- return this.extent;
- }
- };
- var Common$1 = {
- measureLength: function measureLength(c1, c2) {
- if (!Array.isArray(c1)) {
- return this.measureLenBetween(c1, c2);
- }
- var len = 0;
- for (var i = 0, l = c1.length; i < l - 1; i++) {
- len += this.measureLenBetween(c1[i], c1[i + 1]);
- }
- return len;
- }
- };
- var types = ['Unknown', 'Point', 'LineString', 'Polygon', 'MultiPoint', 'MultiLineString', 'MultiPolygon', 'GeometryCollection'];
- function createFilter(filter) {
- return new Function('f', "var p = (f && f.properties || {}); return " + compile(filter));
- }
- function compile(filter) {
- if (!filter) return 'true';
- var op = filter[0];
- if (filter.length <= 1) return op === 'any' ? 'false' : 'true';
- var str = op === '==' ? compileComparisonOp(filter[1], filter[2], '===', false) : op === '!=' ? compileComparisonOp(filter[1], filter[2], '!==', false) : op === '<' || op === '>' || op === '<=' || op === '>=' ? compileComparisonOp(filter[1], filter[2], op, true) : op === 'any' ? compileLogicalOp(filter.slice(1), '||') : op === 'all' ? compileLogicalOp(filter.slice(1), '&&') : op === 'none' ? compileNegation(compileLogicalOp(filter.slice(1), '||')) : op === 'in' ? compileInOp(filter[1], filter.slice(2)) : op === '!in' ? compileNegation(compileInOp(filter[1], filter.slice(2))) : op === 'has' ? compileHasOp(filter[1]) : op === '!has' ? compileNegation(compileHasOp(filter[1])) : 'true';
- return "(" + str + ")";
- }
- function compilePropertyReference(property) {
- return property[0] === '$' ? 'f.' + property.substring(1) : 'p[' + JSON.stringify(property) + ']';
- }
- function compileComparisonOp(property, value, op, checkType) {
- var left = compilePropertyReference(property);
- var right = property === '$type' ? types.indexOf(value) : JSON.stringify(value);
- return (checkType ? "typeof " + left + "=== typeof " + right + "&&" : '') + left + op + right;
- }
- function getFilterFeature(geometry) {
- var json = geometry._toJSON(),
- g = json['feature'];
- g['type'] = types.indexOf(g['geometry']['type']);
- g['subType'] = json['subType'];
- return g;
- }
- var Sphere = function () {
- function Sphere(radius) {
- this.radius = radius;
- }
- var _proto = Sphere.prototype;
- _proto.measureLenBetween = function measureLenBetween(c1, c2) {
- if (!c1 || !c2) {
- return 0;
- }
- var b = toRadian(c1.y);
- var d = toRadian(c2.y),
- e = b - d,
- f = toRadian(c1.x) - toRadian(c2.x);
- b = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(e / 2), 2) + Math.cos(b) * Math.cos(d) * Math.pow(Math.sin(f / 2), 2)));
- b *= this.radius;
- return Math.round(b * 1E5) / 1E5;
- };
- _proto.measureArea = function measureArea(coordinates) {
- var a = toRadian(this.radius);
- var b = 0,
- c = coordinates,
- d = c.length;
- if (d < 3) {
- return 0;
- }
- var i;
- for (i = 0; i < d - 1; i++) {
- var e = c[i],
- f = c[i + 1];
- b += e.x * a * Math.cos(toRadian(e.y)) * f.y * a - f.x * a * Math.cos(toRadian(f.y)) * e.y * a;
- }
- d = c[i];
- c = c[0];
- b += d.x * a * Math.cos(toRadian(d.y)) * c.y * a - c.x * a * Math.cos(toRadian(c.y)) * d.y * a;
- return 0.5 * Math.abs(b);
- };
- _proto.locate = function locate(c, xDist, yDist) {
- c = new Coordinate(c.x, c.y);
- return this._locate(c, xDist, yDist);
- };
- _proto._locate = function _locate(c, xDist, yDist) {
- if (!c) {
- return null;
- }
- if (!xDist) {
- xDist = 0;
- }
- if (!yDist) {
- yDist = 0;
- }
- if (!xDist && !yDist) {
- return c;
- }
- var x, y;
- var ry = toRadian(c.y);
- if (yDist !== 0) {
- var dy = Math.abs(yDist);
- var sy = Math.sin(dy / (2 * this.radius)) * 2;
- ry = ry + sy * (yDist > 0 ? 1 : -1);
- y = wrap(ry * 180 / Math.PI, -90, 90);
- } else {
- y = c.y;
- }
- if (xDist !== 0) {
- var dx = Math.abs(xDist);
- var rx = toRadian(c.x);
- var sx = 2 * Math.sqrt(Math.pow(Math.sin(dx / (2 * this.radius)), 2) / Math.pow(Math.cos(ry), 2));
- rx = rx + sx * (xDist > 0 ? 1 : -1);
- x = wrap(rx * 180 / Math.PI, -180, 180);
- } else {
- x = c.x;
- }
- c.x = x;
- c.y = y;
- return c;
- };
- _proto.rotate = function rotate(c, pivot, angle) {
- c = new Coordinate(c);
- return this._rotate(c, pivot, angle);
- };
- _proto._rotate = function _rotate(c, pivot, angle) {
- var initialAngle = rhumbBearing(pivot, c);
- var finalAngle = initialAngle - angle;
- var distance = this.measureLenBetween(pivot, c);
- c.x = pivot.x;
- c.y = pivot.y;
- return calculateRhumbDestination(c, distance, finalAngle, this.radius);
- };
- return Sphere;
- }();
- var WGS84Sphere = extend({
- 'measure': 'EPSG:4326',
- sphere: new Sphere(6378137),
- measureLenBetween: function measureLenBetween() {
- return this.sphere.measureLenBetween.apply(this.sphere, arguments);
- },
- measureArea: function measureArea() {
- return this.sphere.measureArea.apply(this.sphere, arguments);
- },
- _locate: function _locate() {
- return this.sphere._locate.apply(this.sphere, arguments);
- },
- locate: function locate() {
- return this.sphere.locate.apply(this.sphere, arguments);
- },
- _rotate: function _rotate() {
- return this.sphere._rotate.apply(this.sphere, arguments);
- },
- rotate: function rotate() {
- return this.sphere.rotate.apply(this.sphere, arguments);
- }
- }, Common$1);
- var BaiduSphere = extend({
- 'measure': 'BAIDU',
- sphere: new Sphere(6370996.81),
- measureLenBetween: function measureLenBetween() {
- return this.sphere.measureLenBetween.apply(this.sphere, arguments);
- },
- measureArea: function measureArea() {
- return this.sphere.measureArea.apply(this.sphere, arguments);
- },
- _locate: function _locate() {
- return this.sphere._locate.apply(this.sphere, arguments);
- },
- locate: function locate() {
- return this.sphere.locate.apply(this.sphere, arguments);
- },
- _rotate: function _rotate() {
- return this.sphere._rotate.apply(this.sphere, arguments);
- },
- rotate: function rotate() {
- return this.sphere.rotate.apply(this.sphere, arguments);
- }
- }, Common$1);
- var DEFAULT = WGS84Sphere;
- var EPSG3857 = extend({}, Common, {
- code: 'EPSG:3857',
- rad: Math.PI / 180,
- metersPerDegree: 6378137 * Math.PI / 180,
- maxLatitude: 85.0511287798,
- project: function project(lnglat) {
- var rad = this.rad,
- metersPerDegree = this.metersPerDegree,
- max = this.maxLatitude;
- var lng = lnglat.x,
- lat = Math.max(Math.min(max, lnglat.y), -max);
- var c;
- if (lat === 0) {
- c = 0;
- } else {
- c = Math.log(Math.tan((90 + lat) * rad / 2)) / rad;
- }
- return new Coordinate(lng * metersPerDegree, c * metersPerDegree);
- },
- unproject: function unproject(pLnglat) {
- var x = pLnglat.x,
- y = pLnglat.y;
- var rad = this.rad,
- metersPerDegree = this.metersPerDegree;
- var c;
- if (y === 0) {
- c = 0;
- } else {
- c = y / metersPerDegree;
- c = (2 * Math.atan(Math.exp(c * rad)) - Math.PI / 2) / rad;
- }
- return new Coordinate(wrap(x / metersPerDegree, -180, 180), wrap(c, -this.maxLatitude, this.maxLatitude));
- }
- }, WGS84Sphere);
- var PROJ4326 = extend({}, Common, {
- code: 'EPSG:4326',
- project: function project(p) {
- return new Coordinate(p);
- },
- unproject: function unproject(p) {
- return new Coordinate(p);
- }
- }, WGS84Sphere);
- var DEFAULT$1 = EPSG3857;
- var Projection_EPSG4490 = extend({}, PROJ4326, {
- code: 'EPSG:4490'
- });
- var Projection_Baidu = extend({}, Common, {
- code: 'BAIDU',
- project: function project(p) {
- return this.convertLL2MC(p);
- },
- unproject: function unproject(p) {
- return this.convertMC2LL(p);
- }
- }, BaiduSphere, {
- EARTHRADIUS: 6370996.81,
- MCBAND: [12890594.86, 8362377.87, 5591021, 3481989.83, 1678043.12, 0],
- LLBAND: [75, 60, 45, 30, 15, 0],
- MC2LL: [[1.410526172116255e-8, 0.00000898305509648872, -1.9939833816331, 200.9824383106796, -187.2403703815547, 91.6087516669843, -23.38765649603339, 2.57121317296198, -0.03801003308653, 17337981.2], [-7.435856389565537e-9, 0.000008983055097726239, -0.78625201886289, 96.32687599759846, -1.85204757529826, -59.36935905485877, 47.40033549296737, -16.50741931063887, 2.28786674699375, 10260144.86], [-3.030883460898826e-8, 0.00000898305509983578, 0.30071316287616, 59.74293618442277, 7.357984074871, -25.38371002664745, 13.45380521110908, -3.29883767235584, 0.32710905363475, 6856817.37], [-1.981981304930552e-8, 0.000008983055099779535, 0.03278182852591, 40.31678527705744, 0.65659298677277, -4.44255534477492, 0.85341911805263, 0.12923347998204, -0.04625736007561, 4482777.06], [3.09191371068437e-9, 0.000008983055096812155, 0.00006995724062, 23.10934304144901, -0.00023663490511, -0.6321817810242, -0.00663494467273, 0.03430082397953, -0.00466043876332, 2555164.4], [2.890871144776878e-9, 0.000008983055095805407, -3.068298e-8, 7.47137025468032, -0.00000353937994, -0.02145144861037, -0.00001234426596, 0.00010322952773, -0.00000323890364, 826088.5]],
- LL2MC: [[-0.0015702102444, 111320.7020616939, 1704480524535203, -10338987376042340, 26112667856603880, -35149669176653700, 26595700718403920, -10725012454188240, 1800819912950474, 82.5], [0.0008277824516172526, 111320.7020463578, 647795574.6671607, -4082003173.641316, 10774905663.51142, -15171875531.51559, 12053065338.62167, -5124939663.577472, 913311935.9512032, 67.5], [0.00337398766765, 111320.7020202162, 4481351.045890365, -23393751.19931662, 79682215.47186455, -115964993.2797253, 97236711.15602145, -43661946.33752821, 8477230.501135234, 52.5], [0.00220636496208, 111320.7020209128, 51751.86112841131, 3796837.749470245, 992013.7397791013, -1221952.21711287, 1340652.697009075, -620943.6990984312, 144416.9293806241, 37.5], [-0.0003441963504368392, 111320.7020576856, 278.2353980772752, 2485758.690035394, 6070.750963243378, 54821.18345352118, 9540.606633304236, -2710.55326746645, 1405.483844121726, 22.5], [-0.0003218135878613132, 111320.7020701615, 0.00369383431289, 823725.6402795718, 0.46104986909093, 2351.343141331292, 1.58060784298199, 8.77738589078284, 0.37238884252424, 7.45]],
- convertMC2LL: function convertMC2LL(cB) {
- var cC = {
- x: Math.abs(cB.x),
- y: Math.abs(cB.y)
- };
- var cE;
- for (var cD = 0, len = this.MCBAND.length; cD < len; cD++) {
- if (cC.y >= this.MCBAND[cD]) {
- cE = this.MC2LL[cD];
- break;
- }
- }
- var T = this.convertor(cB, cE);
- var result = new Coordinate(T.x, T.y);
- return result;
- },
- convertLL2MC: function convertLL2MC(T) {
- var cD, cC, len;
- T.x = this.getLoop(T.x, -180, 180);
- T.y = this.getRange(T.y, -74, 74);
- var cB = new Coordinate(T.x, T.y);
- for (cC = 0, len = this.LLBAND.length; cC < len; cC++) {
- if (cB.y >= this.LLBAND[cC]) {
- cD = this.LL2MC[cC];
- break;
- }
- }
- if (!cD) {
- for (cC = this.LLBAND.length - 1; cC >= 0; cC--) {
- if (cB.y <= -this.LLBAND[cC]) {
- cD = this.LL2MC[cC];
- break;
- }
- }
- }
- var cE = this.convertor(T, cD);
- var result = new Coordinate(cE.x, cE.y);
- return result;
- },
- convertor: function convertor(cC, cD) {
- if (!cC || !cD) {
- return null;
- }
- var T = cD[0] + cD[1] * Math.abs(cC.x);
- var cB = Math.abs(cC.y) / cD[9];
- var cE = cD[2] + cD[3] * cB + cD[4] * cB * cB + cD[5] * cB * cB * cB + cD[6] * cB * cB * cB * cB + cD[7] * cB * cB * cB * cB * cB + cD[8] * cB * cB * cB * cB * cB * cB;
- T *= cC.x < 0 ? -1 : 1;
- cE *= cC.y < 0 ? -1 : 1;
- return new Coordinate(T, cE);
- },
- toRadians: function toRadians(T) {
- return Math.PI * T / 180;
- },
- toDegrees: function toDegrees(T) {
- return 180 * T / Math.PI;
- },
- getRange: function getRange(cC, cB, T) {
- if (cB != null) {
- cC = Math.max(cC, cB);
- }
- if (T != null) {
- cC = Math.min(cC, T);
- }
- return cC;
- },
- getLoop: function getLoop(cC, cB, T) {
- while (cC > T) {
- cC -= T - cB;
- }
- while (cC < cB) {
- cC += T - cB;
- }
- return cC;
- }
- });
- var Projection_IDENTITY = extend({}, Common, {
- code: 'IDENTITY',
- project: function project(p) {
- return p.copy();
- },
- unproject: function unproject(p) {
- return p.copy();
- }
- }, Identity);
- var projections = /*#__PURE__*/Object.freeze({
- EPSG3857: EPSG3857,
- DEFAULT: DEFAULT$1,
- EPSG4326: PROJ4326,
- EPSG4490: Projection_EPSG4490,
- BAIDU: Projection_Baidu,
- IDENTITY: Projection_IDENTITY,
- Common: Common
- });
- var SpatialReference = function () {
- function SpatialReference(options) {
- if (options === void 0) {
- options = {};
- }
- this.options = options;
- this._initSpatialRef();
- }
- SpatialReference.getProjectionInstance = function getProjectionInstance(prjName) {
- if (!prjName) {
- return null;
- }
- if (isObject(prjName)) {
- return prjName;
- }
- prjName = (prjName + '').toLowerCase();
- for (var p in projections) {
- if (hasOwn(projections, p)) {
- var code = projections[p]['code'];
- if (code && code.toLowerCase() === prjName) {
- return projections[p];
- }
- }
- }
- return null;
- };
- SpatialReference.equals = function equals(sp1, sp2) {
- if (!sp1 && !sp2) {
- return true;
- } else if (!sp1 || !sp2) {
- return false;
- }
- if (sp1.projection !== sp2.projection) {
- return false;
- }
- var f1 = sp1.fullExtent,
- f2 = sp2.fullExtent;
- if (f1 && f2) {
- if (f1.top !== f2.top || f1.bottom !== f2.bottom || f1.left !== f2.left || f1.right !== f2.right) {
- return false;
- }
- }
- var r1 = sp1.resolutions,
- r2 = sp2.resolutions;
- if (r1 && r2) {
- if (r1.length !== r2.length) {
- return false;
- }
- for (var i = 0; i < r1.length; i++) {
- if (r1[i] !== r2[i]) {
- return false;
- }
- }
- }
- return true;
- };
- var _proto = SpatialReference.prototype;
- _proto._initSpatialRef = function _initSpatialRef() {
- var projection = this.options['projection'];
- if (projection) {
- projection = SpatialReference.getProjectionInstance(projection);
- } else {
- projection = DEFAULT$1;
- }
- if (!projection) {
- throw new Error('must provide a valid projection in map\'s spatial reference.');
- }
- projection = extend({}, Common, projection);
- if (!projection.measureLength) {
- extend(projection, Measurer.DEFAULT);
- }
- this._projection = projection;
- var defaultSpatialRef,
- resolutions = this.options['resolutions'];
- if (!resolutions) {
- if (projection['code']) {
- defaultSpatialRef = DefaultSpatialRef[projection['code']];
- if (defaultSpatialRef) {
- resolutions = defaultSpatialRef['resolutions'];
- }
- }
- if (!resolutions) {
- throw new Error('must provide valid resolutions in map\'s spatial reference.');
- }
- }
- this._resolutions = resolutions;
- var fullExtent = this.options['fullExtent'];
- if (!fullExtent) {
- if (projection['code']) {
- defaultSpatialRef = DefaultSpatialRef[projection['code']];
- if (defaultSpatialRef) {
- fullExtent = defaultSpatialRef['fullExtent'];
- }
- }
- if (!fullExtent) {
- throw new Error('must provide a valid fullExtent in map\'s spatial reference.');
- }
- }
- if (!isNil(fullExtent['left'])) {
- this._fullExtent = new Extent(new Coordinate(fullExtent['left'], fullExtent['top']), new Coordinate(fullExtent['right'], fullExtent['bottom']));
- } else {
- this._fullExtent = new Extent(fullExtent);
- fullExtent['left'] = fullExtent['xmin'];
- fullExtent['right'] = fullExtent['xmax'];
- fullExtent['top'] = fullExtent['ymax'];
- fullExtent['bottom'] = fullExtent['ymin'];
- }
- if (isNil(fullExtent['top']) || isNil(fullExtent['bottom']) || isNil(fullExtent['left']) || isNil(fullExtent['right'])) {
- throw new Error('must provide valid top/bottom/left/right in fullExtent.');
- }
- extend(this._fullExtent, fullExtent);
- this._projection.fullExtent = fullExtent;
- var a = fullExtent['right'] >= fullExtent['left'] ? 1 : -1,
- b = fullExtent['top'] >= fullExtent['bottom'] ? -1 : 1;
- this._transformation = new Transformation([a, b, 0, 0]);
- };
- _proto.getResolutions = function getResolutions() {
- return this._resolutions || [];
- };
- _proto.getResolution = function getResolution(zoom) {
- var z = zoom | 0;
- if (z < 0) {
- z = 0;
- } else if (z > this._resolutions.length - 1) {
- z = this._resolutions.length - 1;
- }
- var res = this._resolutions[z];
- if (!isInteger(zoom) && z !== this._resolutions.length - 1) {
- var next = this._resolutions[z + 1];
- return res + (next - res) * (zoom - z);
- }
- return res;
- };
- _proto.getProjection = function getProjection() {
- return this._projection;
- };
- _proto.getFullExtent = function getFullExtent() {
- return this._fullExtent;
- };
- _proto.getTransformation = function getTransformation() {
- return this._transformation;
- };
- _proto.getMinZoom = function getMinZoom() {
- for (var i = 0; i < this._resolutions.length; i++) {
- if (!isNil(this._resolutions[i])) {
- return i;
- }
- }
- return 0;
- };
- _proto.getMaxZoom = function getMaxZoom() {
- for (var i = this._resolutions.length - 1; i >= 0; i--) {
- if (!isNil(this._resolutions[i])) {
- return i;
- }
- }
- return this._resolutions.length - 1;
- };
- _proto.getZoomDirection = function getZoomDirection() {
- return sign(this._resolutions[this.getMinZoom()] - this._resolutions[this.getMaxZoom()]);
- };
- _proto.toJSON = function toJSON() {
- if (!this.json) {
- this.json = {
- 'resolutions': this._resolutions,
- 'fullExtent': {
- 'top': this._fullExtent.top,
- 'left': this._fullExtent.left,
- 'bottom': this._fullExtent.bottom,
- 'right': this._fullExtent.right
- },
- 'projection': this._projection.code
- };
- }
- return this.json;
- };
- return SpatialReference;
- }();
- var Eventable = function Eventable(Base) {
- return function (_Base) {
- _inheritsLoose(_class, _Base);
- function _class() {
- return _Base.apply(this, arguments) || this;
- }
- var _proto = _class.prototype;
- _proto.on = function on$$1(eventsOn, handler, context) {
- if (!eventsOn) {
- return this;
- }
- if (!isString(eventsOn)) {
- return this._switch('on', eventsOn, handler);
- }
- if (!handler) {
- return this;
- }
- if (!this._eventMap) {
- this._eventMap = {};
- }
- var eventTypes = eventsOn.toLowerCase().split(' ');
- var evtType;
- if (!context) {
- context = this;
- }
- var handlerChain;
- for (var ii = 0, ll = eventTypes.length; ii < ll; ii++) {
- evtType = eventTypes[ii];
- handlerChain = this._eventMap[evtType];
- if (!handlerChain) {
- handlerChain = [];
- this._eventMap[evtType] = handlerChain;
- }
- var l = handlerChain.length;
- if (l > 0) {
- for (var i = 0; i < l; i++) {
- if (handler === handlerChain[i].handler && handlerChain[i].context === context) {
- return this;
- }
- }
- }
- handlerChain.push({
- handler: handler,
- context: context
- });
- }
- return this;
- };
- _proto.addEventListener = function addEventListener() {
- return this.on.apply(this, arguments);
- };
- _proto.once = function once(eventTypes, handler, context) {
- if (!isString(eventTypes)) {
- var once = {};
- for (var p in eventTypes) {
- if (eventTypes.hasOwnProperty(p)) {
- once[p] = this._wrapOnceHandler(p, eventTypes[p], context);
- }
- }
- return this._switch('on', once);
- }
- var evetTypes = eventTypes.split(' ');
- for (var i = 0, l = evetTypes.length; i < l; i++) {
- this.on(evetTypes[i], this._wrapOnceHandler(evetTypes[i], handler, context));
- }
- return this;
- };
- _proto.off = function off$$1(eventsOff, handler, context) {
- if (!this._eventMap || !eventsOff) {
- return this;
- }
- if (!isString(eventsOff)) {
- return this._switch('off', eventsOff, handler);
- }
- if (!handler) {
- return this;
- }
- var eventTypes = eventsOff.split(' ');
- var eventType, listeners, wrapKey;
- if (!context) {
- context = this;
- }
- for (var j = 0, jl = eventTypes.length; j < jl; j++) {
- eventType = eventTypes[j].toLowerCase();
- wrapKey = 'Z__' + eventType;
- listeners = this._eventMap[eventType];
- if (!listeners) {
- return this;
- }
- for (var i = listeners.length - 1; i >= 0; i--) {
- var listener = listeners[i];
- if ((handler === listener.handler || handler === listener.handler[wrapKey]) && listener.context === context) {
- delete listener.handler[wrapKey];
- listeners.splice(i, 1);
- }
- }
- }
- return this;
- };
- _proto.removeEventListener = function removeEventListener() {
- return this.off.apply(this, arguments);
- };
- _proto.listens = function listens(eventType, handler, context) {
- if (!this._eventMap || !isString(eventType)) {
- return 0;
- }
- var handlerChain = this._eventMap[eventType.toLowerCase()];
- if (!handlerChain || !handlerChain.length) {
- return 0;
- }
- var count = 0;
- for (var i = 0, len = handlerChain.length; i < len; i++) {
- if (handler) {
- if (handler === handlerChain[i].handler && (isNil(context) || handlerChain[i].context === context)) {
- return 1;
- }
- } else {
- count++;
- }
- }
- return count;
- };
- _proto.copyEventListeners = function copyEventListeners(target) {
- var eventMap = target._eventMap;
- if (!eventMap) {
- return this;
- }
- var handlerChain;
- for (var eventType in eventMap) {
- handlerChain = eventMap[eventType];
- for (var i = 0, len = handlerChain.length; i < len; i++) {
- this.on(eventType, handlerChain[i].handler, handlerChain[i].context);
- }
- }
- return this;
- };
- _proto.fire = function fire() {
- if (this._eventParent) {
- return this._eventParent.fire.apply(this._eventParent, arguments);
- }
- return this._fire.apply(this, arguments);
- };
- _proto._wrapOnceHandler = function _wrapOnceHandler(evtType, handler, context) {
- var me = this;
- var key = 'Z__' + evtType;
- var called = false;
- var fn = function onceHandler() {
- if (called) {
- return;
- }
- delete fn[key];
- called = true;
- if (context) {
- handler.apply(context, arguments);
- } else {
- handler.apply(this, arguments);
- }
- me.off(evtType, onceHandler, this);
- };
- fn[key] = handler;
- return fn;
- };
- _proto._switch = function _switch(to, eventKeys, context) {
- for (var p in eventKeys) {
- if (eventKeys.hasOwnProperty(p)) {
- this[to](p, eventKeys[p], context);
- }
- }
- return this;
- };
- _proto._clearListeners = function _clearListeners(eventType) {
- if (!this._eventMap || !isString(eventType)) {
- return;
- }
- var handlerChain = this._eventMap[eventType.toLowerCase()];
- if (!handlerChain) {
- return;
- }
- this._eventMap[eventType] = null;
- };
- _proto._clearAllListeners = function _clearAllListeners() {
- this._eventMap = null;
- };
- _proto._setEventParent = function _setEventParent(parent) {
- this._eventParent = parent;
- return this;
- };
- _proto._fire = function _fire(eventType, param) {
- if (!this._eventMap) {
- return this;
- }
- var handlerChain = this._eventMap[eventType.toLowerCase()];
- if (!handlerChain) {
- return this;
- }
- if (!param) {
- param = {};
- }
- param['type'] = eventType;
- param['target'] = this;
- var queue = handlerChain.slice(0);
- var context, bubble, passed;
- for (var i = 0, len = queue.length; i < len; i++) {
- if (!queue[i]) {
- continue;
- }
- context = queue[i].context;
- bubble = true;
- passed = extend({}, param);
- if (context) {
- bubble = queue[i].handler.call(context, passed);
- } else {
- bubble = queue[i].handler(passed);
- }
- if (bubble === false) {
- if (param['domEvent']) {
- stopPropagation(param['domEvent']);
- }
- }
- }
- return this;
- };
- return _class;
- }(Base);
- };
- var Handler = function () {
- function Handler(target) {
- this.target = target;
- }
- var _proto = Handler.prototype;
- _proto.enable = function enable() {
- if (this._enabled) {
- return this;
- }
- this._enabled = true;
- this.addHooks();
- return this;
- };
- _proto.disable = function disable() {
- if (!this._enabled) {
- return this;
- }
- this._enabled = false;
- this.removeHooks();
- return this;
- };
- _proto.enabled = function enabled() {
- return !!this._enabled;
- };
- _proto.remove = function remove() {
- this.disable();
- delete this.target;
- delete this.dom;
- };
- return Handler;
- }();
- var Handler$1 = Eventable(Handler);
- function Handlerable(Base) {
- return function (_Base) {
- _inheritsLoose(_class, _Base);
- function _class() {
- return _Base.apply(this, arguments) || this;
- }
- var _proto = _class.prototype;
- _proto.addHandler = function addHandler(name, handlerClass) {
- if (!handlerClass) {
- return this;
- }
- if (!this._handlers) {
- this._handlers = [];
- }
- if (this[name]) {
- this[name].enable();
- return this;
- }
- var handler = this[name] = new handlerClass(this);
- this._handlers.push(handler);
- if (this.options[name]) {
- handler.enable();
- }
- return this;
- };
- _proto.removeHandler = function removeHandler(name) {
- if (!name) {
- return this;
- }
- var handler = this[name];
- if (handler) {
- var hit = this._handlers.indexOf(handler);
- if (hit >= 0) {
- this._handlers.splice(hit, 1);
- }
- this[name].remove();
- delete this[name];
- }
- return this;
- };
- _proto._clearHandlers = function _clearHandlers() {
- for (var i = 0, len = this._handlers.length; i < len; i++) {
- this._handlers[i].remove();
- }
- this._handlers = [];
- };
- return _class;
- }(Base);
- }
- var registeredTypes = {};
- var JSONAble = (function (Base) {
- return function (_Base) {
- _inheritsLoose(_class, _Base);
- function _class() {
- return _Base.apply(this, arguments) || this;
- }
- _class.registerJSONType = function registerJSONType(type) {
- if (!type) {
- return this;
- }
- registeredTypes[type] = this;
- return this;
- };
- _class.getJSONClass = function getJSONClass(type) {
- if (!type) {
- return null;
- }
- return registeredTypes[type];
- };
- var _proto = _class.prototype;
- _proto.getJSONType = function getJSONType() {
- if (this._jsonType === undefined) {
- var clazz = Object.getPrototypeOf(this).constructor;
- for (var p in registeredTypes) {
- if (registeredTypes[p] === clazz) {
- this._jsonType = p;
- break;
- }
- }
- }
- if (!this._jsonType) {
- throw new Error('Found an unregistered geometry class!');
- }
- return this._jsonType;
- };
- return _class;
- }(Base);
- });
- var Class = function () {
- function Class(options) {
- if (!this || !this.setOptions) {
- throw new Error('Class instance is being created without "new" operator.');
- }
- this.setOptions(options);
- this.callInitHooks();
- }
- var _proto = Class.prototype;
- _proto.callInitHooks = function callInitHooks() {
- var proto = Object.getPrototypeOf(this);
- this._visitInitHooks(proto);
- return this;
- };
- _proto.setOptions = function setOptions(options) {
- if (!this.hasOwnProperty('options')) {
- this.options = this.options ? Object.create(this.options) : {};
- }
- if (!options) {
- return this;
- }
- for (var i in options) {
- this.options[i] = options[i];
- }
- return this;
- };
- _proto.config = function config(conf) {
- if (!conf) {
- var config = {};
- for (var p in this.options) {
- if (this.options.hasOwnProperty(p)) {
- config[p] = this.options[p];
- }
- }
- return config;
- } else {
- if (arguments.length === 2) {
- var t = {};
- t[conf] = arguments[1];
- conf = t;
- }
- for (var i in conf) {
- this.options[i] = conf[i];
- if (this[i] && this[i] instanceof Handler$1) {
- if (conf[i]) {
- this[i].enable();
- } else {
- this[i].disable();
- }
- }
- }
- this.onConfig(conf);
- }
- return this;
- };
- _proto.onConfig = function onConfig() { };
- _proto._visitInitHooks = function _visitInitHooks(proto) {
- if (this._initHooksCalled) {
- return;
- }
- var parentProto = Object.getPrototypeOf(proto);
- if (parentProto._visitInitHooks) {
- parentProto._visitInitHooks.call(this, parentProto);
- }
- this._initHooksCalled = true;
- var hooks = proto._initHooks;
- if (hooks && hooks !== parentProto._initHooks) {
- for (var i = 0; i < hooks.length; i++) {
- hooks[i].call(this);
- }
- }
- };
- Class.addInitHook = function addInitHook(fn) {
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
- args[_key - 1] = arguments[_key];
- }
- var init = typeof fn === 'function' ? fn : function () {
- this[fn].apply(this, args);
- };
- var proto = this.prototype;
- var parentProto = Object.getPrototypeOf(proto);
- if (!proto._initHooks || proto._initHooks === parentProto._initHooks) {
- proto._initHooks = [];
- }
- proto._initHooks.push(init);
- return this;
- };
- Class.include = function include() {
- for (var i = 0; i < arguments.length; i++) {
- extend(this.prototype, i < 0 || arguments.length <= i ? undefined : arguments[i]);
- }
- return this;
- };
- Class.mergeOptions = function mergeOptions(options) {
- var proto = this.prototype;
- var parentProto = Object.getPrototypeOf(proto);
- if (!proto.options || proto.options === parentProto.options) {
- proto.options = proto.options ? Object.create(proto.options) : {};
- }
- extend(proto.options, options);
- return this;
- };
- return Class;
- }();
- var options$2 = {
- 'id': null,
- 'visible': true,
- 'editable': true,
- 'cursor': null,
- 'defaultProjection': 'EPSG:4326'
- };
- var Geometry = function (_JSONAble) {
- _inheritsLoose(Geometry, _JSONAble);
- function Geometry(options) {
- var _this;
- var opts = extend({}, options);
- var symbol = opts['symbol'];
- var properties = opts['properties'];
- var id = opts['id'];
- delete opts['symbol'];
- delete opts['id'];
- delete opts['properties'];
- _this = _JSONAble.call(this, opts) || this;
- if (symbol) {
- _this.setSymbol(symbol);
- }
- if (properties) {
- _this.setProperties(properties);
- }
- if (!isNil(id)) {
- _this.setId(id);
- }
- return _this;
- }
- var _proto = Geometry.prototype;
- _proto.getFirstCoordinate = function getFirstCoordinate() {
- if (this.type === 'GeometryCollection') {
- var geometries = this.getGeometries();
- if (!geometries.length) {
- return null;
- }
- return geometries[0].getFirstCoordinate();
- }
- var coordinates = this.getCoordinates();
- if (!Array.isArray(coordinates)) {
- return coordinates;
- }
- do {
- coordinates = coordinates[0];
- } while (Array.isArray(coordinates) && coordinates.length > 0);
- return coordinates;
- };
- _proto.getLastCoordinate = function getLastCoordinate() {
- if (this.type === 'GeometryCollection') {
- var geometries = this.getGeometries();
- if (!geometries.length) {
- return null;
- }
- return geometries[geometries.length - 1].getLastCoordinate();
- }
- var coordinates = this.getCoordinates();
- if (!Array.isArray(coordinates)) {
- return coordinates;
- }
- do {
- coordinates = coordinates[coordinates.length - 1];
- } while (Array.isArray(coordinates) && coordinates.length > 0);
- return coordinates;
- };
- _proto.addTo = function addTo(layer, fitview) {
- layer.addGeometry(this, fitview);
- return this;
- };
- _proto.getLayer = function getLayer() {
- if (!this._layer) {
- return null;
- }
- return this._layer;
- };
- _proto.getMap = function getMap() {
- if (!this._layer) {
- return null;
- }
- return this._layer.getMap();
- };
- _proto.getId = function getId() {
- return this._id;
- };
- _proto.setId = function setId(id) {
- var oldId = this.getId();
- this._id = id;
- this._fireEvent('idchange', {
- 'old': oldId,
- 'new': id
- });
- return this;
- };
- _proto.getProperties = function getProperties() {
- if (!this.properties) {
- if (this._getParent()) {
- return this._getParent().getProperties();
- }
- return null;
- }
- return this.properties;
- };
- _proto.setProperties = function setProperties(properties) {
- var old = this.properties;
- this.properties = isObject(properties) ? extend({}, properties) : properties;
- this._repaint();
- this._fireEvent('propertieschange', {
- 'old': old,
- 'new': properties
- });
- return this;
- };
- _proto.getType = function getType() {
- return this.type;
- };
- _proto.getSymbol = function getSymbol() {
- var s = this._symbol;
- if (s) {
- if (!Array.isArray(s)) {
- return extend({}, s);
- } else {
- return extendSymbol(s);
- }
- }
- return null;
- };
- _proto.setSymbol = function setSymbol(symbol) {
- this._symbol = this._prepareSymbol(symbol);
- this.onSymbolChanged();
- return this;
- };
- _proto.updateSymbol = function updateSymbol(props) {
- if (!props) {
- return this;
- }
- var s = this._getSymbol();
- if (s) {
- s = extendSymbol(s, props);
- } else {
- s = extendSymbol(this._getInternalSymbol(), props);
- }
- return this.setSymbol(s);
- };
- _proto.getCenter = function getCenter() {
- return this._computeCenter(this._getMeasurer());
- };
- _proto.getExtent = function getExtent() {
- var prjExt = this._getPrjExtent();
- if (prjExt) {
- var p = this._getProjection();
- var min = p.unproject(new Coordinate(prjExt['xmin'], prjExt['ymin'])),
- max = p.unproject(new Coordinate(prjExt['xmax'], prjExt['ymax']));
- return new Extent(min, max, this._getProjection());
- } else {
- return this._computeExtent(this._getMeasurer());
- }
- };
- _proto.getContainerExtent = function getContainerExtent() {
- var painter = this._getPainter();
- return painter ? painter.getContainerExtent() : null;
- };
- _proto.getSize = function getSize() {
- var extent = this.getContainerExtent();
- return extent ? extent.getSize() : null;
- };
- _proto.containsPoint = function containsPoint(containerPoint, t) {
- if (!this.getMap()) {
- throw new Error('The geometry is required to be added on a map to perform "containsPoint".');
- }
- if (containerPoint instanceof Coordinate) {
- containerPoint = this.getMap().coordToContainerPoint(containerPoint);
- }
- return this._containsPoint(containerPoint, t);
- };
- _proto._containsPoint = function _containsPoint(containerPoint, t) {
- var painter = this._getPainter();
- if (!painter) {
- return false;
- }
- if (isNil(t) && this._hitTestTolerance) {
- t = this._hitTestTolerance();
- }
- return painter.hitTest(containerPoint, t);
- };
- _proto.show = function show() {
- this.options['visible'] = true;
- if (this.getMap()) {
- var painter = this._getPainter();
- if (painter) {
- painter.show();
- }
- this._fireEvent('show');
- }
- return this;
- };
- _proto.hide = function hide() {
- this.options['visible'] = false;
- if (this.getMap()) {
- this.onHide();
- var painter = this._getPainter();
- if (painter) {
- painter.hide();
- }
- this._fireEvent('hide');
- }
- return this;
- };
- _proto.isVisible = function isVisible() {
- if (!this.options['visible']) {
- return false;
- }
- var symbol = this._getInternalSymbol();
- if (!symbol) {
- return true;
- }
- if (Array.isArray(symbol)) {
- if (!symbol.length) {
- return true;
- }
- for (var i = 0, l = symbol.length; i < l; i++) {
- if (isNil(symbol[i]['opacity']) || symbol[i]['opacity'] > 0) {
- return true;
- }
- }
- return false;
- } else {
- return isNil(symbol['opacity']) || isNumber(symbol['opacity']) && symbol['opacity'] > 0;
- }
- };
- _proto.getZIndex = function getZIndex() {
- return this.options['zIndex'] || 0;
- };
- _proto.setZIndex = function setZIndex(zIndex) {
- var old = this.options['zIndex'];
- this.options['zIndex'] = zIndex;
- this._fireEvent('zindexchange', {
- 'old': old,
- 'new': zIndex
- });
- return this;
- };
- _proto.setZIndexSilently = function setZIndexSilently(zIndex) {
- this.options['zIndex'] = zIndex;
- return this;
- };
- _proto.bringToFront = function bringToFront() {
- var layer = this.getLayer();
- if (!layer || !layer.getGeoMaxZIndex) {
- return this;
- }
- var topZ = layer.getGeoMaxZIndex();
- this.setZIndex(topZ + 1);
- return this;
- };
- _proto.bringToBack = function bringToBack() {
- var layer = this.getLayer();
- if (!layer || !layer.getGeoMinZIndex) {
- return this;
- }
- var bottomZ = layer.getGeoMinZIndex();
- this.setZIndex(bottomZ - 1);
- return this;
- };
- _proto.translate = function translate(x, y) {
- if (isNil(x)) {
- return this;
- }
- var offset = new Coordinate(x, y);
- if (offset.x === 0 && offset.y === 0) {
- return this;
- }
- var coordinates = this.getCoordinates();
- if (coordinates) {
- if (Array.isArray(coordinates)) {
- var translated = forEachCoord(coordinates, function (coord) {
- return coord.add(offset);
- });
- this.setCoordinates(translated);
- } else {
- this.setCoordinates(coordinates.add(offset));
- }
- }
- return this;
- };
- _proto.flash = function flash$$1(interval, count, cb, context) {
- return flash.call(this, interval, count, cb, context);
- };
- _proto.copy = function copy() {
- var json = this.toJSON();
- var ret = Geometry.fromJSON(json);
- ret.options['visible'] = true;
- return ret;
- };
- _proto.remove = function remove() {
- var layer = this.getLayer();
- if (!layer) {
- return this;
- }
- this._fireEvent('removestart');
- this._unbind();
- this._fireEvent('removeend');
- this._fireEvent('remove');
- return this;
- };
- _proto.toGeoJSONGeometry = function toGeoJSONGeometry() {
- var gJson = this._exportGeoJSONGeometry();
- return gJson;
- };
- _proto.toGeoJSON = function toGeoJSON(opts) {
- if (!opts) {
- opts = {};
- }
- var feature = {
- 'type': 'Feature',
- 'geometry': null
- };
- if (isNil(opts['geometry']) || opts['geometry']) {
- var geoJSON = this._exportGeoJSONGeometry();
- feature['geometry'] = geoJSON;
- }
- var id = this.getId();
- if (!isNil(id)) {
- feature['id'] = id;
- }
- var properties;
- if (isNil(opts['properties']) || opts['properties']) {
- properties = this._exportProperties();
- }
- feature['properties'] = properties;
- return feature;
- };
- _proto.toJSON = function toJSON(options) {
- if (!options) {
- options = {};
- }
- var json = this._toJSON(options);
- var other = this._exportGraphicOptions(options);
- extend(json, other);
- return json;
- };
- _proto.getLength = function getLength() {
- return this._computeGeodesicLength(this._getMeasurer());
- };
- _proto.getArea = function getArea() {
- return this._computeGeodesicArea(this._getMeasurer());
- };
- _proto.rotate = function rotate(angle, pivot) {
- if (this.type === 'GeometryCollection') {
- var geometries = this.getGeometries();
- geometries.forEach(function (g) {
- return g.rotate(angle, pivot);
- });
- return this;
- }
- if (!pivot) {
- pivot = this.getCenter();
- } else {
- pivot = new Coordinate(pivot);
- }
- var measurer = this._getMeasurer();
- var coordinates = this.getCoordinates();
- if (!Array.isArray(coordinates)) {
- if (pivot.x !== coordinates.x || pivot.y !== coordinates.y) {
- var c = measurer._rotate(coordinates, pivot, angle);
- this.setCoordinates(c);
- }
- return this;
- }
- forEachCoord(coordinates, function (c) {
- return measurer._rotate(c, pivot, angle);
- });
- this.setCoordinates(coordinates);
- return this;
- };
- _proto._getConnectPoints = function _getConnectPoints() {
- return [this.getCenter()];
- };
- _proto._initOptions = function _initOptions(options) {
- var opts = extend({}, options);
- var symbol = opts['symbol'];
- var properties = opts['properties'];
- var id = opts['id'];
- delete opts['symbol'];
- delete opts['id'];
- delete opts['properties'];
- this.setOptions(opts);
- if (symbol) {
- this.setSymbol(symbol);
- }
- if (properties) {
- this.setProperties(properties);
- }
- if (!isNil(id)) {
- this.setId(id);
- }
- };
- _proto._bindLayer = function _bindLayer(layer) {
- if (this.getLayer()) {
- throw new Error('Geometry cannot be added to two or more layers at the same time.');
- }
- this._layer = layer;
- this._clearCache();
- this._clearProjection();
- };
- _proto._prepareSymbol = function _prepareSymbol(symbol) {
- if (Array.isArray(symbol)) {
- var cookedSymbols = [];
- for (var i = 0; i < symbol.length; i++) {
- cookedSymbols.push(convertResourceUrl(this._checkAndCopySymbol(symbol[i])));
- }
- return cookedSymbols;
- } else if (symbol) {
- symbol = this._checkAndCopySymbol(symbol);
- return convertResourceUrl(symbol);
- }
- return null;
- };
- _proto._checkAndCopySymbol = function _checkAndCopySymbol(symbol) {
- var s = {};
- for (var i in symbol) {
- if (NUMERICAL_PROPERTIES[i] && isString(symbol[i])) {
- s[i] = +symbol[i];
- } else {
- s[i] = symbol[i];
- }
- }
- return s;
- };
- _proto._getSymbol = function _getSymbol() {
- return this._symbol;
- };
- _proto._setExternSymbol = function _setExternSymbol(symbol) {
- this._externSymbol = this._prepareSymbol(symbol);
- this.onSymbolChanged();
- return this;
- };
- _proto._getInternalSymbol = function _getInternalSymbol() {
- if (this._symbol) {
- return this._symbol;
- } else if (this._externSymbol) {
- return this._externSymbol;
- } else if (this.options['symbol']) {
- return this.options['symbol'];
- }
- return null;
- };
- _proto._getPrjExtent = function _getPrjExtent() {
- var p = this._getProjection();
- this._verifyProjection();
- if (!this._extent && p) {
- this._extent = this._computePrjExtent(p);
- }
- return this._extent;
- };
- _proto._unbind = function _unbind() {
- var layer = this.getLayer();
- if (!layer) {
- return;
- }
- if (this._animPlayer) {
- this._animPlayer.finish();
- }
- this._clearHandlers();
- this._unbindMenu();
- this._unbindInfoWindow();
- if (this.isEditing()) {
- this.endEdit();
- }
- this._removePainter();
- if (this.onRemove) {
- this.onRemove();
- }
- if (layer.onRemoveGeometry) {
- layer.onRemoveGeometry(this);
- }
- delete this._layer;
- delete this._internalId;
- delete this._extent;
- };
- _proto._getInternalId = function _getInternalId() {
- return this._internalId;
- };
- _proto._setInternalId = function _setInternalId(id) {
- this._internalId = id;
- };
- _proto._getMeasurer = function _getMeasurer() {
- if (this._getProjection()) {
- return this._getProjection();
- }
- return SpatialReference.getProjectionInstance(this.options['defaultProjection']);
- };
- _proto._getProjection = function _getProjection() {
- var map = this.getMap();
- if (map) {
- return map.getProjection();
- }
- return null;
- };
- _proto._verifyProjection = function _verifyProjection() {
- var projection = this._getProjection();
- if (this._projCode && (!projection || this._projCode !== projection.code)) {
- this._clearProjection();
- }
- this._projCode = projection ? projection.code : null;
- };
- _proto._getExternalResources = function _getExternalResources() {
- var symbol = this._getInternalSymbol();
- return getExternalResources(symbol);
- };
- _proto._getPainter = function _getPainter() {
- if (!this._painter && this.getMap()) {
- if (GEOMETRY_COLLECTION_TYPES.indexOf(this.type) !== -1) {
- this._painter = new CollectionPainter(this);
- } else {
- this._painter = new Painter(this);
- }
- }
- return this._painter;
- };
- _proto._removePainter = function _removePainter() {
- if (this._painter) {
- this._painter.remove();
- }
- delete this._painter;
- };
- _proto._paint = function _paint(extent) {
- if (this._painter) {
- this._painter.paint(extent);
- }
- };
- _proto._clearCache = function _clearCache() {
- delete this._extent;
- };
- _proto._clearProjection = function _clearProjection() {
- delete this._extent;
- };
- _proto._repaint = function _repaint() {
- if (this._painter) {
- this._painter.repaint();
- }
- };
- _proto.onHide = function onHide() {
- this.closeMenu();
- this.closeInfoWindow();
- };
- _proto.onShapeChanged = function onShapeChanged() {
- this._clearCache();
- this._repaint();
- this._fireEvent('shapechange');
- };
- _proto.onPositionChanged = function onPositionChanged() {
- this._clearCache();
- this._repaint();
- this._fireEvent('positionchange');
- };
- _proto.onSymbolChanged = function onSymbolChanged() {
- if (this._painter) {
- this._painter.refreshSymbol();
- }
- this._fireEvent('symbolchange');
- };
- _proto.onConfig = function onConfig(conf) {
- var properties;
- if (conf['properties']) {
- properties = conf['properties'];
- delete conf['properties'];
- }
- var needRepaint = false;
- for (var p in conf) {
- if (conf.hasOwnProperty(p)) {
- var prefix = p.slice(0, 5);
- if (prefix === 'arrow' || prefix === 'smoot') {
- needRepaint = true;
- break;
- }
- }
- }
- if (properties) {
- this.setProperties(properties);
- this._repaint();
- } else if (needRepaint) {
- this._repaint();
- }
- };
- _proto._setParent = function _setParent(geometry) {
- if (geometry) {
- this._parent = geometry;
- }
- };
- _proto._getParent = function _getParent() {
- return this._parent;
- };
- _proto._fireEvent = function _fireEvent(eventName, param) {
- if (this.getLayer() && this.getLayer()._onGeometryEvent) {
- if (!param) {
- param = {};
- }
- param['type'] = eventName;
- param['target'] = this;
- this.getLayer()._onGeometryEvent(param);
- }
- this.fire(eventName, param);
- };
- _proto._toJSON = function _toJSON(options) {
- return {
- 'feature': this.toGeoJSON(options)
- };
- };
- _proto._exportGraphicOptions = function _exportGraphicOptions(options) {
- var json = {};
- if (isNil(options['options']) || options['options']) {
- json['options'] = this.config();
- }
- if (isNil(options['symbol']) || options['symbol']) {
- json['symbol'] = this.getSymbol();
- }
- if (isNil(options['infoWindow']) || options['infoWindow']) {
- if (this._infoWinOptions) {
- json['infoWindow'] = this._infoWinOptions;
- }
- }
- return json;
- };
- _proto._exportGeoJSONGeometry = function _exportGeoJSONGeometry() {
- var points = this.getCoordinates();
- var coordinates = Coordinate.toNumberArrays(points);
- return {
- 'type': this.getType(),
- 'coordinates': coordinates
- };
- };
- _proto._exportProperties = function _exportProperties() {
- var properties = null;
- var geoProperties = this.getProperties();
- if (!isNil(geoProperties)) {
- if (isObject(geoProperties)) {
- properties = extend({}, geoProperties);
- } else {
- properties = geoProperties;
- }
- }
- return properties;
- };
- return Geometry;
- }(JSONAble(Eventable(Handlerable(Class))));
- Geometry.mergeOptions(options$2);
- var Marker = function (_CenterMixin) {
- _inheritsLoose(Marker, _CenterMixin);
- function Marker(coordinates, opts) {
- var _this;
- _this = _CenterMixin.call(this, opts) || this;
- _this.type = 'Point';
- if (coordinates) {
- _this.setCoordinates(coordinates);
- }
- return _this;
- }
- var _proto = Marker.prototype;
- _proto.getOutline = function getOutline() {
- var painter = this._getPainter();
- if (!painter) {
- return null;
- }
- var coord = this.getCoordinates();
- var extent = painter.getContainerExtent();
- var anchor = this.getMap().coordToContainerPoint(coord);
- return new Marker(coord, {
- 'symbol': {
- 'markerType': 'square',
- 'markerWidth': extent.getWidth(),
- 'markerHeight': extent.getHeight(),
- 'markerLineWidth': 1,
- 'markerLineColor': '6b707b',
- 'markerFill': 'rgba(0, 0, 0, 0)',
- 'markerDx': extent.xmin - (anchor.x - extent.getWidth() / 2),
- 'markerDy': extent.ymin - (anchor.y - extent.getHeight() / 2)
- }
- });
- };
- _proto._isVectorMarker = function _isVectorMarker() {
- var symbol = this._getInternalSymbol();
- if (Array.isArray(symbol)) {
- return false;
- }
- return VectorMarkerSymbolizer.test(symbol);
- };
- _proto._canEdit = function _canEdit() {
- var symbol = this._getInternalSymbol();
- if (Array.isArray(symbol)) {
- return false;
- }
- return VectorMarkerSymbolizer.test(symbol) || VectorPathMarkerSymbolizer.test(symbol) || ImageMarkerSymbolizer.test(symbol);
- };
- _proto._containsPoint = function _containsPoint(point, t) {
- var extent = this.getContainerExtent();
- if (t) {
- extent = extent.expand(t);
- }
- if (extent.contains(point)) {
- if (this.options['hitTestForEvent']) {
- return _CenterMixin.prototype._containsPoint.call(this, point, t);
- } else {
- return true;
- }
- } else {
- return false;
- }
- };
- _proto._computeExtent = function _computeExtent() {
- return computeExtent.call(this, 'getCenter');
- };
- _proto._computePrjExtent = function _computePrjExtent() {
- return computeExtent.call(this, '_getPrjCoordinates');
- };
- _proto._computeGeodesicLength = function _computeGeodesicLength() {
- return 0;
- };
- _proto._computeGeodesicArea = function _computeGeodesicArea() {
- return 0;
- };
- _proto._getSprite = function _getSprite(resources, canvasClass) {
- if (this._getPainter()) {
- return this._getPainter().getSprite(resources, canvasClass);
- }
- return new Painter(this).getSprite(resources, canvasClass);
- };
- return Marker;
- }(CenterMixin(Geometry));
- var options$3 = {
- 'smoothness': 0,
- 'enableClip': true,
- 'enableSimplify': true,
- 'simplifyTolerance': 2,
- 'symbol': {
- 'lineColor': '#000',
- 'lineWidth': 2,
- 'lineOpacity': 1,
- 'polygonFill': '#fff',
- 'polygonOpacity': 1,
- 'opacity': 1
- }
- };
- var Path = function (_Geometry) {
- _inheritsLoose(Path, _Geometry);
- function Path() {
-
- return _Geometry.apply(this, arguments) || this;
- }
- var _proto = Path.prototype;
- _proto.getOutline = function getOutline() {
- var painter = this._getPainter();
- if (!painter) {
- return null;
- }
- var map = this.getMap();
- var extent = painter.getContainerExtent().convertTo(function (c) {
- return map.containerPointToCoord(c);
- });
- return new Polygon(extent.toArray(), {
- symbol: {
- 'lineWidth': 1,
- 'lineColor': '6b707b'
- }
- });
- };
- _proto.animateShow = function animateShow(options, cb) {
- var _this = this;
- if (options === void 0) {
- options = {};
- }
- if (this._showPlayer) {
- this._showPlayer.finish();
- }
- if (isFunction(options)) {
- options = {};
- cb = options;
- }
- var coordinates = this.getCoordinates();
- if (coordinates.length === 0) {
- return this;
- }
- this._animIdx = 0;
- this._animLenSoFar = 0;
- this.show();
- var isPolygon = !!this.getShell;
- var animCoords = isPolygon ? this.getShell().concat(this.getShell()[0]) : this.getCoordinates();
- var projection = this._getProjection();
- this._aniShowCenter = projection.unproject(this._getPrjExtent().getCenter());
- var duration = options['duration'] || 1000,
- length = this.getLength(),
- easing = options['easing'] || 'out';
- this.setCoordinates([]);
- var player = this._showPlayer = Animation.animate({
- 't': duration
- }, {
- 'duration': duration,
- 'easing': easing
- }, function (frame) {
- if (!_this.getMap()) {
- if (player.playState !== 'finished') {
- player.finish();
- if (cb) {
- var _coordinates = _this.getCoordinates();
- cb(frame, _coordinates[_coordinates.length - 1]);
- }
- }
- return;
- }
- var currentCoord = _this._drawAnimShowFrame(frame.styles.t, duration, length, animCoords);
- if (frame.state.playState === 'finished') {
- delete _this._showPlayer;
- delete _this._aniShowCenter;
- delete _this._animIdx;
- delete _this._animLenSoFar;
- delete _this._animTailRatio;
- _this.setCoordinates(coordinates);
- }
- if (cb) {
- cb(frame, currentCoord);
- }
- });
- player.play();
- return player;
- };
- _proto._drawAnimShowFrame = function _drawAnimShowFrame(t, duration, length, coordinates) {
- if (t === 0) {
- return coordinates[0];
- }
- var map = this.getMap();
- var targetLength = t / duration * length;
- var segLen = 0;
- var i, l;
- for (i = this._animIdx, l = coordinates.length; i < l - 1; i++) {
- segLen = map.computeLength(coordinates[i], coordinates[i + 1]);
- if (this._animLenSoFar + segLen > targetLength) {
- break;
- }
- this._animLenSoFar += segLen;
- }
- this._animIdx = i;
- if (this._animIdx >= l - 1) {
- this.setCoordinates(coordinates);
- return coordinates[coordinates.length - 1];
- }
- var idx = this._animIdx;
- var p1 = coordinates[idx],
- p2 = coordinates[idx + 1],
- span = targetLength - this._animLenSoFar,
- r = span / segLen;
- this._animTailRatio = r;
- var x = p1.x + (p2.x - p1.x) * r,
- y = p1.y + (p2.y - p1.y) * r,
- targetCoord = new Coordinate(x, y);
- var isPolygon = !!this.getShell;
- if (!isPolygon && this.options['smoothness'] > 0) {
- var animCoords = coordinates.slice(0, this._animIdx + 3);
- this.setCoordinates(animCoords);
- } else {
- var _animCoords = coordinates.slice(0, this._animIdx + 1);
- _animCoords.push(targetCoord);
- if (isPolygon) {
- this.setCoordinates([this._aniShowCenter].concat(_animCoords));
- } else {
- this.setCoordinates(_animCoords);
- }
- }
- return targetCoord;
- };
- _proto._getCenterInExtent = function _getCenterInExtent(extent, coordinates, clipFn) {
- var meExtent = this.getExtent();
- if (!extent.intersects(meExtent)) {
- return null;
- }
- var clipped = clipFn(coordinates, extent);
- if (clipped.length === 0) {
- return null;
- }
- var sumx = 0,
- sumy = 0,
- counter = 0;
- clipped.forEach(function (part) {
- if (Array.isArray(part)) {
- part.forEach(function (c) {
- if (c.point) {
- c = c.point;
- }
- sumx += c.x;
- sumy += c.y;
- counter++;
- });
- } else {
- if (part.point) {
- part = part.point;
- }
- sumx += part.x;
- sumy += part.y;
- counter++;
- }
- });
- var c = new Coordinate(sumx, sumy)._multi(1 / counter);
- c.count = counter;
- return c;
- };
- _proto._getPath2DPoints = function _getPath2DPoints(prjCoords, disableSimplify, zoom) {
- if (!isArrayHasData(prjCoords)) {
- return [];
- }
- var map = this.getMap(),
- isSimplify = !disableSimplify && this._shouldSimplify(),
- tolerance = this.options['simplifyTolerance'] * map._getResolution(),
- isMulti = Array.isArray(prjCoords[0]);
- delete this._simplified;
- if (isSimplify && !isMulti) {
- var count = prjCoords.length;
- prjCoords = simplify(prjCoords, tolerance, false);
- this._simplified = prjCoords.length < count;
- }
- if (isNil(zoom)) {
- zoom = map.getZoom();
- }
- return forEachCoord(prjCoords, function (c) {
- return map._prjToPoint(c, zoom);
- });
- };
- _proto._shouldSimplify = function _shouldSimplify() {
- var layer = this.getLayer(),
- properties = this.getProperties();
- var hasAltitude = properties && layer.options['enableAltitude'] && !isNil(properties[layer.options['altitudeProperty']]);
- return layer && layer.options['enableSimplify'] && !hasAltitude && this.options['enableSimplify'] && !this._showPlayer;
- };
- _proto._setPrjCoordinates = function _setPrjCoordinates(prjPoints) {
- this._prjCoords = prjPoints;
- this.onShapeChanged();
- };
- _proto._getPrjCoordinates = function _getPrjCoordinates() {
- var projection = this._getProjection();
- if (!projection) {
- return null;
- }
- this._verifyProjection();
- if (!this._prjCoords) {
- this._prjCoords = this._projectCoords(this._coordinates);
- }
- return this._prjCoords;
- };
- _proto._updateCache = function _updateCache() {
- this._clearCache();
- var projection = this._getProjection();
- if (!projection) {
- return;
- }
- if (this._prjCoords) {
- this._coordinates = this._unprojectCoords(this._getPrjCoordinates());
- }
- };
- _proto._clearProjection = function _clearProjection() {
- this._prjCoords = null;
- _Geometry.prototype._clearProjection.call(this);
- };
- _proto._projectCoords = function _projectCoords(points) {
- var projection = this._getProjection();
- if (projection) {
- return projection.projectCoords(points);
- }
- return [];
- };
- _proto._unprojectCoords = function _unprojectCoords(prjPoints) {
- var projection = this._getProjection();
- if (projection) {
- return projection.unprojectCoords(prjPoints);
- }
- return [];
- };
- _proto._computeCenter = function _computeCenter() {
- var ring = this._coordinates;
- if (!isArrayHasData(ring)) {
- return null;
- }
- var sumx = 0,
- sumy = 0,
- counter = 0;
- var size = ring.length;
- for (var i = 0; i < size; i++) {
- if (ring[i]) {
- if (isNumber(ring[i].x) && isNumber(ring[i].y)) {
- sumx += ring[i].x;
- sumy += ring[i].y;
- counter++;
- }
- }
- }
- return new Coordinate(sumx / counter, sumy / counter);
- };
- _proto._computeExtent = function _computeExtent() {
- var shell = this._coordinates;
- if (!isArrayHasData(shell)) {
- return null;
- }
- var rings = [shell];
- if (this.hasHoles && this.hasHoles()) {
- rings.push.apply(rings, this.getHoles());
- }
- return this._coords2Extent(rings, this._getProjection());
- };
- _proto._computePrjExtent = function _computePrjExtent() {
- var coords = [this._getPrjCoordinates()];
- if (this.hasHoles && this.hasHoles()) {
- coords.push.apply(coords, this._getPrjHoles());
- }
- return this._coords2Extent(coords);
- };
- _proto._get2DLength = function _get2DLength() {
- var vertexes = this._getPath2DPoints(this._getPrjCoordinates(), true);
- var len = 0;
- for (var i = 1, l = vertexes.length; i < l; i++) {
- len += vertexes[i].distanceTo(vertexes[i - 1]);
- }
- return len;
- };
- _proto._hitTestTolerance = function _hitTestTolerance() {
- var symbol = this._getInternalSymbol();
- var w;
- if (Array.isArray(symbol)) {
- w = 0;
- for (var i = 0; i < symbol.length; i++) {
- if (isNumber(symbol[i]['lineWidth'])) {
- if (symbol[i]['lineWidth'] > w) {
- w = symbol[i]['lineWidth'];
- }
- }
- }
- } else {
- w = symbol['lineWidth'];
- }
- return isNumber(w) ? w / 2 : 1.5;
- };
- _proto._coords2Extent = function _coords2Extent(coords, proj) {
- var result = new Extent(proj);
- for (var i = 0, l = coords.length; i < l; i++) {
- for (var j = 0, ll = coords[i].length; j < ll; j++) {
- result._combine(coords[i][j]);
- }
- }
- return result;
- };
- return Path;
- }(Geometry);
- Path.mergeOptions(options$3);
- var Position = function () {
- function Position(x, y) {
- if (!isNil(x) && !isNil(y)) {
- this.x = +x;
- this.y = +y;
- } else if (!isNil(x.x) && !isNil(x.y)) {
- this.x = +x.x;
- this.y = +x.y;
- } else if (Array.isArray(x)) {
- this.x = +x[0];
- this.y = +x[1];
- }
- if (this._isNaN()) {
- throw new Error('Position is NaN');
- }
- }
- var _proto = Position.prototype;
- _proto.abs = function abs() {
- return new this.constructor(Math.abs(this.x), Math.abs(this.y));
- };
- _proto._abs = function _abs() {
- this.x = Math.abs(this.x);
- this.y = Math.abs(this.y);
- return this;
- };
- _proto._round = function _round() {
- this.x = Math.round(this.x);
- this.y = Math.round(this.y);
- return this;
- };
- _proto.round = function round() {
- return new this.constructor(Math.round(this.x), Math.round(this.y));
- };
- _proto._ceil = function _ceil() {
- this.x = Math.ceil(this.x);
- this.y = Math.ceil(this.y);
- return this;
- };
- _proto.ceil = function ceil() {
- return new this.constructor(Math.ceil(this.x), Math.ceil(this.y));
- };
- _proto._floor = function _floor() {
- this.x = Math.floor(this.x);
- this.y = Math.floor(this.y);
- return this;
- };
- _proto.floor = function floor() {
- return new this.constructor(Math.floor(this.x), Math.floor(this.y));
- };
- _proto.copy = function copy() {
- return new this.constructor(this.x, this.y);
- };
- _proto._add = function _add(x, y) {
- if (!isNil(x.x)) {
- this.x += x.x;
- this.y += x.y;
- } else if (!isNil(x[0])) {
- this.x += x[0];
- this.y += x[1];
- } else {
- this.x += x;
- this.y += y;
- }
- return this;
- };
- _proto.add = function add(x, y) {
- var nx, ny;
- if (!isNil(x.x)) {
- nx = this.x + x.x;
- ny = this.y + x.y;
- } else if (!isNil(x[0])) {
- nx = this.x + x[0];
- ny = this.y + x[1];
- } else {
- nx = this.x + x;
- ny = this.y + y;
- }
- return new this.constructor(nx, ny);
- };
- _proto._sub = function _sub(x, y) {
- if (!isNil(x.x)) {
- this.x -= x.x;
- this.y -= x.y;
- } else if (!isNil(x[0])) {
- this.x -= x[0];
- this.y -= x[1];
- } else {
- this.x -= x;
- this.y -= y;
- }
- return this;
- };
- _proto._substract = function _substract() {
- return this._sub.apply(this, arguments);
- };
- _proto.sub = function sub(x, y) {
- var nx, ny;
- if (!isNil(x.x)) {
- nx = this.x - x.x;
- ny = this.y - x.y;
- } else if (!isNil(x[0])) {
- nx = this.x - x[0];
- ny = this.y - x[1];
- } else {
- nx = this.x - x;
- ny = this.y - y;
- }
- return new this.constructor(nx, ny);
- };
- _proto.substract = function substract() {
- return this.sub.apply(this, arguments);
- };
- _proto.multi = function multi(ratio) {
- return new this.constructor(this.x * ratio, this.y * ratio);
- };
- _proto._multi = function _multi(ratio) {
- this.x *= ratio;
- this.y *= ratio;
- return this;
- };
- _proto.div = function div(n) {
- return this.multi(1 / n);
- };
- _proto._div = function _div(n) {
- return this._multi(1 / n);
- };
- _proto.equals = function equals(c) {
- if (!(c instanceof this.constructor)) {
- return false;
- }
- return this.x === c.x && this.y === c.y;
- };
- _proto._isNaN = function _isNaN() {
- return isNaN(this.x) || isNaN(this.y);
- };
- _proto.isZero = function isZero() {
- return this.x === 0 && this.y === 0;
- };
- _proto.toArray = function toArray() {
- return [this.x, this.y];
- };
- _proto.toFixed = function toFixed(n) {
- return new this.constructor(this.x.toFixed(n), this.y.toFixed(n));
- };
- _proto.toJSON = function toJSON() {
- return {
- x: this.x,
- y: this.y
- };
- };
- return Position;
- }();
- var Point = function (_Position) {
- _inheritsLoose(Point, _Position);
- function Point() {
- return _Position.apply(this, arguments) || this;
- }
- var _proto = Point.prototype;
- _proto.closeTo = function closeTo(p, delta) {
- if (!delta) {
- delta = 0;
- }
- return this.x >= p.x - delta && this.x <= p.x + delta && this.y >= p.y - delta && this.y <= p.y + delta;
- };
- _proto.distanceTo = function distanceTo(point) {
- var x = point.x - this.x,
- y = point.y - this.y;
- return Math.sqrt(x * x + y * y);
- };
- _proto.mag = function mag() {
- return Math.sqrt(this.x * this.x + this.y * this.y);
- };
- _proto.unit = function unit() {
- return this.copy()._unit();
- };
- _proto._unit = function _unit() {
- this._div(this.mag());
- return this;
- };
- _proto.perp = function perp() {
- return this.copy()._perp();
- };
- _proto._perp = function _perp() {
- var y = this.y;
- this.y = this.x;
- this.x = -y;
- return this;
- };
- _proto.angleWith = function angleWith(b) {
- return this.angleWithSep(b.x, b.y);
- };
- _proto.angleWithSep = function angleWithSep(x, y) {
- return Math.atan2(this.x * y - this.y * x, this.x * x + this.y * y);
- };
- _proto._rotate = function _rotate(angle) {
- var cos = Math.cos(angle),
- sin = Math.sin(angle),
- x = cos * this.x - sin * this.y,
- y = sin * this.x + cos * this.y;
- this.x = x;
- this.y = y;
- return this;
- };
- _proto.rotate = function rotate(a) {
- return this.copy()._rotate(a);
- };
- return Point;
- }(Position);
- var Identity = extend({
- 'measure': 'IDENTITY',
- measureLenBetween: function measureLenBetween(c1, c2) {
- if (!c1 || !c2) {
- return 0;
- }
- try {
- return Math.sqrt(Math.pow(c1.x - c2.x, 2) + Math.pow(c1.y - c2.y, 2));
- } catch (err) {
- return 0;
- }
- },
- measureArea: function measureArea(coordinates) {
- if (!Array.isArray(coordinates)) {
- return 0;
- }
- var area = 0;
- for (var i = 0, len = coordinates.length; i < len; i++) {
- var c1 = coordinates[i];
- var c2 = null;
- if (i === len - 1) {
- c2 = coordinates[0];
- } else {
- c2 = coordinates[i + 1];
- }
- area += c1.x * c2.y - c1.y * c2.x;
- }
- return Math.abs(area / 2);
- },
- locate: function locate(c, xDist, yDist) {
- c = new Coordinate(c.x, c.y);
- return this._locate(c, xDist, yDist);
- },
- _locate: function _locate(c, xDist, yDist) {
- if (!c) {
- return null;
- }
- if (!xDist) {
- xDist = 0;
- }
- if (!yDist) {
- yDist = 0;
- }
- if (!xDist && !yDist) {
- return c;
- }
- c.x = c.x + xDist;
- c.y = c.y + yDist;
- return c;
- },
- rotate: function rotate(c, pivot, angle) {
- c = new Coordinate(c.x, c.y);
- return this._rotate(c, pivot, angle);
- },
- _rotate: function () {
- var tmp = new Point(0, 0);
- return function (c, pivot, angle) {
- tmp.x = c.x - pivot.x;
- tmp.y = c.y - pivot.y;
- tmp._rotate(angle * Math.PI / 180);
- c.x = pivot.x + tmp.x;
- c.y = pivot.y + tmp.y;
- return c;
- };
- }()
- }, Common$1);
- function _assertThisInitialized(self) {
- if (self === void 0) {
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
- }
- return self;
- }
- var uid = 0;
- function UID() {
- return uid++;
- }
- var DefaultSpatialRef = {
- 'EPSG:3857': {
- 'resolutions': function () {
- var resolutions = [];
- var d = 2 * 6378137 * Math.PI;
- for (var i = 0; i < 21; i++) {
- resolutions[i] = d / (256 * Math.pow(2, i));
- }
- return resolutions;
- }(),
- 'fullExtent': {
- 'top': 6378137 * Math.PI,
- 'left': -6378137 * Math.PI,
- 'bottom': -6378137 * Math.PI,
- 'right': 6378137 * Math.PI
- }
- },
- 'EPSG:4326': {
- 'fullExtent': {
- 'top': 90,
- 'left': -180,
- 'bottom': -90,
- 'right': 180
- },
- 'resolutions': function () {
- var resolutions = [];
- for (var i = 0; i < 20; i++) {
- resolutions[i] = 180 / (Math.pow(2, i) * 128);
- }
- return resolutions;
- }()
- },
- 'BAIDU': {
- 'resolutions': function () {
- var res = Math.pow(2, 18);
- var resolutions = [];
- for (var i = 0; i < 20; i++) {
- resolutions[i] = res;
- res *= 0.5;
- }
- resolutions[0] = null;
- resolutions[1] = null;
- resolutions[2] = null;
- return resolutions;
- }(),
- 'fullExtent': {
- 'top': 33554432,
- 'left': -33554432,
- 'bottom': -33554432,
- 'right': 33554432
- }
- },
- 'IDENTITY': {
- 'resolutions': function () {
- var res = Math.pow(2, 8);
- var resolutions = [];
- for (var i = 0; i < 18; i++) {
- resolutions[i] = res;
- res *= 0.5;
- }
- return resolutions;
- }(),
- 'fullExtent': {
- 'top': 200000,
- 'left': -200000,
- 'bottom': -200000,
- 'right': 200000
- }
- }
- };
- DefaultSpatialRef['EPSG:4490'] = DefaultSpatialRef['EPSG:4326'];
- var Coordinate = function (_Position) {
- _inheritsLoose(Coordinate, _Position);
- function Coordinate() {
- return _Position.apply(this, arguments) || this;
- }
- Coordinate.toNumberArrays = function toNumberArrays(coordinates) {
- if (!Array.isArray(coordinates)) {
- return [coordinates.x, coordinates.y];
- }
- return forEachCoord(coordinates, function (coord) {
- return [coord.x, coord.y];
- });
- };
- Coordinate.toCoordinates = function toCoordinates(coordinates) {
- if (isNumber(coordinates[0]) && isNumber(coordinates[1])) {
- return new Coordinate(coordinates);
- }
- var result = [];
- for (var i = 0, len = coordinates.length; i < len; i++) {
- var child = coordinates[i];
- if (Array.isArray(child)) {
- if (isNumber(child[0])) {
- result.push(new Coordinate(child));
- } else {
- result.push(Coordinate.toCoordinates(child));
- }
- } else {
- result.push(new Coordinate(child));
- }
- }
- return result;
- };
- return Coordinate;
- }(Position);
- var JSON_TYPE = 'Polygon';
- var Polygon = function (_Path) {
- _inheritsLoose(Polygon, _Path);
- function Polygon(coordinates, opts) {
- var _this;
- _this = _Path.call(this, opts) || this;
- _this.type = 'Polygon';
- if (coordinates) {
- _this.setCoordinates(coordinates);
- }
- return _this;
- }
- var _proto = Polygon.prototype;
- _proto.setCoordinates = function setCoordinates(coordinates) {
- if (!coordinates) {
- this._coordinates = null;
- this._holes = null;
- this._projectRings();
- return this;
- }
- var rings = Coordinate.toCoordinates(coordinates);
- var len = rings.length;
- if (!Array.isArray(rings[0])) {
- this._coordinates = this._trimRing(rings);
- } else {
- this._coordinates = this._trimRing(rings[0]);
- if (len > 1) {
- var holes = [];
- for (var i = 1; i < len; i++) {
- if (!rings[i]) {
- continue;
- }
- holes.push(this._trimRing(rings[i]));
- }
- this._holes = holes;
- }
- }
- this._projectRings();
- return this;
- };
- _proto.getCoordinates = function getCoordinates() {
- if (!this._coordinates) {
- return [];
- }
- var holes = this.getHoles();
- var rings = [this._copyAndCloseRing(this._coordinates)];
- for (var i = 0, l = holes.length; i < l; i++) {
- rings.push(this._copyAndCloseRing(holes[i]));
- }
- return rings;
- };
- _proto.getCenterInExtent = function getCenterInExtent(extent) {
- return this._getCenterInExtent(extent, this.getShell(), clipPolygon);
- };
- _proto.getShell = function getShell() {
- return this._coordinates || [];
- };
- _proto.getHoles = function getHoles() {
- return this._holes || [];
- };
- _proto.hasHoles = function hasHoles() {
- return this.getHoles().length > 0;
- };
- _proto._projectRings = function _projectRings() {
- if (!this.getMap()) {
- this.onShapeChanged();
- return;
- }
- this._prjCoords = this._projectCoords(this._coordinates);
- this._prjHoles = this._projectCoords(this._holes);
- this.onShapeChanged();
- };
- _proto._cleanRing = function _cleanRing(ring) {
- for (var i = ring.length - 1; i >= 0; i--) {
- if (!ring[i]) {
- ring.splice(i, 1);
- }
- }
- };
- _proto._checkRing = function _checkRing(ring) {
- this._cleanRing(ring);
- if (!ring || !isArrayHasData(ring)) {
- return false;
- }
- var lastPoint = ring[ring.length - 1];
- var isClose = true;
- if (ring[0].x !== lastPoint.x || ring[0].y !== lastPoint.y) {
- isClose = false;
- }
- return isClose;
- };
- _proto._trimRing = function _trimRing(ring) {
- var isClose = this._checkRing(ring);
- if (isArrayHasData(ring) && isClose) {
- ring.splice(ring.length - 1, 1);
- }
- return ring;
- };
- _proto._copyAndCloseRing = function _copyAndCloseRing(ring) {
- ring = ring.slice(0);
- var isClose = this._checkRing(ring);
- if (isArrayHasData(ring) && !isClose) {
- ring.push(ring[0].copy());
- return ring;
- } else {
- return ring;
- }
- };
- _proto._getPrjShell = function _getPrjShell() {
- if (this.getJSONType() === JSON_TYPE) {
- return this._getPrjCoordinates();
- }
- var projection = this._getProjection();
- if (!projection) {
- return null;
- }
- this._verifyProjection();
- if (!this._prjShell) {
- this._prjShell = this._projectCoords(this.getShell());
- }
- return this._prjShell;
- };
- _proto._getPrjHoles = function _getPrjHoles() {
- var projection = this._getProjection();
- if (!projection) {
- return null;
- }
- this._verifyProjection();
- if (!this._prjHoles) {
- this._prjHoles = this._projectCoords(this.getHoles());
- }
- return this._prjHoles;
- };
- _proto._computeGeodesicLength = function _computeGeodesicLength(measurer) {
- var rings = this.getCoordinates();
- if (!isArrayHasData(rings)) {
- return 0;
- }
- var result = 0;
- for (var i = 0, len = rings.length; i < len; i++) {
- result += measurer.measureLength(rings[i]);
- }
- return result;
- };
- _proto._computeGeodesicArea = function _computeGeodesicArea(measurer) {
- var rings = this.getCoordinates();
- if (!isArrayHasData(rings)) {
- return 0;
- }
- var result = measurer.measureArea(rings[0]);
- for (var i = 1, len = rings.length; i < len; i++) {
- result -= measurer.measureArea(rings[i]);
- }
- return result;
- };
- _proto._updateCache = function _updateCache() {
- _Path.prototype._updateCache.call(this);
- if (this._prjHoles) {
- this._holes = this._unprojectCoords(this._getPrjHoles());
- }
- };
- _proto._clearCache = function _clearCache() {
- delete this._prjShell;
- return _Path.prototype._clearCache.call(this);
- };
- _proto._clearProjection = function _clearProjection() {
- if (this._prjHoles) {
- this._prjHoles = null;
- }
- if (this._prjShell) {
- this._prjShell = null;
- }
- _Path.prototype._clearProjection.call(this);
- };
- return Polygon;
- }(Path);
- Polygon.registerJSONType(JSON_TYPE);
- var options$5 = {
- 'arrowStyle': null,
- 'arrowPlacement': 'vertex-last'
- };
- var LineString = function (_Path) {
- _inheritsLoose(LineString, _Path);
- function LineString(coordinates, options) {
- var _this;
- _this = _Path.call(this, options) || this;
- _this.type = 'LineString';
- if (coordinates) {
- _this.setCoordinates(coordinates);
- }
- return _this;
- }
- var _proto = LineString.prototype;
- _proto.setCoordinates = function setCoordinates(coordinates) {
- if (!coordinates) {
- this._coordinates = null;
- this._setPrjCoordinates(null);
- return this;
- }
- this._coordinates = Coordinate.toCoordinates(coordinates);
- if (this.getMap()) {
- this._setPrjCoordinates(this._projectCoords(this._coordinates));
- } else {
- this.onShapeChanged();
- }
- return this;
- };
- _proto.getCoordinates = function getCoordinates() {
- return this._coordinates || [];
- };
- _proto.getCenterInExtent = function getCenterInExtent(extent) {
- return this._getCenterInExtent(extent, this.getCoordinates(), clipLine);
- };
- _proto._computeGeodesicLength = function _computeGeodesicLength(measurer) {
- return measurer.measureLength(this.getCoordinates());
- };
- _proto._computeGeodesicArea = function _computeGeodesicArea() {
- return 0;
- };
- return LineString;
- }(Path);
- LineString.mergeOptions(options$5);
- LineString.registerJSONType('LineString');
- var GeometryCollection = function (_Geometry) {
- _inheritsLoose(GeometryCollection, _Geometry);
- function GeometryCollection(geometries, opts) {
- var _this;
- _this = _Geometry.call(this, opts) || this;
- _this.type = 'GeometryCollection';
- _this.setGeometries(geometries);
- return _this;
- }
- var _proto = GeometryCollection.prototype;
- _proto.setGeometries = function setGeometries(_geometries) {
- var geometries = this._checkGeometries(_geometries || []);
- var symbol = this._getSymbol();
- var options = this.config();
- for (var i = geometries.length - 1; i >= 0; i--) {
- geometries[i]._initOptions(options);
- geometries[i]._setParent(this);
- geometries[i]._setEventParent(this);
- if (symbol) {
- geometries[i].setSymbol(symbol);
- }
- }
- this._geometries = geometries;
- if (this.getLayer()) {
- this._bindGeometriesToLayer();
- this.onShapeChanged();
- }
- return this;
- };
- _proto.getGeometries = function getGeometries() {
- return this._geometries || [];
- };
- _proto.forEach = function forEach(fn, context) {
- var geometries = this.getGeometries();
- for (var i = 0, l = geometries.length; i < l; i++) {
- if (!geometries[i]) {
- continue;
- }
- if (!context) {
- fn(geometries[i], i);
- } else {
- fn.call(context, geometries[i], i);
- }
- }
- return this;
- };
- _proto.filter = function filter(fn, context) {
- if (!fn) {
- return new GeometryCollection();
- }
- var selected = [];
- var isFn = isFunction(fn);
- var filter = isFn ? fn : createFilter(fn);
- this.forEach(function (geometry) {
- var g = isFn ? geometry : getFilterFeature(geometry);
- if (context ? filter.call(context, g) : filter(g)) {
- selected.push(geometry);
- }
- }, this);
- return new GeometryCollection(selected);
- };
- _proto.translate = function translate(offset) {
- if (!offset) {
- return this;
- }
- if (this.isEmpty()) {
- return this;
- }
- var args = arguments;
- this.forEach(function (geometry) {
- if (geometry && geometry.translate) {
- geometry.translate.apply(geometry, args);
- }
- });
- return this;
- };
- _proto.isEmpty = function isEmpty() {
- return !isArrayHasData(this.getGeometries());
- };
- _proto.remove = function remove() {
- this.forEach(function (geometry) {
- geometry._unbind();
- });
- return Geometry.prototype.remove.apply(this, arguments);
- };
- _proto.show = function show() {
- this.options['visible'] = true;
- this.forEach(function (geometry) {
- geometry.show();
- });
- return this;
- };
- _proto.hide = function hide() {
- this.options['visible'] = false;
- this.forEach(function (geometry) {
- geometry.hide();
- });
- return this;
- };
- _proto.onConfig = function onConfig(config) {
- this.forEach(function (geometry) {
- geometry.config(config);
- });
- };
- _proto.getSymbol = function getSymbol() {
- var s = _Geometry.prototype.getSymbol.call(this);
- if (!s) {
- var symbols = [];
- var is = false;
- this.forEach(function (g) {
- var symbol = g.getSymbol();
- if (symbol && !is) {
- is = true;
- }
- symbols.push(g.getSymbol());
- });
- if (is) {
- s = {
- 'children': symbols
- };
- }
- }
- return s;
- };
- _proto.setSymbol = function setSymbol(s) {
- if (s && s['children']) {
- this._symbol = null;
- this.forEach(function (g, i) {
- g.setSymbol(s['children'][i]);
- });
- } else {
- var symbol = this._prepareSymbol(s);
- this._symbol = symbol;
- this.forEach(function (g) {
- g.setSymbol(symbol);
- });
- }
- this.onSymbolChanged();
- return this;
- };
- _proto._setExternSymbol = function _setExternSymbol(symbol) {
- symbol = this._prepareSymbol(symbol);
- this._externSymbol = symbol;
- this.forEach(function (geometry) {
- geometry._setExternSymbol(symbol);
- });
- this.onSymbolChanged();
- return this;
- };
- _proto._bindLayer = function _bindLayer() {
- _Geometry.prototype._bindLayer.apply(this, arguments);
- this._bindGeometriesToLayer();
- };
- _proto._bindGeometriesToLayer = function _bindGeometriesToLayer() {
- var layer = this.getLayer();
- this.forEach(function (geometry) {
- geometry._bindLayer(layer);
- });
- };
- _proto._checkGeometries = function _checkGeometries(geometries) {
- var invalidGeoError = 'The geometry added to collection is invalid.';
- if (geometries && !Array.isArray(geometries)) {
- if (geometries instanceof Geometry) {
- return [geometries];
- } else {
- throw new Error(invalidGeoError);
- }
- } else {
- for (var i = 0, l = geometries.length; i < l; i++) {
- if (!this._checkGeo(geometries[i])) {
- throw new Error(invalidGeoError + ' Index: ' + i);
- }
- }
- return geometries;
- }
- };
- _proto._checkGeo = function _checkGeo(geo) {
- return geo instanceof Geometry;
- };
- _proto._updateCache = function _updateCache() {
- this._clearCache();
- if (this.isEmpty()) {
- return;
- }
- this.forEach(function (geometry) {
- if (geometry && geometry._updateCache) {
- geometry._updateCache();
- }
- });
- };
- _proto._removePainter = function _removePainter() {
- if (this._painter) {
- this._painter.remove();
- }
- delete this._painter;
- this.forEach(function (geometry) {
- geometry._removePainter();
- });
- };
- _proto._computeCenter = function _computeCenter(projection) {
- if (!projection || this.isEmpty()) {
- return null;
- }
- var sumX = 0,
- sumY = 0,
- counter = 0;
- var geometries = this.getGeometries();
- for (var i = 0, l = geometries.length; i < l; i++) {
- if (!geometries[i]) {
- continue;
- }
- var center = geometries[i]._computeCenter(projection);
- if (center) {
- sumX += center.x;
- sumY += center.y;
- counter++;
- }
- }
- if (counter === 0) {
- return null;
- }
- return new Coordinate(sumX / counter, sumY / counter);
- };
- _proto._containsPoint = function _containsPoint(point, t) {
- if (this.isEmpty()) {
- return false;
- }
- var geometries = this.getGeometries();
- for (var i = 0, l = geometries.length; i < l; i++) {
- if (geometries[i]._containsPoint(point, t)) {
- return true;
- }
- }
- return false;
- };
- _proto._computeExtent = function _computeExtent(projection) {
- return computeExtent$1.call(this, projection, '_computeExtent');
- };
- _proto._computePrjExtent = function _computePrjExtent(projection) {
- return computeExtent$1.call(this, projection, '_computePrjExtent');
- };
- _proto._computeGeodesicLength = function _computeGeodesicLength(projection) {
- if (!projection || this.isEmpty()) {
- return 0;
- }
- var geometries = this.getGeometries();
- var result = 0;
- for (var i = 0, l = geometries.length; i < l; i++) {
- if (!geometries[i]) {
- continue;
- }
- result += geometries[i]._computeGeodesicLength(projection);
- }
- return result;
- };
- _proto._computeGeodesicArea = function _computeGeodesicArea(projection) {
- if (!projection || this.isEmpty()) {
- return 0;
- }
- var geometries = this.getGeometries();
- var result = 0;
- for (var i = 0, l = geometries.length; i < l; i++) {
- if (!geometries[i]) {
- continue;
- }
- result += geometries[i]._computeGeodesicArea(projection);
- }
- return result;
- };
- _proto._exportGeoJSONGeometry = function _exportGeoJSONGeometry() {
- var children = [];
- if (!this.isEmpty()) {
- var geometries = this.getGeometries();
- for (var i = 0, l = geometries.length; i < l; i++) {
- if (!geometries[i]) {
- continue;
- }
- children.push(geometries[i]._exportGeoJSONGeometry());
- }
- }
- return {
- 'type': 'GeometryCollection',
- 'geometries': children
- };
- };
- _proto._clearProjection = function _clearProjection() {
- if (this.isEmpty()) {
- return;
- }
- var geometries = this.getGeometries();
- for (var i = 0, l = geometries.length; i < l; i++) {
- if (!geometries[i]) {
- continue;
- }
- geometries[i]._clearProjection();
- }
- };
- _proto._getConnectPoints = function _getConnectPoints() {
- var extent = this.getExtent();
- var anchors = [new Coordinate(extent.xmin, extent.ymax), new Coordinate(extent.xmax, extent.ymin), new Coordinate(extent.xmin, extent.ymin), new Coordinate(extent.xmax, extent.ymax)];
- return anchors;
- };
- _proto._getExternalResources = function _getExternalResources() {
- if (this.isEmpty()) {
- return [];
- }
- var geometries = this.getGeometries(),
- resources = [];
- var cache = {};
- var symbol, res, key;
- for (var i = 0, l = geometries.length; i < l; i++) {
- if (!geometries[i]) {
- continue;
- }
- symbol = geometries[i]._getInternalSymbol();
- res = getExternalResources(symbol);
- for (var ii = 0, ll = res.length; ii < ll; ii++) {
- key = res[ii].join();
- if (!cache[key]) {
- resources.push(res[ii]);
- cache[key] = 1;
- }
- }
- }
- return resources;
- };
- _proto.startEdit = function startEdit(opts) {
- var _this2 = this;
- if (this.isEmpty()) {
- return this;
- }
- if (!opts) {
- opts = {};
- }
- if (opts['symbol']) {
- this._originalSymbol = this.getSymbol();
- this.setSymbol(opts['symbol']);
- }
- this._draggbleBeforeEdit = this.options['draggable'];
- this.config('draggable', false);
- var geometries = this.getGeometries();
- for (var i = 0, l = geometries.length; i < l; i++) {
- geometries[i].startEdit(opts);
- }
- this._editing = true;
- this.hide();
- setTimeout(function () {
- _this2.fire('editstart');
- }, 1);
- return this;
- };
- _proto.endEdit = function endEdit() {
- if (this.isEmpty()) {
- return this;
- }
- var geometries = this.getGeometries();
- for (var i = 0, l = geometries.length; i < l; i++) {
- geometries[i].endEdit();
- }
- if (this._originalSymbol) {
- this.setSymbol(this._originalSymbol);
- delete this._originalSymbol;
- }
- this._editing = false;
- this.show();
- this.config('draggable', this._draggbleBeforeEdit);
- this.fire('editend');
- return this;
- };
- _proto.isEditing = function isEditing() {
- if (!this._editing) {
- return false;
- }
- return true;
- };
- return GeometryCollection;
- }(Geometry);
- GeometryCollection.registerJSONType('GeometryCollection');
- function toGeometry(geoJSON) {
- if (isString(geoJSON)) {
- geoJSON = parseJSON(geoJSON);
- }
- if (Array.isArray(geoJSON)) {
- var resultGeos = [];
- for (var i = 0, len = geoJSON.length; i < len; i++) {
- var geo = _convert(geoJSON[i]);
- if (Array.isArray(geo)) {
- pushIn(resultGeos, geo);
- } else {
- resultGeos.push(geo);
- }
- }
- return resultGeos;
- } else {
- var resultGeo = GeoJSON._convert(geoJSON);
- return resultGeo;
- }
- }
- var MultiGeometry = function (_GeometryCollection) {
- _inheritsLoose(MultiGeometry, _GeometryCollection);
- function MultiGeometry(geoType, type, data, options) {
- var _this;
- _this = _GeometryCollection.call(this, null, options) || this;
- _this.GeometryType = geoType;
- _this.type = type;
- _this._initData(data);
- return _this;
- }
- var _proto = MultiGeometry.prototype;
- _proto.getCoordinates = function getCoordinates() {
- var coordinates = [];
- var geometries = this.getGeometries();
- for (var i = 0, l = geometries.length; i < l; i++) {
- var child = geometries[i];
- coordinates.push(child.getShell && child.getJSONType() !== 'Polygon' ? [child.getShell()] : child.getCoordinates());
- }
- return coordinates;
- };
- _proto.setCoordinates = function setCoordinates(coordinates) {
- coordinates = coordinates || [];
- var geometries = [];
- for (var i = 0, l = coordinates.length; i < l; i++) {
- var g = new this.GeometryType(coordinates[i], this.config());
- geometries.push(g);
- }
- this.setGeometries(geometries);
- return this;
- };
- _proto._initData = function _initData(data) {
- data = data || [];
- if (data.length) {
- if (data[0] instanceof this.GeometryType) {
- this.setGeometries(data);
- } else {
- this.setCoordinates(data);
- }
- }
- };
- _proto._checkGeo = function _checkGeo(geo) {
- return geo instanceof this.GeometryType;
- };
- _proto._exportGeoJSONGeometry = function _exportGeoJSONGeometry() {
- var points = this.getCoordinates();
- var coordinates = Coordinate.toNumberArrays(points);
- return {
- 'type': this.getType(),
- 'coordinates': coordinates
- };
- };
- return MultiGeometry;
- }(GeometryCollection);
- var MultiPoint = function (_MultiGeometry) {
- _inheritsLoose(MultiPoint, _MultiGeometry);
- function MultiPoint(data, opts) {
- return _MultiGeometry.call(this, Marker, 'MultiPoint', data, opts) || this;
- }
- var _proto = MultiPoint.prototype;
- _proto.findClosest = function findClosest(coordinate) {
- if (!coordinate) {
- return null;
- }
- var coords = this.getCoordinates();
- var hit = null;
- var max = Infinity;
- coords.forEach(function (c) {
- var dist = distanceTo(c, coordinate);
- if (dist < max) {
- hit = c;
- max = dist;
- }
- });
- return hit;
- };
- return MultiPoint;
- }(MultiGeometry);
- MultiPoint.registerJSONType('MultiPoint');
- function distanceTo(p0, p1) {
- var x = p1.x - p0.x,
- y = p1.y - p0.y;
- return Math.sqrt(x * x + y * y);
- }
- var MultiPath = function (_MultiGeometry) {
- _inheritsLoose(MultiPath, _MultiGeometry);
- function MultiPath() {
- return _MultiGeometry.apply(this, arguments) || this;
- }
- var _proto = MultiPath.prototype;
- _proto.getCenterInExtent = function getCenterInExtent(extent) {
- var children = this.getGeometries();
- var sumx = 0,
- sumy = 0,
- counter = 0;
- children.forEach(function (l) {
- var c = l.getCenterInExtent(extent);
- if (c) {
- sumx += c.x * c.count;
- sumy += c.y * c.count;
- counter += c.count;
- }
- });
- if (counter === 0) {
- return null;
- }
- return new Coordinate(sumx, sumy)._multi(1 / counter);
- };
- return MultiPath;
- }(MultiGeometry);
- var MultiLineString = function (_MultiPath) {
- _inheritsLoose(MultiLineString, _MultiPath);
- function MultiLineString(data, options) {
- return _MultiPath.call(this, LineString, 'MultiLineString', data, options) || this;
- }
- return MultiLineString;
- }(MultiPath);
- MultiLineString.registerJSONType('MultiLineString');
- var MultiPolygon = function (_MultiPath) {
- _inheritsLoose(MultiPolygon, _MultiPath);
- function MultiPolygon(data, opts) {
- return _MultiPath.call(this, Polygon, 'MultiPolygon', data, opts) || this;
- }
- return MultiPolygon;
- }(MultiPath);
- function CenterMixin(Base) {
- return function (_Base) {
- _inheritsLoose(_class, _Base);
- function _class() {
- return _Base.apply(this, arguments) || this;
- }
- var _proto = _class.prototype;
- _proto.getCoordinates = function getCoordinates() {
- return this._coordinates;
- };
- _proto.setCoordinates = function setCoordinates(coordinates) {
- var center = coordinates instanceof Coordinate ? coordinates : new Coordinate(coordinates);
- if (center.equals(this._coordinates)) {
- return this;
- }
- this._coordinates = center;
- if (!this.getMap()) {
- this.onPositionChanged();
- return this;
- }
- var projection = this._getProjection();
- this._setPrjCoordinates(projection.project(this._coordinates));
- return this;
- };
- _proto._getCenter2DPoint = function _getCenter2DPoint(zoom) {
- var map = this.getMap();
- if (!map) {
- return null;
- }
- var z = isNil(zoom) ? map.getZoom() : map.getGLZoom();
- var pcenter = this._getPrjCoordinates();
- if (!pcenter) {
- return null;
- }
- return map._prjToPoint(pcenter, z);
- };
- _proto._getPrjCoordinates = function _getPrjCoordinates() {
- var projection = this._getProjection();
- if (!projection) {
- return null;
- }
- this._verifyProjection();
- if (!this._pcenter) {
- if (this._coordinates) {
- this._pcenter = projection.project(this._coordinates);
- }
- }
- return this._pcenter;
- };
- _proto._setPrjCoordinates = function _setPrjCoordinates(pcenter) {
- this._pcenter = pcenter;
- this.onPositionChanged();
- };
- _proto._updateCache = function _updateCache() {
- this._clearCache();
- var projection = this._getProjection();
- if (this._pcenter && projection) {
- this._coordinates = projection.unproject(this._pcenter);
- }
- };
- _proto._clearProjection = function _clearProjection() {
- this._pcenter = null;
- _Base.prototype._clearProjection.call(this);
- };
- _proto._computeCenter = function _computeCenter() {
- return this._coordinates ? this._coordinates.copy() : null;
- };
- return _class;
- }(Base);
- }
- MultiPolygon.registerJSONType('MultiPolygon');
- var types$1 = {
- 'Marker': Marker,
- 'LineString': LineString,
- 'Polygon': Polygon,
- 'MultiPoint': MultiPoint,
- 'MultiLineString': MultiLineString,
- 'MultiPolygon': MultiPolygon
- };
- function _convert(json) {
- if (!json || isNil(json['type'])) {
- return null;
- }
- var type = json['type'];
- if (type === 'Feature') {
- var g = json['geometry'];
- var geometry = _convert(g);
- if (!geometry) {
- return null;
- }
- geometry.setId(json['id']);
- geometry.setProperties(json['properties']);
- return geometry;
- } else if (type === 'FeatureCollection') {
- var features = json['features'];
- if (!features) {
- return null;
- }
- var result = toGeometry(features);
- return result;
- } else if (['Point', 'LineString', 'Polygon', 'MultiPoint', 'MultiLineString', 'MultiPolygon'].indexOf(type) >= 0) {
- var clazz = type === 'Point' ? 'Marker' : type;
- return new types$1[clazz](json['coordinates']);
- } else if (type === 'GeometryCollection') {
- var geometries = json['geometries'];
- if (!isArrayHasData(geometries)) {
- return new GeometryCollection();
- }
- var mGeos = [];
- var size = geometries.length;
- for (var i = 0; i < size; i++) {
- mGeos.push(_convert(geometries[i]));
- }
- return new GeometryCollection(mGeos);
- }
- return null;
- }
- var Renderable = (function (Base) {
- return function (_Base) {
- _inheritsLoose(_class, _Base);
- function _class() {
- return _Base.apply(this, arguments) || this;
- }
- _class.registerRenderer = function registerRenderer(name, clazz) {
- var proto = this.prototype;
- var parentProto = Object.getPrototypeOf(proto);
- if (!proto._rendererClasses || proto._rendererClasses === parentProto._rendererClasses) {
- proto._rendererClasses = proto._rendererClasses ? Object.create(proto._rendererClasses) : {};
- }
- proto._rendererClasses[name.toLowerCase()] = clazz;
- return this;
- };
- _class.getRendererClass = function getRendererClass(name) {
- var proto = this.prototype;
- if (!proto._rendererClasses) {
- return null;
- }
- return proto._rendererClasses[name.toLowerCase()];
- };
- return _class;
- }(Base);
- });
- var IS_NODE = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]' && !process.versions['electron'] && !process.versions['nw'] && !process.versions['node-webkit'];
- var Browser = {};
- // if (!IS_NODE) {
- // var ua = navigator.userAgent.toLowerCase(),
- // doc = document.documentElement,
- // ie = 'ActiveXObject' in window,
- // webkit = ua.indexOf('webkit') !== -1,
- // phantomjs = ua.indexOf('phantom') !== -1,
- // android23 = ua.search('android [23]') !== -1,
- // chrome = ua.indexOf('chrome') !== -1,
- // gecko = ua.indexOf('gecko') !== -1 && !webkit && !window.opera && !ie,
- // mobile = typeof orientation !== 'undefined' || ua.indexOf('mobile') !== -1,
- // msPointer = !window.PointerEvent && window.MSPointerEvent,
- // pointer = window.PointerEvent && navigator.pointerEnabled || msPointer,
- // ie3d = ie && 'transition' in doc.style,
- // webkit3d = 'WebKitCSSMatrix' in window && 'm11' in new window.WebKitCSSMatrix() && !android23,
- // gecko3d = 'MozPerspective' in doc.style,
- // opera12 = 'OTransition' in doc.style,
- // any3d = (ie3d || webkit3d || gecko3d) && !opera12 && !phantomjs;
- // var chromeVersion = 0;
- // if (chrome) {
- // chromeVersion = ua.match(/chrome\/([\d.]+)/)[1];
- // }
- // var touch = !phantomjs && (pointer || 'ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch);
- // var webgl;
- // try {
- // var canvas = document.createElement('canvas');
- // var gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
- // webgl = gl && gl instanceof WebGLRenderingContext;
- // } catch (err) {
- // webgl = false;
- // }
- // Browser = {
- // ie: ie,
- // ielt9: ie && !document.addEventListener,
- // edge: 'msLaunchUri' in navigator && !('documentMode' in document),
- // webkit: webkit,
- // gecko: gecko,
- // android: ua.indexOf('android') !== -1,
- // android23: android23,
- // chrome: chrome,
- // chromeVersion: chromeVersion,
- // safari: !chrome && ua.indexOf('safari') !== -1,
- // phantomjs: phantomjs,
- // ie3d: ie3d,
- // webkit3d: webkit3d,
- // gecko3d: gecko3d,
- // opera12: opera12,
- // any3d: any3d,
- // mobile: mobile,
- // mobileWebkit: mobile && webkit,
- // mobileWebkit3d: mobile && webkit3d,
- // mobileOpera: mobile && window.opera,
- // mobileGecko: mobile && gecko,
- // touch: !!touch,
- // msPointer: !!msPointer,
- // pointer: !!pointer,
- // retina: (window.devicePixelRatio || window.screen.deviceXDPI / window.screen.logicalXDPI) > 1,
- // language: navigator.browserLanguage ? navigator.browserLanguage : navigator.language,
- // ie9: ie && document.documentMode === 9,
- // ie10: ie && document.documentMode === 10,
- // webgl: webgl
- // };
- // }
- var Extent = function () {
- function Extent(p1, p2, p3, p4) {
- this._clazz = Coordinate;
- var l = arguments.length;
- var proj = l > 0 ? arguments[l - 1] : null;
- if (proj && proj.unproject) {
- this.projection = arguments[l - 1];
- }
- this._dirty = true;
- this._initialize(p1, p2, p3, p4);
- }
- var _proto = Extent.prototype;
- _proto._initialize = function _initialize(p1, p2, p3, p4) {
- this.xmin = null;
- this.xmax = null;
- this.ymin = null;
- this.ymax = null;
- if (isNil(p1)) {
- return;
- }
- var projection = this.projection;
- if (isNumber(p1) && isNumber(p2) && isNumber(p3) && isNumber(p4)) {
- if (projection) {
- this['xmin'] = p1;
- this['ymin'] = p2;
- this['xmax'] = p3;
- this['ymax'] = p4;
- } else {
- this['xmin'] = Math.min(p1, p3);
- this['ymin'] = Math.min(p2, p4);
- this['xmax'] = Math.max(p1, p3);
- this['ymax'] = Math.max(p2, p4);
- }
- return;
- } else if (Array.isArray(p1)) {
- if (projection) {
- this['xmin'] = p1[0];
- this['ymin'] = p1[1];
- this['xmax'] = p1[2];
- this['ymax'] = p1[3];
- } else {
- this['xmin'] = Math.min(p1[0], p1[2]);
- this['ymin'] = Math.min(p1[1], p1[3]);
- this['xmax'] = Math.max(p1[0], p1[2]);
- this['ymax'] = Math.max(p1[1], p1[3]);
- }
- } else if (isNumber(p1.x) && isNumber(p2.x) && isNumber(p1.y) && isNumber(p2.y)) {
- if (projection) {
- this['xmin'] = p1.x;
- this['ymin'] = p1.y;
- this['xmax'] = p2.x;
- this['ymax'] = p2.y;
- } else {
- if (p1.x > p2.x) {
- this['xmin'] = p2.x;
- this['xmax'] = p1.x;
- } else {
- this['xmin'] = p1.x;
- this['xmax'] = p2.x;
- }
- if (p1.y > p2.y) {
- this['ymin'] = p2.y;
- this['ymax'] = p1.y;
- } else {
- this['ymin'] = p1.y;
- this['ymax'] = p2.y;
- }
- }
- } else if (isNumber(p1['xmin']) && isNumber(p1['xmax']) && isNumber(p1['ymin']) && isNumber(p1['ymax'])) {
- this['xmin'] = p1['xmin'];
- this['ymin'] = p1['ymin'];
- this['xmax'] = p1['xmax'];
- this['ymax'] = p1['ymax'];
- }
- };
- _proto._add = function _add(p) {
- this._dirty = true;
- if (!isNil(p.x)) {
- this['xmin'] += p.x;
- this['ymin'] += p.y;
- this['xmax'] += p.x;
- this['ymax'] += p.y;
- } else if (!isNil(p.xmin)) {
- this['xmin'] += p.xmin;
- this['ymin'] += p.ymin;
- this['xmax'] += p.xmax;
- this['ymax'] += p.ymax;
- } else if (!isNil(p[0])) {
- this['xmin'] += p[0];
- this['ymin'] += p[1];
- this['xmax'] += p[0];
- this['ymax'] += p[1];
- }
- return this;
- };
- _proto.add = function add() {
- var e = new this.constructor(this['xmin'], this['ymin'], this['xmax'], this['ymax'], this.projection);
- return e._add.apply(e, arguments);
- };
- _proto._sub = function _sub(p) {
- this._dirty = true;
- if (!isNil(p.x)) {
- this['xmin'] -= p.x;
- this['ymin'] -= p.y;
- this['xmax'] -= p.x;
- this['ymax'] -= p.y;
- } else if (!isNil(p.xmin)) {
- this['xmin'] -= p.xmin;
- this['ymin'] -= p.ymin;
- this['xmax'] -= p.xmax;
- this['ymax'] -= p.ymax;
- } else if (!isNil(p[0])) {
- this['xmin'] -= p[0];
- this['ymin'] -= p[1];
- this['xmax'] -= p[0];
- this['ymax'] -= p[1];
- }
- return this;
- };
- _proto._substract = function _substract() {
- return this._sub.apply(this, arguments);
- };
- _proto.sub = function sub() {
- var e = new this.constructor(this['xmin'], this['ymin'], this['xmax'], this['ymax'], this.projection);
- return e._sub.apply(e, arguments);
- };
- _proto.substract = function substract() {
- return this.sub.apply(this, arguments);
- };
- _proto.round = function round() {
- return new this.constructor(Math.round(this['xmin']), Math.round(this['ymin']), Math.round(this['xmax']), Math.round(this['ymax']), this.projection);
- };
- _proto._round = function _round() {
- this._dirty = true;
- this['xmin'] = Math.round(this['xmin']);
- this['ymin'] = Math.round(this['ymin']);
- this['xmax'] = Math.round(this['xmax']);
- this['ymax'] = Math.round(this['ymax']);
- return this;
- };
- _proto.getMin = function getMin() {
- return new this._clazz(this['xmin'], this['ymin']);
- };
- _proto.getMax = function getMax() {
- return new this._clazz(this['xmax'], this['ymax']);
- };
- _proto.getCenter = function getCenter() {
- return new this._clazz((this['xmin'] + this['xmax']) / 2, (this['ymin'] + this['ymax']) / 2);
- };
- _proto.isValid = function isValid() {
- return isNumber(this['xmin']) && isNumber(this['ymin']) && isNumber(this['xmax']) && isNumber(this['ymax']);
- };
- _proto.equals = function equals(ext2) {
- return this['xmin'] === ext2['xmin'] && this['xmax'] === ext2['xmax'] && this['ymin'] === ext2['ymin'] && this['ymax'] === ext2['ymax'];
- };
- _proto.intersects = function intersects(ext2) {
- this._project(this);
- this._project(ext2);
- var rxmin = Math.max(this['pxmin'], ext2['pxmin']);
- var rymin = Math.max(this['pymin'], ext2['pymin']);
- var rxmax = Math.min(this['pxmax'], ext2['pxmax']);
- var rymax = Math.min(this['pymax'], ext2['pymax']);
- var intersects = !(rxmin > rxmax || rymin > rymax);
- return intersects;
- };
- _proto.within = function within(extent) {
- this._project(this);
- this._project(extent);
- return this.pxmin >= extent.pxmin && this.pxmax <= extent.pxmax && this.pymin >= extent.pymin && this.pymax <= extent.pymax;
- };
- _proto.contains = function contains(c) {
- if (!c) {
- return false;
- }
- this._project(this);
- var proj = this.projection;
- if (Array.isArray(c)) {
- c = new this._clazz(c);
- }
- if (proj) {
- c = proj.project(c);
- }
- return c.x >= this.pxmin && c.x <= this.pxmax && c.y >= this.pymin && c.y <= this.pymax;
- };
- _proto.getWidth = function getWidth() {
- return Math.abs(this['xmax'] - this['xmin']);
- };
- _proto.getHeight = function getHeight() {
- return Math.abs(this['ymax'] - this['ymin']);
- };
- _proto.getSize = function getSize() {
- return new Size(this.getWidth(), this.getHeight());
- };
- _proto.__combine = function __combine(extent) {
- if (!(extent instanceof this.constructor)) {
- extent = new this.constructor(extent, extent);
- }
- this._project(extent);
- this._project(this);
- var xmin = this['pxmin'];
- if (!isNumber(xmin)) {
- xmin = extent['pxmin'];
- } else if (isNumber(extent['pxmin'])) {
- if (xmin > extent['pxmin']) {
- xmin = extent['pxmin'];
- }
- }
- var xmax = this['pxmax'];
- if (!isNumber(xmax)) {
- xmax = extent['pxmax'];
- } else if (isNumber(extent['pxmax'])) {
- if (xmax < extent['pxmax']) {
- xmax = extent['pxmax'];
- }
- }
- var ymin = this['pymin'];
- if (!isNumber(ymin)) {
- ymin = extent['pymin'];
- } else if (isNumber(extent['pymin'])) {
- if (ymin > extent['pymin']) {
- ymin = extent['pymin'];
- }
- }
- var ymax = this['pymax'];
- if (!isNumber(ymax)) {
- ymax = extent['pymax'];
- } else if (isNumber(extent['pymax'])) {
- if (ymax < extent['pymax']) {
- ymax = extent['pymax'];
- }
- }
- var proj = this.projection;
- if (proj) {
- var min = proj.unproject(new this._clazz(xmin, ymin)),
- max = proj.unproject(new this._clazz(xmax, ymax));
- xmin = min.x;
- ymin = min.y;
- xmax = max.x;
- ymax = max.y;
- }
- return [xmin, ymin, xmax, ymax];
- };
- _proto._combine = function _combine(extent) {
- if (!extent) {
- return this;
- }
- var ext = this.__combine(extent);
- this['xmin'] = ext[0];
- this['ymin'] = ext[1];
- this['xmax'] = ext[2];
- this['ymax'] = ext[3];
- this._dirty = true;
- return this;
- };
- _proto.combine = function combine(extent) {
- if (!extent) {
- return this;
- }
- var ext = this.__combine(extent);
- return new this.constructor(ext[0], ext[1], ext[2], ext[3], this.projection);
- };
- _proto.intersection = function intersection(extent) {
- if (!this.intersects(extent)) {
- return null;
- }
- var min = new this._clazz(Math.max(this['pxmin'], extent['pxmin']), Math.max(this['pymin'], extent['pymin'])),
- max = new this._clazz(Math.min(this['pxmax'], extent['pxmax']), Math.min(this['pymax'], extent['pymax']));
- var proj = this.projection;
- if (proj) {
- min = proj.unproject(min);
- max = proj.unproject(max);
- }
- return new this.constructor(min, max, proj);
- };
- _proto.expand = function expand(distance) {
- var w, h;
- if (!isNumber(distance)) {
- w = distance['width'] || distance['x'] || distance[0] || 0;
- h = distance['height'] || distance['y'] || distance[1] || 0;
- } else {
- w = h = distance;
- }
- return new this.constructor(this['xmin'] - w, this['ymin'] - h, this['xmax'] + w, this['ymax'] + h, this.projection);
- };
- _proto._expand = function _expand(distance) {
- var w, h;
- if (!isNumber(distance)) {
- w = distance['width'] || distance['x'] || distance[0] || 0;
- h = distance['height'] || distance['y'] || distance[1] || 0;
- } else {
- w = h = distance;
- }
- this['xmin'] -= w;
- this['ymin'] -= h;
- this['xmax'] += w;
- this['ymax'] += h;
- this._dirty = true;
- return this;
- };
- _proto.toJSON = function toJSON() {
- return {
- 'xmin': this['xmin'],
- 'ymin': this['ymin'],
- 'xmax': this['xmax'],
- 'ymax': this['ymax']
- };
- };
- _proto.toArray = function toArray() {
- var xmin = this['xmin'],
- ymin = this['ymin'],
- xmax = this['xmax'],
- ymax = this['ymax'];
- return [new this._clazz([xmin, ymax]), new this._clazz([xmax, ymax]), new this._clazz([xmax, ymin]), new this._clazz([xmin, ymin]), new this._clazz([xmin, ymax])];
- };
- _proto.toString = function toString() {
- return this.xmin + "," + this.ymin + "," + this.xmax + "," + this.ymax;
- };
- _proto.copy = function copy() {
- return new this.constructor(this['xmin'], this['ymin'], this['xmax'], this['ymax'], this.projection);
- };
- _proto.convertTo = function convertTo(fn) {
- if (!this.isValid()) {
- return null;
- }
- var e = new this.constructor();
- var coord = new this._clazz(this.xmin, this.ymax);
- e._combine(fn(coord));
- coord.x = this.xmax;
- e._combine(fn(coord));
- coord.y = this.ymin;
- e._combine(fn(coord));
- coord.x = this.xmin;
- e._combine(fn(coord));
- return e;
- };
- _proto._project = function _project(ext) {
- if (!ext || !ext.isValid()) {
- return;
- }
- var proj = this.projection;
- if (proj) {
- if (ext._dirty) {
- var minmax = [ext.getMin(), ext.getMax()];
- minmax = proj.projectCoords(minmax);
- var min = minmax[0],
- max = minmax[1];
- ext.pxmin = Math.min(min.x, max.x);
- ext.pymin = Math.min(min.y, max.y);
- ext.pxmax = Math.max(min.x, max.x);
- ext.pymax = Math.max(min.y, max.y);
- }
- delete ext._dirty;
- } else {
- ext.pxmin = ext.xmin;
- ext.pxmax = ext.xmax;
- ext.pymin = ext.ymin;
- ext.pymax = ext.ymax;
- }
- };
- return Extent;
- }();
- var Transformation = function () {
- function Transformation(matrix) {
- this.matrix = matrix;
- }
- var _proto = Transformation.prototype;
- _proto.transform = function transform(coordinates, scale) {
- return new Point(this.matrix[0] * (coordinates.x - this.matrix[2]) / scale, this.matrix[1] * (coordinates.y - this.matrix[3]) / scale);
- };
- _proto.untransform = function untransform(point, scale) {
- return new Coordinate(point.x * scale / this.matrix[0] + this.matrix[2], point.y * scale / this.matrix[1] + this.matrix[3]);
- };
- return Transformation;
- }();
- var Browser$1 = Browser;
- var options$1 = {
- 'maxVisualPitch': 60,
- 'maxPitch': 80,
- 'centerCross': false,
- 'zoomInCenter': false,
- 'zoomAnimation': function () {
- return !IS_NODE;
- }(),
- 'zoomAnimationDuration': 330,
- 'panAnimation': function () {
- return !IS_NODE;
- }(),
- 'panAnimationDuration': 600,
- 'zoomable': true,
- 'enableInfoWindow': true,
- 'hitDetect': function () {
- return false;
- }(),
- 'hitDetectLimit': 5,
- 'fpsOnInteracting': 25,
- 'layerCanvasLimitOnInteracting': -1,
- 'maxZoom': null,
- 'minZoom': null,
- 'maxExtent': null,
- 'checkSize': true,
- 'renderer': 'canvas'
- };
- var Map$1 = function (_Handlerable) {
- _inheritsLoose(Map, _Handlerable);
- function Map(container, options) {
- var _this;
- if (!options) {
- throw new Error('Invalid options when creating map.');
- }
- if (!options['center']) {
- throw new Error('Invalid center when creating map.');
- }
- var opts = extend({}, options);
- var zoom = opts['zoom'];
- delete opts['zoom'];
- var center = new Coordinate(opts['center']);
- delete opts['center'];
- var baseLayer = opts['baseLayer'];
- delete opts['baseLayer'];
- var layers = opts['layers'];
- delete opts['layers'];
- _this = _Handlerable.call(this, opts) || this;
- Object.defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), 'id', {
- value: UID(),
- writable: false
- });
- _this._loaded = false;
- // _this._initContainer(container);
- _this._panels = {};
- _this._baseLayer = null;
- _this._layers = [];
- _this._zoomLevel = zoom;
- _this._center = center;
- _this.setSpatialReference(opts['spatialReference'] || opts['view']);
- _this._mapViewPoint = new Point(0, 0);
- // _this._initRenderer();
- // _this._updateMapSize(_this._getContainerDomSize());
- // if (baseLayer) {
- // _this.setBaseLayer(baseLayer);
- // }
- // if (layers) {
- // _this.addLayer(layers);
- // }
- // _this._Load();
- return _this;
- }
- Map.addOnLoadHook = function addOnLoadHook(fn) {
- var args = Array.prototype.slice.call(arguments, 1);
- var onload = typeof fn === 'function' ? fn : function () {
- this[fn].apply(this, args);
- };
- this.prototype._onLoadHooks = this.prototype._onLoadHooks || [];
- this.prototype._onLoadHooks.push(onload);
- return this;
- };
- var _proto = Map.prototype;
- _proto.isLoaded = function isLoaded() {
- return !!this._loaded;
- };
- _proto.getContainer = function getContainer() {
- return this._containerDOM;
- };
- _proto.getSpatialReference = function getSpatialReference() {
- return this._spatialReference;
- };
- _proto.setSpatialReference = function setSpatialReference(ref) {
- var oldRef = this.options['spatialReference'];
- if (this._loaded && SpatialReference.equals(oldRef, ref)) {
- return this;
- }
- ref = extend({}, ref);
- this._center = this.getCenter();
- this.options['spatialReference'] = ref;
- this._spatialReference = new SpatialReference(ref);
- if (this.options['spatialReference'] && isFunction(this.options['spatialReference']['projection'])) {
- var projection = this._spatialReference.getProjection();
- this.options['spatialReference']['projection'] = projection['code'];
- }
- this._resetMapStatus();
- this._fireEvent('spatialreferencechange', {
- 'old': oldRef,
- 'new': extend({}, this.options['spatialReference'])
- });
- return this;
- };
- _proto.onConfig = function onConfig(conf) {
- var ref = conf['spatialReference'] || conf['view'];
- if (!isNil(ref)) {
- this.setSpatialReference(ref);
- }
- return this;
- };
- _proto.getProjection = function getProjection() {
- if (!this._spatialReference) {
- return null;
- }
- return this._spatialReference.getProjection();
- };
- _proto.getFullExtent = function getFullExtent() {
- if (!this._spatialReference) {
- return null;
- }
- return this._spatialReference.getFullExtent();
- };
- _proto.setCursor = function setCursor(cursor) {
- delete this._cursor;
- this._trySetCursor(cursor);
- this._cursor = cursor;
- return this;
- };
- _proto.resetCursor = function resetCursor() {
- return this.setCursor(null);
- };
- _proto.getCenter = function getCenter() {
- if (!this._loaded || !this._prjCenter) {
- return this._center;
- }
- var projection = this.getProjection();
- return projection.unproject(this._prjCenter);
- };
- _proto.setCenter = function setCenter(center) {
- if (!center) {
- return this;
- }
- center = new Coordinate(center);
- if (!this._verifyExtent(center)) {
- return this;
- }
- if (!this._loaded) {
- this._center = center;
- return this;
- }
- this.onMoveStart();
- var projection = this.getProjection();
- var _pcenter = projection.project(center);
- this._setPrjCenter(_pcenter);
- this.onMoveEnd(this._parseEventFromCoord(this.getCenter()));
- return this;
- };
- _proto.getSize = function getSize() {
- if (isNil(this.width) || isNil(this.height)) {
- return this._getContainerDomSize();
- }
- return new Size(this.width, this.height);
- };
- _proto.getContainerExtent = function getContainerExtent() {
- var visualHeight = this.height;
- var pitch = this.getPitch(),
- maxVisualPitch = this.options['maxVisualPitch'];
- if (maxVisualPitch && pitch > maxVisualPitch) {
- visualHeight = this._getVisualHeight(maxVisualPitch);
- }
- return new PointExtent(0, this.height - visualHeight, this.width, this.height);
- };
- _proto._getVisualHeight = function _getVisualHeight(maxVisualPitch) {
- var pitch = this.getPitch();
- var visualDistance = this.height / 2 * Math.tan(maxVisualPitch * Math.PI / 180);
- return this.height / 2 + visualDistance * Math.tan((90 - pitch) * Math.PI / 180);
- };
- _proto.getExtent = function getExtent() {
- return this._pointToExtent(this._get2DExtent());
- };
- _proto.getProjExtent = function getProjExtent() {
- var extent2D = this._get2DExtent();
- return new Extent(this._pointToPrj(extent2D.getMin()), this._pointToPrj(extent2D.getMax()));
- };
- _proto.getPrjExtent = function getPrjExtent() {
- return this.getProjExtent();
- };
- _proto.getMaxExtent = function getMaxExtent() {
- if (!this.options['maxExtent']) {
- return null;
- }
- return new Extent(this.options['maxExtent'], this.getProjection());
- };
- _proto.setMaxExtent = function setMaxExtent(extent) {
- if (extent) {
- var maxExt = new Extent(extent, this.getProjection());
- this.options['maxExtent'] = maxExt;
- var center = this.getCenter();
- if (!this._verifyExtent(center)) {
- this.panTo(maxExt.getCenter());
- }
- } else {
- delete this.options['maxExtent'];
- }
- return this;
- };
- _proto.getZoom = function getZoom() {
- return this._zoomLevel;
- };
- _proto.getZoomForScale = function getZoomForScale(scale, fromZoom, isFraction) {
- var zoom = this.getZoom();
- if (isNil(fromZoom)) {
- fromZoom = zoom;
- }
- if (scale === 1 && fromZoom === zoom) {
- return zoom;
- }
- var res = this._getResolution(fromZoom),
- targetRes = res / scale;
- var scaleZoom = this.getZoomFromRes(targetRes);
- if (isFraction) {
- return scaleZoom;
- } else {
- var delta = 1E-6;
- return this.getSpatialReference().getZoomDirection() < 0 ? Math.ceil(scaleZoom - delta) : Math.floor(scaleZoom + delta);
- }
- };
- _proto.getZoomFromRes = function getZoomFromRes(res) {
- var resolutions = this._getResolutions(),
- minRes = this._getResolution(this.getMinZoom()),
- maxRes = this._getResolution(this.getMaxZoom());
- if (minRes <= maxRes) {
- if (res <= minRes) {
- return this.getMinZoom();
- } else if (res >= maxRes) {
- return this.getMaxZoom();
- }
- } else if (res >= minRes) {
- return this.getMinZoom();
- } else if (res <= maxRes) {
- return this.getMaxZoom();
- }
- var l = resolutions.length;
- for (var i = 0; i < l - 1; i++) {
- if (!resolutions[i]) {
- continue;
- }
- var gap = resolutions[i + 1] - resolutions[i];
- var test = res - resolutions[i];
- if (sign(gap) === sign(test) && Math.abs(gap) >= Math.abs(test)) {
- return i + test / gap;
- }
- }
- return l - 1;
- };
- _proto.setZoom = function setZoom(zoom, options) {
- if (options === void 0) {
- options = {
- 'animation': true
- };
- }
- if (isNaN(zoom) || isNil(zoom)) {
- return this;
- }
- if (this._loaded && this.options['zoomAnimation'] && options['animation']) {
- this._zoomAnimation(zoom);
- } else {
- this._zoom(zoom);
- }
- return this;
- };
- _proto.getMaxZoom = function getMaxZoom() {
- if (!isNil(this.options['maxZoom'])) {
- return this.options['maxZoom'];
- }
- return this.getMaxNativeZoom();
- };
- _proto.setMaxZoom = function setMaxZoom(maxZoom) {
- var viewMaxZoom = this.getMaxNativeZoom();
- if (maxZoom > viewMaxZoom) {
- maxZoom = viewMaxZoom;
- }
- if (maxZoom !== null && maxZoom < this._zoomLevel) {
- this.setZoom(maxZoom);
- }
- this.options['maxZoom'] = maxZoom;
- return this;
- };
- _proto.getMinZoom = function getMinZoom() {
- if (!isNil(this.options['minZoom'])) {
- return this.options['minZoom'];
- }
- return this._spatialReference.getMinZoom();
- };
- _proto.setMinZoom = function setMinZoom(minZoom) {
- if (minZoom !== null) {
- var viewMinZoom = this._spatialReference.getMinZoom();
- if (minZoom < viewMinZoom) {
- minZoom = viewMinZoom;
- }
- if (minZoom > this._zoomLevel) {
- this.setZoom(minZoom);
- }
- }
- this.options['minZoom'] = minZoom;
- return this;
- };
- _proto.getMaxNativeZoom = function getMaxNativeZoom() {
- var ref = this.getSpatialReference();
- if (!ref) {
- return null;
- }
- return ref.getMaxZoom();
- };
- _proto.getGLZoom = function getGLZoom() {
- return this.getMaxNativeZoom() / 2;
- };
- _proto.getGLScale = function getGLScale(zoom) {
- if (isNil(zoom)) {
- zoom = this.getZoom();
- }
- return this.getScale(zoom) / this.getScale(this.getGLZoom());
- };
- _proto.zoomIn = function zoomIn() {
- return this.setZoom(this.getZoom() + 1);
- };
- _proto.zoomOut = function zoomOut() {
- return this.setZoom(this.getZoom() - 1);
- };
- _proto.isZooming = function isZooming() {
- return !!this._zooming;
- };
- _proto.isInteracting = function isInteracting() {
- return this.isZooming() || this.isMoving() || this.isRotating();
- };
- _proto.setCenterAndZoom = function setCenterAndZoom(center, zoom) {
- if (!isNil(zoom) && this._zoomLevel !== zoom) {
- this.setCenter(center);
- this.setZoom(zoom, {
- animation: false
- });
- } else {
- this.setCenter(center);
- }
- return this;
- };
- _proto.getFitZoom = function getFitZoom(extent) {
- var _this2 = this;
- if (!extent || !(extent instanceof Extent)) {
- return this._zoomLevel;
- }
- if (extent['xmin'] === extent['xmax'] && extent['ymin'] === extent['ymax']) {
- return this.getMaxZoom();
- }
- var size = this.getSize();
- var containerExtent = extent.convertTo(function (p) {
- return _this2.coordToContainerPoint(p);
- });
- var w = containerExtent.getWidth(),
- h = containerExtent.getHeight();
- var scaleX = size['width'] / w,
- scaleY = size['height'] / h;
- var scale = this.getSpatialReference().getZoomDirection() < 0 ? Math.max(scaleX, scaleY) : Math.min(scaleX, scaleY);
- var zoom = this.getZoomForScale(scale);
- return zoom;
- };
- _proto.getView = function getView() {
- return {
- 'center': this.getCenter().toArray(),
- 'zoom': this.getZoom(),
- 'pitch': this.getPitch(),
- 'bearing': this.getBearing()
- };
- };
- _proto.setView = function setView(view) {
- if (!view) {
- return this;
- }
- if (view['center']) {
- this.setCenter(view['center']);
- }
- if (view['zoom']) {
- this.setZoom(view['zoom'], {
- 'animation': false
- });
- }
- if (view['pitch']) {
- this.setPitch(view['pitch']);
- }
- if (view['bearing']) {
- this.setBearing(view['bearing']);
- }
- return this;
- };
- _proto.getResolution = function getResolution(zoom) {
- return this._getResolution(zoom);
- };
- _proto.getScale = function getScale(zoom) {
- var z = isNil(zoom) ? this.getZoom() : zoom;
- var max = this._getResolution(this.getMaxNativeZoom()),
- res = this._getResolution(z);
- return res / max;
- };
- _proto.fitExtent = function fitExtent(extent, zoomOffset, options, step) {
- if (options === void 0) {
- options = {};
- }
- if (!extent) {
- return this;
- }
- extent = new Extent(extent, this.getProjection());
- var zoom = this.getFitZoom(extent) + (zoomOffset || 0);
- var center = extent.getCenter();
- if (typeof options['animation'] === 'undefined' || options['animation']) return this.animateTo({
- center: center,
- zoom: zoom
- }, {
- 'duration': options['duration'] || this.options['zoomAnimationDuration'],
- 'easing': options['easing'] || 'out'
- }, step); else return this.setCenterAndZoom(center, zoom);
- };
- _proto.getBaseLayer = function getBaseLayer() {
- return this._baseLayer;
- };
- _proto.setBaseLayer = function setBaseLayer(baseLayer) {
- var isChange = false;
- if (this._baseLayer) {
- isChange = true;
- this._fireEvent('baselayerchangestart');
- this._baseLayer.remove();
- }
- if (!baseLayer) {
- delete this._baseLayer;
- this._fireEvent('baselayerchangeend');
- this._fireEvent('setbaselayer');
- return this;
- }
- this._baseLayer = baseLayer;
- baseLayer._bindMap(this, -1);
- function onbaseLayerload() {
- this._fireEvent('baselayerload');
- if (isChange) {
- isChange = false;
- this._fireEvent('baselayerchangeend');
- }
- }
- this._baseLayer.on('layerload', onbaseLayerload, this);
- if (this._loaded) {
- this._baseLayer.load();
- }
- this._fireEvent('setbaselayer');
- return this;
- };
- _proto.removeBaseLayer = function removeBaseLayer() {
- if (this._baseLayer) {
- this._baseLayer.remove();
- delete this._baseLayer;
- this._fireEvent('baselayerremove');
- }
- return this;
- };
- _proto.getLayers = function getLayers(filter) {
- return this._getLayers(function (layer) {
- if (layer === this._baseLayer || layer.getId().indexOf(INTERNAL_LAYER_PREFIX) >= 0) {
- return false;
- }
- if (filter) {
- return filter(layer);
- }
- return true;
- });
- };
- _proto.getLayer = function getLayer(id) {
- if (!id) {
- return null;
- }
- var layer = this._layerCache ? this._layerCache[id] : null;
- if (layer) {
- return layer;
- }
- var baseLayer = this.getBaseLayer();
- if (baseLayer && baseLayer.getId() === id) {
- return baseLayer;
- }
- return null;
- };
- _proto.addLayer = function addLayer(layers) {
- if (!layers) {
- return this;
- }
- if (!Array.isArray(layers)) {
- layers = Array.prototype.slice.call(arguments, 0);
- return this.addLayer(layers);
- }
- if (!this._layerCache) {
- this._layerCache = {};
- }
- var mapLayers = this._layers;
- for (var i = 0, len = layers.length; i < len; i++) {
- var layer = layers[i];
- var id = layer.getId();
- if (isNil(id)) {
- throw new Error('Invalid id for the layer: ' + id);
- }
- if (layer.getMap() === this) {
- continue;
- }
- if (this._layerCache[id]) {
- throw new Error('Duplicate layer id in the map: ' + id);
- }
- this._layerCache[id] = layer;
- layer._bindMap(this);
- mapLayers.push(layer);
- if (this._loaded) {
- layer.load();
- }
- }
- this._sortLayersByZIndex();
- this._fireEvent('addlayer', {
- 'layers': layers
- });
- return this;
- };
- _proto.removeLayer = function removeLayer(layers) {
- if (!layers) {
- return this;
- }
- if (!Array.isArray(layers)) {
- return this.removeLayer([layers]);
- }
- var removed = [];
- for (var i = 0, len = layers.length; i < len; i++) {
- var layer = layers[i];
- if (!(layer instanceof Layer)) {
- layer = this.getLayer(layer);
- }
- if (!layer) {
- continue;
- }
- var map = layer.getMap();
- if (!map || map !== this) {
- continue;
- }
- removed.push(layer);
- this._removeLayer(layer, this._layers);
- if (this._loaded) {
- layer._doRemove();
- }
- var id = layer.getId();
- if (this._layerCache) {
- delete this._layerCache[id];
- }
- }
- if (removed.length > 0) {
- this.once('frameend', function () {
- removed.forEach(function (layer) {
- layer.fire('remove');
- });
- });
- }
- this._fireEvent('removelayer', {
- 'layers': layers
- });
- return this;
- };
- _proto.sortLayers = function sortLayers(layers) {
- if (!layers || !Array.isArray(layers)) {
- return this;
- }
- var layersToOrder = [];
- var minZ = Number.MAX_VALUE;
- for (var i = 0, l = layers.length; i < l; i++) {
- var layer = layers[i];
- if (isString(layers[i])) {
- layer = this.getLayer(layer);
- }
- if (!(layer instanceof Layer) || !layer.getMap() || layer.getMap() !== this) {
- throw new Error('It must be a layer added to this map to order.');
- }
- if (layer.getZIndex() < minZ) {
- minZ = layer.getZIndex();
- }
- layersToOrder.push(layer);
- }
- for (var _i = 0, _l = layersToOrder.length; _i < _l; _i++) {
- layersToOrder[_i].setZIndex(minZ + _i);
- }
- return this;
- };
- _proto.toDataURL = function toDataURL(options) {
- if (!options) {
- options = {};
- }
- var mimeType = options['mimeType'];
- if (!mimeType) {
- mimeType = 'image/png';
- }
- var save = options['save'];
- var renderer = this._getRenderer();
- if (renderer && renderer.toDataURL) {
- var file = options['fileName'];
- if (!file) {
- file = 'export';
- }
- var dataURL = renderer.toDataURL(mimeType);
- if (save && dataURL) {
- var imgURL;
- if (typeof Blob !== 'undefined' && typeof atob !== 'undefined') {
- var blob = b64toBlob(dataURL.replace(/^data:image\/(png|jpeg|jpg);base64,/, ''), mimeType);
- imgURL = URL.createObjectURL(blob);
- } else {
- imgURL = dataURL;
- }
- var dlLink = document.createElement('a');
- dlLink.download = file;
- dlLink.href = imgURL;
- document.body.appendChild(dlLink);
- dlLink.click();
- document.body.removeChild(dlLink);
- }
- return dataURL;
- }
- return null;
- };
- _proto.coordinateToPoint = function coordinateToPoint(coordinate, zoom) {
- var prjCoord = this.getProjection().project(coordinate);
- return this._prjToPoint(prjCoord, zoom);
- };
- _proto.coordToPoint = function coordToPoint(coordinate, zoom) {
- return this.coordinateToPoint(coordinate, zoom);
- };
- _proto.pointToCoordinate = function pointToCoordinate(point, zoom) {
- var prjCoord = this._pointToPrj(point, zoom);
- return this.getProjection().unproject(prjCoord);
- };
- _proto.pointToCoord = function pointToCoord(point, zoom) {
- return this.pointToCoordinate(point, zoom);
- };
- _proto.coordinateToViewPoint = function coordinateToViewPoint(coordinate) {
- return this._prjToViewPoint(this.getProjection().project(coordinate));
- };
- _proto.coordToViewPoint = function coordToViewPoint(coordinate) {
- return this.coordinateToViewPoint(coordinate);
- };
- _proto.viewPointToCoordinate = function viewPointToCoordinate(viewPoint) {
- return this.getProjection().unproject(this._viewPointToPrj(viewPoint));
- };
- _proto.viewPointToCoord = function viewPointToCoord(viewPoint) {
- return this.viewPointToCoordinate(viewPoint);
- };
- _proto.coordinateToContainerPoint = function coordinateToContainerPoint(coordinate, zoom) {
- var pCoordinate = this.getProjection().project(coordinate);
- return this._prjToContainerPoint(pCoordinate, zoom);
- };
- _proto.coordToContainerPoint = function coordToContainerPoint(coordinate, zoom) {
- return this.coordinateToContainerPoint(coordinate, zoom);
- };
- _proto.containerPointToCoordinate = function containerPointToCoordinate(containerPoint) {
- var pCoordinate = this._containerPointToPrj(containerPoint);
- return this.getProjection().unproject(pCoordinate);
- };
- _proto.containerPointToCoord = function containerPointToCoord(containerPoint) {
- return this.containerPointToCoordinate(containerPoint);
- };
- _proto.containerPointToViewPoint = function containerPointToViewPoint(containerPoint) {
- return containerPoint.sub(this.getViewPoint());
- };
- _proto.viewPointToContainerPoint = function viewPointToContainerPoint(viewPoint) {
- return viewPoint.add(this.getViewPoint());
- };
- _proto.containerToExtent = function containerToExtent(containerExtent) {
- var extent2D = new PointExtent(this._containerPointToPoint(containerExtent.getMin()), this._containerPointToPoint(containerExtent.getMax()));
- return this._pointToExtent(extent2D);
- };
- _proto.checkSize = function checkSize() {
- var justStart = now() - this._initTime < 1500 && this.width === 0 || this.height === 0;
- var watched = this._getContainerDomSize(),
- oldHeight = this.height,
- oldWidth = this.width;
- if (watched['width'] === oldWidth && watched['height'] === oldHeight) {
- return this;
- }
- var center = this.getCenter();
- this._updateMapSize(watched);
- var resizeOffset = new Point((oldWidth - watched.width) / 2, (oldHeight - watched.height) / 2);
- this._offsetCenterByPixel(resizeOffset);
- this._mapViewCoord = this._getPrjCenter();
- var hided = watched['width'] === 0 || watched['height'] === 0 || oldWidth === 0 || oldHeight === 0;
- if (justStart || hided) {
- this._noEvent = true;
- this.setCenter(center);
- delete this._noEvent;
- }
- this._fireEvent('resize');
- return this;
- };
- _proto.distanceToPixel = function distanceToPixel(xDist, yDist, zoom) {
- var projection = this.getProjection();
- if (!projection) {
- return null;
- }
- var scale = this.getScale() / this.getScale(zoom);
- var center = this.getCenter(),
- target = projection.locate(center, xDist, yDist);
- var p0 = this.coordToContainerPoint(center),
- p1 = this.coordToContainerPoint(target);
- p1._sub(p0)._multi(scale)._abs();
- return new Size(p1.x, p1.y);
- };
- _proto.distanceToPoint = function distanceToPoint(xDist, yDist, zoom) {
- var projection = this.getProjection();
- if (!projection) {
- return null;
- }
- var center = this.getCenter(),
- target = projection.locate(center, xDist, yDist);
- var p0 = this.coordToPoint(center, zoom),
- p1 = this.coordToPoint(target, zoom);
- p1._sub(p0)._abs();
- return p1;
- };
- _proto.pixelToDistance = function pixelToDistance(width, height) {
- var projection = this.getProjection();
- if (!projection) {
- return null;
- }
- var fullExt = this.getFullExtent();
- var d = fullExt['top'] > fullExt['bottom'] ? -1 : 1;
- var target = new Point(this.width / 2 + width, this.height / 2 + d * height);
- var coord = this.containerPointToCoord(target);
- return projection.measureLength(this.getCenter(), coord);
- };
- _proto.pointToDistance = function pointToDistance(dx, dy, zoom) {
- var projection = this.getProjection();
- if (!projection) {
- return null;
- }
- var c = this._prjToPoint(this._getPrjCenter(), zoom);
- c._add(dx, dy);
- var target = this.pointToCoord(c, zoom);
- return projection.measureLength(this.getCenter(), target);
- };
- _proto.locate = function locate(coordinate, dx, dy) {
- return this.getProjection()._locate(new Coordinate(coordinate), dx, dy);
- };
- _proto.locateByPoint = function locateByPoint(coordinate, px, py) {
- var point = this.coordToContainerPoint(coordinate);
- return this.containerPointToCoord(point._add(px, py));
- };
- _proto.getMainPanel = function getMainPanel() {
- return this._getRenderer().getMainPanel();
- };
- _proto.getPanels = function getPanels() {
- return this._panels;
- };
- _proto.remove = function remove() {
- if (this.isRemoved()) {
- return this;
- }
- this._fireEvent('removestart');
- this._removeDomEvents();
- this._clearHandlers();
- this.removeBaseLayer();
- var layers = this.getLayers();
- for (var i = 0; i < layers.length; i++) {
- layers[i].remove();
- }
- if (this._getRenderer()) {
- this._getRenderer().remove();
- }
- if (this._containerDOM.innerHTML) {
- this._containerDOM.innerHTML = '';
- }
- delete this._panels;
- delete this._containerDOM;
- delete this.renderer;
- this._fireEvent('removeend');
- this._clearAllListeners();
- return this;
- };
- _proto.isRemoved = function isRemoved() {
- return !this._containerDOM;
- };
- _proto.isMoving = function isMoving() {
- return !!this._moving;
- };
- _proto.onMoveStart = function onMoveStart(param) {
- this._originCenter = this.getCenter();
- this._moving = true;
- this._trySetCursor('move');
- this._fireEvent('movestart', this._parseEvent(param ? param['domEvent'] : null, 'movestart'));
- };
- _proto.onMoving = function onMoving(param) {
- this._fireEvent('moving', this._parseEvent(param ? param['domEvent'] : null, 'moving'));
- };
- _proto.onMoveEnd = function onMoveEnd(param) {
- this._moving = false;
- this._trySetCursor('default');
- this._fireEvent('moveend', param && param['domEvent'] ? this._parseEvent(param['domEvent'], 'moveend') : param);
- if (!this._verifyExtent(this.getCenter())) {
- var moveTo = this._originCenter;
- if (!this._verifyExtent(moveTo)) {
- moveTo = this.getMaxExtent().getCenter();
- }
- this.panTo(moveTo);
- }
- };
- _proto.onDragRotateStart = function onDragRotateStart(param) {
- this._dragRotating = true;
- this._fireEvent('dragrotatestart', this._parseEvent(param ? param['domEvent'] : null, 'dragrotatestart'));
- };
- _proto.onDragRotating = function onDragRotating(param) {
- this._fireEvent('dragrotating', this._parseEvent(param ? param['domEvent'] : null, 'dragrotating'));
- };
- _proto.onDragRotateEnd = function onDragRotateEnd(param) {
- this._dragRotating = false;
- this._fireEvent('dragrotateend', this._parseEvent(param ? param['domEvent'] : null, 'dragrotateend'));
- };
- _proto.isDragRotating = function isDragRotating() {
- return !!this._dragRotating;
- };
- _proto.getRenderer = function getRenderer() {
- return this._getRenderer();
- };
- _proto._initContainer = function _initContainer(container) {
- if (isString(container)) {
- this._containerDOM = document.getElementById(container);
- if (!this._containerDOM) {
- throw new Error('Invalid container when creating map: \'' + container + '\'');
- }
- } else {
- this._containerDOM = container;
- if (IS_NODE) {
- this.CanvasClass = this._containerDOM.constructor;
- }
- }
- if (this._containerDOM.childNodes && this._containerDOM.childNodes.length > 0) {
- if (this._containerDOM.childNodes[0].className === 'maptalks-wrapper') {
- throw new Error('Container is already loaded with another map instance, use map.remove() to clear it.');
- }
- }
- };
- _proto._trySetCursor = function _trySetCursor(cursor) {
- if (!this._cursor && !this._priorityCursor) {
- if (!cursor) {
- cursor = 'default';
- }
- this._setCursorToPanel(cursor);
- }
- return this;
- };
- _proto._setPriorityCursor = function _setPriorityCursor(cursor) {
- if (!cursor) {
- var hasCursor = false;
- if (this._priorityCursor) {
- hasCursor = true;
- }
- delete this._priorityCursor;
- if (hasCursor) {
- this.setCursor(this._cursor);
- }
- } else {
- this._priorityCursor = cursor;
- this._setCursorToPanel(cursor);
- }
- return this;
- };
- _proto._setCursorToPanel = function _setCursorToPanel(cursor) {
- var panel = this.getMainPanel();
- if (panel && panel.style && panel.style.cursor !== cursor) {
- panel.style.cursor = cursor;
- }
- };
- _proto._get2DExtent = function _get2DExtent(zoom) {
- var _this3 = this;
- var cExtent = this.getContainerExtent();
- return cExtent.convertTo(function (c) {
- return _this3._containerPointToPoint(c, zoom);
- });
- };
- _proto._pointToExtent = function _pointToExtent(extent2D) {
- var min2d = extent2D.getMin(),
- max2d = extent2D.getMax();
- var fullExtent = this.getFullExtent();
- var _ref = !fullExtent || fullExtent.left <= fullExtent.right ? [min2d.x, max2d.x] : [max2d.x, min2d.x],
- minx = _ref[0],
- maxx = _ref[1];
- var _ref2 = !fullExtent || fullExtent.top > fullExtent.bottom ? [max2d.y, min2d.y] : [min2d.y, max2d.y],
- miny = _ref2[0],
- maxy = _ref2[1];
- var min = new Coordinate(minx, miny),
- max = new Coordinate(maxx, maxy);
- return new Extent(this.pointToCoord(min), this.pointToCoord(max), this.getProjection());
- };
- _proto._removeLayer = function _removeLayer(layer, layerList) {
- if (!layer || !layerList) {
- return;
- }
- var index = layerList.indexOf(layer);
- if (index > -1) {
- layerList.splice(index, 1);
- }
- };
- _proto._sortLayersByZIndex = function _sortLayersByZIndex() {
- if (!this._layers) {
- return;
- }
- for (var i = 0, l = this._layers.length; i < l; i++) {
- this._layers[i]._order = i;
- }
- this._layers.sort(function (a, b) {
- var c = a.getZIndex() - b.getZIndex();
- if (c === 0) {
- return a._order - b._order;
- }
- return c;
- });
- };
- _proto._fireEvent = function _fireEvent(eventName, param) {
- if (this._noEvent) {
- return;
- }
- this.fire('_' + eventName, param);
- this.fire(eventName, param);
- };
- _proto._Load = function _Load() {
- this._resetMapStatus();
- if (this.options['pitch']) {
- this.setPitch(this.options['pitch']);
- delete this.options['pitch'];
- }
- if (this.options['bearing']) {
- this.setBearing(this.options['bearing']);
- delete this.options['bearing'];
- }
- this._loadAllLayers();
- this._getRenderer().onLoad();
- this._loaded = true;
- this._callOnLoadHooks();
- this._initTime = now();
- };
- _proto._initRenderer = function _initRenderer() {
- var renderer = this.options['renderer'];
- var clazz = Map.getRendererClass(renderer);
- this._renderer = new clazz(this);
- this._renderer.load();
- };
- _proto._getRenderer = function _getRenderer() {
- return this._renderer;
- };
- _proto._loadAllLayers = function _loadAllLayers() {
- function loadLayer(layer) {
- if (layer) {
- layer.load();
- }
- }
- if (this._baseLayer) {
- this._baseLayer.load();
- }
- this._eachLayer(loadLayer, this.getLayers());
- };
- _proto._getLayers = function _getLayers(filter) {
- var layers = this._baseLayer ? [this._baseLayer].concat(this._layers) : this._layers;
- var result = [];
- for (var i = 0; i < layers.length; i++) {
- if (!filter || filter.call(this, layers[i])) {
- result.push(layers[i]);
- }
- }
- return result;
- };
- _proto._eachLayer = function _eachLayer(fn) {
- if (arguments.length < 2) {
- return;
- }
- var layerLists = Array.prototype.slice.call(arguments, 1);
- if (layerLists && !Array.isArray(layerLists)) {
- layerLists = [layerLists];
- }
- var layers = [];
- for (var i = 0, len = layerLists.length; i < len; i++) {
- layers = layers.concat(layerLists[i]);
- }
- for (var j = 0, jlen = layers.length; j < jlen; j++) {
- fn.call(fn, layers[j]);
- }
- };
- _proto._onLayerEvent = function _onLayerEvent(param) {
- if (!param) {
- return;
- }
- if (param['type'] === 'idchange') {
- delete this._layerCache[param['old']];
- this._layerCache[param['new']] = param['target'];
- }
- };
- _proto._resetMapStatus = function _resetMapStatus() {
- var maxZoom = this.getMaxZoom(),
- minZoom = this.getMinZoom();
- var viewMaxZoom = this._spatialReference.getMaxZoom(),
- viewMinZoom = this._spatialReference.getMinZoom();
- if (isNil(maxZoom) || maxZoom === -1 || maxZoom > viewMaxZoom) {
- this.setMaxZoom(viewMaxZoom);
- }
- if (isNil(minZoom) || minZoom === -1 || minZoom < viewMinZoom) {
- this.setMinZoom(viewMinZoom);
- }
- maxZoom = this.getMaxZoom();
- minZoom = this.getMinZoom();
- if (maxZoom < minZoom) {
- this.setMaxZoom(minZoom);
- }
- if (isNil(this._zoomLevel) || this._zoomLevel > maxZoom) {
- this._zoomLevel = maxZoom;
- }
- if (this._zoomLevel < minZoom) {
- this._zoomLevel = minZoom;
- }
- delete this._prjCenter;
- var projection = this.getProjection();
- this._prjCenter = projection.project(this._center);
- // this._calcMatrices();
- // var renderer = this._getRenderer();
- // if (renderer) {
- // renderer.resetContainer();
- // }
- };
- _proto._getContainerDomSize = function _getContainerDomSize() {
- if (!this._containerDOM) {
- return null;
- }
- var containerDOM = this._containerDOM;
- var width, height;
- if (!isNil(containerDOM.width) && !isNil(containerDOM.height)) {
- width = containerDOM.width;
- height = containerDOM.height;
- if (Browser$1.retina && containerDOM['layer']) {
- width /= 2;
- height /= 2;
- }
- } else if (!isNil(containerDOM.clientWidth) && !isNil(containerDOM.clientHeight)) {
- width = parseInt(containerDOM.clientWidth, 0);
- height = parseInt(containerDOM.clientHeight, 0);
- } else {
- throw new Error('can not get size of container');
- }
- return new Size(width, height);
- };
- _proto._updateMapSize = function _updateMapSize(mSize) {
- this.width = mSize['width'];
- this.height = mSize['height'];
- this._getRenderer().updateMapSize(mSize);
- this._calcMatrices();
- return this;
- };
- _proto._getPrjCenter = function _getPrjCenter() {
- return this._prjCenter;
- };
- _proto._setPrjCenter = function _setPrjCenter(pcenter) {
- this._prjCenter = pcenter;
- if (this.isInteracting() && !this.isMoving()) {
- this._mapViewCoord = pcenter;
- }
- this._calcMatrices();
- };
- _proto._setPrjCoordAtContainerPoint = function _setPrjCoordAtContainerPoint(coordinate, point) {
- if (point.x === this.width / 2 && point.y === this.height / 2) {
- return this;
- }
- var t = this._containerPointToPoint(point)._sub(this._prjToPoint(this._getPrjCenter()));
- var pcenter = this._pointToPrj(this._prjToPoint(coordinate).sub(t));
- this._setPrjCenter(pcenter);
- return this;
- };
- _proto._verifyExtent = function _verifyExtent(center) {
- if (!center) {
- return false;
- }
- var maxExt = this.getMaxExtent();
- if (!maxExt) {
- return true;
- }
- return maxExt.contains(center);
- };
- _proto._offsetCenterByPixel = function _offsetCenterByPixel(pixel) {
- var pos = new Point(this.width / 2 - pixel.x, this.height / 2 - pixel.y);
- var pCenter = this._containerPointToPrj(pos);
- this._setPrjCenter(pCenter);
- return pCenter;
- };
- _proto.offsetPlatform = function offsetPlatform(offset) {
- if (!offset) {
- return this._mapViewPoint;
- } else {
- this._getRenderer().offsetPlatform(offset);
- this._mapViewCoord = this._getPrjCenter();
- this._mapViewPoint = this._mapViewPoint.add(offset);
- return this;
- }
- };
- _proto.getViewPoint = function getViewPoint() {
- var offset = this._getViewPointFrameOffset();
- var panelOffset = this.offsetPlatform();
- if (offset) {
- panelOffset = panelOffset.add(offset);
- }
- return panelOffset;
- };
- _proto._getViewPointFrameOffset = function _getViewPointFrameOffset() {
- if (this.isZooming()) {
- return null;
- }
- var pcenter = this._getPrjCenter();
- if (this._mapViewCoord && !this._mapViewCoord.equals(pcenter)) {
- return this._prjToContainerPoint(this._mapViewCoord).sub(this._prjToContainerPoint(pcenter));
- }
- return null;
- };
- _proto._resetMapViewPoint = function _resetMapViewPoint() {
- this._mapViewPoint = new Point(0, 0);
- this._mapViewCoord = this._getPrjCenter();
- };
- _proto._getResolution = function _getResolution(zoom) {
- if (isNil(zoom)) {
- zoom = this.getZoom();
- }
- return this._spatialReference.getResolution(zoom);
- };
- _proto._getResolutions = function _getResolutions() {
- return this._spatialReference.getResolutions();
- };
- _proto._prjToPoint = function _prjToPoint(pCoord, zoom) {
- zoom = isNil(zoom) ? this.getZoom() : zoom;
- return this._spatialReference.getTransformation().transform(pCoord, this._getResolution(zoom));
- };
- _proto._pointToPrj = function _pointToPrj(point, zoom) {
- zoom = isNil(zoom) ? this.getZoom() : zoom;
- return this._spatialReference.getTransformation().untransform(point, this._getResolution(zoom));
- };
- _proto._pointToPoint = function _pointToPoint(point, zoom) {
- if (!isNil(zoom)) {
- return point.multi(this._getResolution(zoom) / this._getResolution());
- }
- return point.copy();
- };
- _proto._pointToPointAtZoom = function _pointToPointAtZoom(point, zoom) {
- if (!isNil(zoom)) {
- return point.multi(this._getResolution() / this._getResolution(zoom));
- }
- return point.copy();
- };
- _proto._containerPointToPrj = function _containerPointToPrj(containerPoint) {
- return this._pointToPrj(this._containerPointToPoint(containerPoint));
- };
- _proto._viewPointToPrj = function _viewPointToPrj(viewPoint) {
- return this._containerPointToPrj(this.viewPointToContainerPoint(viewPoint));
- };
- _proto._prjToContainerPoint = function _prjToContainerPoint(pCoordinate, zoom) {
- return this._pointToContainerPoint(this._prjToPoint(pCoordinate, zoom), zoom);
- };
- _proto._prjToViewPoint = function _prjToViewPoint(pCoordinate) {
- var containerPoint = this._prjToContainerPoint(pCoordinate);
- return this._containerPointToViewPoint(containerPoint);
- };
- _proto._containerPointToViewPoint = function _containerPointToViewPoint(containerPoint) {
- if (!containerPoint) {
- return null;
- }
- return containerPoint._sub(this.getViewPoint());
- };
- _proto._viewPointToPoint = function _viewPointToPoint(viewPoint, zoom) {
- return this._containerPointToPoint(this.viewPointToContainerPoint(viewPoint), zoom);
- };
- _proto._pointToViewPoint = function _pointToViewPoint(point, zoom) {
- return this._prjToViewPoint(this._pointToPrj(point, zoom));
- };
- _proto._callOnLoadHooks = function _callOnLoadHooks() {
- var proto = Map.prototype;
- if (!proto._onLoadHooks) {
- return;
- }
- for (var i = 0, l = proto._onLoadHooks.length; i < l; i++) {
- proto._onLoadHooks[i].call(this);
- }
- };
- return Map;
- }(Handlerable(Eventable(Renderable(Class))));
- Map$1.mergeOptions(options$1);
- var RADIAN = Math.PI / 180;
- var DEFAULT_FOV = 0.6435011087932844;
- Map$1.include({
- getFov: function getFov() {
- if (!this._fov) {
- this._fov = DEFAULT_FOV;
- }
- return this._fov / RADIAN;
- },
- setFov: function setFov(fov) {
- if (this.isZooming()) {
- return this;
- }
- fov = Math.max(0.01, Math.min(60, fov));
- if (this._fov === fov) return this;
- var from = this.getFov();
- this._fov = fov * RADIAN;
- this._calcMatrices();
- this._renderLayers();
- this._fireEvent('fovchange', {
- 'from': from,
- 'to': this.getFov()
- });
- return this;
- },
- getBearing: function getBearing() {
- if (!this._angle) {
- return 0;
- }
- return -this._angle / RADIAN;
- },
- setBearing: function setBearing(bearing) {
- if (Browser$1.ie9) {
- throw new Error('map can\'t rotate in IE9.');
- }
- var b = -wrap(bearing, -180, 180) * RADIAN;
- if (this._angle === b) return this;
- var from = this.getBearing();
- this._fireEvent('rotatestart', {
- 'from': from,
- 'to': b
- });
- this._angle = b;
- this._calcMatrices();
- this._renderLayers();
- this._fireEvent('rotate', {
- 'from': from,
- 'to': b
- });
- this._fireEvent('rotateend', {
- 'from': from,
- 'to': b
- });
- return this;
- },
- getPitch: function getPitch() {
- if (!this._pitch) {
- return 0;
- }
- return this._pitch / Math.PI * 180;
- },
- setPitch: function setPitch(pitch) {
- if (Browser$1.ie9) {
- throw new Error('map can\'t tilt in IE9.');
- }
- var p = clamp(pitch, 0, this.options['maxPitch']) * RADIAN;
- if (this._pitch === p) return this;
- var from = this.getPitch();
- this._fireEvent('pitchstart', {
- 'from': from,
- 'to': p
- });
- this._pitch = p;
- this._calcMatrices();
- this._renderLayers();
- this._fireEvent('pitch', {
- 'from': from,
- 'to': p
- });
- this._fireEvent('pitchend', {
- 'from': from,
- 'to': p
- });
- return this;
- },
- isTransforming: function isTransforming() {
- return !!(this._pitch || this._angle);
- },
- getFrustumAltitude: function getFrustumAltitude() {
- var pitch = 90 - this.getPitch();
- var fov = this.getFov() / 2;
- var cameraAlt = this.cameraPosition ? this.cameraPosition[2] : 0;
- if (fov <= pitch) {
- return cameraAlt;
- }
- fov = Math.PI * fov / 180;
- var d1 = new Point(this.cameraPosition).distanceTo(new Point(this.cameraLookAt)),
- d2 = cameraAlt * Math.tan(fov * 2);
- var d = Math.tan(fov) * (d1 + d2);
- return cameraAlt + d;
- },
- _pointToContainerPoint: function () {
- var a = [0, 0, 0];
- return function (point, zoom, altitude) {
- if (altitude === void 0) {
- altitude = 0;
- }
- point = this._pointToPoint(point, zoom);
- if (this.isTransforming() || altitude) {
- altitude *= this.getResolution(zoom) / this.getResolution();
- var _scale = this._glScale;
- set$2(a, point.x * _scale, point.y * _scale, altitude * _scale);
- var t = this._projIfBehindCamera(a, this.cameraPosition, this.cameraForward);
- applyMatrix(t, t, this.projViewMatrix);
- var w2 = this.width / 2,
- h2 = this.height / 2;
- t[0] = t[0] * w2 + w2;
- t[1] = -(t[1] * h2) + h2;
- return new Point(t[0], t[1]);
- } else {
- var centerPoint = this._prjToPoint(this._getPrjCenter());
- return point._sub(centerPoint)._add(this.width / 2, this.height / 2);
- }
- };
- }(),
- _projIfBehindCamera: function () {
- var vectorFromCam = new Array(3);
- var proj = new Array(3);
- var sub = new Array(3);
- return function (position, cameraPos, camForward) {
- subtract(vectorFromCam, position, cameraPos);
- var camNormDot = dot(camForward, vectorFromCam);
- if (camNormDot <= 0) {
- scale$1(proj, camForward, camNormDot * 1.01);
- add(position, cameraPos, subtract(sub, vectorFromCam, proj));
- }
- return position;
- };
- }(),
- _containerPointToPoint: function () {
- var cp = [0, 0, 0],
- coord0 = [0, 0, 0, 1],
- coord1 = [0, 0, 0, 1];
- return function (p, zoom) {
- if (this.isTransforming()) {
- var w2 = this.width / 2 || 1,
- h2 = this.height / 2 || 1;
- set$2(cp, (p.x - w2) / w2, (h2 - p.y) / h2, 0);
- set$2(coord0, cp[0], cp[1], 0);
- set$2(coord1, cp[0], cp[1], 1);
- coord0[3] = coord1[3] = 1;
- applyMatrix(coord0, coord0, this.projViewMatrixInverse);
- applyMatrix(coord1, coord1, this.projViewMatrixInverse);
- var x0 = coord0[0];
- var x1 = coord1[0];
- var y0 = coord0[1];
- var y1 = coord1[1];
- var z0 = coord0[2];
- var z1 = coord1[2];
- var t = z0 === z1 ? 0 : (0 - z0) / (z1 - z0);
- var point = new Point(interpolate(x0, x1, t), interpolate(y0, y1, t))._multi(1 / this._glScale);
- return zoom === undefined || this.getZoom() === zoom ? point : this._pointToPointAtZoom(point, zoom);
- }
- var centerPoint = this._prjToPoint(this._getPrjCenter(), zoom),
- scale$$1 = zoom !== undefined ? this._getResolution() / this._getResolution(zoom) : 1;
- var x = scale$$1 * (p.x - this.width / 2),
- y = scale$$1 * (p.y - this.height / 2);
- return centerPoint._add(x, y);
- };
- }(),
- _calcMatrices: function () {
- var m0 = Browser$1.ie9 ? null : createMat4(),
- m1 = Browser$1.ie9 ? null : createMat4();
- return function () {
- if (Browser$1.ie9) {
- return;
- }
- var size = this.getSize();
- var w = size.width || 1,
- h = size.height || 1;
- this._glScale = this.getGLScale();
- var fov = this.getFov() * Math.PI / 180;
- var maxScale = this.getScale(this.getMinZoom()) / this.getScale(this.getMaxNativeZoom());
- var farZ = maxScale * h / 2 / this._getFovRatio() * 1.4;
- var projMatrix = this.projMatrix || createMat4();
- perspective(projMatrix, fov, w / h, 0.1, farZ);
- this.projMatrix = projMatrix;
- var worldMatrix = this._getCameraWorldMatrix();
- this.viewMatrix = invert(m0, worldMatrix);
- this.projViewMatrix = multiply(this.projViewMatrix || createMat4(), projMatrix, this.viewMatrix);
- this.projViewMatrixInverse = multiply(this.projViewMatrixInverse || createMat4(), worldMatrix, invert(m1, projMatrix));
- this.domCssMatrix = this._calcDomMatrix();
- };
- }(),
- _calcDomMatrix: function () {
- var m = Browser$1.ie9 ? null : createMat4(),
- minusY = [1, -1, 1],
- arr = [0, 0, 0];
- return function () {
- var cameraToCenterDistance = 0.5 / Math.tan(this._fov / 2) * this.height;
- scale(m, this.projMatrix, minusY);
- translate(m, m, set$2(arr, 0, 0, -cameraToCenterDistance));
- if (this._pitch) {
- rotateX(m, m, this._pitch);
- }
- if (this._angle) {
- rotateZ(m, m, this._angle);
- }
- var m1 = createMat4();
- scale(m1, m1, set$2(arr, this.width / 2, -this.height / 2, 1));
- return multiply(this.domCssMatrix || createMat4(), m1, m);
- };
- }(),
- _getCameraWorldMatrix: function () {
- var q = {},
- minusY = [1, -1, 1];
- return function () {
- var targetZ = this.getGLZoom();
- var size = this.getSize(),
- scale$$1 = this.getGLScale();
- var center2D = this._prjToPoint(this._prjCenter, targetZ);
- this.cameraLookAt = set$2(this.cameraLookAt || [0, 0, 0], center2D.x, center2D.y, 0);
- var pitch = this.getPitch() * RADIAN;
- var bearing = -this.getBearing() * RADIAN;
- var ratio = this._getFovRatio();
- var z = scale$$1 * (size.height || 1) / 2 / ratio;
- var cz = z * Math.cos(pitch);
- var dist = Math.sin(pitch) * z;
- var cx = center2D.x + dist * Math.sin(bearing);
- var cy = center2D.y + dist * Math.cos(bearing);
- this.cameraPosition = set$2(this.cameraPosition || [0, 0, 0], cx, cy, cz);
- var d = dist || 1;
- var up = this.cameraUp = set$2(this.cameraUp || [0, 0, 0], Math.sin(bearing) * d, Math.cos(bearing) * d, 0);
- var m = this.cameraWorldMatrix = this.cameraWorldMatrix || createMat4();
- lookAt(m, this.cameraPosition, this.cameraLookAt, up);
- var cameraForward = this.cameraForward || [0, 0, 0];
- subtract(cameraForward, this.cameraLookAt, this.cameraPosition);
- this.cameraForward = normalize(cameraForward, cameraForward);
- matrixToQuaternion(q, m);
- quaternionToMatrix(m, q);
- setPosition(m, this.cameraPosition);
- scale(m, m, minusY);
- return m;
- };
- }(),
- _getFovRatio: function _getFovRatio() {
- var fov = this.getFov();
- return Math.tan(fov / 2 * RADIAN);
- },
- _renderLayers: function _renderLayers() {
- if (this.isInteracting()) {
- return;
- }
- var layers = this._getLayers();
- layers.forEach(function (layer) {
- if (!layer) {
- return;
- }
- var renderer = layer._getRenderer();
- if (renderer && renderer.setToRedraw) {
- renderer.setToRedraw();
- }
- });
- }
- });
- function createMat4() {
- return identity(new Array(16));
- }
- function identity(out) {
- out[0] = 1;
- out[1] = 0;
- out[2] = 0;
- out[3] = 0;
- out[4] = 0;
- out[5] = 1;
- out[6] = 0;
- out[7] = 0;
- out[8] = 0;
- out[9] = 0;
- out[10] = 1;
- out[11] = 0;
- out[12] = 0;
- out[13] = 0;
- out[14] = 0;
- out[15] = 1;
- return out;
- }
- Map$1.include({
- _zoom: function _zoom(nextZoom, origin) {
- if (!this.options['zoomable'] || this.isZooming()) {
- return;
- }
- origin = this._checkZoomOrigin(origin);
- nextZoom = this._checkZoom(nextZoom);
- this.onZoomStart(nextZoom, origin);
- this._frameZoom = this.getZoom();
- this.onZoomEnd(nextZoom, origin);
- },
- _zoomAnimation: function _zoomAnimation(nextZoom, origin, startScale) {
- if (!this.options['zoomable'] || this.isZooming()) {
- return;
- }
- nextZoom = this._checkZoom(nextZoom);
- if (this.getZoom() === nextZoom) {
- return;
- }
- origin = this._checkZoomOrigin(origin);
- this._startZoomAnim(nextZoom, origin, startScale);
- },
- _checkZoomOrigin: function _checkZoomOrigin(origin) {
- if (!origin || this.options['zoomInCenter']) {
- origin = new Point(this.width / 2, this.height / 2);
- }
- return origin;
- },
- _startZoomAnim: function _startZoomAnim(nextZoom, origin, startScale) {
- if (isNil(startScale)) {
- startScale = 1;
- }
- var endScale = this._getResolution(this._startZoomVal) / this._getResolution(nextZoom);
- var duration = this.options['zoomAnimationDuration'] * Math.abs(endScale - startScale) / Math.abs(endScale - 1);
- this._frameZoom = this._startZoomVal;
- this.animateTo({
- 'zoom': nextZoom,
- 'around': origin
- }, {
- 'continueOnViewChanged': true,
- 'duration': duration
- });
- },
- onZoomStart: function onZoomStart(nextZoom, origin) {
- if (!this.options['zoomable'] || this.isZooming()) {
- return;
- }
- this._zooming = true;
- this._startZoomVal = this.getZoom();
- this._startZoomCoord = this._containerPointToPrj(origin);
- this._fireEvent('zoomstart', {
- 'from': this._startZoomVal,
- 'to': nextZoom
- });
- },
- onZooming: function onZooming(nextZoom, origin, startScale) {
- if (!this.options['zoomable']) {
- return;
- }
- var frameZoom = this._frameZoom;
- if (frameZoom === nextZoom) {
- return;
- }
- if (isNil(startScale)) {
- startScale = 1;
- }
- this._zoomTo(nextZoom, origin);
- var res = this.getResolution(nextZoom),
- fromRes = this.getResolution(this._startZoomVal),
- scale = fromRes / res / startScale,
- startPoint = this._prjToContainerPoint(this._startZoomCoord, this._startZoomVal);
- var offset = this.getViewPoint();
- if (!this.isRotating() && !startPoint.equals(origin) && scale !== 1) {
- var pitch = this.getPitch();
- var originOffset = startPoint._sub(origin)._multi(1 / (1 - scale));
- if (pitch) {
- originOffset.y /= Math.cos(pitch * Math.PI / 180);
- }
- origin = origin.add(originOffset);
- }
- var matrix = {
- 'view': [scale, 0, 0, scale, (origin.x - offset.x) * (1 - scale), (origin.y - offset.y) * (1 - scale)]
- };
- if (Browser$1.retina) {
- origin = origin.multi(2);
- }
- matrix['container'] = [scale, 0, 0, scale, origin.x * (1 - scale), origin.y * (1 - scale)];
- this._fireEvent('zooming', {
- 'from': this._startZoomVal,
- 'to': nextZoom,
- 'origin': origin,
- 'matrix': matrix
- });
- this._frameZoom = nextZoom;
- },
- onZoomEnd: function onZoomEnd(nextZoom, origin) {
- if (!this.options['zoomable']) {
- return;
- }
- var startZoomVal = this._startZoomVal;
- this._zoomTo(nextZoom, origin);
- this._zooming = false;
- // this._getRenderer().onZoomEnd();
- this._fireEvent('zoomend', {
- 'from': startZoomVal,
- 'to': nextZoom
- });
- if (!this._verifyExtent(this.getCenter())) {
- this.panTo(this.getMaxExtent().getCenter());
- }
- },
- _zoomTo: function _zoomTo(nextZoom, origin) {
- this._zoomLevel = nextZoom;
- this._calcMatrices();
- if (origin) {
- this._setPrjCoordAtContainerPoint(this._startZoomCoord, origin);
- }
- },
- _checkZoom: function _checkZoom(nextZoom) {
- var maxZoom = this.getMaxZoom(),
- minZoom = this.getMinZoom();
- if (nextZoom < minZoom) {
- nextZoom = minZoom;
- }
- if (nextZoom > maxZoom) {
- nextZoom = maxZoom;
- }
- return nextZoom;
- }
- });
- var Size = function () {
- function Size(width, height) {
- if (isNumber(width) && isNumber(height)) {
- this.width = width;
- this.height = height;
- } else if (isNumber(width['width'])) {
- this.width = width.width;
- this.height = width.height;
- } else if (Array.isArray(width)) {
- this.width = width[0];
- this.height = width[1];
- }
- }
- var _proto = Size.prototype;
- _proto.copy = function copy() {
- return new Size(this['width'], this['height']);
- };
- _proto.add = function add(x, y) {
- var w, h;
- if (x instanceof Size) {
- w = this.width + x.width;
- h = this.height + x.height;
- } else {
- w = this.width + x;
- h = this.height + y;
- }
- return new Size(w, h);
- };
- _proto.equals = function equals(size) {
- return this['width'] === size['width'] && this['height'] === size['height'];
- };
- _proto.multi = function multi(ratio) {
- return new Size(this['width'] * ratio, this['height'] * ratio);
- };
- _proto._multi = function _multi(ratio) {
- this['width'] *= ratio;
- this['height'] *= ratio;
- return this;
- };
- _proto._round = function _round() {
- this['width'] = Math.round(this['width']);
- this['height'] = Math.round(this['height']);
- return this;
- };
- _proto.toPoint = function toPoint() {
- return new Point(this['width'], this['height']);
- };
- _proto.toArray = function toArray() {
- return [this['width'], this['height']];
- };
- _proto.toJSON = function toJSON() {
- return {
- 'width': this['width'],
- 'height': this['height']
- };
- };
- return Size;
- }();
- function perspective(out, fovy, aspect, near, far) {
- var f = 1.0 / Math.tan(fovy / 2),
- nf = 1 / (near - far);
- out[0] = f / aspect;
- out[1] = 0;
- out[2] = 0;
- out[3] = 0;
- out[4] = 0;
- out[5] = f;
- out[6] = 0;
- out[7] = 0;
- out[8] = 0;
- out[9] = 0;
- out[10] = (far + near) * nf;
- out[11] = -1;
- out[12] = 0;
- out[13] = 0;
- out[14] = 2 * far * near * nf;
- out[15] = 0;
- return out;
- }
- function set$2(out, x, y, z) {
- out[0] = x;
- out[1] = y;
- out[2] = z;
- return out;
- }
- function lookAt(te, eye, target, up) {
- var x = [0, 0, 0];
- var y = [0, 0, 0];
- var z = [0, 0, 0];
- subtract(z, eye, target);
- if (length(z) === 0) {
- z[2] = 1;
- }
- normalize(z, z);
- cross(x, up, z);
- if (length(z) === 0) {
- if (Math.abs(up[2]) === 1) {
- z[0] += 0.0001;
- } else {
- z[2] += 0.0001;
- }
- normalize(z, z);
- cross(x, up, z);
- }
- normalize(x, x);
- cross(y, z, x);
- te[0] = x[0];
- te[4] = y[0];
- te[8] = z[0];
- te[1] = x[1];
- te[5] = y[1];
- te[9] = z[1];
- te[2] = x[2];
- te[6] = y[2];
- te[10] = z[2];
- return te;
- }
- function subtract(out, a, b) {
- out[0] = a[0] - b[0];
- out[1] = a[1] - b[1];
- out[2] = a[2] - b[2];
- return out;
- }
- function length(a) {
- var x = a[0],
- y = a[1],
- z = a[2];
- return Math.sqrt(x * x + y * y + z * z);
- }
- function normalize(out, a) {
- var x = a[0],
- y = a[1],
- z = a[2];
- var len = x * x + y * y + z * z;
- if (len > 0) {
- len = 1 / Math.sqrt(len);
- out[0] = a[0] * len;
- out[1] = a[1] * len;
- out[2] = a[2] * len;
- }
- return out;
- }
- function cross(out, a, b) {
- var ax = a[0],
- ay = a[1],
- az = a[2],
- bx = b[0],
- by = b[1],
- bz = b[2];
- out[0] = ay * bz - az * by;
- out[1] = az * bx - ax * bz;
- out[2] = ax * by - ay * bx;
- return out;
- }
- function matrixToQuaternion(out, te) {
- var m11 = te[0],
- m12 = te[4],
- m13 = te[8],
- m21 = te[1],
- m22 = te[5],
- m23 = te[9],
- m31 = te[2],
- m32 = te[6],
- m33 = te[10],
- trace = m11 + m22 + m33;
- var s;
- if (trace > 0) {
- s = 0.5 / Math.sqrt(trace + 1.0);
- out.w = 0.25 / s;
- out.x = (m32 - m23) * s;
- out.y = (m13 - m31) * s;
- out.z = (m21 - m12) * s;
- } else if (m11 > m22 && m11 > m33) {
- s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
- out.w = (m32 - m23) / s;
- out.x = 0.25 * s;
- out.y = (m12 + m21) / s;
- out.z = (m13 + m31) / s;
- } else if (m22 > m33) {
- s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
- out.w = (m13 - m31) / s;
- out.x = (m12 + m21) / s;
- out.y = 0.25 * s;
- out.z = (m23 + m32) / s;
- } else {
- s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
- out.w = (m21 - m12) / s;
- out.x = (m13 + m31) / s;
- out.y = (m23 + m32) / s;
- out.z = 0.25 * s;
- }
- return this;
- }
- function quaternionToMatrix(out, q) {
- var te = out;
- var x = q.x,
- y = q.y,
- z = q.z,
- w = q.w;
- var x2 = x + x,
- y2 = y + y,
- z2 = z + z;
- var xx = x * x2,
- xy = x * y2,
- xz = x * z2;
- var yy = y * y2,
- yz = y * z2,
- zz = z * z2;
- var wx = w * x2,
- wy = w * y2,
- wz = w * z2;
- te[0] = 1 - (yy + zz);
- te[4] = xy - wz;
- te[8] = xz + wy;
- te[1] = xy + wz;
- te[5] = 1 - (xx + zz);
- te[9] = yz - wx;
- te[2] = xz - wy;
- te[6] = yz + wx;
- te[10] = 1 - (xx + yy);
- te[3] = 0;
- te[7] = 0;
- te[11] = 0;
- te[12] = 0;
- te[13] = 0;
- te[14] = 0;
- te[15] = 1;
- return te;
- }
- function setPosition(out, v) {
- var te = out;
- te[12] = v[0];
- te[13] = v[1];
- te[14] = v[2];
- return out;
- }
- function scale(out, a, v) {
- var x = v[0],
- y = v[1],
- z = v[2];
- out[0] = a[0] * x;
- out[1] = a[1] * x;
- out[2] = a[2] * x;
- out[3] = a[3] * x;
- out[4] = a[4] * y;
- out[5] = a[5] * y;
- out[6] = a[6] * y;
- out[7] = a[7] * y;
- out[8] = a[8] * z;
- out[9] = a[9] * z;
- out[10] = a[10] * z;
- out[11] = a[11] * z;
- out[12] = a[12];
- out[13] = a[13];
- out[14] = a[14];
- out[15] = a[15];
- return out;
- }
- function invert(out, a) {
- var a00 = a[0],
- a01 = a[1],
- a02 = a[2],
- a03 = a[3],
- a10 = a[4],
- a11 = a[5],
- a12 = a[6],
- a13 = a[7],
- a20 = a[8],
- a21 = a[9],
- a22 = a[10],
- a23 = a[11],
- a30 = a[12],
- a31 = a[13],
- a32 = a[14],
- a33 = a[15],
- b00 = a00 * a11 - a01 * a10,
- b01 = a00 * a12 - a02 * a10,
- b02 = a00 * a13 - a03 * a10,
- b03 = a01 * a12 - a02 * a11,
- b04 = a01 * a13 - a03 * a11,
- b05 = a02 * a13 - a03 * a12,
- b06 = a20 * a31 - a21 * a30,
- b07 = a20 * a32 - a22 * a30,
- b08 = a20 * a33 - a23 * a30,
- b09 = a21 * a32 - a22 * a31,
- b10 = a21 * a33 - a23 * a31,
- b11 = a22 * a33 - a23 * a32,
- det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
- if (!det) {
- return null;
- }
- det = 1.0 / det;
- out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
- out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
- out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
- out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
- out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
- out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
- out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
- out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
- out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
- out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
- out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
- out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
- out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
- out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
- out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
- out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
- return out;
- }
- function multiply(out, a, b) {
- var a00 = a[0],
- a01 = a[1],
- a02 = a[2],
- a03 = a[3],
- a10 = a[4],
- a11 = a[5],
- a12 = a[6],
- a13 = a[7],
- a20 = a[8],
- a21 = a[9],
- a22 = a[10],
- a23 = a[11],
- a30 = a[12],
- a31 = a[13],
- a32 = a[14],
- a33 = a[15];
- var b0 = b[0],
- b1 = b[1],
- b2 = b[2],
- b3 = b[3];
- out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
- out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
- out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
- out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
- b0 = b[4];
- b1 = b[5];
- b2 = b[6];
- b3 = b[7];
- out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
- out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
- out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
- out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
- b0 = b[8];
- b1 = b[9];
- b2 = b[10];
- b3 = b[11];
- out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
- out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
- out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
- out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
- b0 = b[12];
- b1 = b[13];
- b2 = b[14];
- b3 = b[15];
- out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
- out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
- out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
- out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
- return out;
- }
- function translate(out, a, v) {
- var x = v[0],
- y = v[1],
- z = v[2],
- a00,
- a01,
- a02,
- a03,
- a10,
- a11,
- a12,
- a13,
- a20,
- a21,
- a22,
- a23;
- if (a === out) {
- out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
- out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
- out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
- out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
- } else {
- a00 = a[0];
- a01 = a[1];
- a02 = a[2];
- a03 = a[3];
- a10 = a[4];
- a11 = a[5];
- a12 = a[6];
- a13 = a[7];
- a20 = a[8];
- a21 = a[9];
- a22 = a[10];
- a23 = a[11];
- out[0] = a00;
- out[1] = a01;
- out[2] = a02;
- out[3] = a03;
- out[4] = a10;
- out[5] = a11;
- out[6] = a12;
- out[7] = a13;
- out[8] = a20;
- out[9] = a21;
- out[10] = a22;
- out[11] = a23;
- out[12] = a00 * x + a10 * y + a20 * z + a[12];
- out[13] = a01 * x + a11 * y + a21 * z + a[13];
- out[14] = a02 * x + a12 * y + a22 * z + a[14];
- out[15] = a03 * x + a13 * y + a23 * z + a[15];
- }
- return out;
- }
- Map$1.include({
- animateTo: function animateTo(view, options, step) {
- var _this = this;
- if (options === void 0) {
- options = {};
- }
- this._stopAnim(this._animPlayer);
- if (isFunction(options)) {
- step = options;
- options = {};
- }
- var projection = this.getProjection(),
- currView = this.getView(),
- props = {};
- var empty = true;
- for (var p in view) {
- if (hasOwn(view, p) && !isNil(currView[p])) {
- empty = false;
- if (p === 'center') {
- var from = new Coordinate(currView[p]).toFixed(7),
- to = new Coordinate(view[p]).toFixed(7);
- if (!from.equals(to)) {
- props['center'] = [from, to];
- }
- } else if (currView[p] !== view[p] && p !== 'around') {
- props[p] = [currView[p], view[p]];
- }
- }
- }
- if (empty) {
- return null;
- }
- var zoomOrigin = view['around'] || new Point(this.width / 2, this.height / 2);
- var preView = this.getView();
- var renderer = this._getRenderer(),
- framer = function framer(fn) {
- renderer.callInNextFrame(fn);
- };
- var player = this._animPlayer = Animation.animate(props, {
- 'easing': options['easing'] || 'out',
- 'duration': options['duration'] || this.options['zoomAnimationDuration'],
- 'framer': framer
- }, function (frame) {
- if (_this.isRemoved()) {
- player.finish();
- return;
- }
- if (player.playState === 'running') {
- var _view = _this.getView();
- if (!options['continueOnViewChanged'] && !equalView(_view, preView)) {
- _this._stopAnim(player);
- return;
- }
- if (frame.styles['center']) {
- var center = frame.styles['center'];
- _this._setPrjCenter(projection.project(center));
- _this.onMoving(_this._parseEventFromCoord(_this.getCenter()));
- }
- if (!isNil(frame.styles['zoom'])) {
- _this.onZooming(frame.styles['zoom'], zoomOrigin);
- }
- if (!isNil(frame.styles['pitch'])) {
- _this.setPitch(frame.styles['pitch']);
- }
- if (!isNil(frame.styles['bearing'])) {
- _this.setBearing(frame.styles['bearing']);
- }
- preView = _this.getView();
- _this._fireEvent('animating');
- } else if (player.playState === 'finished') {
- if (!player._interupted) {
- if (props['center']) {
- _this._setPrjCenter(projection.project(props['center'][1]));
- }
- if (!isNil(props['pitch'])) {
- _this.setPitch(props['pitch'][1]);
- }
- if (!isNil(props['bearing'])) {
- _this.setBearing(props['bearing'][1]);
- }
- }
- _this._endAnim(player, props, zoomOrigin, options);
- preView = _this.getView();
- }
- if (step) {
- step(frame);
- }
- });
- this._startAnim(props, zoomOrigin);
- return player;
- },
- isAnimating: function isAnimating() {
- return !!this._animPlayer;
- },
- isRotating: function isRotating() {
- return this.isDragRotating() || !!this._animRotating;
- },
- _endAnim: function _endAnim(player, props, zoomOrigin, options) {
- delete this._animRotating;
- var evtType = player._interupted ? 'animateinterrupted' : 'animateend';
- if (player === this._animPlayer) {
- delete this._animPlayer;
- }
- if (props['center']) {
- var endCoord;
- if (player._interupted) {
- endCoord = this.getCenter();
- } else {
- endCoord = props['center'][1];
- }
- this.onMoveEnd(this._parseEventFromCoord(endCoord));
- }
- if (!isNil(props['zoom'])) {
- if (player._interupted) {
- this.onZoomEnd(this.getZoom(), zoomOrigin);
- } else if (!options['wheelZoom']) {
- this.onZoomEnd(props['zoom'][1], zoomOrigin);
- } else {
- this.onZooming(props['zoom'][1], zoomOrigin);
- }
- }
- if (evtType) {
- this._fireEvent(evtType);
- }
- if (!isNil(props['pitch']) && !this.getPitch()) {
- this.getRenderer().setToRedraw();
- }
- },
- _startAnim: function _startAnim(props, zoomOrigin) {
- if (!this._animPlayer) {
- return;
- }
- if (props['center']) {
- this.onMoveStart();
- }
- if (props['zoom'] && !this.isZooming()) {
- this.onZoomStart(props['zoom'][1], zoomOrigin);
- }
- if (props['pitch'] || props['bearing']) {
- this._animRotating = true;
- }
- this._fireEvent('animatestart');
- this._animPlayer.play();
- },
- _stopAnim: function _stopAnim(player) {
- if (player && player.playState !== 'finished') {
- player._interupted = true;
- player.finish();
- }
- }
- });
- function rotateZ(out, a, rad) {
- var s = Math.sin(rad),
- c = Math.cos(rad),
- a00 = a[0],
- a01 = a[1],
- a02 = a[2],
- a03 = a[3],
- a10 = a[4],
- a11 = a[5],
- a12 = a[6],
- a13 = a[7];
- if (a !== out) {
- out[8] = a[8];
- out[9] = a[9];
- out[10] = a[10];
- out[11] = a[11];
- out[12] = a[12];
- out[13] = a[13];
- out[14] = a[14];
- out[15] = a[15];
- }
- out[0] = a00 * c + a10 * s;
- out[1] = a01 * c + a11 * s;
- out[2] = a02 * c + a12 * s;
- out[3] = a03 * c + a13 * s;
- out[4] = a10 * c - a00 * s;
- out[5] = a11 * c - a01 * s;
- out[6] = a12 * c - a02 * s;
- out[7] = a13 * c - a03 * s;
- return out;
- }
- function clamp(n, min, max) {
- return Math.min(max, Math.max(min, n));
- }
- function rotateX(out, a, rad) {
- var s = Math.sin(rad),
- c = Math.cos(rad),
- a10 = a[4],
- a11 = a[5],
- a12 = a[6],
- a13 = a[7],
- a20 = a[8],
- a21 = a[9],
- a22 = a[10],
- a23 = a[11];
- if (a !== out) {
- out[0] = a[0];
- out[1] = a[1];
- out[2] = a[2];
- out[3] = a[3];
- out[12] = a[12];
- out[13] = a[13];
- out[14] = a[14];
- out[15] = a[15];
- }
- out[4] = a10 * c + a20 * s;
- out[5] = a11 * c + a21 * s;
- out[6] = a12 * c + a22 * s;
- out[7] = a13 * c + a23 * s;
- out[8] = a20 * c - a10 * s;
- out[9] = a21 * c - a11 * s;
- out[10] = a22 * c - a12 * s;
- out[11] = a23 * c - a13 * s;
- return out;
- }
- function applyMatrix(out, v, e) {
- var x = v[0],
- y = v[1],
- z = v[2];
- var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
- out[0] = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
- out[1] = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
- out[2] = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
- return out;
- }
- function interpolate(a, b, t) {
- return a * (1 - t) + b * t;
- }
- export default toGeometry
- export {
- Map$1,
- Coordinate,
- MultiPolygon,
- Polygon
- }
|