mapv.js 277 KB

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