baidu_mapv.js 292 KB

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