mapv.js 185 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797
  1. /*!
  2. * Copyright (c) 2016, Baidu, Inc. All rights reserved.
  3. * mapv.(http://mapv.baidu.com)
  4. * github: https://github.com/huiyan-fe/mapv
  5. * license: BSD 3-clause "New" or "Revised"
  6. * version: 2.0.20
  7. */
  8. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  10. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  11. (factory((global.mapv = global.mapv || {})));
  12. }(this, (function (exports) { 'use strict';
  13. var version = "2.0.20";
  14. /**
  15. * @author kyle / http://nikai.us/
  16. */
  17. var clear = function (context) {
  18. context && context.clearRect && context.clearRect(0, 0, context.canvas.width, context.canvas.height);
  19. //context.canvas.width = context.canvas.width;
  20. //context.canvas.height = context.canvas.height;
  21. };
  22. /**
  23. * @author kyle / http://nikai.us/
  24. */
  25. var resolutionScale$1 = function (context) {
  26. var devicePixelRatio = window.devicePixelRatio || 1;
  27. context.canvas.width = context.canvas.width * devicePixelRatio;
  28. context.canvas.height = context.canvas.height * devicePixelRatio;
  29. context.canvas.style.width = context.canvas.width / devicePixelRatio + 'px';
  30. context.canvas.style.height = context.canvas.height / devicePixelRatio + 'px';
  31. context.scale(devicePixelRatio, devicePixelRatio);
  32. };
  33. function Event() {
  34. this._subscribers = {}; // event subscribers
  35. }
  36. /**
  37. * Subscribe to an event, add an event listener
  38. * @param {String} event Event name. Available events: 'put', 'update',
  39. * 'remove'
  40. * @param {function} callback Callback method. Called with three parameters:
  41. * {String} event
  42. * {Object | null} params
  43. * {String | Number} senderId
  44. */
  45. Event.prototype.on = function (event, callback) {
  46. var subscribers = this._subscribers[event];
  47. if (!subscribers) {
  48. subscribers = [];
  49. this._subscribers[event] = subscribers;
  50. }
  51. subscribers.push({
  52. callback: callback
  53. });
  54. };
  55. /**
  56. * Unsubscribe from an event, remove an event listener
  57. * @param {String} event
  58. * @param {function} callback
  59. */
  60. Event.prototype.off = function (event, callback) {
  61. var subscribers = this._subscribers[event];
  62. if (subscribers) {
  63. //this._subscribers[event] = subscribers.filter(listener => listener.callback != callback);
  64. for (var i = 0; i < subscribers.length; i++) {
  65. if (subscribers[i].callback == callback) {
  66. subscribers.splice(i, 1);
  67. i--;
  68. }
  69. }
  70. }
  71. };
  72. /**
  73. * Trigger an event
  74. * @param {String} event
  75. * @param {Object | null} params
  76. * @param {String} [senderId] Optional id of the sender.
  77. * @private
  78. */
  79. Event.prototype._trigger = function (event, params, senderId) {
  80. if (event == '*') {
  81. throw new Error('Cannot trigger event *');
  82. }
  83. var subscribers = [];
  84. if (event in this._subscribers) {
  85. subscribers = subscribers.concat(this._subscribers[event]);
  86. }
  87. if ('*' in this._subscribers) {
  88. subscribers = subscribers.concat(this._subscribers['*']);
  89. }
  90. for (var i = 0, len = subscribers.length; i < len; i++) {
  91. var subscriber = subscribers[i];
  92. if (subscriber.callback) {
  93. subscriber.callback(event, params, senderId || null);
  94. }
  95. }
  96. };
  97. /**
  98. * get the center by the city name
  99. * @author kyle / http://nikai.us/
  100. */
  101. 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" }] };
  102. function getCenter(g) {
  103. var item = g.split("|");
  104. item[0] = item[0].split(",");
  105. return {
  106. lng: parseFloat(item[0][0]),
  107. lat: parseFloat(item[0][1])
  108. };
  109. }
  110. var cityCenter = {
  111. getProvinceNameByCityName: function getProvinceNameByCityName(name) {
  112. var provinces = citycenter.provinces;
  113. for (var i = 0; i < provinces.length; i++) {
  114. var provinceName = provinces[i].n;
  115. var cities = provinces[i].cities;
  116. for (var j = 0; j < cities.length; j++) {
  117. if (cities[j].n == name) {
  118. return provinceName;
  119. }
  120. }
  121. }
  122. return null;
  123. },
  124. getCenterByCityName: function getCenterByCityName(name) {
  125. name = name.replace('市', '');
  126. for (var i = 0; i < citycenter.municipalities.length; i++) {
  127. if (citycenter.municipalities[i].n == name) {
  128. return getCenter(citycenter.municipalities[i].g);
  129. }
  130. }
  131. for (var i = 0; i < citycenter.other.length; i++) {
  132. if (citycenter.other[i].n == name) {
  133. return getCenter(citycenter.other[i].g);
  134. }
  135. }
  136. var provinces = citycenter.provinces;
  137. for (var i = 0; i < provinces.length; i++) {
  138. if (provinces[i].n == name) {
  139. return getCenter(provinces[i].g);
  140. }
  141. var cities = provinces[i].cities;
  142. for (var j = 0; j < cities.length; j++) {
  143. if (cities[j].n == name) {
  144. return getCenter(cities[j].g);
  145. }
  146. }
  147. }
  148. return null;
  149. }
  150. };
  151. var classCallCheck = function (instance, Constructor) {
  152. if (!(instance instanceof Constructor)) {
  153. throw new TypeError("Cannot call a class as a function");
  154. }
  155. };
  156. var createClass = function () {
  157. function defineProperties(target, props) {
  158. for (var i = 0; i < props.length; i++) {
  159. var descriptor = props[i];
  160. descriptor.enumerable = descriptor.enumerable || false;
  161. descriptor.configurable = true;
  162. if ("value" in descriptor) descriptor.writable = true;
  163. Object.defineProperty(target, descriptor.key, descriptor);
  164. }
  165. }
  166. return function (Constructor, protoProps, staticProps) {
  167. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  168. if (staticProps) defineProperties(Constructor, staticProps);
  169. return Constructor;
  170. };
  171. }();
  172. var get = function get(object, property, receiver) {
  173. if (object === null) object = Function.prototype;
  174. var desc = Object.getOwnPropertyDescriptor(object, property);
  175. if (desc === undefined) {
  176. var parent = Object.getPrototypeOf(object);
  177. if (parent === null) {
  178. return undefined;
  179. } else {
  180. return get(parent, property, receiver);
  181. }
  182. } else if ("value" in desc) {
  183. return desc.value;
  184. } else {
  185. var getter = desc.get;
  186. if (getter === undefined) {
  187. return undefined;
  188. }
  189. return getter.call(receiver);
  190. }
  191. };
  192. var inherits = function (subClass, superClass) {
  193. if (typeof superClass !== "function" && superClass !== null) {
  194. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  195. }
  196. subClass.prototype = Object.create(superClass && superClass.prototype, {
  197. constructor: {
  198. value: subClass,
  199. enumerable: false,
  200. writable: true,
  201. configurable: true
  202. }
  203. });
  204. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  205. };
  206. var possibleConstructorReturn = function (self, call) {
  207. if (!self) {
  208. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  209. }
  210. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  211. };
  212. /**
  213. * @author kyle / http://nikai.us/
  214. */
  215. function DataSet(data, options) {
  216. Event.bind(this)();
  217. this._options = options || {};
  218. this._data = []; // map with data indexed by id
  219. // add initial data when provided
  220. if (data) {
  221. this.add(data);
  222. }
  223. }
  224. DataSet.prototype = Event.prototype;
  225. /**
  226. * Add data.
  227. */
  228. DataSet.prototype.add = function (data, senderId) {
  229. if (Array.isArray(data)) {
  230. // Array
  231. for (var i = 0, len = data.length; i < len; i++) {
  232. if (data[i].time && data[i].time.length == 14 && data[i].time.substr(0, 2) == '20') {
  233. var time = data[i].time;
  234. 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();
  235. }
  236. this._data.push(data[i]);
  237. }
  238. } else if (data instanceof Object) {
  239. // Single item
  240. this._data.push(data);
  241. } else {
  242. throw new Error('Unknown dataType');
  243. }
  244. this._dataCache = JSON.parse(JSON.stringify(this._data));
  245. };
  246. DataSet.prototype.reset = function () {
  247. this._data = JSON.parse(JSON.stringify(this._dataCache));
  248. };
  249. /**
  250. * get data.
  251. */
  252. DataSet.prototype.get = function (args) {
  253. args = args || {};
  254. //console.time('copy data time')
  255. var start = new Date();
  256. // TODO: 不修改原始数据,在数据上挂载新的名称,每次修改数据直接修改新名称下的数据,可以省去deepCopy
  257. // var data = deepCopy(this._data);
  258. var data = this._data;
  259. var start = new Date();
  260. if (args.filter) {
  261. var newData = [];
  262. for (var i = 0; i < data.length; i++) {
  263. if (args.filter(data[i])) {
  264. newData.push(data[i]);
  265. }
  266. }
  267. data = newData;
  268. }
  269. if (args.transferCoordinate) {
  270. data = this.transferCoordinate(data, args.transferCoordinate, args.fromColumn, args.toColumn);
  271. }
  272. // console.timeEnd('transferCoordinate time')
  273. return data;
  274. };
  275. /**
  276. * set data.
  277. */
  278. DataSet.prototype.set = function (data) {
  279. this._set(data);
  280. this._trigger('change');
  281. };
  282. /**
  283. * set data.
  284. */
  285. DataSet.prototype._set = function (data) {
  286. this.clear();
  287. this.add(data);
  288. };
  289. /**
  290. * clear data.
  291. */
  292. DataSet.prototype.clear = function (args) {
  293. this._data = []; // map with data indexed by id
  294. };
  295. /**
  296. * remove data.
  297. */
  298. DataSet.prototype.remove = function (args) {};
  299. /**
  300. * update data.
  301. */
  302. DataSet.prototype.update = function (cbk, condition) {
  303. var data = this._data;
  304. var item = null;
  305. for (var i = 0; i < data.length; i++) {
  306. if (condition) {
  307. var flag = true;
  308. for (var key in condition) {
  309. if (data[i][key] != condition[key]) {
  310. flag = false;
  311. }
  312. }
  313. if (flag) {
  314. cbk && cbk(data[i]);
  315. }
  316. } else {
  317. cbk && cbk(data[i]);
  318. }
  319. }
  320. this._dataCache = JSON.parse(JSON.stringify(this._data));
  321. this._trigger('change');
  322. };
  323. /**
  324. * transfer coordinate.
  325. */
  326. DataSet.prototype.transferCoordinate = function (data, transferFn, fromColumn, toColumnName) {
  327. toColumnName = toColumnName || '_coordinates';
  328. fromColumn = fromColumn || 'coordinates';
  329. for (var i = 0; i < data.length; i++) {
  330. var geometry = data[i].geometry;
  331. var coordinates = geometry[fromColumn];
  332. switch (geometry.type) {
  333. case 'Point':
  334. geometry[toColumnName] = transferFn(coordinates);
  335. break;
  336. case 'LineString':
  337. var newCoordinates = [];
  338. for (var j = 0; j < coordinates.length; j++) {
  339. newCoordinates.push(transferFn(coordinates[j]));
  340. }
  341. geometry[toColumnName] = newCoordinates;
  342. break;
  343. case 'Polygon':
  344. var newCoordinates = getPolygon(coordinates);
  345. geometry[toColumnName] = newCoordinates;
  346. break;
  347. case 'MultiPolygon':
  348. var newCoordinates = [];
  349. for (var c = 0; c < coordinates.length; c++) {
  350. var polygon = coordinates[c];
  351. var polygon = getPolygon(polygon);
  352. newCoordinates.push(polygon);
  353. }
  354. geometry[toColumnName] = newCoordinates;
  355. break;
  356. }
  357. }
  358. function getPolygon(coordinates) {
  359. var newCoordinates = [];
  360. for (var c = 0; c < coordinates.length; c++) {
  361. var coordinate = coordinates[c];
  362. var newcoordinate = [];
  363. for (var j = 0; j < coordinate.length; j++) {
  364. newcoordinate.push(transferFn(coordinate[j]));
  365. }
  366. newCoordinates.push(newcoordinate);
  367. }
  368. return newCoordinates;
  369. }
  370. return data;
  371. };
  372. DataSet.prototype.initGeometry = function (transferFn) {
  373. if (transferFn) {
  374. this._data.forEach(function (item) {
  375. item.geometry = transferFn(item);
  376. });
  377. } else {
  378. this._data.forEach(function (item) {
  379. if (!item.geometry) {
  380. if (item.lng && item.lat) {
  381. item.geometry = {
  382. type: 'Point',
  383. coordinates: [item.lng, item.lat]
  384. };
  385. } else if (item.city) {
  386. var center = cityCenter.getCenterByCityName(item.city);
  387. if (center) {
  388. item.geometry = {
  389. type: 'Point',
  390. coordinates: [center.lng, center.lat]
  391. };
  392. }
  393. }
  394. }
  395. });
  396. }
  397. };
  398. /**
  399. * 获取当前列的最大值
  400. */
  401. DataSet.prototype.getMax = function (columnName) {
  402. var data = this._data;
  403. if (!data || data.length <= 0) {
  404. return;
  405. }
  406. var max = parseFloat(data[0][columnName]);
  407. for (var i = 1; i < data.length; i++) {
  408. var value = parseFloat(data[i][columnName]);
  409. if (value > max) {
  410. max = value;
  411. }
  412. }
  413. return max;
  414. };
  415. /**
  416. * 获取当前列的总和
  417. */
  418. DataSet.prototype.getSum = function (columnName) {
  419. var data = this._data;
  420. if (!data || data.length <= 0) {
  421. return;
  422. }
  423. var sum = 0;
  424. for (var i = 0; i < data.length; i++) {
  425. if (data[i][columnName]) {
  426. sum += parseFloat(data[i][columnName]);
  427. }
  428. }
  429. return sum;
  430. };
  431. /**
  432. * 获取当前列的最小值
  433. */
  434. DataSet.prototype.getMin = function (columnName) {
  435. var data = this._data;
  436. if (!data || data.length <= 0) {
  437. return;
  438. }
  439. var min = parseFloat(data[0][columnName]);
  440. for (var i = 1; i < data.length; i++) {
  441. var value = parseFloat(data[i][columnName]);
  442. if (value < min) {
  443. min = value;
  444. }
  445. }
  446. return min;
  447. };
  448. /**
  449. * 获取去重的数据
  450. */
  451. DataSet.prototype.getUnique = function (columnName) {
  452. var data = this._data;
  453. if (!data || data.length <= 0) {
  454. return;
  455. }
  456. var maps = {};
  457. for (var i = 1; i < data.length; i++) {
  458. maps[data[i][columnName]] = true;
  459. }
  460. var data = [];
  461. for (var key in maps) {
  462. data.push(key);
  463. }
  464. return data;
  465. };
  466. function hex_corner(center, size, i) {
  467. var angle_deg = 60 * i + 30;
  468. var angle_rad = Math.PI / 180 * angle_deg;
  469. return [center.x + size * Math.cos(angle_rad), center.y + size * Math.sin(angle_rad)];
  470. }
  471. function draw(context, x, y, size) {
  472. for (var j = 0; j < 6; j++) {
  473. var result = hex_corner({
  474. x: x,
  475. y: y
  476. }, size, j);
  477. context.lineTo(result[0], result[1]);
  478. }
  479. }
  480. /**
  481. * @author kyle / http://nikai.us/
  482. */
  483. var pathSimple = {
  484. drawDataSet: function drawDataSet(context, dataSet, options) {
  485. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  486. for (var i = 0, len = data.length; i < len; i++) {
  487. var item = data[i];
  488. this.draw(context, item, options);
  489. }
  490. },
  491. draw: function draw$$1(context, data, options) {
  492. var type = data.geometry.type;
  493. var coordinates = data.geometry._coordinates || data.geometry.coordinates;
  494. var symbol = options.symbol || 'circle';
  495. switch (type) {
  496. case 'Point':
  497. var size = data._size || data.size || options._size || options.size || 5;
  498. if (symbol === 'circle') {
  499. if (options.bigData === 'Point') {
  500. context.moveTo(coordinates[0], coordinates[1]);
  501. }
  502. context.arc(coordinates[0], coordinates[1], size, 0, Math.PI * 2);
  503. } else if (symbol === 'rect') {
  504. context.rect(coordinates[0] - size / 2, coordinates[1] - size / 2, size, size);
  505. } else if (symbol === 'honeycomb') {
  506. draw(context, coordinates[0], coordinates[1], size);
  507. }
  508. break;
  509. case 'LineString':
  510. for (var j = 0; j < coordinates.length; j++) {
  511. var x = coordinates[j][0];
  512. var y = coordinates[j][1];
  513. if (j == 0) {
  514. context.moveTo(x, y);
  515. } else {
  516. context.lineTo(x, y);
  517. }
  518. }
  519. break;
  520. case 'Polygon':
  521. this.drawPolygon(context, coordinates);
  522. break;
  523. case 'MultiPolygon':
  524. for (var i = 0; i < coordinates.length; i++) {
  525. var polygon = coordinates[i];
  526. this.drawPolygon(context, polygon);
  527. }
  528. context.closePath();
  529. break;
  530. default:
  531. console.log('type' + type + 'is not support now!');
  532. break;
  533. }
  534. },
  535. drawPolygon: function drawPolygon(context, coordinates) {
  536. for (var i = 0; i < coordinates.length; i++) {
  537. var coordinate = coordinates[i];
  538. context.moveTo(coordinate[0][0], coordinate[0][1]);
  539. for (var j = 1; j < coordinate.length; j++) {
  540. context.lineTo(coordinate[j][0], coordinate[j][1]);
  541. }
  542. context.lineTo(coordinate[0][0], coordinate[0][1]);
  543. }
  544. }
  545. };
  546. /**
  547. * @author kyle / http://nikai.us/
  548. */
  549. var drawSimple = {
  550. draw: function draw(context, dataSet, options) {
  551. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  552. // console.log('xxxx',options)
  553. context.save();
  554. for (var key in options) {
  555. context[key] = options[key];
  556. }
  557. // console.log(data);
  558. if (options.bigData) {
  559. context.save();
  560. context.beginPath();
  561. for (var i = 0, len = data.length; i < len; i++) {
  562. var item = data[i];
  563. pathSimple.draw(context, item, options);
  564. }
  565. var type = options.bigData;
  566. if (type == 'Point' || type == 'Polygon' || type == 'MultiPolygon') {
  567. context.fill();
  568. if ((item.strokeStyle || options.strokeStyle) && options.lineWidth) {
  569. context.stroke();
  570. }
  571. } else if (type == 'LineString') {
  572. context.stroke();
  573. }
  574. context.restore();
  575. } else {
  576. for (var i = 0, len = data.length; i < len; i++) {
  577. var item = data[i];
  578. context.save();
  579. if (item.fillStyle || item._fillStyle) {
  580. context.fillStyle = item.fillStyle || item._fillStyle;
  581. }
  582. if (item.strokeStyle || item._strokeStyle) {
  583. context.strokeStyle = item.strokeStyle || item._strokeStyle;
  584. }
  585. var type = item.geometry.type;
  586. context.beginPath();
  587. pathSimple.draw(context, item, options);
  588. if (type == 'Point' || type == 'Polygon' || type == 'MultiPolygon') {
  589. context.fill();
  590. if ((item.strokeStyle || options.strokeStyle) && options.lineWidth) {
  591. context.stroke();
  592. }
  593. } else if (type == 'LineString') {
  594. if (item.lineWidth || item._lineWidth) {
  595. context.lineWidth = item.lineWidth || item._lineWidth;
  596. }
  597. context.stroke();
  598. }
  599. context.restore();
  600. }
  601. }
  602. context.restore();
  603. }
  604. };
  605. function Canvas(width, height) {
  606. var canvas;
  607. if (typeof document === 'undefined') {
  608. // var Canvas = require('canvas');
  609. // canvas = new Canvas(width, height);
  610. } else {
  611. var canvas = document.createElement('canvas');
  612. if (width) {
  613. canvas.width = width;
  614. }
  615. if (height) {
  616. canvas.height = height;
  617. }
  618. }
  619. return canvas;
  620. }
  621. /**
  622. * @author kyle / http://nikai.us/
  623. */
  624. function Intensity(options) {
  625. options = options || {};
  626. this.gradient = options.gradient || {
  627. 0.25: "rgba(0, 0, 255, 1)",
  628. 0.55: "rgba(0, 255, 0, 1)",
  629. 0.85: "rgba(255, 255, 0, 1)",
  630. 1.0: "rgba(255, 0, 0, 1)"
  631. };
  632. this.maxSize = options.maxSize || 35;
  633. this.minSize = options.minSize || 0;
  634. this.max = options.max || 100;
  635. this.min = options.min || 0;
  636. this.initPalette();
  637. }
  638. Intensity.prototype.setMax = function (value) {
  639. this.max = value || 100;
  640. };
  641. Intensity.prototype.setMin = function (value) {
  642. this.min = value || 0;
  643. };
  644. Intensity.prototype.setMaxSize = function (maxSize) {
  645. this.maxSize = maxSize || 35;
  646. };
  647. Intensity.prototype.setMinSize = function (minSize) {
  648. this.minSize = minSize || 0;
  649. };
  650. Intensity.prototype.initPalette = function () {
  651. var gradient = this.gradient;
  652. var canvas = new Canvas(256, 1);
  653. var paletteCtx = this.paletteCtx = canvas.getContext('2d');
  654. var lineGradient = paletteCtx.createLinearGradient(0, 0, 256, 1);
  655. for (var key in gradient) {
  656. lineGradient.addColorStop(parseFloat(key), gradient[key]);
  657. }
  658. paletteCtx.fillStyle = lineGradient;
  659. paletteCtx.fillRect(0, 0, 256, 1);
  660. };
  661. Intensity.prototype.getColor = function (value) {
  662. var imageData = this.getImageData(value);
  663. return "rgba(" + imageData[0] + ", " + imageData[1] + ", " + imageData[2] + ", " + imageData[3] / 256 + ")";
  664. };
  665. Intensity.prototype.getImageData = function (value) {
  666. var imageData = this.paletteCtx.getImageData(0, 0, 256, 1).data;
  667. if (value === undefined) {
  668. return imageData;
  669. }
  670. var max = this.max;
  671. var min = this.min;
  672. if (value > max) {
  673. value = max;
  674. }
  675. if (value < min) {
  676. value = min;
  677. }
  678. var index = Math.floor((value - min) / (max - min) * (256 - 1)) * 4;
  679. return [imageData[index], imageData[index + 1], imageData[index + 2], imageData[index + 3]];
  680. };
  681. /**
  682. * @param Number value
  683. * @param Number max of value
  684. * @param Number max of size
  685. * @param Object other options
  686. */
  687. Intensity.prototype.getSize = function (value) {
  688. var size = 0;
  689. var max = this.max;
  690. var min = this.min;
  691. var maxSize = this.maxSize;
  692. var minSize = this.minSize;
  693. if (value > max) {
  694. value = max;
  695. }
  696. if (value < min) {
  697. value = min;
  698. }
  699. size = minSize + (value - min) / (max - min) * (maxSize - minSize);
  700. return size;
  701. };
  702. Intensity.prototype.getLegend = function (options) {
  703. var gradient = this.gradient;
  704. var width = options.width || 20;
  705. var height = options.height || 180;
  706. var canvas = new Canvas(width, height);
  707. var paletteCtx = canvas.getContext('2d');
  708. var lineGradient = paletteCtx.createLinearGradient(0, height, 0, 0);
  709. for (var key in gradient) {
  710. lineGradient.addColorStop(parseFloat(key), gradient[key]);
  711. }
  712. paletteCtx.fillStyle = lineGradient;
  713. paletteCtx.fillRect(0, 0, width, height);
  714. return canvas;
  715. };
  716. var global$1 = typeof window === 'undefined' ? {} : window;
  717. var devicePixelRatio = global$1.devicePixelRatio || 1;
  718. /**
  719. * @author kyle / http://nikai.us/
  720. */
  721. function createCircle(size) {
  722. var shadowBlur = size / 2;
  723. var r2 = size + shadowBlur;
  724. var offsetDistance = 10000;
  725. var circle = new Canvas(r2 * 2, r2 * 2);
  726. var context = circle.getContext('2d');
  727. context.shadowBlur = shadowBlur;
  728. context.shadowColor = 'black';
  729. context.shadowOffsetX = context.shadowOffsetY = offsetDistance;
  730. context.beginPath();
  731. context.arc(r2 - offsetDistance, r2 - offsetDistance, size, 0, Math.PI * 2, true);
  732. context.closePath();
  733. context.fill();
  734. return circle;
  735. }
  736. function colorize(pixels, gradient, options) {
  737. var maxOpacity = options.maxOpacity || 0.8;
  738. for (var i = 3, len = pixels.length, j; i < len; i += 4) {
  739. j = pixels[i] * 4; // get gradient color from opacity value
  740. if (pixels[i] / 256 > maxOpacity) {
  741. pixels[i] = 256 * maxOpacity;
  742. }
  743. pixels[i - 3] = gradient[j];
  744. pixels[i - 2] = gradient[j + 1];
  745. pixels[i - 1] = gradient[j + 2];
  746. }
  747. }
  748. function drawGray(context, dataSet, options) {
  749. var max = options.max || 100;
  750. var min = options.min || 0;
  751. // console.log(max)
  752. var size = options._size;
  753. if (size == undefined) {
  754. size = options.size;
  755. if (size == undefined) {
  756. size = 13;
  757. }
  758. }
  759. var intensity = new Intensity({
  760. gradient: options.gradient,
  761. max: max,
  762. min: min
  763. });
  764. var circle = createCircle(size);
  765. var circleHalfWidth = circle.width / 2;
  766. var circleHalfHeight = circle.height / 2;
  767. var data = dataSet;
  768. var dataOrderByAlpha = {};
  769. data.forEach(function (item, index) {
  770. var count = item.count === undefined ? 1 : item.count;
  771. var alpha = Math.min(1, count / max).toFixed(2);
  772. dataOrderByAlpha[alpha] = dataOrderByAlpha[alpha] || [];
  773. dataOrderByAlpha[alpha].push(item);
  774. });
  775. for (var i in dataOrderByAlpha) {
  776. if (isNaN(i)) continue;
  777. var _data = dataOrderByAlpha[i];
  778. context.beginPath();
  779. if (!options.withoutAlpha) {
  780. context.globalAlpha = i;
  781. }
  782. context.strokeStyle = intensity.getColor(i * max);
  783. _data.forEach(function (item, index) {
  784. if (!item.geometry) {
  785. return;
  786. }
  787. var coordinates = item.geometry._coordinates || item.geometry.coordinates;
  788. var type = item.geometry.type;
  789. if (type === 'Point') {
  790. var count = item.count === undefined ? 1 : item.count;
  791. context.globalAlpha = count / max;
  792. context.drawImage(circle, coordinates[0] - circleHalfWidth, coordinates[1] - circleHalfHeight);
  793. } else if (type === 'LineString') {
  794. var count = item.count === undefined ? 1 : item.count;
  795. context.globalAlpha = count / max;
  796. context.beginPath();
  797. pathSimple.draw(context, item, options);
  798. context.stroke();
  799. } else if (type === 'Polygon') {}
  800. });
  801. }
  802. }
  803. function draw$1(context, dataSet, options) {
  804. if (context.canvas.width <= 0 || context.canvas.height <= 0) {
  805. return;
  806. }
  807. var strength = options.strength || 0.3;
  808. context.strokeStyle = 'rgba(0,0,0,' + strength + ')';
  809. var shadowCanvas = new Canvas(context.canvas.width, context.canvas.height);
  810. var shadowContext = shadowCanvas.getContext('2d');
  811. shadowContext.scale(devicePixelRatio, devicePixelRatio);
  812. options = options || {};
  813. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  814. context.save();
  815. var intensity = new Intensity({
  816. gradient: options.gradient
  817. });
  818. //console.time('drawGray')
  819. drawGray(shadowContext, data, options);
  820. //console.timeEnd('drawGray');
  821. // return false;
  822. if (!options.absolute) {
  823. //console.time('changeColor');
  824. var colored = shadowContext.getImageData(0, 0, context.canvas.width, context.canvas.height);
  825. colorize(colored.data, intensity.getImageData(), options);
  826. //console.timeEnd('changeColor');
  827. context.putImageData(colored, 0, 0);
  828. context.restore();
  829. }
  830. intensity = null;
  831. shadowCanvas = null;
  832. }
  833. var drawHeatmap = {
  834. draw: draw$1
  835. };
  836. /**
  837. * @author kyle / http://nikai.us/
  838. */
  839. var drawGrid = {
  840. draw: function draw(context, dataSet, options) {
  841. context.save();
  842. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  843. var grids = {};
  844. var size = options._size || options.size || 50;
  845. var offset = options.offset || {
  846. x: 0,
  847. y: 0
  848. };
  849. for (var i = 0; i < data.length; i++) {
  850. var coordinates = data[i].geometry._coordinates || data[i].geometry.coordinates;
  851. var gridKey = Math.floor((coordinates[0] - offset.x) / size) + "," + Math.floor((coordinates[1] - offset.y) / size);
  852. if (!grids[gridKey]) {
  853. grids[gridKey] = 0;
  854. }
  855. grids[gridKey] += ~~(data[i].count || 1);
  856. }
  857. var intensity = new Intensity({
  858. max: options.max || 100,
  859. gradient: options.gradient
  860. });
  861. for (var gridKey in grids) {
  862. gridKey = gridKey.split(",");
  863. context.beginPath();
  864. context.rect(gridKey[0] * size + .5 + offset.x, gridKey[1] * size + .5 + offset.y, size, size);
  865. context.fillStyle = intensity.getColor(grids[gridKey]);
  866. context.fill();
  867. if (options.strokeStyle && options.lineWidth) {
  868. context.stroke();
  869. }
  870. }
  871. if (options.label && options.label.show !== false) {
  872. context.fillStyle = options.label.fillStyle || 'white';
  873. if (options.label.font) {
  874. context.font = options.label.font;
  875. }
  876. if (options.label.shadowColor) {
  877. context.shadowColor = options.label.shadowColor;
  878. }
  879. if (options.label.shadowBlur) {
  880. context.shadowBlur = options.label.shadowBlur;
  881. }
  882. for (var gridKey in grids) {
  883. gridKey = gridKey.split(",");
  884. var text = grids[gridKey];
  885. var textWidth = context.measureText(text).width;
  886. context.fillText(text, gridKey[0] * size + .5 + offset.x + size / 2 - textWidth / 2, gridKey[1] * size + .5 + offset.y + size / 2 + 5);
  887. }
  888. }
  889. context.restore();
  890. }
  891. };
  892. /**
  893. * @author kyle / http://nikai.us/
  894. */
  895. function hex_corner$1(center, size, i) {
  896. var angle_deg = 60 * i + 30;
  897. var angle_rad = Math.PI / 180 * angle_deg;
  898. return [center.x + size * Math.cos(angle_rad), center.y + size * Math.sin(angle_rad)];
  899. }
  900. var drawHoneycomb = {
  901. draw: function draw(context, dataSet, options) {
  902. context.save();
  903. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  904. for (var key in options) {
  905. context[key] = options[key];
  906. }
  907. var grids = {};
  908. var offset = options.offset || {
  909. x: 10,
  910. y: 10
  911. };
  912. var r = options._size || options.size || 40;
  913. r = r / 2 / Math.sin(Math.PI / 3);
  914. var dx = r * 2 * Math.sin(Math.PI / 3);
  915. var dy = r * 1.5;
  916. var binsById = {};
  917. for (var i = 0; i < data.length; i++) {
  918. var coordinates = data[i].geometry._coordinates || data[i].geometry.coordinates;
  919. var py = (coordinates[1] - offset.y) / dy,
  920. pj = Math.round(py),
  921. px = (coordinates[0] - offset.x) / dx - (pj & 1 ? .5 : 0),
  922. pi = Math.round(px),
  923. py1 = py - pj;
  924. if (Math.abs(py1) * 3 > 1) {
  925. var px1 = px - pi,
  926. pi2 = pi + (px < pi ? -1 : 1) / 2,
  927. pj2 = pj + (py < pj ? -1 : 1),
  928. px2 = px - pi2,
  929. py2 = py - pj2;
  930. if (px1 * px1 + py1 * py1 > px2 * px2 + py2 * py2) pi = pi2 + (pj & 1 ? 1 : -1) / 2, pj = pj2;
  931. }
  932. var id = pi + "-" + pj,
  933. bin = binsById[id];
  934. if (bin) {
  935. bin.push(data[i]);
  936. } else {
  937. bin = binsById[id] = [data[i]];
  938. bin.i = pi;
  939. bin.j = pj;
  940. bin.x = (pi + (pj & 1 ? 1 / 2 : 0)) * dx;
  941. bin.y = pj * dy;
  942. }
  943. }
  944. var intensity = new Intensity({
  945. max: options.max || 100,
  946. maxSize: r,
  947. gradient: options.gradient
  948. });
  949. for (var key in binsById) {
  950. var item = binsById[key];
  951. context.beginPath();
  952. for (var j = 0; j < 6; j++) {
  953. var result = hex_corner$1({
  954. x: item.x + offset.x,
  955. y: item.y + offset.y
  956. }, r, j);
  957. context.lineTo(result[0], result[1]);
  958. }
  959. context.closePath();
  960. var count = 0;
  961. for (var i = 0; i < item.length; i++) {
  962. count += item[i].count || 1;
  963. }
  964. item.count = count;
  965. context.fillStyle = intensity.getColor(count);
  966. context.fill();
  967. if (options.strokeStyle && options.lineWidth) {
  968. context.stroke();
  969. }
  970. }
  971. if (options.label && options.label.show !== false) {
  972. context.fillStyle = options.label.fillStyle || 'white';
  973. if (options.label.font) {
  974. context.font = options.label.font;
  975. }
  976. if (options.label.shadowColor) {
  977. context.shadowColor = options.label.shadowColor;
  978. }
  979. if (options.label.shadowBlur) {
  980. context.shadowBlur = options.label.shadowBlur;
  981. }
  982. for (var key in binsById) {
  983. var item = binsById[key];
  984. var text = item.count;
  985. if (text < 0) {
  986. text = text.toFixed(2);
  987. } else {
  988. text = ~~text;
  989. }
  990. var textWidth = context.measureText(text).width;
  991. context.fillText(text, item.x + offset.x - textWidth / 2, item.y + offset.y + 5);
  992. }
  993. }
  994. context.restore();
  995. }
  996. };
  997. function createShader(gl, src, type) {
  998. var shader = gl.createShader(type);
  999. gl.shaderSource(shader, src);
  1000. gl.compileShader(shader);
  1001. return shader;
  1002. }
  1003. function initShaders(gl, vs_source, fs_source) {
  1004. var vertexShader = createShader(gl, vs_source, gl.VERTEX_SHADER);
  1005. var fragmentShader = createShader(gl, fs_source, gl.FRAGMENT_SHADER);
  1006. var glProgram = gl.createProgram();
  1007. gl.attachShader(glProgram, vertexShader);
  1008. gl.attachShader(glProgram, fragmentShader);
  1009. gl.linkProgram(glProgram);
  1010. gl.useProgram(glProgram);
  1011. return glProgram;
  1012. }
  1013. function getColorData(color) {
  1014. var tmpCanvas = document.createElement('canvas');
  1015. var tmpCtx = tmpCanvas.getContext('2d');
  1016. tmpCanvas.width = 1;
  1017. tmpCanvas.height = 1;
  1018. tmpCtx.fillStyle = color;
  1019. tmpCtx.fillRect(0, 0, 1, 1);
  1020. return tmpCtx.getImageData(0, 0, 1, 1).data;
  1021. }
  1022. var vs_s = ['attribute vec4 a_Position;', 'void main() {', 'gl_Position = a_Position;', 'gl_PointSize = 30.0;', '}'].join('');
  1023. var fs_s = ['precision mediump float;', 'uniform vec4 u_FragColor;', 'void main() {', 'gl_FragColor = u_FragColor;', '}'].join('');
  1024. function draw$2(gl, data, options) {
  1025. if (!data) {
  1026. return;
  1027. }
  1028. var program = initShaders(gl, vs_s, fs_s);
  1029. gl.enable(gl.BLEND);
  1030. gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
  1031. //gl.clearColor(0.0, 0.0, 1.0, 1.0);
  1032. gl.clear(gl.COLOR_BUFFER_BIT);
  1033. var halfCanvasWidth = gl.canvas.width / 2;
  1034. var halfCanvasHeight = gl.canvas.height / 2;
  1035. // Create a buffer object
  1036. var vertexBuffer = gl.createBuffer();
  1037. // Bind the buffer object to target
  1038. gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
  1039. var a_Position = gl.getAttribLocation(program, 'a_Position');
  1040. // Assign the buffer object to a_Position variable
  1041. gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, 0, 0);
  1042. // Enable the assignment to a_Position variable
  1043. gl.enableVertexAttribArray(a_Position);
  1044. var uFragColor = gl.getUniformLocation(program, 'u_FragColor');
  1045. var colored = getColorData(options.strokeStyle || 'red');
  1046. gl.uniform4f(uFragColor, colored[0] / 255, colored[1] / 255, colored[2] / 255, colored[3] / 255);
  1047. gl.lineWidth(options.lineWidth || 1);
  1048. for (var i = 0, len = data.length; i < len; i++) {
  1049. var _geometry = data[i].geometry._coordinates;
  1050. var verticesData = [];
  1051. for (var j = 0; j < _geometry.length; j++) {
  1052. var item = _geometry[j];
  1053. var x = (item[0] - halfCanvasWidth) / halfCanvasWidth;
  1054. var y = (halfCanvasHeight - item[1]) / halfCanvasHeight;
  1055. verticesData.push(x, y);
  1056. }
  1057. var vertices = new Float32Array(verticesData);
  1058. // Write date into the buffer object
  1059. gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
  1060. gl.drawArrays(gl.LINE_STRIP, 0, _geometry.length);
  1061. }
  1062. }
  1063. var line = {
  1064. draw: draw$2
  1065. };
  1066. var vs_s$1 = ['attribute vec4 a_Position;', 'attribute float a_PointSize;', 'void main() {', 'gl_Position = a_Position;', 'gl_PointSize = a_PointSize;', '}'].join('');
  1067. var fs_s$1 = ['precision mediump float;', 'uniform vec4 u_FragColor;', 'void main() {', 'gl_FragColor = u_FragColor;', '}'].join('');
  1068. function draw$3(gl, data, options) {
  1069. if (!data) {
  1070. return;
  1071. }
  1072. var program = initShaders(gl, vs_s$1, fs_s$1);
  1073. var a_Position = gl.getAttribLocation(program, 'a_Position');
  1074. var a_PointSize = gl.getAttribLocation(program, 'a_PointSize');
  1075. var uFragColor = gl.getUniformLocation(program, 'u_FragColor');
  1076. //gl.clearColor(0.0, 0.0, 1.0, 1.0);
  1077. gl.clear(gl.COLOR_BUFFER_BIT);
  1078. var halfCanvasWidth = gl.canvas.width / 2;
  1079. var halfCanvasHeight = gl.canvas.height / 2;
  1080. var verticesData = [];
  1081. var count = 0;
  1082. for (var i = 0; i < data.length; i++) {
  1083. var item = data[i].geometry._coordinates;
  1084. var x = (item[0] - halfCanvasWidth) / halfCanvasWidth;
  1085. var y = (halfCanvasHeight - item[1]) / halfCanvasHeight;
  1086. if (x < -1 || x > 1 || y < -1 || y > 1) {
  1087. continue;
  1088. }
  1089. verticesData.push(x, y);
  1090. count++;
  1091. }
  1092. var vertices = new Float32Array(verticesData);
  1093. var n = count; // The number of vertices
  1094. // Create a buffer object
  1095. var vertexBuffer = gl.createBuffer();
  1096. // Bind the buffer object to target
  1097. gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
  1098. // Write date into the buffer object
  1099. gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
  1100. // Assign the buffer object to a_Position variable
  1101. gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, 0, 0);
  1102. // Enable the assignment to a_Position variable
  1103. gl.enableVertexAttribArray(a_Position);
  1104. gl.vertexAttrib1f(a_PointSize, options._size);
  1105. var colored = getColorData(options.fillStyle || 'red');
  1106. gl.uniform4f(uFragColor, colored[0] / 255, colored[1] / 255, colored[2] / 255, colored[3] / 255);
  1107. gl.drawArrays(gl.POINTS, 0, n);
  1108. }
  1109. var point = {
  1110. draw: draw$3
  1111. };
  1112. function earcut(data, holeIndices, dim) {
  1113. dim = dim || 2;
  1114. var hasHoles = holeIndices && holeIndices.length,
  1115. outerLen = hasHoles ? holeIndices[0] * dim : data.length,
  1116. outerNode = linkedList(data, 0, outerLen, dim, true),
  1117. triangles = [];
  1118. if (!outerNode) return triangles;
  1119. var minX, minY, maxX, maxY, x, y, size;
  1120. if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim);
  1121. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  1122. if (data.length > 80 * dim) {
  1123. minX = maxX = data[0];
  1124. minY = maxY = data[1];
  1125. for (var i = dim; i < outerLen; i += dim) {
  1126. x = data[i];
  1127. y = data[i + 1];
  1128. if (x < minX) minX = x;
  1129. if (y < minY) minY = y;
  1130. if (x > maxX) maxX = x;
  1131. if (y > maxY) maxY = y;
  1132. }
  1133. // minX, minY and size are later used to transform coords into integers for z-order calculation
  1134. size = Math.max(maxX - minX, maxY - minY);
  1135. }
  1136. earcutLinked(outerNode, triangles, dim, minX, minY, size);
  1137. return triangles;
  1138. }
  1139. // create a circular doubly linked list from polygon points in the specified winding order
  1140. function linkedList(data, start, end, dim, clockwise) {
  1141. var i, last;
  1142. if (clockwise === signedArea(data, start, end, dim) > 0) {
  1143. for (i = start; i < end; i += dim) {
  1144. last = insertNode(i, data[i], data[i + 1], last);
  1145. }
  1146. } else {
  1147. for (i = end - dim; i >= start; i -= dim) {
  1148. last = insertNode(i, data[i], data[i + 1], last);
  1149. }
  1150. }
  1151. if (last && equals(last, last.next)) {
  1152. removeNode(last);
  1153. last = last.next;
  1154. }
  1155. return last;
  1156. }
  1157. // eliminate colinear or duplicate points
  1158. function filterPoints(start, end) {
  1159. if (!start) return start;
  1160. if (!end) end = start;
  1161. var p = start,
  1162. again;
  1163. do {
  1164. again = false;
  1165. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  1166. removeNode(p);
  1167. p = end = p.prev;
  1168. if (p === p.next) return null;
  1169. again = true;
  1170. } else {
  1171. p = p.next;
  1172. }
  1173. } while (again || p !== end);
  1174. return end;
  1175. }
  1176. // main ear slicing loop which triangulates a polygon (given as a linked list)
  1177. function earcutLinked(ear, triangles, dim, minX, minY, size, pass) {
  1178. if (!ear) return;
  1179. // interlink polygon nodes in z-order
  1180. if (!pass && size) indexCurve(ear, minX, minY, size);
  1181. var stop = ear,
  1182. prev,
  1183. next;
  1184. // iterate through ears, slicing them one by one
  1185. while (ear.prev !== ear.next) {
  1186. prev = ear.prev;
  1187. next = ear.next;
  1188. if (size ? isEarHashed(ear, minX, minY, size) : isEar(ear)) {
  1189. // cut off the triangle
  1190. triangles.push(prev.i / dim);
  1191. triangles.push(ear.i / dim);
  1192. triangles.push(next.i / dim);
  1193. removeNode(ear);
  1194. // skipping the next vertice leads to less sliver triangles
  1195. ear = next.next;
  1196. stop = next.next;
  1197. continue;
  1198. }
  1199. ear = next;
  1200. // if we looped through the whole remaining polygon and can't find any more ears
  1201. if (ear === stop) {
  1202. // try filtering points and slicing again
  1203. if (!pass) {
  1204. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, size, 1);
  1205. // if this didn't work, try curing all small self-intersections locally
  1206. } else if (pass === 1) {
  1207. ear = cureLocalIntersections(ear, triangles, dim);
  1208. earcutLinked(ear, triangles, dim, minX, minY, size, 2);
  1209. // as a last resort, try splitting the remaining polygon into two
  1210. } else if (pass === 2) {
  1211. splitEarcut(ear, triangles, dim, minX, minY, size);
  1212. }
  1213. break;
  1214. }
  1215. }
  1216. }
  1217. // check whether a polygon node forms a valid ear with adjacent nodes
  1218. function isEar(ear) {
  1219. var a = ear.prev,
  1220. b = ear,
  1221. c = ear.next;
  1222. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  1223. // now make sure we don't have other points inside the potential ear
  1224. var p = ear.next.next;
  1225. while (p !== ear.prev) {
  1226. 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;
  1227. p = p.next;
  1228. }
  1229. return true;
  1230. }
  1231. function isEarHashed(ear, minX, minY, size) {
  1232. var a = ear.prev,
  1233. b = ear,
  1234. c = ear.next;
  1235. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  1236. // triangle bbox; min & max are calculated like this for speed
  1237. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  1238. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  1239. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  1240. maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
  1241. // z-order range for the current triangle bbox;
  1242. var minZ = zOrder(minTX, minTY, minX, minY, size),
  1243. maxZ = zOrder(maxTX, maxTY, minX, minY, size);
  1244. // first look for points inside the triangle in increasing z-order
  1245. var p = ear.nextZ;
  1246. while (p && p.z <= maxZ) {
  1247. 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;
  1248. p = p.nextZ;
  1249. }
  1250. // then look for points in decreasing z-order
  1251. p = ear.prevZ;
  1252. while (p && p.z >= minZ) {
  1253. 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;
  1254. p = p.prevZ;
  1255. }
  1256. return true;
  1257. }
  1258. // go through all polygon nodes and cure small local self-intersections
  1259. function cureLocalIntersections(start, triangles, dim) {
  1260. var p = start;
  1261. do {
  1262. var a = p.prev,
  1263. b = p.next.next;
  1264. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  1265. triangles.push(a.i / dim);
  1266. triangles.push(p.i / dim);
  1267. triangles.push(b.i / dim);
  1268. // remove two nodes involved
  1269. removeNode(p);
  1270. removeNode(p.next);
  1271. p = start = b;
  1272. }
  1273. p = p.next;
  1274. } while (p !== start);
  1275. return p;
  1276. }
  1277. // try splitting polygon into two and triangulate them independently
  1278. function splitEarcut(start, triangles, dim, minX, minY, size) {
  1279. // look for a valid diagonal that divides the polygon into two
  1280. var a = start;
  1281. do {
  1282. var b = a.next.next;
  1283. while (b !== a.prev) {
  1284. if (a.i !== b.i && isValidDiagonal(a, b)) {
  1285. // split the polygon in two by the diagonal
  1286. var c = splitPolygon(a, b);
  1287. // filter colinear points around the cuts
  1288. a = filterPoints(a, a.next);
  1289. c = filterPoints(c, c.next);
  1290. // run earcut on each half
  1291. earcutLinked(a, triangles, dim, minX, minY, size);
  1292. earcutLinked(c, triangles, dim, minX, minY, size);
  1293. return;
  1294. }
  1295. b = b.next;
  1296. }
  1297. a = a.next;
  1298. } while (a !== start);
  1299. }
  1300. // link every hole into the outer loop, producing a single-ring polygon without holes
  1301. function eliminateHoles(data, holeIndices, outerNode, dim) {
  1302. var queue = [],
  1303. i,
  1304. len,
  1305. start,
  1306. end,
  1307. list;
  1308. for (i = 0, len = holeIndices.length; i < len; i++) {
  1309. start = holeIndices[i] * dim;
  1310. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  1311. list = linkedList(data, start, end, dim, false);
  1312. if (list === list.next) list.steiner = true;
  1313. queue.push(getLeftmost(list));
  1314. }
  1315. queue.sort(compareX);
  1316. // process holes from left to right
  1317. for (i = 0; i < queue.length; i++) {
  1318. eliminateHole(queue[i], outerNode);
  1319. outerNode = filterPoints(outerNode, outerNode.next);
  1320. }
  1321. return outerNode;
  1322. }
  1323. function compareX(a, b) {
  1324. return a.x - b.x;
  1325. }
  1326. // find a bridge between vertices that connects hole with an outer ring and and link it
  1327. function eliminateHole(hole, outerNode) {
  1328. outerNode = findHoleBridge(hole, outerNode);
  1329. if (outerNode) {
  1330. var b = splitPolygon(outerNode, hole);
  1331. filterPoints(b, b.next);
  1332. }
  1333. }
  1334. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  1335. function findHoleBridge(hole, outerNode) {
  1336. var p = outerNode,
  1337. hx = hole.x,
  1338. hy = hole.y,
  1339. qx = -Infinity,
  1340. m;
  1341. // find a segment intersected by a ray from the hole's leftmost point to the left;
  1342. // segment's endpoint with lesser x will be potential connection point
  1343. do {
  1344. if (hy <= p.y && hy >= p.next.y) {
  1345. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  1346. if (x <= hx && x > qx) {
  1347. qx = x;
  1348. if (x === hx) {
  1349. if (hy === p.y) return p;
  1350. if (hy === p.next.y) return p.next;
  1351. }
  1352. m = p.x < p.next.x ? p : p.next;
  1353. }
  1354. }
  1355. p = p.next;
  1356. } while (p !== outerNode);
  1357. if (!m) return null;
  1358. if (hx === qx) return m.prev; // hole touches outer segment; pick lower endpoint
  1359. // look for points inside the triangle of hole point, segment intersection and endpoint;
  1360. // if there are no points found, we have a valid connection;
  1361. // otherwise choose the point of the minimum angle with the ray as connection point
  1362. var stop = m,
  1363. mx = m.x,
  1364. my = m.y,
  1365. tanMin = Infinity,
  1366. tan;
  1367. p = m.next;
  1368. while (p !== stop) {
  1369. if (hx >= p.x && p.x >= mx && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
  1370. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  1371. if ((tan < tanMin || tan === tanMin && p.x > m.x) && locallyInside(p, hole)) {
  1372. m = p;
  1373. tanMin = tan;
  1374. }
  1375. }
  1376. p = p.next;
  1377. }
  1378. return m;
  1379. }
  1380. // interlink polygon nodes in z-order
  1381. function indexCurve(start, minX, minY, size) {
  1382. var p = start;
  1383. do {
  1384. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, size);
  1385. p.prevZ = p.prev;
  1386. p.nextZ = p.next;
  1387. p = p.next;
  1388. } while (p !== start);
  1389. p.prevZ.nextZ = null;
  1390. p.prevZ = null;
  1391. sortLinked(p);
  1392. }
  1393. // Simon Tatham's linked list merge sort algorithm
  1394. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  1395. function sortLinked(list) {
  1396. var i,
  1397. p,
  1398. q,
  1399. e,
  1400. tail,
  1401. numMerges,
  1402. pSize,
  1403. qSize,
  1404. inSize = 1;
  1405. do {
  1406. p = list;
  1407. list = null;
  1408. tail = null;
  1409. numMerges = 0;
  1410. while (p) {
  1411. numMerges++;
  1412. q = p;
  1413. pSize = 0;
  1414. for (i = 0; i < inSize; i++) {
  1415. pSize++;
  1416. q = q.nextZ;
  1417. if (!q) break;
  1418. }
  1419. qSize = inSize;
  1420. while (pSize > 0 || qSize > 0 && q) {
  1421. if (pSize === 0) {
  1422. e = q;
  1423. q = q.nextZ;
  1424. qSize--;
  1425. } else if (qSize === 0 || !q) {
  1426. e = p;
  1427. p = p.nextZ;
  1428. pSize--;
  1429. } else if (p.z <= q.z) {
  1430. e = p;
  1431. p = p.nextZ;
  1432. pSize--;
  1433. } else {
  1434. e = q;
  1435. q = q.nextZ;
  1436. qSize--;
  1437. }
  1438. if (tail) tail.nextZ = e;else list = e;
  1439. e.prevZ = tail;
  1440. tail = e;
  1441. }
  1442. p = q;
  1443. }
  1444. tail.nextZ = null;
  1445. inSize *= 2;
  1446. } while (numMerges > 1);
  1447. return list;
  1448. }
  1449. // z-order of a point given coords and size of the data bounding box
  1450. function zOrder(x, y, minX, minY, size) {
  1451. // coords are transformed into non-negative 15-bit integer range
  1452. x = 32767 * (x - minX) / size;
  1453. y = 32767 * (y - minY) / size;
  1454. x = (x | x << 8) & 0x00FF00FF;
  1455. x = (x | x << 4) & 0x0F0F0F0F;
  1456. x = (x | x << 2) & 0x33333333;
  1457. x = (x | x << 1) & 0x55555555;
  1458. y = (y | y << 8) & 0x00FF00FF;
  1459. y = (y | y << 4) & 0x0F0F0F0F;
  1460. y = (y | y << 2) & 0x33333333;
  1461. y = (y | y << 1) & 0x55555555;
  1462. return x | y << 1;
  1463. }
  1464. // find the leftmost node of a polygon ring
  1465. function getLeftmost(start) {
  1466. var p = start,
  1467. leftmost = start;
  1468. do {
  1469. if (p.x < leftmost.x) leftmost = p;
  1470. p = p.next;
  1471. } while (p !== start);
  1472. return leftmost;
  1473. }
  1474. // check if a point lies within a convex triangle
  1475. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  1476. 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;
  1477. }
  1478. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  1479. function isValidDiagonal(a, b) {
  1480. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b);
  1481. }
  1482. // signed area of a triangle
  1483. function area(p, q, r) {
  1484. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  1485. }
  1486. // check if two points are equal
  1487. function equals(p1, p2) {
  1488. return p1.x === p2.x && p1.y === p2.y;
  1489. }
  1490. // check if two segments intersect
  1491. function intersects(p1, q1, p2, q2) {
  1492. if (equals(p1, q1) && equals(p2, q2) || equals(p1, q2) && equals(p2, q1)) return true;
  1493. return area(p1, q1, p2) > 0 !== area(p1, q1, q2) > 0 && area(p2, q2, p1) > 0 !== area(p2, q2, q1) > 0;
  1494. }
  1495. // check if a polygon diagonal intersects any polygon segments
  1496. function intersectsPolygon(a, b) {
  1497. var p = a;
  1498. do {
  1499. 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;
  1500. p = p.next;
  1501. } while (p !== a);
  1502. return false;
  1503. }
  1504. // check if a polygon diagonal is locally inside the polygon
  1505. function locallyInside(a, b) {
  1506. 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;
  1507. }
  1508. // check if the middle point of a polygon diagonal is inside the polygon
  1509. function middleInside(a, b) {
  1510. var p = a,
  1511. inside = false,
  1512. px = (a.x + b.x) / 2,
  1513. py = (a.y + b.y) / 2;
  1514. do {
  1515. 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;
  1516. p = p.next;
  1517. } while (p !== a);
  1518. return inside;
  1519. }
  1520. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  1521. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  1522. function splitPolygon(a, b) {
  1523. var a2 = new Node(a.i, a.x, a.y),
  1524. b2 = new Node(b.i, b.x, b.y),
  1525. an = a.next,
  1526. bp = b.prev;
  1527. a.next = b;
  1528. b.prev = a;
  1529. a2.next = an;
  1530. an.prev = a2;
  1531. b2.next = a2;
  1532. a2.prev = b2;
  1533. bp.next = b2;
  1534. b2.prev = bp;
  1535. return b2;
  1536. }
  1537. // create a node and optionally link it with previous one (in a circular doubly linked list)
  1538. function insertNode(i, x, y, last) {
  1539. var p = new Node(i, x, y);
  1540. if (!last) {
  1541. p.prev = p;
  1542. p.next = p;
  1543. } else {
  1544. p.next = last.next;
  1545. p.prev = last;
  1546. last.next.prev = p;
  1547. last.next = p;
  1548. }
  1549. return p;
  1550. }
  1551. function removeNode(p) {
  1552. p.next.prev = p.prev;
  1553. p.prev.next = p.next;
  1554. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  1555. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  1556. }
  1557. function Node(i, x, y) {
  1558. // vertice index in coordinates array
  1559. this.i = i;
  1560. // vertex coordinates
  1561. this.x = x;
  1562. this.y = y;
  1563. // previous and next vertice nodes in a polygon ring
  1564. this.prev = null;
  1565. this.next = null;
  1566. // z-order curve value
  1567. this.z = null;
  1568. // previous and next nodes in z-order
  1569. this.prevZ = null;
  1570. this.nextZ = null;
  1571. // indicates whether this is a steiner point
  1572. this.steiner = false;
  1573. }
  1574. // return a percentage difference between the polygon area and its triangulation area;
  1575. // used to verify correctness of triangulation
  1576. earcut.deviation = function (data, holeIndices, dim, triangles) {
  1577. var hasHoles = holeIndices && holeIndices.length;
  1578. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  1579. var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));
  1580. if (hasHoles) {
  1581. for (var i = 0, len = holeIndices.length; i < len; i++) {
  1582. var start = holeIndices[i] * dim;
  1583. var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  1584. polygonArea -= Math.abs(signedArea(data, start, end, dim));
  1585. }
  1586. }
  1587. var trianglesArea = 0;
  1588. for (i = 0; i < triangles.length; i += 3) {
  1589. var a = triangles[i] * dim;
  1590. var b = triangles[i + 1] * dim;
  1591. var c = triangles[i + 2] * dim;
  1592. trianglesArea += Math.abs((data[a] - data[c]) * (data[b + 1] - data[a + 1]) - (data[a] - data[b]) * (data[c + 1] - data[a + 1]));
  1593. }
  1594. return polygonArea === 0 && trianglesArea === 0 ? 0 : Math.abs((trianglesArea - polygonArea) / polygonArea);
  1595. };
  1596. function signedArea(data, start, end, dim) {
  1597. var sum = 0;
  1598. for (var i = start, j = end - dim; i < end; i += dim) {
  1599. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  1600. j = i;
  1601. }
  1602. return sum;
  1603. }
  1604. // turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts
  1605. earcut.flatten = function (data) {
  1606. var dim = data[0][0].length,
  1607. result = { vertices: [], holes: [], dimensions: dim },
  1608. holeIndex = 0;
  1609. for (var i = 0; i < data.length; i++) {
  1610. for (var j = 0; j < data[i].length; j++) {
  1611. for (var d = 0; d < dim; d++) {
  1612. result.vertices.push(data[i][j][d]);
  1613. }
  1614. }
  1615. if (i > 0) {
  1616. holeIndex += data[i - 1].length;
  1617. result.holes.push(holeIndex);
  1618. }
  1619. }
  1620. return result;
  1621. };
  1622. var vs_s$2 = ['attribute vec4 a_Position;', 'void main() {', 'gl_Position = a_Position;', 'gl_PointSize = 30.0;', '}'].join('');
  1623. var fs_s$2 = ['precision mediump float;', 'uniform vec4 u_FragColor;', 'void main() {', 'gl_FragColor = u_FragColor;', '}'].join('');
  1624. function draw$4(gl, data, options) {
  1625. if (!data) {
  1626. return;
  1627. }
  1628. // gl.clearColor(0.0, 0.0, 0.0, 1.0);
  1629. gl.clear(gl.COLOR_BUFFER_BIT);
  1630. gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
  1631. var program = initShaders(gl, vs_s$2, fs_s$2);
  1632. gl.enable(gl.BLEND);
  1633. gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
  1634. var halfCanvasWidth = gl.canvas.width / 2;
  1635. var halfCanvasHeight = gl.canvas.height / 2;
  1636. // Bind the buffer object to target
  1637. gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
  1638. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.createBuffer());
  1639. var a_Position = gl.getAttribLocation(program, 'a_Position');
  1640. // Assign the buffer object to a_Position variable
  1641. gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, 0, 0);
  1642. // Enable the assignment to a_Position variable
  1643. gl.enableVertexAttribArray(a_Position);
  1644. var uFragColor = gl.getUniformLocation(program, 'u_FragColor');
  1645. var colored = getColorData(options.fillStyle || 'red');
  1646. gl.uniform4f(uFragColor, colored[0] / 255, colored[1] / 255, colored[2] / 255, colored[3] / 255);
  1647. gl.lineWidth(options.lineWidth || 1);
  1648. var verticesArr = [];
  1649. var trianglesArr = [];
  1650. var maxSize = 65536;
  1651. var indexOffset = 0;
  1652. for (var i = 0, len = data.length; i < len; i++) {
  1653. var flatten = earcut.flatten(data[i].geometry._coordinates || data[i].geometry.coordinates);
  1654. var vertices = flatten.vertices;
  1655. indexOffset = verticesArr.length / 2;
  1656. for (var j = 0; j < vertices.length; j += 2) {
  1657. vertices[j] = (vertices[j] - halfCanvasWidth) / halfCanvasWidth;
  1658. vertices[j + 1] = (halfCanvasHeight - vertices[j + 1]) / halfCanvasHeight;
  1659. }
  1660. if ((verticesArr.length + vertices.length) / 2 > maxSize) {
  1661. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(verticesArr), gl.STATIC_DRAW);
  1662. gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(trianglesArr), gl.STATIC_DRAW);
  1663. gl.drawElements(gl.TRIANGLES, trianglesArr.length, gl.UNSIGNED_SHORT, 0);
  1664. verticesArr.length = 0;
  1665. trianglesArr.length = 0;
  1666. indexOffset = 0;
  1667. }
  1668. for (var j = 0; j < vertices.length; j++) {
  1669. verticesArr.push(vertices[j]);
  1670. }
  1671. var triangles = earcut(vertices, flatten.holes, flatten.dimensions);
  1672. for (var j = 0; j < triangles.length; j++) {
  1673. trianglesArr.push(triangles[j] + indexOffset);
  1674. }
  1675. }
  1676. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(verticesArr), gl.STATIC_DRAW);
  1677. gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(trianglesArr), gl.STATIC_DRAW);
  1678. gl.drawElements(gl.TRIANGLES, trianglesArr.length, gl.UNSIGNED_SHORT, 0);
  1679. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  1680. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
  1681. }
  1682. var polygon = {
  1683. draw: draw$4
  1684. };
  1685. /**
  1686. * @author kyle / http://nikai.us/
  1687. */
  1688. var webglDrawSimple = {
  1689. draw: function draw(gl, dataSet, options) {
  1690. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  1691. if (data.length > 0) {
  1692. if (data[0].geometry.type == "LineString") {
  1693. line.draw(gl, data, options);
  1694. } else if (data[0].geometry.type == "Polygon" || data[0].geometry.type == "MultiPolygon") {
  1695. polygon.draw(gl, data, options);
  1696. } else {
  1697. point.draw(gl, data, options);
  1698. }
  1699. }
  1700. }
  1701. };
  1702. /**
  1703. * 根据弧线的坐标节点数组
  1704. */
  1705. function getCurvePoints(points, options) {
  1706. options = options || {};
  1707. var curvePoints = [];
  1708. for (var i = 0; i < points.length - 1; i++) {
  1709. var p = getCurveByTwoPoints(points[i], points[i + 1], options.count);
  1710. if (p && p.length > 0) {
  1711. curvePoints = curvePoints.concat(p);
  1712. }
  1713. }
  1714. return curvePoints;
  1715. }
  1716. /**
  1717. * 根据两点获取曲线坐标点数组
  1718. * @param Point 起点
  1719. * @param Point 终点
  1720. */
  1721. function getCurveByTwoPoints(obj1, obj2, count) {
  1722. if (!obj1 || !obj2) {
  1723. return null;
  1724. }
  1725. var B1 = function B1(x) {
  1726. return 1 - 2 * x + x * x;
  1727. };
  1728. var B2 = function B2(x) {
  1729. return 2 * x - 2 * x * x;
  1730. };
  1731. var B3 = function B3(x) {
  1732. return x * x;
  1733. };
  1734. var curveCoordinates = [];
  1735. var count = count || 40; // 曲线是由一些小的线段组成的,这个表示这个曲线所有到的折线的个数
  1736. var isFuture = false;
  1737. var t, h, h2, lat3, lng3, j, t2;
  1738. var LnArray = [];
  1739. var i = 0;
  1740. var inc = 0;
  1741. if (typeof obj2 == "undefined") {
  1742. if (typeof curveCoordinates != "undefined") {
  1743. curveCoordinates = [];
  1744. }
  1745. return;
  1746. }
  1747. var lat1 = parseFloat(obj1.lat);
  1748. var lat2 = parseFloat(obj2.lat);
  1749. var lng1 = parseFloat(obj1.lng);
  1750. var lng2 = parseFloat(obj2.lng);
  1751. // 计算曲线角度的方法
  1752. if (lng2 > lng1) {
  1753. if (parseFloat(lng2 - lng1) > 180) {
  1754. if (lng1 < 0) {
  1755. lng1 = parseFloat(180 + 180 + lng1);
  1756. }
  1757. }
  1758. }
  1759. if (lng1 > lng2) {
  1760. if (parseFloat(lng1 - lng2) > 180) {
  1761. if (lng2 < 0) {
  1762. lng2 = parseFloat(180 + 180 + lng2);
  1763. }
  1764. }
  1765. }
  1766. j = 0;
  1767. t2 = 0;
  1768. if (lat2 == lat1) {
  1769. t = 0;
  1770. h = lng1 - lng2;
  1771. } else if (lng2 == lng1) {
  1772. t = Math.PI / 2;
  1773. h = lat1 - lat2;
  1774. } else {
  1775. t = Math.atan((lat2 - lat1) / (lng2 - lng1));
  1776. h = (lat2 - lat1) / Math.sin(t);
  1777. }
  1778. if (t2 == 0) {
  1779. t2 = t + Math.PI / 5;
  1780. }
  1781. h2 = h / 2;
  1782. lng3 = h2 * Math.cos(t2) + lng1;
  1783. lat3 = h2 * Math.sin(t2) + lat1;
  1784. for (i = 0; i < count + 1; i++) {
  1785. curveCoordinates.push([lng1 * B1(inc) + lng3 * B2(inc) + lng2 * B3(inc), lat1 * B1(inc) + lat3 * B2(inc) + lat2 * B3(inc)]);
  1786. inc = inc + 1 / count;
  1787. }
  1788. return curveCoordinates;
  1789. }
  1790. var curve = {
  1791. getPoints: getCurvePoints
  1792. };
  1793. /*
  1794. FDEB algorithm implementation [www.win.tue.nl/~dholten/papers/forcebundles_eurovis.pdf].
  1795. Author: (github.com/upphiminn)
  1796. 2013
  1797. */
  1798. var ForceEdgeBundling = function ForceEdgeBundling() {
  1799. var data_nodes = {},
  1800. // {'nodeid':{'x':,'y':},..}
  1801. data_edges = [],
  1802. // [{'source':'nodeid1', 'target':'nodeid2'},..]
  1803. compatibility_list_for_edge = [],
  1804. subdivision_points_for_edge = [],
  1805. K = 0.1,
  1806. // global bundling constant controling edge stiffness
  1807. S_initial = 0.1,
  1808. // init. distance to move points
  1809. P_initial = 1,
  1810. // init. subdivision number
  1811. P_rate = 2,
  1812. // subdivision rate increase
  1813. C = 6,
  1814. // number of cycles to perform
  1815. I_initial = 70,
  1816. // init. number of iterations for cycle
  1817. I_rate = 0.6666667,
  1818. // rate at which iteration number decreases i.e. 2/3
  1819. compatibility_threshold = 0.6,
  1820. invers_quadratic_mode = false,
  1821. eps = 1e-8;
  1822. /*** Geometry Helper Methods ***/
  1823. function vector_dot_product(p, q) {
  1824. return p.x * q.x + p.y * q.y;
  1825. }
  1826. function edge_as_vector(P) {
  1827. return { 'x': data_nodes[P.target].x - data_nodes[P.source].x,
  1828. 'y': data_nodes[P.target].y - data_nodes[P.source].y };
  1829. }
  1830. function edge_length(e) {
  1831. 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));
  1832. }
  1833. function custom_edge_length(e) {
  1834. return Math.sqrt(Math.pow(e.source.x - e.target.x, 2) + Math.pow(e.source.y - e.target.y, 2));
  1835. }
  1836. function edge_midpoint(e) {
  1837. var middle_x = (data_nodes[e.source].x + data_nodes[e.target].x) / 2.0;
  1838. var middle_y = (data_nodes[e.source].y + data_nodes[e.target].y) / 2.0;
  1839. return { 'x': middle_x, 'y': middle_y };
  1840. }
  1841. function compute_divided_edge_length(e_idx) {
  1842. var length = 0;
  1843. for (var i = 1; i < subdivision_points_for_edge[e_idx].length; i++) {
  1844. var segment_length = euclidean_distance(subdivision_points_for_edge[e_idx][i], subdivision_points_for_edge[e_idx][i - 1]);
  1845. length += segment_length;
  1846. }
  1847. return length;
  1848. }
  1849. function euclidean_distance(p, q) {
  1850. return Math.sqrt(Math.pow(p.x - q.x, 2) + Math.pow(p.y - q.y, 2));
  1851. }
  1852. function project_point_on_line(p, Q) {
  1853. 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));
  1854. 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);
  1855. return { 'x': Q.source.x + r * (Q.target.x - Q.source.x), 'y': Q.source.y + r * (Q.target.y - Q.source.y) };
  1856. }
  1857. /*** ********************** ***/
  1858. /*** Initialization Methods ***/
  1859. function initialize_edge_subdivisions() {
  1860. for (var i = 0; i < data_edges.length; i++) {
  1861. if (P_initial == 1) subdivision_points_for_edge[i] = []; //0 subdivisions
  1862. else {
  1863. subdivision_points_for_edge[i] = [];
  1864. subdivision_points_for_edge[i].push(data_nodes[data_edges[i].source]);
  1865. subdivision_points_for_edge[i].push(data_nodes[data_edges[i].target]);
  1866. }
  1867. }
  1868. }
  1869. function initialize_compatibility_lists() {
  1870. for (var i = 0; i < data_edges.length; i++) {
  1871. compatibility_list_for_edge[i] = [];
  1872. } //0 compatible edges.
  1873. }
  1874. function filter_self_loops(edgelist) {
  1875. var filtered_edge_list = [];
  1876. for (var e = 0; e < edgelist.length; e++) {
  1877. 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) {
  1878. //or smaller than eps
  1879. filtered_edge_list.push(edgelist[e]);
  1880. }
  1881. }
  1882. return filtered_edge_list;
  1883. }
  1884. /*** ********************** ***/
  1885. /*** Force Calculation Methods ***/
  1886. function apply_spring_force(e_idx, i, kP) {
  1887. var prev = subdivision_points_for_edge[e_idx][i - 1];
  1888. var next = subdivision_points_for_edge[e_idx][i + 1];
  1889. var crnt = subdivision_points_for_edge[e_idx][i];
  1890. var x = prev.x - crnt.x + next.x - crnt.x;
  1891. var y = prev.y - crnt.y + next.y - crnt.y;
  1892. x *= kP;
  1893. y *= kP;
  1894. return { 'x': x, 'y': y };
  1895. }
  1896. function apply_electrostatic_force(e_idx, i, S) {
  1897. var sum_of_forces = { 'x': 0, 'y': 0 };
  1898. var compatible_edges_list = compatibility_list_for_edge[e_idx];
  1899. for (var oe = 0; oe < compatible_edges_list.length; oe++) {
  1900. var force = { 'x': subdivision_points_for_edge[compatible_edges_list[oe]][i].x - subdivision_points_for_edge[e_idx][i].x,
  1901. 'y': subdivision_points_for_edge[compatible_edges_list[oe]][i].y - subdivision_points_for_edge[e_idx][i].y };
  1902. if (Math.abs(force.x) > eps || Math.abs(force.y) > eps) {
  1903. var diff = 1 / Math.pow(custom_edge_length({ 'source': subdivision_points_for_edge[compatible_edges_list[oe]][i],
  1904. 'target': subdivision_points_for_edge[e_idx][i] }), 1);
  1905. sum_of_forces.x += force.x * diff;
  1906. sum_of_forces.y += force.y * diff;
  1907. }
  1908. }
  1909. return sum_of_forces;
  1910. }
  1911. function apply_resulting_forces_on_subdivision_points(e_idx, P, S) {
  1912. 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.
  1913. // (length * (num of sub division pts - 1))
  1914. var resulting_forces_for_subdivision_points = [{ 'x': 0, 'y': 0 }];
  1915. for (var i = 1; i < P + 1; i++) {
  1916. // exclude initial end points of the edge 0 and P+1
  1917. var resulting_force = { 'x': 0, 'y': 0 };
  1918. var spring_force = apply_spring_force(e_idx, i, kP);
  1919. var electrostatic_force = apply_electrostatic_force(e_idx, i, S);
  1920. resulting_force.x = S * (spring_force.x + electrostatic_force.x);
  1921. resulting_force.y = S * (spring_force.y + electrostatic_force.y);
  1922. resulting_forces_for_subdivision_points.push(resulting_force);
  1923. }
  1924. resulting_forces_for_subdivision_points.push({ 'x': 0, 'y': 0 });
  1925. return resulting_forces_for_subdivision_points;
  1926. }
  1927. /*** ********************** ***/
  1928. /*** Edge Division Calculation Methods ***/
  1929. function update_edge_divisions(P) {
  1930. for (var e_idx = 0; e_idx < data_edges.length; e_idx++) {
  1931. if (P == 1) {
  1932. subdivision_points_for_edge[e_idx].push(data_nodes[data_edges[e_idx].source]); // source
  1933. subdivision_points_for_edge[e_idx].push(edge_midpoint(data_edges[e_idx])); // mid point
  1934. subdivision_points_for_edge[e_idx].push(data_nodes[data_edges[e_idx].target]); // target
  1935. } else {
  1936. var divided_edge_length = compute_divided_edge_length(e_idx);
  1937. var segment_length = divided_edge_length / (P + 1);
  1938. var current_segment_length = segment_length;
  1939. var new_subdivision_points = [];
  1940. new_subdivision_points.push(data_nodes[data_edges[e_idx].source]); //source
  1941. for (var i = 1; i < subdivision_points_for_edge[e_idx].length; i++) {
  1942. var old_segment_length = euclidean_distance(subdivision_points_for_edge[e_idx][i], subdivision_points_for_edge[e_idx][i - 1]);
  1943. while (old_segment_length > current_segment_length) {
  1944. var percent_position = current_segment_length / old_segment_length;
  1945. var new_subdivision_point_x = subdivision_points_for_edge[e_idx][i - 1].x;
  1946. var new_subdivision_point_y = subdivision_points_for_edge[e_idx][i - 1].y;
  1947. new_subdivision_point_x += percent_position * (subdivision_points_for_edge[e_idx][i].x - subdivision_points_for_edge[e_idx][i - 1].x);
  1948. new_subdivision_point_y += percent_position * (subdivision_points_for_edge[e_idx][i].y - subdivision_points_for_edge[e_idx][i - 1].y);
  1949. new_subdivision_points.push({ 'x': new_subdivision_point_x,
  1950. 'y': new_subdivision_point_y });
  1951. old_segment_length -= current_segment_length;
  1952. current_segment_length = segment_length;
  1953. }
  1954. current_segment_length -= old_segment_length;
  1955. }
  1956. new_subdivision_points.push(data_nodes[data_edges[e_idx].target]); //target
  1957. subdivision_points_for_edge[e_idx] = new_subdivision_points;
  1958. }
  1959. }
  1960. }
  1961. /*** ********************** ***/
  1962. /*** Edge compatibility measures ***/
  1963. function angle_compatibility(P, Q) {
  1964. var result = Math.abs(vector_dot_product(edge_as_vector(P), edge_as_vector(Q)) / (edge_length(P) * edge_length(Q)));
  1965. return result;
  1966. }
  1967. function scale_compatibility(P, Q) {
  1968. var lavg = (edge_length(P) + edge_length(Q)) / 2.0;
  1969. var result = 2.0 / (lavg / Math.min(edge_length(P), edge_length(Q)) + Math.max(edge_length(P), edge_length(Q)) / lavg);
  1970. return result;
  1971. }
  1972. function position_compatibility(P, Q) {
  1973. var lavg = (edge_length(P) + edge_length(Q)) / 2.0;
  1974. var midP = { 'x': (data_nodes[P.source].x + data_nodes[P.target].x) / 2.0,
  1975. 'y': (data_nodes[P.source].y + data_nodes[P.target].y) / 2.0 };
  1976. var midQ = { 'x': (data_nodes[Q.source].x + data_nodes[Q.target].x) / 2.0,
  1977. 'y': (data_nodes[Q.source].y + data_nodes[Q.target].y) / 2.0 };
  1978. var result = lavg / (lavg + euclidean_distance(midP, midQ));
  1979. return result;
  1980. }
  1981. function edge_visibility(P, Q) {
  1982. var I0 = project_point_on_line(data_nodes[Q.source], { 'source': data_nodes[P.source],
  1983. 'target': data_nodes[P.target] });
  1984. var I1 = project_point_on_line(data_nodes[Q.target], { 'source': data_nodes[P.source],
  1985. 'target': data_nodes[P.target] }); //send acutal edge points positions
  1986. var midI = { 'x': (I0.x + I1.x) / 2.0,
  1987. 'y': (I0.y + I1.y) / 2.0 };
  1988. var midP = { 'x': (data_nodes[P.source].x + data_nodes[P.target].x) / 2.0,
  1989. 'y': (data_nodes[P.source].y + data_nodes[P.target].y) / 2.0 };
  1990. var result = Math.max(0, 1 - 2 * euclidean_distance(midP, midI) / euclidean_distance(I0, I1));
  1991. return result;
  1992. }
  1993. function visibility_compatibility(P, Q) {
  1994. return Math.min(edge_visibility(P, Q), edge_visibility(Q, P));
  1995. }
  1996. function compatibility_score(P, Q) {
  1997. var result = angle_compatibility(P, Q) * scale_compatibility(P, Q) * position_compatibility(P, Q) * visibility_compatibility(P, Q);
  1998. return result;
  1999. }
  2000. function are_compatible(P, Q) {
  2001. // console.log('compatibility ' + P.source +' - '+ P.target + ' and ' + Q.source +' '+ Q.target);
  2002. return compatibility_score(P, Q) >= compatibility_threshold;
  2003. }
  2004. function compute_compatibility_lists() {
  2005. for (var e = 0; e < data_edges.length - 1; e++) {
  2006. for (var oe = e + 1; oe < data_edges.length; oe++) {
  2007. // don't want any duplicates
  2008. if (e == oe) continue;else {
  2009. if (are_compatible(data_edges[e], data_edges[oe])) {
  2010. compatibility_list_for_edge[e].push(oe);
  2011. compatibility_list_for_edge[oe].push(e);
  2012. }
  2013. }
  2014. }
  2015. }
  2016. }
  2017. /*** ************************ ***/
  2018. /*** Main Bundling Loop Methods ***/
  2019. var forcebundle = function forcebundle() {
  2020. var S = S_initial;
  2021. var I = I_initial;
  2022. var P = P_initial;
  2023. initialize_edge_subdivisions();
  2024. initialize_compatibility_lists();
  2025. update_edge_divisions(P);
  2026. compute_compatibility_lists();
  2027. for (var cycle = 0; cycle < C; cycle++) {
  2028. for (var iteration = 0; iteration < I; iteration++) {
  2029. var forces = [];
  2030. for (var edge = 0; edge < data_edges.length; edge++) {
  2031. forces[edge] = apply_resulting_forces_on_subdivision_points(edge, P, S);
  2032. }
  2033. for (var e = 0; e < data_edges.length; e++) {
  2034. for (var i = 0; i < P + 1; i++) {
  2035. subdivision_points_for_edge[e][i].x += forces[e][i].x;
  2036. subdivision_points_for_edge[e][i].y += forces[e][i].y;
  2037. }
  2038. }
  2039. }
  2040. //prepare for next cycle
  2041. S = S / 2;
  2042. P = P * 2;
  2043. I = I_rate * I;
  2044. update_edge_divisions(P);
  2045. // console.log('C' + cycle);
  2046. // console.log('P' + P);
  2047. // console.log('S' + S);
  2048. }
  2049. return subdivision_points_for_edge;
  2050. };
  2051. /*** ************************ ***/
  2052. /*** Getters/Setters Methods ***/
  2053. forcebundle.nodes = function (nl) {
  2054. if (arguments.length == 0) {
  2055. return data_nodes;
  2056. } else {
  2057. data_nodes = nl;
  2058. }
  2059. return forcebundle;
  2060. };
  2061. forcebundle.edges = function (ll) {
  2062. if (arguments.length == 0) {
  2063. return data_edges;
  2064. } else {
  2065. data_edges = filter_self_loops(ll); //remove edges to from to the same point
  2066. }
  2067. return forcebundle;
  2068. };
  2069. forcebundle.bundling_stiffness = function (k) {
  2070. if (arguments.length == 0) {
  2071. return K;
  2072. } else {
  2073. K = k;
  2074. }
  2075. return forcebundle;
  2076. };
  2077. forcebundle.step_size = function (step) {
  2078. if (arguments.length == 0) {
  2079. return S_initial;
  2080. } else {
  2081. S_initial = step;
  2082. }
  2083. return forcebundle;
  2084. };
  2085. forcebundle.cycles = function (c) {
  2086. if (arguments.length == 0) {
  2087. return C;
  2088. } else {
  2089. C = c;
  2090. }
  2091. return forcebundle;
  2092. };
  2093. forcebundle.iterations = function (i) {
  2094. if (arguments.length == 0) {
  2095. return I_initial;
  2096. } else {
  2097. I_initial = i;
  2098. }
  2099. return forcebundle;
  2100. };
  2101. forcebundle.iterations_rate = function (i) {
  2102. if (arguments.length == 0) {
  2103. return I_rate;
  2104. } else {
  2105. I_rate = i;
  2106. }
  2107. return forcebundle;
  2108. };
  2109. forcebundle.subdivision_points_seed = function (p) {
  2110. if (arguments.length == 0) {
  2111. return P;
  2112. } else {
  2113. P = p;
  2114. }
  2115. return forcebundle;
  2116. };
  2117. forcebundle.subdivision_rate = function (r) {
  2118. if (arguments.length == 0) {
  2119. return P_rate;
  2120. } else {
  2121. P_rate = r;
  2122. }
  2123. return forcebundle;
  2124. };
  2125. forcebundle.compatbility_threshold = function (t) {
  2126. if (arguments.length == 0) {
  2127. return compatbility_threshold;
  2128. } else {
  2129. compatibility_threshold = t;
  2130. }
  2131. return forcebundle;
  2132. };
  2133. /*** ************************ ***/
  2134. return forcebundle;
  2135. };
  2136. /**
  2137. * @author kyle / http://nikai.us/
  2138. */
  2139. /**
  2140. * Category
  2141. * @param {Object} splitList:
  2142. * {
  2143. * other: 1,
  2144. * 1: 2,
  2145. * 2: 3,
  2146. * 3: 4,
  2147. * 4: 5,
  2148. * 5: 6,
  2149. * 6: 7
  2150. * }
  2151. */
  2152. function Category(splitList) {
  2153. this.splitList = splitList || {
  2154. other: 1
  2155. };
  2156. }
  2157. Category.prototype.get = function (count) {
  2158. var splitList = this.splitList;
  2159. var value = splitList['other'];
  2160. for (var i in splitList) {
  2161. if (count == i) {
  2162. value = splitList[i];
  2163. break;
  2164. }
  2165. }
  2166. return value;
  2167. };
  2168. /**
  2169. * 根据DataSet自动生成对应的splitList
  2170. */
  2171. Category.prototype.generateByDataSet = function (dataSet, color) {
  2172. 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)'];
  2173. var data = dataSet.get();
  2174. this.splitList = {};
  2175. var count = 0;
  2176. for (var i = 0; i < data.length; i++) {
  2177. if (this.splitList[data[i].count] === undefined) {
  2178. this.splitList[data[i].count] = colors[count];
  2179. count++;
  2180. }
  2181. if (count >= colors.length - 1) {
  2182. break;
  2183. }
  2184. }
  2185. this.splitList['other'] = colors[colors.length - 1];
  2186. };
  2187. Category.prototype.getLegend = function (options) {
  2188. var splitList = this.splitList;
  2189. var container = document.createElement('div');
  2190. container.style.cssText = "background:#fff; padding: 5px; border: 1px solid #ccc;";
  2191. var html = '';
  2192. for (var key in splitList) {
  2193. 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>';
  2194. }
  2195. container.innerHTML = html;
  2196. return container;
  2197. };
  2198. /**
  2199. * @author kyle / http://nikai.us/
  2200. */
  2201. /**
  2202. * Choropleth
  2203. * @param {Object} splitList:
  2204. * [
  2205. * {
  2206. * start: 0,
  2207. * end: 2,
  2208. * value: randomColor()
  2209. * },{
  2210. * start: 2,
  2211. * end: 4,
  2212. * value: randomColor()
  2213. * },{
  2214. * start: 4,
  2215. * value: randomColor()
  2216. * }
  2217. * ];
  2218. *
  2219. */
  2220. function Choropleth(splitList) {
  2221. this.splitList = splitList || [{
  2222. start: 0,
  2223. value: 'red'
  2224. }];
  2225. }
  2226. Choropleth.prototype.get = function (count) {
  2227. var splitList = this.splitList;
  2228. var value = false;
  2229. for (var i = 0; i < splitList.length; i++) {
  2230. 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)) {
  2231. value = splitList[i].value;
  2232. break;
  2233. }
  2234. }
  2235. return value;
  2236. };
  2237. /**
  2238. * 根据DataSet自动生成对应的splitList
  2239. */
  2240. Choropleth.prototype.generateByDataSet = function (dataSet) {
  2241. var min = dataSet.getMin('count');
  2242. var max = dataSet.getMax('count');
  2243. this.generateByMinMax(min, max);
  2244. };
  2245. /**
  2246. * 根据DataSet自动生成对应的splitList
  2247. */
  2248. Choropleth.prototype.generateByMinMax = function (min, max) {
  2249. 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)'];
  2250. var splitNum = Number((max - min) / 7);
  2251. // console.log(splitNum)
  2252. max = Number(max);
  2253. var index = Number(min);
  2254. this.splitList = [];
  2255. var count = 0;
  2256. while (index < max) {
  2257. this.splitList.push({
  2258. start: index,
  2259. end: index + splitNum,
  2260. value: colors[count]
  2261. });
  2262. count++;
  2263. index += splitNum;
  2264. // console.log(index, max)
  2265. }
  2266. // console.log('splitNum')
  2267. };
  2268. Choropleth.prototype.getLegend = function (options) {
  2269. var splitList = this.splitList;
  2270. };
  2271. /**
  2272. * @author Mofei<http://www.zhuwenlong.com>
  2273. */
  2274. var MapHelper = function () {
  2275. function MapHelper(id, type, opt) {
  2276. classCallCheck(this, MapHelper);
  2277. if (!id || !type) {
  2278. console.warn('id 和 type 为必填项');
  2279. return false;
  2280. }
  2281. if (type == 'baidu') {
  2282. if (!BMap) {
  2283. console.warn('请先引入百度地图JS API');
  2284. return false;
  2285. }
  2286. } else {
  2287. console.warn('暂不支持你的地图类型');
  2288. }
  2289. this.type = type;
  2290. var center = opt && opt.center ? opt.center : [106.962497, 38.208726];
  2291. var zoom = opt && opt.zoom ? opt.zoom : 5;
  2292. var map = this.map = new BMap.Map(id, {
  2293. enableMapClick: false
  2294. });
  2295. map.centerAndZoom(new BMap.Point(center[0], center[1]), zoom);
  2296. map.enableScrollWheelZoom(true);
  2297. map.setMapStyle({
  2298. style: 'light'
  2299. });
  2300. }
  2301. createClass(MapHelper, [{
  2302. key: 'addLayer',
  2303. value: function addLayer(datas, options) {
  2304. if (this.type == 'baidu') {
  2305. return new mapv.baiduMapLayer(this.map, dataSet, options);
  2306. }
  2307. }
  2308. }, {
  2309. key: 'getMap',
  2310. value: function getMap() {
  2311. return this.map;
  2312. }
  2313. }]);
  2314. return MapHelper;
  2315. }();
  2316. // function MapHelper(dom, type, opt) {
  2317. // var map = new BMap.Map(dom, {
  2318. // enableMapClick: false
  2319. // });
  2320. // map.centerAndZoom(new BMap.Point(106.962497, 38.208726), 5);
  2321. // map.enableScrollWheelZoom(true);
  2322. // map.setMapStyle({
  2323. // style: 'light'
  2324. // });
  2325. // }
  2326. /**
  2327. * 一直覆盖在当前地图视野的Canvas对象
  2328. *
  2329. * @author nikai (@胖嘟嘟的骨头, nikai@baidu.com)
  2330. *
  2331. * @param
  2332. * {
  2333. * map 地图实例对象
  2334. * }
  2335. */
  2336. function CanvasLayer(options) {
  2337. this.options = options || {};
  2338. this.paneName = this.options.paneName || 'mapPane';
  2339. this.context = this.options.context || '2d';
  2340. this.zIndex = this.options.zIndex || 0;
  2341. this.mixBlendMode = this.options.mixBlendMode || null;
  2342. this.enableMassClear = this.options.enableMassClear;
  2343. this._map = options.map;
  2344. this._lastDrawTime = null;
  2345. this.show();
  2346. }
  2347. var global$3 = typeof window === 'undefined' ? {} : window;
  2348. if (global$3.BMap) {
  2349. CanvasLayer.prototype = new BMap.Overlay();
  2350. CanvasLayer.prototype.initialize = function (map) {
  2351. this._map = map;
  2352. var canvas = this.canvas = document.createElement("canvas");
  2353. canvas.style.cssText = "position:absolute;" + "left:0;" + "top:0;" + "z-index:" + this.zIndex + ";user-select:none;";
  2354. canvas.style.mixBlendMode = this.mixBlendMode;
  2355. this.adjustSize();
  2356. map.getPanes()[this.paneName].appendChild(canvas);
  2357. var that = this;
  2358. map.addEventListener('resize', function () {
  2359. that.adjustSize();
  2360. that._draw();
  2361. });
  2362. return this.canvas;
  2363. };
  2364. CanvasLayer.prototype.adjustSize = function () {
  2365. var size = this._map.getSize();
  2366. var canvas = this.canvas;
  2367. var devicePixelRatio = this.devicePixelRatio = global$3.devicePixelRatio || 1;
  2368. canvas.width = size.width * devicePixelRatio;
  2369. canvas.height = size.height * devicePixelRatio;
  2370. if (this.context == '2d') {
  2371. canvas.getContext(this.context).scale(devicePixelRatio, devicePixelRatio);
  2372. }
  2373. canvas.style.width = size.width + "px";
  2374. canvas.style.height = size.height + "px";
  2375. };
  2376. CanvasLayer.prototype.draw = function () {
  2377. var self = this;
  2378. clearTimeout(self.timeoutID);
  2379. self.timeoutID = setTimeout(function () {
  2380. self._draw();
  2381. }, 15);
  2382. };
  2383. CanvasLayer.prototype._draw = function () {
  2384. var map = this._map;
  2385. var size = map.getSize();
  2386. var center = map.getCenter();
  2387. if (center) {
  2388. var pixel = map.pointToOverlayPixel(center);
  2389. this.canvas.style.left = pixel.x - size.width / 2 + 'px';
  2390. this.canvas.style.top = pixel.y - size.height / 2 + 'px';
  2391. this.dispatchEvent('draw');
  2392. this.options.update && this.options.update.call(this);
  2393. }
  2394. };
  2395. CanvasLayer.prototype.getContainer = function () {
  2396. return this.canvas;
  2397. };
  2398. CanvasLayer.prototype.show = function () {
  2399. if (!this.canvas) {
  2400. this._map.addOverlay(this);
  2401. }
  2402. this.canvas.style.display = "block";
  2403. };
  2404. CanvasLayer.prototype.hide = function () {
  2405. this.canvas.style.display = "none";
  2406. //this._map.removeOverlay(this);
  2407. };
  2408. CanvasLayer.prototype.setZIndex = function (zIndex) {
  2409. this.zIndex = zIndex;
  2410. this.canvas.style.zIndex = this.zIndex;
  2411. };
  2412. CanvasLayer.prototype.getZIndex = function () {
  2413. return this.zIndex;
  2414. };
  2415. }
  2416. /**
  2417. * Tween.js - Licensed under the MIT license
  2418. * https://github.com/tweenjs/tween.js
  2419. * ----------------------------------------------
  2420. *
  2421. * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
  2422. * Thank you all, you're awesome!
  2423. */
  2424. var TWEEN = TWEEN || function () {
  2425. var _tweens = [];
  2426. return {
  2427. getAll: function getAll() {
  2428. return _tweens;
  2429. },
  2430. removeAll: function removeAll() {
  2431. _tweens = [];
  2432. },
  2433. add: function add(tween) {
  2434. _tweens.push(tween);
  2435. },
  2436. remove: function remove(tween) {
  2437. var i = _tweens.indexOf(tween);
  2438. if (i !== -1) {
  2439. _tweens.splice(i, 1);
  2440. }
  2441. },
  2442. update: function update(time, preserve) {
  2443. if (_tweens.length === 0) {
  2444. return false;
  2445. }
  2446. var i = 0;
  2447. time = time !== undefined ? time : TWEEN.now();
  2448. while (i < _tweens.length) {
  2449. if (_tweens[i].update(time) || preserve) {
  2450. i++;
  2451. } else {
  2452. _tweens.splice(i, 1);
  2453. }
  2454. }
  2455. return true;
  2456. }
  2457. };
  2458. }();
  2459. // Include a performance.now polyfill.
  2460. // In node.js, use process.hrtime.
  2461. if (typeof window === 'undefined' && typeof process !== 'undefined') {
  2462. TWEEN.now = function () {
  2463. var time = process.hrtime();
  2464. // Convert [seconds, nanoseconds] to milliseconds.
  2465. return time[0] * 1000 + time[1] / 1000000;
  2466. };
  2467. }
  2468. // In a browser, use window.performance.now if it is available.
  2469. else if (typeof window !== 'undefined' && window.performance !== undefined && window.performance.now !== undefined) {
  2470. // This must be bound, because directly assigning this function
  2471. // leads to an invocation exception in Chrome.
  2472. TWEEN.now = window.performance.now.bind(window.performance);
  2473. }
  2474. // Use Date.now if it is available.
  2475. else if (Date.now !== undefined) {
  2476. TWEEN.now = Date.now;
  2477. }
  2478. // Otherwise, use 'new Date().getTime()'.
  2479. else {
  2480. TWEEN.now = function () {
  2481. return new Date().getTime();
  2482. };
  2483. }
  2484. TWEEN.Tween = function (object) {
  2485. var _object = object;
  2486. var _valuesStart = {};
  2487. var _valuesEnd = {};
  2488. var _valuesStartRepeat = {};
  2489. var _duration = 1000;
  2490. var _repeat = 0;
  2491. var _repeatDelayTime;
  2492. var _yoyo = false;
  2493. var _isPlaying = false;
  2494. var _reversed = false;
  2495. var _delayTime = 0;
  2496. var _startTime = null;
  2497. var _easingFunction = TWEEN.Easing.Linear.None;
  2498. var _interpolationFunction = TWEEN.Interpolation.Linear;
  2499. var _chainedTweens = [];
  2500. var _onStartCallback = null;
  2501. var _onStartCallbackFired = false;
  2502. var _onUpdateCallback = null;
  2503. var _onCompleteCallback = null;
  2504. var _onStopCallback = null;
  2505. this.to = function (properties, duration) {
  2506. _valuesEnd = properties;
  2507. if (duration !== undefined) {
  2508. _duration = duration;
  2509. }
  2510. return this;
  2511. };
  2512. this.start = function (time) {
  2513. TWEEN.add(this);
  2514. _isPlaying = true;
  2515. _onStartCallbackFired = false;
  2516. _startTime = time !== undefined ? time : TWEEN.now();
  2517. _startTime += _delayTime;
  2518. for (var property in _valuesEnd) {
  2519. // Check if an Array was provided as property value
  2520. if (_valuesEnd[property] instanceof Array) {
  2521. if (_valuesEnd[property].length === 0) {
  2522. continue;
  2523. }
  2524. // Create a local copy of the Array with the start value at the front
  2525. _valuesEnd[property] = [_object[property]].concat(_valuesEnd[property]);
  2526. }
  2527. // If `to()` specifies a property that doesn't exist in the source object,
  2528. // we should not set that property in the object
  2529. if (_object[property] === undefined) {
  2530. continue;
  2531. }
  2532. // Save the starting value.
  2533. _valuesStart[property] = _object[property];
  2534. if (_valuesStart[property] instanceof Array === false) {
  2535. _valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings
  2536. }
  2537. _valuesStartRepeat[property] = _valuesStart[property] || 0;
  2538. }
  2539. return this;
  2540. };
  2541. this.stop = function () {
  2542. if (!_isPlaying) {
  2543. return this;
  2544. }
  2545. TWEEN.remove(this);
  2546. _isPlaying = false;
  2547. if (_onStopCallback !== null) {
  2548. _onStopCallback.call(_object, _object);
  2549. }
  2550. this.stopChainedTweens();
  2551. return this;
  2552. };
  2553. this.end = function () {
  2554. this.update(_startTime + _duration);
  2555. return this;
  2556. };
  2557. this.stopChainedTweens = function () {
  2558. for (var i = 0, numChainedTweens = _chainedTweens.length; i < numChainedTweens; i++) {
  2559. _chainedTweens[i].stop();
  2560. }
  2561. };
  2562. this.delay = function (amount) {
  2563. _delayTime = amount;
  2564. return this;
  2565. };
  2566. this.repeat = function (times) {
  2567. _repeat = times;
  2568. return this;
  2569. };
  2570. this.repeatDelay = function (amount) {
  2571. _repeatDelayTime = amount;
  2572. return this;
  2573. };
  2574. this.yoyo = function (yoyo) {
  2575. _yoyo = yoyo;
  2576. return this;
  2577. };
  2578. this.easing = function (easing) {
  2579. _easingFunction = easing;
  2580. return this;
  2581. };
  2582. this.interpolation = function (interpolation) {
  2583. _interpolationFunction = interpolation;
  2584. return this;
  2585. };
  2586. this.chain = function () {
  2587. _chainedTweens = arguments;
  2588. return this;
  2589. };
  2590. this.onStart = function (callback) {
  2591. _onStartCallback = callback;
  2592. return this;
  2593. };
  2594. this.onUpdate = function (callback) {
  2595. _onUpdateCallback = callback;
  2596. return this;
  2597. };
  2598. this.onComplete = function (callback) {
  2599. _onCompleteCallback = callback;
  2600. return this;
  2601. };
  2602. this.onStop = function (callback) {
  2603. _onStopCallback = callback;
  2604. return this;
  2605. };
  2606. this.update = function (time) {
  2607. var property;
  2608. var elapsed;
  2609. var value;
  2610. if (time < _startTime) {
  2611. return true;
  2612. }
  2613. if (_onStartCallbackFired === false) {
  2614. if (_onStartCallback !== null) {
  2615. _onStartCallback.call(_object, _object);
  2616. }
  2617. _onStartCallbackFired = true;
  2618. }
  2619. elapsed = (time - _startTime) / _duration;
  2620. elapsed = elapsed > 1 ? 1 : elapsed;
  2621. value = _easingFunction(elapsed);
  2622. for (property in _valuesEnd) {
  2623. // Don't update properties that do not exist in the source object
  2624. if (_valuesStart[property] === undefined) {
  2625. continue;
  2626. }
  2627. var start = _valuesStart[property] || 0;
  2628. var end = _valuesEnd[property];
  2629. if (end instanceof Array) {
  2630. _object[property] = _interpolationFunction(end, value);
  2631. } else {
  2632. // Parses relative end values with start as base (e.g.: +10, -3)
  2633. if (typeof end === 'string') {
  2634. if (end.charAt(0) === '+' || end.charAt(0) === '-') {
  2635. end = start + parseFloat(end);
  2636. } else {
  2637. end = parseFloat(end);
  2638. }
  2639. }
  2640. // Protect against non numeric properties.
  2641. if (typeof end === 'number') {
  2642. _object[property] = start + (end - start) * value;
  2643. }
  2644. }
  2645. }
  2646. if (_onUpdateCallback !== null) {
  2647. _onUpdateCallback.call(_object, value);
  2648. }
  2649. if (elapsed === 1) {
  2650. if (_repeat > 0) {
  2651. if (isFinite(_repeat)) {
  2652. _repeat--;
  2653. }
  2654. // Reassign starting values, restart by making startTime = now
  2655. for (property in _valuesStartRepeat) {
  2656. if (typeof _valuesEnd[property] === 'string') {
  2657. _valuesStartRepeat[property] = _valuesStartRepeat[property] + parseFloat(_valuesEnd[property]);
  2658. }
  2659. if (_yoyo) {
  2660. var tmp = _valuesStartRepeat[property];
  2661. _valuesStartRepeat[property] = _valuesEnd[property];
  2662. _valuesEnd[property] = tmp;
  2663. }
  2664. _valuesStart[property] = _valuesStartRepeat[property];
  2665. }
  2666. if (_yoyo) {
  2667. _reversed = !_reversed;
  2668. }
  2669. if (_repeatDelayTime !== undefined) {
  2670. _startTime = time + _repeatDelayTime;
  2671. } else {
  2672. _startTime = time + _delayTime;
  2673. }
  2674. return true;
  2675. } else {
  2676. if (_onCompleteCallback !== null) {
  2677. _onCompleteCallback.call(_object, _object);
  2678. }
  2679. for (var i = 0, numChainedTweens = _chainedTweens.length; i < numChainedTweens; i++) {
  2680. // Make the chained tweens start exactly at the time they should,
  2681. // even if the `update()` method was called way past the duration of the tween
  2682. _chainedTweens[i].start(_startTime + _duration);
  2683. }
  2684. return false;
  2685. }
  2686. }
  2687. return true;
  2688. };
  2689. };
  2690. TWEEN.Easing = {
  2691. Linear: {
  2692. None: function None(k) {
  2693. return k;
  2694. }
  2695. },
  2696. Quadratic: {
  2697. In: function In(k) {
  2698. return k * k;
  2699. },
  2700. Out: function Out(k) {
  2701. return k * (2 - k);
  2702. },
  2703. InOut: function InOut(k) {
  2704. if ((k *= 2) < 1) {
  2705. return 0.5 * k * k;
  2706. }
  2707. return -0.5 * (--k * (k - 2) - 1);
  2708. }
  2709. },
  2710. Cubic: {
  2711. In: function In(k) {
  2712. return k * k * k;
  2713. },
  2714. Out: function Out(k) {
  2715. return --k * k * k + 1;
  2716. },
  2717. InOut: function InOut(k) {
  2718. if ((k *= 2) < 1) {
  2719. return 0.5 * k * k * k;
  2720. }
  2721. return 0.5 * ((k -= 2) * k * k + 2);
  2722. }
  2723. },
  2724. Quartic: {
  2725. In: function In(k) {
  2726. return k * k * k * k;
  2727. },
  2728. Out: function Out(k) {
  2729. return 1 - --k * k * k * k;
  2730. },
  2731. InOut: function InOut(k) {
  2732. if ((k *= 2) < 1) {
  2733. return 0.5 * k * k * k * k;
  2734. }
  2735. return -0.5 * ((k -= 2) * k * k * k - 2);
  2736. }
  2737. },
  2738. Quintic: {
  2739. In: function In(k) {
  2740. return k * k * k * k * k;
  2741. },
  2742. Out: function Out(k) {
  2743. return --k * k * k * k * k + 1;
  2744. },
  2745. InOut: function InOut(k) {
  2746. if ((k *= 2) < 1) {
  2747. return 0.5 * k * k * k * k * k;
  2748. }
  2749. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  2750. }
  2751. },
  2752. Sinusoidal: {
  2753. In: function In(k) {
  2754. return 1 - Math.cos(k * Math.PI / 2);
  2755. },
  2756. Out: function Out(k) {
  2757. return Math.sin(k * Math.PI / 2);
  2758. },
  2759. InOut: function InOut(k) {
  2760. return 0.5 * (1 - Math.cos(Math.PI * k));
  2761. }
  2762. },
  2763. Exponential: {
  2764. In: function In(k) {
  2765. return k === 0 ? 0 : Math.pow(1024, k - 1);
  2766. },
  2767. Out: function Out(k) {
  2768. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  2769. },
  2770. InOut: function InOut(k) {
  2771. if (k === 0) {
  2772. return 0;
  2773. }
  2774. if (k === 1) {
  2775. return 1;
  2776. }
  2777. if ((k *= 2) < 1) {
  2778. return 0.5 * Math.pow(1024, k - 1);
  2779. }
  2780. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  2781. }
  2782. },
  2783. Circular: {
  2784. In: function In(k) {
  2785. return 1 - Math.sqrt(1 - k * k);
  2786. },
  2787. Out: function Out(k) {
  2788. return Math.sqrt(1 - --k * k);
  2789. },
  2790. InOut: function InOut(k) {
  2791. if ((k *= 2) < 1) {
  2792. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  2793. }
  2794. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  2795. }
  2796. },
  2797. Elastic: {
  2798. In: function In(k) {
  2799. if (k === 0) {
  2800. return 0;
  2801. }
  2802. if (k === 1) {
  2803. return 1;
  2804. }
  2805. return -Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI);
  2806. },
  2807. Out: function Out(k) {
  2808. if (k === 0) {
  2809. return 0;
  2810. }
  2811. if (k === 1) {
  2812. return 1;
  2813. }
  2814. return Math.pow(2, -10 * k) * Math.sin((k - 0.1) * 5 * Math.PI) + 1;
  2815. },
  2816. InOut: function InOut(k) {
  2817. if (k === 0) {
  2818. return 0;
  2819. }
  2820. if (k === 1) {
  2821. return 1;
  2822. }
  2823. k *= 2;
  2824. if (k < 1) {
  2825. return -0.5 * Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI);
  2826. }
  2827. return 0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1;
  2828. }
  2829. },
  2830. Back: {
  2831. In: function In(k) {
  2832. var s = 1.70158;
  2833. return k * k * ((s + 1) * k - s);
  2834. },
  2835. Out: function Out(k) {
  2836. var s = 1.70158;
  2837. return --k * k * ((s + 1) * k + s) + 1;
  2838. },
  2839. InOut: function InOut(k) {
  2840. var s = 1.70158 * 1.525;
  2841. if ((k *= 2) < 1) {
  2842. return 0.5 * (k * k * ((s + 1) * k - s));
  2843. }
  2844. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  2845. }
  2846. },
  2847. Bounce: {
  2848. In: function In(k) {
  2849. return 1 - TWEEN.Easing.Bounce.Out(1 - k);
  2850. },
  2851. Out: function Out(k) {
  2852. if (k < 1 / 2.75) {
  2853. return 7.5625 * k * k;
  2854. } else if (k < 2 / 2.75) {
  2855. return 7.5625 * (k -= 1.5 / 2.75) * k + 0.75;
  2856. } else if (k < 2.5 / 2.75) {
  2857. return 7.5625 * (k -= 2.25 / 2.75) * k + 0.9375;
  2858. } else {
  2859. return 7.5625 * (k -= 2.625 / 2.75) * k + 0.984375;
  2860. }
  2861. },
  2862. InOut: function InOut(k) {
  2863. if (k < 0.5) {
  2864. return TWEEN.Easing.Bounce.In(k * 2) * 0.5;
  2865. }
  2866. return TWEEN.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5;
  2867. }
  2868. }
  2869. };
  2870. TWEEN.Interpolation = {
  2871. Linear: function Linear(v, k) {
  2872. var m = v.length - 1;
  2873. var f = m * k;
  2874. var i = Math.floor(f);
  2875. var fn = TWEEN.Interpolation.Utils.Linear;
  2876. if (k < 0) {
  2877. return fn(v[0], v[1], f);
  2878. }
  2879. if (k > 1) {
  2880. return fn(v[m], v[m - 1], m - f);
  2881. }
  2882. return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);
  2883. },
  2884. Bezier: function Bezier(v, k) {
  2885. var b = 0;
  2886. var n = v.length - 1;
  2887. var pw = Math.pow;
  2888. var bn = TWEEN.Interpolation.Utils.Bernstein;
  2889. for (var i = 0; i <= n; i++) {
  2890. b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
  2891. }
  2892. return b;
  2893. },
  2894. CatmullRom: function CatmullRom(v, k) {
  2895. var m = v.length - 1;
  2896. var f = m * k;
  2897. var i = Math.floor(f);
  2898. var fn = TWEEN.Interpolation.Utils.CatmullRom;
  2899. if (v[0] === v[m]) {
  2900. if (k < 0) {
  2901. i = Math.floor(f = m * (1 + k));
  2902. }
  2903. return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
  2904. } else {
  2905. if (k < 0) {
  2906. return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);
  2907. }
  2908. if (k > 1) {
  2909. return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
  2910. }
  2911. 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);
  2912. }
  2913. },
  2914. Utils: {
  2915. Linear: function Linear(p0, p1, t) {
  2916. return (p1 - p0) * t + p0;
  2917. },
  2918. Bernstein: function Bernstein(n, i) {
  2919. var fc = TWEEN.Interpolation.Utils.Factorial;
  2920. return fc(n) / fc(i) / fc(n - i);
  2921. },
  2922. Factorial: function () {
  2923. var a = [1];
  2924. return function (n) {
  2925. var s = 1;
  2926. if (a[n]) {
  2927. return a[n];
  2928. }
  2929. for (var i = n; i > 1; i--) {
  2930. s *= i;
  2931. }
  2932. a[n] = s;
  2933. return s;
  2934. };
  2935. }(),
  2936. CatmullRom: function CatmullRom(p0, p1, p2, p3, t) {
  2937. var v0 = (p2 - p0) * 0.5;
  2938. var v1 = (p3 - p1) * 0.5;
  2939. var t2 = t * t;
  2940. var t3 = t * t2;
  2941. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  2942. }
  2943. }
  2944. };
  2945. /**
  2946. * 根据2点获取角度
  2947. * @param Array [123, 23] 点1
  2948. * @param Array [123, 23] 点2
  2949. * @return angle 角度,不是弧度
  2950. */
  2951. function getAngle(start, end) {
  2952. var diff_x = end[0] - start[0];
  2953. var diff_y = end[1] - start[1];
  2954. var deg = 360 * Math.atan(diff_y / diff_x) / (2 * Math.PI);
  2955. if (end[0] < start[0]) {
  2956. deg = deg + 180;
  2957. }
  2958. return deg;
  2959. }
  2960. /**
  2961. * 绘制沿线箭头
  2962. * @author kyle / http://nikai.us/
  2963. */
  2964. var imageCache = {};
  2965. var object = {
  2966. draw: function draw(context, dataSet, options) {
  2967. var imageCacheKey = 'http://huiyan.baidu.com/github/tools/gis-drawing/static/images/direction.png';
  2968. if (options.arrow && options.arrow.url) {
  2969. imageCacheKey = options.arrow.url;
  2970. }
  2971. if (!imageCache[imageCacheKey]) {
  2972. imageCache[imageCacheKey] = null;
  2973. }
  2974. var directionImage = imageCache[imageCacheKey];
  2975. if (!directionImage) {
  2976. var args = Array.prototype.slice.call(arguments);
  2977. var image = new Image();
  2978. image.onload = function () {
  2979. imageCache[imageCacheKey] = image;
  2980. object.draw.apply(null, args);
  2981. };
  2982. image.src = imageCacheKey;
  2983. return;
  2984. }
  2985. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  2986. // console.log('xxxx',options)
  2987. context.save();
  2988. for (var key in options) {
  2989. context[key] = options[key];
  2990. }
  2991. var points = [];
  2992. var preCoordinate = null;
  2993. for (var i = 0, len = data.length; i < len; i++) {
  2994. var item = data[i];
  2995. context.save();
  2996. if (item.fillStyle || item._fillStyle) {
  2997. context.fillStyle = item.fillStyle || item._fillStyle;
  2998. }
  2999. if (item.strokeStyle || item._strokeStyle) {
  3000. context.strokeStyle = item.strokeStyle || item._strokeStyle;
  3001. }
  3002. var type = item.geometry.type;
  3003. context.beginPath();
  3004. if (type === 'LineString') {
  3005. var coordinates = item.geometry._coordinates || item.geometry.coordinates;
  3006. var interval = options.arrow.interval !== undefined ? options.arrow.interval : 1;
  3007. for (var j = 0; j < coordinates.length; j += interval) {
  3008. if (coordinates[j] && coordinates[j + 1]) {
  3009. var coordinate = coordinates[j];
  3010. if (preCoordinate && getDistance(coordinate, preCoordinate) < 30) {
  3011. continue;
  3012. }
  3013. context.save();
  3014. var angle = getAngle(coordinates[j], coordinates[j + 1]);
  3015. context.translate(coordinate[0], coordinate[1]);
  3016. context.rotate(angle * Math.PI / 180);
  3017. context.drawImage(directionImage, -directionImage.width / 2 / devicePixelRatio, -directionImage.height / 2 / devicePixelRatio, directionImage.width / devicePixelRatio, directionImage.height / devicePixelRatio);
  3018. context.restore();
  3019. points.push(coordinate);
  3020. preCoordinate = coordinate;
  3021. }
  3022. }
  3023. }
  3024. context.restore();
  3025. }
  3026. context.restore();
  3027. }
  3028. };
  3029. function getDistance(coordinateA, coordinateB) {
  3030. return Math.sqrt(Math.pow(coordinateA[0] - coordinateB[0], 2) + Math.pow(coordinateA[1] - coordinateB[1], 2));
  3031. }
  3032. /**
  3033. * @author Mofei Zhu<mapv@zhuwenlong.com>
  3034. * This file is to draw text
  3035. */
  3036. var drawText = {
  3037. draw: function draw(context, dataSet, options) {
  3038. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  3039. context.save();
  3040. // set from options
  3041. for (var key in options) {
  3042. context[key] = options[key];
  3043. }
  3044. var offset = options.offset || {
  3045. x: 0,
  3046. y: 0
  3047. };
  3048. var rects = [];
  3049. var size = options._size || options.size;
  3050. if (size) {
  3051. context.font = "bold " + size + "px Arial";
  3052. } else {
  3053. size = 12;
  3054. }
  3055. var textKey = options.textKey || 'text';
  3056. if (!options.textAlign) {
  3057. context.textAlign = 'center';
  3058. }
  3059. if (!options.textBaseline) {
  3060. context.textBaseline = 'middle';
  3061. }
  3062. if (options.avoid) {
  3063. // 标注避让
  3064. for (var i = 0, len = data.length; i < len; i++) {
  3065. var coordinates = data[i].geometry._coordinates || data[i].geometry.coordinates;
  3066. var x = coordinates[0] + offset.x;
  3067. var y = coordinates[1] + offset.y;
  3068. var text = data[i][textKey];
  3069. var textWidth = context.measureText(text).width;
  3070. // 根据文本宽度和高度调整x,y位置,使得绘制文本时候坐标点在文本中心点,这个计算出的是左上角坐标
  3071. var px = x - textWidth / 2;
  3072. var py = y - size / 2;
  3073. var rect = {
  3074. sw: {
  3075. x: px,
  3076. y: py + size
  3077. },
  3078. ne: {
  3079. x: px + textWidth,
  3080. y: py
  3081. }
  3082. };
  3083. if (!hasOverlay(rects, rect)) {
  3084. rects.push(rect);
  3085. px = px + textWidth / 2;
  3086. py = py + size / 2;
  3087. context.fillText(text, px, py);
  3088. }
  3089. }
  3090. } else {
  3091. for (var i = 0, len = data.length; i < len; i++) {
  3092. var coordinates = data[i].geometry._coordinates || data[i].geometry.coordinates;
  3093. var x = coordinates[0] + offset.x;
  3094. var y = coordinates[1] + offset.y;
  3095. var text = data[i][textKey];
  3096. context.fillText(text, x, y);
  3097. }
  3098. }
  3099. context.restore();
  3100. }
  3101. /*
  3102. * 当前文字区域和已有的文字区域是否有重叠部分
  3103. */
  3104. };function hasOverlay(rects, overlay) {
  3105. for (var i = 0; i < rects.length; i++) {
  3106. if (isRectOverlay(rects[i], overlay)) {
  3107. return true;
  3108. }
  3109. }
  3110. return false;
  3111. }
  3112. //判断2个矩形是否有重叠部分
  3113. function isRectOverlay(rect1, rect2) {
  3114. //minx、miny 2个矩形右下角最小的x和y
  3115. //maxx、maxy 2个矩形左上角最大的x和y
  3116. var minx = Math.min(rect1.ne.x, rect2.ne.x);
  3117. var miny = Math.min(rect1.sw.y, rect2.sw.y);
  3118. var maxx = Math.max(rect1.sw.x, rect2.sw.x);
  3119. var maxy = Math.max(rect1.ne.y, rect2.ne.y);
  3120. if (minx > maxx && miny > maxy) {
  3121. return true;
  3122. }
  3123. return false;
  3124. }
  3125. /**
  3126. * @author Mofei Zhu<mapv@zhuwenlong.com>
  3127. * This file is to draw text
  3128. */
  3129. var drawIcon = {
  3130. draw: function draw(context, dataSet, options) {
  3131. var data = dataSet instanceof DataSet ? dataSet.get() : dataSet;
  3132. context.fillStyle = 'white';
  3133. context.textAlign = 'center';
  3134. context.textBaseline = 'middle';
  3135. var offset = options.offset || {
  3136. x: 0,
  3137. y: 0
  3138. };
  3139. // set from options
  3140. // for (var key in options) {
  3141. // context[key] = options[key];
  3142. // }
  3143. // console.log(data)
  3144. for (var i = 0, len = data.length; i < len; i++) {
  3145. if (data[i].geometry) {
  3146. var deg = data[i].deg || options.deg;
  3147. var icon = data[i].icon || options.icon;
  3148. var coordinates = data[i].geometry._coordinates || data[i].geometry.coordinates;
  3149. var x = coordinates[0];
  3150. var y = coordinates[1];
  3151. if (deg) {
  3152. context.save();
  3153. context.translate(x, y);
  3154. context.rotate(deg * Math.PI / 180);
  3155. context.translate(-x, -y);
  3156. }
  3157. var width = options._width || options.width || icon.width;
  3158. var height = options._height || options.height || icon.height;
  3159. x = x - width / 2 + offset.x;
  3160. y = y - height / 2 + offset.y;
  3161. if (options.sx && options.sy && options.swidth && options.sheight && options.width && options.height) {
  3162. context.drawImage(icon, options.sx, options.sy, options.swidth, options.sheight, x, y, width, height);
  3163. } else if (options.width && options.height) {
  3164. context.drawImage(icon, x, y, width, height);
  3165. } else {
  3166. context.drawImage(icon, x, y);
  3167. }
  3168. if (deg) {
  3169. context.restore();
  3170. }
  3171. }
  3172. }
  3173. }
  3174. };
  3175. /**
  3176. * @author kyle / http://nikai.us/
  3177. */
  3178. if (typeof window !== 'undefined') {
  3179. requestAnimationFrame(animate);
  3180. }
  3181. function animate(time) {
  3182. requestAnimationFrame(animate);
  3183. TWEEN.update(time);
  3184. }
  3185. var BaseLayer = function () {
  3186. function BaseLayer(map, dataSet, options) {
  3187. classCallCheck(this, BaseLayer);
  3188. if (!(dataSet instanceof DataSet)) {
  3189. dataSet = new DataSet(dataSet);
  3190. }
  3191. this.dataSet = dataSet;
  3192. this.map = map;
  3193. }
  3194. createClass(BaseLayer, [{
  3195. key: "getDefaultContextConfig",
  3196. value: function getDefaultContextConfig() {
  3197. return {
  3198. globalAlpha: 1,
  3199. globalCompositeOperation: 'source-over',
  3200. imageSmoothingEnabled: true,
  3201. strokeStyle: '#000000',
  3202. fillStyle: '#000000',
  3203. shadowOffsetX: 0,
  3204. shadowOffsetY: 0,
  3205. shadowBlur: 0,
  3206. shadowColor: 'rgba(0, 0, 0, 0)',
  3207. lineWidth: 1,
  3208. lineCap: 'butt',
  3209. lineJoin: 'miter',
  3210. miterLimit: 10,
  3211. lineDashOffset: 0,
  3212. font: '10px sans-serif',
  3213. textAlign: 'start',
  3214. textBaseline: 'alphabetic'
  3215. };
  3216. }
  3217. }, {
  3218. key: "initDataRange",
  3219. value: function initDataRange(options) {
  3220. var self = this;
  3221. self.intensity = new Intensity({
  3222. maxSize: self.options.maxSize,
  3223. minSize: self.options.minSize,
  3224. gradient: self.options.gradient,
  3225. max: self.options.max || this.dataSet.getMax('count')
  3226. });
  3227. self.category = new Category(self.options.splitList);
  3228. self.choropleth = new Choropleth(self.options.splitList);
  3229. if (self.options.splitList === undefined) {
  3230. self.category.generateByDataSet(this.dataSet, self.options.color);
  3231. }
  3232. if (self.options.splitList === undefined) {
  3233. var min = self.options.min || this.dataSet.getMin('count');
  3234. var max = self.options.max || this.dataSet.getMax('count');
  3235. self.choropleth.generateByMinMax(min, max);
  3236. }
  3237. }
  3238. }, {
  3239. key: "getLegend",
  3240. value: function getLegend(options) {
  3241. var draw = this.options.draw;
  3242. var legend = null;
  3243. var self = this;
  3244. if (self.options.draw == 'intensity' || self.options.draw == 'heatmap') {
  3245. return this.intensity.getLegend(options);
  3246. } else if (self.options.draw == 'category') {
  3247. return this.category.getLegend(options);
  3248. }
  3249. }
  3250. }, {
  3251. key: "processData",
  3252. value: function processData(data) {
  3253. var self = this;
  3254. var draw = self.options.draw;
  3255. if (draw == 'bubble' || draw == 'intensity' || draw == 'category' || draw == 'choropleth' || draw == 'simple') {
  3256. for (var i = 0; i < data.length; i++) {
  3257. var item = data[i];
  3258. if (self.options.draw == 'bubble') {
  3259. data[i]._size = self.intensity.getSize(item.count);
  3260. } else {
  3261. data[i]._size = undefined;
  3262. }
  3263. var styleType = '_fillStyle';
  3264. if (data[i].geometry.type === 'LineString' || self.options.styleType === 'stroke') {
  3265. styleType = '_strokeStyle';
  3266. }
  3267. if (self.options.draw == 'intensity') {
  3268. data[i][styleType] = self.intensity.getColor(item.count);
  3269. } else if (self.options.draw == 'category') {
  3270. data[i][styleType] = self.category.get(item.count);
  3271. } else if (self.options.draw == 'choropleth') {
  3272. data[i][styleType] = self.choropleth.get(item.count);
  3273. }
  3274. }
  3275. }
  3276. }
  3277. }, {
  3278. key: "isEnabledTime",
  3279. value: function isEnabledTime() {
  3280. var animationOptions = this.options.animation;
  3281. var flag = animationOptions && !(animationOptions.enabled === false);
  3282. return flag;
  3283. }
  3284. }, {
  3285. key: "argCheck",
  3286. value: function argCheck(options) {
  3287. if (options.draw == 'heatmap') {
  3288. if (options.strokeStyle) {
  3289. console.warn('[heatmap] options.strokeStyle is discard, pleause use options.strength [eg: options.strength = 0.1]');
  3290. }
  3291. }
  3292. }
  3293. }, {
  3294. key: "drawContext",
  3295. value: function drawContext(context, dataSet, options, nwPixel) {
  3296. var self = this;
  3297. switch (self.options.draw) {
  3298. case 'heatmap':
  3299. drawHeatmap.draw(context, dataSet, self.options);
  3300. break;
  3301. case 'grid':
  3302. case 'honeycomb':
  3303. self.options.offset = {
  3304. x: nwPixel.x,
  3305. y: nwPixel.y
  3306. };
  3307. if (self.options.draw == 'grid') {
  3308. drawGrid.draw(context, dataSet, self.options);
  3309. } else {
  3310. drawHoneycomb.draw(context, dataSet, self.options);
  3311. }
  3312. break;
  3313. case 'text':
  3314. drawText.draw(context, dataSet, self.options);
  3315. break;
  3316. case 'icon':
  3317. drawIcon.draw(context, dataSet, self.options);
  3318. break;
  3319. case 'clip':
  3320. context.save();
  3321. context.fillStyle = self.options.fillStyle || 'rgba(0, 0, 0, 0.5)';
  3322. context.fillRect(0, 0, context.canvas.width, context.canvas.height);
  3323. drawSimple.draw(context, dataSet, self.options);
  3324. context.beginPath();
  3325. pathSimple.drawDataSet(context, dataSet, self.options);
  3326. context.clip();
  3327. clear(context);
  3328. context.restore();
  3329. break;
  3330. default:
  3331. if (self.options.context == "webgl") {
  3332. webglDrawSimple.draw(self.canvasLayer.canvas.getContext('webgl'), dataSet, self.options);
  3333. } else {
  3334. drawSimple.draw(context, dataSet, self.options);
  3335. }
  3336. }
  3337. if (self.options.arrow && self.options.arrow.show !== false) {
  3338. object.draw(context, dataSet, self.options);
  3339. }
  3340. }
  3341. }, {
  3342. key: "isPointInPath",
  3343. value: function isPointInPath(context, pixel) {
  3344. var context = this.canvasLayer.canvas.getContext(this.context);
  3345. var data = this.dataSet.get();
  3346. for (var i = 0; i < data.length; i++) {
  3347. context.beginPath();
  3348. pathSimple.draw(context, data[i], this.options);
  3349. var x = pixel.x * this.canvasLayer.devicePixelRatio;
  3350. var y = pixel.y * this.canvasLayer.devicePixelRatio;
  3351. if (context.isPointInPath(x, y) || context.isPointInStroke(x, y)) {
  3352. return data[i];
  3353. }
  3354. }
  3355. }
  3356. }, {
  3357. key: "clickEvent",
  3358. value: function clickEvent(pixel, e) {
  3359. var dataItem = this.isPointInPath(this.getContext(), pixel);
  3360. if (dataItem) {
  3361. this.options.methods.click(dataItem, e);
  3362. } else {
  3363. this.options.methods.click(null, e);
  3364. }
  3365. }
  3366. }, {
  3367. key: "mousemoveEvent",
  3368. value: function mousemoveEvent(pixel, e) {
  3369. var dataItem = this.isPointInPath(this.getContext(), pixel);
  3370. if (dataItem) {
  3371. this.options.methods.mousemove(dataItem, e);
  3372. } else {
  3373. this.options.methods.mousemove(null, e);
  3374. }
  3375. }
  3376. /**
  3377. * obj.options
  3378. */
  3379. }, {
  3380. key: "update",
  3381. value: function update(obj, isDraw) {
  3382. var self = this;
  3383. var _options = obj.options;
  3384. var options = self.options;
  3385. for (var i in _options) {
  3386. options[i] = _options[i];
  3387. }
  3388. self.init(options);
  3389. if (isDraw !== false) {
  3390. self.draw();
  3391. }
  3392. }
  3393. }, {
  3394. key: "setOptions",
  3395. value: function setOptions(options) {
  3396. var self = this;
  3397. self.dataSet.reset();
  3398. // console.log('xxx1')
  3399. self.init(options);
  3400. // console.log('xxx')
  3401. self.draw();
  3402. }
  3403. }, {
  3404. key: "set",
  3405. value: function set$$1(obj) {
  3406. var self = this;
  3407. var ctx = this.getContext();
  3408. var conf = this.getDefaultContextConfig();
  3409. for (var i in conf) {
  3410. ctx[i] = conf[i];
  3411. }
  3412. self.init(obj.options);
  3413. self.draw();
  3414. }
  3415. }, {
  3416. key: "destroy",
  3417. value: function destroy() {
  3418. this.unbindEvent();
  3419. this.hide();
  3420. }
  3421. }, {
  3422. key: "initAnimator",
  3423. value: function initAnimator() {
  3424. var self = this;
  3425. var animationOptions = self.options.animation;
  3426. if (self.options.draw == 'time' || self.isEnabledTime()) {
  3427. if (!animationOptions.stepsRange) {
  3428. animationOptions.stepsRange = {
  3429. start: this.dataSet.getMin('time') || 0,
  3430. end: this.dataSet.getMax('time') || 0
  3431. };
  3432. }
  3433. this.steps = { step: animationOptions.stepsRange.start };
  3434. self.animator = new TWEEN.Tween(this.steps).onUpdate(function () {
  3435. self._canvasUpdate(this.step);
  3436. }).repeat(Infinity);
  3437. this.addAnimatorEvent();
  3438. var duration = animationOptions.duration * 1000 || 5000;
  3439. self.animator.to({ step: animationOptions.stepsRange.end }, duration);
  3440. self.animator.start();
  3441. } else {
  3442. self.animator && self.animator.stop();
  3443. }
  3444. }
  3445. }, {
  3446. key: "addAnimatorEvent",
  3447. value: function addAnimatorEvent() {}
  3448. }, {
  3449. key: "animatorMovestartEvent",
  3450. value: function animatorMovestartEvent() {
  3451. var animationOptions = this.options.animation;
  3452. if (this.isEnabledTime() && this.animator) {
  3453. this.steps.step = animationOptions.stepsRange.start;
  3454. this.animator.stop();
  3455. }
  3456. }
  3457. }, {
  3458. key: "animatorMoveendEvent",
  3459. value: function animatorMoveendEvent() {
  3460. if (this.isEnabledTime() && this.animator) {
  3461. this.animator.start();
  3462. }
  3463. }
  3464. }]);
  3465. return BaseLayer;
  3466. }();
  3467. var AnimationLayer = function (_BaseLayer) {
  3468. inherits(AnimationLayer, _BaseLayer);
  3469. function AnimationLayer(map, dataSet, options) {
  3470. classCallCheck(this, AnimationLayer);
  3471. var _this = possibleConstructorReturn(this, (AnimationLayer.__proto__ || Object.getPrototypeOf(AnimationLayer)).call(this, map, dataSet, options));
  3472. _this.map = map;
  3473. _this.options = options || {};
  3474. _this.dataSet = dataSet;
  3475. var canvasLayer = new CanvasLayer({
  3476. map: map,
  3477. zIndex: _this.options.zIndex,
  3478. update: _this._canvasUpdate.bind(_this)
  3479. });
  3480. _this.init(_this.options);
  3481. _this.canvasLayer = canvasLayer;
  3482. _this.transferToMercator();
  3483. var self = _this;
  3484. dataSet.on('change', function () {
  3485. self.transferToMercator();
  3486. canvasLayer.draw();
  3487. });
  3488. _this.ctx = canvasLayer.canvas.getContext('2d');
  3489. _this.start();
  3490. return _this;
  3491. }
  3492. createClass(AnimationLayer, [{
  3493. key: "draw",
  3494. value: function draw() {
  3495. this.canvasLayer.draw();
  3496. }
  3497. }, {
  3498. key: "init",
  3499. value: function init(options) {
  3500. var self = this;
  3501. self.options = options;
  3502. this.initDataRange(options);
  3503. this.context = self.options.context || '2d';
  3504. if (self.options.zIndex) {
  3505. this.canvasLayer && this.canvasLayer.setZIndex(self.options.zIndex);
  3506. }
  3507. if (self.options.max) {
  3508. this.intensity.setMax(self.options.max);
  3509. }
  3510. if (self.options.min) {
  3511. this.intensity.setMin(self.options.min);
  3512. }
  3513. this.initAnimator();
  3514. }
  3515. // 经纬度左边转换为墨卡托坐标
  3516. }, {
  3517. key: "transferToMercator",
  3518. value: function transferToMercator() {
  3519. var projection = this.map.getMapType().getProjection();
  3520. if (this.options.coordType !== 'bd09mc') {
  3521. var data = this.dataSet.get();
  3522. data = this.dataSet.transferCoordinate(data, function (coordinates) {
  3523. var pixel = projection.lngLatToPoint({
  3524. lng: coordinates[0],
  3525. lat: coordinates[1]
  3526. });
  3527. return [pixel.x, pixel.y];
  3528. }, 'coordinates', 'coordinates_mercator');
  3529. this.dataSet._set(data);
  3530. }
  3531. }
  3532. }, {
  3533. key: "_canvasUpdate",
  3534. value: function _canvasUpdate() {
  3535. var ctx = this.ctx;
  3536. if (!ctx) {
  3537. return;
  3538. }
  3539. //clear(ctx);
  3540. var map = this.map;
  3541. var zoomUnit = Math.pow(2, 18 - map.getZoom());
  3542. var projection = map.getMapType().getProjection();
  3543. var mcCenter = projection.lngLatToPoint(map.getCenter());
  3544. var nwMc = new BMap.Pixel(mcCenter.x - map.getSize().width / 2 * zoomUnit, mcCenter.y + map.getSize().height / 2 * zoomUnit); //左上角墨卡托坐标
  3545. clear(ctx);
  3546. var dataGetOptions = {
  3547. fromColumn: this.options.coordType == 'bd09mc' ? 'coordinates' : 'coordinates_mercator',
  3548. transferCoordinate: function transferCoordinate(coordinate) {
  3549. if (!coordinate) {
  3550. return;
  3551. }
  3552. var x = (coordinate[0] - nwMc.x) / zoomUnit;
  3553. var y = (nwMc.y - coordinate[1]) / zoomUnit;
  3554. return [x, y];
  3555. }
  3556. };
  3557. this.data = this.dataSet.get(dataGetOptions);
  3558. this.processData(this.data);
  3559. this.drawAnimation();
  3560. }
  3561. }, {
  3562. key: "drawAnimation",
  3563. value: function drawAnimation() {
  3564. var ctx = this.ctx;
  3565. var data = this.data;
  3566. if (!data) {
  3567. return;
  3568. }
  3569. ctx.save();
  3570. ctx.globalCompositeOperation = 'destination-out';
  3571. ctx.fillStyle = 'rgba(0, 0, 0, .1)';
  3572. ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  3573. ctx.restore();
  3574. ctx.save();
  3575. if (this.options.shadowColor) {
  3576. ctx.shadowColor = this.options.shadowColor;
  3577. }
  3578. if (this.options.shadowBlur) {
  3579. ctx.shadowBlur = this.options.shadowBlur;
  3580. }
  3581. if (this.options.globalAlpha) {
  3582. ctx.globalAlpha = this.options.globalAlpha;
  3583. }
  3584. if (this.options.globalCompositeOperation) {
  3585. ctx.globalCompositeOperation = this.options.globalCompositeOperation;
  3586. }
  3587. var options = this.options;
  3588. for (var i = 0; i < data.length; i++) {
  3589. if (data[i].geometry.type === 'Point') {
  3590. ctx.beginPath();
  3591. var maxSize = data[i].size || this.options.size;
  3592. var minSize = data[i].minSize || this.options.minSize || 0;
  3593. if (data[i]._size === undefined) {
  3594. data[i]._size = minSize;
  3595. }
  3596. ctx.arc(data[i].geometry._coordinates[0], data[i].geometry._coordinates[1], data[i]._size, 0, Math.PI * 2, true);
  3597. ctx.closePath();
  3598. data[i]._size++;
  3599. if (data[i]._size > maxSize) {
  3600. data[i]._size = minSize;
  3601. }
  3602. ctx.lineWidth = 1;
  3603. ctx.strokeStyle = data[i].strokeStyle || data[i]._strokeStyle || options.strokeStyle || 'yellow';
  3604. ctx.stroke();
  3605. var fillStyle = data[i].fillStyle || data[i]._fillStyle || options.fillStyle;
  3606. if (fillStyle) {
  3607. ctx.fillStyle = fillStyle;
  3608. ctx.fill();
  3609. }
  3610. } else if (data[i].geometry.type === 'LineString') {
  3611. ctx.beginPath();
  3612. var size = data[i].size || this.options.size || 5;
  3613. var minSize = data[i].minSize || this.options.minSize || 0;
  3614. if (data[i]._index === undefined) {
  3615. data[i]._index = 0;
  3616. }
  3617. var index = data[i]._index;
  3618. ctx.arc(data[i].geometry._coordinates[index][0], data[i].geometry._coordinates[index][1], size, 0, Math.PI * 2, true);
  3619. ctx.closePath();
  3620. data[i]._index++;
  3621. if (data[i]._index >= data[i].geometry._coordinates.length) {
  3622. data[i]._index = 0;
  3623. }
  3624. var strokeStyle = data[i].strokeStyle || options.strokeStyle;
  3625. var fillStyle = data[i].fillStyle || options.fillStyle || 'yellow';
  3626. ctx.fillStyle = fillStyle;
  3627. ctx.fill();
  3628. if (strokeStyle && options.lineWidth) {
  3629. ctx.lineWidth = options.lineWidth || 1;
  3630. ctx.strokeStyle = strokeStyle;
  3631. ctx.stroke();
  3632. }
  3633. }
  3634. }
  3635. ctx.restore();
  3636. }
  3637. }, {
  3638. key: "animate",
  3639. value: function animate() {
  3640. this.drawAnimation();
  3641. var animateTime = this.options.animateTime || 100;
  3642. this.timeout = setTimeout(this.animate.bind(this), animateTime);
  3643. }
  3644. }, {
  3645. key: "start",
  3646. value: function start() {
  3647. this.stop();
  3648. this.animate();
  3649. }
  3650. }, {
  3651. key: "stop",
  3652. value: function stop() {
  3653. clearTimeout(this.timeout);
  3654. }
  3655. }, {
  3656. key: "unbindEvent",
  3657. value: function unbindEvent() {}
  3658. }, {
  3659. key: "hide",
  3660. value: function hide() {
  3661. this.canvasLayer.hide();
  3662. this.stop();
  3663. }
  3664. }, {
  3665. key: "show",
  3666. value: function show() {
  3667. this.start();
  3668. }
  3669. }]);
  3670. return AnimationLayer;
  3671. }(BaseLayer);
  3672. /**
  3673. * @author kyle / http://nikai.us/
  3674. */
  3675. var Layer = function (_BaseLayer) {
  3676. inherits(Layer, _BaseLayer);
  3677. function Layer(map, dataSet, options) {
  3678. classCallCheck(this, Layer);
  3679. var _this = possibleConstructorReturn(this, (Layer.__proto__ || Object.getPrototypeOf(Layer)).call(this, map, dataSet, options));
  3680. var self = _this;
  3681. var data = null;
  3682. options = options || {};
  3683. _this.clickEvent = _this.clickEvent.bind(_this);
  3684. _this.mousemoveEvent = _this.mousemoveEvent.bind(_this);
  3685. self.init(options);
  3686. self.argCheck(options);
  3687. self.transferToMercator();
  3688. var canvasLayer = _this.canvasLayer = new CanvasLayer({
  3689. map: map,
  3690. context: _this.context,
  3691. paneName: options.paneName,
  3692. mixBlendMode: options.mixBlendMode,
  3693. enableMassClear: options.enableMassClear,
  3694. zIndex: options.zIndex,
  3695. update: function update() {
  3696. self._canvasUpdate();
  3697. }
  3698. });
  3699. dataSet.on('change', function () {
  3700. self.transferToMercator();
  3701. canvasLayer.draw();
  3702. });
  3703. return _this;
  3704. }
  3705. createClass(Layer, [{
  3706. key: "clickEvent",
  3707. value: function clickEvent(e) {
  3708. var pixel = e.pixel;
  3709. get(Layer.prototype.__proto__ || Object.getPrototypeOf(Layer.prototype), "clickEvent", this).call(this, pixel, e);
  3710. }
  3711. }, {
  3712. key: "mousemoveEvent",
  3713. value: function mousemoveEvent(e) {
  3714. var pixel = e.pixel;
  3715. get(Layer.prototype.__proto__ || Object.getPrototypeOf(Layer.prototype), "mousemoveEvent", this).call(this, pixel, e);
  3716. }
  3717. }, {
  3718. key: "bindEvent",
  3719. value: function bindEvent(e) {
  3720. this.unbindEvent();
  3721. var map = this.map;
  3722. if (this.options.methods) {
  3723. if (this.options.methods.click) {
  3724. map.setDefaultCursor("default");
  3725. map.addEventListener('click', this.clickEvent);
  3726. }
  3727. if (this.options.methods.mousemove) {
  3728. map.addEventListener('mousemove', this.mousemoveEvent);
  3729. }
  3730. }
  3731. }
  3732. }, {
  3733. key: "unbindEvent",
  3734. value: function unbindEvent(e) {
  3735. var map = this.map;
  3736. if (this.options.methods) {
  3737. if (this.options.methods.click) {
  3738. map.removeEventListener('click', this.clickEvent);
  3739. }
  3740. if (this.options.methods.mousemove) {
  3741. map.removeEventListener('mousemove', this.mousemoveEvent);
  3742. }
  3743. }
  3744. }
  3745. // 经纬度左边转换为墨卡托坐标
  3746. }, {
  3747. key: "transferToMercator",
  3748. value: function transferToMercator() {
  3749. var projection = this.map.getMapType().getProjection();
  3750. if (this.options.coordType !== 'bd09mc') {
  3751. var data = this.dataSet.get();
  3752. data = this.dataSet.transferCoordinate(data, function (coordinates) {
  3753. var pixel = projection.lngLatToPoint({
  3754. lng: coordinates[0],
  3755. lat: coordinates[1]
  3756. });
  3757. return [pixel.x, pixel.y];
  3758. }, 'coordinates', 'coordinates_mercator');
  3759. this.dataSet._set(data);
  3760. }
  3761. }
  3762. }, {
  3763. key: "getContext",
  3764. value: function getContext() {
  3765. return this.canvasLayer.canvas.getContext(this.context);
  3766. }
  3767. }, {
  3768. key: "_canvasUpdate",
  3769. value: function _canvasUpdate(time) {
  3770. if (!this.canvasLayer) {
  3771. return;
  3772. }
  3773. var self = this;
  3774. var animationOptions = self.options.animation;
  3775. var map = this.canvasLayer._map;
  3776. var zoomUnit = Math.pow(2, 18 - map.getZoom());
  3777. var projection = map.getMapType().getProjection();
  3778. var mcCenter = projection.lngLatToPoint(map.getCenter());
  3779. var nwMc = new BMap.Pixel(mcCenter.x - map.getSize().width / 2 * zoomUnit, mcCenter.y + map.getSize().height / 2 * zoomUnit); //左上角墨卡托坐标
  3780. var context = this.getContext();
  3781. if (self.isEnabledTime()) {
  3782. if (time === undefined) {
  3783. clear(context);
  3784. return;
  3785. }
  3786. if (this.context == '2d') {
  3787. context.save();
  3788. context.globalCompositeOperation = 'destination-out';
  3789. context.fillStyle = 'rgba(0, 0, 0, .1)';
  3790. context.fillRect(0, 0, context.canvas.width, context.canvas.height);
  3791. context.restore();
  3792. }
  3793. } else {
  3794. clear(context);
  3795. }
  3796. if (this.context == '2d') {
  3797. for (var key in self.options) {
  3798. context[key] = self.options[key];
  3799. }
  3800. } else {
  3801. context.clear(context.COLOR_BUFFER_BIT);
  3802. }
  3803. if (self.options.minZoom && map.getZoom() < self.options.minZoom || self.options.maxZoom && map.getZoom() > self.options.maxZoom) {
  3804. return;
  3805. }
  3806. var scale = 1;
  3807. if (this.context != '2d') {
  3808. scale = this.canvasLayer.devicePixelRatio;
  3809. }
  3810. var dataGetOptions = {
  3811. fromColumn: self.options.coordType == 'bd09mc' ? 'coordinates' : 'coordinates_mercator',
  3812. transferCoordinate: function transferCoordinate(coordinate) {
  3813. var x = (coordinate[0] - nwMc.x) / zoomUnit * scale;
  3814. var y = (nwMc.y - coordinate[1]) / zoomUnit * scale;
  3815. return [x, y];
  3816. }
  3817. };
  3818. if (time !== undefined) {
  3819. dataGetOptions.filter = function (item) {
  3820. var trails = animationOptions.trails || 10;
  3821. if (time && item.time > time - trails && item.time < time) {
  3822. return true;
  3823. } else {
  3824. return false;
  3825. }
  3826. };
  3827. }
  3828. // get data from data set
  3829. var data = self.dataSet.get(dataGetOptions);
  3830. this.processData(data);
  3831. var nwPixel = map.pointToPixel(new BMap.Point(0, 0));
  3832. if (self.options.unit == 'm') {
  3833. if (self.options.size) {
  3834. self.options._size = self.options.size / zoomUnit;
  3835. }
  3836. if (self.options.width) {
  3837. self.options._width = self.options.width / zoomUnit;
  3838. }
  3839. if (self.options.height) {
  3840. self.options._height = self.options.height / zoomUnit;
  3841. }
  3842. } else {
  3843. self.options._size = self.options.size;
  3844. self.options._height = self.options.height;
  3845. self.options._width = self.options.width;
  3846. }
  3847. this.drawContext(context, data, self.options, nwPixel);
  3848. //console.timeEnd('draw');
  3849. //console.timeEnd('update')
  3850. self.options.updateCallback && self.options.updateCallback(time);
  3851. }
  3852. }, {
  3853. key: "init",
  3854. value: function init(options) {
  3855. var self = this;
  3856. self.options = options;
  3857. this.initDataRange(options);
  3858. this.context = self.options.context || '2d';
  3859. if (self.options.zIndex) {
  3860. this.canvasLayer && this.canvasLayer.setZIndex(self.options.zIndex);
  3861. }
  3862. if (self.options.max) {
  3863. this.intensity.setMax(self.options.max);
  3864. }
  3865. if (self.options.min) {
  3866. this.intensity.setMin(self.options.min);
  3867. }
  3868. this.initAnimator();
  3869. this.bindEvent();
  3870. }
  3871. }, {
  3872. key: "addAnimatorEvent",
  3873. value: function addAnimatorEvent() {
  3874. this.map.addEventListener('movestart', this.animatorMovestartEvent.bind(this));
  3875. this.map.addEventListener('moveend', this.animatorMoveendEvent.bind(this));
  3876. }
  3877. }, {
  3878. key: "show",
  3879. value: function show() {
  3880. this.map.addOverlay(this.canvasLayer);
  3881. }
  3882. }, {
  3883. key: "hide",
  3884. value: function hide() {
  3885. this.map.removeOverlay(this.canvasLayer);
  3886. }
  3887. }, {
  3888. key: "draw",
  3889. value: function draw() {
  3890. this.canvasLayer.draw();
  3891. }
  3892. }]);
  3893. return Layer;
  3894. }(BaseLayer);
  3895. /**
  3896. * Copyright 2012 Google Inc. All Rights Reserved.
  3897. *
  3898. * Licensed under the Apache License, Version 2.0 (the "License");
  3899. * you may not use this file except in compliance with the License.
  3900. * You may obtain a copy of the License at
  3901. *
  3902. * http://www.apache.org/licenses/LICENSE-2.0
  3903. *
  3904. * Unless required by applicable law or agreed to in writing, software
  3905. * distributed under the License is distributed on an "AS IS" BASIS,
  3906. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3907. * See the License for the specific language governing permissions and
  3908. * limitations under the License.
  3909. */
  3910. /**
  3911. * @fileoverview Extends OverlayView to provide a canvas "Layer".
  3912. * @author Brendan Kenny
  3913. */
  3914. /**
  3915. * A map layer that provides a canvas over the slippy map and a callback
  3916. * system for efficient animation. Requires canvas and CSS 2D transform
  3917. * support.
  3918. * @constructor
  3919. * @extends google.maps.OverlayView
  3920. * @param {CanvasLayerOptions=} opt_options Options to set in this CanvasLayer.
  3921. */
  3922. function CanvasLayer$2(opt_options) {
  3923. /**
  3924. * If true, canvas is in a map pane and the OverlayView is fully functional.
  3925. * See google.maps.OverlayView.onAdd for more information.
  3926. * @type {boolean}
  3927. * @private
  3928. */
  3929. this.isAdded_ = false;
  3930. /**
  3931. * If true, each update will immediately schedule the next.
  3932. * @type {boolean}
  3933. * @private
  3934. */
  3935. this.isAnimated_ = false;
  3936. /**
  3937. * The name of the MapPane in which this layer will be displayed.
  3938. * @type {string}
  3939. * @private
  3940. */
  3941. this.paneName_ = CanvasLayer$2.DEFAULT_PANE_NAME_;
  3942. /**
  3943. * A user-supplied function called whenever an update is required. Null or
  3944. * undefined if a callback is not provided.
  3945. * @type {?function=}
  3946. * @private
  3947. */
  3948. this.updateHandler_ = null;
  3949. /**
  3950. * A user-supplied function called whenever an update is required and the
  3951. * map has been resized since the last update. Null or undefined if a
  3952. * callback is not provided.
  3953. * @type {?function}
  3954. * @private
  3955. */
  3956. this.resizeHandler_ = null;
  3957. /**
  3958. * The LatLng coordinate of the top left of the current view of the map. Will
  3959. * be null when this.isAdded_ is false.
  3960. * @type {google.maps.LatLng}
  3961. * @private
  3962. */
  3963. this.topLeft_ = null;
  3964. /**
  3965. * The map-pan event listener. Will be null when this.isAdded_ is false. Will
  3966. * be null when this.isAdded_ is false.
  3967. * @type {?function}
  3968. * @private
  3969. */
  3970. this.centerListener_ = null;
  3971. /**
  3972. * The map-resize event listener. Will be null when this.isAdded_ is false.
  3973. * @type {?function}
  3974. * @private
  3975. */
  3976. this.resizeListener_ = null;
  3977. /**
  3978. * If true, the map size has changed and this.resizeHandler_ must be called
  3979. * on the next update.
  3980. * @type {boolean}
  3981. * @private
  3982. */
  3983. this.needsResize_ = true;
  3984. /**
  3985. * A browser-defined id for the currently requested callback. Null when no
  3986. * callback is queued.
  3987. * @type {?number}
  3988. * @private
  3989. */
  3990. this.requestAnimationFrameId_ = null;
  3991. var canvas = document.createElement('canvas');
  3992. canvas.style.position = 'absolute';
  3993. canvas.style.top = 0;
  3994. canvas.style.left = 0;
  3995. canvas.style.pointerEvents = 'none';
  3996. /**
  3997. * The canvas element.
  3998. * @type {!HTMLCanvasElement}
  3999. */
  4000. this.canvas = canvas;
  4001. /**
  4002. * The CSS width of the canvas, which may be different than the width of the
  4003. * backing store.
  4004. * @private {number}
  4005. */
  4006. this.canvasCssWidth_ = 300;
  4007. /**
  4008. * The CSS height of the canvas, which may be different than the height of
  4009. * the backing store.
  4010. * @private {number}
  4011. */
  4012. this.canvasCssHeight_ = 150;
  4013. /**
  4014. * A value for scaling the CanvasLayer resolution relative to the CanvasLayer
  4015. * display size.
  4016. * @private {number}
  4017. */
  4018. this.resolutionScale_ = 1;
  4019. /**
  4020. * Simple bind for functions with no args for bind-less browsers (Safari).
  4021. * @param {Object} thisArg The this value used for the target function.
  4022. * @param {function} func The function to be bound.
  4023. */
  4024. function simpleBindShim(thisArg, func) {
  4025. return function () {
  4026. func.apply(thisArg);
  4027. };
  4028. }
  4029. /**
  4030. * A reference to this.repositionCanvas_ with this bound as its this value.
  4031. * @type {function}
  4032. * @private
  4033. */
  4034. this.repositionFunction_ = simpleBindShim(this, this.repositionCanvas_);
  4035. /**
  4036. * A reference to this.resize_ with this bound as its this value.
  4037. * @type {function}
  4038. * @private
  4039. */
  4040. this.resizeFunction_ = simpleBindShim(this, this.resize_);
  4041. /**
  4042. * A reference to this.update_ with this bound as its this value.
  4043. * @type {function}
  4044. * @private
  4045. */
  4046. this.requestUpdateFunction_ = simpleBindShim(this, this.update_);
  4047. // set provided options, if any
  4048. if (opt_options) {
  4049. this.setOptions(opt_options);
  4050. }
  4051. }
  4052. var global$4 = typeof window === 'undefined' ? {} : window;
  4053. if (global$4.google && global$4.google.maps) {
  4054. CanvasLayer$2.prototype = new google.maps.OverlayView();
  4055. /**
  4056. * The default MapPane to contain the canvas.
  4057. * @type {string}
  4058. * @const
  4059. * @private
  4060. */
  4061. CanvasLayer$2.DEFAULT_PANE_NAME_ = 'overlayLayer';
  4062. /**
  4063. * Transform CSS property name, with vendor prefix if required. If browser
  4064. * does not support transforms, property will be ignored.
  4065. * @type {string}
  4066. * @const
  4067. * @private
  4068. */
  4069. CanvasLayer$2.CSS_TRANSFORM_ = function () {
  4070. var div = document.createElement('div');
  4071. var transformProps = ['transform', 'WebkitTransform', 'MozTransform', 'OTransform', 'msTransform'];
  4072. for (var i = 0; i < transformProps.length; i++) {
  4073. var prop = transformProps[i];
  4074. if (div.style[prop] !== undefined) {
  4075. return prop;
  4076. }
  4077. }
  4078. // return unprefixed version by default
  4079. return transformProps[0];
  4080. }();
  4081. /**
  4082. * The requestAnimationFrame function, with vendor-prefixed or setTimeout-based
  4083. * fallbacks. MUST be called with window as thisArg.
  4084. * @type {function}
  4085. * @param {function} callback The function to add to the frame request queue.
  4086. * @return {number} The browser-defined id for the requested callback.
  4087. * @private
  4088. */
  4089. CanvasLayer$2.prototype.requestAnimFrame_ = global$4.requestAnimationFrame || global$4.webkitRequestAnimationFrame || global$4.mozRequestAnimationFrame || global$4.oRequestAnimationFrame || global$4.msRequestAnimationFrame || function (callback) {
  4090. return global$4.setTimeout(callback, 1000 / 60);
  4091. };
  4092. /**
  4093. * The cancelAnimationFrame function, with vendor-prefixed fallback. Does not
  4094. * fall back to clearTimeout as some platforms implement requestAnimationFrame
  4095. * but not cancelAnimationFrame, and the cost is an extra frame on onRemove.
  4096. * MUST be called with window as thisArg.
  4097. * @type {function}
  4098. * @param {number=} requestId The id of the frame request to cancel.
  4099. * @private
  4100. */
  4101. CanvasLayer$2.prototype.cancelAnimFrame_ = global$4.cancelAnimationFrame || global$4.webkitCancelAnimationFrame || global$4.mozCancelAnimationFrame || global$4.oCancelAnimationFrame || global$4.msCancelAnimationFrame || function (requestId) {};
  4102. /**
  4103. * Sets any options provided. See CanvasLayerOptions for more information.
  4104. * @param {CanvasLayerOptions} options The options to set.
  4105. */
  4106. CanvasLayer$2.prototype.setOptions = function (options) {
  4107. if (options.animate !== undefined) {
  4108. this.setAnimate(options.animate);
  4109. }
  4110. if (options.paneName !== undefined) {
  4111. this.setPaneName(options.paneName);
  4112. }
  4113. if (options.updateHandler !== undefined) {
  4114. this.setUpdateHandler(options.updateHandler);
  4115. }
  4116. if (options.resizeHandler !== undefined) {
  4117. this.setResizeHandler(options.resizeHandler);
  4118. }
  4119. if (options.resolutionScale !== undefined) {
  4120. this.setResolutionScale(options.resolutionScale);
  4121. }
  4122. if (options.map !== undefined) {
  4123. this.setMap(options.map);
  4124. }
  4125. };
  4126. /**
  4127. * Set the animated state of the layer. If true, updateHandler will be called
  4128. * repeatedly, once per frame. If false, updateHandler will only be called when
  4129. * a map property changes that could require the canvas content to be redrawn.
  4130. * @param {boolean} animate Whether the canvas is animated.
  4131. */
  4132. CanvasLayer$2.prototype.setAnimate = function (animate) {
  4133. this.isAnimated_ = !!animate;
  4134. if (this.isAnimated_) {
  4135. this.scheduleUpdate();
  4136. }
  4137. };
  4138. /**
  4139. * @return {boolean} Whether the canvas is animated.
  4140. */
  4141. CanvasLayer$2.prototype.isAnimated = function () {
  4142. return this.isAnimated_;
  4143. };
  4144. /**
  4145. * Set the MapPane in which this layer will be displayed, by name. See
  4146. * {@code google.maps.MapPanes} for the panes available.
  4147. * @param {string} paneName The name of the desired MapPane.
  4148. */
  4149. CanvasLayer$2.prototype.setPaneName = function (paneName) {
  4150. this.paneName_ = paneName;
  4151. this.setPane_();
  4152. };
  4153. /**
  4154. * @return {string} The name of the current container pane.
  4155. */
  4156. CanvasLayer$2.prototype.getPaneName = function () {
  4157. return this.paneName_;
  4158. };
  4159. /**
  4160. * Adds the canvas to the specified container pane. Since this is guaranteed to
  4161. * execute only after onAdd is called, this is when paneName's existence is
  4162. * checked (and an error is thrown if it doesn't exist).
  4163. * @private
  4164. */
  4165. CanvasLayer$2.prototype.setPane_ = function () {
  4166. if (!this.isAdded_) {
  4167. return;
  4168. }
  4169. // onAdd has been called, so panes can be used
  4170. var panes = this.getPanes();
  4171. if (!panes[this.paneName_]) {
  4172. throw new Error('"' + this.paneName_ + '" is not a valid MapPane name.');
  4173. }
  4174. panes[this.paneName_].appendChild(this.canvas);
  4175. };
  4176. /**
  4177. * Set a function that will be called whenever the parent map and the overlay's
  4178. * canvas have been resized. If opt_resizeHandler is null or unspecified, any
  4179. * existing callback is removed.
  4180. * @param {?function=} opt_resizeHandler The resize callback function.
  4181. */
  4182. CanvasLayer$2.prototype.setResizeHandler = function (opt_resizeHandler) {
  4183. this.resizeHandler_ = opt_resizeHandler;
  4184. };
  4185. /**
  4186. * Sets a value for scaling the canvas resolution relative to the canvas
  4187. * display size. This can be used to save computation by scaling the backing
  4188. * buffer down, or to support high DPI devices by scaling it up (by e.g.
  4189. * window.devicePixelRatio).
  4190. * @param {number} scale
  4191. */
  4192. CanvasLayer$2.prototype.setResolutionScale = function (scale) {
  4193. if (typeof scale === 'number') {
  4194. this.resolutionScale_ = scale;
  4195. this.resize_();
  4196. }
  4197. };
  4198. /**
  4199. * Set a function that will be called when a repaint of the canvas is required.
  4200. * If opt_updateHandler is null or unspecified, any existing callback is
  4201. * removed.
  4202. * @param {?function=} opt_updateHandler The update callback function.
  4203. */
  4204. CanvasLayer$2.prototype.setUpdateHandler = function (opt_updateHandler) {
  4205. this.updateHandler_ = opt_updateHandler;
  4206. };
  4207. /**
  4208. * @inheritDoc
  4209. */
  4210. CanvasLayer$2.prototype.onAdd = function () {
  4211. if (this.isAdded_) {
  4212. return;
  4213. }
  4214. this.isAdded_ = true;
  4215. this.setPane_();
  4216. this.resizeListener_ = google.maps.event.addListener(this.getMap(), 'resize', this.resizeFunction_);
  4217. this.centerListener_ = google.maps.event.addListener(this.getMap(), 'center_changed', this.repositionFunction_);
  4218. this.resize_();
  4219. this.repositionCanvas_();
  4220. };
  4221. /**
  4222. * @inheritDoc
  4223. */
  4224. CanvasLayer$2.prototype.onRemove = function () {
  4225. if (!this.isAdded_) {
  4226. return;
  4227. }
  4228. this.isAdded_ = false;
  4229. this.topLeft_ = null;
  4230. // remove canvas and listeners for pan and resize from map
  4231. this.canvas.parentElement.removeChild(this.canvas);
  4232. if (this.centerListener_) {
  4233. google.maps.event.removeListener(this.centerListener_);
  4234. this.centerListener_ = null;
  4235. }
  4236. if (this.resizeListener_) {
  4237. google.maps.event.removeListener(this.resizeListener_);
  4238. this.resizeListener_ = null;
  4239. }
  4240. // cease canvas update callbacks
  4241. if (this.requestAnimationFrameId_) {
  4242. this.cancelAnimFrame_.call(global$4, this.requestAnimationFrameId_);
  4243. this.requestAnimationFrameId_ = null;
  4244. }
  4245. };
  4246. /**
  4247. * The internal callback for resize events that resizes the canvas to keep the
  4248. * map properly covered.
  4249. * @private
  4250. */
  4251. CanvasLayer$2.prototype.resize_ = function () {
  4252. if (!this.isAdded_) {
  4253. return;
  4254. }
  4255. var map = this.getMap();
  4256. var mapWidth = map.getDiv().offsetWidth;
  4257. var mapHeight = map.getDiv().offsetHeight;
  4258. var newWidth = mapWidth * this.resolutionScale_;
  4259. var newHeight = mapHeight * this.resolutionScale_;
  4260. var oldWidth = this.canvas.width;
  4261. var oldHeight = this.canvas.height;
  4262. // resizing may allocate a new back buffer, so do so conservatively
  4263. if (oldWidth !== newWidth || oldHeight !== newHeight) {
  4264. this.canvas.width = newWidth;
  4265. this.canvas.height = newHeight;
  4266. this.needsResize_ = true;
  4267. this.scheduleUpdate();
  4268. }
  4269. // reset styling if new sizes don't match; resize of data not needed
  4270. if (this.canvasCssWidth_ !== mapWidth || this.canvasCssHeight_ !== mapHeight) {
  4271. this.canvasCssWidth_ = mapWidth;
  4272. this.canvasCssHeight_ = mapHeight;
  4273. this.canvas.style.width = mapWidth + 'px';
  4274. this.canvas.style.height = mapHeight + 'px';
  4275. }
  4276. };
  4277. /**
  4278. * @inheritDoc
  4279. */
  4280. CanvasLayer$2.prototype.draw = function () {
  4281. this.repositionCanvas_();
  4282. };
  4283. /**
  4284. * Internal callback for map view changes. Since the Maps API moves the overlay
  4285. * along with the map, this function calculates the opposite translation to
  4286. * keep the canvas in place.
  4287. * @private
  4288. */
  4289. CanvasLayer$2.prototype.repositionCanvas_ = function () {
  4290. // TODO(bckenny): *should* only be executed on RAF, but in current browsers
  4291. // this causes noticeable hitches in map and overlay relative
  4292. // positioning.
  4293. var map = this.getMap();
  4294. // topLeft can't be calculated from map.getBounds(), because bounds are
  4295. // clamped to -180 and 180 when completely zoomed out. Instead, calculate
  4296. // left as an offset from the center, which is an unwrapped LatLng.
  4297. var top = map.getBounds().getNorthEast().lat();
  4298. var center = map.getCenter();
  4299. var scale = Math.pow(2, map.getZoom());
  4300. var left = center.lng() - this.canvasCssWidth_ * 180 / (256 * scale);
  4301. this.topLeft_ = new google.maps.LatLng(top, left);
  4302. // Canvas position relative to draggable map's container depends on
  4303. // overlayView's projection, not the map's. Have to use the center of the
  4304. // map for this, not the top left, for the same reason as above.
  4305. var projection = this.getProjection();
  4306. var divCenter = projection.fromLatLngToDivPixel(center);
  4307. var offsetX = -Math.round(this.canvasCssWidth_ / 2 - divCenter.x);
  4308. var offsetY = -Math.round(this.canvasCssHeight_ / 2 - divCenter.y);
  4309. this.canvas.style[CanvasLayer$2.CSS_TRANSFORM_] = 'translate(' + offsetX + 'px,' + offsetY + 'px)';
  4310. this.scheduleUpdate();
  4311. };
  4312. /**
  4313. * Internal callback that serves as main animation scheduler via
  4314. * requestAnimationFrame. Calls resize and update callbacks if set, and
  4315. * schedules the next frame if overlay is animated.
  4316. * @private
  4317. */
  4318. CanvasLayer$2.prototype.update_ = function () {
  4319. this.requestAnimationFrameId_ = null;
  4320. if (!this.isAdded_) {
  4321. return;
  4322. }
  4323. if (this.isAnimated_) {
  4324. this.scheduleUpdate();
  4325. }
  4326. if (this.needsResize_ && this.resizeHandler_) {
  4327. this.needsResize_ = false;
  4328. this.resizeHandler_();
  4329. }
  4330. if (this.updateHandler_) {
  4331. this.updateHandler_();
  4332. }
  4333. };
  4334. /**
  4335. * A convenience method to get the current LatLng coordinate of the top left of
  4336. * the current view of the map.
  4337. * @return {google.maps.LatLng} The top left coordinate.
  4338. */
  4339. CanvasLayer$2.prototype.getTopLeft = function () {
  4340. return this.topLeft_;
  4341. };
  4342. /**
  4343. * Schedule a requestAnimationFrame callback to updateHandler. If one is
  4344. * already scheduled, there is no effect.
  4345. */
  4346. CanvasLayer$2.prototype.scheduleUpdate = function () {
  4347. if (this.isAdded_ && !this.requestAnimationFrameId_) {
  4348. this.requestAnimationFrameId_ = this.requestAnimFrame_.call(global$4, this.requestUpdateFunction_);
  4349. }
  4350. };
  4351. }
  4352. /**
  4353. * @author kyle / http://nikai.us/
  4354. */
  4355. var Layer$2 = function (_BaseLayer) {
  4356. inherits(Layer, _BaseLayer);
  4357. function Layer(map, dataSet, options) {
  4358. classCallCheck(this, Layer);
  4359. var _this = possibleConstructorReturn(this, (Layer.__proto__ || Object.getPrototypeOf(Layer)).call(this, map, dataSet, options));
  4360. var self = _this;
  4361. var data = null;
  4362. options = options || {};
  4363. self.init(options);
  4364. self.argCheck(options);
  4365. var canvasLayerOptions = {
  4366. map: map,
  4367. animate: false,
  4368. updateHandler: function updateHandler() {
  4369. self._canvasUpdate();
  4370. },
  4371. resolutionScale: resolutionScale
  4372. };
  4373. var canvasLayer = _this.canvasLayer = new CanvasLayer$2(canvasLayerOptions);
  4374. _this.clickEvent = _this.clickEvent.bind(_this);
  4375. _this.mousemoveEvent = _this.mousemoveEvent.bind(_this);
  4376. _this.bindEvent();
  4377. return _this;
  4378. }
  4379. createClass(Layer, [{
  4380. key: "clickEvent",
  4381. value: function clickEvent(e) {
  4382. var pixel = e.pixel;
  4383. get(Layer.prototype.__proto__ || Object.getPrototypeOf(Layer.prototype), "clickEvent", this).call(this, pixel, e);
  4384. }
  4385. }, {
  4386. key: "mousemoveEvent",
  4387. value: function mousemoveEvent(e) {
  4388. var pixel = e.pixel;
  4389. get(Layer.prototype.__proto__ || Object.getPrototypeOf(Layer.prototype), "mousemoveEvent", this).call(this, pixel, e);
  4390. }
  4391. }, {
  4392. key: "bindEvent",
  4393. value: function bindEvent(e) {
  4394. var map = this.map;
  4395. if (this.options.methods) {
  4396. if (this.options.methods.click) {
  4397. map.setDefaultCursor("default");
  4398. map.addListener('click', this.clickEvent);
  4399. }
  4400. if (this.options.methods.mousemove) {
  4401. map.addListener('mousemove', this.mousemoveEvent);
  4402. }
  4403. }
  4404. }
  4405. }, {
  4406. key: "unbindEvent",
  4407. value: function unbindEvent(e) {
  4408. var map = this.map;
  4409. if (this.options.methods) {
  4410. if (this.options.methods.click) {
  4411. map.removeListener('click', this.clickEvent);
  4412. }
  4413. if (this.options.methods.mousemove) {
  4414. map.removeListener('mousemove', this.mousemoveEvent);
  4415. }
  4416. }
  4417. }
  4418. }, {
  4419. key: "getContext",
  4420. value: function getContext() {
  4421. return this.canvasLayer.canvas.getContext(this.context);
  4422. }
  4423. }, {
  4424. key: "_canvasUpdate",
  4425. value: function _canvasUpdate(time) {
  4426. if (!this.canvasLayer) {
  4427. return;
  4428. }
  4429. var self = this;
  4430. var animationOptions = self.options.animation;
  4431. var context = this.getContext();
  4432. if (self.isEnabledTime()) {
  4433. if (time === undefined) {
  4434. clear(context);
  4435. return;
  4436. }
  4437. if (this.context == '2d') {
  4438. context.save();
  4439. context.globalCompositeOperation = 'destination-out';
  4440. context.fillStyle = 'rgba(0, 0, 0, .1)';
  4441. context.fillRect(0, 0, context.canvas.width, context.canvas.height);
  4442. context.restore();
  4443. }
  4444. } else {
  4445. clear(context);
  4446. }
  4447. if (this.context == '2d') {
  4448. for (var key in self.options) {
  4449. context[key] = self.options[key];
  4450. }
  4451. } else {
  4452. context.clear(context.COLOR_BUFFER_BIT);
  4453. }
  4454. if (self.options.minZoom && map.getZoom() < self.options.minZoom || self.options.maxZoom && map.getZoom() > self.options.maxZoom) {
  4455. return;
  4456. }
  4457. var scale = 1;
  4458. if (this.context != '2d') {
  4459. scale = this.canvasLayer.devicePixelRatio;
  4460. }
  4461. var map = this.map;
  4462. var mapProjection = map.getProjection();
  4463. var scale = Math.pow(2, map.zoom) * resolutionScale;
  4464. var offset = mapProjection.fromLatLngToPoint(this.canvasLayer.getTopLeft());
  4465. var dataGetOptions = {
  4466. //fromColumn: self.options.coordType == 'bd09mc' ? 'coordinates' : 'coordinates_mercator',
  4467. transferCoordinate: function transferCoordinate(coordinate) {
  4468. var latLng = new google.maps.LatLng(coordinate[1], coordinate[0]);
  4469. var worldPoint = mapProjection.fromLatLngToPoint(latLng);
  4470. var pixel = {
  4471. x: (worldPoint.x - offset.x) * scale,
  4472. y: (worldPoint.y - offset.y) * scale
  4473. };
  4474. return [pixel.x, pixel.y];
  4475. }
  4476. };
  4477. if (time !== undefined) {
  4478. dataGetOptions.filter = function (item) {
  4479. var trails = animationOptions.trails || 10;
  4480. if (time && item.time > time - trails && item.time < time) {
  4481. return true;
  4482. } else {
  4483. return false;
  4484. }
  4485. };
  4486. }
  4487. // get data from data set
  4488. var data = self.dataSet.get(dataGetOptions);
  4489. this.processData(data);
  4490. var latLng = new google.maps.LatLng(0, 0);
  4491. var worldPoint = mapProjection.fromLatLngToPoint(latLng);
  4492. var pixel = {
  4493. x: (worldPoint.x - offset.x) * scale,
  4494. y: (worldPoint.y - offset.y) * scale
  4495. };
  4496. if (self.options.unit == 'm' && self.options.size) {
  4497. self.options._size = self.options.size / zoomUnit;
  4498. } else {
  4499. self.options._size = self.options.size;
  4500. }
  4501. this.drawContext(context, new DataSet(data), self.options, pixel);
  4502. //console.timeEnd('draw');
  4503. //console.timeEnd('update')
  4504. self.options.updateCallback && self.options.updateCallback(time);
  4505. }
  4506. }, {
  4507. key: "init",
  4508. value: function init(options) {
  4509. var self = this;
  4510. self.options = options;
  4511. this.initDataRange(options);
  4512. this.context = self.options.context || '2d';
  4513. if (self.options.zIndex) {
  4514. this.canvasLayer && this.canvasLayer.setZIndex(self.options.zIndex);
  4515. }
  4516. this.initAnimator();
  4517. }
  4518. }, {
  4519. key: "addAnimatorEvent",
  4520. value: function addAnimatorEvent() {
  4521. this.map.addListener('movestart', this.animatorMovestartEvent.bind(this));
  4522. this.map.addListener('moveend', this.animatorMoveendEvent.bind(this));
  4523. }
  4524. }, {
  4525. key: "show",
  4526. value: function show() {
  4527. this.map.addOverlay(this.canvasLayer);
  4528. }
  4529. }, {
  4530. key: "hide",
  4531. value: function hide() {
  4532. this.map.removeOverlay(this.canvasLayer);
  4533. }
  4534. }, {
  4535. key: "draw",
  4536. value: function draw() {
  4537. self.canvasLayer.draw();
  4538. }
  4539. }]);
  4540. return Layer;
  4541. }(BaseLayer);
  4542. /**
  4543. * @author kyle / http://nikai.us/
  4544. */
  4545. var geojson = {
  4546. getDataSet: function getDataSet(geoJson) {
  4547. var data = [];
  4548. var features = geoJson.features;
  4549. for (var i = 0; i < features.length; i++) {
  4550. var feature = features[i];
  4551. var geometry = feature.geometry;
  4552. var properties = feature.properties;
  4553. var item = {};
  4554. for (var key in properties) {
  4555. item[key] = properties[key];
  4556. }
  4557. item.geometry = geometry;
  4558. data.push(item);
  4559. }
  4560. return new DataSet(data);
  4561. }
  4562. };
  4563. /**
  4564. * @author kyle / http://nikai.us/
  4565. */
  4566. var csv = {
  4567. CSVToArray: function CSVToArray(strData, strDelimiter) {
  4568. // Check to see if the delimiter is defined. If not,
  4569. // then default to comma.
  4570. strDelimiter = strDelimiter || ",";
  4571. // Create a regular expression to parse the CSV values.
  4572. var objPattern = new RegExp(
  4573. // Delimiters.
  4574. "(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +
  4575. // Quoted fields.
  4576. "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +
  4577. // Standard fields.
  4578. "([^\"\\" + strDelimiter + "\\r\\n]*))", "gi");
  4579. // Create an array to hold our data. Give the array
  4580. // a default empty first row.
  4581. var arrData = [[]];
  4582. // Create an array to hold our individual pattern
  4583. // matching groups.
  4584. var arrMatches = null;
  4585. // Keep looping over the regular expression matches
  4586. // until we can no longer find a match.
  4587. while (arrMatches = objPattern.exec(strData)) {
  4588. // Get the delimiter that was found.
  4589. var strMatchedDelimiter = arrMatches[1];
  4590. // Check to see if the given delimiter has a length
  4591. // (is not the start of string) and if it matches
  4592. // field delimiter. If id does not, then we know
  4593. // that this delimiter is a row delimiter.
  4594. if (strMatchedDelimiter.length && strMatchedDelimiter !== strDelimiter) {
  4595. // Since we have reached a new row of data,
  4596. // add an empty row to our data array.
  4597. arrData.push([]);
  4598. }
  4599. var strMatchedValue;
  4600. // Now that we have our delimiter out of the way,
  4601. // let's check to see which kind of value we
  4602. // captured (quoted or unquoted).
  4603. if (arrMatches[2]) {
  4604. // We found a quoted value. When we capture
  4605. // this value, unescape any double quotes.
  4606. strMatchedValue = arrMatches[2].replace(new RegExp("\"\"", "g"), "\"");
  4607. } else {
  4608. // We found a non-quoted value.
  4609. strMatchedValue = arrMatches[3];
  4610. }
  4611. // Now that we have our value string, let's add
  4612. // it to the data array.
  4613. arrData[arrData.length - 1].push(strMatchedValue);
  4614. }
  4615. // Return the parsed data.
  4616. return arrData;
  4617. },
  4618. getDataSet: function getDataSet(csvStr, split) {
  4619. var arr = this.CSVToArray(csvStr, split || ',');
  4620. var data = [];
  4621. var header = arr[0];
  4622. for (var i = 1; i < arr.length - 1; i++) {
  4623. var line = arr[i];
  4624. var item = {};
  4625. for (var j = 0; j < line.length; j++) {
  4626. var value = line[j];
  4627. if (header[j] == 'geometry') {
  4628. value = JSON.parse(value);
  4629. }
  4630. item[header[j]] = value;
  4631. }
  4632. data.push(item);
  4633. }
  4634. return new DataSet(data);
  4635. }
  4636. };
  4637. exports.version = version;
  4638. exports.canvasClear = clear;
  4639. exports.canvasResolutionScale = resolutionScale$1;
  4640. exports.canvasDrawSimple = drawSimple;
  4641. exports.canvasDrawHeatmap = drawHeatmap;
  4642. exports.canvasDrawGrid = drawGrid;
  4643. exports.canvasDrawHoneycomb = drawHoneycomb;
  4644. exports.webglDrawSimple = webglDrawSimple;
  4645. exports.webglDrawPoint = point;
  4646. exports.webglDrawLine = line;
  4647. exports.webglDrawPolygon = polygon;
  4648. exports.utilCityCenter = cityCenter;
  4649. exports.utilCurve = curve;
  4650. exports.utilForceEdgeBundling = ForceEdgeBundling;
  4651. exports.utilDataRangeIntensity = Intensity;
  4652. exports.utilDataRangeCategory = Category;
  4653. exports.utilDataRangeChoropleth = Choropleth;
  4654. exports.Map = MapHelper;
  4655. exports.baiduMapCanvasLayer = CanvasLayer;
  4656. exports.baiduMapAnimationLayer = AnimationLayer;
  4657. exports.baiduMapLayer = Layer;
  4658. exports.googleMapCanvasLayer = CanvasLayer$2;
  4659. exports.googleMapLayer = Layer$2;
  4660. exports.DataSet = DataSet;
  4661. exports.geojson = geojson;
  4662. exports.csv = csv;
  4663. Object.defineProperty(exports, '__esModule', { value: true });
  4664. })));