mapv.js 275 KB

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