mapv.js 282 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (factory((global.mapv = global.mapv || {})));
  5. }(this, (function (exports) { 'use strict';
  6. var version = "2.0.56";
  7. /**
  8. * @author kyle / http://nikai.us/
  9. */
  10. var clear = function (context) {
  11. context && context.clearRect && context.clearRect(0, 0, context.canvas.width, context.canvas.height);
  12. //context.canvas.width = context.canvas.width;
  13. //context.canvas.height = context.canvas.height;
  14. };
  15. /**
  16. * @author kyle / http://nikai.us/
  17. */
  18. var resolutionScale$1 = function (context) {
  19. var devicePixelRatio = window.devicePixelRatio || 1;
  20. context.canvas.width = context.canvas.width * devicePixelRatio;
  21. context.canvas.height = context.canvas.height * devicePixelRatio;
  22. context.canvas.style.width = context.canvas.width / devicePixelRatio + 'px';
  23. context.canvas.style.height = context.canvas.height / devicePixelRatio + 'px';
  24. context.scale(devicePixelRatio, devicePixelRatio);
  25. };
  26. function Event() {
  27. this._subscribers = {}; // event subscribers
  28. }
  29. /**
  30. * Subscribe to an event, add an event listener
  31. * @param {String} event Event name. Available events: 'put', 'update',
  32. * 'remove'
  33. * @param {function} callback Callback method. Called with three parameters:
  34. * {String} event
  35. * {Object | null} params
  36. * {String | Number} senderId
  37. */
  38. Event.prototype.on = function (event, callback) {
  39. var subscribers = this._subscribers[event];
  40. if (!subscribers) {
  41. subscribers = [];
  42. this._subscribers[event] = subscribers;
  43. }
  44. subscribers.push({
  45. callback: callback
  46. });
  47. };
  48. /**
  49. * Unsubscribe from an event, remove an event listener
  50. * @param {String} event
  51. * @param {function} callback
  52. */
  53. Event.prototype.off = function (event, callback) {
  54. var subscribers = this._subscribers[event];
  55. if (subscribers) {
  56. //this._subscribers[event] = subscribers.filter(listener => listener.callback != callback);
  57. for (var i = 0; i < subscribers.length; i++) {
  58. if (subscribers[i].callback == callback) {
  59. subscribers.splice(i, 1);
  60. i--;
  61. }
  62. }
  63. }
  64. };
  65. /**
  66. * Trigger an event
  67. * @param {String} event
  68. * @param {Object | null} params
  69. * @param {String} [senderId] Optional id of the sender.
  70. * @private
  71. */
  72. Event.prototype._trigger = function (event, params, senderId) {
  73. if (event == '*') {
  74. throw new Error('Cannot trigger event *');
  75. }
  76. var subscribers = [];
  77. if (event in this._subscribers) {
  78. subscribers = subscribers.concat(this._subscribers[event]);
  79. }
  80. if ('*' in this._subscribers) {
  81. subscribers = subscribers.concat(this._subscribers['*']);
  82. }
  83. for (var i = 0, len = subscribers.length; i < len; i++) {
  84. var subscriber = subscribers[i];
  85. if (subscriber.callback) {
  86. subscriber.callback(event, params, senderId || null);
  87. }
  88. }
  89. };
  90. /**
  91. * get the center by the city name
  92. * @author kyle / http://nikai.us/
  93. */
  94. var citycenter = { municipalities: [{ n: "北京", g: "116.395645,39.929986|12" }, { n: "上海", g: "121.487899,31.249162|12" }, { n: "天津", g: "117.210813,39.14393|12" }, { n: "重庆", g: "106.530635,29.544606|12" }], provinces: [{ n: "安徽", g: "117.216005,31.859252|8", cities: [{ n: "合肥", g: "117.282699,31.866942|12" }, { n: "安庆", g: "117.058739,30.537898|13" }, { n: "蚌埠", g: "117.35708,32.929499|13" }, { n: "亳州", g: "115.787928,33.871211|13" }, { n: "巢湖", g: "117.88049,31.608733|13" }, { n: "池州", g: "117.494477,30.660019|14" }, { n: "滁州", g: "118.32457,32.317351|13" }, { n: "阜阳", g: "115.820932,32.901211|13" }, { n: "淮北", g: "116.791447,33.960023|13" }, { n: "淮南", g: "117.018639,32.642812|13" }, { n: "黄山", g: "118.29357,29.734435|13" }, { n: "六安", g: "116.505253,31.755558|13" }, { n: "马鞍山", g: "118.515882,31.688528|13" }, { n: "宿州", g: "116.988692,33.636772|13" }, { n: "铜陵", g: "117.819429,30.94093|14" }, { n: "芜湖", g: "118.384108,31.36602|12" }, { n: "宣城", g: "118.752096,30.951642|13" }] }, { n: "福建", g: "117.984943,26.050118|8", cities: [{ n: "福州", g: "119.330221,26.047125|12" }, { n: "龙岩", g: "117.017997,25.078685|13" }, { n: "南平", g: "118.181883,26.643626|13" }, { n: "宁德", g: "119.542082,26.656527|14" }, { n: "莆田", g: "119.077731,25.44845|13" }, { n: "泉州", g: "118.600362,24.901652|12" }, { n: "三明", g: "117.642194,26.270835|14" }, { n: "厦门", g: "118.103886,24.489231|12" }, { n: "漳州", g: "117.676205,24.517065|12" }] }, { n: "甘肃", g: "102.457625,38.103267|6", cities: [{ n: "兰州", g: "103.823305,36.064226|12" }, { n: "白银", g: "104.171241,36.546682|13" }, { n: "定西", g: "104.626638,35.586056|13" }, { n: "甘南州", g: "102.917442,34.992211|14" }, { n: "嘉峪关", g: "98.281635,39.802397|13" }, { n: "金昌", g: "102.208126,38.516072|13" }, { n: "酒泉", g: "98.508415,39.741474|13" }, { n: "临夏州", g: "103.215249,35.598514|13" }, { n: "陇南", g: "104.934573,33.39448|14" }, { n: "平凉", g: "106.688911,35.55011|13" }, { n: "庆阳", g: "107.644227,35.726801|13" }, { n: "天水", g: "105.736932,34.584319|13" }, { n: "武威", g: "102.640147,37.933172|13" }, { n: "张掖", g: "100.459892,38.93932|13" }] }, { n: "广东", g: "113.394818,23.408004|8", cities: [{ n: "广州", g: "113.30765,23.120049|12" }, { n: "潮州", g: "116.630076,23.661812|13" }, { n: "东莞", g: "113.763434,23.043024|12" }, { n: "佛山", g: "113.134026,23.035095|13" }, { n: "河源", g: "114.713721,23.757251|12" }, { n: "惠州", g: "114.410658,23.11354|12" }, { n: "江门", g: "113.078125,22.575117|13" }, { n: "揭阳", g: "116.379501,23.547999|13" }, { n: "茂名", g: "110.931245,21.668226|13" }, { n: "梅州", g: "116.126403,24.304571|13" }, { n: "清远", g: "113.040773,23.698469|13" }, { n: "汕头", g: "116.72865,23.383908|13" }, { n: "汕尾", g: "115.372924,22.778731|14" }, { n: "韶关", g: "113.594461,24.80296|13" }, { n: "深圳", g: "114.025974,22.546054|12" }, { n: "阳江", g: "111.97701,21.871517|14" }, { n: "云浮", g: "112.050946,22.937976|13" }, { n: "湛江", g: "110.365067,21.257463|13" }, { n: "肇庆", g: "112.479653,23.078663|13" }, { n: "中山", g: "113.42206,22.545178|12" }, { n: "珠海", g: "113.562447,22.256915|13" }] }, { n: "广西", g: "108.924274,23.552255|7", cities: [{ n: "南宁", g: "108.297234,22.806493|12" }, { n: "百色", g: "106.631821,23.901512|13" }, { n: "北海", g: "109.122628,21.472718|13" }, { n: "崇左", g: "107.357322,22.415455|14" }, { n: "防城港", g: "108.351791,21.617398|15" }, { n: "桂林", g: "110.26092,25.262901|12" }, { n: "贵港", g: "109.613708,23.103373|13" }, { n: "河池", g: "108.069948,24.699521|14" }, { n: "贺州", g: "111.552594,24.411054|14" }, { n: "来宾", g: "109.231817,23.741166|14" }, { n: "柳州", g: "109.422402,24.329053|12" }, { n: "钦州", g: "108.638798,21.97335|13" }, { n: "梧州", g: "111.305472,23.485395|13" }, { n: "玉林", g: "110.151676,22.643974|14" }] }, { n: "贵州", g: "106.734996,26.902826|8", cities: [{ n: "贵阳", g: "106.709177,26.629907|12" }, { n: "安顺", g: "105.92827,26.228595|13" }, { n: "毕节地区", g: "105.300492,27.302612|14" }, { n: "六盘水", g: "104.852087,26.591866|13" }, { n: "铜仁地区", g: "109.196161,27.726271|14" }, { n: "遵义", g: "106.93126,27.699961|13" }, { n: "黔西南州", g: "104.900558,25.095148|11" }, { n: "黔东南州", g: "107.985353,26.583992|11" }, { n: "黔南州", g: "107.523205,26.264536|11" }] }, { n: "海南", g: "109.733755,19.180501|9", cities: [{ n: "海口", g: "110.330802,20.022071|13" }, { n: "白沙", g: "109.358586,19.216056|12" }, { n: "保亭", g: "109.656113,18.597592|12" }, { n: "昌江", g: "109.0113,19.222483|12" }, { n: "儋州", g: "109.413973,19.571153|13" }, { n: "澄迈", g: "109.996736,19.693135|13" }, { n: "东方", g: "108.85101,18.998161|13" }, { n: "定安", g: "110.32009,19.490991|13" }, { n: "琼海", g: "110.414359,19.21483|13" }, { n: "琼中", g: "109.861849,19.039771|12" }, { n: "乐东", g: "109.062698,18.658614|12" }, { n: "临高", g: "109.724101,19.805922|13" }, { n: "陵水", g: "109.948661,18.575985|12" }, { n: "三亚", g: "109.522771,18.257776|12" }, { n: "屯昌", g: "110.063364,19.347749|13" }, { n: "万宁", g: "110.292505,18.839886|13" }, { n: "文昌", g: "110.780909,19.750947|13" }, { n: "五指山", g: "109.51775,18.831306|13" }] }, { n: "河北", g: "115.661434,38.61384|7", cities: [{ n: "石家庄", g: "114.522082,38.048958|12" }, { n: "保定", g: "115.49481,38.886565|13" }, { n: "沧州", g: "116.863806,38.297615|13" }, { n: "承德", g: "117.933822,40.992521|14" }, { n: "邯郸", g: "114.482694,36.609308|13" }, { n: "衡水", g: "115.686229,37.746929|13" }, { n: "廊坊", g: "116.703602,39.518611|13" }, { n: "秦皇岛", g: "119.604368,39.945462|12" }, { n: "唐山", g: "118.183451,39.650531|13" }, { n: "邢台", g: "114.520487,37.069531|13" }, { n: "张家口", g: "114.893782,40.811188|13" }] }, { n: "河南", g: "113.486804,34.157184|7", cities: [{ n: "郑州", g: "113.649644,34.75661|12" }, { n: "安阳", g: "114.351807,36.110267|12" }, { n: "鹤壁", g: "114.29777,35.755426|13" }, { n: "焦作", g: "113.211836,35.234608|13" }, { n: "开封", g: "114.351642,34.801854|13" }, { n: "洛阳", g: "112.447525,34.657368|12" }, { n: "漯河", g: "114.046061,33.576279|13" }, { n: "南阳", g: "112.542842,33.01142|13" }, { n: "平顶山", g: "113.300849,33.745301|13" }, { n: "濮阳", g: "115.026627,35.753298|12" }, { n: "三门峡", g: "111.181262,34.78332|13" }, { n: "商丘", g: "115.641886,34.438589|13" }, { n: "新乡", g: "113.91269,35.307258|13" }, { n: "信阳", g: "114.085491,32.128582|13" }, { n: "许昌", g: "113.835312,34.02674|13" }, { n: "周口", g: "114.654102,33.623741|13" }, { n: "驻马店", g: "114.049154,32.983158|13" }] }, { n: "黑龙江", g: "128.047414,47.356592|6", cities: [{ n: "哈尔滨", g: "126.657717,45.773225|12" }, { n: "大庆", g: "125.02184,46.596709|12" }, { n: "大兴安岭地区", g: "124.196104,51.991789|10" }, { n: "鹤岗", g: "130.292472,47.338666|13" }, { n: "黑河", g: "127.50083,50.25069|14" }, { n: "鸡西", g: "130.941767,45.32154|13" }, { n: "佳木斯", g: "130.284735,46.81378|12" }, { n: "牡丹江", g: "129.608035,44.588521|13" }, { n: "七台河", g: "131.019048,45.775005|14" }, { n: "齐齐哈尔", g: "123.987289,47.3477|13" }, { n: "双鸭山", g: "131.171402,46.655102|13" }, { n: "绥化", g: "126.989095,46.646064|13" }, { n: "伊春", g: "128.910766,47.734685|14" }] }, { n: "湖北", g: "112.410562,31.209316|8", cities: [{ n: "武汉", g: "114.3162,30.581084|12" }, { n: "鄂州", g: "114.895594,30.384439|14" }, { n: "恩施", g: "109.517433,30.308978|14" }, { n: "黄冈", g: "114.906618,30.446109|14" }, { n: "黄石", g: "115.050683,30.216127|13" }, { n: "荆门", g: "112.21733,31.042611|13" }, { n: "荆州", g: "112.241866,30.332591|12" }, { n: "潜江", g: "112.768768,30.343116|13" }, { n: "神农架林区", g: "110.487231,31.595768|13" }, { n: "十堰", g: "110.801229,32.636994|13" }, { n: "随州", g: "113.379358,31.717858|13" }, { n: "天门", g: "113.12623,30.649047|13" }, { n: "仙桃", g: "113.387448,30.293966|13" }, { n: "咸宁", g: "114.300061,29.880657|13" }, { n: "襄阳", g: "112.176326,32.094934|12" }, { n: "孝感", g: "113.935734,30.927955|13" }, { n: "宜昌", g: "111.310981,30.732758|13" }] }, { n: "湖南", g: "111.720664,27.695864|7", cities: [{ n: "长沙", g: "112.979353,28.213478|12" }, { n: "常德", g: "111.653718,29.012149|12" }, { n: "郴州", g: "113.037704,25.782264|13" }, { n: "衡阳", g: "112.583819,26.898164|13" }, { n: "怀化", g: "109.986959,27.557483|13" }, { n: "娄底", g: "111.996396,27.741073|13" }, { n: "邵阳", g: "111.461525,27.236811|13" }, { n: "湘潭", g: "112.935556,27.835095|13" }, { n: "湘西州", g: "109.745746,28.317951|14" }, { n: "益阳", g: "112.366547,28.588088|13" }, { n: "永州", g: "111.614648,26.435972|13" }, { n: "岳阳", g: "113.146196,29.378007|13" }, { n: "张家界", g: "110.48162,29.124889|13" }, { n: "株洲", g: "113.131695,27.827433|13" }] }, { n: "江苏", g: "119.368489,33.013797|8", cities: [{ n: "南京", g: "118.778074,32.057236|12" }, { n: "常州", g: "119.981861,31.771397|12" }, { n: "淮安", g: "119.030186,33.606513|12" }, { n: "连云港", g: "119.173872,34.601549|12" }, { n: "南通", g: "120.873801,32.014665|12" }, { n: "苏州", g: "120.619907,31.317987|12" }, { n: "宿迁", g: "118.296893,33.95205|13" }, { n: "泰州", g: "119.919606,32.476053|13" }, { n: "无锡", g: "120.305456,31.570037|12" }, { n: "徐州", g: "117.188107,34.271553|12" }, { n: "盐城", g: "120.148872,33.379862|12" }, { n: "扬州", g: "119.427778,32.408505|13" }, { n: "镇江", g: "119.455835,32.204409|13" }] }, { n: "江西", g: "115.676082,27.757258|7", cities: [{ n: "南昌", g: "115.893528,28.689578|12" }, { n: "抚州", g: "116.360919,27.954545|13" }, { n: "赣州", g: "114.935909,25.845296|13" }, { n: "吉安", g: "114.992039,27.113848|13" }, { n: "景德镇", g: "117.186523,29.303563|12" }, { n: "九江", g: "115.999848,29.71964|13" }, { n: "萍乡", g: "113.859917,27.639544|13" }, { n: "上饶", g: "117.955464,28.457623|13" }, { n: "新余", g: "114.947117,27.822322|13" }, { n: "宜春", g: "114.400039,27.81113|13" }, { n: "鹰潭", g: "117.03545,28.24131|13" }] }, { n: "吉林", g: "126.262876,43.678846|7", cities: [{ n: "长春", g: "125.313642,43.898338|12" }, { n: "白城", g: "122.840777,45.621086|13" }, { n: "白山", g: "126.435798,41.945859|13" }, { n: "吉林", g: "126.564544,43.871988|12" }, { n: "辽源", g: "125.133686,42.923303|13" }, { n: "四平", g: "124.391382,43.175525|12" }, { n: "松原", g: "124.832995,45.136049|13" }, { n: "通化", g: "125.94265,41.736397|13" }, { n: "延边", g: "129.485902,42.896414|13" }] }, { n: "辽宁", g: "122.753592,41.6216|8", cities: [{ n: "沈阳", g: "123.432791,41.808645|12" }, { n: "鞍山", g: "123.007763,41.118744|13" }, { n: "本溪", g: "123.778062,41.325838|12" }, { n: "朝阳", g: "120.446163,41.571828|13" }, { n: "大连", g: "121.593478,38.94871|12" }, { n: "丹东", g: "124.338543,40.129023|12" }, { n: "抚顺", g: "123.92982,41.877304|12" }, { n: "阜新", g: "121.660822,42.01925|14" }, { n: "葫芦岛", g: "120.860758,40.74303|13" }, { n: "锦州", g: "121.147749,41.130879|13" }, { n: "辽阳", g: "123.172451,41.273339|14" }, { n: "盘锦", g: "122.073228,41.141248|13" }, { n: "铁岭", g: "123.85485,42.299757|13" }, { n: "营口", g: "122.233391,40.668651|13" }] }, { n: "内蒙古", g: "114.415868,43.468238|5", cities: [{ n: "呼和浩特", g: "111.660351,40.828319|12" }, { n: "阿拉善盟", g: "105.695683,38.843075|14" }, { n: "包头", g: "109.846239,40.647119|12" }, { n: "巴彦淖尔", g: "107.423807,40.76918|12" }, { n: "赤峰", g: "118.930761,42.297112|12" }, { n: "鄂尔多斯", g: "109.993706,39.81649|12" }, { n: "呼伦贝尔", g: "119.760822,49.201636|12" }, { n: "通辽", g: "122.260363,43.633756|12" }, { n: "乌海", g: "106.831999,39.683177|13" }, { n: "乌兰察布", g: "113.112846,41.022363|12" }, { n: "锡林郭勒盟", g: "116.02734,43.939705|11" }, { n: "兴安盟", g: "122.048167,46.083757|11" }] }, { n: "宁夏", g: "106.155481,37.321323|8", cities: [{ n: "银川", g: "106.206479,38.502621|12" }, { n: "固原", g: "106.285268,36.021523|13" }, { n: "石嘴山", g: "106.379337,39.020223|13" }, { n: "吴忠", g: "106.208254,37.993561|14" }, { n: "中卫", g: "105.196754,37.521124|14" }] }, { n: "青海", g: "96.202544,35.499761|7", cities: [{ n: "西宁", g: "101.767921,36.640739|12" }, { n: "果洛州", g: "100.223723,34.480485|11" }, { n: "海东地区", g: "102.085207,36.51761|11" }, { n: "海北州", g: "100.879802,36.960654|11" }, { n: "海南州", g: "100.624066,36.284364|11" }, { n: "海西州", g: "97.342625,37.373799|11" }, { n: "黄南州", g: "102.0076,35.522852|11" }, { n: "玉树州", g: "97.013316,33.00624|14" }] }, { n: "山东", g: "118.527663,36.09929|8", cities: [{ n: "济南", g: "117.024967,36.682785|12" }, { n: "滨州", g: "117.968292,37.405314|12" }, { n: "东营", g: "118.583926,37.487121|12" }, { n: "德州", g: "116.328161,37.460826|12" }, { n: "菏泽", g: "115.46336,35.26244|13" }, { n: "济宁", g: "116.600798,35.402122|13" }, { n: "莱芜", g: "117.684667,36.233654|13" }, { n: "聊城", g: "115.986869,36.455829|12" }, { n: "临沂", g: "118.340768,35.072409|12" }, { n: "青岛", g: "120.384428,36.105215|12" }, { n: "日照", g: "119.50718,35.420225|12" }, { n: "泰安", g: "117.089415,36.188078|13" }, { n: "威海", g: "122.093958,37.528787|13" }, { n: "潍坊", g: "119.142634,36.716115|12" }, { n: "烟台", g: "121.309555,37.536562|12" }, { n: "枣庄", g: "117.279305,34.807883|13" }, { n: "淄博", g: "118.059134,36.804685|12" }] }, { n: "山西", g: "112.515496,37.866566|7", cities: [{ n: "太原", g: "112.550864,37.890277|12" }, { n: "长治", g: "113.120292,36.201664|12" }, { n: "大同", g: "113.290509,40.113744|12" }, { n: "晋城", g: "112.867333,35.499834|13" }, { n: "晋中", g: "112.738514,37.693362|13" }, { n: "临汾", g: "111.538788,36.099745|13" }, { n: "吕梁", g: "111.143157,37.527316|14" }, { n: "朔州", g: "112.479928,39.337672|13" }, { n: "忻州", g: "112.727939,38.461031|12" }, { n: "阳泉", g: "113.569238,37.869529|13" }, { n: "运城", g: "111.006854,35.038859|13" }] }, { n: "陕西", g: "109.503789,35.860026|7", cities: [{ n: "西安", g: "108.953098,34.2778|12" }, { n: "安康", g: "109.038045,32.70437|13" }, { n: "宝鸡", g: "107.170645,34.364081|12" }, { n: "汉中", g: "107.045478,33.081569|13" }, { n: "商洛", g: "109.934208,33.873907|13" }, { n: "铜川", g: "108.968067,34.908368|13" }, { n: "渭南", g: "109.483933,34.502358|13" }, { n: "咸阳", g: "108.707509,34.345373|13" }, { n: "延安", g: "109.50051,36.60332|13" }, { n: "榆林", g: "109.745926,38.279439|12" }] }, { n: "四川", g: "102.89916,30.367481|7", cities: [{ n: "成都", g: "104.067923,30.679943|12" }, { n: "阿坝州", g: "102.228565,31.905763|15" }, { n: "巴中", g: "106.757916,31.869189|14" }, { n: "达州", g: "107.494973,31.214199|14" }, { n: "德阳", g: "104.402398,31.13114|13" }, { n: "甘孜州", g: "101.969232,30.055144|15" }, { n: "广安", g: "106.63572,30.463984|13" }, { n: "广元", g: "105.819687,32.44104|13" }, { n: "乐山", g: "103.760824,29.600958|13" }, { n: "凉山州", g: "102.259591,27.892393|14" }, { n: "泸州", g: "105.44397,28.89593|14" }, { n: "南充", g: "106.105554,30.800965|13" }, { n: "眉山", g: "103.84143,30.061115|13" }, { n: "绵阳", g: "104.705519,31.504701|12" }, { n: "内江", g: "105.073056,29.599462|13" }, { n: "攀枝花", g: "101.722423,26.587571|14" }, { n: "遂宁", g: "105.564888,30.557491|12" }, { n: "雅安", g: "103.009356,29.999716|13" }, { n: "宜宾", g: "104.633019,28.769675|13" }, { n: "资阳", g: "104.63593,30.132191|13" }, { n: "自贡", g: "104.776071,29.359157|13" }] }, { n: "西藏", g: "89.137982,31.367315|6", cities: [{ n: "拉萨", g: "91.111891,29.662557|13" }, { n: "阿里地区", g: "81.107669,30.404557|11" }, { n: "昌都地区", g: "97.185582,31.140576|15" }, { n: "林芝地区", g: "94.349985,29.666941|11" }, { n: "那曲地区", g: "92.067018,31.48068|14" }, { n: "日喀则地区", g: "88.891486,29.269023|14" }, { n: "山南地区", g: "91.750644,29.229027|11" }] }, { n: "新疆", g: "85.614899,42.127001|6", cities: [{ n: "乌鲁木齐", g: "87.564988,43.84038|12" }, { n: "阿拉尔", g: "81.291737,40.61568|13" }, { n: "阿克苏地区", g: "80.269846,41.171731|12" }, { n: "阿勒泰地区", g: "88.137915,47.839744|13" }, { n: "巴音郭楞", g: "86.121688,41.771362|12" }, { n: "博尔塔拉州", g: "82.052436,44.913651|11" }, { n: "昌吉州", g: "87.296038,44.007058|13" }, { n: "哈密地区", g: "93.528355,42.858596|13" }, { n: "和田地区", g: "79.930239,37.116774|13" }, { n: "喀什地区", g: "75.992973,39.470627|12" }, { n: "克拉玛依", g: "84.88118,45.594331|13" }, { n: "克孜勒苏州", g: "76.137564,39.750346|11" }, { n: "石河子", g: "86.041865,44.308259|13" }, { n: "塔城地区", g: "82.974881,46.758684|12" }, { n: "图木舒克", g: "79.198155,39.889223|13" }, { n: "吐鲁番地区", g: "89.181595,42.96047|13" }, { n: "五家渠", g: "87.565449,44.368899|13" }, { n: "伊犁州", g: "81.297854,43.922248|11" }] }, { n: "云南", g: "101.592952,24.864213|7", cities: [{ n: "昆明", g: "102.714601,25.049153|12" }, { n: "保山", g: "99.177996,25.120489|13" }, { n: "楚雄州", g: "101.529382,25.066356|13" }, { n: "大理州", g: "100.223675,25.5969|14" }, { n: "德宏州", g: "98.589434,24.44124|14" }, { n: "迪庆州", g: "99.713682,27.831029|14" }, { n: "红河州", g: "103.384065,23.367718|11" }, { n: "丽江", g: "100.229628,26.875351|13" }, { n: "临沧", g: "100.092613,23.887806|14" }, { n: "怒江州", g: "98.859932,25.860677|14" }, { n: "普洱", g: "100.980058,22.788778|14" }, { n: "曲靖", g: "103.782539,25.520758|12" }, { n: "昭通", g: "103.725021,27.340633|13" }, { n: "文山", g: "104.089112,23.401781|14" }, { n: "西双版纳", g: "100.803038,22.009433|13" }, { n: "玉溪", g: "102.545068,24.370447|13" }] }, { n: "浙江", g: "119.957202,29.159494|8", cities: [{ n: "杭州", g: "120.219375,30.259244|12" }, { n: "湖州", g: "120.137243,30.877925|12" }, { n: "嘉兴", g: "120.760428,30.773992|13" }, { n: "金华", g: "119.652576,29.102899|12" }, { n: "丽水", g: "119.929576,28.4563|13" }, { n: "宁波", g: "121.579006,29.885259|12" }, { n: "衢州", g: "118.875842,28.95691|12" }, { n: "绍兴", g: "120.592467,30.002365|13" }, { n: "台州", g: "121.440613,28.668283|13" }, { n: "温州", g: "120.690635,28.002838|12" }, { n: "舟山", g: "122.169872,30.03601|13" }] }], other: [{ n: "香港", g: "114.186124,22.293586|11" }, { n: "澳门", g: "113.557519,22.204118|13" }, { n: "台湾", g: "120.961454,23.80406|8" }] };
  95. function getCenter(g) {
  96. var item = g.split("|");
  97. item[0] = item[0].split(",");
  98. return {
  99. lng: parseFloat(item[0][0]),
  100. lat: parseFloat(item[0][1])
  101. };
  102. }
  103. var cityCenter = {
  104. getProvinceNameByCityName: function getProvinceNameByCityName(name) {
  105. var provinces = citycenter.provinces;
  106. for (var i = 0; i < provinces.length; i++) {
  107. var provinceName = provinces[i].n;
  108. var cities = provinces[i].cities;
  109. for (var j = 0; j < cities.length; j++) {
  110. if (cities[j].n == name) {
  111. return provinceName;
  112. }
  113. }
  114. }
  115. return null;
  116. },
  117. getCenterByCityName: function getCenterByCityName(name) {
  118. name = name.replace('市', '');
  119. for (var i = 0; i < citycenter.municipalities.length; i++) {
  120. if (citycenter.municipalities[i].n == name) {
  121. return getCenter(citycenter.municipalities[i].g);
  122. }
  123. }
  124. for (var i = 0; i < citycenter.other.length; i++) {
  125. if (citycenter.other[i].n == name) {
  126. return getCenter(citycenter.other[i].g);
  127. }
  128. }
  129. var provinces = citycenter.provinces;
  130. for (var i = 0; i < provinces.length; i++) {
  131. if (provinces[i].n == name) {
  132. return getCenter(provinces[i].g);
  133. }
  134. var cities = provinces[i].cities;
  135. for (var j = 0; j < cities.length; j++) {
  136. if (cities[j].n == name) {
  137. return getCenter(cities[j].g);
  138. }
  139. }
  140. }
  141. return null;
  142. }
  143. };
  144. var classCallCheck = function (instance, Constructor) {
  145. if (!(instance instanceof Constructor)) {
  146. throw new TypeError("Cannot call a class as a function");
  147. }
  148. };
  149. var createClass = function () {
  150. function defineProperties(target, props) {
  151. for (var i = 0; i < props.length; i++) {
  152. var descriptor = props[i];
  153. descriptor.enumerable = descriptor.enumerable || false;
  154. descriptor.configurable = true;
  155. if ("value" in descriptor) descriptor.writable = true;
  156. Object.defineProperty(target, descriptor.key, descriptor);
  157. }
  158. }
  159. return function (Constructor, protoProps, staticProps) {
  160. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  161. if (staticProps) defineProperties(Constructor, staticProps);
  162. return Constructor;
  163. };
  164. }();
  165. var get = function get(object, property, receiver) {
  166. if (object === null) object = Function.prototype;
  167. var desc = Object.getOwnPropertyDescriptor(object, property);
  168. if (desc === undefined) {
  169. var parent = Object.getPrototypeOf(object);
  170. if (parent === null) {
  171. return undefined;
  172. } else {
  173. return get(parent, property, receiver);
  174. }
  175. } else if ("value" in desc) {
  176. return desc.value;
  177. } else {
  178. var getter = desc.get;
  179. if (getter === undefined) {
  180. return undefined;
  181. }
  182. return getter.call(receiver);
  183. }
  184. };
  185. var inherits = function (subClass, superClass) {
  186. if (typeof superClass !== "function" && superClass !== null) {
  187. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  188. }
  189. subClass.prototype = Object.create(superClass && superClass.prototype, {
  190. constructor: {
  191. value: subClass,
  192. enumerable: false,
  193. writable: true,
  194. configurable: true
  195. }
  196. });
  197. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  198. };
  199. var possibleConstructorReturn = function (self, call) {
  200. if (!self) {
  201. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  202. }
  203. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  204. };
  205. /**
  206. * @author kyle / http://nikai.us/
  207. */
  208. /**
  209. * DataSet
  210. *
  211. * A data set can:
  212. * - add/remove/update data
  213. * - gives triggers upon changes in the data
  214. * - can import/export data in various data formats
  215. * @param {Array} [data] Optional array with initial data
  216. * the field geometry is like geojson, it can be:
  217. * {
  218. * "type": "Point",
  219. * "coordinates": [125.6, 10.1]
  220. * }
  221. * {
  222. * "type": "LineString",
  223. * "coordinates": [
  224. * [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
  225. * ]
  226. * }
  227. * {
  228. * "type": "Polygon",
  229. * "coordinates": [
  230. * [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
  231. * [100.0, 1.0], [100.0, 0.0] ]
  232. * ]
  233. * }
  234. * @param {Object} [options] Available options:
  235. *
  236. */
  237. function DataSet(data, options) {
  238. Event.bind(this)();
  239. this._options = options || {};
  240. this._data = []; // map with data indexed by id
  241. // add initial data when provided
  242. if (data) {
  243. this.add(data);
  244. }
  245. }
  246. DataSet.prototype = Event.prototype;
  247. /**
  248. * Add data.
  249. */
  250. DataSet.prototype.add = function (data, senderId) {
  251. if (Array.isArray(data)) {
  252. // Array
  253. for (var i = 0, len = data.length; i < len; i++) {
  254. if (data[i]) {
  255. if (data[i].time && data[i].time.length == 14 && data[i].time.substr(0, 2) == '20') {
  256. var time = data[i].time;
  257. data[i].time = new Date(time.substr(0, 4) + '-' + time.substr(4, 2) + '-' + time.substr(6, 2) + ' ' + time.substr(8, 2) + ':' + time.substr(10, 2) + ':' + time.substr(12, 2)).getTime();
  258. }
  259. this._data.push(data[i]);
  260. }
  261. }
  262. } else if (data instanceof Object) {
  263. // Single item
  264. this._data.push(data);
  265. } else {
  266. throw new Error('Unknown dataType');
  267. }
  268. this._dataCache = JSON.parse(JSON.stringify(this._data));
  269. };
  270. DataSet.prototype.reset = function () {
  271. this._data = JSON.parse(JSON.stringify(this._dataCache));
  272. };
  273. /**
  274. * get data.
  275. */
  276. DataSet.prototype.get = function (args) {
  277. args = args || {};
  278. //console.time('copy data time')
  279. var start = new Date();
  280. // TODO: 不修改原始数据,在数据上挂载新的名称,每次修改数据直接修改新名称下的数据,可以省去deepCopy
  281. // var data = deepCopy(this._data);
  282. var data = this._data;
  283. var start = new Date();
  284. if (args.filter) {
  285. var newData = [];
  286. for (var i = 0; i < data.length; i++) {
  287. if (args.filter(data[i])) {
  288. newData.push(data[i]);
  289. }
  290. }
  291. data = newData;
  292. }
  293. if (args.transferCoordinate) {
  294. data = this.transferCoordinate(data, args.transferCoordinate, args.fromColumn, args.toColumn);
  295. }
  296. // console.timeEnd('transferCoordinate time')
  297. return data;
  298. };
  299. /**
  300. * set data.
  301. */
  302. DataSet.prototype.set = function (data) {
  303. this._set(data);
  304. this._trigger('change');
  305. };
  306. /**
  307. * set data.
  308. */
  309. DataSet.prototype._set = function (data) {
  310. this.clear();
  311. this.add(data);
  312. };
  313. /**
  314. * clear data.
  315. */
  316. DataSet.prototype.clear = function (args) {
  317. this._data = []; // map with data indexed by id
  318. };
  319. /**
  320. * remove data.
  321. */
  322. DataSet.prototype.remove = function (args) {};
  323. /**
  324. * update data.
  325. */
  326. DataSet.prototype.update = function (cbk, condition) {
  327. var data = this._data;
  328. var item = null;
  329. for (var i = 0; i < data.length; i++) {
  330. if (condition) {
  331. var flag = true;
  332. for (var key in condition) {
  333. if (data[i][key] != condition[key]) {
  334. flag = false;
  335. }
  336. }
  337. if (flag) {
  338. cbk && cbk(data[i]);
  339. }
  340. } else {
  341. cbk && cbk(data[i]);
  342. }
  343. }
  344. this._dataCache = JSON.parse(JSON.stringify(this._data));
  345. this._trigger('change');
  346. };
  347. /**
  348. * transfer coordinate.
  349. */
  350. DataSet.prototype.transferCoordinate = function (data, transferFn, fromColumn, toColumnName) {
  351. toColumnName = toColumnName || '_coordinates';
  352. fromColumn = fromColumn || 'coordinates';
  353. for (var i = 0; i < data.length; i++) {
  354. var geometry = data[i].geometry;
  355. var coordinates = geometry[fromColumn];
  356. switch (geometry.type) {
  357. case 'Point':
  358. geometry[toColumnName] = transferFn(coordinates);
  359. break;
  360. case 'LineString':
  361. var newCoordinates = [];
  362. for (var j = 0; j < coordinates.length; j++) {
  363. newCoordinates.push(transferFn(coordinates[j]));
  364. }
  365. geometry[toColumnName] = newCoordinates;
  366. break;
  367. case 'MultiLineString':
  368. case 'Polygon':
  369. var newCoordinates = getPolygon(coordinates);
  370. geometry[toColumnName] = newCoordinates;
  371. break;
  372. case 'MultiPolygon':
  373. var newCoordinates = [];
  374. for (var c = 0; c < coordinates.length; c++) {
  375. var polygon = coordinates[c];
  376. var polygon = getPolygon(polygon);
  377. newCoordinates.push(polygon);
  378. }
  379. geometry[toColumnName] = newCoordinates;
  380. break;
  381. }
  382. }
  383. function getPolygon(coordinates) {
  384. var newCoordinates = [];
  385. for (var c = 0; c < coordinates.length; c++) {
  386. var coordinate = coordinates[c];
  387. var newcoordinate = [];
  388. for (var j = 0; j < coordinate.length; j++) {
  389. newcoordinate.push(transferFn(coordinate[j]));
  390. }
  391. newCoordinates.push(newcoordinate);
  392. }
  393. return newCoordinates;
  394. }
  395. return data;
  396. };
  397. DataSet.prototype.initGeometry = function (transferFn) {
  398. if (transferFn) {
  399. this._data.forEach(function (item) {
  400. item.geometry = transferFn(item);
  401. });
  402. } else {
  403. this._data.forEach(function (item) {
  404. if (!item.geometry) {
  405. if (item.lng && item.lat) {
  406. item.geometry = {
  407. type: 'Point',
  408. coordinates: [item.lng, item.lat]
  409. };
  410. } else if (item.city) {
  411. var center = cityCenter.getCenterByCityName(item.city);
  412. if (center) {
  413. item.geometry = {
  414. type: 'Point',
  415. coordinates: [center.lng, center.lat]
  416. };
  417. }
  418. }
  419. }
  420. });
  421. }
  422. };
  423. /**
  424. * 获取当前列的最大值
  425. */
  426. DataSet.prototype.getMax = function (columnName) {
  427. var data = this._data;
  428. if (!data || data.length <= 0) {
  429. return;
  430. }
  431. var max = parseFloat(data[0][columnName]);
  432. for (var i = 1; i < data.length; i++) {
  433. var value = parseFloat(data[i][columnName]);
  434. if (value > max) {
  435. max = value;
  436. }
  437. }
  438. return max;
  439. };
  440. /**
  441. * 获取当前列的总和
  442. */
  443. DataSet.prototype.getSum = function (columnName) {
  444. var data = this._data;
  445. if (!data || data.length <= 0) {
  446. return;
  447. }
  448. var sum = 0;
  449. for (var i = 0; i < data.length; i++) {
  450. if (data[i][columnName]) {
  451. sum += parseFloat(data[i][columnName]);
  452. }
  453. }
  454. return sum;
  455. };
  456. /**
  457. * 获取当前列的最小值
  458. */
  459. DataSet.prototype.getMin = function (columnName) {
  460. var data = this._data;
  461. if (!data || data.length <= 0) {
  462. return;
  463. }
  464. var min = parseFloat(data[0][columnName]);
  465. for (var i = 1; i < data.length; i++) {
  466. var value = parseFloat(data[i][columnName]);
  467. if (value < min) {
  468. min = value;
  469. }
  470. }
  471. return min;
  472. };
  473. /**
  474. * 获取去重的数据
  475. */
  476. DataSet.prototype.getUnique = function (columnName) {
  477. var data = this._data;
  478. if (!data || data.length <= 0) {
  479. return;
  480. }
  481. var maps = {};
  482. for (var i = 1; i < data.length; i++) {
  483. maps[data[i][columnName]] = true;
  484. }
  485. var data = [];
  486. for (var key in maps) {
  487. data.push(key);
  488. }
  489. return data;
  490. };
  491. function hex_corner(center, size, i) {
  492. var angle_deg = 60 * i + 30;
  493. var angle_rad = Math.PI / 180 * angle_deg;
  494. return [center.x + size * Math.cos(angle_rad), center.y + size * Math.sin(angle_rad)];
  495. }
  496. function draw(context, x, y, size) {
  497. for (var j = 0; j < 6; j++) {
  498. var result = hex_corner({
  499. x: x,
  500. y: y
  501. }, size, j);
  502. context.lineTo(result[0], result[1]);
  503. }
  504. }
  505. /**
  506. * @author kyle / http://nikai.us/
  507. */
  508. var pathSimple = {
  509. drawDataSet: function drawDataSet(context, dataSet, options) {
  510. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  511. for (var i = 0, len = data.length; i < len; i++) {
  512. var item = data[i];
  513. this.draw(context, item, options);
  514. }
  515. },
  516. draw: function draw$$1(context, data, options) {
  517. var type = data.geometry.type;
  518. var coordinates = data.geometry._coordinates || data.geometry.coordinates;
  519. var symbol = data.symbol || options.symbol || 'circle';
  520. switch (type) {
  521. case 'Point':
  522. var size = data._size || data.size || options._size || options.size || 5;
  523. if (symbol === 'circle') {
  524. if (options.bigData === 'Point') {
  525. context.moveTo(coordinates[0], coordinates[1]);
  526. }
  527. context.arc(coordinates[0], coordinates[1], size, 0, Math.PI * 2);
  528. } else if (symbol === 'rect') {
  529. context.rect(coordinates[0] - size / 2, coordinates[1] - size / 2, size, size);
  530. } else if (symbol === 'honeycomb') {
  531. draw(context, coordinates[0], coordinates[1], size);
  532. }
  533. break;
  534. case 'LineString':
  535. this.drawLineString(context, coordinates);
  536. break;
  537. case 'MultiLineString':
  538. for (var i = 0; i < coordinates.length; i++) {
  539. var lineString = coordinates[i];
  540. this.drawLineString(context, lineString);
  541. }
  542. break;
  543. case 'Polygon':
  544. this.drawPolygon(context, coordinates);
  545. break;
  546. case 'MultiPolygon':
  547. for (var i = 0; i < coordinates.length; i++) {
  548. var polygon = coordinates[i];
  549. this.drawPolygon(context, polygon);
  550. if (options.multiPolygonDraw) {
  551. var flag = options.multiPolygonDraw();
  552. if (flag) {
  553. return flag;
  554. }
  555. }
  556. }
  557. break;
  558. default:
  559. console.error('type' + type + 'is not support now!');
  560. break;
  561. }
  562. },
  563. drawLineString: function drawLineString(context, coordinates) {
  564. for (var j = 0; j < coordinates.length; j++) {
  565. var x = coordinates[j][0];
  566. var y = coordinates[j][1];
  567. if (j == 0) {
  568. context.moveTo(x, y);
  569. } else {
  570. context.lineTo(x, y);
  571. }
  572. }
  573. },
  574. drawPolygon: function drawPolygon(context, coordinates) {
  575. context.beginPath();
  576. for (var i = 0; i < coordinates.length; i++) {
  577. var coordinate = coordinates[i];
  578. context.moveTo(coordinate[0][0], coordinate[0][1]);
  579. for (var j = 1; j < coordinate.length; j++) {
  580. context.lineTo(coordinate[j][0], coordinate[j][1]);
  581. }
  582. context.lineTo(coordinate[0][0], coordinate[0][1]);
  583. context.closePath();
  584. }
  585. }
  586. };
  587. /**
  588. * @author kyle / http://nikai.us/
  589. */
  590. var drawSimple = {
  591. draw: function draw(context, dataSet, options) {
  592. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  593. // console.log('xxxx',options)
  594. context.save();
  595. for (var key in options) {
  596. context[key] = options[key];
  597. }
  598. // console.log(data);
  599. if (options.bigData) {
  600. context.save();
  601. context.beginPath();
  602. for (var i = 0, len = data.length; i < len; i++) {
  603. var item = data[i];
  604. pathSimple.draw(context, item, options);
  605. }
  606. var type = options.bigData;
  607. if (type == 'Point' || type == 'Polygon' || type == 'MultiPolygon') {
  608. context.fill();
  609. if (context.lineDash) {
  610. context.setLineDash(context.lineDash);
  611. }
  612. if (item.lineDash) {
  613. context.setLineDash(item.lineDash);
  614. }
  615. if ((item.strokeStyle || options.strokeStyle) && options.lineWidth) {
  616. context.stroke();
  617. }
  618. } else if (type == 'LineString' || type == 'MultiLineString') {
  619. context.stroke();
  620. }
  621. context.restore();
  622. } else {
  623. for (var i = 0, len = data.length; i < len; i++) {
  624. var item = data[i];
  625. context.save();
  626. if (item.fillStyle || item._fillStyle) {
  627. context.fillStyle = item.fillStyle || item._fillStyle;
  628. }
  629. if (item.strokeStyle || item._strokeStyle) {
  630. context.strokeStyle = item.strokeStyle || item._strokeStyle;
  631. }
  632. if (context.lineDash) {
  633. context.setLineDash(context.lineDash);
  634. }
  635. if (item.lineDash) {
  636. context.setLineDash(item.lineDash);
  637. }
  638. var type = item.geometry.type;
  639. context.beginPath();
  640. options.multiPolygonDraw = function () {
  641. context.fill();
  642. if ((item.strokeStyle || options.strokeStyle) && options.lineWidth) {
  643. context.stroke();
  644. }
  645. };
  646. pathSimple.draw(context, item, options);
  647. if (type == 'Point' || type == 'Polygon' || type == 'MultiPolygon') {
  648. context.fill();
  649. if ((item.strokeStyle || options.strokeStyle) && options.lineWidth) {
  650. context.stroke();
  651. }
  652. } else if (type == 'LineString' || type == 'MultiLineString') {
  653. if (item.lineWidth || item._lineWidth) {
  654. context.lineWidth = item.lineWidth || item._lineWidth;
  655. }
  656. context.stroke();
  657. }
  658. context.restore();
  659. }
  660. }
  661. context.restore();
  662. }
  663. };
  664. function Canvas(width, height) {
  665. var canvas;
  666. if (typeof document === 'undefined') {
  667. // var Canvas = require('canvas');
  668. // canvas = new Canvas(width, height);
  669. } else {
  670. var canvas = document.createElement('canvas');
  671. if (width) {
  672. canvas.width = width;
  673. }
  674. if (height) {
  675. canvas.height = height;
  676. }
  677. }
  678. return canvas;
  679. }
  680. /**
  681. * @author kyle / http://nikai.us/
  682. */
  683. /**
  684. * Category
  685. * @param {Object} [options] Available options:
  686. * {Object} gradient: { 0.25: "rgb(0,0,255)", 0.55: "rgb(0,255,0)", 0.85: "yellow", 1.0: "rgb(255,0,0)"}
  687. */
  688. function Intensity(options) {
  689. options = options || {};
  690. this.gradient = options.gradient || {
  691. 0.25: "rgba(0, 0, 255, 1)",
  692. 0.55: "rgba(0, 255, 0, 1)",
  693. 0.85: "rgba(255, 255, 0, 1)",
  694. 1.0: "rgba(255, 0, 0, 1)"
  695. };
  696. this.maxSize = options.maxSize || 35;
  697. this.minSize = options.minSize || 0;
  698. this.max = options.max || 100;
  699. this.min = options.min || 0;
  700. this.initPalette();
  701. }
  702. Intensity.prototype.setMax = function (value) {
  703. this.max = value || 100;
  704. };
  705. Intensity.prototype.setMin = function (value) {
  706. this.min = value || 0;
  707. };
  708. Intensity.prototype.setMaxSize = function (maxSize) {
  709. this.maxSize = maxSize || 35;
  710. };
  711. Intensity.prototype.setMinSize = function (minSize) {
  712. this.minSize = minSize || 0;
  713. };
  714. Intensity.prototype.initPalette = function () {
  715. var gradient = this.gradient;
  716. var canvas = new Canvas(256, 1);
  717. var paletteCtx = this.paletteCtx = canvas.getContext('2d');
  718. var lineGradient = paletteCtx.createLinearGradient(0, 0, 256, 1);
  719. for (var key in gradient) {
  720. lineGradient.addColorStop(parseFloat(key), gradient[key]);
  721. }
  722. paletteCtx.fillStyle = lineGradient;
  723. paletteCtx.fillRect(0, 0, 256, 1);
  724. };
  725. Intensity.prototype.getColor = function (value) {
  726. var imageData = this.getImageData(value);
  727. return "rgba(" + imageData[0] + ", " + imageData[1] + ", " + imageData[2] + ", " + imageData[3] / 256 + ")";
  728. };
  729. Intensity.prototype.getImageData = function (value) {
  730. var imageData = this.paletteCtx.getImageData(0, 0, 256, 1).data;
  731. if (value === undefined) {
  732. return imageData;
  733. }
  734. var max = this.max;
  735. var min = this.min;
  736. if (value > max) {
  737. value = max;
  738. }
  739. if (value < min) {
  740. value = min;
  741. }
  742. var index = Math.floor((value - min) / (max - min) * (256 - 1)) * 4;
  743. return [imageData[index], imageData[index + 1], imageData[index + 2], imageData[index + 3]];
  744. };
  745. /**
  746. * @param Number value
  747. * @param Number max of value
  748. * @param Number max of size
  749. * @param Object other options
  750. */
  751. Intensity.prototype.getSize = function (value) {
  752. var size = 0;
  753. var max = this.max;
  754. var min = this.min;
  755. var maxSize = this.maxSize;
  756. var minSize = this.minSize;
  757. if (value > max) {
  758. value = max;
  759. }
  760. if (value < min) {
  761. value = min;
  762. }
  763. if (max > min) {
  764. size = minSize + (value - min) / (max - min) * (maxSize - minSize);
  765. } else {
  766. return maxSize;
  767. }
  768. return size;
  769. };
  770. Intensity.prototype.getLegend = function (options) {
  771. var gradient = this.gradient;
  772. var width = options.width || 20;
  773. var height = options.height || 180;
  774. var canvas = new Canvas(width, height);
  775. var paletteCtx = canvas.getContext('2d');
  776. var lineGradient = paletteCtx.createLinearGradient(0, height, 0, 0);
  777. for (var key in gradient) {
  778. lineGradient.addColorStop(parseFloat(key), gradient[key]);
  779. }
  780. paletteCtx.fillStyle = lineGradient;
  781. paletteCtx.fillRect(0, 0, width, height);
  782. return canvas;
  783. };
  784. var global$1 = typeof window === 'undefined' ? {} : window;
  785. var devicePixelRatio = global$1.devicePixelRatio || 1;
  786. /**
  787. * @author kyle / http://nikai.us/
  788. */
  789. function createCircle(size) {
  790. var shadowBlur = size / 2;
  791. var r2 = size + shadowBlur;
  792. var offsetDistance = 10000;
  793. var circle = new Canvas(r2 * 2, r2 * 2);
  794. var context = circle.getContext('2d');
  795. context.shadowBlur = shadowBlur;
  796. context.shadowColor = 'black';
  797. context.shadowOffsetX = context.shadowOffsetY = offsetDistance;
  798. context.beginPath();
  799. context.arc(r2 - offsetDistance, r2 - offsetDistance, size, 0, Math.PI * 2, true);
  800. context.closePath();
  801. context.fill();
  802. return circle;
  803. }
  804. function colorize(pixels, gradient, options) {
  805. var max = getMax(options);
  806. var min = getMin(options);
  807. var diff = max - min;
  808. var range = options.range || null;
  809. var jMin = 0;
  810. var jMax = 1024;
  811. if (range && range.length === 2) {
  812. jMin = (range[0] - min) / diff * 1024;
  813. }
  814. if (range && range.length === 2) {
  815. jMax = (range[1] - min) / diff * 1024;
  816. }
  817. var maxOpacity = options.maxOpacity || 0.8;
  818. var minOpacity = options.minOpacity || 0;
  819. var range = options.range;
  820. for (var i = 3, len = pixels.length, j; i < len; i += 4) {
  821. j = pixels[i] * 4; // get gradient color from opacity value
  822. if (pixels[i] / 256 > maxOpacity) {
  823. pixels[i] = 256 * maxOpacity;
  824. }
  825. if (pixels[i] / 256 < minOpacity) {
  826. pixels[i] = 256 * minOpacity;
  827. }
  828. if (j && j >= jMin && j <= jMax) {
  829. pixels[i - 3] = gradient[j];
  830. pixels[i - 2] = gradient[j + 1];
  831. pixels[i - 1] = gradient[j + 2];
  832. } else {
  833. pixels[i] = 0;
  834. }
  835. }
  836. }
  837. function getMax(options) {
  838. var max = options.max || 100;
  839. return max;
  840. }
  841. function getMin(options) {
  842. var min = options.min || 0;
  843. return min;
  844. }
  845. function drawGray(context, dataSet, options) {
  846. var max = getMax(options);
  847. var min = getMin(options);
  848. // console.log(max)
  849. var size = options._size;
  850. if (size == undefined) {
  851. size = options.size;
  852. if (size == undefined) {
  853. size = 13;
  854. }
  855. }
  856. var intensity = new Intensity({
  857. gradient: options.gradient,
  858. max: max,
  859. min: min
  860. });
  861. var circle = createCircle(size);
  862. var circleHalfWidth = circle.width / 2;
  863. var circleHalfHeight = circle.height / 2;
  864. var data = dataSet;
  865. var dataOrderByAlpha = {};
  866. data.forEach(function (item, index) {
  867. var count = item.count === undefined ? 1 : item.count;
  868. var alpha = Math.min(1, count / max).toFixed(2);
  869. dataOrderByAlpha[alpha] = dataOrderByAlpha[alpha] || [];
  870. dataOrderByAlpha[alpha].push(item);
  871. });
  872. for (var i in dataOrderByAlpha) {
  873. if (isNaN(i)) continue;
  874. var _data = dataOrderByAlpha[i];
  875. context.beginPath();
  876. if (!options.withoutAlpha) {
  877. context.globalAlpha = i;
  878. }
  879. context.strokeStyle = intensity.getColor(i * max);
  880. _data.forEach(function (item, index) {
  881. if (!item.geometry) {
  882. return;
  883. }
  884. var coordinates = item.geometry._coordinates || item.geometry.coordinates;
  885. var type = item.geometry.type;
  886. if (type === 'Point') {
  887. var count = item.count === undefined ? 1 : item.count;
  888. context.globalAlpha = count / max;
  889. context.drawImage(circle, coordinates[0] - circleHalfWidth, coordinates[1] - circleHalfHeight);
  890. } else if (type === 'LineString') {
  891. var count = item.count === undefined ? 1 : item.count;
  892. context.globalAlpha = count / max;
  893. context.beginPath();
  894. pathSimple.draw(context, item, options);
  895. context.stroke();
  896. } else if (type === 'Polygon') {}
  897. });
  898. }
  899. }
  900. function draw$1(context, dataSet, options) {
  901. if (context.canvas.width <= 0 || context.canvas.height <= 0) {
  902. return;
  903. }
  904. var strength = options.strength || 0.3;
  905. context.strokeStyle = 'rgba(0,0,0,' + strength + ')';
  906. var shadowCanvas = new Canvas(context.canvas.width, context.canvas.height);
  907. var shadowContext = shadowCanvas.getContext('2d');
  908. shadowContext.scale(devicePixelRatio, devicePixelRatio);
  909. options = options || {};
  910. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  911. context.save();
  912. var intensity = new Intensity({
  913. gradient: options.gradient
  914. });
  915. //console.time('drawGray')
  916. drawGray(shadowContext, data, options);
  917. //console.timeEnd('drawGray');
  918. // return false;
  919. if (!options.absolute) {
  920. //console.time('changeColor');
  921. var colored = shadowContext.getImageData(0, 0, context.canvas.width, context.canvas.height);
  922. colorize(colored.data, intensity.getImageData(), options);
  923. //console.timeEnd('changeColor');
  924. context.putImageData(colored, 0, 0);
  925. context.restore();
  926. }
  927. intensity = null;
  928. shadowCanvas = null;
  929. }
  930. var drawHeatmap = {
  931. draw: draw$1
  932. };
  933. /**
  934. * @author kyle / http://nikai.us/
  935. */
  936. var drawGrid = {
  937. draw: function draw(context, dataSet, options) {
  938. context.save();
  939. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  940. var grids = {};
  941. var size = options._size || options.size || 50;
  942. // 后端传入数据为网格数据时,传入enableCluster为false,前端不进行删格化操作,直接画方格
  943. var enableCluster = 'enableCluster' in options ? options.enableCluster : true;
  944. var offset = options.offset || {
  945. x: 0,
  946. y: 0
  947. };
  948. var intensity = new Intensity({
  949. min: options.min || 0,
  950. max: options.max || 100,
  951. gradient: options.gradient
  952. });
  953. if (!enableCluster) {
  954. for (var i = 0; i < data.length; i++) {
  955. var coordinates = data[i].geometry._coordinates || data[i].geometry.coordinates;
  956. var gridKey = coordinates.join(',');
  957. grids[gridKey] = data[i].count || 1;
  958. }
  959. for (var _gridKey in grids) {
  960. _gridKey = _gridKey.split(',');
  961. context.beginPath();
  962. context.rect(+_gridKey[0] - size / 2, +_gridKey[1] - size / 2, size, size);
  963. context.fillStyle = intensity.getColor(grids[_gridKey]);
  964. context.fill();
  965. if (options.strokeStyle && options.lineWidth) {
  966. context.stroke();
  967. }
  968. }
  969. } else {
  970. for (var _i = 0; _i < data.length; _i++) {
  971. var coordinates = data[_i].geometry._coordinates || data[_i].geometry.coordinates;
  972. var gridKey = Math.floor((coordinates[0] - offset.x) / size) + ',' + Math.floor((coordinates[1] - offset.y) / size);
  973. if (!grids[gridKey]) {
  974. grids[gridKey] = 0;
  975. }
  976. grids[gridKey] += ~~(data[_i].count || 1);
  977. }
  978. for (var _gridKey2 in grids) {
  979. _gridKey2 = _gridKey2.split(',');
  980. context.beginPath();
  981. context.rect(_gridKey2[0] * size + .5 + offset.x, _gridKey2[1] * size + .5 + offset.y, size, size);
  982. context.fillStyle = intensity.getColor(grids[_gridKey2]);
  983. context.fill();
  984. if (options.strokeStyle && options.lineWidth) {
  985. context.stroke();
  986. }
  987. }
  988. }
  989. if (options.label && options.label.show !== false) {
  990. context.fillStyle = options.label.fillStyle || 'white';
  991. if (options.label.font) {
  992. context.font = options.label.font;
  993. }
  994. if (options.label.shadowColor) {
  995. context.shadowColor = options.label.shadowColor;
  996. }
  997. if (options.label.shadowBlur) {
  998. context.shadowBlur = options.label.shadowBlur;
  999. }
  1000. for (var gridKey in grids) {
  1001. gridKey = gridKey.split(',');
  1002. var text = grids[gridKey];
  1003. var textWidth = context.measureText(text).width;
  1004. if (!enableCluster) {
  1005. context.fillText(text, +gridKey[0] - textWidth / 2, +gridKey[1] + 5);
  1006. } else {
  1007. context.fillText(text, gridKey[0] * size + .5 + offset.x + size / 2 - textWidth / 2, gridKey[1] * size + .5 + offset.y + size / 2 + 5);
  1008. }
  1009. }
  1010. }
  1011. context.restore();
  1012. }
  1013. };
  1014. /**
  1015. * @author kyle / http://nikai.us/
  1016. */
  1017. function hex_corner$1(center, size, i) {
  1018. var angle_deg = 60 * i + 30;
  1019. var angle_rad = Math.PI / 180 * angle_deg;
  1020. return [center.x + size * Math.cos(angle_rad), center.y + size * Math.sin(angle_rad)];
  1021. }
  1022. var drawHoneycomb = {
  1023. draw: function draw(context, dataSet, options) {
  1024. context.save();
  1025. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  1026. for (var key in options) {
  1027. context[key] = options[key];
  1028. }
  1029. var grids = {};
  1030. var offset = options.offset || {
  1031. x: 10,
  1032. y: 10
  1033. };
  1034. var r = options._size || options.size || 40;
  1035. r = r / 2 / Math.sin(Math.PI / 3);
  1036. var dx = r * 2 * Math.sin(Math.PI / 3);
  1037. var dy = r * 1.5;
  1038. var binsById = {};
  1039. for (var i = 0; i < data.length; i++) {
  1040. var coordinates = data[i].geometry._coordinates || data[i].geometry.coordinates;
  1041. var py = (coordinates[1] - offset.y) / dy,
  1042. pj = Math.round(py),
  1043. px = (coordinates[0] - offset.x) / dx - (pj & 1 ? .5 : 0),
  1044. pi = Math.round(px),
  1045. py1 = py - pj;
  1046. if (Math.abs(py1) * 3 > 1) {
  1047. var px1 = px - pi,
  1048. pi2 = pi + (px < pi ? -1 : 1) / 2,
  1049. pj2 = pj + (py < pj ? -1 : 1),
  1050. px2 = px - pi2,
  1051. py2 = py - pj2;
  1052. if (px1 * px1 + py1 * py1 > px2 * px2 + py2 * py2) pi = pi2 + (pj & 1 ? 1 : -1) / 2, pj = pj2;
  1053. }
  1054. var id = pi + "-" + pj,
  1055. bin = binsById[id];
  1056. if (bin) {
  1057. bin.push(data[i]);
  1058. } else {
  1059. bin = binsById[id] = [data[i]];
  1060. bin.i = pi;
  1061. bin.j = pj;
  1062. bin.x = (pi + (pj & 1 ? 1 / 2 : 0)) * dx;
  1063. bin.y = pj * dy;
  1064. }
  1065. }
  1066. var intensity = new Intensity({
  1067. max: options.max || 100,
  1068. maxSize: r,
  1069. gradient: options.gradient
  1070. });
  1071. for (var key in binsById) {
  1072. var item = binsById[key];
  1073. context.beginPath();
  1074. for (var j = 0; j < 6; j++) {
  1075. var result = hex_corner$1({
  1076. x: item.x + offset.x,
  1077. y: item.y + offset.y
  1078. }, r, j);
  1079. context.lineTo(result[0], result[1]);
  1080. }
  1081. context.closePath();
  1082. var count = 0;
  1083. for (var i = 0; i < item.length; i++) {
  1084. count += item[i].count || 1;
  1085. }
  1086. item.count = count;
  1087. context.fillStyle = intensity.getColor(count);
  1088. context.fill();
  1089. if (options.strokeStyle && options.lineWidth) {
  1090. context.stroke();
  1091. }
  1092. }
  1093. if (options.label && options.label.show !== false) {
  1094. context.fillStyle = options.label.fillStyle || 'white';
  1095. if (options.label.font) {
  1096. context.font = options.label.font;
  1097. }
  1098. if (options.label.shadowColor) {
  1099. context.shadowColor = options.label.shadowColor;
  1100. }
  1101. if (options.label.shadowBlur) {
  1102. context.shadowBlur = options.label.shadowBlur;
  1103. }
  1104. for (var key in binsById) {
  1105. var item = binsById[key];
  1106. var text = item.count;
  1107. if (text < 0) {
  1108. text = text.toFixed(2);
  1109. } else {
  1110. text = ~~text;
  1111. }
  1112. var textWidth = context.measureText(text).width;
  1113. context.fillText(text, item.x + offset.x - textWidth / 2, item.y + offset.y + 5);
  1114. }
  1115. }
  1116. context.restore();
  1117. }
  1118. };
  1119. function createShader(gl, src, type) {
  1120. var shader = gl.createShader(type);
  1121. gl.shaderSource(shader, src);
  1122. gl.compileShader(shader);
  1123. return shader;
  1124. }
  1125. function initShaders(gl, vs_source, fs_source) {
  1126. var vertexShader = createShader(gl, vs_source, gl.VERTEX_SHADER);
  1127. var fragmentShader = createShader(gl, fs_source, gl.FRAGMENT_SHADER);
  1128. var glProgram = gl.createProgram();
  1129. gl.attachShader(glProgram, vertexShader);
  1130. gl.attachShader(glProgram, fragmentShader);
  1131. gl.linkProgram(glProgram);
  1132. gl.useProgram(glProgram);
  1133. return glProgram;
  1134. }
  1135. function getColorData(color) {
  1136. var tmpCanvas = document.createElement('canvas');
  1137. var tmpCtx = tmpCanvas.getContext('2d');
  1138. tmpCanvas.width = 1;
  1139. tmpCanvas.height = 1;
  1140. tmpCtx.fillStyle = color;
  1141. tmpCtx.fillRect(0, 0, 1, 1);
  1142. return tmpCtx.getImageData(0, 0, 1, 1).data;
  1143. }
  1144. var vs_s = ['attribute vec4 a_Position;', 'void main() {', 'gl_Position = a_Position;', 'gl_PointSize = 30.0;', '}'].join('');
  1145. var fs_s = ['precision mediump float;', 'uniform vec4 u_FragColor;', 'void main() {', 'gl_FragColor = u_FragColor;', '}'].join('');
  1146. function draw$2(gl, data, options) {
  1147. if (!data) {
  1148. return;
  1149. }
  1150. var program = initShaders(gl, vs_s, fs_s);
  1151. gl.enable(gl.BLEND);
  1152. gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
  1153. //gl.clearColor(0.0, 0.0, 1.0, 1.0);
  1154. gl.clear(gl.COLOR_BUFFER_BIT);
  1155. var halfCanvasWidth = gl.canvas.width / 2;
  1156. var halfCanvasHeight = gl.canvas.height / 2;
  1157. // Create a buffer object
  1158. var vertexBuffer = gl.createBuffer();
  1159. // Bind the buffer object to target
  1160. gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
  1161. var a_Position = gl.getAttribLocation(program, 'a_Position');
  1162. // Assign the buffer object to a_Position variable
  1163. gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, 0, 0);
  1164. // Enable the assignment to a_Position variable
  1165. gl.enableVertexAttribArray(a_Position);
  1166. var uFragColor = gl.getUniformLocation(program, 'u_FragColor');
  1167. var colored = getColorData(options.strokeStyle || 'red');
  1168. gl.uniform4f(uFragColor, colored[0] / 255, colored[1] / 255, colored[2] / 255, colored[3] / 255);
  1169. gl.lineWidth(options.lineWidth || 1);
  1170. for (var i = 0, len = data.length; i < len; i++) {
  1171. var _geometry = data[i].geometry._coordinates;
  1172. var verticesData = [];
  1173. for (var j = 0; j < _geometry.length; j++) {
  1174. var item = _geometry[j];
  1175. var x = (item[0] - halfCanvasWidth) / halfCanvasWidth;
  1176. var y = (halfCanvasHeight - item[1]) / halfCanvasHeight;
  1177. verticesData.push(x, y);
  1178. }
  1179. var vertices = new Float32Array(verticesData);
  1180. // Write date into the buffer object
  1181. gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
  1182. gl.drawArrays(gl.LINE_STRIP, 0, _geometry.length);
  1183. }
  1184. }
  1185. var line = {
  1186. draw: draw$2
  1187. };
  1188. var vs_s$1 = ['attribute vec4 a_Position;', 'attribute float a_PointSize;', 'void main() {', 'gl_Position = a_Position;', 'gl_PointSize = a_PointSize;', '}'].join('');
  1189. var fs_s$1 = ['precision mediump float;', 'uniform vec4 u_FragColor;', 'void main() {', 'gl_FragColor = u_FragColor;', '}'].join('');
  1190. function draw$3(gl, data, options) {
  1191. if (!data) {
  1192. return;
  1193. }
  1194. var program = initShaders(gl, vs_s$1, fs_s$1);
  1195. var a_Position = gl.getAttribLocation(program, 'a_Position');
  1196. var a_PointSize = gl.getAttribLocation(program, 'a_PointSize');
  1197. var uFragColor = gl.getUniformLocation(program, 'u_FragColor');
  1198. //gl.clearColor(0.0, 0.0, 1.0, 1.0);
  1199. gl.clear(gl.COLOR_BUFFER_BIT);
  1200. var halfCanvasWidth = gl.canvas.width / 2;
  1201. var halfCanvasHeight = gl.canvas.height / 2;
  1202. var verticesData = [];
  1203. var count = 0;
  1204. for (var i = 0; i < data.length; i++) {
  1205. var item = data[i].geometry._coordinates;
  1206. var x = (item[0] - halfCanvasWidth) / halfCanvasWidth;
  1207. var y = (halfCanvasHeight - item[1]) / halfCanvasHeight;
  1208. if (x < -1 || x > 1 || y < -1 || y > 1) {
  1209. continue;
  1210. }
  1211. verticesData.push(x, y);
  1212. count++;
  1213. }
  1214. var vertices = new Float32Array(verticesData);
  1215. var n = count; // The number of vertices
  1216. // Create a buffer object
  1217. var vertexBuffer = gl.createBuffer();
  1218. // Bind the buffer object to target
  1219. gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
  1220. // Write date into the buffer object
  1221. gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
  1222. // Assign the buffer object to a_Position variable
  1223. gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, 0, 0);
  1224. // Enable the assignment to a_Position variable
  1225. gl.enableVertexAttribArray(a_Position);
  1226. gl.vertexAttrib1f(a_PointSize, options._size);
  1227. var colored = getColorData(options.fillStyle || 'red');
  1228. gl.uniform4f(uFragColor, colored[0] / 255, colored[1] / 255, colored[2] / 255, colored[3] / 255);
  1229. gl.drawArrays(gl.POINTS, 0, n);
  1230. }
  1231. var point = {
  1232. draw: draw$3
  1233. };
  1234. function earcut(data, holeIndices, dim) {
  1235. dim = dim || 2;
  1236. var hasHoles = holeIndices && holeIndices.length,
  1237. outerLen = hasHoles ? holeIndices[0] * dim : data.length,
  1238. outerNode = linkedList(data, 0, outerLen, dim, true),
  1239. triangles = [];
  1240. if (!outerNode) return triangles;
  1241. var minX, minY, maxX, maxY, x, y, size;
  1242. if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim);
  1243. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  1244. if (data.length > 80 * dim) {
  1245. minX = maxX = data[0];
  1246. minY = maxY = data[1];
  1247. for (var i = dim; i < outerLen; i += dim) {
  1248. x = data[i];
  1249. y = data[i + 1];
  1250. if (x < minX) minX = x;
  1251. if (y < minY) minY = y;
  1252. if (x > maxX) maxX = x;
  1253. if (y > maxY) maxY = y;
  1254. }
  1255. // minX, minY and size are later used to transform coords into integers for z-order calculation
  1256. size = Math.max(maxX - minX, maxY - minY);
  1257. }
  1258. earcutLinked(outerNode, triangles, dim, minX, minY, size);
  1259. return triangles;
  1260. }
  1261. // create a circular doubly linked list from polygon points in the specified winding order
  1262. function linkedList(data, start, end, dim, clockwise) {
  1263. var i, last;
  1264. if (clockwise === signedArea(data, start, end, dim) > 0) {
  1265. for (i = start; i < end; i += dim) {
  1266. last = insertNode(i, data[i], data[i + 1], last);
  1267. }
  1268. } else {
  1269. for (i = end - dim; i >= start; i -= dim) {
  1270. last = insertNode(i, data[i], data[i + 1], last);
  1271. }
  1272. }
  1273. if (last && equals(last, last.next)) {
  1274. removeNode(last);
  1275. last = last.next;
  1276. }
  1277. return last;
  1278. }
  1279. // eliminate colinear or duplicate points
  1280. function filterPoints(start, end) {
  1281. if (!start) return start;
  1282. if (!end) end = start;
  1283. var p = start,
  1284. again;
  1285. do {
  1286. again = false;
  1287. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  1288. removeNode(p);
  1289. p = end = p.prev;
  1290. if (p === p.next) return null;
  1291. again = true;
  1292. } else {
  1293. p = p.next;
  1294. }
  1295. } while (again || p !== end);
  1296. return end;
  1297. }
  1298. // main ear slicing loop which triangulates a polygon (given as a linked list)
  1299. function earcutLinked(ear, triangles, dim, minX, minY, size, pass) {
  1300. if (!ear) return;
  1301. // interlink polygon nodes in z-order
  1302. if (!pass && size) indexCurve(ear, minX, minY, size);
  1303. var stop = ear,
  1304. prev,
  1305. next;
  1306. // iterate through ears, slicing them one by one
  1307. while (ear.prev !== ear.next) {
  1308. prev = ear.prev;
  1309. next = ear.next;
  1310. if (size ? isEarHashed(ear, minX, minY, size) : isEar(ear)) {
  1311. // cut off the triangle
  1312. triangles.push(prev.i / dim);
  1313. triangles.push(ear.i / dim);
  1314. triangles.push(next.i / dim);
  1315. removeNode(ear);
  1316. // skipping the next vertice leads to less sliver triangles
  1317. ear = next.next;
  1318. stop = next.next;
  1319. continue;
  1320. }
  1321. ear = next;
  1322. // if we looped through the whole remaining polygon and can't find any more ears
  1323. if (ear === stop) {
  1324. // try filtering points and slicing again
  1325. if (!pass) {
  1326. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, size, 1);
  1327. // if this didn't work, try curing all small self-intersections locally
  1328. } else if (pass === 1) {
  1329. ear = cureLocalIntersections(ear, triangles, dim);
  1330. earcutLinked(ear, triangles, dim, minX, minY, size, 2);
  1331. // as a last resort, try splitting the remaining polygon into two
  1332. } else if (pass === 2) {
  1333. splitEarcut(ear, triangles, dim, minX, minY, size);
  1334. }
  1335. break;
  1336. }
  1337. }
  1338. }
  1339. // check whether a polygon node forms a valid ear with adjacent nodes
  1340. function isEar(ear) {
  1341. var a = ear.prev,
  1342. b = ear,
  1343. c = ear.next;
  1344. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  1345. // now make sure we don't have other points inside the potential ear
  1346. var p = ear.next.next;
  1347. while (p !== ear.prev) {
  1348. if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
  1349. p = p.next;
  1350. }
  1351. return true;
  1352. }
  1353. function isEarHashed(ear, minX, minY, size) {
  1354. var a = ear.prev,
  1355. b = ear,
  1356. c = ear.next;
  1357. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  1358. // triangle bbox; min & max are calculated like this for speed
  1359. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  1360. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  1361. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  1362. maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
  1363. // z-order range for the current triangle bbox;
  1364. var minZ = zOrder(minTX, minTY, minX, minY, size),
  1365. maxZ = zOrder(maxTX, maxTY, minX, minY, size);
  1366. // first look for points inside the triangle in increasing z-order
  1367. var p = ear.nextZ;
  1368. while (p && p.z <= maxZ) {
  1369. if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
  1370. p = p.nextZ;
  1371. }
  1372. // then look for points in decreasing z-order
  1373. p = ear.prevZ;
  1374. while (p && p.z >= minZ) {
  1375. if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
  1376. p = p.prevZ;
  1377. }
  1378. return true;
  1379. }
  1380. // go through all polygon nodes and cure small local self-intersections
  1381. function cureLocalIntersections(start, triangles, dim) {
  1382. var p = start;
  1383. do {
  1384. var a = p.prev,
  1385. b = p.next.next;
  1386. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  1387. triangles.push(a.i / dim);
  1388. triangles.push(p.i / dim);
  1389. triangles.push(b.i / dim);
  1390. // remove two nodes involved
  1391. removeNode(p);
  1392. removeNode(p.next);
  1393. p = start = b;
  1394. }
  1395. p = p.next;
  1396. } while (p !== start);
  1397. return p;
  1398. }
  1399. // try splitting polygon into two and triangulate them independently
  1400. function splitEarcut(start, triangles, dim, minX, minY, size) {
  1401. // look for a valid diagonal that divides the polygon into two
  1402. var a = start;
  1403. do {
  1404. var b = a.next.next;
  1405. while (b !== a.prev) {
  1406. if (a.i !== b.i && isValidDiagonal(a, b)) {
  1407. // split the polygon in two by the diagonal
  1408. var c = splitPolygon(a, b);
  1409. // filter colinear points around the cuts
  1410. a = filterPoints(a, a.next);
  1411. c = filterPoints(c, c.next);
  1412. // run earcut on each half
  1413. earcutLinked(a, triangles, dim, minX, minY, size);
  1414. earcutLinked(c, triangles, dim, minX, minY, size);
  1415. return;
  1416. }
  1417. b = b.next;
  1418. }
  1419. a = a.next;
  1420. } while (a !== start);
  1421. }
  1422. // link every hole into the outer loop, producing a single-ring polygon without holes
  1423. function eliminateHoles(data, holeIndices, outerNode, dim) {
  1424. var queue = [],
  1425. i,
  1426. len,
  1427. start,
  1428. end,
  1429. list;
  1430. for (i = 0, len = holeIndices.length; i < len; i++) {
  1431. start = holeIndices[i] * dim;
  1432. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  1433. list = linkedList(data, start, end, dim, false);
  1434. if (list === list.next) list.steiner = true;
  1435. queue.push(getLeftmost(list));
  1436. }
  1437. queue.sort(compareX);
  1438. // process holes from left to right
  1439. for (i = 0; i < queue.length; i++) {
  1440. eliminateHole(queue[i], outerNode);
  1441. outerNode = filterPoints(outerNode, outerNode.next);
  1442. }
  1443. return outerNode;
  1444. }
  1445. function compareX(a, b) {
  1446. return a.x - b.x;
  1447. }
  1448. // find a bridge between vertices that connects hole with an outer ring and and link it
  1449. function eliminateHole(hole, outerNode) {
  1450. outerNode = findHoleBridge(hole, outerNode);
  1451. if (outerNode) {
  1452. var b = splitPolygon(outerNode, hole);
  1453. filterPoints(b, b.next);
  1454. }
  1455. }
  1456. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  1457. function findHoleBridge(hole, outerNode) {
  1458. var p = outerNode,
  1459. hx = hole.x,
  1460. hy = hole.y,
  1461. qx = -Infinity,
  1462. m;
  1463. // find a segment intersected by a ray from the hole's leftmost point to the left;
  1464. // segment's endpoint with lesser x will be potential connection point
  1465. do {
  1466. if (hy <= p.y && hy >= p.next.y) {
  1467. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  1468. if (x <= hx && x > qx) {
  1469. qx = x;
  1470. if (x === hx) {
  1471. if (hy === p.y) return p;
  1472. if (hy === p.next.y) return p.next;
  1473. }
  1474. m = p.x < p.next.x ? p : p.next;
  1475. }
  1476. }
  1477. p = p.next;
  1478. } while (p !== outerNode);
  1479. if (!m) return null;
  1480. if (hx === qx) return m.prev; // hole touches outer segment; pick lower endpoint
  1481. // look for points inside the triangle of hole point, segment intersection and endpoint;
  1482. // if there are no points found, we have a valid connection;
  1483. // otherwise choose the point of the minimum angle with the ray as connection point
  1484. var stop = m,
  1485. mx = m.x,
  1486. my = m.y,
  1487. tanMin = Infinity,
  1488. tan;
  1489. p = m.next;
  1490. while (p !== stop) {
  1491. if (hx >= p.x && p.x >= mx && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
  1492. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  1493. if ((tan < tanMin || tan === tanMin && p.x > m.x) && locallyInside(p, hole)) {
  1494. m = p;
  1495. tanMin = tan;
  1496. }
  1497. }
  1498. p = p.next;
  1499. }
  1500. return m;
  1501. }
  1502. // interlink polygon nodes in z-order
  1503. function indexCurve(start, minX, minY, size) {
  1504. var p = start;
  1505. do {
  1506. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, size);
  1507. p.prevZ = p.prev;
  1508. p.nextZ = p.next;
  1509. p = p.next;
  1510. } while (p !== start);
  1511. p.prevZ.nextZ = null;
  1512. p.prevZ = null;
  1513. sortLinked(p);
  1514. }
  1515. // Simon Tatham's linked list merge sort algorithm
  1516. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  1517. function sortLinked(list) {
  1518. var i,
  1519. p,
  1520. q,
  1521. e,
  1522. tail,
  1523. numMerges,
  1524. pSize,
  1525. qSize,
  1526. inSize = 1;
  1527. do {
  1528. p = list;
  1529. list = null;
  1530. tail = null;
  1531. numMerges = 0;
  1532. while (p) {
  1533. numMerges++;
  1534. q = p;
  1535. pSize = 0;
  1536. for (i = 0; i < inSize; i++) {
  1537. pSize++;
  1538. q = q.nextZ;
  1539. if (!q) break;
  1540. }
  1541. qSize = inSize;
  1542. while (pSize > 0 || qSize > 0 && q) {
  1543. if (pSize === 0) {
  1544. e = q;
  1545. q = q.nextZ;
  1546. qSize--;
  1547. } else if (qSize === 0 || !q) {
  1548. e = p;
  1549. p = p.nextZ;
  1550. pSize--;
  1551. } else if (p.z <= q.z) {
  1552. e = p;
  1553. p = p.nextZ;
  1554. pSize--;
  1555. } else {
  1556. e = q;
  1557. q = q.nextZ;
  1558. qSize--;
  1559. }
  1560. if (tail) tail.nextZ = e;else list = e;
  1561. e.prevZ = tail;
  1562. tail = e;
  1563. }
  1564. p = q;
  1565. }
  1566. tail.nextZ = null;
  1567. inSize *= 2;
  1568. } while (numMerges > 1);
  1569. return list;
  1570. }
  1571. // z-order of a point given coords and size of the data bounding box
  1572. function zOrder(x, y, minX, minY, size) {
  1573. // coords are transformed into non-negative 15-bit integer range
  1574. x = 32767 * (x - minX) / size;
  1575. y = 32767 * (y - minY) / size;
  1576. x = (x | x << 8) & 0x00FF00FF;
  1577. x = (x | x << 4) & 0x0F0F0F0F;
  1578. x = (x | x << 2) & 0x33333333;
  1579. x = (x | x << 1) & 0x55555555;
  1580. y = (y | y << 8) & 0x00FF00FF;
  1581. y = (y | y << 4) & 0x0F0F0F0F;
  1582. y = (y | y << 2) & 0x33333333;
  1583. y = (y | y << 1) & 0x55555555;
  1584. return x | y << 1;
  1585. }
  1586. // find the leftmost node of a polygon ring
  1587. function getLeftmost(start) {
  1588. var p = start,
  1589. leftmost = start;
  1590. do {
  1591. if (p.x < leftmost.x) leftmost = p;
  1592. p = p.next;
  1593. } while (p !== start);
  1594. return leftmost;
  1595. }
  1596. // check if a point lies within a convex triangle
  1597. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  1598. return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
  1599. }
  1600. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  1601. function isValidDiagonal(a, b) {
  1602. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b);
  1603. }
  1604. // signed area of a triangle
  1605. function area(p, q, r) {
  1606. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  1607. }
  1608. // check if two points are equal
  1609. function equals(p1, p2) {
  1610. return p1.x === p2.x && p1.y === p2.y;
  1611. }
  1612. // check if two segments intersect
  1613. function intersects(p1, q1, p2, q2) {
  1614. if (equals(p1, q1) && equals(p2, q2) || equals(p1, q2) && equals(p2, q1)) return true;
  1615. return area(p1, q1, p2) > 0 !== area(p1, q1, q2) > 0 && area(p2, q2, p1) > 0 !== area(p2, q2, q1) > 0;
  1616. }
  1617. // check if a polygon diagonal intersects any polygon segments
  1618. function intersectsPolygon(a, b) {
  1619. var p = a;
  1620. do {
  1621. if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b)) return true;
  1622. p = p.next;
  1623. } while (p !== a);
  1624. return false;
  1625. }
  1626. // check if a polygon diagonal is locally inside the polygon
  1627. function locallyInside(a, b) {
  1628. return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
  1629. }
  1630. // check if the middle point of a polygon diagonal is inside the polygon
  1631. function middleInside(a, b) {
  1632. var p = a,
  1633. inside = false,
  1634. px = (a.x + b.x) / 2,
  1635. py = (a.y + b.y) / 2;
  1636. do {
  1637. if (p.y > py !== p.next.y > py && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x) inside = !inside;
  1638. p = p.next;
  1639. } while (p !== a);
  1640. return inside;
  1641. }
  1642. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  1643. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  1644. function splitPolygon(a, b) {
  1645. var a2 = new Node(a.i, a.x, a.y),
  1646. b2 = new Node(b.i, b.x, b.y),
  1647. an = a.next,
  1648. bp = b.prev;
  1649. a.next = b;
  1650. b.prev = a;
  1651. a2.next = an;
  1652. an.prev = a2;
  1653. b2.next = a2;
  1654. a2.prev = b2;
  1655. bp.next = b2;
  1656. b2.prev = bp;
  1657. return b2;
  1658. }
  1659. // create a node and optionally link it with previous one (in a circular doubly linked list)
  1660. function insertNode(i, x, y, last) {
  1661. var p = new Node(i, x, y);
  1662. if (!last) {
  1663. p.prev = p;
  1664. p.next = p;
  1665. } else {
  1666. p.next = last.next;
  1667. p.prev = last;
  1668. last.next.prev = p;
  1669. last.next = p;
  1670. }
  1671. return p;
  1672. }
  1673. function removeNode(p) {
  1674. p.next.prev = p.prev;
  1675. p.prev.next = p.next;
  1676. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  1677. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  1678. }
  1679. function Node(i, x, y) {
  1680. // vertice index in coordinates array
  1681. this.i = i;
  1682. // vertex coordinates
  1683. this.x = x;
  1684. this.y = y;
  1685. // previous and next vertice nodes in a polygon ring
  1686. this.prev = null;
  1687. this.next = null;
  1688. // z-order curve value
  1689. this.z = null;
  1690. // previous and next nodes in z-order
  1691. this.prevZ = null;
  1692. this.nextZ = null;
  1693. // indicates whether this is a steiner point
  1694. this.steiner = false;
  1695. }
  1696. // return a percentage difference between the polygon area and its triangulation area;
  1697. // used to verify correctness of triangulation
  1698. earcut.deviation = function (data, holeIndices, dim, triangles) {
  1699. var hasHoles = holeIndices && holeIndices.length;
  1700. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  1701. var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));
  1702. if (hasHoles) {
  1703. for (var i = 0, len = holeIndices.length; i < len; i++) {
  1704. var start = holeIndices[i] * dim;
  1705. var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  1706. polygonArea -= Math.abs(signedArea(data, start, end, dim));
  1707. }
  1708. }
  1709. var trianglesArea = 0;
  1710. for (i = 0; i < triangles.length; i += 3) {
  1711. var a = triangles[i] * dim;
  1712. var b = triangles[i + 1] * dim;
  1713. var c = triangles[i + 2] * dim;
  1714. trianglesArea += Math.abs((data[a] - data[c]) * (data[b + 1] - data[a + 1]) - (data[a] - data[b]) * (data[c + 1] - data[a + 1]));
  1715. }
  1716. return polygonArea === 0 && trianglesArea === 0 ? 0 : Math.abs((trianglesArea - polygonArea) / polygonArea);
  1717. };
  1718. function signedArea(data, start, end, dim) {
  1719. var sum = 0;
  1720. for (var i = start, j = end - dim; i < end; i += dim) {
  1721. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  1722. j = i;
  1723. }
  1724. return sum;
  1725. }
  1726. // turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts
  1727. earcut.flatten = function (data) {
  1728. var dim = data[0][0].length,
  1729. result = { vertices: [], holes: [], dimensions: dim },
  1730. holeIndex = 0;
  1731. for (var i = 0; i < data.length; i++) {
  1732. for (var j = 0; j < data[i].length; j++) {
  1733. for (var d = 0; d < dim; d++) {
  1734. result.vertices.push(data[i][j][d]);
  1735. }
  1736. }
  1737. if (i > 0) {
  1738. holeIndex += data[i - 1].length;
  1739. result.holes.push(holeIndex);
  1740. }
  1741. }
  1742. return result;
  1743. };
  1744. var vs_s$2 = ['attribute vec4 a_Position;', 'void main() {', 'gl_Position = a_Position;', 'gl_PointSize = 30.0;', '}'].join('');
  1745. var fs_s$2 = ['precision mediump float;', 'uniform vec4 u_FragColor;', 'void main() {', 'gl_FragColor = u_FragColor;', '}'].join('');
  1746. function draw$4(gl, data, options) {
  1747. if (!data) {
  1748. return;
  1749. }
  1750. // gl.clearColor(0.0, 0.0, 0.0, 1.0);
  1751. gl.clear(gl.COLOR_BUFFER_BIT);
  1752. gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
  1753. var program = initShaders(gl, vs_s$2, fs_s$2);
  1754. gl.enable(gl.BLEND);
  1755. gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
  1756. var halfCanvasWidth = gl.canvas.width / 2;
  1757. var halfCanvasHeight = gl.canvas.height / 2;
  1758. // Bind the buffer object to target
  1759. gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
  1760. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.createBuffer());
  1761. var a_Position = gl.getAttribLocation(program, 'a_Position');
  1762. // Assign the buffer object to a_Position variable
  1763. gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, 0, 0);
  1764. // Enable the assignment to a_Position variable
  1765. gl.enableVertexAttribArray(a_Position);
  1766. var uFragColor = gl.getUniformLocation(program, 'u_FragColor');
  1767. var colored = getColorData(options.fillStyle || 'red');
  1768. gl.uniform4f(uFragColor, colored[0] / 255, colored[1] / 255, colored[2] / 255, colored[3] / 255);
  1769. gl.lineWidth(options.lineWidth || 1);
  1770. var verticesArr = [];
  1771. var trianglesArr = [];
  1772. var maxSize = 65536;
  1773. var indexOffset = 0;
  1774. for (var i = 0, len = data.length; i < len; i++) {
  1775. var flatten = earcut.flatten(data[i].geometry._coordinates || data[i].geometry.coordinates);
  1776. var vertices = flatten.vertices;
  1777. indexOffset = verticesArr.length / 2;
  1778. for (var j = 0; j < vertices.length; j += 2) {
  1779. vertices[j] = (vertices[j] - halfCanvasWidth) / halfCanvasWidth;
  1780. vertices[j + 1] = (halfCanvasHeight - vertices[j + 1]) / halfCanvasHeight;
  1781. }
  1782. if ((verticesArr.length + vertices.length) / 2 > maxSize) {
  1783. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(verticesArr), gl.STATIC_DRAW);
  1784. gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(trianglesArr), gl.STATIC_DRAW);
  1785. gl.drawElements(gl.TRIANGLES, trianglesArr.length, gl.UNSIGNED_SHORT, 0);
  1786. verticesArr.length = 0;
  1787. trianglesArr.length = 0;
  1788. indexOffset = 0;
  1789. }
  1790. for (var j = 0; j < vertices.length; j++) {
  1791. verticesArr.push(vertices[j]);
  1792. }
  1793. var triangles = earcut(vertices, flatten.holes, flatten.dimensions);
  1794. for (var j = 0; j < triangles.length; j++) {
  1795. trianglesArr.push(triangles[j] + indexOffset);
  1796. }
  1797. }
  1798. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(verticesArr), gl.STATIC_DRAW);
  1799. gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(trianglesArr), gl.STATIC_DRAW);
  1800. gl.drawElements(gl.TRIANGLES, trianglesArr.length, gl.UNSIGNED_SHORT, 0);
  1801. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  1802. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
  1803. }
  1804. var polygon = {
  1805. draw: draw$4
  1806. };
  1807. /**
  1808. * @author kyle / http://nikai.us/
  1809. */
  1810. var webglDrawSimple = {
  1811. draw: function draw(gl, dataSet, options) {
  1812. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  1813. if (data.length > 0) {
  1814. if (data[0].geometry.type == "LineString") {
  1815. line.draw(gl, data, options);
  1816. } else if (data[0].geometry.type == "Polygon" || data[0].geometry.type == "MultiPolygon") {
  1817. polygon.draw(gl, data, options);
  1818. } else {
  1819. point.draw(gl, data, options);
  1820. }
  1821. }
  1822. }
  1823. };
  1824. /**
  1825. * 根据弧线的坐标节点数组
  1826. */
  1827. function getCurvePoints(points, options) {
  1828. options = options || {};
  1829. var curvePoints = [];
  1830. for (var i = 0; i < points.length - 1; i++) {
  1831. var p = getCurveByTwoPoints(points[i], points[i + 1], options.count);
  1832. if (p && p.length > 0) {
  1833. curvePoints = curvePoints.concat(p);
  1834. }
  1835. }
  1836. return curvePoints;
  1837. }
  1838. /**
  1839. * 根据两点获取曲线坐标点数组
  1840. * @param Point 起点
  1841. * @param Point 终点
  1842. */
  1843. function getCurveByTwoPoints(obj1, obj2, count) {
  1844. if (!obj1 || !obj2) {
  1845. return null;
  1846. }
  1847. var B1 = function B1(x) {
  1848. return 1 - 2 * x + x * x;
  1849. };
  1850. var B2 = function B2(x) {
  1851. return 2 * x - 2 * x * x;
  1852. };
  1853. var B3 = function B3(x) {
  1854. return x * x;
  1855. };
  1856. var curveCoordinates = [];
  1857. var count = count || 40; // 曲线是由一些小的线段组成的,这个表示这个曲线所有到的折线的个数
  1858. var isFuture = false;
  1859. var t, h, h2, lat3, lng3, j, t2;
  1860. var LnArray = [];
  1861. var i = 0;
  1862. var inc = 0;
  1863. if (typeof obj2 == "undefined") {
  1864. if (typeof curveCoordinates != "undefined") {
  1865. curveCoordinates = [];
  1866. }
  1867. return;
  1868. }
  1869. var lat1 = parseFloat(obj1.lat);
  1870. var lat2 = parseFloat(obj2.lat);
  1871. var lng1 = parseFloat(obj1.lng);
  1872. var lng2 = parseFloat(obj2.lng);
  1873. // 计算曲线角度的方法
  1874. if (lng2 > lng1) {
  1875. if (parseFloat(lng2 - lng1) > 180) {
  1876. if (lng1 < 0) {
  1877. lng1 = parseFloat(180 + 180 + lng1);
  1878. lng2 = parseFloat(180 + 180 + lng2);
  1879. }
  1880. }
  1881. }
  1882. // 此时纠正了 lng1 lng2
  1883. j = 0;
  1884. t2 = 0;
  1885. // 纬度相同
  1886. if (lat2 == lat1) {
  1887. t = 0;
  1888. h = lng1 - lng2;
  1889. // 经度相同
  1890. } else if (lng2 == lng1) {
  1891. t = Math.PI / 2;
  1892. h = lat1 - lat2;
  1893. } else {
  1894. t = Math.atan((lat2 - lat1) / (lng2 - lng1));
  1895. h = (lat2 - lat1) / Math.sin(t);
  1896. }
  1897. if (t2 == 0) {
  1898. t2 = t + Math.PI / 5;
  1899. }
  1900. h2 = h / 2;
  1901. lng3 = h2 * Math.cos(t2) + lng1;
  1902. lat3 = h2 * Math.sin(t2) + lat1;
  1903. for (i = 0; i < count + 1; i++) {
  1904. var x = lng1 * B1(inc) + lng3 * B2(inc) + lng2 * B3(inc);
  1905. var y = lat1 * B1(inc) + lat3 * B2(inc) + lat2 * B3(inc);
  1906. var lng1_src = obj1.lng;
  1907. var lng2_src = obj2.lng;
  1908. curveCoordinates.push([lng1_src < 0 && lng2_src > 0 ? x - 360 : x, y]);
  1909. inc = inc + 1 / count;
  1910. }
  1911. return curveCoordinates;
  1912. }
  1913. var curve = {
  1914. getPoints: getCurvePoints
  1915. };
  1916. /*
  1917. FDEB algorithm implementation [www.win.tue.nl/~dholten/papers/forcebundles_eurovis.pdf].
  1918. Author: (github.com/upphiminn)
  1919. 2013
  1920. */
  1921. var ForceEdgeBundling = function ForceEdgeBundling() {
  1922. var data_nodes = {},
  1923. // {'nodeid':{'x':,'y':},..}
  1924. data_edges = [],
  1925. // [{'source':'nodeid1', 'target':'nodeid2'},..]
  1926. compatibility_list_for_edge = [],
  1927. subdivision_points_for_edge = [],
  1928. K = 0.1,
  1929. // global bundling constant controling edge stiffness
  1930. S_initial = 0.1,
  1931. // init. distance to move points
  1932. P_initial = 1,
  1933. // init. subdivision number
  1934. P_rate = 2,
  1935. // subdivision rate increase
  1936. C = 6,
  1937. // number of cycles to perform
  1938. I_initial = 70,
  1939. // init. number of iterations for cycle
  1940. I_rate = 0.6666667,
  1941. // rate at which iteration number decreases i.e. 2/3
  1942. compatibility_threshold = 0.6,
  1943. invers_quadratic_mode = false,
  1944. eps = 1e-8;
  1945. /*** Geometry Helper Methods ***/
  1946. function vector_dot_product(p, q) {
  1947. return p.x * q.x + p.y * q.y;
  1948. }
  1949. function edge_as_vector(P) {
  1950. return { 'x': data_nodes[P.target].x - data_nodes[P.source].x,
  1951. 'y': data_nodes[P.target].y - data_nodes[P.source].y };
  1952. }
  1953. function edge_length(e) {
  1954. return Math.sqrt(Math.pow(data_nodes[e.source].x - data_nodes[e.target].x, 2) + Math.pow(data_nodes[e.source].y - data_nodes[e.target].y, 2));
  1955. }
  1956. function custom_edge_length(e) {
  1957. return Math.sqrt(Math.pow(e.source.x - e.target.x, 2) + Math.pow(e.source.y - e.target.y, 2));
  1958. }
  1959. function edge_midpoint(e) {
  1960. var middle_x = (data_nodes[e.source].x + data_nodes[e.target].x) / 2.0;
  1961. var middle_y = (data_nodes[e.source].y + data_nodes[e.target].y) / 2.0;
  1962. return { 'x': middle_x, 'y': middle_y };
  1963. }
  1964. function compute_divided_edge_length(e_idx) {
  1965. var length = 0;
  1966. for (var i = 1; i < subdivision_points_for_edge[e_idx].length; i++) {
  1967. var segment_length = euclidean_distance(subdivision_points_for_edge[e_idx][i], subdivision_points_for_edge[e_idx][i - 1]);
  1968. length += segment_length;
  1969. }
  1970. return length;
  1971. }
  1972. function euclidean_distance(p, q) {
  1973. return Math.sqrt(Math.pow(p.x - q.x, 2) + Math.pow(p.y - q.y, 2));
  1974. }
  1975. function project_point_on_line(p, Q) {
  1976. var L = Math.sqrt((Q.target.x - Q.source.x) * (Q.target.x - Q.source.x) + (Q.target.y - Q.source.y) * (Q.target.y - Q.source.y));
  1977. var r = ((Q.source.y - p.y) * (Q.source.y - Q.target.y) - (Q.source.x - p.x) * (Q.target.x - Q.source.x)) / (L * L);
  1978. return { 'x': Q.source.x + r * (Q.target.x - Q.source.x), 'y': Q.source.y + r * (Q.target.y - Q.source.y) };
  1979. }
  1980. /*** ********************** ***/
  1981. /*** Initialization Methods ***/
  1982. function initialize_edge_subdivisions() {
  1983. for (var i = 0; i < data_edges.length; i++) {
  1984. if (P_initial == 1) subdivision_points_for_edge[i] = []; //0 subdivisions
  1985. else {
  1986. subdivision_points_for_edge[i] = [];
  1987. subdivision_points_for_edge[i].push(data_nodes[data_edges[i].source]);
  1988. subdivision_points_for_edge[i].push(data_nodes[data_edges[i].target]);
  1989. }
  1990. }
  1991. }
  1992. function initialize_compatibility_lists() {
  1993. for (var i = 0; i < data_edges.length; i++) {
  1994. compatibility_list_for_edge[i] = [];
  1995. } //0 compatible edges.
  1996. }
  1997. function filter_self_loops(edgelist) {
  1998. var filtered_edge_list = [];
  1999. for (var e = 0; e < edgelist.length; e++) {
  2000. if (data_nodes[edgelist[e].source].x != data_nodes[edgelist[e].target].x && data_nodes[edgelist[e].source].y != data_nodes[edgelist[e].target].y) {
  2001. //or smaller than eps
  2002. filtered_edge_list.push(edgelist[e]);
  2003. }
  2004. }
  2005. return filtered_edge_list;
  2006. }
  2007. /*** ********************** ***/
  2008. /*** Force Calculation Methods ***/
  2009. function apply_spring_force(e_idx, i, kP) {
  2010. var prev = subdivision_points_for_edge[e_idx][i - 1];
  2011. var next = subdivision_points_for_edge[e_idx][i + 1];
  2012. var crnt = subdivision_points_for_edge[e_idx][i];
  2013. var x = prev.x - crnt.x + next.x - crnt.x;
  2014. var y = prev.y - crnt.y + next.y - crnt.y;
  2015. x *= kP;
  2016. y *= kP;
  2017. return { 'x': x, 'y': y };
  2018. }
  2019. function apply_electrostatic_force(e_idx, i, S) {
  2020. var sum_of_forces = { 'x': 0, 'y': 0 };
  2021. var compatible_edges_list = compatibility_list_for_edge[e_idx];
  2022. for (var oe = 0; oe < compatible_edges_list.length; oe++) {
  2023. var force = { 'x': subdivision_points_for_edge[compatible_edges_list[oe]][i].x - subdivision_points_for_edge[e_idx][i].x,
  2024. 'y': subdivision_points_for_edge[compatible_edges_list[oe]][i].y - subdivision_points_for_edge[e_idx][i].y };
  2025. if (Math.abs(force.x) > eps || Math.abs(force.y) > eps) {
  2026. var diff = 1 / Math.pow(custom_edge_length({ 'source': subdivision_points_for_edge[compatible_edges_list[oe]][i],
  2027. 'target': subdivision_points_for_edge[e_idx][i] }), 1);
  2028. sum_of_forces.x += force.x * diff;
  2029. sum_of_forces.y += force.y * diff;
  2030. }
  2031. }
  2032. return sum_of_forces;
  2033. }
  2034. function apply_resulting_forces_on_subdivision_points(e_idx, P, S) {
  2035. var kP = K / (edge_length(data_edges[e_idx]) * (P + 1)); // kP=K/|P|(number of segments), where |P| is the initial length of edge P.
  2036. // (length * (num of sub division pts - 1))
  2037. var resulting_forces_for_subdivision_points = [{ 'x': 0, 'y': 0 }];
  2038. for (var i = 1; i < P + 1; i++) {
  2039. // exclude initial end points of the edge 0 and P+1
  2040. var resulting_force = { 'x': 0, 'y': 0 };
  2041. var spring_force = apply_spring_force(e_idx, i, kP);
  2042. var electrostatic_force = apply_electrostatic_force(e_idx, i, S);
  2043. resulting_force.x = S * (spring_force.x + electrostatic_force.x);
  2044. resulting_force.y = S * (spring_force.y + electrostatic_force.y);
  2045. resulting_forces_for_subdivision_points.push(resulting_force);
  2046. }
  2047. resulting_forces_for_subdivision_points.push({ 'x': 0, 'y': 0 });
  2048. return resulting_forces_for_subdivision_points;
  2049. }
  2050. /*** ********************** ***/
  2051. /*** Edge Division Calculation Methods ***/
  2052. function update_edge_divisions(P) {
  2053. for (var e_idx = 0; e_idx < data_edges.length; e_idx++) {
  2054. if (P == 1) {
  2055. subdivision_points_for_edge[e_idx].push(data_nodes[data_edges[e_idx].source]); // source
  2056. subdivision_points_for_edge[e_idx].push(edge_midpoint(data_edges[e_idx])); // mid point
  2057. subdivision_points_for_edge[e_idx].push(data_nodes[data_edges[e_idx].target]); // target
  2058. } else {
  2059. var divided_edge_length = compute_divided_edge_length(e_idx);
  2060. var segment_length = divided_edge_length / (P + 1);
  2061. var current_segment_length = segment_length;
  2062. var new_subdivision_points = [];
  2063. new_subdivision_points.push(data_nodes[data_edges[e_idx].source]); //source
  2064. for (var i = 1; i < subdivision_points_for_edge[e_idx].length; i++) {
  2065. var old_segment_length = euclidean_distance(subdivision_points_for_edge[e_idx][i], subdivision_points_for_edge[e_idx][i - 1]);
  2066. while (old_segment_length > current_segment_length) {
  2067. var percent_position = current_segment_length / old_segment_length;
  2068. var new_subdivision_point_x = subdivision_points_for_edge[e_idx][i - 1].x;
  2069. var new_subdivision_point_y = subdivision_points_for_edge[e_idx][i - 1].y;
  2070. new_subdivision_point_x += percent_position * (subdivision_points_for_edge[e_idx][i].x - subdivision_points_for_edge[e_idx][i - 1].x);
  2071. new_subdivision_point_y += percent_position * (subdivision_points_for_edge[e_idx][i].y - subdivision_points_for_edge[e_idx][i - 1].y);
  2072. new_subdivision_points.push({ 'x': new_subdivision_point_x,
  2073. 'y': new_subdivision_point_y });
  2074. old_segment_length -= current_segment_length;
  2075. current_segment_length = segment_length;
  2076. }
  2077. current_segment_length -= old_segment_length;
  2078. }
  2079. new_subdivision_points.push(data_nodes[data_edges[e_idx].target]); //target
  2080. subdivision_points_for_edge[e_idx] = new_subdivision_points;
  2081. }
  2082. }
  2083. }
  2084. /*** ********************** ***/
  2085. /*** Edge compatibility measures ***/
  2086. function angle_compatibility(P, Q) {
  2087. var result = Math.abs(vector_dot_product(edge_as_vector(P), edge_as_vector(Q)) / (edge_length(P) * edge_length(Q)));
  2088. return result;
  2089. }
  2090. function scale_compatibility(P, Q) {
  2091. var lavg = (edge_length(P) + edge_length(Q)) / 2.0;
  2092. var result = 2.0 / (lavg / Math.min(edge_length(P), edge_length(Q)) + Math.max(edge_length(P), edge_length(Q)) / lavg);
  2093. return result;
  2094. }
  2095. function position_compatibility(P, Q) {
  2096. var lavg = (edge_length(P) + edge_length(Q)) / 2.0;
  2097. var midP = { 'x': (data_nodes[P.source].x + data_nodes[P.target].x) / 2.0,
  2098. 'y': (data_nodes[P.source].y + data_nodes[P.target].y) / 2.0 };
  2099. var midQ = { 'x': (data_nodes[Q.source].x + data_nodes[Q.target].x) / 2.0,
  2100. 'y': (data_nodes[Q.source].y + data_nodes[Q.target].y) / 2.0 };
  2101. var result = lavg / (lavg + euclidean_distance(midP, midQ));
  2102. return result;
  2103. }
  2104. function edge_visibility(P, Q) {
  2105. var I0 = project_point_on_line(data_nodes[Q.source], { 'source': data_nodes[P.source],
  2106. 'target': data_nodes[P.target] });
  2107. var I1 = project_point_on_line(data_nodes[Q.target], { 'source': data_nodes[P.source],
  2108. 'target': data_nodes[P.target] }); //send acutal edge points positions
  2109. var midI = { 'x': (I0.x + I1.x) / 2.0,
  2110. 'y': (I0.y + I1.y) / 2.0 };
  2111. var midP = { 'x': (data_nodes[P.source].x + data_nodes[P.target].x) / 2.0,
  2112. 'y': (data_nodes[P.source].y + data_nodes[P.target].y) / 2.0 };
  2113. var result = Math.max(0, 1 - 2 * euclidean_distance(midP, midI) / euclidean_distance(I0, I1));
  2114. return result;
  2115. }
  2116. function visibility_compatibility(P, Q) {
  2117. return Math.min(edge_visibility(P, Q), edge_visibility(Q, P));
  2118. }
  2119. function compatibility_score(P, Q) {
  2120. var result = angle_compatibility(P, Q) * scale_compatibility(P, Q) * position_compatibility(P, Q) * visibility_compatibility(P, Q);
  2121. return result;
  2122. }
  2123. function are_compatible(P, Q) {
  2124. // console.log('compatibility ' + P.source +' - '+ P.target + ' and ' + Q.source +' '+ Q.target);
  2125. return compatibility_score(P, Q) >= compatibility_threshold;
  2126. }
  2127. function compute_compatibility_lists() {
  2128. for (var e = 0; e < data_edges.length - 1; e++) {
  2129. for (var oe = e + 1; oe < data_edges.length; oe++) {
  2130. // don't want any duplicates
  2131. if (e == oe) continue;else {
  2132. if (are_compatible(data_edges[e], data_edges[oe])) {
  2133. compatibility_list_for_edge[e].push(oe);
  2134. compatibility_list_for_edge[oe].push(e);
  2135. }
  2136. }
  2137. }
  2138. }
  2139. }
  2140. /*** ************************ ***/
  2141. /*** Main Bundling Loop Methods ***/
  2142. var forcebundle = function forcebundle() {
  2143. var S = S_initial;
  2144. var I = I_initial;
  2145. var P = P_initial;
  2146. initialize_edge_subdivisions();
  2147. initialize_compatibility_lists();
  2148. update_edge_divisions(P);
  2149. compute_compatibility_lists();
  2150. for (var cycle = 0; cycle < C; cycle++) {
  2151. for (var iteration = 0; iteration < I; iteration++) {
  2152. var forces = [];
  2153. for (var edge = 0; edge < data_edges.length; edge++) {
  2154. forces[edge] = apply_resulting_forces_on_subdivision_points(edge, P, S);
  2155. }
  2156. for (var e = 0; e < data_edges.length; e++) {
  2157. for (var i = 0; i < P + 1; i++) {
  2158. subdivision_points_for_edge[e][i].x += forces[e][i].x;
  2159. subdivision_points_for_edge[e][i].y += forces[e][i].y;
  2160. }
  2161. }
  2162. }
  2163. //prepare for next cycle
  2164. S = S / 2;
  2165. P = P * 2;
  2166. I = I_rate * I;
  2167. update_edge_divisions(P);
  2168. // console.log('C' + cycle);
  2169. // console.log('P' + P);
  2170. // console.log('S' + S);
  2171. }
  2172. return subdivision_points_for_edge;
  2173. };
  2174. /*** ************************ ***/
  2175. /*** Getters/Setters Methods ***/
  2176. forcebundle.nodes = function (nl) {
  2177. if (arguments.length == 0) {
  2178. return data_nodes;
  2179. } else {
  2180. data_nodes = nl;
  2181. }
  2182. return forcebundle;
  2183. };
  2184. forcebundle.edges = function (ll) {
  2185. if (arguments.length == 0) {
  2186. return data_edges;
  2187. } else {
  2188. data_edges = filter_self_loops(ll); //remove edges to from to the same point
  2189. }
  2190. return forcebundle;
  2191. };
  2192. forcebundle.bundling_stiffness = function (k) {
  2193. if (arguments.length == 0) {
  2194. return K;
  2195. } else {
  2196. K = k;
  2197. }
  2198. return forcebundle;
  2199. };
  2200. forcebundle.step_size = function (step) {
  2201. if (arguments.length == 0) {
  2202. return S_initial;
  2203. } else {
  2204. S_initial = step;
  2205. }
  2206. return forcebundle;
  2207. };
  2208. forcebundle.cycles = function (c) {
  2209. if (arguments.length == 0) {
  2210. return C;
  2211. } else {
  2212. C = c;
  2213. }
  2214. return forcebundle;
  2215. };
  2216. forcebundle.iterations = function (i) {
  2217. if (arguments.length == 0) {
  2218. return I_initial;
  2219. } else {
  2220. I_initial = i;
  2221. }
  2222. return forcebundle;
  2223. };
  2224. forcebundle.iterations_rate = function (i) {
  2225. if (arguments.length == 0) {
  2226. return I_rate;
  2227. } else {
  2228. I_rate = i;
  2229. }
  2230. return forcebundle;
  2231. };
  2232. forcebundle.subdivision_points_seed = function (p) {
  2233. if (arguments.length == 0) {
  2234. return P;
  2235. } else {
  2236. P = p;
  2237. }
  2238. return forcebundle;
  2239. };
  2240. forcebundle.subdivision_rate = function (r) {
  2241. if (arguments.length == 0) {
  2242. return P_rate;
  2243. } else {
  2244. P_rate = r;
  2245. }
  2246. return forcebundle;
  2247. };
  2248. forcebundle.compatbility_threshold = function (t) {
  2249. if (arguments.length == 0) {
  2250. return compatbility_threshold;
  2251. } else {
  2252. compatibility_threshold = t;
  2253. }
  2254. return forcebundle;
  2255. };
  2256. /*** ************************ ***/
  2257. return forcebundle;
  2258. };
  2259. /**
  2260. * @author kyle / http://nikai.us/
  2261. */
  2262. /**
  2263. * Category
  2264. * @param {Object} splitList:
  2265. * {
  2266. * other: 1,
  2267. * 1: 2,
  2268. * 2: 3,
  2269. * 3: 4,
  2270. * 4: 5,
  2271. * 5: 6,
  2272. * 6: 7
  2273. * }
  2274. */
  2275. function Category(splitList) {
  2276. this.splitList = splitList || {
  2277. other: 1
  2278. };
  2279. }
  2280. Category.prototype.get = function (count) {
  2281. var splitList = this.splitList;
  2282. var value = splitList['other'];
  2283. for (var i in splitList) {
  2284. if (count == i) {
  2285. value = splitList[i];
  2286. break;
  2287. }
  2288. }
  2289. return value;
  2290. };
  2291. /**
  2292. * 根据DataSet自动生成对应的splitList
  2293. */
  2294. Category.prototype.generateByDataSet = function (dataSet, color) {
  2295. var colors = color || ['rgba(255, 255, 0, 0.8)', 'rgba(253, 98, 104, 0.8)', 'rgba(255, 146, 149, 0.8)', 'rgba(255, 241, 193, 0.8)', 'rgba(110, 176, 253, 0.8)', 'rgba(52, 139, 251, 0.8)', 'rgba(17, 102, 252, 0.8)'];
  2296. var data = dataSet.get();
  2297. this.splitList = {};
  2298. var count = 0;
  2299. for (var i = 0; i < data.length; i++) {
  2300. if (this.splitList[data[i].count] === undefined) {
  2301. this.splitList[data[i].count] = colors[count];
  2302. count++;
  2303. }
  2304. if (count >= colors.length - 1) {
  2305. break;
  2306. }
  2307. }
  2308. this.splitList['other'] = colors[colors.length - 1];
  2309. };
  2310. Category.prototype.getLegend = function (options) {
  2311. var splitList = this.splitList;
  2312. var container = document.createElement('div');
  2313. container.style.cssText = "background:#fff; padding: 5px; border: 1px solid #ccc;";
  2314. var html = '';
  2315. for (var key in splitList) {
  2316. html += '<div style="line-height: 19px;" value="' + key + '"><span style="vertical-align: -2px; display: inline-block; width: 30px;height: 19px;background:' + splitList[key] + ';"></span><span style="margin-left: 3px;">' + key + '<span></div>';
  2317. }
  2318. container.innerHTML = html;
  2319. return container;
  2320. };
  2321. /**
  2322. * @author kyle / http://nikai.us/
  2323. */
  2324. /**
  2325. * Choropleth
  2326. * @param {Object} splitList:
  2327. * [
  2328. * {
  2329. * start: 0,
  2330. * end: 2,
  2331. * value: randomColor()
  2332. * },{
  2333. * start: 2,
  2334. * end: 4,
  2335. * value: randomColor()
  2336. * },{
  2337. * start: 4,
  2338. * value: randomColor()
  2339. * }
  2340. * ];
  2341. *
  2342. */
  2343. function Choropleth(splitList) {
  2344. this.splitList = splitList || [{
  2345. start: 0,
  2346. value: 'red'
  2347. }];
  2348. }
  2349. Choropleth.prototype.get = function (count) {
  2350. var splitList = this.splitList;
  2351. var value = false;
  2352. for (var i = 0; i < splitList.length; i++) {
  2353. if ((splitList[i].start === undefined || splitList[i].start !== undefined && count >= splitList[i].start) && (splitList[i].end === undefined || splitList[i].end !== undefined && count < splitList[i].end)) {
  2354. value = splitList[i].value;
  2355. break;
  2356. }
  2357. }
  2358. return value;
  2359. };
  2360. /**
  2361. * 根据DataSet自动生成对应的splitList
  2362. */
  2363. Choropleth.prototype.generateByDataSet = function (dataSet) {
  2364. var min = dataSet.getMin('count');
  2365. var max = dataSet.getMax('count');
  2366. this.generateByMinMax(min, max);
  2367. };
  2368. /**
  2369. * 根据DataSet自动生成对应的splitList
  2370. */
  2371. Choropleth.prototype.generateByMinMax = function (min, max) {
  2372. var colors = ['rgba(255, 255, 0, 0.8)', 'rgba(253, 98, 104, 0.8)', 'rgba(255, 146, 149, 0.8)', 'rgba(255, 241, 193, 0.8)', 'rgba(110, 176, 253, 0.8)', 'rgba(52, 139, 251, 0.8)', 'rgba(17, 102, 252, 0.8)'];
  2373. var splitNum = Number((max - min) / 7);
  2374. // console.log(splitNum)
  2375. max = Number(max);
  2376. var index = Number(min);
  2377. this.splitList = [];
  2378. var count = 0;
  2379. while (index < max) {
  2380. this.splitList.push({
  2381. start: index,
  2382. end: index + splitNum,
  2383. value: colors[count]
  2384. });
  2385. count++;
  2386. index += splitNum;
  2387. // console.log(index, max)
  2388. }
  2389. // console.log('splitNum')
  2390. };
  2391. Choropleth.prototype.getLegend = function (options) {
  2392. var splitList = this.splitList;
  2393. };
  2394. /**
  2395. * @author Mofei<http://www.zhuwenlong.com>
  2396. */
  2397. var MapHelper = function () {
  2398. function MapHelper(id, type, opt) {
  2399. classCallCheck(this, MapHelper);
  2400. if (!id || !type) {
  2401. console.warn('id 和 type 为必填项');
  2402. return false;
  2403. }
  2404. if (type == 'baidu') {
  2405. if (!BMap) {
  2406. console.warn('请先引入百度地图JS API');
  2407. return false;
  2408. }
  2409. } else {
  2410. console.warn('暂不支持你的地图类型');
  2411. }
  2412. this.type = type;
  2413. var center = opt && opt.center ? opt.center : [106.962497, 38.208726];
  2414. var zoom = opt && opt.zoom ? opt.zoom : 5;
  2415. var map = this.map = new BMap.Map(id, {
  2416. enableMapClick: false
  2417. });
  2418. map.centerAndZoom(new BMap.Point(center[0], center[1]), zoom);
  2419. map.enableScrollWheelZoom(true);
  2420. map.setMapStyle({
  2421. style: 'light'
  2422. });
  2423. }
  2424. createClass(MapHelper, [{
  2425. key: 'addLayer',
  2426. value: function addLayer(datas, options) {
  2427. if (this.type == 'baidu') {
  2428. return new mapv.baiduMapLayer(this.map, dataSet, options);
  2429. }
  2430. }
  2431. }, {
  2432. key: 'getMap',
  2433. value: function getMap() {
  2434. return this.map;
  2435. }
  2436. }]);
  2437. return MapHelper;
  2438. }();
  2439. /**
  2440. * 一直覆盖在当前地图视野的Canvas对象
  2441. *
  2442. * @author nikai (@胖嘟嘟的骨头, nikai@baidu.com)
  2443. *
  2444. * @param
  2445. * {
  2446. * map 地图实例对象
  2447. * }
  2448. */
  2449. function CanvasLayer(options) {
  2450. this.options = options || {};
  2451. this.paneName = this.options.paneName || 'mapPane';
  2452. this.context = this.options.context || '2d';
  2453. this.zIndex = this.options.zIndex || 0;
  2454. this.mixBlendMode = this.options.mixBlendMode || null;
  2455. this.enableMassClear = this.options.enableMassClear;
  2456. this._map = options.map;
  2457. this._lastDrawTime = null;
  2458. this.show();
  2459. }
  2460. var global$3 = typeof window === 'undefined' ? {} : window;
  2461. var BMap$1 = global$3.BMap || global$3.BMapGL;
  2462. if (BMap$1) {
  2463. CanvasLayer.prototype = new BMap$1.Overlay();
  2464. CanvasLayer.prototype.initialize = function (map) {
  2465. this._map = map;
  2466. var canvas = this.canvas = document.createElement("canvas");
  2467. canvas.style.cssText = "position:absolute;" + "left:0;" + "top:0;" + "z-index:" + this.zIndex + ";user-select:none;";
  2468. canvas.style.mixBlendMode = this.mixBlendMode;
  2469. this.adjustSize();
  2470. var pane = map.getPanes()[this.paneName];
  2471. if (!pane) {
  2472. pane = map.getPanes().floatShadow;
  2473. }
  2474. pane.appendChild(canvas);
  2475. var that = this;
  2476. map.addEventListener('resize', function () {
  2477. that.adjustSize();
  2478. that._draw();
  2479. });
  2480. map.addEventListener('update', function () {
  2481. that._draw();
  2482. });
  2483. /*
  2484. map.addEventListener('moving', function() {
  2485. that._draw();
  2486. });
  2487. */
  2488. if (this.options.updateImmediate) {
  2489. setTimeout(function () {
  2490. that._draw();
  2491. }, 100);
  2492. }
  2493. return this.canvas;
  2494. };
  2495. CanvasLayer.prototype.adjustSize = function () {
  2496. var size = this._map.getSize();
  2497. var canvas = this.canvas;
  2498. var devicePixelRatio = this.devicePixelRatio = global$3.devicePixelRatio || 1;
  2499. canvas.width = size.width * devicePixelRatio;
  2500. canvas.height = size.height * devicePixelRatio;
  2501. if (this.context == '2d') {
  2502. canvas.getContext(this.context).scale(devicePixelRatio, devicePixelRatio);
  2503. }
  2504. canvas.style.width = size.width + "px";
  2505. canvas.style.height = size.height + "px";
  2506. };
  2507. CanvasLayer.prototype.draw = function () {
  2508. var self = this;
  2509. if (this.options.updateImmediate) {
  2510. self._draw();
  2511. } else {
  2512. clearTimeout(self.timeoutID);
  2513. self.timeoutID = setTimeout(function () {
  2514. self._draw();
  2515. }, 15);
  2516. }
  2517. };
  2518. CanvasLayer.prototype._draw = function () {
  2519. var map = this._map;
  2520. var size = map.getSize();
  2521. var center = map.getCenter();
  2522. if (center) {
  2523. var pixel = map.pointToOverlayPixel(center);
  2524. this.canvas.style.left = pixel.x - size.width / 2 + 'px';
  2525. this.canvas.style.top = pixel.y - size.height / 2 + 'px';
  2526. this.dispatchEvent('draw');
  2527. this.options.update && this.options.update.call(this);
  2528. }
  2529. };
  2530. CanvasLayer.prototype.getContainer = function () {
  2531. return this.canvas;
  2532. };
  2533. CanvasLayer.prototype.show = function () {
  2534. if (!this.canvas) {
  2535. this._map.addOverlay(this);
  2536. }
  2537. this.canvas.style.display = "block";
  2538. };
  2539. CanvasLayer.prototype.hide = function () {
  2540. this.canvas.style.display = "none";
  2541. //this._map.removeOverlay(this);
  2542. };
  2543. CanvasLayer.prototype.setZIndex = function (zIndex) {
  2544. this.zIndex = zIndex;
  2545. this.canvas.style.zIndex = this.zIndex;
  2546. };
  2547. CanvasLayer.prototype.getZIndex = function () {
  2548. return this.zIndex;
  2549. };
  2550. }
  2551. /**
  2552. * Tween.js - Licensed under the MIT license
  2553. * https://github.com/tweenjs/tween.js
  2554. * ----------------------------------------------
  2555. *
  2556. * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
  2557. * Thank you all, you're awesome!
  2558. */
  2559. var TWEEN = TWEEN || function () {
  2560. var _tweens = [];
  2561. return {
  2562. getAll: function getAll() {
  2563. return _tweens;
  2564. },
  2565. removeAll: function removeAll() {
  2566. _tweens = [];
  2567. },
  2568. add: function add(tween) {
  2569. _tweens.push(tween);
  2570. },
  2571. remove: function remove(tween) {
  2572. var i = _tweens.indexOf(tween);
  2573. if (i !== -1) {
  2574. _tweens.splice(i, 1);
  2575. }
  2576. },
  2577. update: function update(time, preserve) {
  2578. if (_tweens.length === 0) {
  2579. return false;
  2580. }
  2581. var i = 0;
  2582. time = time !== undefined ? time : TWEEN.now();
  2583. while (i < _tweens.length) {
  2584. if (_tweens[i].update(time) || preserve) {
  2585. i++;
  2586. } else {
  2587. _tweens.splice(i, 1);
  2588. }
  2589. }
  2590. return true;
  2591. }
  2592. };
  2593. }();
  2594. // Include a performance.now polyfill.
  2595. // In node.js, use process.hrtime.
  2596. if (typeof window === 'undefined' && typeof process !== 'undefined') {
  2597. TWEEN.now = function () {
  2598. var time = process.hrtime();
  2599. // Convert [seconds, nanoseconds] to milliseconds.
  2600. return time[0] * 1000 + time[1] / 1000000;
  2601. };
  2602. }
  2603. // In a browser, use window.performance.now if it is available.
  2604. else if (typeof window !== 'undefined' && window.performance !== undefined && window.performance.now !== undefined) {
  2605. // This must be bound, because directly assigning this function
  2606. // leads to an invocation exception in Chrome.
  2607. TWEEN.now = window.performance.now.bind(window.performance);
  2608. }
  2609. // Use Date.now if it is available.
  2610. else if (Date.now !== undefined) {
  2611. TWEEN.now = Date.now;
  2612. }
  2613. // Otherwise, use 'new Date().getTime()'.
  2614. else {
  2615. TWEEN.now = function () {
  2616. return new Date().getTime();
  2617. };
  2618. }
  2619. TWEEN.Tween = function (object) {
  2620. var _object = object;
  2621. var _valuesStart = {};
  2622. var _valuesEnd = {};
  2623. var _valuesStartRepeat = {};
  2624. var _duration = 1000;
  2625. var _repeat = 0;
  2626. var _repeatDelayTime;
  2627. var _yoyo = false;
  2628. var _isPlaying = false;
  2629. var _reversed = false;
  2630. var _delayTime = 0;
  2631. var _startTime = null;
  2632. var _easingFunction = TWEEN.Easing.Linear.None;
  2633. var _interpolationFunction = TWEEN.Interpolation.Linear;
  2634. var _chainedTweens = [];
  2635. var _onStartCallback = null;
  2636. var _onStartCallbackFired = false;
  2637. var _onUpdateCallback = null;
  2638. var _onCompleteCallback = null;
  2639. var _onStopCallback = null;
  2640. this.to = function (properties, duration) {
  2641. _valuesEnd = properties;
  2642. if (duration !== undefined) {
  2643. _duration = duration;
  2644. }
  2645. return this;
  2646. };
  2647. this.start = function (time) {
  2648. TWEEN.add(this);
  2649. _isPlaying = true;
  2650. _onStartCallbackFired = false;
  2651. _startTime = time !== undefined ? time : TWEEN.now();
  2652. _startTime += _delayTime;
  2653. for (var property in _valuesEnd) {
  2654. // Check if an Array was provided as property value
  2655. if (_valuesEnd[property] instanceof Array) {
  2656. if (_valuesEnd[property].length === 0) {
  2657. continue;
  2658. }
  2659. // Create a local copy of the Array with the start value at the front
  2660. _valuesEnd[property] = [_object[property]].concat(_valuesEnd[property]);
  2661. }
  2662. // If `to()` specifies a property that doesn't exist in the source object,
  2663. // we should not set that property in the object
  2664. if (_object[property] === undefined) {
  2665. continue;
  2666. }
  2667. // Save the starting value.
  2668. _valuesStart[property] = _object[property];
  2669. if (_valuesStart[property] instanceof Array === false) {
  2670. _valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings
  2671. }
  2672. _valuesStartRepeat[property] = _valuesStart[property] || 0;
  2673. }
  2674. return this;
  2675. };
  2676. this.stop = function () {
  2677. if (!_isPlaying) {
  2678. return this;
  2679. }
  2680. TWEEN.remove(this);
  2681. _isPlaying = false;
  2682. if (_onStopCallback !== null) {
  2683. _onStopCallback.call(_object, _object);
  2684. }
  2685. this.stopChainedTweens();
  2686. return this;
  2687. };
  2688. this.end = function () {
  2689. this.update(_startTime + _duration);
  2690. return this;
  2691. };
  2692. this.stopChainedTweens = function () {
  2693. for (var i = 0, numChainedTweens = _chainedTweens.length; i < numChainedTweens; i++) {
  2694. _chainedTweens[i].stop();
  2695. }
  2696. };
  2697. this.delay = function (amount) {
  2698. _delayTime = amount;
  2699. return this;
  2700. };
  2701. this.repeat = function (times) {
  2702. _repeat = times;
  2703. return this;
  2704. };
  2705. this.repeatDelay = function (amount) {
  2706. _repeatDelayTime = amount;
  2707. return this;
  2708. };
  2709. this.yoyo = function (yoyo) {
  2710. _yoyo = yoyo;
  2711. return this;
  2712. };
  2713. this.easing = function (easing) {
  2714. _easingFunction = easing;
  2715. return this;
  2716. };
  2717. this.interpolation = function (interpolation) {
  2718. _interpolationFunction = interpolation;
  2719. return this;
  2720. };
  2721. this.chain = function () {
  2722. _chainedTweens = arguments;
  2723. return this;
  2724. };
  2725. this.onStart = function (callback) {
  2726. _onStartCallback = callback;
  2727. return this;
  2728. };
  2729. this.onUpdate = function (callback) {
  2730. _onUpdateCallback = callback;
  2731. return this;
  2732. };
  2733. this.onComplete = function (callback) {
  2734. _onCompleteCallback = callback;
  2735. return this;
  2736. };
  2737. this.onStop = function (callback) {
  2738. _onStopCallback = callback;
  2739. return this;
  2740. };
  2741. this.update = function (time) {
  2742. var property;
  2743. var elapsed;
  2744. var value;
  2745. if (time < _startTime) {
  2746. return true;
  2747. }
  2748. if (_onStartCallbackFired === false) {
  2749. if (_onStartCallback !== null) {
  2750. _onStartCallback.call(_object, _object);
  2751. }
  2752. _onStartCallbackFired = true;
  2753. }
  2754. elapsed = (time - _startTime) / _duration;
  2755. elapsed = elapsed > 1 ? 1 : elapsed;
  2756. value = _easingFunction(elapsed);
  2757. for (property in _valuesEnd) {
  2758. // Don't update properties that do not exist in the source object
  2759. if (_valuesStart[property] === undefined) {
  2760. continue;
  2761. }
  2762. var start = _valuesStart[property] || 0;
  2763. var end = _valuesEnd[property];
  2764. if (end instanceof Array) {
  2765. _object[property] = _interpolationFunction(end, value);
  2766. } else {
  2767. // Parses relative end values with start as base (e.g.: +10, -3)
  2768. if (typeof end === 'string') {
  2769. if (end.charAt(0) === '+' || end.charAt(0) === '-') {
  2770. end = start + parseFloat(end);
  2771. } else {
  2772. end = parseFloat(end);
  2773. }
  2774. }
  2775. // Protect against non numeric properties.
  2776. if (typeof end === 'number') {
  2777. _object[property] = start + (end - start) * value;
  2778. }
  2779. }
  2780. }
  2781. if (_onUpdateCallback !== null) {
  2782. _onUpdateCallback.call(_object, value);
  2783. }
  2784. if (elapsed === 1) {
  2785. if (_repeat > 0) {
  2786. if (isFinite(_repeat)) {
  2787. _repeat--;
  2788. }
  2789. // Reassign starting values, restart by making startTime = now
  2790. for (property in _valuesStartRepeat) {
  2791. if (typeof _valuesEnd[property] === 'string') {
  2792. _valuesStartRepeat[property] = _valuesStartRepeat[property] + parseFloat(_valuesEnd[property]);
  2793. }
  2794. if (_yoyo) {
  2795. var tmp = _valuesStartRepeat[property];
  2796. _valuesStartRepeat[property] = _valuesEnd[property];
  2797. _valuesEnd[property] = tmp;
  2798. }
  2799. _valuesStart[property] = _valuesStartRepeat[property];
  2800. }
  2801. if (_yoyo) {
  2802. _reversed = !_reversed;
  2803. }
  2804. if (_repeatDelayTime !== undefined) {
  2805. _startTime = time + _repeatDelayTime;
  2806. } else {
  2807. _startTime = time + _delayTime;
  2808. }
  2809. return true;
  2810. } else {
  2811. if (_onCompleteCallback !== null) {
  2812. _onCompleteCallback.call(_object, _object);
  2813. }
  2814. for (var i = 0, numChainedTweens = _chainedTweens.length; i < numChainedTweens; i++) {
  2815. // Make the chained tweens start exactly at the time they should,
  2816. // even if the `update()` method was called way past the duration of the tween
  2817. _chainedTweens[i].start(_startTime + _duration);
  2818. }
  2819. return false;
  2820. }
  2821. }
  2822. return true;
  2823. };
  2824. };
  2825. TWEEN.Easing = {
  2826. Linear: {
  2827. None: function None(k) {
  2828. return k;
  2829. }
  2830. },
  2831. Quadratic: {
  2832. In: function In(k) {
  2833. return k * k;
  2834. },
  2835. Out: function Out(k) {
  2836. return k * (2 - k);
  2837. },
  2838. InOut: function InOut(k) {
  2839. if ((k *= 2) < 1) {
  2840. return 0.5 * k * k;
  2841. }
  2842. return -0.5 * (--k * (k - 2) - 1);
  2843. }
  2844. },
  2845. Cubic: {
  2846. In: function In(k) {
  2847. return k * k * k;
  2848. },
  2849. Out: function Out(k) {
  2850. return --k * k * k + 1;
  2851. },
  2852. InOut: function InOut(k) {
  2853. if ((k *= 2) < 1) {
  2854. return 0.5 * k * k * k;
  2855. }
  2856. return 0.5 * ((k -= 2) * k * k + 2);
  2857. }
  2858. },
  2859. Quartic: {
  2860. In: function In(k) {
  2861. return k * k * k * k;
  2862. },
  2863. Out: function Out(k) {
  2864. return 1 - --k * k * k * k;
  2865. },
  2866. InOut: function InOut(k) {
  2867. if ((k *= 2) < 1) {
  2868. return 0.5 * k * k * k * k;
  2869. }
  2870. return -0.5 * ((k -= 2) * k * k * k - 2);
  2871. }
  2872. },
  2873. Quintic: {
  2874. In: function In(k) {
  2875. return k * k * k * k * k;
  2876. },
  2877. Out: function Out(k) {
  2878. return --k * k * k * k * k + 1;
  2879. },
  2880. InOut: function InOut(k) {
  2881. if ((k *= 2) < 1) {
  2882. return 0.5 * k * k * k * k * k;
  2883. }
  2884. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  2885. }
  2886. },
  2887. Sinusoidal: {
  2888. In: function In(k) {
  2889. return 1 - Math.cos(k * Math.PI / 2);
  2890. },
  2891. Out: function Out(k) {
  2892. return Math.sin(k * Math.PI / 2);
  2893. },
  2894. InOut: function InOut(k) {
  2895. return 0.5 * (1 - Math.cos(Math.PI * k));
  2896. }
  2897. },
  2898. Exponential: {
  2899. In: function In(k) {
  2900. return k === 0 ? 0 : Math.pow(1024, k - 1);
  2901. },
  2902. Out: function Out(k) {
  2903. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  2904. },
  2905. InOut: function InOut(k) {
  2906. if (k === 0) {
  2907. return 0;
  2908. }
  2909. if (k === 1) {
  2910. return 1;
  2911. }
  2912. if ((k *= 2) < 1) {
  2913. return 0.5 * Math.pow(1024, k - 1);
  2914. }
  2915. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  2916. }
  2917. },
  2918. Circular: {
  2919. In: function In(k) {
  2920. return 1 - Math.sqrt(1 - k * k);
  2921. },
  2922. Out: function Out(k) {
  2923. return Math.sqrt(1 - --k * k);
  2924. },
  2925. InOut: function InOut(k) {
  2926. if ((k *= 2) < 1) {
  2927. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  2928. }
  2929. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  2930. }
  2931. },
  2932. Elastic: {
  2933. In: function In(k) {
  2934. if (k === 0) {
  2935. return 0;
  2936. }
  2937. if (k === 1) {
  2938. return 1;
  2939. }
  2940. return -Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI);
  2941. },
  2942. Out: function Out(k) {
  2943. if (k === 0) {
  2944. return 0;
  2945. }
  2946. if (k === 1) {
  2947. return 1;
  2948. }
  2949. return Math.pow(2, -10 * k) * Math.sin((k - 0.1) * 5 * Math.PI) + 1;
  2950. },
  2951. InOut: function InOut(k) {
  2952. if (k === 0) {
  2953. return 0;
  2954. }
  2955. if (k === 1) {
  2956. return 1;
  2957. }
  2958. k *= 2;
  2959. if (k < 1) {
  2960. return -0.5 * Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI);
  2961. }
  2962. return 0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1;
  2963. }
  2964. },
  2965. Back: {
  2966. In: function In(k) {
  2967. var s = 1.70158;
  2968. return k * k * ((s + 1) * k - s);
  2969. },
  2970. Out: function Out(k) {
  2971. var s = 1.70158;
  2972. return --k * k * ((s + 1) * k + s) + 1;
  2973. },
  2974. InOut: function InOut(k) {
  2975. var s = 1.70158 * 1.525;
  2976. if ((k *= 2) < 1) {
  2977. return 0.5 * (k * k * ((s + 1) * k - s));
  2978. }
  2979. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  2980. }
  2981. },
  2982. Bounce: {
  2983. In: function In(k) {
  2984. return 1 - TWEEN.Easing.Bounce.Out(1 - k);
  2985. },
  2986. Out: function Out(k) {
  2987. if (k < 1 / 2.75) {
  2988. return 7.5625 * k * k;
  2989. } else if (k < 2 / 2.75) {
  2990. return 7.5625 * (k -= 1.5 / 2.75) * k + 0.75;
  2991. } else if (k < 2.5 / 2.75) {
  2992. return 7.5625 * (k -= 2.25 / 2.75) * k + 0.9375;
  2993. } else {
  2994. return 7.5625 * (k -= 2.625 / 2.75) * k + 0.984375;
  2995. }
  2996. },
  2997. InOut: function InOut(k) {
  2998. if (k < 0.5) {
  2999. return TWEEN.Easing.Bounce.In(k * 2) * 0.5;
  3000. }
  3001. return TWEEN.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5;
  3002. }
  3003. }
  3004. };
  3005. TWEEN.Interpolation = {
  3006. Linear: function Linear(v, k) {
  3007. var m = v.length - 1;
  3008. var f = m * k;
  3009. var i = Math.floor(f);
  3010. var fn = TWEEN.Interpolation.Utils.Linear;
  3011. if (k < 0) {
  3012. return fn(v[0], v[1], f);
  3013. }
  3014. if (k > 1) {
  3015. return fn(v[m], v[m - 1], m - f);
  3016. }
  3017. return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);
  3018. },
  3019. Bezier: function Bezier(v, k) {
  3020. var b = 0;
  3021. var n = v.length - 1;
  3022. var pw = Math.pow;
  3023. var bn = TWEEN.Interpolation.Utils.Bernstein;
  3024. for (var i = 0; i <= n; i++) {
  3025. b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
  3026. }
  3027. return b;
  3028. },
  3029. CatmullRom: function CatmullRom(v, k) {
  3030. var m = v.length - 1;
  3031. var f = m * k;
  3032. var i = Math.floor(f);
  3033. var fn = TWEEN.Interpolation.Utils.CatmullRom;
  3034. if (v[0] === v[m]) {
  3035. if (k < 0) {
  3036. i = Math.floor(f = m * (1 + k));
  3037. }
  3038. return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
  3039. } else {
  3040. if (k < 0) {
  3041. return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);
  3042. }
  3043. if (k > 1) {
  3044. return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
  3045. }
  3046. return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);
  3047. }
  3048. },
  3049. Utils: {
  3050. Linear: function Linear(p0, p1, t) {
  3051. return (p1 - p0) * t + p0;
  3052. },
  3053. Bernstein: function Bernstein(n, i) {
  3054. var fc = TWEEN.Interpolation.Utils.Factorial;
  3055. return fc(n) / fc(i) / fc(n - i);
  3056. },
  3057. Factorial: function () {
  3058. var a = [1];
  3059. return function (n) {
  3060. var s = 1;
  3061. if (a[n]) {
  3062. return a[n];
  3063. }
  3064. for (var i = n; i > 1; i--) {
  3065. s *= i;
  3066. }
  3067. a[n] = s;
  3068. return s;
  3069. };
  3070. }(),
  3071. CatmullRom: function CatmullRom(p0, p1, p2, p3, t) {
  3072. var v0 = (p2 - p0) * 0.5;
  3073. var v1 = (p3 - p1) * 0.5;
  3074. var t2 = t * t;
  3075. var t3 = t * t2;
  3076. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  3077. }
  3078. }
  3079. };
  3080. /**
  3081. * 根据2点获取角度
  3082. * @param Array [123, 23] 点1
  3083. * @param Array [123, 23] 点2
  3084. * @return angle 角度,不是弧度
  3085. */
  3086. function getAngle(start, end) {
  3087. var diff_x = end[0] - start[0];
  3088. var diff_y = end[1] - start[1];
  3089. var deg = 360 * Math.atan(diff_y / diff_x) / (2 * Math.PI);
  3090. if (end[0] < start[0]) {
  3091. deg = deg + 180;
  3092. }
  3093. return deg;
  3094. }
  3095. /**
  3096. * 绘制沿线箭头
  3097. * @author kyle / http://nikai.us/
  3098. */
  3099. var imageCache = {};
  3100. var object = {
  3101. draw: function draw(context, dataSet, options) {
  3102. var imageCacheKey = 'http://huiyan.baidu.com/github/tools/gis-drawing/static/images/direction.png';
  3103. if (options.arrow && options.arrow.url) {
  3104. imageCacheKey = options.arrow.url;
  3105. }
  3106. if (!imageCache[imageCacheKey]) {
  3107. imageCache[imageCacheKey] = null;
  3108. }
  3109. var directionImage = imageCache[imageCacheKey];
  3110. if (!directionImage) {
  3111. var args = Array.prototype.slice.call(arguments);
  3112. var image = new Image();
  3113. image.onload = function () {
  3114. imageCache[imageCacheKey] = image;
  3115. object.draw.apply(null, args);
  3116. };
  3117. image.src = imageCacheKey;
  3118. return;
  3119. }
  3120. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  3121. // console.log('xxxx',options)
  3122. context.save();
  3123. for (var key in options) {
  3124. context[key] = options[key];
  3125. }
  3126. var points = [];
  3127. var preCoordinate = null;
  3128. for (var i = 0, len = data.length; i < len; i++) {
  3129. var item = data[i];
  3130. context.save();
  3131. if (item.fillStyle || item._fillStyle) {
  3132. context.fillStyle = item.fillStyle || item._fillStyle;
  3133. }
  3134. if (item.strokeStyle || item._strokeStyle) {
  3135. context.strokeStyle = item.strokeStyle || item._strokeStyle;
  3136. }
  3137. var type = item.geometry.type;
  3138. context.beginPath();
  3139. if (type === 'LineString') {
  3140. var coordinates = item.geometry._coordinates || item.geometry.coordinates;
  3141. var interval = options.arrow.interval !== undefined ? options.arrow.interval : 1;
  3142. for (var j = 0; j < coordinates.length; j += interval) {
  3143. if (coordinates[j] && coordinates[j + 1]) {
  3144. var coordinate = coordinates[j];
  3145. if (preCoordinate && getDistance(coordinate, preCoordinate) < 30) {
  3146. continue;
  3147. }
  3148. context.save();
  3149. var angle = getAngle(coordinates[j], coordinates[j + 1]);
  3150. context.translate(coordinate[0], coordinate[1]);
  3151. context.rotate(angle * Math.PI / 180);
  3152. context.drawImage(directionImage, -directionImage.width / 2 / 2, -directionImage.height / 2 / 2, directionImage.width / 2, directionImage.height / 2);
  3153. context.restore();
  3154. points.push(coordinate);
  3155. preCoordinate = coordinate;
  3156. }
  3157. }
  3158. }
  3159. context.restore();
  3160. }
  3161. context.restore();
  3162. }
  3163. };
  3164. function getDistance(coordinateA, coordinateB) {
  3165. return Math.sqrt(Math.pow(coordinateA[0] - coordinateB[0], 2) + Math.pow(coordinateA[1] - coordinateB[1], 2));
  3166. }
  3167. /**
  3168. * @author Mofei Zhu<mapv@zhuwenlong.com>
  3169. * This file is to draw text
  3170. */
  3171. var drawClip = {
  3172. draw: function draw(context, dataSet, options) {
  3173. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  3174. context.save();
  3175. context.fillStyle = options.fillStyle || 'rgba(0, 0, 0, 0.5)';
  3176. context.fillRect(0, 0, context.canvas.width, context.canvas.height);
  3177. options.multiPolygonDraw = function () {
  3178. context.save();
  3179. context.clip();
  3180. clear(context);
  3181. context.restore();
  3182. };
  3183. for (var i = 0, len = data.length; i < len; i++) {
  3184. context.beginPath();
  3185. pathSimple.drawDataSet(context, [data[i]], options);
  3186. context.save();
  3187. context.clip();
  3188. clear(context);
  3189. context.restore();
  3190. }
  3191. context.restore();
  3192. }
  3193. };
  3194. /**
  3195. * @author kyle / http://nikai.us/
  3196. */
  3197. var drawCluster = {
  3198. draw: function draw(context, dataSet, options) {
  3199. context.save();
  3200. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  3201. var pointCountMax;
  3202. var pointCountMin;
  3203. for (var i = 0; i < data.length; i++) {
  3204. var item = data[i];
  3205. if (item.properties && item.properties.cluster) {
  3206. if (pointCountMax === undefined) {
  3207. pointCountMax = item.properties.point_count;
  3208. }
  3209. if (pointCountMin === undefined) {
  3210. pointCountMin = item.properties.point_count;
  3211. }
  3212. pointCountMax = Math.max(pointCountMax, item.properties.point_count);
  3213. pointCountMin = Math.min(pointCountMin, item.properties.point_count);
  3214. }
  3215. }
  3216. var intensity = new Intensity({
  3217. min: pointCountMin,
  3218. max: pointCountMax,
  3219. minSize: options.minSize || 8,
  3220. maxSize: options.maxSize || 30,
  3221. gradient: options.gradient
  3222. });
  3223. for (var i = 0; i < data.length; i++) {
  3224. var item = data[i];
  3225. var coordinates = data[i].geometry._coordinates || data[i].geometry.coordinates;
  3226. context.beginPath();
  3227. if (item.properties && item.properties.cluster) {
  3228. context.arc(coordinates[0], coordinates[1], intensity.getSize(item.properties.point_count), 0, Math.PI * 2);
  3229. context.fillStyle = intensity.getColor(item.properties.point_count);
  3230. context.fill();
  3231. if (options.label && options.label.show !== false) {
  3232. context.fillStyle = options.label.fillStyle || 'white';
  3233. if (options.label.font) {
  3234. context.font = options.label.font;
  3235. }
  3236. if (options.label.shadowColor) {
  3237. context.shadowColor = options.label.shadowColor;
  3238. }
  3239. if (options.label.shadowBlur) {
  3240. context.shadowBlur = options.label.shadowBlur;
  3241. }
  3242. var text = item.properties.point_count;
  3243. var textWidth = context.measureText(text).width;
  3244. context.fillText(text, coordinates[0] + .5 - textWidth / 2, coordinates[1] + .5 + 3);
  3245. }
  3246. } else {
  3247. context.arc(coordinates[0], coordinates[1], options.size || 5, 0, Math.PI * 2);
  3248. context.fillStyle = options.fillStyle || 'red';
  3249. context.fill();
  3250. }
  3251. }
  3252. context.restore();
  3253. }
  3254. };
  3255. /**
  3256. * @author Mofei Zhu<mapv@zhuwenlong.com>
  3257. * This file is to draw text
  3258. */
  3259. var drawText = {
  3260. draw: function draw(context, dataSet, options) {
  3261. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  3262. context.save();
  3263. // set from options
  3264. for (var key in options) {
  3265. context[key] = options[key];
  3266. }
  3267. var rects = [];
  3268. var size = options._size || options.size;
  3269. if (size) {
  3270. context.font = "bold " + size + "px Arial";
  3271. } else {
  3272. size = 12;
  3273. }
  3274. var textKey = options.textKey || 'text';
  3275. if (!options.textAlign) {
  3276. context.textAlign = 'center';
  3277. }
  3278. if (!options.textBaseline) {
  3279. context.textBaseline = 'middle';
  3280. }
  3281. if (options.avoid) {
  3282. // 标注避让
  3283. for (var i = 0, len = data.length; i < len; i++) {
  3284. var offset = data[i].offset || options.offset || {
  3285. x: 0,
  3286. y: 0
  3287. };
  3288. var coordinates = data[i].geometry._coordinates || data[i].geometry.coordinates;
  3289. var x = coordinates[0] + offset.x;
  3290. var y = coordinates[1] + offset.y;
  3291. var text = data[i][textKey];
  3292. var textWidth = context.measureText(text).width;
  3293. // 根据文本宽度和高度调整x,y位置,使得绘制文本时候坐标点在文本中心点,这个计算出的是左上角坐标
  3294. var px = x - textWidth / 2;
  3295. var py = y - size / 2;
  3296. var rect = {
  3297. sw: {
  3298. x: px,
  3299. y: py + size
  3300. },
  3301. ne: {
  3302. x: px + textWidth,
  3303. y: py
  3304. }
  3305. };
  3306. if (!hasOverlay(rects, rect)) {
  3307. rects.push(rect);
  3308. px = px + textWidth / 2;
  3309. py = py + size / 2;
  3310. context.fillText(text, px, py);
  3311. }
  3312. }
  3313. } else {
  3314. for (var i = 0, len = data.length; i < len; i++) {
  3315. var offset = data[i].offset || options.offset || {
  3316. x: 0,
  3317. y: 0
  3318. };
  3319. var coordinates = data[i].geometry._coordinates || data[i].geometry.coordinates;
  3320. var x = coordinates[0] + offset.x;
  3321. var y = coordinates[1] + offset.y;
  3322. var text = data[i][textKey];
  3323. context.fillText(text, x, y);
  3324. }
  3325. }
  3326. context.restore();
  3327. }
  3328. /*
  3329. * 当前文字区域和已有的文字区域是否有重叠部分
  3330. */
  3331. };function hasOverlay(rects, overlay) {
  3332. for (var i = 0; i < rects.length; i++) {
  3333. if (isRectOverlay(rects[i], overlay)) {
  3334. return true;
  3335. }
  3336. }
  3337. return false;
  3338. }
  3339. //判断2个矩形是否有重叠部分
  3340. function isRectOverlay(rect1, rect2) {
  3341. //minx、miny 2个矩形右下角最小的x和y
  3342. //maxx、maxy 2个矩形左上角最大的x和y
  3343. var minx = Math.min(rect1.ne.x, rect2.ne.x);
  3344. var miny = Math.min(rect1.sw.y, rect2.sw.y);
  3345. var maxx = Math.max(rect1.sw.x, rect2.sw.x);
  3346. var maxy = Math.max(rect1.ne.y, rect2.ne.y);
  3347. if (minx > maxx && miny > maxy) {
  3348. return true;
  3349. }
  3350. return false;
  3351. }
  3352. /**
  3353. * @author Mofei Zhu<mapv@zhuwenlong.com>
  3354. * This file is to draw text
  3355. */
  3356. var drawIcon = {
  3357. draw: function draw(context, dataSet, options) {
  3358. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  3359. context.fillStyle = 'white';
  3360. context.textAlign = 'center';
  3361. context.textBaseline = 'middle';
  3362. var offset = options.offset || {
  3363. x: 0,
  3364. y: 0
  3365. };
  3366. // set from options
  3367. // for (var key in options) {
  3368. // context[key] = options[key];
  3369. // }
  3370. // console.log(data)
  3371. for (var i = 0, len = data.length; i < len; i++) {
  3372. if (data[i].geometry) {
  3373. var deg = data[i].deg || options.deg;
  3374. var icon = data[i].icon || options.icon;
  3375. var coordinates = data[i].geometry._coordinates || data[i].geometry.coordinates;
  3376. var x = coordinates[0];
  3377. var y = coordinates[1];
  3378. if (deg) {
  3379. context.save();
  3380. context.translate(x, y);
  3381. context.rotate(deg * Math.PI / 180);
  3382. context.translate(-x, -y);
  3383. }
  3384. var width = options._width || options.width || icon.width;
  3385. var height = options._height || options.height || icon.height;
  3386. x = x - width / 2 + offset.x;
  3387. y = y - height / 2 + offset.y;
  3388. if (options.sx && options.sy && options.swidth && options.sheight && options.width && options.height) {
  3389. context.drawImage(icon, options.sx, options.sy, options.swidth, options.sheight, x, y, width, height);
  3390. } else if (options.width && options.height) {
  3391. context.drawImage(icon, x, y, width, height);
  3392. } else {
  3393. context.drawImage(icon, x, y);
  3394. }
  3395. if (deg) {
  3396. context.restore();
  3397. }
  3398. }
  3399. }
  3400. }
  3401. };
  3402. /**
  3403. * from https://github.com/mapbox/supercluster
  3404. */
  3405. function sortKD(ids, coords, nodeSize, left, right, depth) {
  3406. if (right - left <= nodeSize) {
  3407. return;
  3408. }
  3409. var m = left + right >> 1;
  3410. select(ids, coords, m, left, right, depth % 2);
  3411. sortKD(ids, coords, nodeSize, left, m - 1, depth + 1);
  3412. sortKD(ids, coords, nodeSize, m + 1, right, depth + 1);
  3413. }
  3414. function select(ids, coords, k, left, right, inc) {
  3415. while (right > left) {
  3416. if (right - left > 600) {
  3417. var n = right - left + 1;
  3418. var m = k - left + 1;
  3419. var z = Math.log(n);
  3420. var s = 0.5 * Math.exp(2 * z / 3);
  3421. var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
  3422. var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
  3423. var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
  3424. select(ids, coords, k, newLeft, newRight, inc);
  3425. }
  3426. var t = coords[2 * k + inc];
  3427. var i = left;
  3428. var j = right;
  3429. swapItem(ids, coords, left, k);
  3430. if (coords[2 * right + inc] > t) {
  3431. swapItem(ids, coords, left, right);
  3432. }
  3433. while (i < j) {
  3434. swapItem(ids, coords, i, j);
  3435. i++;
  3436. j--;
  3437. while (coords[2 * i + inc] < t) {
  3438. i++;
  3439. }
  3440. while (coords[2 * j + inc] > t) {
  3441. j--;
  3442. }
  3443. }
  3444. if (coords[2 * left + inc] === t) {
  3445. swapItem(ids, coords, left, j);
  3446. } else {
  3447. j++;
  3448. swapItem(ids, coords, j, right);
  3449. }
  3450. if (j <= k) {
  3451. left = j + 1;
  3452. }
  3453. if (k <= j) {
  3454. right = j - 1;
  3455. }
  3456. }
  3457. }
  3458. function swapItem(ids, coords, i, j) {
  3459. swap(ids, i, j);
  3460. swap(coords, 2 * i, 2 * j);
  3461. swap(coords, 2 * i + 1, 2 * j + 1);
  3462. }
  3463. function swap(arr, i, j) {
  3464. var tmp = arr[i];
  3465. arr[i] = arr[j];
  3466. arr[j] = tmp;
  3467. }
  3468. function range(ids, coords, minX, minY, maxX, maxY, nodeSize) {
  3469. var stack = [0, ids.length - 1, 0];
  3470. var result = [];
  3471. var x, y;
  3472. while (stack.length) {
  3473. var axis = stack.pop();
  3474. var right = stack.pop();
  3475. var left = stack.pop();
  3476. if (right - left <= nodeSize) {
  3477. for (var i = left; i <= right; i++) {
  3478. x = coords[2 * i];
  3479. y = coords[2 * i + 1];
  3480. if (x >= minX && x <= maxX && y >= minY && y <= maxY) {
  3481. result.push(ids[i]);
  3482. }
  3483. }
  3484. continue;
  3485. }
  3486. var m = Math.floor((left + right) / 2);
  3487. x = coords[2 * m];
  3488. y = coords[2 * m + 1];
  3489. if (x >= minX && x <= maxX && y >= minY && y <= maxY) {
  3490. result.push(ids[m]);
  3491. }
  3492. var nextAxis = (axis + 1) % 2;
  3493. if (axis === 0 ? minX <= x : minY <= y) {
  3494. stack.push(left);
  3495. stack.push(m - 1);
  3496. stack.push(nextAxis);
  3497. }
  3498. if (axis === 0 ? maxX >= x : maxY >= y) {
  3499. stack.push(m + 1);
  3500. stack.push(right);
  3501. stack.push(nextAxis);
  3502. }
  3503. }
  3504. return result;
  3505. }
  3506. function within(ids, coords, qx, qy, r, nodeSize) {
  3507. var stack = [0, ids.length - 1, 0];
  3508. var result = [];
  3509. var r2 = r * r;
  3510. while (stack.length) {
  3511. var axis = stack.pop();
  3512. var right = stack.pop();
  3513. var left = stack.pop();
  3514. if (right - left <= nodeSize) {
  3515. for (var i = left; i <= right; i++) {
  3516. if (sqDist(coords[2 * i], coords[2 * i + 1], qx, qy) <= r2) {
  3517. result.push(ids[i]);
  3518. }
  3519. }
  3520. continue;
  3521. }
  3522. var m = Math.floor((left + right) / 2);
  3523. var x = coords[2 * m];
  3524. var y = coords[2 * m + 1];
  3525. if (sqDist(x, y, qx, qy) <= r2) {
  3526. result.push(ids[m]);
  3527. }
  3528. var nextAxis = (axis + 1) % 2;
  3529. if (axis === 0 ? qx - r <= x : qy - r <= y) {
  3530. stack.push(left);
  3531. stack.push(m - 1);
  3532. stack.push(nextAxis);
  3533. }
  3534. if (axis === 0 ? qx + r >= x : qy + r >= y) {
  3535. stack.push(m + 1);
  3536. stack.push(right);
  3537. stack.push(nextAxis);
  3538. }
  3539. }
  3540. return result;
  3541. }
  3542. function sqDist(ax, ay, bx, by) {
  3543. var dx = ax - bx;
  3544. var dy = ay - by;
  3545. return dx * dx + dy * dy;
  3546. }
  3547. var defaultGetX = function defaultGetX(p) {
  3548. return p[0];
  3549. };
  3550. var defaultGetY = function defaultGetY(p) {
  3551. return p[1];
  3552. };
  3553. var KDBush = function KDBush(points, getX, getY, nodeSize, ArrayType) {
  3554. if (getX === void 0) getX = defaultGetX;
  3555. if (getY === void 0) getY = defaultGetY;
  3556. if (nodeSize === void 0) nodeSize = 64;
  3557. if (ArrayType === void 0) ArrayType = Float64Array;
  3558. this.nodeSize = nodeSize;
  3559. this.points = points;
  3560. var IndexArrayType = points.length < 65536 ? Uint16Array : Uint32Array;
  3561. var ids = this.ids = new IndexArrayType(points.length);
  3562. var coords = this.coords = new ArrayType(points.length * 2);
  3563. for (var i = 0; i < points.length; i++) {
  3564. ids[i] = i;
  3565. coords[2 * i] = getX(points[i]);
  3566. coords[2 * i + 1] = getY(points[i]);
  3567. }
  3568. sortKD(ids, coords, nodeSize, 0, ids.length - 1, 0);
  3569. };
  3570. KDBush.prototype.range = function range$1(minX, minY, maxX, maxY) {
  3571. return range(this.ids, this.coords, minX, minY, maxX, maxY, this.nodeSize);
  3572. };
  3573. KDBush.prototype.within = function within$1(x, y, r) {
  3574. return within(this.ids, this.coords, x, y, r, this.nodeSize);
  3575. };
  3576. var defaultOptions = {
  3577. minZoom: 0, // min zoom to generate clusters on
  3578. maxZoom: 16, // max zoom level to cluster the points on
  3579. radius: 40, // cluster radius in pixels
  3580. extent: 512, // tile extent (radius is calculated relative to it)
  3581. nodeSize: 64, // size of the KD-tree leaf node, affects performance
  3582. log: false, // whether to log timing info
  3583. // a reduce function for calculating custom cluster properties
  3584. reduce: null, // (accumulated, props) => { accumulated.sum += props.sum; }
  3585. // properties to use for individual points when running the reducer
  3586. map: function map(props) {
  3587. return props;
  3588. } // props => ({sum: props.my_value})
  3589. };
  3590. var Supercluster = function Supercluster(options) {
  3591. this.options = extend(Object.create(defaultOptions), options);
  3592. this.trees = new Array(this.options.maxZoom + 1);
  3593. };
  3594. Supercluster.prototype.load = function load(points) {
  3595. var ref = this.options;
  3596. var log = ref.log;
  3597. var minZoom = ref.minZoom;
  3598. var maxZoom = ref.maxZoom;
  3599. var nodeSize = ref.nodeSize;
  3600. if (log) {}
  3601. var timerId = "prepare " + points.length + " points";
  3602. if (log) {}
  3603. this.points = points;
  3604. // generate a cluster object for each point and index input points into a KD-tree
  3605. var clusters = [];
  3606. for (var i = 0; i < points.length; i++) {
  3607. if (!points[i].geometry) {
  3608. continue;
  3609. }
  3610. clusters.push(createPointCluster(points[i], i));
  3611. }
  3612. this.trees[maxZoom + 1] = new KDBush(clusters, getX, getY, nodeSize, Float32Array);
  3613. if (log) {}
  3614. // cluster points on max zoom, then cluster the results on previous zoom, etc.;
  3615. // results in a cluster hierarchy across zoom levels
  3616. for (var z = maxZoom; z >= minZoom; z--) {
  3617. var now = +Date.now();
  3618. // create a new set of clusters for the zoom and index them with a KD-tree
  3619. clusters = this._cluster(clusters, z);
  3620. this.trees[z] = new KDBush(clusters, getX, getY, nodeSize, Float32Array);
  3621. if (log) {}
  3622. }
  3623. if (log) {}
  3624. return this;
  3625. };
  3626. Supercluster.prototype.getClusters = function getClusters(bbox, zoom) {
  3627. var minLng = ((bbox[0] + 180) % 360 + 360) % 360 - 180;
  3628. var minLat = Math.max(-90, Math.min(90, bbox[1]));
  3629. var maxLng = bbox[2] === 180 ? 180 : ((bbox[2] + 180) % 360 + 360) % 360 - 180;
  3630. var maxLat = Math.max(-90, Math.min(90, bbox[3]));
  3631. if (bbox[2] - bbox[0] >= 360) {
  3632. minLng = -180;
  3633. maxLng = 180;
  3634. } else if (minLng > maxLng) {
  3635. var easternHem = this.getClusters([minLng, minLat, 180, maxLat], zoom);
  3636. var westernHem = this.getClusters([-180, minLat, maxLng, maxLat], zoom);
  3637. return easternHem.concat(westernHem);
  3638. }
  3639. var tree = this.trees[this._limitZoom(zoom)];
  3640. var ids = tree.range(lngX(minLng), latY(maxLat), lngX(maxLng), latY(minLat));
  3641. var clusters = [];
  3642. for (var i = 0, list = ids; i < list.length; i += 1) {
  3643. var id = list[i];
  3644. var c = tree.points[id];
  3645. clusters.push(c.numPoints ? getClusterJSON(c) : this.points[c.index]);
  3646. }
  3647. return clusters;
  3648. };
  3649. Supercluster.prototype.getChildren = function getChildren(clusterId) {
  3650. var originId = clusterId >> 5;
  3651. var originZoom = clusterId % 32;
  3652. var errorMsg = 'No cluster with the specified id.';
  3653. var index = this.trees[originZoom];
  3654. if (!index) {
  3655. throw new Error(errorMsg);
  3656. }
  3657. var origin = index.points[originId];
  3658. if (!origin) {
  3659. throw new Error(errorMsg);
  3660. }
  3661. var r = this.options.radius / (this.options.extent * Math.pow(2, originZoom - 1));
  3662. var ids = index.within(origin.x, origin.y, r);
  3663. var children = [];
  3664. for (var i = 0, list = ids; i < list.length; i += 1) {
  3665. var id = list[i];
  3666. var c = index.points[id];
  3667. if (c.parentId === clusterId) {
  3668. children.push(c.numPoints ? getClusterJSON(c) : this.points[c.index]);
  3669. }
  3670. }
  3671. if (children.length === 0) {
  3672. throw new Error(errorMsg);
  3673. }
  3674. return children;
  3675. };
  3676. Supercluster.prototype.getLeaves = function getLeaves(clusterId, limit, offset) {
  3677. limit = limit || 10;
  3678. offset = offset || 0;
  3679. var leaves = [];
  3680. this._appendLeaves(leaves, clusterId, limit, offset, 0);
  3681. return leaves;
  3682. };
  3683. Supercluster.prototype.getTile = function getTile(z, x, y) {
  3684. var tree = this.trees[this._limitZoom(z)];
  3685. var z2 = Math.pow(2, z);
  3686. var ref = this.options;
  3687. var extent = ref.extent;
  3688. var radius = ref.radius;
  3689. var p = radius / extent;
  3690. var top = (y - p) / z2;
  3691. var bottom = (y + 1 + p) / z2;
  3692. var tile = {
  3693. features: []
  3694. };
  3695. this._addTileFeatures(tree.range((x - p) / z2, top, (x + 1 + p) / z2, bottom), tree.points, x, y, z2, tile);
  3696. if (x === 0) {
  3697. this._addTileFeatures(tree.range(1 - p / z2, top, 1, bottom), tree.points, z2, y, z2, tile);
  3698. }
  3699. if (x === z2 - 1) {
  3700. this._addTileFeatures(tree.range(0, top, p / z2, bottom), tree.points, -1, y, z2, tile);
  3701. }
  3702. return tile.features.length ? tile : null;
  3703. };
  3704. Supercluster.prototype.getClusterExpansionZoom = function getClusterExpansionZoom(clusterId) {
  3705. var clusterZoom = clusterId % 32 - 1;
  3706. while (clusterZoom <= this.options.maxZoom) {
  3707. var children = this.getChildren(clusterId);
  3708. clusterZoom++;
  3709. if (children.length !== 1) {
  3710. break;
  3711. }
  3712. clusterId = children[0].properties.cluster_id;
  3713. }
  3714. return clusterZoom;
  3715. };
  3716. Supercluster.prototype._appendLeaves = function _appendLeaves(result, clusterId, limit, offset, skipped) {
  3717. var children = this.getChildren(clusterId);
  3718. for (var i = 0, list = children; i < list.length; i += 1) {
  3719. var child = list[i];
  3720. var props = child.properties;
  3721. if (props && props.cluster) {
  3722. if (skipped + props.point_count <= offset) {
  3723. // skip the whole cluster
  3724. skipped += props.point_count;
  3725. } else {
  3726. // enter the cluster
  3727. skipped = this._appendLeaves(result, props.cluster_id, limit, offset, skipped);
  3728. // exit the cluster
  3729. }
  3730. } else if (skipped < offset) {
  3731. // skip a single point
  3732. skipped++;
  3733. } else {
  3734. // add a single point
  3735. result.push(child);
  3736. }
  3737. if (result.length === limit) {
  3738. break;
  3739. }
  3740. }
  3741. return skipped;
  3742. };
  3743. Supercluster.prototype._addTileFeatures = function _addTileFeatures(ids, points, x, y, z2, tile) {
  3744. for (var i$1 = 0, list = ids; i$1 < list.length; i$1 += 1) {
  3745. var i = list[i$1];
  3746. var c = points[i];
  3747. var f = {
  3748. type: 1,
  3749. geometry: [[Math.round(this.options.extent * (c.x * z2 - x)), Math.round(this.options.extent * (c.y * z2 - y))]],
  3750. tags: c.numPoints ? getClusterProperties(c) : this.points[c.index].properties
  3751. };
  3752. var id = c.numPoints ? c.id : this.points[c.index].id;
  3753. if (id !== undefined) {
  3754. f.id = id;
  3755. }
  3756. tile.features.push(f);
  3757. }
  3758. };
  3759. Supercluster.prototype._limitZoom = function _limitZoom(z) {
  3760. return Math.max(this.options.minZoom, Math.min(z, this.options.maxZoom + 1));
  3761. };
  3762. Supercluster.prototype._cluster = function _cluster(points, zoom) {
  3763. var clusters = [];
  3764. var ref = this.options;
  3765. var radius = ref.radius;
  3766. var extent = ref.extent;
  3767. var reduce = ref.reduce;
  3768. var r = radius / (extent * Math.pow(2, zoom));
  3769. // loop through each point
  3770. for (var i = 0; i < points.length; i++) {
  3771. var p = points[i];
  3772. // if we've already visited the point at this zoom level, skip it
  3773. if (p.zoom <= zoom) {
  3774. continue;
  3775. }
  3776. p.zoom = zoom;
  3777. // find all nearby points
  3778. var tree = this.trees[zoom + 1];
  3779. var neighborIds = tree.within(p.x, p.y, r);
  3780. var numPoints = p.numPoints || 1;
  3781. var wx = p.x * numPoints;
  3782. var wy = p.y * numPoints;
  3783. var clusterProperties = reduce && numPoints > 1 ? this._map(p, true) : null;
  3784. // encode both zoom and point index on which the cluster originated
  3785. var id = (i << 5) + (zoom + 1);
  3786. for (var i$1 = 0, list = neighborIds; i$1 < list.length; i$1 += 1) {
  3787. var neighborId = list[i$1];
  3788. var b = tree.points[neighborId];
  3789. // filter out neighbors that are already processed
  3790. if (b.zoom <= zoom) {
  3791. continue;
  3792. }
  3793. b.zoom = zoom; // save the zoom (so it doesn't get processed twice)
  3794. var numPoints2 = b.numPoints || 1;
  3795. wx += b.x * numPoints2; // accumulate coordinates for calculating weighted center
  3796. wy += b.y * numPoints2;
  3797. numPoints += numPoints2;
  3798. b.parentId = id;
  3799. if (reduce) {
  3800. if (!clusterProperties) {
  3801. clusterProperties = this._map(p, true);
  3802. }
  3803. reduce(clusterProperties, this._map(b));
  3804. }
  3805. }
  3806. if (numPoints === 1) {
  3807. clusters.push(p);
  3808. } else {
  3809. p.parentId = id;
  3810. clusters.push(createCluster(wx / numPoints, wy / numPoints, id, numPoints, clusterProperties));
  3811. }
  3812. }
  3813. return clusters;
  3814. };
  3815. Supercluster.prototype._map = function _map(point, clone) {
  3816. if (point.numPoints) {
  3817. return clone ? extend({}, point.properties) : point.properties;
  3818. }
  3819. var original = this.points[point.index].properties;
  3820. var result = this.options.map(original);
  3821. return clone && result === original ? extend({}, result) : result;
  3822. };
  3823. function createCluster(x, y, id, numPoints, properties) {
  3824. return {
  3825. x: x, // weighted cluster center
  3826. y: y,
  3827. zoom: Infinity, // the last zoom the cluster was processed at
  3828. id: id, // encodes index of the first child of the cluster and its zoom level
  3829. parentId: -1, // parent cluster id
  3830. numPoints: numPoints,
  3831. properties: properties
  3832. };
  3833. }
  3834. function createPointCluster(p, id) {
  3835. var ref = p.geometry.coordinates;
  3836. var x = ref[0];
  3837. var y = ref[1];
  3838. return {
  3839. x: lngX(x), // projected point coordinates
  3840. y: latY(y),
  3841. zoom: Infinity, // the last zoom the point was processed at
  3842. index: id, // index of the source feature in the original input array,
  3843. parentId: -1 // parent cluster id
  3844. };
  3845. }
  3846. function getClusterJSON(cluster) {
  3847. return {
  3848. type: 'Feature',
  3849. id: cluster.id,
  3850. properties: getClusterProperties(cluster),
  3851. geometry: {
  3852. type: 'Point',
  3853. coordinates: [xLng(cluster.x), yLat(cluster.y)]
  3854. }
  3855. };
  3856. }
  3857. function getClusterProperties(cluster) {
  3858. var count = cluster.numPoints;
  3859. var abbrev = count >= 10000 ? Math.round(count / 1000) + "k" : count >= 1000 ? Math.round(count / 100) / 10 + "k" : count;
  3860. return extend(extend({}, cluster.properties), {
  3861. cluster: true,
  3862. cluster_id: cluster.id,
  3863. point_count: count,
  3864. point_count_abbreviated: abbrev
  3865. });
  3866. }
  3867. // longitude/latitude to spherical mercator in [0..1] range
  3868. function lngX(lng) {
  3869. return lng / 360 + 0.5;
  3870. }
  3871. function latY(lat) {
  3872. var sin = Math.sin(lat * Math.PI / 180);
  3873. var y = 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
  3874. return y < 0 ? 0 : y > 1 ? 1 : y;
  3875. }
  3876. // spherical mercator to longitude/latitude
  3877. function xLng(x) {
  3878. return (x - 0.5) * 360;
  3879. }
  3880. function yLat(y) {
  3881. var y2 = (180 - y * 360) * Math.PI / 180;
  3882. return 360 * Math.atan(Math.exp(y2)) / Math.PI - 90;
  3883. }
  3884. function extend(dest, src) {
  3885. for (var id in src) {
  3886. dest[id] = src[id];
  3887. }
  3888. return dest;
  3889. }
  3890. function getX(p) {
  3891. return p.x;
  3892. }
  3893. function getY(p) {
  3894. return p.y;
  3895. }
  3896. /**
  3897. * @author kyle / http://nikai.us/
  3898. */
  3899. if (typeof window !== 'undefined') {
  3900. requestAnimationFrame(animate);
  3901. }
  3902. function animate(time) {
  3903. requestAnimationFrame(animate);
  3904. TWEEN.update(time);
  3905. }
  3906. var BaseLayer = function () {
  3907. function BaseLayer(map, dataSet, options) {
  3908. classCallCheck(this, BaseLayer);
  3909. if (!(dataSet instanceof DataSet)) {
  3910. dataSet = new DataSet(dataSet);
  3911. }
  3912. this.dataSet = dataSet;
  3913. this.map = map;
  3914. if (options.draw === 'cluster' && !this.supercluster) {
  3915. this.supercluster = new Supercluster({ maxZoom: options.maxZoom || 19, radius: options.clusterRadius || 100 });
  3916. this.supercluster.load(dataSet.get());
  3917. this.clusterDataSet = new DataSet();
  3918. }
  3919. }
  3920. createClass(BaseLayer, [{
  3921. key: "getDefaultContextConfig",
  3922. value: function getDefaultContextConfig() {
  3923. return {
  3924. globalAlpha: 1,
  3925. globalCompositeOperation: 'source-over',
  3926. imageSmoothingEnabled: true,
  3927. strokeStyle: '#000000',
  3928. fillStyle: '#000000',
  3929. shadowOffsetX: 0,
  3930. shadowOffsetY: 0,
  3931. shadowBlur: 0,
  3932. shadowColor: 'rgba(0, 0, 0, 0)',
  3933. lineWidth: 1,
  3934. lineCap: 'butt',
  3935. lineJoin: 'miter',
  3936. miterLimit: 10,
  3937. lineDashOffset: 0,
  3938. font: '10px sans-serif',
  3939. textAlign: 'start',
  3940. textBaseline: 'alphabetic'
  3941. };
  3942. }
  3943. }, {
  3944. key: "initDataRange",
  3945. value: function initDataRange(options) {
  3946. var self = this;
  3947. self.intensity = new Intensity({
  3948. maxSize: self.options.maxSize,
  3949. minSize: self.options.minSize,
  3950. gradient: self.options.gradient,
  3951. max: self.options.max || this.dataSet.getMax('count')
  3952. });
  3953. self.category = new Category(self.options.splitList);
  3954. self.choropleth = new Choropleth(self.options.splitList);
  3955. if (self.options.splitList === undefined) {
  3956. self.category.generateByDataSet(this.dataSet, self.options.color);
  3957. }
  3958. if (self.options.splitList === undefined) {
  3959. var min = self.options.min || this.dataSet.getMin('count');
  3960. var max = self.options.max || this.dataSet.getMax('count');
  3961. self.choropleth.generateByMinMax(min, max);
  3962. }
  3963. }
  3964. }, {
  3965. key: "getLegend",
  3966. value: function getLegend(options) {
  3967. var draw = this.options.draw;
  3968. var legend = null;
  3969. var self = this;
  3970. if (self.options.draw == 'intensity' || self.options.draw == 'heatmap') {
  3971. return this.intensity.getLegend(options);
  3972. } else if (self.options.draw == 'category') {
  3973. return this.category.getLegend(options);
  3974. }
  3975. }
  3976. }, {
  3977. key: "processData",
  3978. value: function processData(data) {
  3979. var self = this;
  3980. var draw = self.options.draw;
  3981. if (draw == 'bubble' || draw == 'intensity' || draw == 'category' || draw == 'choropleth' || draw == 'simple') {
  3982. for (var i = 0; i < data.length; i++) {
  3983. var item = data[i];
  3984. if (self.options.draw == 'bubble') {
  3985. data[i]._size = self.intensity.getSize(item.count);
  3986. } else {
  3987. data[i]._size = undefined;
  3988. }
  3989. var styleType = '_fillStyle';
  3990. if (data[i].geometry.type === 'LineString' || self.options.styleType === 'stroke') {
  3991. styleType = '_strokeStyle';
  3992. }
  3993. if (self.options.draw == 'intensity') {
  3994. data[i][styleType] = self.intensity.getColor(item.count);
  3995. } else if (self.options.draw == 'category') {
  3996. data[i][styleType] = self.category.get(item.count);
  3997. } else if (self.options.draw == 'choropleth') {
  3998. data[i][styleType] = self.choropleth.get(item.count);
  3999. }
  4000. }
  4001. }
  4002. }
  4003. }, {
  4004. key: "isEnabledTime",
  4005. value: function isEnabledTime() {
  4006. var animationOptions = this.options.animation;
  4007. var flag = animationOptions && !(animationOptions.enabled === false);
  4008. return flag;
  4009. }
  4010. }, {
  4011. key: "argCheck",
  4012. value: function argCheck(options) {
  4013. if (options.draw == 'heatmap') {
  4014. if (options.strokeStyle) {
  4015. console.warn('[heatmap] options.strokeStyle is discard, pleause use options.strength [eg: options.strength = 0.1]');
  4016. }
  4017. }
  4018. }
  4019. }, {
  4020. key: "drawContext",
  4021. value: function drawContext(context, dataSet, options, nwPixel) {
  4022. var self = this;
  4023. switch (self.options.draw) {
  4024. case 'heatmap':
  4025. drawHeatmap.draw(context, dataSet, self.options);
  4026. break;
  4027. case 'grid':
  4028. case 'cluster':
  4029. case 'honeycomb':
  4030. self.options.offset = {
  4031. x: nwPixel.x,
  4032. y: nwPixel.y
  4033. };
  4034. if (self.options.draw === 'grid') {
  4035. drawGrid.draw(context, dataSet, self.options);
  4036. } else if (self.options.draw === 'cluster') {
  4037. drawCluster.draw(context, dataSet, self.options);
  4038. } else {
  4039. drawHoneycomb.draw(context, dataSet, self.options);
  4040. }
  4041. break;
  4042. case 'text':
  4043. drawText.draw(context, dataSet, self.options);
  4044. break;
  4045. case 'icon':
  4046. drawIcon.draw(context, dataSet, self.options);
  4047. break;
  4048. case 'clip':
  4049. drawClip.draw(context, dataSet, self.options);
  4050. break;
  4051. default:
  4052. if (self.options.context == "webgl") {
  4053. webglDrawSimple.draw(self.canvasLayer.canvas.getContext('webgl'), dataSet, self.options);
  4054. } else {
  4055. drawSimple.draw(context, dataSet, self.options);
  4056. }
  4057. }
  4058. if (self.options.arrow && self.options.arrow.show !== false) {
  4059. object.draw(context, dataSet, self.options);
  4060. }
  4061. }
  4062. }, {
  4063. key: "isPointInPath",
  4064. value: function isPointInPath(context, pixel) {
  4065. var context = this.canvasLayer.canvas.getContext(this.context);
  4066. var data;
  4067. if (this.options.draw === 'cluster') {
  4068. data = this.clusterDataSet.get();
  4069. } else {
  4070. data = this.dataSet.get();
  4071. }
  4072. for (var i = 0; i < data.length; i++) {
  4073. context.beginPath();
  4074. var options = this.options;
  4075. var x = pixel.x * this.canvasLayer.devicePixelRatio;
  4076. var y = pixel.y * this.canvasLayer.devicePixelRatio;
  4077. options.multiPolygonDraw = function () {
  4078. if (context.isPointInPath(x, y)) {
  4079. return data[i];
  4080. }
  4081. };
  4082. pathSimple.draw(context, data[i], options);
  4083. var geoType = data[i].geometry && data[i].geometry.type;
  4084. if (geoType.indexOf('LineString') > -1) {
  4085. if (context.isPointInStroke && context.isPointInStroke(x, y)) {
  4086. return data[i];
  4087. }
  4088. } else {
  4089. if (context.isPointInPath(x, y)) {
  4090. return data[i];
  4091. }
  4092. }
  4093. }
  4094. }
  4095. }, {
  4096. key: "clickEvent",
  4097. value: function clickEvent(pixel, e) {
  4098. if (!this.options.methods) {
  4099. return;
  4100. }
  4101. var dataItem = this.isPointInPath(this.getContext(), pixel);
  4102. if (dataItem) {
  4103. this.options.methods.click(dataItem, e);
  4104. } else {
  4105. this.options.methods.click(null, e);
  4106. }
  4107. }
  4108. }, {
  4109. key: "mousemoveEvent",
  4110. value: function mousemoveEvent(pixel, e) {
  4111. if (!this.options.methods) {
  4112. return;
  4113. }
  4114. var dataItem = this.isPointInPath(this.getContext(), pixel);
  4115. if (dataItem) {
  4116. this.options.methods.mousemove(dataItem, e);
  4117. } else {
  4118. this.options.methods.mousemove(null, e);
  4119. }
  4120. }
  4121. }, {
  4122. key: "tapEvent",
  4123. value: function tapEvent(pixel, e) {
  4124. if (!this.options.methods) {
  4125. return;
  4126. }
  4127. var dataItem = this.isPointInPath(this.getContext(), pixel);
  4128. if (dataItem) {
  4129. this.options.methods.tap(dataItem, e);
  4130. } else {
  4131. this.options.methods.tap(null, e);
  4132. }
  4133. }
  4134. /**
  4135. * obj.options
  4136. */
  4137. }, {
  4138. key: "update",
  4139. value: function update(obj, isDraw) {
  4140. var self = this;
  4141. var _options = obj.options;
  4142. var options = self.options;
  4143. for (var i in _options) {
  4144. options[i] = _options[i];
  4145. }
  4146. self.init(options);
  4147. if (isDraw !== false) {
  4148. self.draw();
  4149. }
  4150. }
  4151. }, {
  4152. key: "setOptions",
  4153. value: function setOptions(options) {
  4154. var self = this;
  4155. self.dataSet.reset();
  4156. // console.log('xxx1')
  4157. self.init(options);
  4158. // console.log('xxx')
  4159. self.draw();
  4160. }
  4161. }, {
  4162. key: "set",
  4163. value: function set$$1(obj) {
  4164. var self = this;
  4165. var ctx = this.getContext();
  4166. var conf = this.getDefaultContextConfig();
  4167. for (var i in conf) {
  4168. ctx[i] = conf[i];
  4169. }
  4170. self.init(obj.options);
  4171. self.draw();
  4172. }
  4173. }, {
  4174. key: "destroy",
  4175. value: function destroy() {
  4176. this.unbindEvent();
  4177. this.hide();
  4178. }
  4179. }, {
  4180. key: "initAnimator",
  4181. value: function initAnimator() {
  4182. var self = this;
  4183. var animationOptions = self.options.animation;
  4184. if (self.options.draw == 'time' || self.isEnabledTime()) {
  4185. if (!animationOptions.stepsRange) {
  4186. animationOptions.stepsRange = {
  4187. start: this.dataSet.getMin('time') || 0,
  4188. end: this.dataSet.getMax('time') || 0
  4189. };
  4190. }
  4191. this.steps = { step: animationOptions.stepsRange.start };
  4192. self.animator = new TWEEN.Tween(this.steps).onUpdate(function () {
  4193. self._canvasUpdate(this.step);
  4194. }).repeat(Infinity);
  4195. this.addAnimatorEvent();
  4196. var duration = animationOptions.duration * 1000 || 5000;
  4197. self.animator.to({ step: animationOptions.stepsRange.end }, duration);
  4198. self.animator.start();
  4199. } else {
  4200. self.animator && self.animator.stop();
  4201. }
  4202. }
  4203. }, {
  4204. key: "addAnimatorEvent",
  4205. value: function addAnimatorEvent() {}
  4206. }, {
  4207. key: "animatorMovestartEvent",
  4208. value: function animatorMovestartEvent() {
  4209. var animationOptions = this.options.animation;
  4210. if (this.isEnabledTime() && this.animator) {
  4211. this.steps.step = animationOptions.stepsRange.start;
  4212. this.animator.stop();
  4213. }
  4214. }
  4215. }, {
  4216. key: "animatorMoveendEvent",
  4217. value: function animatorMoveendEvent() {
  4218. if (this.isEnabledTime() && this.animator) {
  4219. this.animator.start();
  4220. }
  4221. }
  4222. }]);
  4223. return BaseLayer;
  4224. }();
  4225. var global$4 = typeof window === 'undefined' ? {} : window;
  4226. var BMap$2 = global$4.BMap || global$4.BMapGL;
  4227. var AnimationLayer = function (_BaseLayer) {
  4228. inherits(AnimationLayer, _BaseLayer);
  4229. function AnimationLayer(map, dataSet, options) {
  4230. classCallCheck(this, AnimationLayer);
  4231. var _this = possibleConstructorReturn(this, (AnimationLayer.__proto__ || Object.getPrototypeOf(AnimationLayer)).call(this, map, dataSet, options));
  4232. _this.map = map;
  4233. _this.options = options || {};
  4234. _this.dataSet = dataSet;
  4235. var canvasLayer = new CanvasLayer({
  4236. map: map,
  4237. zIndex: _this.options.zIndex,
  4238. update: _this._canvasUpdate.bind(_this)
  4239. });
  4240. _this.init(_this.options);
  4241. _this.canvasLayer = canvasLayer;
  4242. _this.transferToMercator();
  4243. var self = _this;
  4244. dataSet.on('change', function () {
  4245. self.transferToMercator();
  4246. canvasLayer.draw();
  4247. });
  4248. _this.ctx = canvasLayer.canvas.getContext('2d');
  4249. _this.start();
  4250. return _this;
  4251. }
  4252. createClass(AnimationLayer, [{
  4253. key: "draw",
  4254. value: function draw() {
  4255. this.canvasLayer.draw();
  4256. }
  4257. }, {
  4258. key: "init",
  4259. value: function init(options) {
  4260. var self = this;
  4261. self.options = options;
  4262. this.initDataRange(options);
  4263. this.context = self.options.context || '2d';
  4264. if (self.options.zIndex) {
  4265. this.canvasLayer && this.canvasLayer.setZIndex(self.options.zIndex);
  4266. }
  4267. if (self.options.max) {
  4268. this.intensity.setMax(self.options.max);
  4269. }
  4270. if (self.options.min) {
  4271. this.intensity.setMin(self.options.min);
  4272. }
  4273. this.initAnimator();
  4274. }
  4275. // 经纬度左边转换为墨卡托坐标
  4276. }, {
  4277. key: "transferToMercator",
  4278. value: function transferToMercator() {
  4279. var map = this.map;
  4280. var mapType = map.getMapType();
  4281. var projection;
  4282. if (mapType.getProjection) {
  4283. projection = mapType.getProjection();
  4284. } else {
  4285. projection = {
  4286. lngLatToPoint: function lngLatToPoint(point) {
  4287. var mc = map.lnglatToMercator(point.lng, point.lat);
  4288. return {
  4289. x: mc[0],
  4290. y: mc[1]
  4291. };
  4292. }
  4293. };
  4294. }
  4295. if (this.options.coordType !== 'bd09mc') {
  4296. var data = this.dataSet.get();
  4297. data = this.dataSet.transferCoordinate(data, function (coordinates) {
  4298. var pixel = projection.lngLatToPoint({
  4299. lng: coordinates[0],
  4300. lat: coordinates[1]
  4301. });
  4302. return [pixel.x, pixel.y];
  4303. }, 'coordinates', 'coordinates_mercator');
  4304. this.dataSet._set(data);
  4305. }
  4306. }
  4307. }, {
  4308. key: "_canvasUpdate",
  4309. value: function _canvasUpdate() {
  4310. var ctx = this.ctx;
  4311. if (!ctx) {
  4312. return;
  4313. }
  4314. //clear(ctx);
  4315. var map = this.map;
  4316. var projection;
  4317. var mcCenter;
  4318. if (map.getMapType().getProjection) {
  4319. projection = map.getMapType().getProjection();
  4320. mcCenter = projection.lngLatToPoint(map.getCenter());
  4321. } else {
  4322. mcCenter = {
  4323. x: map.getCenter().lng,
  4324. y: map.getCenter().lat
  4325. };
  4326. if (mcCenter.x > -180 && mcCenter.x < 180) {
  4327. mcCenter = map.lnglatToMercator(mcCenter.x, mcCenter.y);
  4328. mcCenter = { x: mcCenter[0], y: mcCenter[1] };
  4329. }
  4330. projection = {
  4331. lngLatToPoint: function lngLatToPoint(point) {
  4332. var mc = map.lnglatToMercator(point.lng, point.lat);
  4333. return {
  4334. x: mc[0],
  4335. y: mc[1]
  4336. };
  4337. }
  4338. };
  4339. }
  4340. var zoomUnit;
  4341. if (projection.getZoomUnits) {
  4342. zoomUnit = projection.getZoomUnits(map.getZoom());
  4343. } else {
  4344. zoomUnit = Math.pow(2, 18 - map.getZoom());
  4345. }
  4346. var nwMc = new BMap$2.Pixel(mcCenter.x - map.getSize().width / 2 * zoomUnit, mcCenter.y + map.getSize().height / 2 * zoomUnit); //左上角墨卡托坐标
  4347. clear(ctx);
  4348. var dataGetOptions = {
  4349. fromColumn: this.options.coordType == 'bd09mc' ? 'coordinates' : 'coordinates_mercator',
  4350. transferCoordinate: function transferCoordinate(coordinate) {
  4351. if (!coordinate) {
  4352. return;
  4353. }
  4354. var x = (coordinate[0] - nwMc.x) / zoomUnit;
  4355. var y = (nwMc.y - coordinate[1]) / zoomUnit;
  4356. return [x, y];
  4357. }
  4358. };
  4359. this.data = this.dataSet.get(dataGetOptions);
  4360. this.processData(this.data);
  4361. this.drawAnimation();
  4362. }
  4363. }, {
  4364. key: "drawAnimation",
  4365. value: function drawAnimation() {
  4366. var ctx = this.ctx;
  4367. var data = this.data;
  4368. if (!data) {
  4369. return;
  4370. }
  4371. ctx.save();
  4372. ctx.globalCompositeOperation = 'destination-out';
  4373. ctx.fillStyle = 'rgba(0, 0, 0, .1)';
  4374. ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  4375. ctx.restore();
  4376. ctx.save();
  4377. if (this.options.shadowColor) {
  4378. ctx.shadowColor = this.options.shadowColor;
  4379. }
  4380. if (this.options.shadowBlur) {
  4381. ctx.shadowBlur = this.options.shadowBlur;
  4382. }
  4383. if (this.options.globalAlpha) {
  4384. ctx.globalAlpha = this.options.globalAlpha;
  4385. }
  4386. if (this.options.globalCompositeOperation) {
  4387. ctx.globalCompositeOperation = this.options.globalCompositeOperation;
  4388. }
  4389. var options = this.options;
  4390. for (var i = 0; i < data.length; i++) {
  4391. if (data[i].geometry.type === 'Point') {
  4392. ctx.beginPath();
  4393. var maxSize = data[i].size || this.options.size;
  4394. var minSize = data[i].minSize || this.options.minSize || 0;
  4395. if (data[i]._size === undefined) {
  4396. data[i]._size = minSize;
  4397. }
  4398. ctx.arc(data[i].geometry._coordinates[0], data[i].geometry._coordinates[1], data[i]._size, 0, Math.PI * 2, true);
  4399. ctx.closePath();
  4400. data[i]._size++;
  4401. if (data[i]._size > maxSize) {
  4402. data[i]._size = minSize;
  4403. }
  4404. ctx.lineWidth = 1;
  4405. ctx.strokeStyle = data[i].strokeStyle || data[i]._strokeStyle || options.strokeStyle || 'yellow';
  4406. ctx.stroke();
  4407. var fillStyle = data[i].fillStyle || data[i]._fillStyle || options.fillStyle;
  4408. if (fillStyle) {
  4409. ctx.fillStyle = fillStyle;
  4410. ctx.fill();
  4411. }
  4412. } else if (data[i].geometry.type === 'LineString') {
  4413. ctx.beginPath();
  4414. var size = data[i].size || this.options.size || 5;
  4415. var minSize = data[i].minSize || this.options.minSize || 0;
  4416. if (data[i]._index === undefined) {
  4417. data[i]._index = 0;
  4418. }
  4419. var index = data[i]._index;
  4420. ctx.arc(data[i].geometry._coordinates[index][0], data[i].geometry._coordinates[index][1], size, 0, Math.PI * 2, true);
  4421. ctx.closePath();
  4422. data[i]._index++;
  4423. if (data[i]._index >= data[i].geometry._coordinates.length) {
  4424. data[i]._index = 0;
  4425. }
  4426. var strokeStyle = data[i].strokeStyle || options.strokeStyle;
  4427. var fillStyle = data[i].fillStyle || options.fillStyle || 'yellow';
  4428. ctx.fillStyle = fillStyle;
  4429. ctx.fill();
  4430. if (strokeStyle && options.lineWidth) {
  4431. ctx.lineWidth = options.lineWidth || 1;
  4432. ctx.strokeStyle = strokeStyle;
  4433. ctx.stroke();
  4434. }
  4435. }
  4436. }
  4437. ctx.restore();
  4438. }
  4439. }, {
  4440. key: "animate",
  4441. value: function animate() {
  4442. this.drawAnimation();
  4443. var animateTime = this.options.animateTime || 100;
  4444. this.timeout = setTimeout(this.animate.bind(this), animateTime);
  4445. }
  4446. }, {
  4447. key: "start",
  4448. value: function start() {
  4449. this.stop();
  4450. this.animate();
  4451. }
  4452. }, {
  4453. key: "stop",
  4454. value: function stop() {
  4455. clearTimeout(this.timeout);
  4456. }
  4457. }, {
  4458. key: "unbindEvent",
  4459. value: function unbindEvent() {}
  4460. }, {
  4461. key: "hide",
  4462. value: function hide() {
  4463. this.canvasLayer.hide();
  4464. this.stop();
  4465. }
  4466. }, {
  4467. key: "show",
  4468. value: function show() {
  4469. this.start();
  4470. }
  4471. }, {
  4472. key: "clearData",
  4473. value: function clearData() {
  4474. this.dataSet && this.dataSet.clear();
  4475. this.update({
  4476. options: null
  4477. });
  4478. }
  4479. }, {
  4480. key: "destroy",
  4481. value: function destroy() {
  4482. this.stop();
  4483. this.unbindEvent();
  4484. this.clearData();
  4485. this.map.removeOverlay(this.canvasLayer);
  4486. this.canvasLayer = null;
  4487. }
  4488. }]);
  4489. return AnimationLayer;
  4490. }(BaseLayer);
  4491. /**
  4492. * @author kyle / http://nikai.us/
  4493. */
  4494. var global$5 = typeof window === 'undefined' ? {} : window;
  4495. var BMap$3 = global$5.BMap || global$5.BMapGL;
  4496. var Layer = function (_BaseLayer) {
  4497. inherits(Layer, _BaseLayer);
  4498. function Layer(map, dataSet, options) {
  4499. classCallCheck(this, Layer);
  4500. var _this = possibleConstructorReturn(this, (Layer.__proto__ || Object.getPrototypeOf(Layer)).call(this, map, dataSet, options));
  4501. var self = _this;
  4502. var data = null;
  4503. options = options || {};
  4504. _this.clickEvent = _this.clickEvent.bind(_this);
  4505. _this.mousemoveEvent = _this.mousemoveEvent.bind(_this);
  4506. _this.tapEvent = _this.tapEvent.bind(_this);
  4507. self.init(options);
  4508. self.argCheck(options);
  4509. self.transferToMercator();
  4510. var canvasLayer = _this.canvasLayer = new CanvasLayer({
  4511. map: map,
  4512. context: _this.context,
  4513. updateImmediate: options.updateImmediate,
  4514. paneName: options.paneName,
  4515. mixBlendMode: options.mixBlendMode,
  4516. enableMassClear: options.enableMassClear,
  4517. zIndex: options.zIndex,
  4518. update: function update() {
  4519. self._canvasUpdate();
  4520. }
  4521. });
  4522. dataSet.on('change', function () {
  4523. self.transferToMercator();
  4524. canvasLayer.draw();
  4525. });
  4526. return _this;
  4527. }
  4528. createClass(Layer, [{
  4529. key: "clickEvent",
  4530. value: function clickEvent(e) {
  4531. var pixel = e.pixel;
  4532. get(Layer.prototype.__proto__ || Object.getPrototypeOf(Layer.prototype), "clickEvent", this).call(this, pixel, e);
  4533. }
  4534. }, {
  4535. key: "mousemoveEvent",
  4536. value: function mousemoveEvent(e) {
  4537. var pixel = e.pixel;
  4538. get(Layer.prototype.__proto__ || Object.getPrototypeOf(Layer.prototype), "mousemoveEvent", this).call(this, pixel, e);
  4539. }
  4540. }, {
  4541. key: "tapEvent",
  4542. value: function tapEvent(e) {
  4543. var pixel = e.pixel;
  4544. get(Layer.prototype.__proto__ || Object.getPrototypeOf(Layer.prototype), "tapEvent", this).call(this, pixel, e);
  4545. }
  4546. }, {
  4547. key: "bindEvent",
  4548. value: function bindEvent(e) {
  4549. this.unbindEvent();
  4550. var map = this.map;
  4551. var timer = 0;
  4552. var that = this;
  4553. if (this.options.methods) {
  4554. if (this.options.methods.click) {
  4555. map.setDefaultCursor("default");
  4556. map.addEventListener('click', this.clickEvent);
  4557. }
  4558. if (this.options.methods.mousemove) {
  4559. map.addEventListener('mousemove', this.mousemoveEvent);
  4560. }
  4561. if ("ontouchend" in window.document && this.options.methods.tap) {
  4562. map.addEventListener('touchstart', function (e) {
  4563. timer = new Date();
  4564. });
  4565. map.addEventListener('touchend', function (e) {
  4566. if (new Date() - timer < 300) {
  4567. that.tapEvent(e);
  4568. }
  4569. });
  4570. }
  4571. }
  4572. }
  4573. }, {
  4574. key: "unbindEvent",
  4575. value: function unbindEvent(e) {
  4576. var map = this.map;
  4577. if (this.options.methods) {
  4578. if (this.options.methods.click) {
  4579. map.removeEventListener('click', this.clickEvent);
  4580. }
  4581. if (this.options.methods.mousemove) {
  4582. map.removeEventListener('mousemove', this.mousemoveEvent);
  4583. }
  4584. }
  4585. }
  4586. // 经纬度左边转换为墨卡托坐标
  4587. }, {
  4588. key: "transferToMercator",
  4589. value: function transferToMercator(dataSet) {
  4590. if (!dataSet) {
  4591. dataSet = this.dataSet;
  4592. }
  4593. var map = this.map;
  4594. var mapType = map.getMapType();
  4595. var projection;
  4596. if (mapType.getProjection) {
  4597. projection = mapType.getProjection();
  4598. } else {
  4599. projection = {
  4600. lngLatToPoint: function lngLatToPoint(point) {
  4601. var mc = map.lnglatToMercator(point.lng, point.lat);
  4602. return {
  4603. x: mc[0],
  4604. y: mc[1]
  4605. };
  4606. }
  4607. };
  4608. }
  4609. if (this.options.coordType !== 'bd09mc') {
  4610. var data = dataSet.get();
  4611. data = dataSet.transferCoordinate(data, function (coordinates) {
  4612. if (coordinates[0] < -180 || coordinates[0] > 180 || coordinates[1] < -90 || coordinates[1] > 90) {
  4613. return coordinates;
  4614. } else {
  4615. var pixel = projection.lngLatToPoint({
  4616. lng: coordinates[0],
  4617. lat: coordinates[1]
  4618. });
  4619. return [pixel.x, pixel.y];
  4620. }
  4621. }, 'coordinates', 'coordinates_mercator');
  4622. dataSet._set(data);
  4623. }
  4624. }
  4625. }, {
  4626. key: "getContext",
  4627. value: function getContext() {
  4628. return this.canvasLayer.canvas.getContext(this.context);
  4629. }
  4630. }, {
  4631. key: "_canvasUpdate",
  4632. value: function _canvasUpdate(time) {
  4633. if (!this.canvasLayer) {
  4634. return;
  4635. }
  4636. var self = this;
  4637. var animationOptions = self.options.animation;
  4638. var map = this.canvasLayer._map;
  4639. var projection;
  4640. var mcCenter;
  4641. if (map.getMapType().getProjection) {
  4642. projection = map.getMapType().getProjection();
  4643. mcCenter = projection.lngLatToPoint(map.getCenter());
  4644. } else {
  4645. mcCenter = {
  4646. x: map.getCenter().lng,
  4647. y: map.getCenter().lat
  4648. };
  4649. if (mcCenter.x > -180 && mcCenter.x < 180) {
  4650. mcCenter = map.lnglatToMercator(mcCenter.x, mcCenter.y);
  4651. mcCenter = { x: mcCenter[0], y: mcCenter[1] };
  4652. }
  4653. projection = {
  4654. lngLatToPoint: function lngLatToPoint(point) {
  4655. var mc = map.lnglatToMercator(point.lng, point.lat);
  4656. return {
  4657. x: mc[0],
  4658. y: mc[1]
  4659. };
  4660. }
  4661. };
  4662. }
  4663. var zoomUnit;
  4664. if (projection.getZoomUnits) {
  4665. zoomUnit = projection.getZoomUnits(map.getZoom());
  4666. } else {
  4667. zoomUnit = Math.pow(2, 18 - map.getZoom());
  4668. }
  4669. var nwMc = new BMap$3.Pixel(mcCenter.x - map.getSize().width / 2 * zoomUnit, mcCenter.y + map.getSize().height / 2 * zoomUnit); //左上角墨卡托坐标
  4670. var context = this.getContext();
  4671. if (self.isEnabledTime()) {
  4672. if (time === undefined) {
  4673. clear(context);
  4674. return;
  4675. }
  4676. if (this.context == '2d') {
  4677. context.save();
  4678. context.globalCompositeOperation = 'destination-out';
  4679. context.fillStyle = 'rgba(0, 0, 0, .1)';
  4680. context.fillRect(0, 0, context.canvas.width, context.canvas.height);
  4681. context.restore();
  4682. }
  4683. } else {
  4684. clear(context);
  4685. }
  4686. if (this.context == '2d') {
  4687. for (var key in self.options) {
  4688. context[key] = self.options[key];
  4689. }
  4690. } else {
  4691. context.clear(context.COLOR_BUFFER_BIT);
  4692. }
  4693. if (self.options.minZoom && map.getZoom() < self.options.minZoom || self.options.maxZoom && map.getZoom() > self.options.maxZoom) {
  4694. return;
  4695. }
  4696. var scale = 1;
  4697. if (this.context != '2d') {
  4698. scale = this.canvasLayer.devicePixelRatio;
  4699. }
  4700. var dataGetOptions = {
  4701. fromColumn: self.options.coordType == 'bd09mc' ? 'coordinates' : 'coordinates_mercator',
  4702. transferCoordinate: function transferCoordinate(coordinate) {
  4703. var x = (coordinate[0] - nwMc.x) / zoomUnit * scale;
  4704. var y = (nwMc.y - coordinate[1]) / zoomUnit * scale;
  4705. return [x, y];
  4706. }
  4707. };
  4708. if (time !== undefined) {
  4709. dataGetOptions.filter = function (item) {
  4710. var trails = animationOptions.trails || 10;
  4711. if (time && item.time > time - trails && item.time < time) {
  4712. return true;
  4713. } else {
  4714. return false;
  4715. }
  4716. };
  4717. }
  4718. // get data from data set
  4719. var data;
  4720. if (self.options.draw === 'cluster') {
  4721. var bounds = this.map.getBounds();
  4722. var ne = bounds.getNorthEast();
  4723. var sw = bounds.getSouthWest();
  4724. var clusterData = this.supercluster.getClusters([sw.lng, sw.lat, ne.lng, ne.lat], this.getZoom());
  4725. this.clusterDataSet.set(clusterData);
  4726. this.transferToMercator(this.clusterDataSet);
  4727. data = this.clusterDataSet.get(dataGetOptions);
  4728. } else {
  4729. data = self.dataSet.get(dataGetOptions);
  4730. }
  4731. this.processData(data);
  4732. var nwPixel = map.pointToPixel(new BMap$3.Point(0, 0));
  4733. if (self.options.unit == 'm') {
  4734. if (self.options.size) {
  4735. self.options._size = self.options.size / zoomUnit;
  4736. }
  4737. if (self.options.width) {
  4738. self.options._width = self.options.width / zoomUnit;
  4739. }
  4740. if (self.options.height) {
  4741. self.options._height = self.options.height / zoomUnit;
  4742. }
  4743. } else {
  4744. self.options._size = self.options.size;
  4745. self.options._height = self.options.height;
  4746. self.options._width = self.options.width;
  4747. }
  4748. this.drawContext(context, data, self.options, nwPixel);
  4749. //console.timeEnd('draw');
  4750. //console.timeEnd('update')
  4751. self.options.updateCallback && self.options.updateCallback(time);
  4752. }
  4753. }, {
  4754. key: "init",
  4755. value: function init(options) {
  4756. var self = this;
  4757. self.options = options;
  4758. this.initDataRange(options);
  4759. this.context = self.options.context || '2d';
  4760. if (self.options.zIndex) {
  4761. this.canvasLayer && this.canvasLayer.setZIndex(self.options.zIndex);
  4762. }
  4763. if (self.options.max) {
  4764. this.intensity.setMax(self.options.max);
  4765. }
  4766. if (self.options.min) {
  4767. this.intensity.setMin(self.options.min);
  4768. }
  4769. this.initAnimator();
  4770. this.bindEvent();
  4771. }
  4772. }, {
  4773. key: "getZoom",
  4774. value: function getZoom() {
  4775. return this.map.getZoom();
  4776. }
  4777. }, {
  4778. key: "addAnimatorEvent",
  4779. value: function addAnimatorEvent() {
  4780. this.map.addEventListener('movestart', this.animatorMovestartEvent.bind(this));
  4781. this.map.addEventListener('moveend', this.animatorMoveendEvent.bind(this));
  4782. }
  4783. }, {
  4784. key: "show",
  4785. value: function show() {
  4786. this.map.addOverlay(this.canvasLayer);
  4787. }
  4788. }, {
  4789. key: "hide",
  4790. value: function hide() {
  4791. this.map.removeOverlay(this.canvasLayer);
  4792. }
  4793. }, {
  4794. key: "draw",
  4795. value: function draw() {
  4796. this.canvasLayer && this.canvasLayer.draw();
  4797. }
  4798. }, {
  4799. key: "clearData",
  4800. value: function clearData() {
  4801. this.dataSet && this.dataSet.clear();
  4802. this.update({
  4803. options: null
  4804. });
  4805. }
  4806. }, {
  4807. key: "destroy",
  4808. value: function destroy() {
  4809. this.unbindEvent();
  4810. this.clearData();
  4811. this.map.removeOverlay(this.canvasLayer);
  4812. this.canvasLayer = null;
  4813. }
  4814. }]);
  4815. return Layer;
  4816. }(BaseLayer);
  4817. /**
  4818. * Copyright 2012 Google Inc. All Rights Reserved.
  4819. *
  4820. * Licensed under the Apache License, Version 2.0 (the "License");
  4821. * you may not use this file except in compliance with the License.
  4822. * You may obtain a copy of the License at
  4823. *
  4824. * http://www.apache.org/licenses/LICENSE-2.0
  4825. *
  4826. * Unless required by applicable law or agreed to in writing, software
  4827. * distributed under the License is distributed on an "AS IS" BASIS,
  4828. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4829. * See the License for the specific language governing permissions and
  4830. * limitations under the License.
  4831. */
  4832. /**
  4833. * @fileoverview Extends OverlayView to provide a canvas "Layer".
  4834. * @author Brendan Kenny
  4835. */
  4836. /**
  4837. * A map layer that provides a canvas over the slippy map and a callback
  4838. * system for efficient animation. Requires canvas and CSS 2D transform
  4839. * support.
  4840. * @constructor
  4841. * @extends google.maps.OverlayView
  4842. * @param {CanvasLayerOptions=} opt_options Options to set in this CanvasLayer.
  4843. */
  4844. function CanvasLayer$2(opt_options) {
  4845. /**
  4846. * If true, canvas is in a map pane and the OverlayView is fully functional.
  4847. * See google.maps.OverlayView.onAdd for more information.
  4848. * @type {boolean}
  4849. * @private
  4850. */
  4851. this.isAdded_ = false;
  4852. /**
  4853. * If true, each update will immediately schedule the next.
  4854. * @type {boolean}
  4855. * @private
  4856. */
  4857. this.isAnimated_ = false;
  4858. /**
  4859. * The name of the MapPane in which this layer will be displayed.
  4860. * @type {string}
  4861. * @private
  4862. */
  4863. this.paneName_ = CanvasLayer$2.DEFAULT_PANE_NAME_;
  4864. /**
  4865. * A user-supplied function called whenever an update is required. Null or
  4866. * undefined if a callback is not provided.
  4867. * @type {?function=}
  4868. * @private
  4869. */
  4870. this.updateHandler_ = null;
  4871. /**
  4872. * A user-supplied function called whenever an update is required and the
  4873. * map has been resized since the last update. Null or undefined if a
  4874. * callback is not provided.
  4875. * @type {?function}
  4876. * @private
  4877. */
  4878. this.resizeHandler_ = null;
  4879. /**
  4880. * The LatLng coordinate of the top left of the current view of the map. Will
  4881. * be null when this.isAdded_ is false.
  4882. * @type {google.maps.LatLng}
  4883. * @private
  4884. */
  4885. this.topLeft_ = null;
  4886. /**
  4887. * The map-pan event listener. Will be null when this.isAdded_ is false. Will
  4888. * be null when this.isAdded_ is false.
  4889. * @type {?function}
  4890. * @private
  4891. */
  4892. this.centerListener_ = null;
  4893. /**
  4894. * The map-resize event listener. Will be null when this.isAdded_ is false.
  4895. * @type {?function}
  4896. * @private
  4897. */
  4898. this.resizeListener_ = null;
  4899. /**
  4900. * If true, the map size has changed and this.resizeHandler_ must be called
  4901. * on the next update.
  4902. * @type {boolean}
  4903. * @private
  4904. */
  4905. this.needsResize_ = true;
  4906. /**
  4907. * A browser-defined id for the currently requested callback. Null when no
  4908. * callback is queued.
  4909. * @type {?number}
  4910. * @private
  4911. */
  4912. this.requestAnimationFrameId_ = null;
  4913. var canvas = document.createElement('canvas');
  4914. canvas.style.position = 'absolute';
  4915. canvas.style.top = 0;
  4916. canvas.style.left = 0;
  4917. canvas.style.pointerEvents = 'none';
  4918. /**
  4919. * The canvas element.
  4920. * @type {!HTMLCanvasElement}
  4921. */
  4922. this.canvas = canvas;
  4923. /**
  4924. * The CSS width of the canvas, which may be different than the width of the
  4925. * backing store.
  4926. * @private {number}
  4927. */
  4928. this.canvasCssWidth_ = 300;
  4929. /**
  4930. * The CSS height of the canvas, which may be different than the height of
  4931. * the backing store.
  4932. * @private {number}
  4933. */
  4934. this.canvasCssHeight_ = 150;
  4935. /**
  4936. * A value for scaling the CanvasLayer resolution relative to the CanvasLayer
  4937. * display size.
  4938. * @private {number}
  4939. */
  4940. this.resolutionScale_ = 1;
  4941. /**
  4942. * Simple bind for functions with no args for bind-less browsers (Safari).
  4943. * @param {Object} thisArg The this value used for the target function.
  4944. * @param {function} func The function to be bound.
  4945. */
  4946. function simpleBindShim(thisArg, func) {
  4947. return function () {
  4948. func.apply(thisArg);
  4949. };
  4950. }
  4951. /**
  4952. * A reference to this.repositionCanvas_ with this bound as its this value.
  4953. * @type {function}
  4954. * @private
  4955. */
  4956. this.repositionFunction_ = simpleBindShim(this, this.repositionCanvas_);
  4957. /**
  4958. * A reference to this.resize_ with this bound as its this value.
  4959. * @type {function}
  4960. * @private
  4961. */
  4962. this.resizeFunction_ = simpleBindShim(this, this.resize_);
  4963. /**
  4964. * A reference to this.update_ with this bound as its this value.
  4965. * @type {function}
  4966. * @private
  4967. */
  4968. this.requestUpdateFunction_ = simpleBindShim(this, this.update_);
  4969. // set provided options, if any
  4970. if (opt_options) {
  4971. this.setOptions(opt_options);
  4972. }
  4973. }
  4974. var global$6 = typeof window === 'undefined' ? {} : window;
  4975. if (global$6.google && global$6.google.maps) {
  4976. CanvasLayer$2.prototype = new google.maps.OverlayView();
  4977. /**
  4978. * The default MapPane to contain the canvas.
  4979. * @type {string}
  4980. * @const
  4981. * @private
  4982. */
  4983. CanvasLayer$2.DEFAULT_PANE_NAME_ = 'overlayLayer';
  4984. /**
  4985. * Transform CSS property name, with vendor prefix if required. If browser
  4986. * does not support transforms, property will be ignored.
  4987. * @type {string}
  4988. * @const
  4989. * @private
  4990. */
  4991. CanvasLayer$2.CSS_TRANSFORM_ = function () {
  4992. var div = document.createElement('div');
  4993. var transformProps = ['transform', 'WebkitTransform', 'MozTransform', 'OTransform', 'msTransform'];
  4994. for (var i = 0; i < transformProps.length; i++) {
  4995. var prop = transformProps[i];
  4996. if (div.style[prop] !== undefined) {
  4997. return prop;
  4998. }
  4999. }
  5000. // return unprefixed version by default
  5001. return transformProps[0];
  5002. }();
  5003. /**
  5004. * The requestAnimationFrame function, with vendor-prefixed or setTimeout-based
  5005. * fallbacks. MUST be called with window as thisArg.
  5006. * @type {function}
  5007. * @param {function} callback The function to add to the frame request queue.
  5008. * @return {number} The browser-defined id for the requested callback.
  5009. * @private
  5010. */
  5011. CanvasLayer$2.prototype.requestAnimFrame_ = global$6.requestAnimationFrame || global$6.webkitRequestAnimationFrame || global$6.mozRequestAnimationFrame || global$6.oRequestAnimationFrame || global$6.msRequestAnimationFrame || function (callback) {
  5012. return global$6.setTimeout(callback, 1000 / 60);
  5013. };
  5014. /**
  5015. * The cancelAnimationFrame function, with vendor-prefixed fallback. Does not
  5016. * fall back to clearTimeout as some platforms implement requestAnimationFrame
  5017. * but not cancelAnimationFrame, and the cost is an extra frame on onRemove.
  5018. * MUST be called with window as thisArg.
  5019. * @type {function}
  5020. * @param {number=} requestId The id of the frame request to cancel.
  5021. * @private
  5022. */
  5023. CanvasLayer$2.prototype.cancelAnimFrame_ = global$6.cancelAnimationFrame || global$6.webkitCancelAnimationFrame || global$6.mozCancelAnimationFrame || global$6.oCancelAnimationFrame || global$6.msCancelAnimationFrame || function (requestId) {};
  5024. /**
  5025. * Sets any options provided. See CanvasLayerOptions for more information.
  5026. * @param {CanvasLayerOptions} options The options to set.
  5027. */
  5028. CanvasLayer$2.prototype.setOptions = function (options) {
  5029. if (options.animate !== undefined) {
  5030. this.setAnimate(options.animate);
  5031. }
  5032. if (options.paneName !== undefined) {
  5033. this.setPaneName(options.paneName);
  5034. }
  5035. if (options.updateHandler !== undefined) {
  5036. this.setUpdateHandler(options.updateHandler);
  5037. }
  5038. if (options.resizeHandler !== undefined) {
  5039. this.setResizeHandler(options.resizeHandler);
  5040. }
  5041. if (options.resolutionScale !== undefined) {
  5042. this.setResolutionScale(options.resolutionScale);
  5043. }
  5044. if (options.map !== undefined) {
  5045. this.setMap(options.map);
  5046. }
  5047. };
  5048. /**
  5049. * Set the animated state of the layer. If true, updateHandler will be called
  5050. * repeatedly, once per frame. If false, updateHandler will only be called when
  5051. * a map property changes that could require the canvas content to be redrawn.
  5052. * @param {boolean} animate Whether the canvas is animated.
  5053. */
  5054. CanvasLayer$2.prototype.setAnimate = function (animate) {
  5055. this.isAnimated_ = !!animate;
  5056. if (this.isAnimated_) {
  5057. this.scheduleUpdate();
  5058. }
  5059. };
  5060. /**
  5061. * @return {boolean} Whether the canvas is animated.
  5062. */
  5063. CanvasLayer$2.prototype.isAnimated = function () {
  5064. return this.isAnimated_;
  5065. };
  5066. /**
  5067. * Set the MapPane in which this layer will be displayed, by name. See
  5068. * {@code google.maps.MapPanes} for the panes available.
  5069. * @param {string} paneName The name of the desired MapPane.
  5070. */
  5071. CanvasLayer$2.prototype.setPaneName = function (paneName) {
  5072. this.paneName_ = paneName;
  5073. this.setPane_();
  5074. };
  5075. /**
  5076. * @return {string} The name of the current container pane.
  5077. */
  5078. CanvasLayer$2.prototype.getPaneName = function () {
  5079. return this.paneName_;
  5080. };
  5081. /**
  5082. * Adds the canvas to the specified container pane. Since this is guaranteed to
  5083. * execute only after onAdd is called, this is when paneName's existence is
  5084. * checked (and an error is thrown if it doesn't exist).
  5085. * @private
  5086. */
  5087. CanvasLayer$2.prototype.setPane_ = function () {
  5088. if (!this.isAdded_) {
  5089. return;
  5090. }
  5091. // onAdd has been called, so panes can be used
  5092. var panes = this.getPanes();
  5093. if (!panes[this.paneName_]) {
  5094. throw new Error('"' + this.paneName_ + '" is not a valid MapPane name.');
  5095. }
  5096. panes[this.paneName_].appendChild(this.canvas);
  5097. };
  5098. /**
  5099. * Set a function that will be called whenever the parent map and the overlay's
  5100. * canvas have been resized. If opt_resizeHandler is null or unspecified, any
  5101. * existing callback is removed.
  5102. * @param {?function=} opt_resizeHandler The resize callback function.
  5103. */
  5104. CanvasLayer$2.prototype.setResizeHandler = function (opt_resizeHandler) {
  5105. this.resizeHandler_ = opt_resizeHandler;
  5106. };
  5107. /**
  5108. * Sets a value for scaling the canvas resolution relative to the canvas
  5109. * display size. This can be used to save computation by scaling the backing
  5110. * buffer down, or to support high DPI devices by scaling it up (by e.g.
  5111. * window.devicePixelRatio).
  5112. * @param {number} scale
  5113. */
  5114. CanvasLayer$2.prototype.setResolutionScale = function (scale) {
  5115. if (typeof scale === 'number') {
  5116. this.resolutionScale_ = scale;
  5117. this.resize_();
  5118. }
  5119. };
  5120. /**
  5121. * Set a function that will be called when a repaint of the canvas is required.
  5122. * If opt_updateHandler is null or unspecified, any existing callback is
  5123. * removed.
  5124. * @param {?function=} opt_updateHandler The update callback function.
  5125. */
  5126. CanvasLayer$2.prototype.setUpdateHandler = function (opt_updateHandler) {
  5127. this.updateHandler_ = opt_updateHandler;
  5128. };
  5129. /**
  5130. * @inheritDoc
  5131. */
  5132. CanvasLayer$2.prototype.onAdd = function () {
  5133. if (this.isAdded_) {
  5134. return;
  5135. }
  5136. this.isAdded_ = true;
  5137. this.setPane_();
  5138. this.resizeListener_ = google.maps.event.addListener(this.getMap(), 'resize', this.resizeFunction_);
  5139. this.centerListener_ = google.maps.event.addListener(this.getMap(), 'center_changed', this.repositionFunction_);
  5140. this.resize_();
  5141. this.repositionCanvas_();
  5142. };
  5143. /**
  5144. * @inheritDoc
  5145. */
  5146. CanvasLayer$2.prototype.onRemove = function () {
  5147. if (!this.isAdded_) {
  5148. return;
  5149. }
  5150. this.isAdded_ = false;
  5151. this.topLeft_ = null;
  5152. // remove canvas and listeners for pan and resize from map
  5153. this.canvas.parentElement.removeChild(this.canvas);
  5154. if (this.centerListener_) {
  5155. google.maps.event.removeListener(this.centerListener_);
  5156. this.centerListener_ = null;
  5157. }
  5158. if (this.resizeListener_) {
  5159. google.maps.event.removeListener(this.resizeListener_);
  5160. this.resizeListener_ = null;
  5161. }
  5162. // cease canvas update callbacks
  5163. if (this.requestAnimationFrameId_) {
  5164. this.cancelAnimFrame_.call(global$6, this.requestAnimationFrameId_);
  5165. this.requestAnimationFrameId_ = null;
  5166. }
  5167. };
  5168. /**
  5169. * The internal callback for resize events that resizes the canvas to keep the
  5170. * map properly covered.
  5171. * @private
  5172. */
  5173. CanvasLayer$2.prototype.resize_ = function () {
  5174. if (!this.isAdded_) {
  5175. return;
  5176. }
  5177. var map = this.getMap();
  5178. var mapWidth = map.getDiv().offsetWidth;
  5179. var mapHeight = map.getDiv().offsetHeight;
  5180. var newWidth = mapWidth * this.resolutionScale_;
  5181. var newHeight = mapHeight * this.resolutionScale_;
  5182. var oldWidth = this.canvas.width;
  5183. var oldHeight = this.canvas.height;
  5184. // resizing may allocate a new back buffer, so do so conservatively
  5185. if (oldWidth !== newWidth || oldHeight !== newHeight) {
  5186. this.canvas.width = newWidth;
  5187. this.canvas.height = newHeight;
  5188. this.needsResize_ = true;
  5189. this.scheduleUpdate();
  5190. }
  5191. // reset styling if new sizes don't match; resize of data not needed
  5192. if (this.canvasCssWidth_ !== mapWidth || this.canvasCssHeight_ !== mapHeight) {
  5193. this.canvasCssWidth_ = mapWidth;
  5194. this.canvasCssHeight_ = mapHeight;
  5195. this.canvas.style.width = mapWidth + 'px';
  5196. this.canvas.style.height = mapHeight + 'px';
  5197. }
  5198. };
  5199. /**
  5200. * @inheritDoc
  5201. */
  5202. CanvasLayer$2.prototype.draw = function () {
  5203. this.repositionCanvas_();
  5204. };
  5205. /**
  5206. * Internal callback for map view changes. Since the Maps API moves the overlay
  5207. * along with the map, this function calculates the opposite translation to
  5208. * keep the canvas in place.
  5209. * @private
  5210. */
  5211. CanvasLayer$2.prototype.repositionCanvas_ = function () {
  5212. // TODO(bckenny): *should* only be executed on RAF, but in current browsers
  5213. // this causes noticeable hitches in map and overlay relative
  5214. // positioning.
  5215. var map = this.getMap();
  5216. // topLeft can't be calculated from map.getBounds(), because bounds are
  5217. // clamped to -180 and 180 when completely zoomed out. Instead, calculate
  5218. // left as an offset from the center, which is an unwrapped LatLng.
  5219. var top = map.getBounds().getNorthEast().lat();
  5220. var center = map.getCenter();
  5221. var scale = Math.pow(2, map.getZoom());
  5222. var left = center.lng() - this.canvasCssWidth_ * 180 / (256 * scale);
  5223. this.topLeft_ = new google.maps.LatLng(top, left);
  5224. // Canvas position relative to draggable map's container depends on
  5225. // overlayView's projection, not the map's. Have to use the center of the
  5226. // map for this, not the top left, for the same reason as above.
  5227. var projection = this.getProjection();
  5228. var divCenter = projection.fromLatLngToDivPixel(center);
  5229. var offsetX = -Math.round(this.canvasCssWidth_ / 2 - divCenter.x);
  5230. var offsetY = -Math.round(this.canvasCssHeight_ / 2 - divCenter.y);
  5231. this.canvas.style[CanvasLayer$2.CSS_TRANSFORM_] = 'translate(' + offsetX + 'px,' + offsetY + 'px)';
  5232. this.scheduleUpdate();
  5233. };
  5234. /**
  5235. * Internal callback that serves as main animation scheduler via
  5236. * requestAnimationFrame. Calls resize and update callbacks if set, and
  5237. * schedules the next frame if overlay is animated.
  5238. * @private
  5239. */
  5240. CanvasLayer$2.prototype.update_ = function () {
  5241. this.requestAnimationFrameId_ = null;
  5242. if (!this.isAdded_) {
  5243. return;
  5244. }
  5245. if (this.isAnimated_) {
  5246. this.scheduleUpdate();
  5247. }
  5248. if (this.needsResize_ && this.resizeHandler_) {
  5249. this.needsResize_ = false;
  5250. this.resizeHandler_();
  5251. }
  5252. if (this.updateHandler_) {
  5253. this.updateHandler_();
  5254. }
  5255. };
  5256. /**
  5257. * A convenience method to get the current LatLng coordinate of the top left of
  5258. * the current view of the map.
  5259. * @return {google.maps.LatLng} The top left coordinate.
  5260. */
  5261. CanvasLayer$2.prototype.getTopLeft = function () {
  5262. return this.topLeft_;
  5263. };
  5264. /**
  5265. * Schedule a requestAnimationFrame callback to updateHandler. If one is
  5266. * already scheduled, there is no effect.
  5267. */
  5268. CanvasLayer$2.prototype.scheduleUpdate = function () {
  5269. if (this.isAdded_ && !this.requestAnimationFrameId_) {
  5270. this.requestAnimationFrameId_ = this.requestAnimFrame_.call(global$6, this.requestUpdateFunction_);
  5271. }
  5272. };
  5273. }
  5274. /**
  5275. * @author kyle / http://nikai.us/
  5276. */
  5277. var Layer$2 = function (_BaseLayer) {
  5278. inherits(Layer, _BaseLayer);
  5279. function Layer(map, dataSet, options) {
  5280. classCallCheck(this, Layer);
  5281. var _this = possibleConstructorReturn(this, (Layer.__proto__ || Object.getPrototypeOf(Layer)).call(this, map, dataSet, options));
  5282. var self = _this;
  5283. var data = null;
  5284. options = options || {};
  5285. self.init(options);
  5286. self.argCheck(options);
  5287. var canvasLayerOptions = {
  5288. map: map,
  5289. animate: false,
  5290. updateHandler: function updateHandler() {
  5291. self._canvasUpdate();
  5292. },
  5293. resolutionScale: resolutionScale
  5294. };
  5295. var canvasLayer = _this.canvasLayer = new CanvasLayer$2(canvasLayerOptions);
  5296. _this.clickEvent = _this.clickEvent.bind(_this);
  5297. _this.mousemoveEvent = _this.mousemoveEvent.bind(_this);
  5298. _this.bindEvent();
  5299. return _this;
  5300. }
  5301. createClass(Layer, [{
  5302. key: "clickEvent",
  5303. value: function clickEvent(e) {
  5304. var pixel = e.pixel;
  5305. get(Layer.prototype.__proto__ || Object.getPrototypeOf(Layer.prototype), "clickEvent", this).call(this, pixel, e);
  5306. }
  5307. }, {
  5308. key: "mousemoveEvent",
  5309. value: function mousemoveEvent(e) {
  5310. var pixel = e.pixel;
  5311. get(Layer.prototype.__proto__ || Object.getPrototypeOf(Layer.prototype), "mousemoveEvent", this).call(this, pixel, e);
  5312. }
  5313. }, {
  5314. key: "bindEvent",
  5315. value: function bindEvent(e) {
  5316. var map = this.map;
  5317. if (this.options.methods) {
  5318. if (this.options.methods.click) {
  5319. map.setDefaultCursor("default");
  5320. map.addListener('click', this.clickEvent);
  5321. }
  5322. if (this.options.methods.mousemove) {
  5323. map.addListener('mousemove', this.mousemoveEvent);
  5324. }
  5325. }
  5326. }
  5327. }, {
  5328. key: "unbindEvent",
  5329. value: function unbindEvent(e) {
  5330. var map = this.map;
  5331. if (this.options.methods) {
  5332. if (this.options.methods.click) {
  5333. map.removeListener('click', this.clickEvent);
  5334. }
  5335. if (this.options.methods.mousemove) {
  5336. map.removeListener('mousemove', this.mousemoveEvent);
  5337. }
  5338. }
  5339. }
  5340. }, {
  5341. key: "getContext",
  5342. value: function getContext() {
  5343. return this.canvasLayer.canvas.getContext(this.context);
  5344. }
  5345. }, {
  5346. key: "_canvasUpdate",
  5347. value: function _canvasUpdate(time) {
  5348. if (!this.canvasLayer) {
  5349. return;
  5350. }
  5351. var self = this;
  5352. var animationOptions = self.options.animation;
  5353. var context = this.getContext();
  5354. if (self.isEnabledTime()) {
  5355. if (time === undefined) {
  5356. clear(context);
  5357. return;
  5358. }
  5359. if (this.context == '2d') {
  5360. context.save();
  5361. context.globalCompositeOperation = 'destination-out';
  5362. context.fillStyle = 'rgba(0, 0, 0, .1)';
  5363. context.fillRect(0, 0, context.canvas.width, context.canvas.height);
  5364. context.restore();
  5365. }
  5366. } else {
  5367. clear(context);
  5368. }
  5369. if (this.context == '2d') {
  5370. for (var key in self.options) {
  5371. context[key] = self.options[key];
  5372. }
  5373. } else {
  5374. context.clear(context.COLOR_BUFFER_BIT);
  5375. }
  5376. if (self.options.minZoom && map.getZoom() < self.options.minZoom || self.options.maxZoom && map.getZoom() > self.options.maxZoom) {
  5377. return;
  5378. }
  5379. var scale = 1;
  5380. if (this.context != '2d') {
  5381. scale = this.canvasLayer.devicePixelRatio;
  5382. }
  5383. var map = this.map;
  5384. var mapProjection = map.getProjection();
  5385. var scale = Math.pow(2, map.zoom) * resolutionScale;
  5386. var offset = mapProjection.fromLatLngToPoint(this.canvasLayer.getTopLeft());
  5387. var dataGetOptions = {
  5388. //fromColumn: self.options.coordType == 'bd09mc' ? 'coordinates' : 'coordinates_mercator',
  5389. transferCoordinate: function transferCoordinate(coordinate) {
  5390. var latLng = new google.maps.LatLng(coordinate[1], coordinate[0]);
  5391. var worldPoint = mapProjection.fromLatLngToPoint(latLng);
  5392. var pixel = {
  5393. x: (worldPoint.x - offset.x) * scale,
  5394. y: (worldPoint.y - offset.y) * scale
  5395. };
  5396. return [pixel.x, pixel.y];
  5397. }
  5398. };
  5399. if (time !== undefined) {
  5400. dataGetOptions.filter = function (item) {
  5401. var trails = animationOptions.trails || 10;
  5402. if (time && item.time > time - trails && item.time < time) {
  5403. return true;
  5404. } else {
  5405. return false;
  5406. }
  5407. };
  5408. }
  5409. // get data from data set
  5410. var data = self.dataSet.get(dataGetOptions);
  5411. this.processData(data);
  5412. var latLng = new google.maps.LatLng(0, 0);
  5413. var worldPoint = mapProjection.fromLatLngToPoint(latLng);
  5414. var pixel = {
  5415. x: (worldPoint.x - offset.x) * scale,
  5416. y: (worldPoint.y - offset.y) * scale
  5417. };
  5418. if (self.options.unit == 'm' && self.options.size) {
  5419. self.options._size = self.options.size / zoomUnit;
  5420. } else {
  5421. self.options._size = self.options.size;
  5422. }
  5423. this.drawContext(context, new DataSet(data), self.options, pixel);
  5424. //console.timeEnd('draw');
  5425. //console.timeEnd('update')
  5426. self.options.updateCallback && self.options.updateCallback(time);
  5427. }
  5428. }, {
  5429. key: "init",
  5430. value: function init(options) {
  5431. var self = this;
  5432. self.options = options;
  5433. this.initDataRange(options);
  5434. this.context = self.options.context || '2d';
  5435. if (self.options.zIndex) {
  5436. this.canvasLayer && this.canvasLayer.setZIndex(self.options.zIndex);
  5437. }
  5438. this.initAnimator();
  5439. }
  5440. }, {
  5441. key: "addAnimatorEvent",
  5442. value: function addAnimatorEvent() {
  5443. this.map.addListener('movestart', this.animatorMovestartEvent.bind(this));
  5444. this.map.addListener('moveend', this.animatorMoveendEvent.bind(this));
  5445. }
  5446. }, {
  5447. key: "show",
  5448. value: function show() {
  5449. this.map.addOverlay(this.canvasLayer);
  5450. }
  5451. }, {
  5452. key: "hide",
  5453. value: function hide() {
  5454. this.map.removeOverlay(this.canvasLayer);
  5455. }
  5456. }, {
  5457. key: "draw",
  5458. value: function draw() {
  5459. self.canvasLayer.draw();
  5460. }
  5461. }]);
  5462. return Layer;
  5463. }(BaseLayer);
  5464. /**
  5465. * MapV for maptalks.js (https://github.com/maptalks/maptalks.js)
  5466. * @author fuzhenn / https://github.com/fuzhenn
  5467. */
  5468. // import * as maptalks from 'maptalks';
  5469. var Layer$4 = void 0;
  5470. if (typeof maptalks !== 'undefined') {
  5471. Layer$4 = function (_maptalks$Layer) {
  5472. inherits(Layer, _maptalks$Layer);
  5473. function Layer(id, dataSet, options) {
  5474. classCallCheck(this, Layer);
  5475. var _this = possibleConstructorReturn(this, (Layer.__proto__ || Object.getPrototypeOf(Layer)).call(this, id, options));
  5476. _this.options_ = options;
  5477. _this.dataSet = dataSet;
  5478. _this._initBaseLayer(options);
  5479. return _this;
  5480. }
  5481. createClass(Layer, [{
  5482. key: "_initBaseLayer",
  5483. value: function _initBaseLayer(options) {
  5484. var self = this;
  5485. var baseLayer = this.baseLayer = new BaseLayer(null, this.dataSet, options);
  5486. self.init(options);
  5487. baseLayer.argCheck(options);
  5488. }
  5489. }, {
  5490. key: "clickEvent",
  5491. value: function clickEvent(e) {
  5492. if (!this.baseLayer) {
  5493. return;
  5494. }
  5495. var pixel = e.containerPoint;
  5496. this.baseLayer.clickEvent(pixel, e.domEvent);
  5497. }
  5498. }, {
  5499. key: "mousemoveEvent",
  5500. value: function mousemoveEvent(e) {
  5501. if (!this.baseLayer) {
  5502. return;
  5503. }
  5504. var pixel = e.containerPoint;
  5505. this.baseLayer.mousemoveEvent(pixel, e.domEvent);
  5506. }
  5507. }, {
  5508. key: "getEvents",
  5509. value: function getEvents() {
  5510. return {
  5511. 'click': this.clickEvent,
  5512. 'mousemove': this.mousemoveEvent
  5513. };
  5514. }
  5515. }, {
  5516. key: "init",
  5517. value: function init(options) {
  5518. var base = this.baseLayer;
  5519. base.options = options;
  5520. base.initDataRange(options);
  5521. base.context = base.options.context || '2d';
  5522. base.initAnimator();
  5523. }
  5524. }, {
  5525. key: "addAnimatorEvent",
  5526. value: function addAnimatorEvent() {
  5527. this.map.addListener('movestart', this.animatorMovestartEvent.bind(this));
  5528. this.map.addListener('moveend', this.animatorMoveendEvent.bind(this));
  5529. }
  5530. }]);
  5531. return Layer;
  5532. }(maptalks.Layer);
  5533. var LayerRenderer = function (_maptalks$renderer$Ca) {
  5534. inherits(LayerRenderer, _maptalks$renderer$Ca);
  5535. function LayerRenderer() {
  5536. classCallCheck(this, LayerRenderer);
  5537. return possibleConstructorReturn(this, (LayerRenderer.__proto__ || Object.getPrototypeOf(LayerRenderer)).apply(this, arguments));
  5538. }
  5539. createClass(LayerRenderer, [{
  5540. key: "needToRedraw",
  5541. value: function needToRedraw() {
  5542. var base = this.layer.baseLayer;
  5543. if (base.isEnabledTime()) {
  5544. return true;
  5545. }
  5546. return get(LayerRenderer.prototype.__proto__ || Object.getPrototypeOf(LayerRenderer.prototype), "needToRedraw", this).call(this);
  5547. }
  5548. }, {
  5549. key: "draw",
  5550. value: function draw() {
  5551. var base = this.layer.baseLayer;
  5552. if (!this.canvas || !base.isEnabledTime() || this._shouldClear) {
  5553. this.prepareCanvas();
  5554. this._shouldClear = false;
  5555. }
  5556. this._update(this.gl || this.context, this._mapvFrameTime);
  5557. delete this._mapvFrameTime;
  5558. this.completeRender();
  5559. }
  5560. }, {
  5561. key: "drawOnInteracting",
  5562. value: function drawOnInteracting() {
  5563. this.draw();
  5564. this._shouldClear = false;
  5565. }
  5566. }, {
  5567. key: "onSkipDrawOnInteracting",
  5568. value: function onSkipDrawOnInteracting() {
  5569. this._shouldClear = true;
  5570. }
  5571. }, {
  5572. key: "_canvasUpdate",
  5573. value: function _canvasUpdate(time) {
  5574. this.setToRedraw();
  5575. this._mapvFrameTime = time;
  5576. }
  5577. }, {
  5578. key: "_update",
  5579. value: function _update(context, time) {
  5580. if (!this.canvas) {
  5581. return;
  5582. }
  5583. var self = this.layer.baseLayer;
  5584. var animationOptions = self.options.animation;
  5585. var map = this.getMap();
  5586. if (self.isEnabledTime()) {
  5587. if (time === undefined) {
  5588. clear(context);
  5589. return;
  5590. }
  5591. if (self.context == '2d') {
  5592. context.save();
  5593. context.globalCompositeOperation = 'destination-out';
  5594. context.fillStyle = 'rgba(0, 0, 0, .1)';
  5595. context.fillRect(0, 0, context.canvas.width, context.canvas.height);
  5596. context.restore();
  5597. }
  5598. } else {
  5599. clear(context);
  5600. }
  5601. if (self.context == '2d') {
  5602. for (var key in self.options) {
  5603. context[key] = self.options[key];
  5604. }
  5605. } else {
  5606. context.clear(context.COLOR_BUFFER_BIT);
  5607. }
  5608. var scale = 1;
  5609. if (self.context === '2d' && self.options.draw !== 'heatmap') {
  5610. //in heatmap.js, devicePixelRatio is being mulitplied independently
  5611. scale = self.canvasLayer.devicePixelRatio;
  5612. }
  5613. //reuse to save coordinate instance creation
  5614. var coord = new maptalks.Coordinate(0, 0);
  5615. var dataGetOptions = {
  5616. fromColumn: self.options.coordType === 'bd09mc' ? 'coordinates_mercator' : 'coordinates',
  5617. transferCoordinate: function transferCoordinate(coordinate) {
  5618. coord.x = coordinate[0];
  5619. coord.y = coordinate[1];
  5620. var r = map.coordToContainerPoint(coord)._multi(scale).toArray();
  5621. return r;
  5622. }
  5623. };
  5624. if (time !== undefined) {
  5625. dataGetOptions.filter = function (item) {
  5626. var trails = animationOptions.trails || 10;
  5627. if (time && item.time > time - trails && item.time < time) {
  5628. return true;
  5629. } else {
  5630. return false;
  5631. }
  5632. };
  5633. }
  5634. // get data from data set
  5635. var data = self.dataSet.get(dataGetOptions);
  5636. self.processData(data);
  5637. if (self.options.unit == 'm') {
  5638. if (self.options.size) {
  5639. self.options._size = self.options.size / zoomUnit;
  5640. }
  5641. if (self.options.width) {
  5642. self.options._width = self.options.width / zoomUnit;
  5643. }
  5644. if (self.options.height) {
  5645. self.options._height = self.options.height / zoomUnit;
  5646. }
  5647. } else {
  5648. self.options._size = self.options.size;
  5649. self.options._height = self.options.height;
  5650. self.options._width = self.options.width;
  5651. }
  5652. var zeroZero = new maptalks.Point(0, 0);
  5653. //screen position of the [0, 0] point
  5654. var zeroZeroScreen = map._pointToContainerPoint(zeroZero)._multi(scale);
  5655. self.drawContext(context, data, self.options, zeroZeroScreen);
  5656. //console.timeEnd('draw');
  5657. //console.timeEnd('update')
  5658. self.options.updateCallback && self.options.updateCallback(time);
  5659. }
  5660. }, {
  5661. key: "createCanvas",
  5662. value: function createCanvas() {
  5663. if (this.canvas) {
  5664. return;
  5665. }
  5666. var map = this.getMap();
  5667. var size = map.getSize();
  5668. var r = maptalks.Browser.retina ? 2 : 1,
  5669. w = r * size.width,
  5670. h = r * size.height;
  5671. this.canvas = maptalks.Canvas.createCanvas(w, h, map.CanvasClass);
  5672. var mapvContext = this.layer.baseLayer.context;
  5673. if (mapvContext === '2d') {
  5674. this.context = this.canvas.getContext('2d');
  5675. if (this.layer.options['globalCompositeOperation']) {
  5676. this.context.globalCompositeOperation = this.layer.options['globalCompositeOperation'];
  5677. }
  5678. } else {
  5679. var attributes = {
  5680. 'alpha': true,
  5681. 'preserveDrawingBuffer': true,
  5682. 'antialias': false
  5683. };
  5684. this.gl = this.canvas.getContext('webgl', attributes);
  5685. }
  5686. this.onCanvasCreate();
  5687. this._bindToMapv();
  5688. this.layer.fire('canvascreate', {
  5689. 'context': this.context,
  5690. 'gl': this.gl
  5691. });
  5692. }
  5693. }, {
  5694. key: "_bindToMapv",
  5695. value: function _bindToMapv() {
  5696. //some bindings needed by mapv baselayer
  5697. var base = this.layer.baseLayer;
  5698. this.devicePixelRatio = maptalks.Browser.retina ? 2 : 1;
  5699. base.canvasLayer = this;
  5700. base._canvasUpdate = this._canvasUpdate.bind(this);
  5701. base.getContext = function () {
  5702. var renderer = self.getRenderer();
  5703. return renderer.gl || renderer.context;
  5704. };
  5705. }
  5706. }]);
  5707. return LayerRenderer;
  5708. }(maptalks.renderer.CanvasRenderer);
  5709. Layer$4.registerRenderer('canvas', LayerRenderer);
  5710. }
  5711. var Layer$5 = Layer$4;
  5712. /**
  5713. * MapV for AMap
  5714. * @author sakitam-fdd - https://github.com/sakitam-fdd
  5715. */
  5716. /**
  5717. * create canvas
  5718. * @param width
  5719. * @param height
  5720. * @param Canvas
  5721. * @returns {HTMLCanvasElement}
  5722. */
  5723. var createCanvas = function createCanvas(width, height, Canvas) {
  5724. if (typeof document !== 'undefined') {
  5725. var canvas = document.createElement('canvas');
  5726. canvas.width = width;
  5727. canvas.height = height;
  5728. return canvas;
  5729. } else {
  5730. // create a new canvas instance in node.js
  5731. // the canvas class needs to have a default constructor without any parameter
  5732. return new Canvas(width, height);
  5733. }
  5734. };
  5735. var Layer$6 = function (_BaseLayer) {
  5736. inherits(Layer, _BaseLayer);
  5737. function Layer() {
  5738. var map = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  5739. var dataSet = arguments[1];
  5740. var options = arguments[2];
  5741. classCallCheck(this, Layer);
  5742. var _this = possibleConstructorReturn(this, (Layer.__proto__ || Object.getPrototypeOf(Layer)).call(this, map, dataSet, options));
  5743. _this.options = options;
  5744. /**
  5745. * internal
  5746. * @type {{canvas: null, devicePixelRatio: number}}
  5747. */
  5748. _this.canvasLayer = {
  5749. canvas: null,
  5750. devicePixelRatio: window.devicePixelRatio
  5751. };
  5752. /**
  5753. * canvas layer
  5754. * @type {null}
  5755. * @private
  5756. */
  5757. _this.layer_ = null;
  5758. _this.initDataRange(options);
  5759. _this.initAnimator();
  5760. _this.onEvents();
  5761. map.on('complete', function () {
  5762. this.init(map, options);
  5763. this.argCheck(options);
  5764. }, _this);
  5765. return _this;
  5766. }
  5767. /**
  5768. * init mapv layer
  5769. * @param map
  5770. * @param options
  5771. */
  5772. createClass(Layer, [{
  5773. key: "init",
  5774. value: function init(map, options) {
  5775. if (map) {
  5776. this.map = map;
  5777. this.context = this.options.context || '2d';
  5778. this.getCanvasLayer();
  5779. } else {
  5780. throw new Error('not map object');
  5781. }
  5782. }
  5783. /**
  5784. * update layer
  5785. * @param time
  5786. * @private
  5787. */
  5788. }, {
  5789. key: "_canvasUpdate",
  5790. value: function _canvasUpdate(time) {
  5791. this.render(this.canvasLayer.canvas, time);
  5792. }
  5793. /**
  5794. * render layer
  5795. * @param canvas
  5796. * @param time
  5797. * @returns {Layer}
  5798. */
  5799. }, {
  5800. key: "render",
  5801. value: function render(canvas, time) {
  5802. if (!canvas) return;
  5803. var map = this.map;
  5804. var context = canvas.getContext(this.context);
  5805. var animationOptions = this.options.animation;
  5806. if (this.isEnabledTime()) {
  5807. if (time === undefined) {
  5808. clear(context);
  5809. return this;
  5810. }
  5811. if (this.context === '2d') {
  5812. context.save();
  5813. context.globalCompositeOperation = 'destination-out';
  5814. context.fillStyle = 'rgba(0, 0, 0, .1)';
  5815. context.fillRect(0, 0, context.canvas.width, context.canvas.height);
  5816. context.restore();
  5817. }
  5818. } else {
  5819. clear(context);
  5820. }
  5821. if (this.context === '2d') {
  5822. for (var key in this.options) {
  5823. context[key] = this.options[key];
  5824. }
  5825. } else {
  5826. context.clear(context.COLOR_BUFFER_BIT);
  5827. }
  5828. var dataGetOptions = {
  5829. transferCoordinate: function transferCoordinate(coordinate) {
  5830. var _pixel = map.lngLatToContainer(new AMap.LngLat(coordinate[0], coordinate[1]));
  5831. return [_pixel['x'], _pixel['y']];
  5832. }
  5833. };
  5834. if (time !== undefined) {
  5835. dataGetOptions.filter = function (item) {
  5836. var trails = animationOptions.trails || 10;
  5837. if (time && item.time > time - trails && item.time < time) {
  5838. return true;
  5839. } else {
  5840. return false;
  5841. }
  5842. };
  5843. }
  5844. var data = this.dataSet.get(dataGetOptions);
  5845. this.processData(data);
  5846. if (this.options.unit === 'm') {
  5847. if (this.options.size) {
  5848. this.options._size = this.options.size / zoomUnit;
  5849. }
  5850. if (this.options.width) {
  5851. this.options._width = this.options.width / zoomUnit;
  5852. }
  5853. if (this.options.height) {
  5854. this.options._height = this.options.height / zoomUnit;
  5855. }
  5856. } else {
  5857. this.options._size = this.options.size;
  5858. this.options._height = this.options.height;
  5859. this.options._width = this.options.width;
  5860. }
  5861. this.drawContext(context, new DataSet(data), this.options, { x: 0, y: 0 });
  5862. this.options.updateCallback && this.options.updateCallback(time);
  5863. return this;
  5864. }
  5865. /**
  5866. * get canvas layer
  5867. */
  5868. }, {
  5869. key: "getCanvasLayer",
  5870. value: function getCanvasLayer() {
  5871. if (!this.canvasLayer.canvas && !this.layer_) {
  5872. var canvas = this.canvasFunction();
  5873. var bounds = this.map.getBounds();
  5874. this.layer_ = new AMap.CanvasLayer({
  5875. canvas: canvas,
  5876. bounds: this.options.bounds || bounds,
  5877. zooms: this.options.zooms || [0, 22]
  5878. });
  5879. this.layer_.setMap(this.map);
  5880. this.map.on('mapmove', this.canvasFunction, this);
  5881. this.map.on('zoomchange', this.canvasFunction, this);
  5882. }
  5883. }
  5884. /**
  5885. * canvas constructor
  5886. * @returns {*}
  5887. */
  5888. }, {
  5889. key: "canvasFunction",
  5890. value: function canvasFunction() {
  5891. var _ref = [this.map.getSize().width, this.map.getSize().height],
  5892. width = _ref[0],
  5893. height = _ref[1];
  5894. if (!this.canvasLayer.canvas) {
  5895. this.canvasLayer.canvas = createCanvas(width, height);
  5896. } else {
  5897. this.canvasLayer.canvas.width = width;
  5898. this.canvasLayer.canvas.height = height;
  5899. var bounds = this.map.getBounds();
  5900. if (this.layer_) {
  5901. this.layer_.setBounds(this.options.bounds || bounds);
  5902. }
  5903. }
  5904. this.render(this.canvasLayer.canvas);
  5905. return this.canvasLayer.canvas;
  5906. }
  5907. /**
  5908. * remove layer
  5909. */
  5910. }, {
  5911. key: "removeLayer",
  5912. value: function removeLayer() {
  5913. if (!this.map) return;
  5914. this.unEvents();
  5915. this.map.removeLayer(this.layer_);
  5916. delete this.map;
  5917. delete this.layer_;
  5918. delete this.canvasLayer.canvas;
  5919. }
  5920. }, {
  5921. key: "getContext",
  5922. value: function getContext() {
  5923. return this.canvasLayer.canvas.getContext(this.context);
  5924. }
  5925. /**
  5926. * handle click event
  5927. * @param event
  5928. */
  5929. }, {
  5930. key: "clickEvent",
  5931. value: function clickEvent(event) {
  5932. var pixel = event.pixel;
  5933. get(Layer.prototype.__proto__ || Object.getPrototypeOf(Layer.prototype), "clickEvent", this).call(this, pixel, event);
  5934. }
  5935. /**
  5936. * handle mousemove/pointermove event
  5937. * @param event
  5938. */
  5939. }, {
  5940. key: "mousemoveEvent",
  5941. value: function mousemoveEvent(event) {
  5942. var pixel = event.pixel;
  5943. get(Layer.prototype.__proto__ || Object.getPrototypeOf(Layer.prototype), "mousemoveEvent", this).call(this, pixel, event);
  5944. }
  5945. /**
  5946. * add animator event
  5947. */
  5948. }, {
  5949. key: "addAnimatorEvent",
  5950. value: function addAnimatorEvent() {
  5951. this.map.on('movestart', this.animatorMovestartEvent, this);
  5952. this.map.on('moveend', this.animatorMoveendEvent, this);
  5953. }
  5954. /**
  5955. * bind event
  5956. */
  5957. }, {
  5958. key: "onEvents",
  5959. value: function onEvents() {
  5960. var map = this.map;
  5961. this.unEvents();
  5962. if (this.options.methods) {
  5963. if (this.options.methods.click) {
  5964. map.on('click', this.clickEvent, this);
  5965. }
  5966. if (this.options.methods.mousemove) {
  5967. map.on('mousemove', this.mousemoveEvent, this);
  5968. }
  5969. }
  5970. }
  5971. /**
  5972. * unbind events
  5973. */
  5974. }, {
  5975. key: "unEvents",
  5976. value: function unEvents() {
  5977. var map = this.map;
  5978. if (this.options.methods) {
  5979. if (this.options.methods.click) {
  5980. map.off('click', this.clickEvent, this);
  5981. }
  5982. if (this.options.methods.mousemove) {
  5983. map.off('mousemove', this.mousemoveEvent, this);
  5984. }
  5985. }
  5986. }
  5987. }]);
  5988. return Layer;
  5989. }(BaseLayer);
  5990. /**
  5991. * MapV for openlayers (https://openlayers.org)
  5992. * @author sakitam-fdd - https://github.com/sakitam-fdd
  5993. */
  5994. /**
  5995. * create canvas
  5996. * @param width
  5997. * @param height
  5998. * @returns {HTMLCanvasElement}
  5999. */
  6000. var createCanvas$1 = function createCanvas(width, height) {
  6001. if (typeof document !== 'undefined') {
  6002. var canvas = document.createElement('canvas');
  6003. canvas.width = width;
  6004. canvas.height = height;
  6005. return canvas;
  6006. } else {
  6007. // create a new canvas instance in node.js
  6008. // the canvas class needs to have a default constructor without any parameter
  6009. }
  6010. };
  6011. var Layer$8 = function (_BaseLayer) {
  6012. inherits(Layer, _BaseLayer);
  6013. function Layer() {
  6014. var map = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  6015. var dataSet = arguments[1];
  6016. var options = arguments[2];
  6017. classCallCheck(this, Layer);
  6018. var _this = possibleConstructorReturn(this, (Layer.__proto__ || Object.getPrototypeOf(Layer)).call(this, map, dataSet, options));
  6019. _this.options = options;
  6020. /**
  6021. * internal
  6022. * @type {{canvas: null, devicePixelRatio: number}}
  6023. */
  6024. _this.canvasLayer = {
  6025. canvas: null,
  6026. devicePixelRatio: window.devicePixelRatio
  6027. /**
  6028. * cavnas layer
  6029. * @type {null}
  6030. * @private
  6031. */
  6032. };_this.layer_ = null;
  6033. /**
  6034. * previous cursor
  6035. * @type {undefined}
  6036. * @private
  6037. */
  6038. _this.previousCursor_ = undefined;
  6039. _this.init(map, options);
  6040. _this.argCheck(options);
  6041. return _this;
  6042. }
  6043. /**
  6044. * init mapv layer
  6045. * @param map
  6046. * @param options
  6047. */
  6048. createClass(Layer, [{
  6049. key: "init",
  6050. value: function init(map, options) {
  6051. if (map && map instanceof ol.Map) {
  6052. this.$Map = map;
  6053. this.context = this.options.context || '2d';
  6054. this.getCanvasLayer();
  6055. this.initDataRange(options);
  6056. this.initAnimator();
  6057. this.onEvents();
  6058. } else {
  6059. throw new Error('not map object');
  6060. }
  6061. }
  6062. /**
  6063. * update layer
  6064. * @param time
  6065. * @private
  6066. */
  6067. }, {
  6068. key: "_canvasUpdate",
  6069. value: function _canvasUpdate(time) {
  6070. this.render(this.canvasLayer.canvas, time);
  6071. }
  6072. /**
  6073. * render layer
  6074. * @param canvas
  6075. * @param time
  6076. * @returns {Layer}
  6077. */
  6078. }, {
  6079. key: "render",
  6080. value: function render(canvas, time) {
  6081. var map = this.$Map;
  6082. var context = canvas.getContext(this.context);
  6083. var animationOptions = this.options.animation;
  6084. var _projection = this.options.hasOwnProperty('projection') ? this.options.projection : 'EPSG:4326';
  6085. if (this.isEnabledTime()) {
  6086. if (time === undefined) {
  6087. clear(context);
  6088. return this;
  6089. }
  6090. if (this.context === '2d') {
  6091. context.save();
  6092. context.globalCompositeOperation = 'destination-out';
  6093. context.fillStyle = 'rgba(0, 0, 0, .1)';
  6094. context.fillRect(0, 0, context.canvas.width, context.canvas.height);
  6095. context.restore();
  6096. }
  6097. } else {
  6098. clear(context);
  6099. }
  6100. if (this.context === '2d') {
  6101. for (var key in this.options) {
  6102. context[key] = this.options[key];
  6103. }
  6104. } else {
  6105. context.clear(context.COLOR_BUFFER_BIT);
  6106. }
  6107. var dataGetOptions = {
  6108. transferCoordinate: function transferCoordinate(coordinate) {
  6109. return map.getPixelFromCoordinate(ol.proj.transform(coordinate, _projection, 'EPSG:4326'));
  6110. }
  6111. };
  6112. if (time !== undefined) {
  6113. dataGetOptions.filter = function (item) {
  6114. var trails = animationOptions.trails || 10;
  6115. if (time && item.time > time - trails && item.time < time) {
  6116. return true;
  6117. } else {
  6118. return false;
  6119. }
  6120. };
  6121. }
  6122. var data = this.dataSet.get(dataGetOptions);
  6123. this.processData(data);
  6124. if (this.options.unit === 'm') {
  6125. if (this.options.size) {
  6126. this.options._size = this.options.size / zoomUnit;
  6127. }
  6128. if (this.options.width) {
  6129. this.options._width = this.options.width / zoomUnit;
  6130. }
  6131. if (this.options.height) {
  6132. this.options._height = this.options.height / zoomUnit;
  6133. }
  6134. } else {
  6135. this.options._size = this.options.size;
  6136. this.options._height = this.options.height;
  6137. this.options._width = this.options.width;
  6138. }
  6139. this.drawContext(context, new DataSet(data), this.options, { x: 0, y: 0 });
  6140. this.options.updateCallback && this.options.updateCallback(time);
  6141. return this;
  6142. }
  6143. /**
  6144. * get canvas layer
  6145. */
  6146. }, {
  6147. key: "getCanvasLayer",
  6148. value: function getCanvasLayer() {
  6149. if (!this.canvasLayer.canvas && !this.layer_) {
  6150. var extent = this.getMapExtent();
  6151. this.layer_ = new ol.layer.Image({
  6152. layerName: this.options.layerName,
  6153. minResolution: this.options.minResolution,
  6154. maxResolution: this.options.maxResolution,
  6155. zIndex: this.options.zIndex,
  6156. extent: extent,
  6157. source: new ol.source.ImageCanvas({
  6158. canvasFunction: this.canvasFunction.bind(this),
  6159. projection: this.options.hasOwnProperty('projection') ? this.options.projection : 'EPSG:4326',
  6160. ratio: this.options.hasOwnProperty('ratio') ? this.options.ratio : 1
  6161. })
  6162. });
  6163. this.$Map.addLayer(this.layer_);
  6164. this.$Map.un('precompose', this.reRender, this);
  6165. this.$Map.on('precompose', this.reRender, this);
  6166. }
  6167. }
  6168. /**
  6169. * re render
  6170. */
  6171. }, {
  6172. key: "reRender",
  6173. value: function reRender() {
  6174. if (!this.layer_) return;
  6175. var extent = this.getMapExtent();
  6176. this.layer_.setExtent(extent);
  6177. }
  6178. /**
  6179. * canvas constructor
  6180. * @param extent
  6181. * @param resolution
  6182. * @param pixelRatio
  6183. * @param size
  6184. * @param projection
  6185. * @returns {*}
  6186. */
  6187. }, {
  6188. key: "canvasFunction",
  6189. value: function canvasFunction(extent, resolution, pixelRatio, size, projection) {
  6190. if (!this.canvasLayer.canvas) {
  6191. this.canvasLayer.canvas = createCanvas$1(size[0], size[1]);
  6192. } else {
  6193. this.canvasLayer.canvas.width = size[0];
  6194. this.canvasLayer.canvas.height = size[1];
  6195. }
  6196. this.render(this.canvasLayer.canvas);
  6197. return this.canvasLayer.canvas;
  6198. }
  6199. /**
  6200. * get map current extent
  6201. * @returns {Array}
  6202. */
  6203. }, {
  6204. key: "getMapExtent",
  6205. value: function getMapExtent() {
  6206. var size = this.$Map.getSize();
  6207. return this.$Map.getView().calculateExtent(size);
  6208. }
  6209. /**
  6210. * add layer to map
  6211. * @param map
  6212. */
  6213. }, {
  6214. key: "addTo",
  6215. value: function addTo(map) {
  6216. this.init(map, this.options);
  6217. }
  6218. /**
  6219. * remove layer
  6220. */
  6221. }, {
  6222. key: "removeLayer",
  6223. value: function removeLayer() {
  6224. if (!this.$Map) return;
  6225. this.unEvents();
  6226. this.$Map.un('precompose', this.reRender, this);
  6227. this.$Map.removeLayer(this.layer_);
  6228. delete this.$Map;
  6229. delete this.layer_;
  6230. delete this.canvasLayer.canvas;
  6231. }
  6232. }, {
  6233. key: "getContext",
  6234. value: function getContext() {
  6235. return this.canvasLayer.canvas.getContext(this.context);
  6236. }
  6237. /**
  6238. * handle click event
  6239. * @param event
  6240. */
  6241. }, {
  6242. key: "clickEvent",
  6243. value: function clickEvent(event) {
  6244. var pixel = event.pixel;
  6245. get(Layer.prototype.__proto__ || Object.getPrototypeOf(Layer.prototype), "clickEvent", this).call(this, {
  6246. x: pixel[0],
  6247. y: pixel[1]
  6248. }, event);
  6249. }
  6250. /**
  6251. * handle mousemove/pointermove event
  6252. * @param event
  6253. */
  6254. }, {
  6255. key: "mousemoveEvent",
  6256. value: function mousemoveEvent(event) {
  6257. var pixel = event.pixel;
  6258. get(Layer.prototype.__proto__ || Object.getPrototypeOf(Layer.prototype), "mousemoveEvent", this).call(this, {
  6259. x: pixel[0],
  6260. y: pixel[1]
  6261. }, event);
  6262. }
  6263. /**
  6264. * add animator event
  6265. */
  6266. }, {
  6267. key: "addAnimatorEvent",
  6268. value: function addAnimatorEvent() {
  6269. this.$Map.on('movestart', this.animatorMovestartEvent, this);
  6270. this.$Map.on('moveend', this.animatorMoveendEvent, this);
  6271. }
  6272. /**
  6273. * bind event
  6274. */
  6275. }, {
  6276. key: "onEvents",
  6277. value: function onEvents() {
  6278. var map = this.$Map;
  6279. this.unEvents();
  6280. if (this.options.methods) {
  6281. if (this.options.methods.click) {
  6282. map.on('click', this.clickEvent, this);
  6283. }
  6284. if (this.options.methods.mousemove) {
  6285. map.on('pointermove', this.mousemoveEvent, this);
  6286. }
  6287. }
  6288. }
  6289. /**
  6290. * unbind events
  6291. */
  6292. }, {
  6293. key: "unEvents",
  6294. value: function unEvents() {
  6295. var map = this.$Map;
  6296. if (this.options.methods) {
  6297. if (this.options.methods.click) {
  6298. map.un('click', this.clickEvent, this);
  6299. }
  6300. if (this.options.methods.pointermove) {
  6301. map.un('pointermove', this.mousemoveEvent, this);
  6302. }
  6303. }
  6304. }
  6305. /**
  6306. * set map cursor
  6307. * @param cursor
  6308. * @param feature
  6309. */
  6310. }, {
  6311. key: "setDefaultCursor",
  6312. value: function setDefaultCursor(cursor, feature) {
  6313. if (!this.$Map) return;
  6314. var element = this.$Map.getTargetElement();
  6315. if (feature) {
  6316. if (element.style.cursor !== cursor) {
  6317. this.previousCursor_ = element.style.cursor;
  6318. element.style.cursor = cursor;
  6319. }
  6320. } else if (this.previousCursor_ !== undefined) {
  6321. element.style.cursor = this.previousCursor_;
  6322. this.previousCursor_ = undefined;
  6323. }
  6324. }
  6325. }]);
  6326. return Layer;
  6327. }(BaseLayer);
  6328. // https://github.com/SuperMap/iClient-JavaScript
  6329. /**
  6330. * @class MapVRenderer
  6331. * @classdesc 地图渲染类。
  6332. * @category Visualization MapV
  6333. * @private
  6334. * @extends mapv.BaseLayer
  6335. * @param {L.Map} map - 待渲染的地图。
  6336. * @param {L.Layer} layer - 待渲染的图层。
  6337. * @param {DataSet} dataSet - 待渲染的数据集。
  6338. * @param {Object} options - 渲染的参数。
  6339. */
  6340. var MapVRenderer = function (_BaseLayer) {
  6341. inherits(MapVRenderer, _BaseLayer);
  6342. function MapVRenderer(map, layer, dataSet, options) {
  6343. classCallCheck(this, MapVRenderer);
  6344. var _this = possibleConstructorReturn(this, (MapVRenderer.__proto__ || Object.getPrototypeOf(MapVRenderer)).call(this, map, dataSet, options));
  6345. if (!BaseLayer) {
  6346. return possibleConstructorReturn(_this);
  6347. }
  6348. var self = _this;
  6349. options = options || {};
  6350. self.init(options);
  6351. self.argCheck(options);
  6352. _this.canvasLayer = layer;
  6353. _this.clickEvent = _this.clickEvent.bind(_this);
  6354. _this.mousemoveEvent = _this.mousemoveEvent.bind(_this);
  6355. _this._moveStartEvent = _this.moveStartEvent.bind(_this);
  6356. _this._moveEndEvent = _this.moveEndEvent.bind(_this);
  6357. _this._zoomStartEvent = _this.zoomStartEvent.bind(_this);
  6358. _this.bindEvent();
  6359. return _this;
  6360. }
  6361. /**
  6362. * @function MapVRenderer.prototype.clickEvent
  6363. * @description 点击事件。
  6364. * @param {Object} e - 触发对象。
  6365. */
  6366. createClass(MapVRenderer, [{
  6367. key: 'clickEvent',
  6368. value: function clickEvent(e) {
  6369. var offset = this.map.containerPointToLayerPoint([0, 0]);
  6370. var devicePixelRatio = this.devicePixelRatio = this.canvasLayer.devicePixelRatio = window.devicePixelRatio;
  6371. var pixel = e.layerPoint;
  6372. get(MapVRenderer.prototype.__proto__ || Object.getPrototypeOf(MapVRenderer.prototype), 'clickEvent', this).call(this, L.point((pixel.x - offset.x) / devicePixelRatio, (pixel.y - offset.y) / devicePixelRatio), e);
  6373. }
  6374. /**
  6375. * @function MapVRenderer.prototype.mousemoveEvent
  6376. * @description 鼠标移动事件。
  6377. * @param {Object} e - 触发对象。
  6378. */
  6379. }, {
  6380. key: 'mousemoveEvent',
  6381. value: function mousemoveEvent(e) {
  6382. var pixel = e.layerPoint;
  6383. get(MapVRenderer.prototype.__proto__ || Object.getPrototypeOf(MapVRenderer.prototype), 'mousemoveEvent', this).call(this, pixel, e);
  6384. }
  6385. /**
  6386. * @function MapVRenderer.prototype.bindEvent
  6387. * @description 绑定鼠标移动和鼠标点击事件。
  6388. * @param {Object} e - 触发对象。
  6389. */
  6390. }, {
  6391. key: 'bindEvent',
  6392. value: function bindEvent() {
  6393. var map = this.map;
  6394. if (this.options.methods) {
  6395. if (this.options.methods.click) {
  6396. map.on('click', this.clickEvent);
  6397. }
  6398. if (this.options.methods.mousemove) {
  6399. map.on('mousemove', this.mousemoveEvent);
  6400. }
  6401. }
  6402. this.map.on('movestart', this._moveStartEvent);
  6403. this.map.on('moveend', this._moveEndEvent);
  6404. this.map.on('zoomstart', this._zoomStartEvent);
  6405. }
  6406. /**
  6407. * @function MapVRenderer.prototype.destroy
  6408. * @description 释放资源。
  6409. */
  6410. }, {
  6411. key: 'destroy',
  6412. value: function destroy() {
  6413. this.unbindEvent();
  6414. this.clearData();
  6415. this.animator && this.animator.stop();
  6416. this.animator = null;
  6417. this.canvasLayer = null;
  6418. }
  6419. /**
  6420. * @function MapVRenderer.prototype.unbindEvent
  6421. * @description 解绑鼠标移动和鼠标滑动触发的事件。
  6422. * @param {Object} e - 触发对象。
  6423. */
  6424. }, {
  6425. key: 'unbindEvent',
  6426. value: function unbindEvent() {
  6427. var map = this.map;
  6428. if (this.options.methods) {
  6429. if (this.options.methods.click) {
  6430. map.off('click', this.clickEvent);
  6431. }
  6432. if (this.options.methods.mousemove) {
  6433. map.off('mousemove', this.mousemoveEvent);
  6434. }
  6435. }
  6436. this.map.off('movestart', this._moveStartEvent);
  6437. this.map.off('moveend', this._moveEndEvent);
  6438. this.map.off('zoomstart', this._zoomStartEvent);
  6439. }
  6440. /**
  6441. * @function MapVRenderer.prototype.getContext
  6442. * @description 获取信息。
  6443. */
  6444. }, {
  6445. key: 'getContext',
  6446. value: function getContext() {
  6447. return this.canvasLayer.getCanvas().getContext(this.context);
  6448. }
  6449. /**
  6450. * @function MapVRenderer.prototype.addData
  6451. * @description 添加数据。
  6452. * @param {Object} data - 待添加的数据。
  6453. * @param {Object} options - 待添加的数据信息。
  6454. */
  6455. }, {
  6456. key: 'addData',
  6457. value: function addData(data, options) {
  6458. var _data = data;
  6459. if (data && data.get) {
  6460. _data = data.get();
  6461. }
  6462. this.dataSet.add(_data);
  6463. this.update({
  6464. options: options
  6465. });
  6466. }
  6467. /**
  6468. * @function MapVRenderer.prototype.update
  6469. * @description 更新图层。
  6470. * @param {Object} opt - 待更新的数据。
  6471. * @param {Object} opt.data - mapv数据集。
  6472. * @param {Object} opt.options - mapv绘制参数。
  6473. */
  6474. }, {
  6475. key: 'update',
  6476. value: function update(opt) {
  6477. var update = opt || {};
  6478. var _data = update.data;
  6479. if (_data && _data.get) {
  6480. _data = _data.get();
  6481. }
  6482. if (_data != undefined) {
  6483. this.dataSet.set(_data);
  6484. }
  6485. get(MapVRenderer.prototype.__proto__ || Object.getPrototypeOf(MapVRenderer.prototype), 'update', this).call(this, {
  6486. options: update.options
  6487. });
  6488. }
  6489. /**
  6490. * @function MapVRenderer.prototype.getData
  6491. * @description 获取数据
  6492. */
  6493. }, {
  6494. key: 'getData',
  6495. value: function getData() {
  6496. return this.dataSet;
  6497. }
  6498. /**
  6499. * @function MapVRenderer.prototype.removeData
  6500. * @description 删除符合过滤条件的数据。
  6501. * @param {Function} filter - 过滤条件。条件参数为数据项,返回值为 true,表示删除该元素;否则表示不删除。
  6502. */
  6503. }, {
  6504. key: 'removeData',
  6505. value: function removeData(_filter) {
  6506. if (!this.dataSet) {
  6507. return;
  6508. }
  6509. var newData = this.dataSet.get({
  6510. filter: function filter(data) {
  6511. return _filter != null && typeof _filter === "function" ? !_filter(data) : true;
  6512. }
  6513. });
  6514. this.dataSet.set(newData);
  6515. this.update({
  6516. options: null
  6517. });
  6518. }
  6519. /**
  6520. * @function MapVRenderer.prototype.clearData
  6521. * @description 清除数据
  6522. */
  6523. }, {
  6524. key: 'clearData',
  6525. value: function clearData() {
  6526. this.dataSet && this.dataSet.clear();
  6527. this.update({
  6528. options: null
  6529. });
  6530. }
  6531. }, {
  6532. key: '_canvasUpdate',
  6533. value: function _canvasUpdate(time) {
  6534. if (!this.canvasLayer) {
  6535. return;
  6536. }
  6537. var self = this;
  6538. var animationOptions = self.options.animation;
  6539. var context = this.getContext();
  6540. var map = this.map;
  6541. if (self.isEnabledTime()) {
  6542. if (time === undefined) {
  6543. this.clear(context);
  6544. return;
  6545. }
  6546. if (this.context === '2d') {
  6547. context.save();
  6548. context.globalCompositeOperation = 'destination-out';
  6549. context.fillStyle = 'rgba(0, 0, 0, .1)';
  6550. context.fillRect(0, 0, context.canvas.width, context.canvas.height);
  6551. context.restore();
  6552. }
  6553. } else {
  6554. this.clear(context);
  6555. }
  6556. if (this.context === '2d') {
  6557. for (var key in self.options) {
  6558. context[key] = self.options[key];
  6559. }
  6560. } else {
  6561. context.clear(context.COLOR_BUFFER_BIT);
  6562. }
  6563. if (self.options.minZoom && map.getZoom() < self.options.minZoom || self.options.maxZoom && map.getZoom() > self.options.maxZoom) {
  6564. return;
  6565. }
  6566. var bounds = map.getBounds();
  6567. //获取当前像素下的地理范围
  6568. var dw = bounds.getEast() - bounds.getWest();
  6569. var dh = bounds.getNorth() - bounds.getSouth();
  6570. var mapCanvas = map.getSize();
  6571. var resolutionX = dw / mapCanvas.x,
  6572. resolutionY = dh / mapCanvas.y;
  6573. //var centerPx = map.latLngToLayerPoint(map.getCenter());
  6574. //获取屏幕左上角的地理坐标坐标
  6575. //左上角屏幕坐标为0,0
  6576. var topLeft = this.canvasLayer.getTopLeft();
  6577. var topLeftPX = map.latLngToContainerPoint(topLeft);
  6578. // 获取精确的像素坐标. https://github.com/SuperMap/iClient-JavaScript/blob/eacc26952b8915bba0122db751d766056c5fb24d/src/leaflet/core/Base.js
  6579. // var topLeftPX = map.latLngToAccurateContainerPoint(topLeft);
  6580. // var lopLeft = map.containerPointToLatLng([0, 0]);
  6581. var dataGetOptions = {
  6582. transferCoordinate: function transferCoordinate(coordinate) {
  6583. var offset;
  6584. if (self.context === '2d') {
  6585. offset = map.latLngToContainerPoint(L.latLng(coordinate[1], coordinate[0]));
  6586. // offset = map.latLngToAccurateContainerPoint(L.latLng(coordinate[1], coordinate[0]));
  6587. } else {
  6588. offset = {
  6589. 'x': (coordinate[0] - topLeft.lng) / resolutionX,
  6590. 'y': (topLeft.lat - coordinate[1]) / resolutionY
  6591. };
  6592. }
  6593. var pixel = {
  6594. x: offset.x - topLeftPX.x,
  6595. y: offset.y - topLeftPX.y
  6596. };
  6597. return [pixel.x, pixel.y];
  6598. }
  6599. };
  6600. if (time !== undefined) {
  6601. dataGetOptions.filter = function (item) {
  6602. var trails = animationOptions.trails || 10;
  6603. return time && item.time > time - trails && item.time < time;
  6604. };
  6605. }
  6606. var data = self.dataSet.get(dataGetOptions);
  6607. this.processData(data);
  6608. self.options._size = self.options.size;
  6609. var worldPoint = map.latLngToContainerPoint(L.latLng(0, 0));
  6610. var pixel = {
  6611. x: worldPoint.x - topLeftPX.x,
  6612. y: worldPoint.y - topLeftPX.y
  6613. };
  6614. this.drawContext(context, data, self.options, pixel);
  6615. self.options.updateCallback && self.options.updateCallback(time);
  6616. }
  6617. }, {
  6618. key: 'init',
  6619. value: function init(options) {
  6620. var self = this;
  6621. self.options = options;
  6622. this.initDataRange(options);
  6623. this.context = self.options.context || '2d';
  6624. if (self.options.zIndex) {
  6625. this.canvasLayer && this.canvasLayer.setZIndex(self.options.zIndex);
  6626. }
  6627. this.initAnimator();
  6628. }
  6629. }, {
  6630. key: 'addAnimatorEvent',
  6631. value: function addAnimatorEvent() {}
  6632. /**
  6633. * @function MapVRenderer.prototype.moveStartEvent
  6634. * @description 开始移动事件。
  6635. */
  6636. }, {
  6637. key: 'moveStartEvent',
  6638. value: function moveStartEvent() {
  6639. var animationOptions = this.options.animation;
  6640. if (this.isEnabledTime() && this.animator) {
  6641. this.steps.step = animationOptions.stepsRange.start;
  6642. this._hide();
  6643. }
  6644. }
  6645. /**
  6646. * @function MapVRenderer.prototype.moveEndEvent
  6647. * @description 结束移动事件。
  6648. */
  6649. }, {
  6650. key: 'moveEndEvent',
  6651. value: function moveEndEvent() {
  6652. this.canvasLayer.draw();
  6653. this._show();
  6654. }
  6655. /**
  6656. * @function MapVRenderer.prototype.zoomStartEvent
  6657. * @description 隐藏渲染样式。
  6658. */
  6659. }, {
  6660. key: 'zoomStartEvent',
  6661. value: function zoomStartEvent() {
  6662. this._hide();
  6663. }
  6664. /**
  6665. * @function MapVRenderer.prototype.clear
  6666. * @description 清除信息。
  6667. * @param {string} context - 指定要清除的信息。
  6668. */
  6669. }, {
  6670. key: 'clear',
  6671. value: function clear(context) {
  6672. context && context.clearRect && context.clearRect(0, 0, context.canvas.width, context.canvas.height);
  6673. }
  6674. }, {
  6675. key: '_hide',
  6676. value: function _hide() {
  6677. this.canvasLayer.canvas.style.display = 'none';
  6678. }
  6679. }, {
  6680. key: '_show',
  6681. value: function _show() {
  6682. this.canvasLayer.canvas.style.display = 'block';
  6683. }
  6684. /**
  6685. * @function MapVRenderer.prototype.draw
  6686. * @description 绘制渲染
  6687. */
  6688. }, {
  6689. key: 'draw',
  6690. value: function draw() {
  6691. this.canvasLayer.draw();
  6692. }
  6693. }]);
  6694. return MapVRenderer;
  6695. }(BaseLayer);
  6696. var mapVLayer;
  6697. if (typeof L !== 'undefined') {
  6698. /**
  6699. * @class mapVLayer
  6700. * @classdesc MapV 图层。
  6701. * @category Visualization MapV
  6702. * @extends {L.Layer}
  6703. * @param {mapv.DataSet} dataSet - MapV 图层数据集。
  6704. * @param {Object} mapVOptions - MapV 图层参数。
  6705. * @param {Object} options - 参数。
  6706. * @param {string} [options.attributionPrefix] - 版权信息前缀。
  6707. * @param {string} [options.attribution='© 2018 百度 MapV'] - 版权信息。
  6708. * @fires mapVLayer#loaded
  6709. */
  6710. var MapVLayer = L.Layer.extend({
  6711. options: {
  6712. attributionPrefix: null,
  6713. attribution: ''
  6714. },
  6715. initialize: function initialize(dataSet, mapVOptions, options) {
  6716. options = options || {};
  6717. this.dataSet = dataSet || {};
  6718. this.mapVOptions = mapVOptions || {};
  6719. this.render = this.render.bind(this);
  6720. L.Util.setOptions(this, options);
  6721. if (this.options.attributionPrefix) {
  6722. this.options.attribution = this.options.attributionPrefix + this.options.attribution;
  6723. }
  6724. this.canvas = this._createCanvas();
  6725. L.stamp(this);
  6726. },
  6727. /**
  6728. * @private
  6729. * @function mapVLayer.prototype.onAdd
  6730. * @description 添加地图图层。
  6731. * @param {L.Map} map - 要添加的地图。
  6732. */
  6733. onAdd: function onAdd(map) {
  6734. this._map = map;
  6735. var overlayPane = this.getPane();
  6736. var container = this.container = L.DomUtil.create("div", "leaflet-layer leaflet-zoom-animated", overlayPane);
  6737. container.appendChild(this.canvas);
  6738. var size = map.getSize();
  6739. container.style.width = size.x + "px";
  6740. container.style.height = size.y + "px";
  6741. this.renderer = new MapVRenderer(map, this, this.dataSet, this.mapVOptions);
  6742. this.draw();
  6743. /**
  6744. * @event mapVLayer#loaded
  6745. * @description 图层添加完成之后触发。
  6746. */
  6747. this.fire("loaded");
  6748. },
  6749. // _hide: function () {
  6750. // this.canvas.style.display = 'none';
  6751. // },
  6752. // _show: function () {
  6753. // this.canvas.style.display = 'block';
  6754. // },
  6755. /**
  6756. * @private
  6757. * @function mapVLayer.prototype.onRemove
  6758. * @description 删除地图图层。
  6759. */
  6760. onRemove: function onRemove() {
  6761. L.DomUtil.remove(this.container);
  6762. this.renderer.destroy();
  6763. },
  6764. /**
  6765. * @function mapVLayer.prototype.addData
  6766. * @description 追加数据。
  6767. * @param {Object} data - 要追加的数据。
  6768. * @param {Object} options - 要追加的值。
  6769. */
  6770. addData: function addData(data, options) {
  6771. this.renderer.addData(data, options);
  6772. },
  6773. /**
  6774. * @function mapVLayer.prototype.update
  6775. * @description 更新图层。
  6776. * @param {Object} opt - 待更新的数据。
  6777. * @param {Object} data - mapv 数据集。
  6778. * @param {Object} options - mapv 绘制参数。
  6779. */
  6780. update: function update(opt) {
  6781. this.renderer.update(opt);
  6782. },
  6783. /**
  6784. * @function mapVLayer.prototype.getData
  6785. * @description 获取数据。
  6786. * @returns {mapv.DataSet} mapv 数据集。
  6787. */
  6788. getData: function getData() {
  6789. if (this.renderer) {
  6790. this.dataSet = this.renderer.getData();
  6791. }
  6792. return this.dataSet;
  6793. },
  6794. /**
  6795. * @function mapVLayer.prototype.removeData
  6796. * @description 删除符合过滤条件的数据。
  6797. * @param {Function} filter - 过滤条件。条件参数为数据项,返回值为 true,表示删除该元素;否则表示不删除。
  6798. * @example
  6799. * filter=function(data){
  6800. * if(data.id=="1"){
  6801. * return true
  6802. * }
  6803. * return false;
  6804. * }
  6805. */
  6806. removeData: function removeData(filter) {
  6807. this.renderer && this.renderer.removeData(filter);
  6808. },
  6809. /**
  6810. * @function mapVLayer.prototype.clearData
  6811. * @description 清除数据。
  6812. */
  6813. clearData: function clearData() {
  6814. this.renderer.clearData();
  6815. },
  6816. /**
  6817. * @function mapVLayer.prototype.draw
  6818. * @description 绘制图层。
  6819. */
  6820. draw: function draw() {
  6821. return this._reset();
  6822. },
  6823. /**
  6824. * @function mapVLayer.prototype.setZIndex
  6825. * @description 设置 canvas 层级。
  6826. * @param {number} zIndex - canvas 层级。
  6827. */
  6828. setZIndex: function setZIndex(zIndex) {
  6829. this.canvas.style.zIndex = zIndex;
  6830. },
  6831. /**
  6832. * @function mapVLayer.prototype.render
  6833. * @description 渲染。
  6834. */
  6835. render: function render() {
  6836. this.renderer._canvasUpdate();
  6837. },
  6838. /**
  6839. * @function mapVLayer.prototype.getCanvas
  6840. * @description 获取 canvas。
  6841. * @returns {HTMLElement} 返回 mapV 图层包含的 canvas 对象。
  6842. */
  6843. getCanvas: function getCanvas() {
  6844. return this.canvas;
  6845. },
  6846. /**
  6847. * @function mapVLayer.prototype.getContainer
  6848. * @description 获取容器。
  6849. * @returns {HTMLElement} 返回包含 mapV 图层的 dom 对象。
  6850. */
  6851. getContainer: function getContainer() {
  6852. return this.container;
  6853. },
  6854. /**
  6855. * @function mapVLayer.prototype.getTopLeft
  6856. * @description 获取左上角坐标。
  6857. * @returns {L.Bounds} 返回左上角坐标。
  6858. */
  6859. getTopLeft: function getTopLeft() {
  6860. var map = this._map;
  6861. var topLeft;
  6862. if (map) {
  6863. var bounds = map.getBounds();
  6864. topLeft = bounds.getNorthWest();
  6865. }
  6866. return topLeft;
  6867. },
  6868. _createCanvas: function _createCanvas() {
  6869. var canvas = document.createElement('canvas');
  6870. canvas.style.position = 'absolute';
  6871. canvas.style.top = 0 + "px";
  6872. canvas.style.left = 0 + "px";
  6873. canvas.style.pointerEvents = "none";
  6874. canvas.style.zIndex = this.options.zIndex || 600;
  6875. var global$2 = typeof window === 'undefined' ? {} : window;
  6876. var devicePixelRatio = this.devicePixelRatio = global$2.devicePixelRatio;
  6877. if (!this.mapVOptions.context || this.mapVOptions.context === '2d') {
  6878. canvas.getContext('2d').scale(devicePixelRatio, devicePixelRatio);
  6879. }
  6880. return canvas;
  6881. },
  6882. _resize: function _resize() {
  6883. var canvas = this.canvas;
  6884. if (!canvas) {
  6885. return;
  6886. }
  6887. var map = this._map;
  6888. var size = map.getSize();
  6889. canvas.width = size.x;
  6890. canvas.height = size.y;
  6891. canvas.style.width = size.x + 'px';
  6892. canvas.style.height = size.y + 'px';
  6893. var bounds = map.getBounds();
  6894. var topLeft = map.latLngToLayerPoint(bounds.getNorthWest());
  6895. L.DomUtil.setPosition(canvas, topLeft);
  6896. },
  6897. _reset: function _reset() {
  6898. this._resize();
  6899. this._render();
  6900. },
  6901. redraw: function redraw() {
  6902. this._resize();
  6903. this._render();
  6904. },
  6905. _render: function _render() {
  6906. this.render();
  6907. }
  6908. });
  6909. mapVLayer = function mapVLayer(dataSet, mapVOptions, options) {
  6910. return new MapVLayer(dataSet, mapVOptions, options);
  6911. };
  6912. }
  6913. var mapVLayer$1 = mapVLayer;
  6914. var MapVRenderer$1 = function (_BaseLayer) {
  6915. inherits(MapVRenderer, _BaseLayer);
  6916. /**
  6917. * Creates an instance of MapVRenderer.
  6918. * @param {*} viewer cesium viewer
  6919. * @param {*} dataset mapv dataset
  6920. * @param {*} option mapvOptions
  6921. * @param {*} mapVLayer
  6922. * @memberof MapVRenderer
  6923. */
  6924. function MapVRenderer(viewer, dataset, option, mapVLayer) {
  6925. classCallCheck(this, MapVRenderer);
  6926. var _this = possibleConstructorReturn(this, (MapVRenderer.__proto__ || Object.getPrototypeOf(MapVRenderer)).call(this, viewer, dataset, option));
  6927. if (!BaseLayer) {
  6928. return possibleConstructorReturn(_this);
  6929. }
  6930. _this.map = viewer, _this.scene = viewer.scene, _this.dataSet = dataset;
  6931. option = option || {}, _this.init(option), _this.argCheck(option), _this.initDevicePixelRatio(), _this.canvasLayer = mapVLayer, _this.stopAniamation = !1, _this.animation = option.animation, _this.clickEvent = _this.clickEvent.bind(_this), _this.mousemoveEvent = _this.mousemoveEvent.bind(_this), _this.bindEvent();
  6932. return _this;
  6933. }
  6934. createClass(MapVRenderer, [{
  6935. key: "initDevicePixelRatio",
  6936. value: function initDevicePixelRatio() {
  6937. this.devicePixelRatio = window.devicePixelRatio || 1;
  6938. }
  6939. }, {
  6940. key: "clickEvent",
  6941. value: function clickEvent(t) {
  6942. var e = t.point;
  6943. get(MapVRenderer.prototype.__proto__ || Object.getPrototypeOf(MapVRenderer.prototype), "clickEvent", this).call(this, e, t);
  6944. }
  6945. }, {
  6946. key: "mousemoveEvent",
  6947. value: function mousemoveEvent(t) {
  6948. var e = t.point;
  6949. get(MapVRenderer.prototype.__proto__ || Object.getPrototypeOf(MapVRenderer.prototype), "mousemoveEvent", this).call(this, e, t);
  6950. }
  6951. }, {
  6952. key: "addAnimatorEvent",
  6953. value: function addAnimatorEvent() {}
  6954. }, {
  6955. key: "animatorMovestartEvent",
  6956. value: function animatorMovestartEvent() {
  6957. var t = this.options.animation;
  6958. this.isEnabledTime() && this.animator && (this.steps.step = t.stepsRange.start);
  6959. }
  6960. }, {
  6961. key: "animatorMoveendEvent",
  6962. value: function animatorMoveendEvent() {
  6963. this.isEnabledTime() && this.animator;
  6964. }
  6965. }, {
  6966. key: "bindEvent",
  6967. value: function bindEvent() {
  6968. this.map;
  6969. this.options.methods && (this.options.methods.click, this.options.methods.mousemove);
  6970. }
  6971. }, {
  6972. key: "unbindEvent",
  6973. value: function unbindEvent() {
  6974. var t = this.map;
  6975. this.options.methods && (this.options.methods.click && t.off("click", this.clickEvent), this.options.methods.mousemove && t.off("mousemove", this.mousemoveEvent));
  6976. }
  6977. }, {
  6978. key: "getContext",
  6979. value: function getContext() {
  6980. return this.canvasLayer.canvas.getContext(this.context);
  6981. }
  6982. }, {
  6983. key: "init",
  6984. value: function init(t) {
  6985. this.options = t, this.initDataRange(t), this.context = this.options.context || "2d", this.options.zIndex && this.canvasLayer && this.canvasLayer.setZIndex(this.options.zIndex), this.initAnimator();
  6986. }
  6987. }, {
  6988. key: "_canvasUpdate",
  6989. value: function _canvasUpdate(t) {
  6990. this.map;
  6991. var e = this.scene;
  6992. if (this.canvasLayer && !this.stopAniamation) {
  6993. var i = this.options.animation,
  6994. n = this.getContext();
  6995. if (this.isEnabledTime()) {
  6996. if (void 0 === t) return void this.clear(n);
  6997. "2d" === this.context && (n.save(), n.globalCompositeOperation = "destination-out", n.fillStyle = "rgba(0, 0, 0, .1)", n.fillRect(0, 0, n.canvas.width, n.canvas.height), n.restore());
  6998. } else this.clear(n);
  6999. if ("2d" === this.context) for (var o in this.options) {
  7000. n[o] = this.options[o];
  7001. } else n.clear(n.COLOR_BUFFER_BIT);
  7002. var a = {
  7003. transferCoordinate: function transferCoordinate(t) {
  7004. var i = Cesium.Cartesian3.fromDegrees(t[0], t[1]),
  7005. n = Cesium.SceneTransforms.wgs84ToWindowCoordinates(e, i);
  7006. return void 0 == n ? [-1, -1] : [n.x, n.y];
  7007. }
  7008. };
  7009. void 0 !== t && (a.filter = function (e) {
  7010. var n = i.trails || 10;
  7011. return !!(t && e.time > t - n && e.time < t);
  7012. });
  7013. var c = this.dataSet.get(a);
  7014. this.processData(c), "m" == this.options.unit && this.options.size, this.options._size = this.options.size;
  7015. var h = Cesium.SceneTransforms.wgs84ToWindowCoordinates(e, Cesium.Cartesian3.fromDegrees(0, 0));
  7016. this.drawContext(n, new DataSet(c), this.options, h), this.options.updateCallback && this.options.updateCallback(t);
  7017. }
  7018. }
  7019. }, {
  7020. key: "updateData",
  7021. value: function updateData(t, e) {
  7022. var i = t;
  7023. i && i.get && (i = i.get()), void 0 != i && this.dataSet.set(i), get(MapVRenderer.prototype.__proto__ || Object.getPrototypeOf(MapVRenderer.prototype), "update", this).call(this, {
  7024. options: e
  7025. });
  7026. }
  7027. }, {
  7028. key: "addData",
  7029. value: function addData(t, e) {
  7030. var i = t;
  7031. t && t.get && (i = t.get()), this.dataSet.add(i), this.update({
  7032. options: e
  7033. });
  7034. }
  7035. }, {
  7036. key: "getData",
  7037. value: function getData() {
  7038. return this.dataSet;
  7039. }
  7040. }, {
  7041. key: "removeData",
  7042. value: function removeData(t) {
  7043. if (this.dataSet) {
  7044. var e = this.dataSet.get({
  7045. filter: function filter(e) {
  7046. return null == t || "function" != typeof t || !t(e);
  7047. }
  7048. });
  7049. this.dataSet.set(e), this.update({
  7050. options: null
  7051. });
  7052. }
  7053. }
  7054. }, {
  7055. key: "clearData",
  7056. value: function clearData() {
  7057. this.dataSet && this.dataSet.clear(), this.update({
  7058. options: null
  7059. });
  7060. }
  7061. }, {
  7062. key: "draw",
  7063. value: function draw() {
  7064. this.canvasLayer.draw();
  7065. }
  7066. }, {
  7067. key: "clear",
  7068. value: function clear(t) {
  7069. t && t.clearRect && t.clearRect(0, 0, t.canvas.width, t.canvas.height);
  7070. }
  7071. }]);
  7072. return MapVRenderer;
  7073. }(BaseLayer);
  7074. var mapVLayer$2;
  7075. if (typeof Cesium !== 'undefined') {
  7076. var defIndex = 0;
  7077. var r = Cesium;
  7078. var MapVLayer$1 = function () {
  7079. /**
  7080. *Creates an instance of MapVLayer.
  7081. * @param {*} viewer
  7082. * @param {*} dataset
  7083. * @param {*} options
  7084. * @param {*} container default viewer.container
  7085. * @memberof MapVLayer
  7086. */
  7087. function MapVLayer(viewer, dataset, options, container) {
  7088. classCallCheck(this, MapVLayer);
  7089. this.map = viewer, this.scene = viewer.scene, this.mapvBaseLayer = new MapVRenderer$1(viewer, dataset, options, this), this.mapVOptions = options, this.initDevicePixelRatio(), this.canvas = this._createCanvas(), this.render = this.render.bind(this);
  7090. if (container) {
  7091. this.container = container;
  7092. } else {
  7093. var inner = viewer.container.querySelector('.cesium-viewer-cesiumWidgetContainer');
  7094. this.container = inner ? inner : viewer.container;
  7095. }
  7096. this.addInnerContainer();
  7097. // void 0 != container ? (this.container = container,
  7098. // container.appendChild(this.canvas)) : (this.container = viewer.container,
  7099. // this.addInnerContainer()),
  7100. this.bindEvent();
  7101. this._reset();
  7102. }
  7103. createClass(MapVLayer, [{
  7104. key: 'initDevicePixelRatio',
  7105. value: function initDevicePixelRatio() {
  7106. this.devicePixelRatio = window.devicePixelRatio || 1;
  7107. }
  7108. }, {
  7109. key: 'addInnerContainer',
  7110. value: function addInnerContainer() {
  7111. this.container.appendChild(this.canvas);
  7112. }
  7113. }, {
  7114. key: 'bindEvent',
  7115. value: function bindEvent() {
  7116. var that = this;
  7117. this.innerMoveStart = this.moveStartEvent.bind(this);
  7118. this.innerMoveEnd = this.moveEndEvent.bind(this);
  7119. this.scene.camera.moveStart.addEventListener(this.innerMoveStart, this);
  7120. this.scene.camera.moveEnd.addEventListener(this.innerMoveEnd, this);
  7121. var t = new Cesium.ScreenSpaceEventHandler(this.scene.canvas);
  7122. t.setInputAction(function (t) {
  7123. that.innerMoveEnd();
  7124. }, Cesium.ScreenSpaceEventType.LEFT_UP);
  7125. t.setInputAction(function (t) {
  7126. that.innerMoveEnd();
  7127. }, Cesium.ScreenSpaceEventType.MIDDLE_UP);
  7128. this.handler = t;
  7129. }
  7130. }, {
  7131. key: 'unbindEvent',
  7132. value: function unbindEvent() {
  7133. this.scene.camera.moveStart.removeEventListener(this.innerMoveStart, this);
  7134. this.scene.camera.moveEnd.removeEventListener(this.innerMoveEnd, this);
  7135. this.scene.postRender.removeEventListener(this._reset, this);
  7136. this.handler && (this.handler.destroy(), this.handler = null);
  7137. }
  7138. }, {
  7139. key: 'moveStartEvent',
  7140. value: function moveStartEvent() {
  7141. if (this.mapvBaseLayer) {
  7142. this.mapvBaseLayer.animatorMovestartEvent();
  7143. this.scene.postRender.addEventListener(this._reset, this);
  7144. }
  7145. }
  7146. }, {
  7147. key: 'moveEndEvent',
  7148. value: function moveEndEvent() {
  7149. if (this.mapvBaseLayer) {
  7150. this.scene.postRender.removeEventListener(this._reset, this), this.mapvBaseLayer.animatorMoveendEvent();
  7151. this._reset();
  7152. }
  7153. }
  7154. }, {
  7155. key: 'zoomStartEvent',
  7156. value: function zoomStartEvent() {
  7157. this._unvisiable();
  7158. }
  7159. }, {
  7160. key: 'zoomEndEvent',
  7161. value: function zoomEndEvent() {
  7162. this._unvisiable();
  7163. }
  7164. }, {
  7165. key: 'addData',
  7166. value: function addData(t, e) {
  7167. void 0 != this.mapvBaseLayer && this.mapvBaseLayer.addData(t, e);
  7168. }
  7169. }, {
  7170. key: 'updateData',
  7171. value: function updateData(t, e) {
  7172. void 0 != this.mapvBaseLayer && this.mapvBaseLayer.updateData(t, e);
  7173. }
  7174. }, {
  7175. key: 'getData',
  7176. value: function getData() {
  7177. return this.mapvBaseLayer && (this.dataSet = this.mapvBaseLayer.getData()), this.dataSet;
  7178. }
  7179. }, {
  7180. key: 'removeData',
  7181. value: function removeData(t) {
  7182. void 0 != this.mapvBaseLayer && this.mapvBaseLayer && this.mapvBaseLayer.removeData(t);
  7183. }
  7184. }, {
  7185. key: 'removeAllData',
  7186. value: function removeAllData() {
  7187. void 0 != this.mapvBaseLayer && this.mapvBaseLayer.clearData();
  7188. }
  7189. }, {
  7190. key: '_visiable',
  7191. value: function _visiable() {
  7192. return this.canvas.style.display = "block", this;
  7193. }
  7194. }, {
  7195. key: '_unvisiable',
  7196. value: function _unvisiable() {
  7197. return this.canvas.style.display = "none", this;
  7198. }
  7199. }, {
  7200. key: '_createCanvas',
  7201. value: function _createCanvas() {
  7202. var t = document.createElement("canvas");
  7203. t.id = this.mapVOptions.layerid || "mapv" + defIndex++, t.style.position = "absolute", t.style.top = "0px", t.style.left = "0px", t.style.pointerEvents = "none", t.style.zIndex = this.mapVOptions.zIndex || 0, t.width = parseInt(this.map.canvas.width), t.height = parseInt(this.map.canvas.height), t.style.width = this.map.canvas.style.width, t.style.height = this.map.canvas.style.height;
  7204. var e = this.devicePixelRatio;
  7205. return "2d" == this.mapVOptions.context && t.getContext(this.mapVOptions.context).scale(e, e), t;
  7206. }
  7207. }, {
  7208. key: '_reset',
  7209. value: function _reset() {
  7210. this.resizeCanvas();
  7211. this.fixPosition();
  7212. this.onResize();
  7213. this.render();
  7214. }
  7215. }, {
  7216. key: 'draw',
  7217. value: function draw() {
  7218. this._reset();
  7219. }
  7220. }, {
  7221. key: 'show',
  7222. value: function show() {
  7223. this._visiable();
  7224. }
  7225. }, {
  7226. key: 'hide',
  7227. value: function hide() {
  7228. this._unvisiable();
  7229. }
  7230. }, {
  7231. key: 'destroy',
  7232. value: function destroy() {
  7233. this.remove();
  7234. }
  7235. }, {
  7236. key: 'remove',
  7237. value: function remove() {
  7238. void 0 != this.mapvBaseLayer && (this.removeAllData(), this.mapvBaseLayer.clear(this.mapvBaseLayer.getContext()), this.mapvBaseLayer = void 0, this.canvas.parentElement.removeChild(this.canvas));
  7239. }
  7240. }, {
  7241. key: 'update',
  7242. value: function update(t) {
  7243. void 0 != t && this.updateData(t.data, t.options);
  7244. }
  7245. }, {
  7246. key: 'resizeCanvas',
  7247. value: function resizeCanvas() {
  7248. if (void 0 != this.canvas && null != this.canvas) {
  7249. var t = this.canvas;
  7250. t.style.position = "absolute", t.style.top = "0px", t.style.left = "0px", t.width = parseInt(this.map.canvas.width), t.height = parseInt(this.map.canvas.height), t.style.width = this.map.canvas.style.width, t.style.height = this.map.canvas.style.height;
  7251. }
  7252. }
  7253. }, {
  7254. key: 'fixPosition',
  7255. value: function fixPosition() {}
  7256. }, {
  7257. key: 'onResize',
  7258. value: function onResize() {}
  7259. }, {
  7260. key: 'render',
  7261. value: function render() {
  7262. void 0 != this.mapvBaseLayer && this.mapvBaseLayer._canvasUpdate();
  7263. }
  7264. }]);
  7265. return MapVLayer;
  7266. }();
  7267. mapVLayer$2 = function mapVLayer(viewer, dataSet, mapVOptions, container) {
  7268. return new MapVLayer$1(viewer, dataSet, mapVOptions, container);
  7269. };
  7270. }
  7271. var mapVLayer$3 = mapVLayer$2;
  7272. /**
  7273. * @author kyle / http://nikai.us/
  7274. */
  7275. var geojson = {
  7276. getDataSet: function getDataSet(geoJson) {
  7277. var data = [];
  7278. var features = geoJson.features;
  7279. if (features) {
  7280. for (var i = 0; i < features.length; i++) {
  7281. var feature = features[i];
  7282. var geometry = feature.geometry;
  7283. var properties = feature.properties;
  7284. var item = {};
  7285. for (var key in properties) {
  7286. item[key] = properties[key];
  7287. }
  7288. item.geometry = geometry;
  7289. data.push(item);
  7290. }
  7291. }
  7292. return new DataSet(data);
  7293. }
  7294. };
  7295. /**
  7296. * @author kyle / http://nikai.us/
  7297. */
  7298. var csv = {
  7299. CSVToArray: function CSVToArray(strData, strDelimiter) {
  7300. // Check to see if the delimiter is defined. If not,
  7301. // then default to comma.
  7302. strDelimiter = strDelimiter || ",";
  7303. // Create a regular expression to parse the CSV values.
  7304. var objPattern = new RegExp(
  7305. // Delimiters.
  7306. "(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +
  7307. // Quoted fields.
  7308. "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +
  7309. // Standard fields.
  7310. "([^\"\\" + strDelimiter + "\\r\\n]*))", "gi");
  7311. // Create an array to hold our data. Give the array
  7312. // a default empty first row.
  7313. var arrData = [[]];
  7314. // Create an array to hold our individual pattern
  7315. // matching groups.
  7316. var arrMatches = null;
  7317. // Keep looping over the regular expression matches
  7318. // until we can no longer find a match.
  7319. while (arrMatches = objPattern.exec(strData)) {
  7320. // Get the delimiter that was found.
  7321. var strMatchedDelimiter = arrMatches[1];
  7322. // Check to see if the given delimiter has a length
  7323. // (is not the start of string) and if it matches
  7324. // field delimiter. If id does not, then we know
  7325. // that this delimiter is a row delimiter.
  7326. if (strMatchedDelimiter.length && strMatchedDelimiter !== strDelimiter) {
  7327. // Since we have reached a new row of data,
  7328. // add an empty row to our data array.
  7329. arrData.push([]);
  7330. }
  7331. var strMatchedValue;
  7332. // Now that we have our delimiter out of the way,
  7333. // let's check to see which kind of value we
  7334. // captured (quoted or unquoted).
  7335. if (arrMatches[2]) {
  7336. // We found a quoted value. When we capture
  7337. // this value, unescape any double quotes.
  7338. strMatchedValue = arrMatches[2].replace(new RegExp("\"\"", "g"), "\"");
  7339. } else {
  7340. // We found a non-quoted value.
  7341. strMatchedValue = arrMatches[3];
  7342. }
  7343. // Now that we have our value string, let's add
  7344. // it to the data array.
  7345. arrData[arrData.length - 1].push(strMatchedValue);
  7346. }
  7347. // Return the parsed data.
  7348. return arrData;
  7349. },
  7350. getDataSet: function getDataSet(csvStr, split) {
  7351. var arr = this.CSVToArray(csvStr, split || ',');
  7352. var data = [];
  7353. var header = arr[0];
  7354. for (var i = 1; i < arr.length - 1; i++) {
  7355. var line = arr[i];
  7356. var item = {};
  7357. for (var j = 0; j < line.length; j++) {
  7358. var value = line[j];
  7359. if (header[j] == 'geometry') {
  7360. value = JSON.parse(value);
  7361. }
  7362. item[header[j]] = value;
  7363. }
  7364. data.push(item);
  7365. }
  7366. return new DataSet(data);
  7367. }
  7368. };
  7369. exports.version = version;
  7370. exports.canvasClear = clear;
  7371. exports.canvasResolutionScale = resolutionScale$1;
  7372. exports.canvasDrawSimple = drawSimple;
  7373. exports.canvasDrawHeatmap = drawHeatmap;
  7374. exports.canvasDrawGrid = drawGrid;
  7375. exports.canvasDrawHoneycomb = drawHoneycomb;
  7376. exports.webglDrawSimple = webglDrawSimple;
  7377. exports.webglDrawPoint = point;
  7378. exports.webglDrawLine = line;
  7379. exports.webglDrawPolygon = polygon;
  7380. exports.utilCityCenter = cityCenter;
  7381. exports.utilCurve = curve;
  7382. exports.utilForceEdgeBundling = ForceEdgeBundling;
  7383. exports.utilDataRangeIntensity = Intensity;
  7384. exports.utilDataRangeCategory = Category;
  7385. exports.utilDataRangeChoropleth = Choropleth;
  7386. exports.Map = MapHelper;
  7387. exports.baiduMapCanvasLayer = CanvasLayer;
  7388. exports.baiduMapAnimationLayer = AnimationLayer;
  7389. exports.baiduMapLayer = Layer;
  7390. exports.googleMapCanvasLayer = CanvasLayer$2;
  7391. exports.googleMapLayer = Layer$2;
  7392. exports.MaptalksLayer = Layer$5;
  7393. exports.AMapLayer = Layer$6;
  7394. exports.OpenlayersLayer = Layer$8;
  7395. exports.leafletMapLayer = mapVLayer$1;
  7396. exports.cesiumMapLayer = mapVLayer$3;
  7397. exports.DataSet = DataSet;
  7398. exports.geojson = geojson;
  7399. exports.csv = csv;
  7400. Object.defineProperty(exports, '__esModule', { value: true });
  7401. })));