mapbox-gl-draw-0.18.1.js 263 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.MapboxDraw = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. 'use strict';
  3. var runSetup = require('./src/setup');
  4. var setupOptions = require('./src/options');
  5. var setupAPI = require('./src/api');
  6. var Constants = require('./src/constants');
  7. var setupDraw = function setupDraw(options, api) {
  8. options = setupOptions(options);
  9. var ctx = {
  10. options: options
  11. };
  12. api = setupAPI(ctx, api);
  13. ctx.api = api;
  14. var setup = runSetup(ctx);
  15. api.onAdd = setup.onAdd;
  16. api.onRemove = setup.onRemove;
  17. api.types = Constants.types;
  18. api.options = options;
  19. return api;
  20. };
  21. module.exports = function (options) {
  22. setupDraw(options, this);
  23. };
  24. },{"./src/api":23,"./src/constants":24,"./src/options":59,"./src/setup":61}],2:[function(require,module,exports){
  25. var wgs84 = require('wgs84');
  26. module.exports.geometry = geometry;
  27. module.exports.ring = ringArea;
  28. function geometry(_) {
  29. var area = 0, i;
  30. switch (_.type) {
  31. case 'Polygon':
  32. return polygonArea(_.coordinates);
  33. case 'MultiPolygon':
  34. for (i = 0; i < _.coordinates.length; i++) {
  35. area += polygonArea(_.coordinates[i]);
  36. }
  37. return area;
  38. case 'Point':
  39. case 'MultiPoint':
  40. case 'LineString':
  41. case 'MultiLineString':
  42. return 0;
  43. case 'GeometryCollection':
  44. for (i = 0; i < _.geometries.length; i++) {
  45. area += geometry(_.geometries[i]);
  46. }
  47. return area;
  48. }
  49. }
  50. function polygonArea(coords) {
  51. var area = 0;
  52. if (coords && coords.length > 0) {
  53. area += Math.abs(ringArea(coords[0]));
  54. for (var i = 1; i < coords.length; i++) {
  55. area -= Math.abs(ringArea(coords[i]));
  56. }
  57. }
  58. return area;
  59. }
  60. /**
  61. * Calculate the approximate area of the polygon were it projected onto
  62. * the earth. Note that this area will be positive if ring is oriented
  63. * clockwise, otherwise it will be negative.
  64. *
  65. * Reference:
  66. * Robert. G. Chamberlain and William H. Duquette, "Some Algorithms for
  67. * Polygons on a Sphere", JPL Publication 07-03, Jet Propulsion
  68. * Laboratory, Pasadena, CA, June 2007 http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409
  69. *
  70. * Returns:
  71. * {float} The approximate signed geodesic area of the polygon in square
  72. * meters.
  73. */
  74. function ringArea(coords) {
  75. var p1, p2, p3, lowerIndex, middleIndex, upperIndex, i,
  76. area = 0,
  77. coordsLength = coords.length;
  78. if (coordsLength > 2) {
  79. for (i = 0; i < coordsLength; i++) {
  80. if (i === coordsLength - 2) {// i = N-2
  81. lowerIndex = coordsLength - 2;
  82. middleIndex = coordsLength -1;
  83. upperIndex = 0;
  84. } else if (i === coordsLength - 1) {// i = N-1
  85. lowerIndex = coordsLength - 1;
  86. middleIndex = 0;
  87. upperIndex = 1;
  88. } else { // i = 0 to N-3
  89. lowerIndex = i;
  90. middleIndex = i+1;
  91. upperIndex = i+2;
  92. }
  93. p1 = coords[lowerIndex];
  94. p2 = coords[middleIndex];
  95. p3 = coords[upperIndex];
  96. area += ( rad(p3[0]) - rad(p1[0]) ) * Math.sin( rad(p2[1]));
  97. }
  98. area = area * wgs84.RADIUS * wgs84.RADIUS / 2;
  99. }
  100. return area;
  101. }
  102. function rad(_) {
  103. return _ * Math.PI / 180;
  104. }
  105. },{"wgs84":21}],3:[function(require,module,exports){
  106. module.exports = normalize;
  107. var types = {
  108. Point: 'geometry',
  109. MultiPoint: 'geometry',
  110. LineString: 'geometry',
  111. MultiLineString: 'geometry',
  112. Polygon: 'geometry',
  113. MultiPolygon: 'geometry',
  114. GeometryCollection: 'geometry',
  115. Feature: 'feature',
  116. FeatureCollection: 'featurecollection'
  117. };
  118. /**
  119. * Normalize a GeoJSON feature into a FeatureCollection.
  120. *
  121. * @param {object} gj geojson data
  122. * @returns {object} normalized geojson data
  123. */
  124. function normalize(gj) {
  125. if (!gj || !gj.type) return null;
  126. var type = types[gj.type];
  127. if (!type) return null;
  128. if (type === 'geometry') {
  129. return {
  130. type: 'FeatureCollection',
  131. features: [{
  132. type: 'Feature',
  133. properties: {},
  134. geometry: gj
  135. }]
  136. };
  137. } else if (type === 'feature') {
  138. return {
  139. type: 'FeatureCollection',
  140. features: [gj]
  141. };
  142. } else if (type === 'featurecollection') {
  143. return gj;
  144. }
  145. }
  146. },{}],4:[function(require,module,exports){
  147. var jsonlint = require('jsonlint-lines'),
  148. geojsonHintObject = require('./object');
  149. /**
  150. * @alias geojsonhint
  151. * @param {(string|object)} GeoJSON given as a string or as an object
  152. * @param {Object} options
  153. * @param {boolean} [options.noDuplicateMembers=true] forbid repeated
  154. * properties. This is only available for string input, becaused parsed
  155. * Objects cannot have duplicate properties.
  156. * @param {boolean} [options.precisionWarning=true] warn if GeoJSON contains
  157. * unnecessary coordinate precision.
  158. * @returns {Array<Object>} an array of errors
  159. */
  160. function hint(str, options) {
  161. var gj, errors = [];
  162. if (typeof str === 'object') {
  163. gj = str;
  164. } else if (typeof str === 'string') {
  165. try {
  166. gj = jsonlint.parse(str);
  167. } catch(e) {
  168. var match = e.message.match(/line (\d+)/);
  169. var lineNumber = parseInt(match[1], 10);
  170. return [{
  171. line: lineNumber - 1,
  172. message: e.message,
  173. error: e
  174. }];
  175. }
  176. } else {
  177. return [{
  178. message: 'Expected string or object as input',
  179. line: 0
  180. }];
  181. }
  182. errors = errors.concat(geojsonHintObject.hint(gj, options));
  183. return errors;
  184. }
  185. module.exports.hint = hint;
  186. },{"./object":5,"jsonlint-lines":15}],5:[function(require,module,exports){
  187. var rightHandRule = require('./rhr');
  188. /**
  189. * @alias geojsonhint
  190. * @param {(string|object)} GeoJSON given as a string or as an object
  191. * @param {Object} options
  192. * @param {boolean} [options.noDuplicateMembers=true] forbid repeated
  193. * properties. This is only available for string input, becaused parsed
  194. * Objects cannot have duplicate properties.
  195. * @param {boolean} [options.precisionWarning=true] warn if GeoJSON contains
  196. * unnecessary coordinate precision.
  197. * @returns {Array<Object>} an array of errors
  198. */
  199. function hint(gj, options) {
  200. var errors = [];
  201. var precisionWarningCount = 0;
  202. var maxPrecisionWarnings = 10;
  203. var maxPrecision = 6;
  204. function root(_) {
  205. if ((!options || options.noDuplicateMembers !== false) &&
  206. _.__duplicateProperties__) {
  207. errors.push({
  208. message: 'An object contained duplicate members, making parsing ambigous: ' + _.__duplicateProperties__.join(', '),
  209. line: _.__line__
  210. });
  211. }
  212. if (requiredProperty(_, 'type', 'string')) {
  213. return;
  214. }
  215. if (!types[_.type]) {
  216. var expectedType = typesLower[_.type.toLowerCase()];
  217. if (expectedType !== undefined) {
  218. errors.push({
  219. message: 'Expected ' + expectedType + ' but got ' + _.type + ' (case sensitive)',
  220. line: _.__line__
  221. });
  222. } else {
  223. errors.push({
  224. message: 'The type ' + _.type + ' is unknown',
  225. line: _.__line__
  226. });
  227. }
  228. } else if (_) {
  229. types[_.type](_);
  230. }
  231. }
  232. function everyIs(_, type) {
  233. // make a single exception because typeof null === 'object'
  234. return _.every(function(x) {
  235. return x !== null && typeof x === type;
  236. });
  237. }
  238. function requiredProperty(_, name, type) {
  239. if (typeof _[name] === 'undefined') {
  240. return errors.push({
  241. message: '"' + name + '" member required',
  242. line: _.__line__
  243. });
  244. } else if (type === 'array') {
  245. if (!Array.isArray(_[name])) {
  246. return errors.push({
  247. message: '"' + name +
  248. '" member should be an array, but is an ' +
  249. (typeof _[name]) + ' instead',
  250. line: _.__line__
  251. });
  252. }
  253. } else if (type === 'object' && _[name] && _[name].constructor.name !== 'Object') {
  254. return errors.push({
  255. message: '"' + name +
  256. '" member should be ' + (type) +
  257. ', but is an ' + (_[name].constructor.name) + ' instead',
  258. line: _.__line__
  259. });
  260. } else if (type && typeof _[name] !== type) {
  261. return errors.push({
  262. message: '"' + name +
  263. '" member should be ' + (type) +
  264. ', but is an ' + (typeof _[name]) + ' instead',
  265. line: _.__line__
  266. });
  267. }
  268. }
  269. // https://tools.ietf.org/html/rfc7946#section-3.3
  270. function FeatureCollection(featureCollection) {
  271. crs(featureCollection);
  272. bbox(featureCollection);
  273. if (featureCollection.properties !== undefined) {
  274. errors.push({
  275. message: 'FeatureCollection object cannot contain a "properties" member',
  276. line: featureCollection.__line__
  277. });
  278. }
  279. if (featureCollection.coordinates !== undefined) {
  280. errors.push({
  281. message: 'FeatureCollection object cannot contain a "coordinates" member',
  282. line: featureCollection.__line__
  283. });
  284. }
  285. if (!requiredProperty(featureCollection, 'features', 'array')) {
  286. if (!everyIs(featureCollection.features, 'object')) {
  287. return errors.push({
  288. message: 'Every feature must be an object',
  289. line: featureCollection.__line__
  290. });
  291. }
  292. featureCollection.features.forEach(Feature);
  293. }
  294. }
  295. // https://tools.ietf.org/html/rfc7946#section-3.1.1
  296. function position(_, line) {
  297. if (!Array.isArray(_)) {
  298. return errors.push({
  299. message: 'position should be an array, is a ' + (typeof _) +
  300. ' instead',
  301. line: _.__line__ || line
  302. });
  303. }
  304. if (_.length < 2) {
  305. return errors.push({
  306. message: 'position must have 2 or more elements',
  307. line: _.__line__ || line
  308. });
  309. }
  310. if (_.length > 3) {
  311. return errors.push({
  312. message: 'position should not have more than 3 elements',
  313. level: 'message',
  314. line: _.__line__ || line
  315. });
  316. }
  317. if (!everyIs(_, 'number')) {
  318. return errors.push({
  319. message: 'each element in a position must be a number',
  320. line: _.__line__ || line
  321. });
  322. }
  323. if (options && options.precisionWarning) {
  324. if (precisionWarningCount === maxPrecisionWarnings) {
  325. precisionWarningCount += 1;
  326. return errors.push({
  327. message: 'truncated warnings: we\'ve encountered coordinate precision warning ' + maxPrecisionWarnings + ' times, no more warnings will be reported',
  328. level: 'message',
  329. line: _.__line__ || line
  330. });
  331. } else if (precisionWarningCount < maxPrecisionWarnings) {
  332. _.forEach(function(num) {
  333. var precision = 0;
  334. var decimalStr = String(num).split('.')[1];
  335. if (decimalStr !== undefined)
  336. precision = decimalStr.length;
  337. if (precision > maxPrecision) {
  338. precisionWarningCount += 1;
  339. return errors.push({
  340. message: 'precision of coordinates should be reduced',
  341. level: 'message',
  342. line: _.__line__ || line
  343. });
  344. }
  345. });
  346. }
  347. }
  348. }
  349. function positionArray(coords, type, depth, line) {
  350. if (line === undefined && coords.__line__ !== undefined) {
  351. line = coords.__line__;
  352. }
  353. if (depth === 0) {
  354. return position(coords, line);
  355. }
  356. if (depth === 1 && type) {
  357. if (type === 'LinearRing') {
  358. if (!Array.isArray(coords[coords.length - 1])) {
  359. errors.push({
  360. message: 'a number was found where a coordinate array should have been found: this needs to be nested more deeply',
  361. line: line
  362. });
  363. return true;
  364. }
  365. if (coords.length < 4) {
  366. errors.push({
  367. message: 'a LinearRing of coordinates needs to have four or more positions',
  368. line: line
  369. });
  370. }
  371. if (coords.length &&
  372. (coords[coords.length - 1].length !== coords[0].length ||
  373. !coords[coords.length - 1].every(function(pos, index) {
  374. return coords[0][index] === pos;
  375. }))) {
  376. errors.push({
  377. message: 'the first and last positions in a LinearRing of coordinates must be the same',
  378. line: line
  379. });
  380. return true;
  381. }
  382. } else if (type === 'Line' && coords.length < 2) {
  383. return errors.push({
  384. message: 'a line needs to have two or more coordinates to be valid',
  385. line: line
  386. });
  387. }
  388. }
  389. if (!Array.isArray(coords)) {
  390. errors.push({
  391. message: 'a number was found where a coordinate array should have been found: this needs to be nested more deeply',
  392. line: line
  393. });
  394. } else {
  395. var results = coords.map(function(c) {
  396. return positionArray(c, type, depth - 1, c.__line__ || line);
  397. });
  398. return results.some(function(r) {
  399. return r;
  400. });
  401. }
  402. }
  403. function crs(_) {
  404. if (!_.crs) return;
  405. var defaultCRSName = 'urn:ogc:def:crs:OGC:1.3:CRS84';
  406. if (typeof _.crs === 'object' && _.crs.properties && _.crs.properties.name === defaultCRSName) {
  407. errors.push({
  408. message: 'old-style crs member is not recommended, this object is equivalent to the default and should be removed',
  409. line: _.__line__
  410. });
  411. } else {
  412. errors.push({
  413. message: 'old-style crs member is not recommended',
  414. line: _.__line__
  415. });
  416. }
  417. }
  418. function bbox(_) {
  419. if (!_.bbox) {
  420. return;
  421. }
  422. if (Array.isArray(_.bbox)) {
  423. if (!everyIs(_.bbox, 'number')) {
  424. errors.push({
  425. message: 'each element in a bbox member must be a number',
  426. line: _.bbox.__line__
  427. });
  428. }
  429. if (!(_.bbox.length === 4 || _.bbox.length === 6)) {
  430. errors.push({
  431. message: 'bbox must contain 4 elements (for 2D) or 6 elements (for 3D)',
  432. line: _.bbox.__line__
  433. });
  434. }
  435. return errors.length;
  436. }
  437. errors.push({
  438. message: 'bbox member must be an array of numbers, but is a ' + (typeof _.bbox),
  439. line: _.__line__
  440. });
  441. }
  442. function geometrySemantics(geom) {
  443. if (geom.properties !== undefined) {
  444. errors.push({
  445. message: 'geometry object cannot contain a "properties" member',
  446. line: geom.__line__
  447. });
  448. }
  449. if (geom.geometry !== undefined) {
  450. errors.push({
  451. message: 'geometry object cannot contain a "geometry" member',
  452. line: geom.__line__
  453. });
  454. }
  455. if (geom.features !== undefined) {
  456. errors.push({
  457. message: 'geometry object cannot contain a "features" member',
  458. line: geom.__line__
  459. });
  460. }
  461. }
  462. // https://tools.ietf.org/html/rfc7946#section-3.1.2
  463. function Point(point) {
  464. crs(point);
  465. bbox(point);
  466. geometrySemantics(point);
  467. if (!requiredProperty(point, 'coordinates', 'array')) {
  468. position(point.coordinates);
  469. }
  470. }
  471. // https://tools.ietf.org/html/rfc7946#section-3.1.6
  472. function Polygon(polygon) {
  473. crs(polygon);
  474. bbox(polygon);
  475. if (!requiredProperty(polygon, 'coordinates', 'array')) {
  476. if (!positionArray(polygon.coordinates, 'LinearRing', 2)) {
  477. rightHandRule(polygon, errors);
  478. }
  479. }
  480. }
  481. // https://tools.ietf.org/html/rfc7946#section-3.1.7
  482. function MultiPolygon(multiPolygon) {
  483. crs(multiPolygon);
  484. bbox(multiPolygon);
  485. if (!requiredProperty(multiPolygon, 'coordinates', 'array')) {
  486. if (!positionArray(multiPolygon.coordinates, 'LinearRing', 3)) {
  487. rightHandRule(multiPolygon, errors);
  488. }
  489. }
  490. }
  491. // https://tools.ietf.org/html/rfc7946#section-3.1.4
  492. function LineString(lineString) {
  493. crs(lineString);
  494. bbox(lineString);
  495. if (!requiredProperty(lineString, 'coordinates', 'array')) {
  496. positionArray(lineString.coordinates, 'Line', 1);
  497. }
  498. }
  499. // https://tools.ietf.org/html/rfc7946#section-3.1.5
  500. function MultiLineString(multiLineString) {
  501. crs(multiLineString);
  502. bbox(multiLineString);
  503. if (!requiredProperty(multiLineString, 'coordinates', 'array')) {
  504. positionArray(multiLineString.coordinates, 'Line', 2);
  505. }
  506. }
  507. // https://tools.ietf.org/html/rfc7946#section-3.1.3
  508. function MultiPoint(multiPoint) {
  509. crs(multiPoint);
  510. bbox(multiPoint);
  511. if (!requiredProperty(multiPoint, 'coordinates', 'array')) {
  512. positionArray(multiPoint.coordinates, '', 1);
  513. }
  514. }
  515. // https://tools.ietf.org/html/rfc7946#section-3.1.8
  516. function GeometryCollection(geometryCollection) {
  517. crs(geometryCollection);
  518. bbox(geometryCollection);
  519. if (!requiredProperty(geometryCollection, 'geometries', 'array')) {
  520. if (!everyIs(geometryCollection.geometries, 'object')) {
  521. errors.push({
  522. message: 'The geometries array in a GeometryCollection must contain only geometry objects',
  523. line: geometryCollection.__line__
  524. });
  525. }
  526. if (geometryCollection.geometries.length === 1) {
  527. errors.push({
  528. message: 'GeometryCollection with a single geometry should be avoided in favor of single part or a single object of multi-part type',
  529. line: geometryCollection.geometries.__line__
  530. });
  531. }
  532. geometryCollection.geometries.forEach(function(geometry) {
  533. if (geometry) {
  534. if (geometry.type === 'GeometryCollection') {
  535. errors.push({
  536. message: 'GeometryCollection should avoid nested geometry collections',
  537. line: geometryCollection.geometries.__line__
  538. });
  539. }
  540. root(geometry);
  541. }
  542. });
  543. }
  544. }
  545. // https://tools.ietf.org/html/rfc7946#section-3.2
  546. function Feature(feature) {
  547. crs(feature);
  548. bbox(feature);
  549. // https://github.com/geojson/draft-geojson/blob/master/middle.mkd#feature-object
  550. if (feature.id !== undefined &&
  551. typeof feature.id !== 'string' &&
  552. typeof feature.id !== 'number') {
  553. errors.push({
  554. message: 'Feature "id" member must have a string or number value',
  555. line: feature.__line__
  556. });
  557. }
  558. if (feature.features !== undefined) {
  559. errors.push({
  560. message: 'Feature object cannot contain a "features" member',
  561. line: feature.__line__
  562. });
  563. }
  564. if (feature.coordinates !== undefined) {
  565. errors.push({
  566. message: 'Feature object cannot contain a "coordinates" member',
  567. line: feature.__line__
  568. });
  569. }
  570. if (feature.type !== 'Feature') {
  571. errors.push({
  572. message: 'GeoJSON features must have a type=feature member',
  573. line: feature.__line__
  574. });
  575. }
  576. requiredProperty(feature, 'properties', 'object');
  577. if (!requiredProperty(feature, 'geometry', 'object')) {
  578. // https://tools.ietf.org/html/rfc7946#section-3.2
  579. // tolerate null geometry
  580. if (feature.geometry) root(feature.geometry);
  581. }
  582. }
  583. var types = {
  584. Point: Point,
  585. Feature: Feature,
  586. MultiPoint: MultiPoint,
  587. LineString: LineString,
  588. MultiLineString: MultiLineString,
  589. FeatureCollection: FeatureCollection,
  590. GeometryCollection: GeometryCollection,
  591. Polygon: Polygon,
  592. MultiPolygon: MultiPolygon
  593. };
  594. var typesLower = Object.keys(types).reduce(function(prev, curr) {
  595. prev[curr.toLowerCase()] = curr;
  596. return prev;
  597. }, {});
  598. if (typeof gj !== 'object' ||
  599. gj === null ||
  600. gj === undefined) {
  601. errors.push({
  602. message: 'The root of a GeoJSON object must be an object.',
  603. line: 0
  604. });
  605. return errors;
  606. }
  607. root(gj);
  608. errors.forEach(function(err) {
  609. if ({}.hasOwnProperty.call(err, 'line') && err.line === undefined) {
  610. delete err.line;
  611. }
  612. });
  613. return errors;
  614. }
  615. module.exports.hint = hint;
  616. },{"./rhr":6}],6:[function(require,module,exports){
  617. function rad(x) {
  618. return x * Math.PI / 180;
  619. }
  620. function isRingClockwise (coords) {
  621. var area = 0;
  622. if (coords.length > 2) {
  623. var p1, p2;
  624. for (var i = 0; i < coords.length - 1; i++) {
  625. p1 = coords[i];
  626. p2 = coords[i + 1];
  627. area += rad(p2[0] - p1[0]) * (2 + Math.sin(rad(p1[1])) + Math.sin(rad(p2[1])));
  628. }
  629. }
  630. return area >= 0;
  631. }
  632. function isPolyRHR (coords) {
  633. if (coords && coords.length > 0) {
  634. if (isRingClockwise(coords[0]))
  635. return false;
  636. var interiorCoords = coords.slice(1, coords.length);
  637. if (!interiorCoords.every(isRingClockwise))
  638. return false;
  639. }
  640. return true;
  641. }
  642. function rightHandRule (geometry) {
  643. if (geometry.type === 'Polygon') {
  644. return isPolyRHR(geometry.coordinates);
  645. } else if (geometry.type === 'MultiPolygon') {
  646. return geometry.coordinates.every(isPolyRHR);
  647. }
  648. }
  649. module.exports = function validateRightHandRule(geometry, errors) {
  650. if (!rightHandRule(geometry)) {
  651. errors.push({
  652. message: 'Polygons and MultiPolygons should follow the right-hand rule',
  653. level: 'message',
  654. line: geometry.__line__
  655. });
  656. }
  657. };
  658. },{}],7:[function(require,module,exports){
  659. },{}],8:[function(require,module,exports){
  660. module.exports = Extent;
  661. function Extent() {
  662. if (!(this instanceof Extent)) {
  663. return new Extent();
  664. }
  665. this._bbox = [Infinity, Infinity, -Infinity, -Infinity];
  666. this._valid = false;
  667. }
  668. Extent.prototype.include = function(ll) {
  669. this._valid = true;
  670. this._bbox[0] = Math.min(this._bbox[0], ll[0]);
  671. this._bbox[1] = Math.min(this._bbox[1], ll[1]);
  672. this._bbox[2] = Math.max(this._bbox[2], ll[0]);
  673. this._bbox[3] = Math.max(this._bbox[3], ll[1]);
  674. return this;
  675. };
  676. Extent.prototype.union = function(other) {
  677. this._valid = true;
  678. this._bbox[0] = Math.min(this._bbox[0], other[0]);
  679. this._bbox[1] = Math.min(this._bbox[1], other[1]);
  680. this._bbox[2] = Math.max(this._bbox[2], other[2]);
  681. this._bbox[3] = Math.max(this._bbox[3], other[3]);
  682. return this;
  683. };
  684. Extent.prototype.bbox = function() {
  685. if (!this._valid) return null;
  686. return this._bbox;
  687. };
  688. Extent.prototype.contains = function(ll) {
  689. if (!this._valid) return null;
  690. return this._bbox[0] <= ll[0] &&
  691. this._bbox[1] <= ll[1] &&
  692. this._bbox[2] >= ll[0] &&
  693. this._bbox[3] >= ll[1];
  694. };
  695. Extent.prototype.polygon = function() {
  696. if (!this._valid) return null;
  697. return {
  698. type: 'Polygon',
  699. coordinates: [
  700. [
  701. // W, S
  702. [this._bbox[0], this._bbox[1]],
  703. // E, S
  704. [this._bbox[2], this._bbox[1]],
  705. // E, N
  706. [this._bbox[2], this._bbox[3]],
  707. // W, N
  708. [this._bbox[0], this._bbox[3]],
  709. // W, S
  710. [this._bbox[0], this._bbox[1]]
  711. ]
  712. ]
  713. };
  714. };
  715. },{}],9:[function(require,module,exports){
  716. module.exports = function flatten(list, depth) {
  717. return _flatten(list);
  718. function _flatten(list) {
  719. if (Array.isArray(list) && list.length &&
  720. typeof list[0] === 'number') {
  721. return [list];
  722. }
  723. return list.reduce(function (acc, item) {
  724. if (Array.isArray(item) && Array.isArray(item[0])) {
  725. return acc.concat(_flatten(item));
  726. } else {
  727. acc.push(item);
  728. return acc;
  729. }
  730. }, []);
  731. }
  732. };
  733. },{}],10:[function(require,module,exports){
  734. var geojsonNormalize = require('geojson-normalize'),
  735. geojsonFlatten = require('geojson-flatten'),
  736. flatten = require('./flatten');
  737. module.exports = function(_) {
  738. if (!_) return [];
  739. var normalized = geojsonFlatten(geojsonNormalize(_)),
  740. coordinates = [];
  741. normalized.features.forEach(function(feature) {
  742. if (!feature.geometry) return;
  743. coordinates = coordinates.concat(flatten(feature.geometry.coordinates));
  744. });
  745. return coordinates;
  746. };
  747. },{"./flatten":9,"geojson-flatten":12,"geojson-normalize":13}],11:[function(require,module,exports){
  748. var geojsonCoords = require('geojson-coords'),
  749. traverse = require('traverse'),
  750. extent = require('extent');
  751. module.exports = function(_) {
  752. return getExtent(_).bbox();
  753. };
  754. module.exports.polygon = function(_) {
  755. return getExtent(_).polygon();
  756. };
  757. module.exports.bboxify = function(_) {
  758. return traverse(_).map(function(value) {
  759. if (value && typeof value.type === 'string') {
  760. value.bbox = getExtent(value).bbox();
  761. this.update(value);
  762. }
  763. });
  764. };
  765. function getExtent(_) {
  766. var bbox = [Infinity, Infinity, -Infinity, -Infinity],
  767. ext = extent(),
  768. coords = geojsonCoords(_);
  769. for (var i = 0; i < coords.length; i++) ext.include(coords[i]);
  770. return ext;
  771. }
  772. },{"extent":8,"geojson-coords":10,"traverse":20}],12:[function(require,module,exports){
  773. module.exports = flatten;
  774. function flatten(gj, up) {
  775. switch ((gj && gj.type) || null) {
  776. case 'FeatureCollection':
  777. gj.features = gj.features.reduce(function(mem, feature) {
  778. return mem.concat(flatten(feature));
  779. }, []);
  780. return gj;
  781. case 'Feature':
  782. return flatten(gj.geometry).map(function(geom) {
  783. return {
  784. type: 'Feature',
  785. properties: JSON.parse(JSON.stringify(gj.properties)),
  786. geometry: geom
  787. };
  788. });
  789. case 'MultiPoint':
  790. return gj.coordinates.map(function(_) {
  791. return { type: 'Point', coordinates: _ };
  792. });
  793. case 'MultiPolygon':
  794. return gj.coordinates.map(function(_) {
  795. return { type: 'Polygon', coordinates: _ };
  796. });
  797. case 'MultiLineString':
  798. return gj.coordinates.map(function(_) {
  799. return { type: 'LineString', coordinates: _ };
  800. });
  801. case 'GeometryCollection':
  802. return gj.geometries;
  803. case 'Point':
  804. case 'Polygon':
  805. case 'LineString':
  806. return [gj];
  807. default:
  808. return gj;
  809. }
  810. }
  811. },{}],13:[function(require,module,exports){
  812. arguments[4][3][0].apply(exports,arguments)
  813. },{"dup":3}],14:[function(require,module,exports){
  814. var hat = module.exports = function (bits, base) {
  815. if (!base) base = 16;
  816. if (bits === undefined) bits = 128;
  817. if (bits <= 0) return '0';
  818. var digits = Math.log(Math.pow(2, bits)) / Math.log(base);
  819. for (var i = 2; digits === Infinity; i *= 2) {
  820. digits = Math.log(Math.pow(2, bits / i)) / Math.log(base) * i;
  821. }
  822. var rem = digits - Math.floor(digits);
  823. var res = '';
  824. for (var i = 0; i < Math.floor(digits); i++) {
  825. var x = Math.floor(Math.random() * base).toString(base);
  826. res = x + res;
  827. }
  828. if (rem) {
  829. var b = Math.pow(base, rem);
  830. var x = Math.floor(Math.random() * b).toString(base);
  831. res = x + res;
  832. }
  833. var parsed = parseInt(res, base);
  834. if (parsed !== Infinity && parsed >= Math.pow(2, bits)) {
  835. return hat(bits, base)
  836. }
  837. else return res;
  838. };
  839. hat.rack = function (bits, base, expandBy) {
  840. var fn = function (data) {
  841. var iters = 0;
  842. do {
  843. if (iters ++ > 10) {
  844. if (expandBy) bits += expandBy;
  845. else throw new Error('too many ID collisions, use more bits')
  846. }
  847. var id = hat(bits, base);
  848. } while (Object.hasOwnProperty.call(hats, id));
  849. hats[id] = data;
  850. return id;
  851. };
  852. var hats = fn.hats = {};
  853. fn.get = function (id) {
  854. return fn.hats[id];
  855. };
  856. fn.set = function (id, value) {
  857. fn.hats[id] = value;
  858. return fn;
  859. };
  860. fn.bits = bits || 128;
  861. fn.base = base || 16;
  862. return fn;
  863. };
  864. },{}],15:[function(require,module,exports){
  865. (function (process){
  866. /* parser generated by jison 0.4.17 */
  867. /*
  868. Returns a Parser object of the following structure:
  869. Parser: {
  870. yy: {}
  871. }
  872. Parser.prototype: {
  873. yy: {},
  874. trace: function(),
  875. symbols_: {associative list: name ==> number},
  876. terminals_: {associative list: number ==> name},
  877. productions_: [...],
  878. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  879. table: [...],
  880. defaultActions: {...},
  881. parseError: function(str, hash),
  882. parse: function(input),
  883. lexer: {
  884. EOF: 1,
  885. parseError: function(str, hash),
  886. setInput: function(input),
  887. input: function(),
  888. unput: function(str),
  889. more: function(),
  890. less: function(n),
  891. pastInput: function(),
  892. upcomingInput: function(),
  893. showPosition: function(),
  894. test_match: function(regex_match_array, rule_index),
  895. next: function(),
  896. lex: function(),
  897. begin: function(condition),
  898. popState: function(),
  899. _currentRules: function(),
  900. topState: function(),
  901. pushState: function(condition),
  902. options: {
  903. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  904. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  905. backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
  906. },
  907. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  908. rules: [...],
  909. conditions: {associative list: name ==> set},
  910. }
  911. }
  912. token location info (@$, _$, etc.): {
  913. first_line: n,
  914. last_line: n,
  915. first_column: n,
  916. last_column: n,
  917. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  918. }
  919. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  920. text: (matched text)
  921. token: (the produced terminal token, if any)
  922. line: (yylineno)
  923. }
  924. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  925. loc: (yylloc)
  926. expected: (string describing the set of expected tokens)
  927. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  928. }
  929. */
  930. var jsonlint = (function(){
  931. var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,12],$V1=[1,13],$V2=[1,9],$V3=[1,10],$V4=[1,11],$V5=[1,14],$V6=[1,15],$V7=[14,18,22,24],$V8=[18,22],$V9=[22,24];
  932. var parser = {trace: function trace() { },
  933. yy: {},
  934. symbols_: {"error":2,"JSONString":3,"STRING":4,"JSONNumber":5,"NUMBER":6,"JSONNullLiteral":7,"NULL":8,"JSONBooleanLiteral":9,"TRUE":10,"FALSE":11,"JSONText":12,"JSONValue":13,"EOF":14,"JSONObject":15,"JSONArray":16,"{":17,"}":18,"JSONMemberList":19,"JSONMember":20,":":21,",":22,"[":23,"]":24,"JSONElementList":25,"$accept":0,"$end":1},
  935. terminals_: {2:"error",4:"STRING",6:"NUMBER",8:"NULL",10:"TRUE",11:"FALSE",14:"EOF",17:"{",18:"}",21:":",22:",",23:"[",24:"]"},
  936. productions_: [0,[3,1],[5,1],[7,1],[9,1],[9,1],[12,2],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[15,2],[15,3],[20,3],[19,1],[19,3],[16,2],[16,3],[25,1],[25,3]],
  937. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
  938. /* this == yyval */
  939. var $0 = $$.length - 1;
  940. switch (yystate) {
  941. case 1:
  942. // replace escaped characters with actual character
  943. this.$ = yytext.replace(/\\(\\|")/g, "$"+"1")
  944. .replace(/\\n/g,'\n')
  945. .replace(/\\r/g,'\r')
  946. .replace(/\\t/g,'\t')
  947. .replace(/\\v/g,'\v')
  948. .replace(/\\f/g,'\f')
  949. .replace(/\\b/g,'\b');
  950. break;
  951. case 2:
  952. this.$ = Number(yytext);
  953. break;
  954. case 3:
  955. this.$ = null;
  956. break;
  957. case 4:
  958. this.$ = true;
  959. break;
  960. case 5:
  961. this.$ = false;
  962. break;
  963. case 6:
  964. return this.$ = $$[$0-1];
  965. break;
  966. case 13:
  967. this.$ = {}; Object.defineProperty(this.$, '__line__', {
  968. value: this._$.first_line,
  969. enumerable: false
  970. })
  971. break;
  972. case 14: case 19:
  973. this.$ = $$[$0-1]; Object.defineProperty(this.$, '__line__', {
  974. value: this._$.first_line,
  975. enumerable: false
  976. })
  977. break;
  978. case 15:
  979. this.$ = [$$[$0-2], $$[$0]];
  980. break;
  981. case 16:
  982. this.$ = {}; this.$[$$[$0][0]] = $$[$0][1];
  983. break;
  984. case 17:
  985. this.$ = $$[$0-2];
  986. if ($$[$0-2][$$[$0][0]] !== undefined) {
  987. if (!this.$.__duplicateProperties__) {
  988. Object.defineProperty(this.$, '__duplicateProperties__', {
  989. value: [],
  990. enumerable: false
  991. });
  992. }
  993. this.$.__duplicateProperties__.push($$[$0][0]);
  994. }
  995. $$[$0-2][$$[$0][0]] = $$[$0][1];
  996. break;
  997. case 18:
  998. this.$ = []; Object.defineProperty(this.$, '__line__', {
  999. value: this._$.first_line,
  1000. enumerable: false
  1001. })
  1002. break;
  1003. case 20:
  1004. this.$ = [$$[$0]];
  1005. break;
  1006. case 21:
  1007. this.$ = $$[$0-2]; $$[$0-2].push($$[$0]);
  1008. break;
  1009. }
  1010. },
  1011. table: [{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,12:1,13:2,15:7,16:8,17:$V5,23:$V6},{1:[3]},{14:[1,16]},o($V7,[2,7]),o($V7,[2,8]),o($V7,[2,9]),o($V7,[2,10]),o($V7,[2,11]),o($V7,[2,12]),o($V7,[2,3]),o($V7,[2,4]),o($V7,[2,5]),o([14,18,21,22,24],[2,1]),o($V7,[2,2]),{3:20,4:$V0,18:[1,17],19:18,20:19},{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,13:23,15:7,16:8,17:$V5,23:$V6,24:[1,21],25:22},{1:[2,6]},o($V7,[2,13]),{18:[1,24],22:[1,25]},o($V8,[2,16]),{21:[1,26]},o($V7,[2,18]),{22:[1,28],24:[1,27]},o($V9,[2,20]),o($V7,[2,14]),{3:20,4:$V0,20:29},{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,13:30,15:7,16:8,17:$V5,23:$V6},o($V7,[2,19]),{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,13:31,15:7,16:8,17:$V5,23:$V6},o($V8,[2,17]),o($V8,[2,15]),o($V9,[2,21])],
  1012. defaultActions: {16:[2,6]},
  1013. parseError: function parseError(str, hash) {
  1014. if (hash.recoverable) {
  1015. this.trace(str);
  1016. } else {
  1017. function _parseError (msg, hash) {
  1018. this.message = msg;
  1019. this.hash = hash;
  1020. }
  1021. _parseError.prototype = Error;
  1022. throw new _parseError(str, hash);
  1023. }
  1024. },
  1025. parse: function parse(input) {
  1026. var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
  1027. var args = lstack.slice.call(arguments, 1);
  1028. var lexer = Object.create(this.lexer);
  1029. var sharedState = { yy: {} };
  1030. for (var k in this.yy) {
  1031. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  1032. sharedState.yy[k] = this.yy[k];
  1033. }
  1034. }
  1035. lexer.setInput(input, sharedState.yy);
  1036. sharedState.yy.lexer = lexer;
  1037. sharedState.yy.parser = this;
  1038. if (typeof lexer.yylloc == 'undefined') {
  1039. lexer.yylloc = {};
  1040. }
  1041. var yyloc = lexer.yylloc;
  1042. lstack.push(yyloc);
  1043. var ranges = lexer.options && lexer.options.ranges;
  1044. if (typeof sharedState.yy.parseError === 'function') {
  1045. this.parseError = sharedState.yy.parseError;
  1046. } else {
  1047. this.parseError = Object.getPrototypeOf(this).parseError;
  1048. }
  1049. function popStack(n) {
  1050. stack.length = stack.length - 2 * n;
  1051. vstack.length = vstack.length - n;
  1052. lstack.length = lstack.length - n;
  1053. }
  1054. _token_stack:
  1055. var lex = function () {
  1056. var token;
  1057. token = lexer.lex() || EOF;
  1058. if (typeof token !== 'number') {
  1059. token = self.symbols_[token] || token;
  1060. }
  1061. return token;
  1062. };
  1063. var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
  1064. while (true) {
  1065. state = stack[stack.length - 1];
  1066. if (this.defaultActions[state]) {
  1067. action = this.defaultActions[state];
  1068. } else {
  1069. if (symbol === null || typeof symbol == 'undefined') {
  1070. symbol = lex();
  1071. }
  1072. action = table[state] && table[state][symbol];
  1073. }
  1074. if (typeof action === 'undefined' || !action.length || !action[0]) {
  1075. var errStr = '';
  1076. expected = [];
  1077. for (p in table[state]) {
  1078. if (this.terminals_[p] && p > TERROR) {
  1079. expected.push('\'' + this.terminals_[p] + '\'');
  1080. }
  1081. }
  1082. if (lexer.showPosition) {
  1083. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  1084. } else {
  1085. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  1086. }
  1087. this.parseError(errStr, {
  1088. text: lexer.match,
  1089. token: this.terminals_[symbol] || symbol,
  1090. line: lexer.yylineno,
  1091. loc: yyloc,
  1092. expected: expected
  1093. });
  1094. }
  1095. if (action[0] instanceof Array && action.length > 1) {
  1096. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  1097. }
  1098. switch (action[0]) {
  1099. case 1:
  1100. stack.push(symbol);
  1101. vstack.push(lexer.yytext);
  1102. lstack.push(lexer.yylloc);
  1103. stack.push(action[1]);
  1104. symbol = null;
  1105. if (!preErrorSymbol) {
  1106. yyleng = lexer.yyleng;
  1107. yytext = lexer.yytext;
  1108. yylineno = lexer.yylineno;
  1109. yyloc = lexer.yylloc;
  1110. if (recovering > 0) {
  1111. recovering--;
  1112. }
  1113. } else {
  1114. symbol = preErrorSymbol;
  1115. preErrorSymbol = null;
  1116. }
  1117. break;
  1118. case 2:
  1119. len = this.productions_[action[1]][1];
  1120. yyval.$ = vstack[vstack.length - len];
  1121. yyval._$ = {
  1122. first_line: lstack[lstack.length - (len || 1)].first_line,
  1123. last_line: lstack[lstack.length - 1].last_line,
  1124. first_column: lstack[lstack.length - (len || 1)].first_column,
  1125. last_column: lstack[lstack.length - 1].last_column
  1126. };
  1127. if (ranges) {
  1128. yyval._$.range = [
  1129. lstack[lstack.length - (len || 1)].range[0],
  1130. lstack[lstack.length - 1].range[1]
  1131. ];
  1132. }
  1133. r = this.performAction.apply(yyval, [
  1134. yytext,
  1135. yyleng,
  1136. yylineno,
  1137. sharedState.yy,
  1138. action[1],
  1139. vstack,
  1140. lstack
  1141. ].concat(args));
  1142. if (typeof r !== 'undefined') {
  1143. return r;
  1144. }
  1145. if (len) {
  1146. stack = stack.slice(0, -1 * len * 2);
  1147. vstack = vstack.slice(0, -1 * len);
  1148. lstack = lstack.slice(0, -1 * len);
  1149. }
  1150. stack.push(this.productions_[action[1]][0]);
  1151. vstack.push(yyval.$);
  1152. lstack.push(yyval._$);
  1153. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  1154. stack.push(newState);
  1155. break;
  1156. case 3:
  1157. return true;
  1158. }
  1159. }
  1160. return true;
  1161. }};
  1162. /* generated by jison-lex 0.3.4 */
  1163. var lexer = (function(){
  1164. var lexer = ({
  1165. EOF:1,
  1166. parseError:function parseError(str, hash) {
  1167. if (this.yy.parser) {
  1168. this.yy.parser.parseError(str, hash);
  1169. } else {
  1170. throw new Error(str);
  1171. }
  1172. },
  1173. // resets the lexer, sets new input
  1174. setInput:function (input, yy) {
  1175. this.yy = yy || this.yy || {};
  1176. this._input = input;
  1177. this._more = this._backtrack = this.done = false;
  1178. this.yylineno = this.yyleng = 0;
  1179. this.yytext = this.matched = this.match = '';
  1180. this.conditionStack = ['INITIAL'];
  1181. this.yylloc = {
  1182. first_line: 1,
  1183. first_column: 0,
  1184. last_line: 1,
  1185. last_column: 0
  1186. };
  1187. if (this.options.ranges) {
  1188. this.yylloc.range = [0,0];
  1189. }
  1190. this.offset = 0;
  1191. return this;
  1192. },
  1193. // consumes and returns one char from the input
  1194. input:function () {
  1195. var ch = this._input[0];
  1196. this.yytext += ch;
  1197. this.yyleng++;
  1198. this.offset++;
  1199. this.match += ch;
  1200. this.matched += ch;
  1201. var lines = ch.match(/(?:\r\n?|\n).*/g);
  1202. if (lines) {
  1203. this.yylineno++;
  1204. this.yylloc.last_line++;
  1205. } else {
  1206. this.yylloc.last_column++;
  1207. }
  1208. if (this.options.ranges) {
  1209. this.yylloc.range[1]++;
  1210. }
  1211. this._input = this._input.slice(1);
  1212. return ch;
  1213. },
  1214. // unshifts one char (or a string) into the input
  1215. unput:function (ch) {
  1216. var len = ch.length;
  1217. var lines = ch.split(/(?:\r\n?|\n)/g);
  1218. this._input = ch + this._input;
  1219. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  1220. //this.yyleng -= len;
  1221. this.offset -= len;
  1222. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  1223. this.match = this.match.substr(0, this.match.length - 1);
  1224. this.matched = this.matched.substr(0, this.matched.length - 1);
  1225. if (lines.length - 1) {
  1226. this.yylineno -= lines.length - 1;
  1227. }
  1228. var r = this.yylloc.range;
  1229. this.yylloc = {
  1230. first_line: this.yylloc.first_line,
  1231. last_line: this.yylineno + 1,
  1232. first_column: this.yylloc.first_column,
  1233. last_column: lines ?
  1234. (lines.length === oldLines.length ? this.yylloc.first_column : 0)
  1235. + oldLines[oldLines.length - lines.length].length - lines[0].length :
  1236. this.yylloc.first_column - len
  1237. };
  1238. if (this.options.ranges) {
  1239. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  1240. }
  1241. this.yyleng = this.yytext.length;
  1242. return this;
  1243. },
  1244. // When called from action, caches matched text and appends it on next action
  1245. more:function () {
  1246. this._more = true;
  1247. return this;
  1248. },
  1249. // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
  1250. reject:function () {
  1251. if (this.options.backtrack_lexer) {
  1252. this._backtrack = true;
  1253. } else {
  1254. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), {
  1255. text: "",
  1256. token: null,
  1257. line: this.yylineno
  1258. });
  1259. }
  1260. return this;
  1261. },
  1262. // retain first n characters of the match
  1263. less:function (n) {
  1264. this.unput(this.match.slice(n));
  1265. },
  1266. // displays already matched input, i.e. for error messages
  1267. pastInput:function () {
  1268. var past = this.matched.substr(0, this.matched.length - this.match.length);
  1269. return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
  1270. },
  1271. // displays upcoming input, i.e. for error messages
  1272. upcomingInput:function () {
  1273. var next = this.match;
  1274. if (next.length < 20) {
  1275. next += this._input.substr(0, 20-next.length);
  1276. }
  1277. return (next.substr(0,20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  1278. },
  1279. // displays the character position where the lexing error occurred, i.e. for error messages
  1280. showPosition:function () {
  1281. var pre = this.pastInput();
  1282. var c = new Array(pre.length + 1).join("-");
  1283. return pre + this.upcomingInput() + "\n" + c + "^";
  1284. },
  1285. // test the lexed token: return FALSE when not a match, otherwise return token
  1286. test_match:function (match, indexed_rule) {
  1287. var token,
  1288. lines,
  1289. backup;
  1290. if (this.options.backtrack_lexer) {
  1291. // save context
  1292. backup = {
  1293. yylineno: this.yylineno,
  1294. yylloc: {
  1295. first_line: this.yylloc.first_line,
  1296. last_line: this.last_line,
  1297. first_column: this.yylloc.first_column,
  1298. last_column: this.yylloc.last_column
  1299. },
  1300. yytext: this.yytext,
  1301. match: this.match,
  1302. matches: this.matches,
  1303. matched: this.matched,
  1304. yyleng: this.yyleng,
  1305. offset: this.offset,
  1306. _more: this._more,
  1307. _input: this._input,
  1308. yy: this.yy,
  1309. conditionStack: this.conditionStack.slice(0),
  1310. done: this.done
  1311. };
  1312. if (this.options.ranges) {
  1313. backup.yylloc.range = this.yylloc.range.slice(0);
  1314. }
  1315. }
  1316. lines = match[0].match(/(?:\r\n?|\n).*/g);
  1317. if (lines) {
  1318. this.yylineno += lines.length;
  1319. }
  1320. this.yylloc = {
  1321. first_line: this.yylloc.last_line,
  1322. last_line: this.yylineno + 1,
  1323. first_column: this.yylloc.last_column,
  1324. last_column: lines ?
  1325. lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length :
  1326. this.yylloc.last_column + match[0].length
  1327. };
  1328. this.yytext += match[0];
  1329. this.match += match[0];
  1330. this.matches = match;
  1331. this.yyleng = this.yytext.length;
  1332. if (this.options.ranges) {
  1333. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  1334. }
  1335. this._more = false;
  1336. this._backtrack = false;
  1337. this._input = this._input.slice(match[0].length);
  1338. this.matched += match[0];
  1339. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  1340. if (this.done && this._input) {
  1341. this.done = false;
  1342. }
  1343. if (token) {
  1344. return token;
  1345. } else if (this._backtrack) {
  1346. // recover context
  1347. for (var k in backup) {
  1348. this[k] = backup[k];
  1349. }
  1350. return false; // rule action called reject() implying the next rule should be tested instead.
  1351. }
  1352. return false;
  1353. },
  1354. // return next match in input
  1355. next:function () {
  1356. if (this.done) {
  1357. return this.EOF;
  1358. }
  1359. if (!this._input) {
  1360. this.done = true;
  1361. }
  1362. var token,
  1363. match,
  1364. tempMatch,
  1365. index;
  1366. if (!this._more) {
  1367. this.yytext = '';
  1368. this.match = '';
  1369. }
  1370. var rules = this._currentRules();
  1371. for (var i = 0; i < rules.length; i++) {
  1372. tempMatch = this._input.match(this.rules[rules[i]]);
  1373. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  1374. match = tempMatch;
  1375. index = i;
  1376. if (this.options.backtrack_lexer) {
  1377. token = this.test_match(tempMatch, rules[i]);
  1378. if (token !== false) {
  1379. return token;
  1380. } else if (this._backtrack) {
  1381. match = false;
  1382. continue; // rule action called reject() implying a rule MISmatch.
  1383. } else {
  1384. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  1385. return false;
  1386. }
  1387. } else if (!this.options.flex) {
  1388. break;
  1389. }
  1390. }
  1391. }
  1392. if (match) {
  1393. token = this.test_match(match, rules[index]);
  1394. if (token !== false) {
  1395. return token;
  1396. }
  1397. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  1398. return false;
  1399. }
  1400. if (this._input === "") {
  1401. return this.EOF;
  1402. } else {
  1403. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  1404. text: "",
  1405. token: null,
  1406. line: this.yylineno
  1407. });
  1408. }
  1409. },
  1410. // return next match that has a token
  1411. lex:function lex() {
  1412. var r = this.next();
  1413. if (r) {
  1414. return r;
  1415. } else {
  1416. return this.lex();
  1417. }
  1418. },
  1419. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  1420. begin:function begin(condition) {
  1421. this.conditionStack.push(condition);
  1422. },
  1423. // pop the previously active lexer condition state off the condition stack
  1424. popState:function popState() {
  1425. var n = this.conditionStack.length - 1;
  1426. if (n > 0) {
  1427. return this.conditionStack.pop();
  1428. } else {
  1429. return this.conditionStack[0];
  1430. }
  1431. },
  1432. // produce the lexer rule set which is active for the currently active lexer condition state
  1433. _currentRules:function _currentRules() {
  1434. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  1435. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  1436. } else {
  1437. return this.conditions["INITIAL"].rules;
  1438. }
  1439. },
  1440. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  1441. topState:function topState(n) {
  1442. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  1443. if (n >= 0) {
  1444. return this.conditionStack[n];
  1445. } else {
  1446. return "INITIAL";
  1447. }
  1448. },
  1449. // alias for begin(condition)
  1450. pushState:function pushState(condition) {
  1451. this.begin(condition);
  1452. },
  1453. // return the number of states currently on the stack
  1454. stateStackSize:function stateStackSize() {
  1455. return this.conditionStack.length;
  1456. },
  1457. options: {},
  1458. performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
  1459. var YYSTATE=YY_START;
  1460. switch($avoiding_name_collisions) {
  1461. case 0:/* skip whitespace */
  1462. break;
  1463. case 1:return 6
  1464. break;
  1465. case 2:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2); return 4
  1466. break;
  1467. case 3:return 17
  1468. break;
  1469. case 4:return 18
  1470. break;
  1471. case 5:return 23
  1472. break;
  1473. case 6:return 24
  1474. break;
  1475. case 7:return 22
  1476. break;
  1477. case 8:return 21
  1478. break;
  1479. case 9:return 10
  1480. break;
  1481. case 10:return 11
  1482. break;
  1483. case 11:return 8
  1484. break;
  1485. case 12:return 14
  1486. break;
  1487. case 13:return 'INVALID'
  1488. break;
  1489. }
  1490. },
  1491. rules: [/^(?:\s+)/,/^(?:(-?([0-9]|[1-9][0-9]+))(\.[0-9]+)?([eE][-+]?[0-9]+)?\b)/,/^(?:"(?:\\[\\"bfnrt\/]|\\u[a-fA-F0-9]{4}|[^\\\0-\x09\x0a-\x1f"])*")/,/^(?:\{)/,/^(?:\})/,/^(?:\[)/,/^(?:\])/,/^(?:,)/,/^(?::)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:null\b)/,/^(?:$)/,/^(?:.)/],
  1492. conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],"inclusive":true}}
  1493. });
  1494. return lexer;
  1495. })();
  1496. parser.lexer = lexer;
  1497. function Parser () {
  1498. this.yy = {};
  1499. }
  1500. Parser.prototype = parser;parser.Parser = Parser;
  1501. return new Parser;
  1502. })();
  1503. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  1504. exports.parser = jsonlint;
  1505. exports.Parser = jsonlint.Parser;
  1506. exports.parse = function () { return jsonlint.parse.apply(jsonlint, arguments); };
  1507. exports.main = function commonjsMain(args) {
  1508. if (!args[1]) {
  1509. console.log('Usage: '+args[0]+' FILE');
  1510. process.exit(1);
  1511. }
  1512. var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
  1513. return exports.parser.parse(source);
  1514. };
  1515. if (typeof module !== 'undefined' && require.main === module) {
  1516. exports.main(process.argv.slice(1));
  1517. }
  1518. }
  1519. }).call(this,require('_process'))
  1520. },{"_process":19,"fs":7,"path":17}],16:[function(require,module,exports){
  1521. (function (global){
  1522. /**
  1523. * Lodash (Custom Build) <https://lodash.com/>
  1524. * Build: `lodash modularize exports="npm" -o ./`
  1525. * Copyright JS Foundation and other contributors <https://js.foundation/>
  1526. * Released under MIT license <https://lodash.com/license>
  1527. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  1528. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  1529. */
  1530. /** Used as the size to enable large array optimizations. */
  1531. var LARGE_ARRAY_SIZE = 200;
  1532. /** Used to stand-in for `undefined` hash values. */
  1533. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  1534. /** Used to compose bitmasks for value comparisons. */
  1535. var COMPARE_PARTIAL_FLAG = 1,
  1536. COMPARE_UNORDERED_FLAG = 2;
  1537. /** Used as references for various `Number` constants. */
  1538. var MAX_SAFE_INTEGER = 9007199254740991;
  1539. /** `Object#toString` result references. */
  1540. var argsTag = '[object Arguments]',
  1541. arrayTag = '[object Array]',
  1542. asyncTag = '[object AsyncFunction]',
  1543. boolTag = '[object Boolean]',
  1544. dateTag = '[object Date]',
  1545. errorTag = '[object Error]',
  1546. funcTag = '[object Function]',
  1547. genTag = '[object GeneratorFunction]',
  1548. mapTag = '[object Map]',
  1549. numberTag = '[object Number]',
  1550. nullTag = '[object Null]',
  1551. objectTag = '[object Object]',
  1552. promiseTag = '[object Promise]',
  1553. proxyTag = '[object Proxy]',
  1554. regexpTag = '[object RegExp]',
  1555. setTag = '[object Set]',
  1556. stringTag = '[object String]',
  1557. symbolTag = '[object Symbol]',
  1558. undefinedTag = '[object Undefined]',
  1559. weakMapTag = '[object WeakMap]';
  1560. var arrayBufferTag = '[object ArrayBuffer]',
  1561. dataViewTag = '[object DataView]',
  1562. float32Tag = '[object Float32Array]',
  1563. float64Tag = '[object Float64Array]',
  1564. int8Tag = '[object Int8Array]',
  1565. int16Tag = '[object Int16Array]',
  1566. int32Tag = '[object Int32Array]',
  1567. uint8Tag = '[object Uint8Array]',
  1568. uint8ClampedTag = '[object Uint8ClampedArray]',
  1569. uint16Tag = '[object Uint16Array]',
  1570. uint32Tag = '[object Uint32Array]';
  1571. /**
  1572. * Used to match `RegExp`
  1573. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  1574. */
  1575. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  1576. /** Used to detect host constructors (Safari). */
  1577. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  1578. /** Used to detect unsigned integer values. */
  1579. var reIsUint = /^(?:0|[1-9]\d*)$/;
  1580. /** Used to identify `toStringTag` values of typed arrays. */
  1581. var typedArrayTags = {};
  1582. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  1583. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  1584. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  1585. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  1586. typedArrayTags[uint32Tag] = true;
  1587. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  1588. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  1589. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  1590. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  1591. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  1592. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  1593. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  1594. typedArrayTags[weakMapTag] = false;
  1595. /** Detect free variable `global` from Node.js. */
  1596. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  1597. /** Detect free variable `self`. */
  1598. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  1599. /** Used as a reference to the global object. */
  1600. var root = freeGlobal || freeSelf || Function('return this')();
  1601. /** Detect free variable `exports`. */
  1602. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  1603. /** Detect free variable `module`. */
  1604. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  1605. /** Detect the popular CommonJS extension `module.exports`. */
  1606. var moduleExports = freeModule && freeModule.exports === freeExports;
  1607. /** Detect free variable `process` from Node.js. */
  1608. var freeProcess = moduleExports && freeGlobal.process;
  1609. /** Used to access faster Node.js helpers. */
  1610. var nodeUtil = (function() {
  1611. try {
  1612. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  1613. } catch (e) {}
  1614. }());
  1615. /* Node.js helper references. */
  1616. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  1617. /**
  1618. * A specialized version of `_.filter` for arrays without support for
  1619. * iteratee shorthands.
  1620. *
  1621. * @private
  1622. * @param {Array} [array] The array to iterate over.
  1623. * @param {Function} predicate The function invoked per iteration.
  1624. * @returns {Array} Returns the new filtered array.
  1625. */
  1626. function arrayFilter(array, predicate) {
  1627. var index = -1,
  1628. length = array == null ? 0 : array.length,
  1629. resIndex = 0,
  1630. result = [];
  1631. while (++index < length) {
  1632. var value = array[index];
  1633. if (predicate(value, index, array)) {
  1634. result[resIndex++] = value;
  1635. }
  1636. }
  1637. return result;
  1638. }
  1639. /**
  1640. * Appends the elements of `values` to `array`.
  1641. *
  1642. * @private
  1643. * @param {Array} array The array to modify.
  1644. * @param {Array} values The values to append.
  1645. * @returns {Array} Returns `array`.
  1646. */
  1647. function arrayPush(array, values) {
  1648. var index = -1,
  1649. length = values.length,
  1650. offset = array.length;
  1651. while (++index < length) {
  1652. array[offset + index] = values[index];
  1653. }
  1654. return array;
  1655. }
  1656. /**
  1657. * A specialized version of `_.some` for arrays without support for iteratee
  1658. * shorthands.
  1659. *
  1660. * @private
  1661. * @param {Array} [array] The array to iterate over.
  1662. * @param {Function} predicate The function invoked per iteration.
  1663. * @returns {boolean} Returns `true` if any element passes the predicate check,
  1664. * else `false`.
  1665. */
  1666. function arraySome(array, predicate) {
  1667. var index = -1,
  1668. length = array == null ? 0 : array.length;
  1669. while (++index < length) {
  1670. if (predicate(array[index], index, array)) {
  1671. return true;
  1672. }
  1673. }
  1674. return false;
  1675. }
  1676. /**
  1677. * The base implementation of `_.times` without support for iteratee shorthands
  1678. * or max array length checks.
  1679. *
  1680. * @private
  1681. * @param {number} n The number of times to invoke `iteratee`.
  1682. * @param {Function} iteratee The function invoked per iteration.
  1683. * @returns {Array} Returns the array of results.
  1684. */
  1685. function baseTimes(n, iteratee) {
  1686. var index = -1,
  1687. result = Array(n);
  1688. while (++index < n) {
  1689. result[index] = iteratee(index);
  1690. }
  1691. return result;
  1692. }
  1693. /**
  1694. * The base implementation of `_.unary` without support for storing metadata.
  1695. *
  1696. * @private
  1697. * @param {Function} func The function to cap arguments for.
  1698. * @returns {Function} Returns the new capped function.
  1699. */
  1700. function baseUnary(func) {
  1701. return function(value) {
  1702. return func(value);
  1703. };
  1704. }
  1705. /**
  1706. * Checks if a `cache` value for `key` exists.
  1707. *
  1708. * @private
  1709. * @param {Object} cache The cache to query.
  1710. * @param {string} key The key of the entry to check.
  1711. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1712. */
  1713. function cacheHas(cache, key) {
  1714. return cache.has(key);
  1715. }
  1716. /**
  1717. * Gets the value at `key` of `object`.
  1718. *
  1719. * @private
  1720. * @param {Object} [object] The object to query.
  1721. * @param {string} key The key of the property to get.
  1722. * @returns {*} Returns the property value.
  1723. */
  1724. function getValue(object, key) {
  1725. return object == null ? undefined : object[key];
  1726. }
  1727. /**
  1728. * Converts `map` to its key-value pairs.
  1729. *
  1730. * @private
  1731. * @param {Object} map The map to convert.
  1732. * @returns {Array} Returns the key-value pairs.
  1733. */
  1734. function mapToArray(map) {
  1735. var index = -1,
  1736. result = Array(map.size);
  1737. map.forEach(function(value, key) {
  1738. result[++index] = [key, value];
  1739. });
  1740. return result;
  1741. }
  1742. /**
  1743. * Creates a unary function that invokes `func` with its argument transformed.
  1744. *
  1745. * @private
  1746. * @param {Function} func The function to wrap.
  1747. * @param {Function} transform The argument transform.
  1748. * @returns {Function} Returns the new function.
  1749. */
  1750. function overArg(func, transform) {
  1751. return function(arg) {
  1752. return func(transform(arg));
  1753. };
  1754. }
  1755. /**
  1756. * Converts `set` to an array of its values.
  1757. *
  1758. * @private
  1759. * @param {Object} set The set to convert.
  1760. * @returns {Array} Returns the values.
  1761. */
  1762. function setToArray(set) {
  1763. var index = -1,
  1764. result = Array(set.size);
  1765. set.forEach(function(value) {
  1766. result[++index] = value;
  1767. });
  1768. return result;
  1769. }
  1770. /** Used for built-in method references. */
  1771. var arrayProto = Array.prototype,
  1772. funcProto = Function.prototype,
  1773. objectProto = Object.prototype;
  1774. /** Used to detect overreaching core-js shims. */
  1775. var coreJsData = root['__core-js_shared__'];
  1776. /** Used to resolve the decompiled source of functions. */
  1777. var funcToString = funcProto.toString;
  1778. /** Used to check objects for own properties. */
  1779. var hasOwnProperty = objectProto.hasOwnProperty;
  1780. /** Used to detect methods masquerading as native. */
  1781. var maskSrcKey = (function() {
  1782. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1783. return uid ? ('Symbol(src)_1.' + uid) : '';
  1784. }());
  1785. /**
  1786. * Used to resolve the
  1787. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1788. * of values.
  1789. */
  1790. var nativeObjectToString = objectProto.toString;
  1791. /** Used to detect if a method is native. */
  1792. var reIsNative = RegExp('^' +
  1793. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1794. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1795. );
  1796. /** Built-in value references. */
  1797. var Buffer = moduleExports ? root.Buffer : undefined,
  1798. Symbol = root.Symbol,
  1799. Uint8Array = root.Uint8Array,
  1800. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1801. splice = arrayProto.splice,
  1802. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  1803. /* Built-in method references for those with the same name as other `lodash` methods. */
  1804. var nativeGetSymbols = Object.getOwnPropertySymbols,
  1805. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1806. nativeKeys = overArg(Object.keys, Object);
  1807. /* Built-in method references that are verified to be native. */
  1808. var DataView = getNative(root, 'DataView'),
  1809. Map = getNative(root, 'Map'),
  1810. Promise = getNative(root, 'Promise'),
  1811. Set = getNative(root, 'Set'),
  1812. WeakMap = getNative(root, 'WeakMap'),
  1813. nativeCreate = getNative(Object, 'create');
  1814. /** Used to detect maps, sets, and weakmaps. */
  1815. var dataViewCtorString = toSource(DataView),
  1816. mapCtorString = toSource(Map),
  1817. promiseCtorString = toSource(Promise),
  1818. setCtorString = toSource(Set),
  1819. weakMapCtorString = toSource(WeakMap);
  1820. /** Used to convert symbols to primitives and strings. */
  1821. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1822. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
  1823. /**
  1824. * Creates a hash object.
  1825. *
  1826. * @private
  1827. * @constructor
  1828. * @param {Array} [entries] The key-value pairs to cache.
  1829. */
  1830. function Hash(entries) {
  1831. var index = -1,
  1832. length = entries == null ? 0 : entries.length;
  1833. this.clear();
  1834. while (++index < length) {
  1835. var entry = entries[index];
  1836. this.set(entry[0], entry[1]);
  1837. }
  1838. }
  1839. /**
  1840. * Removes all key-value entries from the hash.
  1841. *
  1842. * @private
  1843. * @name clear
  1844. * @memberOf Hash
  1845. */
  1846. function hashClear() {
  1847. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1848. this.size = 0;
  1849. }
  1850. /**
  1851. * Removes `key` and its value from the hash.
  1852. *
  1853. * @private
  1854. * @name delete
  1855. * @memberOf Hash
  1856. * @param {Object} hash The hash to modify.
  1857. * @param {string} key The key of the value to remove.
  1858. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1859. */
  1860. function hashDelete(key) {
  1861. var result = this.has(key) && delete this.__data__[key];
  1862. this.size -= result ? 1 : 0;
  1863. return result;
  1864. }
  1865. /**
  1866. * Gets the hash value for `key`.
  1867. *
  1868. * @private
  1869. * @name get
  1870. * @memberOf Hash
  1871. * @param {string} key The key of the value to get.
  1872. * @returns {*} Returns the entry value.
  1873. */
  1874. function hashGet(key) {
  1875. var data = this.__data__;
  1876. if (nativeCreate) {
  1877. var result = data[key];
  1878. return result === HASH_UNDEFINED ? undefined : result;
  1879. }
  1880. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1881. }
  1882. /**
  1883. * Checks if a hash value for `key` exists.
  1884. *
  1885. * @private
  1886. * @name has
  1887. * @memberOf Hash
  1888. * @param {string} key The key of the entry to check.
  1889. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1890. */
  1891. function hashHas(key) {
  1892. var data = this.__data__;
  1893. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  1894. }
  1895. /**
  1896. * Sets the hash `key` to `value`.
  1897. *
  1898. * @private
  1899. * @name set
  1900. * @memberOf Hash
  1901. * @param {string} key The key of the value to set.
  1902. * @param {*} value The value to set.
  1903. * @returns {Object} Returns the hash instance.
  1904. */
  1905. function hashSet(key, value) {
  1906. var data = this.__data__;
  1907. this.size += this.has(key) ? 0 : 1;
  1908. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1909. return this;
  1910. }
  1911. // Add methods to `Hash`.
  1912. Hash.prototype.clear = hashClear;
  1913. Hash.prototype['delete'] = hashDelete;
  1914. Hash.prototype.get = hashGet;
  1915. Hash.prototype.has = hashHas;
  1916. Hash.prototype.set = hashSet;
  1917. /**
  1918. * Creates an list cache object.
  1919. *
  1920. * @private
  1921. * @constructor
  1922. * @param {Array} [entries] The key-value pairs to cache.
  1923. */
  1924. function ListCache(entries) {
  1925. var index = -1,
  1926. length = entries == null ? 0 : entries.length;
  1927. this.clear();
  1928. while (++index < length) {
  1929. var entry = entries[index];
  1930. this.set(entry[0], entry[1]);
  1931. }
  1932. }
  1933. /**
  1934. * Removes all key-value entries from the list cache.
  1935. *
  1936. * @private
  1937. * @name clear
  1938. * @memberOf ListCache
  1939. */
  1940. function listCacheClear() {
  1941. this.__data__ = [];
  1942. this.size = 0;
  1943. }
  1944. /**
  1945. * Removes `key` and its value from the list cache.
  1946. *
  1947. * @private
  1948. * @name delete
  1949. * @memberOf ListCache
  1950. * @param {string} key The key of the value to remove.
  1951. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1952. */
  1953. function listCacheDelete(key) {
  1954. var data = this.__data__,
  1955. index = assocIndexOf(data, key);
  1956. if (index < 0) {
  1957. return false;
  1958. }
  1959. var lastIndex = data.length - 1;
  1960. if (index == lastIndex) {
  1961. data.pop();
  1962. } else {
  1963. splice.call(data, index, 1);
  1964. }
  1965. --this.size;
  1966. return true;
  1967. }
  1968. /**
  1969. * Gets the list cache value for `key`.
  1970. *
  1971. * @private
  1972. * @name get
  1973. * @memberOf ListCache
  1974. * @param {string} key The key of the value to get.
  1975. * @returns {*} Returns the entry value.
  1976. */
  1977. function listCacheGet(key) {
  1978. var data = this.__data__,
  1979. index = assocIndexOf(data, key);
  1980. return index < 0 ? undefined : data[index][1];
  1981. }
  1982. /**
  1983. * Checks if a list cache value for `key` exists.
  1984. *
  1985. * @private
  1986. * @name has
  1987. * @memberOf ListCache
  1988. * @param {string} key The key of the entry to check.
  1989. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1990. */
  1991. function listCacheHas(key) {
  1992. return assocIndexOf(this.__data__, key) > -1;
  1993. }
  1994. /**
  1995. * Sets the list cache `key` to `value`.
  1996. *
  1997. * @private
  1998. * @name set
  1999. * @memberOf ListCache
  2000. * @param {string} key The key of the value to set.
  2001. * @param {*} value The value to set.
  2002. * @returns {Object} Returns the list cache instance.
  2003. */
  2004. function listCacheSet(key, value) {
  2005. var data = this.__data__,
  2006. index = assocIndexOf(data, key);
  2007. if (index < 0) {
  2008. ++this.size;
  2009. data.push([key, value]);
  2010. } else {
  2011. data[index][1] = value;
  2012. }
  2013. return this;
  2014. }
  2015. // Add methods to `ListCache`.
  2016. ListCache.prototype.clear = listCacheClear;
  2017. ListCache.prototype['delete'] = listCacheDelete;
  2018. ListCache.prototype.get = listCacheGet;
  2019. ListCache.prototype.has = listCacheHas;
  2020. ListCache.prototype.set = listCacheSet;
  2021. /**
  2022. * Creates a map cache object to store key-value pairs.
  2023. *
  2024. * @private
  2025. * @constructor
  2026. * @param {Array} [entries] The key-value pairs to cache.
  2027. */
  2028. function MapCache(entries) {
  2029. var index = -1,
  2030. length = entries == null ? 0 : entries.length;
  2031. this.clear();
  2032. while (++index < length) {
  2033. var entry = entries[index];
  2034. this.set(entry[0], entry[1]);
  2035. }
  2036. }
  2037. /**
  2038. * Removes all key-value entries from the map.
  2039. *
  2040. * @private
  2041. * @name clear
  2042. * @memberOf MapCache
  2043. */
  2044. function mapCacheClear() {
  2045. this.size = 0;
  2046. this.__data__ = {
  2047. 'hash': new Hash,
  2048. 'map': new (Map || ListCache),
  2049. 'string': new Hash
  2050. };
  2051. }
  2052. /**
  2053. * Removes `key` and its value from the map.
  2054. *
  2055. * @private
  2056. * @name delete
  2057. * @memberOf MapCache
  2058. * @param {string} key The key of the value to remove.
  2059. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2060. */
  2061. function mapCacheDelete(key) {
  2062. var result = getMapData(this, key)['delete'](key);
  2063. this.size -= result ? 1 : 0;
  2064. return result;
  2065. }
  2066. /**
  2067. * Gets the map value for `key`.
  2068. *
  2069. * @private
  2070. * @name get
  2071. * @memberOf MapCache
  2072. * @param {string} key The key of the value to get.
  2073. * @returns {*} Returns the entry value.
  2074. */
  2075. function mapCacheGet(key) {
  2076. return getMapData(this, key).get(key);
  2077. }
  2078. /**
  2079. * Checks if a map value for `key` exists.
  2080. *
  2081. * @private
  2082. * @name has
  2083. * @memberOf MapCache
  2084. * @param {string} key The key of the entry to check.
  2085. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2086. */
  2087. function mapCacheHas(key) {
  2088. return getMapData(this, key).has(key);
  2089. }
  2090. /**
  2091. * Sets the map `key` to `value`.
  2092. *
  2093. * @private
  2094. * @name set
  2095. * @memberOf MapCache
  2096. * @param {string} key The key of the value to set.
  2097. * @param {*} value The value to set.
  2098. * @returns {Object} Returns the map cache instance.
  2099. */
  2100. function mapCacheSet(key, value) {
  2101. var data = getMapData(this, key),
  2102. size = data.size;
  2103. data.set(key, value);
  2104. this.size += data.size == size ? 0 : 1;
  2105. return this;
  2106. }
  2107. // Add methods to `MapCache`.
  2108. MapCache.prototype.clear = mapCacheClear;
  2109. MapCache.prototype['delete'] = mapCacheDelete;
  2110. MapCache.prototype.get = mapCacheGet;
  2111. MapCache.prototype.has = mapCacheHas;
  2112. MapCache.prototype.set = mapCacheSet;
  2113. /**
  2114. *
  2115. * Creates an array cache object to store unique values.
  2116. *
  2117. * @private
  2118. * @constructor
  2119. * @param {Array} [values] The values to cache.
  2120. */
  2121. function SetCache(values) {
  2122. var index = -1,
  2123. length = values == null ? 0 : values.length;
  2124. this.__data__ = new MapCache;
  2125. while (++index < length) {
  2126. this.add(values[index]);
  2127. }
  2128. }
  2129. /**
  2130. * Adds `value` to the array cache.
  2131. *
  2132. * @private
  2133. * @name add
  2134. * @memberOf SetCache
  2135. * @alias push
  2136. * @param {*} value The value to cache.
  2137. * @returns {Object} Returns the cache instance.
  2138. */
  2139. function setCacheAdd(value) {
  2140. this.__data__.set(value, HASH_UNDEFINED);
  2141. return this;
  2142. }
  2143. /**
  2144. * Checks if `value` is in the array cache.
  2145. *
  2146. * @private
  2147. * @name has
  2148. * @memberOf SetCache
  2149. * @param {*} value The value to search for.
  2150. * @returns {number} Returns `true` if `value` is found, else `false`.
  2151. */
  2152. function setCacheHas(value) {
  2153. return this.__data__.has(value);
  2154. }
  2155. // Add methods to `SetCache`.
  2156. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2157. SetCache.prototype.has = setCacheHas;
  2158. /**
  2159. * Creates a stack cache object to store key-value pairs.
  2160. *
  2161. * @private
  2162. * @constructor
  2163. * @param {Array} [entries] The key-value pairs to cache.
  2164. */
  2165. function Stack(entries) {
  2166. var data = this.__data__ = new ListCache(entries);
  2167. this.size = data.size;
  2168. }
  2169. /**
  2170. * Removes all key-value entries from the stack.
  2171. *
  2172. * @private
  2173. * @name clear
  2174. * @memberOf Stack
  2175. */
  2176. function stackClear() {
  2177. this.__data__ = new ListCache;
  2178. this.size = 0;
  2179. }
  2180. /**
  2181. * Removes `key` and its value from the stack.
  2182. *
  2183. * @private
  2184. * @name delete
  2185. * @memberOf Stack
  2186. * @param {string} key The key of the value to remove.
  2187. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2188. */
  2189. function stackDelete(key) {
  2190. var data = this.__data__,
  2191. result = data['delete'](key);
  2192. this.size = data.size;
  2193. return result;
  2194. }
  2195. /**
  2196. * Gets the stack value for `key`.
  2197. *
  2198. * @private
  2199. * @name get
  2200. * @memberOf Stack
  2201. * @param {string} key The key of the value to get.
  2202. * @returns {*} Returns the entry value.
  2203. */
  2204. function stackGet(key) {
  2205. return this.__data__.get(key);
  2206. }
  2207. /**
  2208. * Checks if a stack value for `key` exists.
  2209. *
  2210. * @private
  2211. * @name has
  2212. * @memberOf Stack
  2213. * @param {string} key The key of the entry to check.
  2214. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2215. */
  2216. function stackHas(key) {
  2217. return this.__data__.has(key);
  2218. }
  2219. /**
  2220. * Sets the stack `key` to `value`.
  2221. *
  2222. * @private
  2223. * @name set
  2224. * @memberOf Stack
  2225. * @param {string} key The key of the value to set.
  2226. * @param {*} value The value to set.
  2227. * @returns {Object} Returns the stack cache instance.
  2228. */
  2229. function stackSet(key, value) {
  2230. var data = this.__data__;
  2231. if (data instanceof ListCache) {
  2232. var pairs = data.__data__;
  2233. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  2234. pairs.push([key, value]);
  2235. this.size = ++data.size;
  2236. return this;
  2237. }
  2238. data = this.__data__ = new MapCache(pairs);
  2239. }
  2240. data.set(key, value);
  2241. this.size = data.size;
  2242. return this;
  2243. }
  2244. // Add methods to `Stack`.
  2245. Stack.prototype.clear = stackClear;
  2246. Stack.prototype['delete'] = stackDelete;
  2247. Stack.prototype.get = stackGet;
  2248. Stack.prototype.has = stackHas;
  2249. Stack.prototype.set = stackSet;
  2250. /**
  2251. * Creates an array of the enumerable property names of the array-like `value`.
  2252. *
  2253. * @private
  2254. * @param {*} value The value to query.
  2255. * @param {boolean} inherited Specify returning inherited property names.
  2256. * @returns {Array} Returns the array of property names.
  2257. */
  2258. function arrayLikeKeys(value, inherited) {
  2259. var isArr = isArray(value),
  2260. isArg = !isArr && isArguments(value),
  2261. isBuff = !isArr && !isArg && isBuffer(value),
  2262. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  2263. skipIndexes = isArr || isArg || isBuff || isType,
  2264. result = skipIndexes ? baseTimes(value.length, String) : [],
  2265. length = result.length;
  2266. for (var key in value) {
  2267. if ((inherited || hasOwnProperty.call(value, key)) &&
  2268. !(skipIndexes && (
  2269. // Safari 9 has enumerable `arguments.length` in strict mode.
  2270. key == 'length' ||
  2271. // Node.js 0.10 has enumerable non-index properties on buffers.
  2272. (isBuff && (key == 'offset' || key == 'parent')) ||
  2273. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  2274. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  2275. // Skip index properties.
  2276. isIndex(key, length)
  2277. ))) {
  2278. result.push(key);
  2279. }
  2280. }
  2281. return result;
  2282. }
  2283. /**
  2284. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2285. *
  2286. * @private
  2287. * @param {Array} array The array to inspect.
  2288. * @param {*} key The key to search for.
  2289. * @returns {number} Returns the index of the matched value, else `-1`.
  2290. */
  2291. function assocIndexOf(array, key) {
  2292. var length = array.length;
  2293. while (length--) {
  2294. if (eq(array[length][0], key)) {
  2295. return length;
  2296. }
  2297. }
  2298. return -1;
  2299. }
  2300. /**
  2301. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2302. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2303. * symbols of `object`.
  2304. *
  2305. * @private
  2306. * @param {Object} object The object to query.
  2307. * @param {Function} keysFunc The function to get the keys of `object`.
  2308. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2309. * @returns {Array} Returns the array of property names and symbols.
  2310. */
  2311. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2312. var result = keysFunc(object);
  2313. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2314. }
  2315. /**
  2316. * The base implementation of `getTag` without fallbacks for buggy environments.
  2317. *
  2318. * @private
  2319. * @param {*} value The value to query.
  2320. * @returns {string} Returns the `toStringTag`.
  2321. */
  2322. function baseGetTag(value) {
  2323. if (value == null) {
  2324. return value === undefined ? undefinedTag : nullTag;
  2325. }
  2326. return (symToStringTag && symToStringTag in Object(value))
  2327. ? getRawTag(value)
  2328. : objectToString(value);
  2329. }
  2330. /**
  2331. * The base implementation of `_.isArguments`.
  2332. *
  2333. * @private
  2334. * @param {*} value The value to check.
  2335. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2336. */
  2337. function baseIsArguments(value) {
  2338. return isObjectLike(value) && baseGetTag(value) == argsTag;
  2339. }
  2340. /**
  2341. * The base implementation of `_.isEqual` which supports partial comparisons
  2342. * and tracks traversed objects.
  2343. *
  2344. * @private
  2345. * @param {*} value The value to compare.
  2346. * @param {*} other The other value to compare.
  2347. * @param {boolean} bitmask The bitmask flags.
  2348. * 1 - Unordered comparison
  2349. * 2 - Partial comparison
  2350. * @param {Function} [customizer] The function to customize comparisons.
  2351. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  2352. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2353. */
  2354. function baseIsEqual(value, other, bitmask, customizer, stack) {
  2355. if (value === other) {
  2356. return true;
  2357. }
  2358. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  2359. return value !== value && other !== other;
  2360. }
  2361. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  2362. }
  2363. /**
  2364. * A specialized version of `baseIsEqual` for arrays and objects which performs
  2365. * deep comparisons and tracks traversed objects enabling objects with circular
  2366. * references to be compared.
  2367. *
  2368. * @private
  2369. * @param {Object} object The object to compare.
  2370. * @param {Object} other The other object to compare.
  2371. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  2372. * @param {Function} customizer The function to customize comparisons.
  2373. * @param {Function} equalFunc The function to determine equivalents of values.
  2374. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  2375. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2376. */
  2377. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  2378. var objIsArr = isArray(object),
  2379. othIsArr = isArray(other),
  2380. objTag = objIsArr ? arrayTag : getTag(object),
  2381. othTag = othIsArr ? arrayTag : getTag(other);
  2382. objTag = objTag == argsTag ? objectTag : objTag;
  2383. othTag = othTag == argsTag ? objectTag : othTag;
  2384. var objIsObj = objTag == objectTag,
  2385. othIsObj = othTag == objectTag,
  2386. isSameTag = objTag == othTag;
  2387. if (isSameTag && isBuffer(object)) {
  2388. if (!isBuffer(other)) {
  2389. return false;
  2390. }
  2391. objIsArr = true;
  2392. objIsObj = false;
  2393. }
  2394. if (isSameTag && !objIsObj) {
  2395. stack || (stack = new Stack);
  2396. return (objIsArr || isTypedArray(object))
  2397. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  2398. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  2399. }
  2400. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  2401. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  2402. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  2403. if (objIsWrapped || othIsWrapped) {
  2404. var objUnwrapped = objIsWrapped ? object.value() : object,
  2405. othUnwrapped = othIsWrapped ? other.value() : other;
  2406. stack || (stack = new Stack);
  2407. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  2408. }
  2409. }
  2410. if (!isSameTag) {
  2411. return false;
  2412. }
  2413. stack || (stack = new Stack);
  2414. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  2415. }
  2416. /**
  2417. * The base implementation of `_.isNative` without bad shim checks.
  2418. *
  2419. * @private
  2420. * @param {*} value The value to check.
  2421. * @returns {boolean} Returns `true` if `value` is a native function,
  2422. * else `false`.
  2423. */
  2424. function baseIsNative(value) {
  2425. if (!isObject(value) || isMasked(value)) {
  2426. return false;
  2427. }
  2428. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  2429. return pattern.test(toSource(value));
  2430. }
  2431. /**
  2432. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  2433. *
  2434. * @private
  2435. * @param {*} value The value to check.
  2436. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  2437. */
  2438. function baseIsTypedArray(value) {
  2439. return isObjectLike(value) &&
  2440. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  2441. }
  2442. /**
  2443. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  2444. *
  2445. * @private
  2446. * @param {Object} object The object to query.
  2447. * @returns {Array} Returns the array of property names.
  2448. */
  2449. function baseKeys(object) {
  2450. if (!isPrototype(object)) {
  2451. return nativeKeys(object);
  2452. }
  2453. var result = [];
  2454. for (var key in Object(object)) {
  2455. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  2456. result.push(key);
  2457. }
  2458. }
  2459. return result;
  2460. }
  2461. /**
  2462. * A specialized version of `baseIsEqualDeep` for arrays with support for
  2463. * partial deep comparisons.
  2464. *
  2465. * @private
  2466. * @param {Array} array The array to compare.
  2467. * @param {Array} other The other array to compare.
  2468. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  2469. * @param {Function} customizer The function to customize comparisons.
  2470. * @param {Function} equalFunc The function to determine equivalents of values.
  2471. * @param {Object} stack Tracks traversed `array` and `other` objects.
  2472. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  2473. */
  2474. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  2475. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  2476. arrLength = array.length,
  2477. othLength = other.length;
  2478. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  2479. return false;
  2480. }
  2481. // Assume cyclic values are equal.
  2482. var stacked = stack.get(array);
  2483. if (stacked && stack.get(other)) {
  2484. return stacked == other;
  2485. }
  2486. var index = -1,
  2487. result = true,
  2488. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  2489. stack.set(array, other);
  2490. stack.set(other, array);
  2491. // Ignore non-index properties.
  2492. while (++index < arrLength) {
  2493. var arrValue = array[index],
  2494. othValue = other[index];
  2495. if (customizer) {
  2496. var compared = isPartial
  2497. ? customizer(othValue, arrValue, index, other, array, stack)
  2498. : customizer(arrValue, othValue, index, array, other, stack);
  2499. }
  2500. if (compared !== undefined) {
  2501. if (compared) {
  2502. continue;
  2503. }
  2504. result = false;
  2505. break;
  2506. }
  2507. // Recursively compare arrays (susceptible to call stack limits).
  2508. if (seen) {
  2509. if (!arraySome(other, function(othValue, othIndex) {
  2510. if (!cacheHas(seen, othIndex) &&
  2511. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  2512. return seen.push(othIndex);
  2513. }
  2514. })) {
  2515. result = false;
  2516. break;
  2517. }
  2518. } else if (!(
  2519. arrValue === othValue ||
  2520. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  2521. )) {
  2522. result = false;
  2523. break;
  2524. }
  2525. }
  2526. stack['delete'](array);
  2527. stack['delete'](other);
  2528. return result;
  2529. }
  2530. /**
  2531. * A specialized version of `baseIsEqualDeep` for comparing objects of
  2532. * the same `toStringTag`.
  2533. *
  2534. * **Note:** This function only supports comparing values with tags of
  2535. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  2536. *
  2537. * @private
  2538. * @param {Object} object The object to compare.
  2539. * @param {Object} other The other object to compare.
  2540. * @param {string} tag The `toStringTag` of the objects to compare.
  2541. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  2542. * @param {Function} customizer The function to customize comparisons.
  2543. * @param {Function} equalFunc The function to determine equivalents of values.
  2544. * @param {Object} stack Tracks traversed `object` and `other` objects.
  2545. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2546. */
  2547. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  2548. switch (tag) {
  2549. case dataViewTag:
  2550. if ((object.byteLength != other.byteLength) ||
  2551. (object.byteOffset != other.byteOffset)) {
  2552. return false;
  2553. }
  2554. object = object.buffer;
  2555. other = other.buffer;
  2556. case arrayBufferTag:
  2557. if ((object.byteLength != other.byteLength) ||
  2558. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  2559. return false;
  2560. }
  2561. return true;
  2562. case boolTag:
  2563. case dateTag:
  2564. case numberTag:
  2565. // Coerce booleans to `1` or `0` and dates to milliseconds.
  2566. // Invalid dates are coerced to `NaN`.
  2567. return eq(+object, +other);
  2568. case errorTag:
  2569. return object.name == other.name && object.message == other.message;
  2570. case regexpTag:
  2571. case stringTag:
  2572. // Coerce regexes to strings and treat strings, primitives and objects,
  2573. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  2574. // for more details.
  2575. return object == (other + '');
  2576. case mapTag:
  2577. var convert = mapToArray;
  2578. case setTag:
  2579. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  2580. convert || (convert = setToArray);
  2581. if (object.size != other.size && !isPartial) {
  2582. return false;
  2583. }
  2584. // Assume cyclic values are equal.
  2585. var stacked = stack.get(object);
  2586. if (stacked) {
  2587. return stacked == other;
  2588. }
  2589. bitmask |= COMPARE_UNORDERED_FLAG;
  2590. // Recursively compare objects (susceptible to call stack limits).
  2591. stack.set(object, other);
  2592. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  2593. stack['delete'](object);
  2594. return result;
  2595. case symbolTag:
  2596. if (symbolValueOf) {
  2597. return symbolValueOf.call(object) == symbolValueOf.call(other);
  2598. }
  2599. }
  2600. return false;
  2601. }
  2602. /**
  2603. * A specialized version of `baseIsEqualDeep` for objects with support for
  2604. * partial deep comparisons.
  2605. *
  2606. * @private
  2607. * @param {Object} object The object to compare.
  2608. * @param {Object} other The other object to compare.
  2609. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  2610. * @param {Function} customizer The function to customize comparisons.
  2611. * @param {Function} equalFunc The function to determine equivalents of values.
  2612. * @param {Object} stack Tracks traversed `object` and `other` objects.
  2613. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2614. */
  2615. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  2616. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  2617. objProps = getAllKeys(object),
  2618. objLength = objProps.length,
  2619. othProps = getAllKeys(other),
  2620. othLength = othProps.length;
  2621. if (objLength != othLength && !isPartial) {
  2622. return false;
  2623. }
  2624. var index = objLength;
  2625. while (index--) {
  2626. var key = objProps[index];
  2627. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  2628. return false;
  2629. }
  2630. }
  2631. // Assume cyclic values are equal.
  2632. var stacked = stack.get(object);
  2633. if (stacked && stack.get(other)) {
  2634. return stacked == other;
  2635. }
  2636. var result = true;
  2637. stack.set(object, other);
  2638. stack.set(other, object);
  2639. var skipCtor = isPartial;
  2640. while (++index < objLength) {
  2641. key = objProps[index];
  2642. var objValue = object[key],
  2643. othValue = other[key];
  2644. if (customizer) {
  2645. var compared = isPartial
  2646. ? customizer(othValue, objValue, key, other, object, stack)
  2647. : customizer(objValue, othValue, key, object, other, stack);
  2648. }
  2649. // Recursively compare objects (susceptible to call stack limits).
  2650. if (!(compared === undefined
  2651. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  2652. : compared
  2653. )) {
  2654. result = false;
  2655. break;
  2656. }
  2657. skipCtor || (skipCtor = key == 'constructor');
  2658. }
  2659. if (result && !skipCtor) {
  2660. var objCtor = object.constructor,
  2661. othCtor = other.constructor;
  2662. // Non `Object` object instances with different constructors are not equal.
  2663. if (objCtor != othCtor &&
  2664. ('constructor' in object && 'constructor' in other) &&
  2665. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  2666. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  2667. result = false;
  2668. }
  2669. }
  2670. stack['delete'](object);
  2671. stack['delete'](other);
  2672. return result;
  2673. }
  2674. /**
  2675. * Creates an array of own enumerable property names and symbols of `object`.
  2676. *
  2677. * @private
  2678. * @param {Object} object The object to query.
  2679. * @returns {Array} Returns the array of property names and symbols.
  2680. */
  2681. function getAllKeys(object) {
  2682. return baseGetAllKeys(object, keys, getSymbols);
  2683. }
  2684. /**
  2685. * Gets the data for `map`.
  2686. *
  2687. * @private
  2688. * @param {Object} map The map to query.
  2689. * @param {string} key The reference key.
  2690. * @returns {*} Returns the map data.
  2691. */
  2692. function getMapData(map, key) {
  2693. var data = map.__data__;
  2694. return isKeyable(key)
  2695. ? data[typeof key == 'string' ? 'string' : 'hash']
  2696. : data.map;
  2697. }
  2698. /**
  2699. * Gets the native function at `key` of `object`.
  2700. *
  2701. * @private
  2702. * @param {Object} object The object to query.
  2703. * @param {string} key The key of the method to get.
  2704. * @returns {*} Returns the function if it's native, else `undefined`.
  2705. */
  2706. function getNative(object, key) {
  2707. var value = getValue(object, key);
  2708. return baseIsNative(value) ? value : undefined;
  2709. }
  2710. /**
  2711. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  2712. *
  2713. * @private
  2714. * @param {*} value The value to query.
  2715. * @returns {string} Returns the raw `toStringTag`.
  2716. */
  2717. function getRawTag(value) {
  2718. var isOwn = hasOwnProperty.call(value, symToStringTag),
  2719. tag = value[symToStringTag];
  2720. try {
  2721. value[symToStringTag] = undefined;
  2722. var unmasked = true;
  2723. } catch (e) {}
  2724. var result = nativeObjectToString.call(value);
  2725. if (unmasked) {
  2726. if (isOwn) {
  2727. value[symToStringTag] = tag;
  2728. } else {
  2729. delete value[symToStringTag];
  2730. }
  2731. }
  2732. return result;
  2733. }
  2734. /**
  2735. * Creates an array of the own enumerable symbols of `object`.
  2736. *
  2737. * @private
  2738. * @param {Object} object The object to query.
  2739. * @returns {Array} Returns the array of symbols.
  2740. */
  2741. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  2742. if (object == null) {
  2743. return [];
  2744. }
  2745. object = Object(object);
  2746. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  2747. return propertyIsEnumerable.call(object, symbol);
  2748. });
  2749. };
  2750. /**
  2751. * Gets the `toStringTag` of `value`.
  2752. *
  2753. * @private
  2754. * @param {*} value The value to query.
  2755. * @returns {string} Returns the `toStringTag`.
  2756. */
  2757. var getTag = baseGetTag;
  2758. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  2759. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  2760. (Map && getTag(new Map) != mapTag) ||
  2761. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  2762. (Set && getTag(new Set) != setTag) ||
  2763. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  2764. getTag = function(value) {
  2765. var result = baseGetTag(value),
  2766. Ctor = result == objectTag ? value.constructor : undefined,
  2767. ctorString = Ctor ? toSource(Ctor) : '';
  2768. if (ctorString) {
  2769. switch (ctorString) {
  2770. case dataViewCtorString: return dataViewTag;
  2771. case mapCtorString: return mapTag;
  2772. case promiseCtorString: return promiseTag;
  2773. case setCtorString: return setTag;
  2774. case weakMapCtorString: return weakMapTag;
  2775. }
  2776. }
  2777. return result;
  2778. };
  2779. }
  2780. /**
  2781. * Checks if `value` is a valid array-like index.
  2782. *
  2783. * @private
  2784. * @param {*} value The value to check.
  2785. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  2786. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  2787. */
  2788. function isIndex(value, length) {
  2789. length = length == null ? MAX_SAFE_INTEGER : length;
  2790. return !!length &&
  2791. (typeof value == 'number' || reIsUint.test(value)) &&
  2792. (value > -1 && value % 1 == 0 && value < length);
  2793. }
  2794. /**
  2795. * Checks if `value` is suitable for use as unique object key.
  2796. *
  2797. * @private
  2798. * @param {*} value The value to check.
  2799. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  2800. */
  2801. function isKeyable(value) {
  2802. var type = typeof value;
  2803. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  2804. ? (value !== '__proto__')
  2805. : (value === null);
  2806. }
  2807. /**
  2808. * Checks if `func` has its source masked.
  2809. *
  2810. * @private
  2811. * @param {Function} func The function to check.
  2812. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  2813. */
  2814. function isMasked(func) {
  2815. return !!maskSrcKey && (maskSrcKey in func);
  2816. }
  2817. /**
  2818. * Checks if `value` is likely a prototype object.
  2819. *
  2820. * @private
  2821. * @param {*} value The value to check.
  2822. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  2823. */
  2824. function isPrototype(value) {
  2825. var Ctor = value && value.constructor,
  2826. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  2827. return value === proto;
  2828. }
  2829. /**
  2830. * Converts `value` to a string using `Object.prototype.toString`.
  2831. *
  2832. * @private
  2833. * @param {*} value The value to convert.
  2834. * @returns {string} Returns the converted string.
  2835. */
  2836. function objectToString(value) {
  2837. return nativeObjectToString.call(value);
  2838. }
  2839. /**
  2840. * Converts `func` to its source code.
  2841. *
  2842. * @private
  2843. * @param {Function} func The function to convert.
  2844. * @returns {string} Returns the source code.
  2845. */
  2846. function toSource(func) {
  2847. if (func != null) {
  2848. try {
  2849. return funcToString.call(func);
  2850. } catch (e) {}
  2851. try {
  2852. return (func + '');
  2853. } catch (e) {}
  2854. }
  2855. return '';
  2856. }
  2857. /**
  2858. * Performs a
  2859. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2860. * comparison between two values to determine if they are equivalent.
  2861. *
  2862. * @static
  2863. * @memberOf _
  2864. * @since 4.0.0
  2865. * @category Lang
  2866. * @param {*} value The value to compare.
  2867. * @param {*} other The other value to compare.
  2868. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2869. * @example
  2870. *
  2871. * var object = { 'a': 1 };
  2872. * var other = { 'a': 1 };
  2873. *
  2874. * _.eq(object, object);
  2875. * // => true
  2876. *
  2877. * _.eq(object, other);
  2878. * // => false
  2879. *
  2880. * _.eq('a', 'a');
  2881. * // => true
  2882. *
  2883. * _.eq('a', Object('a'));
  2884. * // => false
  2885. *
  2886. * _.eq(NaN, NaN);
  2887. * // => true
  2888. */
  2889. function eq(value, other) {
  2890. return value === other || (value !== value && other !== other);
  2891. }
  2892. /**
  2893. * Checks if `value` is likely an `arguments` object.
  2894. *
  2895. * @static
  2896. * @memberOf _
  2897. * @since 0.1.0
  2898. * @category Lang
  2899. * @param {*} value The value to check.
  2900. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2901. * else `false`.
  2902. * @example
  2903. *
  2904. * _.isArguments(function() { return arguments; }());
  2905. * // => true
  2906. *
  2907. * _.isArguments([1, 2, 3]);
  2908. * // => false
  2909. */
  2910. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  2911. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  2912. !propertyIsEnumerable.call(value, 'callee');
  2913. };
  2914. /**
  2915. * Checks if `value` is classified as an `Array` object.
  2916. *
  2917. * @static
  2918. * @memberOf _
  2919. * @since 0.1.0
  2920. * @category Lang
  2921. * @param {*} value The value to check.
  2922. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  2923. * @example
  2924. *
  2925. * _.isArray([1, 2, 3]);
  2926. * // => true
  2927. *
  2928. * _.isArray(document.body.children);
  2929. * // => false
  2930. *
  2931. * _.isArray('abc');
  2932. * // => false
  2933. *
  2934. * _.isArray(_.noop);
  2935. * // => false
  2936. */
  2937. var isArray = Array.isArray;
  2938. /**
  2939. * Checks if `value` is array-like. A value is considered array-like if it's
  2940. * not a function and has a `value.length` that's an integer greater than or
  2941. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  2942. *
  2943. * @static
  2944. * @memberOf _
  2945. * @since 4.0.0
  2946. * @category Lang
  2947. * @param {*} value The value to check.
  2948. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  2949. * @example
  2950. *
  2951. * _.isArrayLike([1, 2, 3]);
  2952. * // => true
  2953. *
  2954. * _.isArrayLike(document.body.children);
  2955. * // => true
  2956. *
  2957. * _.isArrayLike('abc');
  2958. * // => true
  2959. *
  2960. * _.isArrayLike(_.noop);
  2961. * // => false
  2962. */
  2963. function isArrayLike(value) {
  2964. return value != null && isLength(value.length) && !isFunction(value);
  2965. }
  2966. /**
  2967. * Checks if `value` is a buffer.
  2968. *
  2969. * @static
  2970. * @memberOf _
  2971. * @since 4.3.0
  2972. * @category Lang
  2973. * @param {*} value The value to check.
  2974. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  2975. * @example
  2976. *
  2977. * _.isBuffer(new Buffer(2));
  2978. * // => true
  2979. *
  2980. * _.isBuffer(new Uint8Array(2));
  2981. * // => false
  2982. */
  2983. var isBuffer = nativeIsBuffer || stubFalse;
  2984. /**
  2985. * Performs a deep comparison between two values to determine if they are
  2986. * equivalent.
  2987. *
  2988. * **Note:** This method supports comparing arrays, array buffers, booleans,
  2989. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  2990. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  2991. * by their own, not inherited, enumerable properties. Functions and DOM
  2992. * nodes are compared by strict equality, i.e. `===`.
  2993. *
  2994. * @static
  2995. * @memberOf _
  2996. * @since 0.1.0
  2997. * @category Lang
  2998. * @param {*} value The value to compare.
  2999. * @param {*} other The other value to compare.
  3000. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  3001. * @example
  3002. *
  3003. * var object = { 'a': 1 };
  3004. * var other = { 'a': 1 };
  3005. *
  3006. * _.isEqual(object, other);
  3007. * // => true
  3008. *
  3009. * object === other;
  3010. * // => false
  3011. */
  3012. function isEqual(value, other) {
  3013. return baseIsEqual(value, other);
  3014. }
  3015. /**
  3016. * Checks if `value` is classified as a `Function` object.
  3017. *
  3018. * @static
  3019. * @memberOf _
  3020. * @since 0.1.0
  3021. * @category Lang
  3022. * @param {*} value The value to check.
  3023. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  3024. * @example
  3025. *
  3026. * _.isFunction(_);
  3027. * // => true
  3028. *
  3029. * _.isFunction(/abc/);
  3030. * // => false
  3031. */
  3032. function isFunction(value) {
  3033. if (!isObject(value)) {
  3034. return false;
  3035. }
  3036. // The use of `Object#toString` avoids issues with the `typeof` operator
  3037. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  3038. var tag = baseGetTag(value);
  3039. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  3040. }
  3041. /**
  3042. * Checks if `value` is a valid array-like length.
  3043. *
  3044. * **Note:** This method is loosely based on
  3045. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  3046. *
  3047. * @static
  3048. * @memberOf _
  3049. * @since 4.0.0
  3050. * @category Lang
  3051. * @param {*} value The value to check.
  3052. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  3053. * @example
  3054. *
  3055. * _.isLength(3);
  3056. * // => true
  3057. *
  3058. * _.isLength(Number.MIN_VALUE);
  3059. * // => false
  3060. *
  3061. * _.isLength(Infinity);
  3062. * // => false
  3063. *
  3064. * _.isLength('3');
  3065. * // => false
  3066. */
  3067. function isLength(value) {
  3068. return typeof value == 'number' &&
  3069. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  3070. }
  3071. /**
  3072. * Checks if `value` is the
  3073. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  3074. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  3075. *
  3076. * @static
  3077. * @memberOf _
  3078. * @since 0.1.0
  3079. * @category Lang
  3080. * @param {*} value The value to check.
  3081. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  3082. * @example
  3083. *
  3084. * _.isObject({});
  3085. * // => true
  3086. *
  3087. * _.isObject([1, 2, 3]);
  3088. * // => true
  3089. *
  3090. * _.isObject(_.noop);
  3091. * // => true
  3092. *
  3093. * _.isObject(null);
  3094. * // => false
  3095. */
  3096. function isObject(value) {
  3097. var type = typeof value;
  3098. return value != null && (type == 'object' || type == 'function');
  3099. }
  3100. /**
  3101. * Checks if `value` is object-like. A value is object-like if it's not `null`
  3102. * and has a `typeof` result of "object".
  3103. *
  3104. * @static
  3105. * @memberOf _
  3106. * @since 4.0.0
  3107. * @category Lang
  3108. * @param {*} value The value to check.
  3109. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  3110. * @example
  3111. *
  3112. * _.isObjectLike({});
  3113. * // => true
  3114. *
  3115. * _.isObjectLike([1, 2, 3]);
  3116. * // => true
  3117. *
  3118. * _.isObjectLike(_.noop);
  3119. * // => false
  3120. *
  3121. * _.isObjectLike(null);
  3122. * // => false
  3123. */
  3124. function isObjectLike(value) {
  3125. return value != null && typeof value == 'object';
  3126. }
  3127. /**
  3128. * Checks if `value` is classified as a typed array.
  3129. *
  3130. * @static
  3131. * @memberOf _
  3132. * @since 3.0.0
  3133. * @category Lang
  3134. * @param {*} value The value to check.
  3135. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3136. * @example
  3137. *
  3138. * _.isTypedArray(new Uint8Array);
  3139. * // => true
  3140. *
  3141. * _.isTypedArray([]);
  3142. * // => false
  3143. */
  3144. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  3145. /**
  3146. * Creates an array of the own enumerable property names of `object`.
  3147. *
  3148. * **Note:** Non-object values are coerced to objects. See the
  3149. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  3150. * for more details.
  3151. *
  3152. * @static
  3153. * @since 0.1.0
  3154. * @memberOf _
  3155. * @category Object
  3156. * @param {Object} object The object to query.
  3157. * @returns {Array} Returns the array of property names.
  3158. * @example
  3159. *
  3160. * function Foo() {
  3161. * this.a = 1;
  3162. * this.b = 2;
  3163. * }
  3164. *
  3165. * Foo.prototype.c = 3;
  3166. *
  3167. * _.keys(new Foo);
  3168. * // => ['a', 'b'] (iteration order is not guaranteed)
  3169. *
  3170. * _.keys('hi');
  3171. * // => ['0', '1']
  3172. */
  3173. function keys(object) {
  3174. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  3175. }
  3176. /**
  3177. * This method returns a new empty array.
  3178. *
  3179. * @static
  3180. * @memberOf _
  3181. * @since 4.13.0
  3182. * @category Util
  3183. * @returns {Array} Returns the new empty array.
  3184. * @example
  3185. *
  3186. * var arrays = _.times(2, _.stubArray);
  3187. *
  3188. * console.log(arrays);
  3189. * // => [[], []]
  3190. *
  3191. * console.log(arrays[0] === arrays[1]);
  3192. * // => false
  3193. */
  3194. function stubArray() {
  3195. return [];
  3196. }
  3197. /**
  3198. * This method returns `false`.
  3199. *
  3200. * @static
  3201. * @memberOf _
  3202. * @since 4.13.0
  3203. * @category Util
  3204. * @returns {boolean} Returns `false`.
  3205. * @example
  3206. *
  3207. * _.times(2, _.stubFalse);
  3208. * // => [false, false]
  3209. */
  3210. function stubFalse() {
  3211. return false;
  3212. }
  3213. module.exports = isEqual;
  3214. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3215. },{}],17:[function(require,module,exports){
  3216. (function (process){
  3217. // Copyright Joyent, Inc. and other Node contributors.
  3218. //
  3219. // Permission is hereby granted, free of charge, to any person obtaining a
  3220. // copy of this software and associated documentation files (the
  3221. // "Software"), to deal in the Software without restriction, including
  3222. // without limitation the rights to use, copy, modify, merge, publish,
  3223. // distribute, sublicense, and/or sell copies of the Software, and to permit
  3224. // persons to whom the Software is furnished to do so, subject to the
  3225. // following conditions:
  3226. //
  3227. // The above copyright notice and this permission notice shall be included
  3228. // in all copies or substantial portions of the Software.
  3229. //
  3230. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  3231. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3232. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  3233. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  3234. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  3235. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  3236. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  3237. // resolves . and .. elements in a path array with directory names there
  3238. // must be no slashes, empty elements, or device names (c:\) in the array
  3239. // (so also no leading and trailing slashes - it does not distinguish
  3240. // relative and absolute paths)
  3241. function normalizeArray(parts, allowAboveRoot) {
  3242. // if the path tries to go above the root, `up` ends up > 0
  3243. var up = 0;
  3244. for (var i = parts.length - 1; i >= 0; i--) {
  3245. var last = parts[i];
  3246. if (last === '.') {
  3247. parts.splice(i, 1);
  3248. } else if (last === '..') {
  3249. parts.splice(i, 1);
  3250. up++;
  3251. } else if (up) {
  3252. parts.splice(i, 1);
  3253. up--;
  3254. }
  3255. }
  3256. // if the path is allowed to go above the root, restore leading ..s
  3257. if (allowAboveRoot) {
  3258. for (; up--; up) {
  3259. parts.unshift('..');
  3260. }
  3261. }
  3262. return parts;
  3263. }
  3264. // Split a filename into [root, dir, basename, ext], unix version
  3265. // 'root' is just a slash, or nothing.
  3266. var splitPathRe =
  3267. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  3268. var splitPath = function(filename) {
  3269. return splitPathRe.exec(filename).slice(1);
  3270. };
  3271. // path.resolve([from ...], to)
  3272. // posix version
  3273. exports.resolve = function() {
  3274. var resolvedPath = '',
  3275. resolvedAbsolute = false;
  3276. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  3277. var path = (i >= 0) ? arguments[i] : process.cwd();
  3278. // Skip empty and invalid entries
  3279. if (typeof path !== 'string') {
  3280. throw new TypeError('Arguments to path.resolve must be strings');
  3281. } else if (!path) {
  3282. continue;
  3283. }
  3284. resolvedPath = path + '/' + resolvedPath;
  3285. resolvedAbsolute = path.charAt(0) === '/';
  3286. }
  3287. // At this point the path should be resolved to a full absolute path, but
  3288. // handle relative paths to be safe (might happen when process.cwd() fails)
  3289. // Normalize the path
  3290. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  3291. return !!p;
  3292. }), !resolvedAbsolute).join('/');
  3293. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  3294. };
  3295. // path.normalize(path)
  3296. // posix version
  3297. exports.normalize = function(path) {
  3298. var isAbsolute = exports.isAbsolute(path),
  3299. trailingSlash = substr(path, -1) === '/';
  3300. // Normalize the path
  3301. path = normalizeArray(filter(path.split('/'), function(p) {
  3302. return !!p;
  3303. }), !isAbsolute).join('/');
  3304. if (!path && !isAbsolute) {
  3305. path = '.';
  3306. }
  3307. if (path && trailingSlash) {
  3308. path += '/';
  3309. }
  3310. return (isAbsolute ? '/' : '') + path;
  3311. };
  3312. // posix version
  3313. exports.isAbsolute = function(path) {
  3314. return path.charAt(0) === '/';
  3315. };
  3316. // posix version
  3317. exports.join = function() {
  3318. var paths = Array.prototype.slice.call(arguments, 0);
  3319. return exports.normalize(filter(paths, function(p, index) {
  3320. if (typeof p !== 'string') {
  3321. throw new TypeError('Arguments to path.join must be strings');
  3322. }
  3323. return p;
  3324. }).join('/'));
  3325. };
  3326. // path.relative(from, to)
  3327. // posix version
  3328. exports.relative = function(from, to) {
  3329. from = exports.resolve(from).substr(1);
  3330. to = exports.resolve(to).substr(1);
  3331. function trim(arr) {
  3332. var start = 0;
  3333. for (; start < arr.length; start++) {
  3334. if (arr[start] !== '') break;
  3335. }
  3336. var end = arr.length - 1;
  3337. for (; end >= 0; end--) {
  3338. if (arr[end] !== '') break;
  3339. }
  3340. if (start > end) return [];
  3341. return arr.slice(start, end - start + 1);
  3342. }
  3343. var fromParts = trim(from.split('/'));
  3344. var toParts = trim(to.split('/'));
  3345. var length = Math.min(fromParts.length, toParts.length);
  3346. var samePartsLength = length;
  3347. for (var i = 0; i < length; i++) {
  3348. if (fromParts[i] !== toParts[i]) {
  3349. samePartsLength = i;
  3350. break;
  3351. }
  3352. }
  3353. var outputParts = [];
  3354. for (var i = samePartsLength; i < fromParts.length; i++) {
  3355. outputParts.push('..');
  3356. }
  3357. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  3358. return outputParts.join('/');
  3359. };
  3360. exports.sep = '/';
  3361. exports.delimiter = ':';
  3362. exports.dirname = function(path) {
  3363. var result = splitPath(path),
  3364. root = result[0],
  3365. dir = result[1];
  3366. if (!root && !dir) {
  3367. // No dirname whatsoever
  3368. return '.';
  3369. }
  3370. if (dir) {
  3371. // It has a dirname, strip trailing slash
  3372. dir = dir.substr(0, dir.length - 1);
  3373. }
  3374. return root + dir;
  3375. };
  3376. exports.basename = function(path, ext) {
  3377. var f = splitPath(path)[2];
  3378. // TODO: make this comparison case-insensitive on windows?
  3379. if (ext && f.substr(-1 * ext.length) === ext) {
  3380. f = f.substr(0, f.length - ext.length);
  3381. }
  3382. return f;
  3383. };
  3384. exports.extname = function(path) {
  3385. return splitPath(path)[3];
  3386. };
  3387. function filter (xs, f) {
  3388. if (xs.filter) return xs.filter(f);
  3389. var res = [];
  3390. for (var i = 0; i < xs.length; i++) {
  3391. if (f(xs[i], i, xs)) res.push(xs[i]);
  3392. }
  3393. return res;
  3394. }
  3395. // String.prototype.substr - negative index don't work in IE8
  3396. var substr = 'ab'.substr(-1) === 'b'
  3397. ? function (str, start, len) { return str.substr(start, len) }
  3398. : function (str, start, len) {
  3399. if (start < 0) start = str.length + start;
  3400. return str.substr(start, len);
  3401. }
  3402. ;
  3403. }).call(this,require('_process'))
  3404. },{"_process":19}],18:[function(require,module,exports){
  3405. 'use strict';
  3406. module.exports = Point;
  3407. /**
  3408. * A standalone point geometry with useful accessor, comparison, and
  3409. * modification methods.
  3410. *
  3411. * @class Point
  3412. * @param {Number} x the x-coordinate. this could be longitude or screen
  3413. * pixels, or any other sort of unit.
  3414. * @param {Number} y the y-coordinate. this could be latitude or screen
  3415. * pixels, or any other sort of unit.
  3416. * @example
  3417. * var point = new Point(-77, 38);
  3418. */
  3419. function Point(x, y) {
  3420. this.x = x;
  3421. this.y = y;
  3422. }
  3423. Point.prototype = {
  3424. /**
  3425. * Clone this point, returning a new point that can be modified
  3426. * without affecting the old one.
  3427. * @return {Point} the clone
  3428. */
  3429. clone: function() { return new Point(this.x, this.y); },
  3430. /**
  3431. * Add this point's x & y coordinates to another point,
  3432. * yielding a new point.
  3433. * @param {Point} p the other point
  3434. * @return {Point} output point
  3435. */
  3436. add: function(p) { return this.clone()._add(p); },
  3437. /**
  3438. * Subtract this point's x & y coordinates to from point,
  3439. * yielding a new point.
  3440. * @param {Point} p the other point
  3441. * @return {Point} output point
  3442. */
  3443. sub: function(p) { return this.clone()._sub(p); },
  3444. /**
  3445. * Multiply this point's x & y coordinates by point,
  3446. * yielding a new point.
  3447. * @param {Point} p the other point
  3448. * @return {Point} output point
  3449. */
  3450. multByPoint: function(p) { return this.clone()._multByPoint(p); },
  3451. /**
  3452. * Divide this point's x & y coordinates by point,
  3453. * yielding a new point.
  3454. * @param {Point} p the other point
  3455. * @return {Point} output point
  3456. */
  3457. divByPoint: function(p) { return this.clone()._divByPoint(p); },
  3458. /**
  3459. * Multiply this point's x & y coordinates by a factor,
  3460. * yielding a new point.
  3461. * @param {Point} k factor
  3462. * @return {Point} output point
  3463. */
  3464. mult: function(k) { return this.clone()._mult(k); },
  3465. /**
  3466. * Divide this point's x & y coordinates by a factor,
  3467. * yielding a new point.
  3468. * @param {Point} k factor
  3469. * @return {Point} output point
  3470. */
  3471. div: function(k) { return this.clone()._div(k); },
  3472. /**
  3473. * Rotate this point around the 0, 0 origin by an angle a,
  3474. * given in radians
  3475. * @param {Number} a angle to rotate around, in radians
  3476. * @return {Point} output point
  3477. */
  3478. rotate: function(a) { return this.clone()._rotate(a); },
  3479. /**
  3480. * Rotate this point around p point by an angle a,
  3481. * given in radians
  3482. * @param {Number} a angle to rotate around, in radians
  3483. * @param {Point} p Point to rotate around
  3484. * @return {Point} output point
  3485. */
  3486. rotateAround: function(a,p) { return this.clone()._rotateAround(a,p); },
  3487. /**
  3488. * Multiply this point by a 4x1 transformation matrix
  3489. * @param {Array<Number>} m transformation matrix
  3490. * @return {Point} output point
  3491. */
  3492. matMult: function(m) { return this.clone()._matMult(m); },
  3493. /**
  3494. * Calculate this point but as a unit vector from 0, 0, meaning
  3495. * that the distance from the resulting point to the 0, 0
  3496. * coordinate will be equal to 1 and the angle from the resulting
  3497. * point to the 0, 0 coordinate will be the same as before.
  3498. * @return {Point} unit vector point
  3499. */
  3500. unit: function() { return this.clone()._unit(); },
  3501. /**
  3502. * Compute a perpendicular point, where the new y coordinate
  3503. * is the old x coordinate and the new x coordinate is the old y
  3504. * coordinate multiplied by -1
  3505. * @return {Point} perpendicular point
  3506. */
  3507. perp: function() { return this.clone()._perp(); },
  3508. /**
  3509. * Return a version of this point with the x & y coordinates
  3510. * rounded to integers.
  3511. * @return {Point} rounded point
  3512. */
  3513. round: function() { return this.clone()._round(); },
  3514. /**
  3515. * Return the magitude of this point: this is the Euclidean
  3516. * distance from the 0, 0 coordinate to this point's x and y
  3517. * coordinates.
  3518. * @return {Number} magnitude
  3519. */
  3520. mag: function() {
  3521. return Math.sqrt(this.x * this.x + this.y * this.y);
  3522. },
  3523. /**
  3524. * Judge whether this point is equal to another point, returning
  3525. * true or false.
  3526. * @param {Point} other the other point
  3527. * @return {boolean} whether the points are equal
  3528. */
  3529. equals: function(other) {
  3530. return this.x === other.x &&
  3531. this.y === other.y;
  3532. },
  3533. /**
  3534. * Calculate the distance from this point to another point
  3535. * @param {Point} p the other point
  3536. * @return {Number} distance
  3537. */
  3538. dist: function(p) {
  3539. return Math.sqrt(this.distSqr(p));
  3540. },
  3541. /**
  3542. * Calculate the distance from this point to another point,
  3543. * without the square root step. Useful if you're comparing
  3544. * relative distances.
  3545. * @param {Point} p the other point
  3546. * @return {Number} distance
  3547. */
  3548. distSqr: function(p) {
  3549. var dx = p.x - this.x,
  3550. dy = p.y - this.y;
  3551. return dx * dx + dy * dy;
  3552. },
  3553. /**
  3554. * Get the angle from the 0, 0 coordinate to this point, in radians
  3555. * coordinates.
  3556. * @return {Number} angle
  3557. */
  3558. angle: function() {
  3559. return Math.atan2(this.y, this.x);
  3560. },
  3561. /**
  3562. * Get the angle from this point to another point, in radians
  3563. * @param {Point} b the other point
  3564. * @return {Number} angle
  3565. */
  3566. angleTo: function(b) {
  3567. return Math.atan2(this.y - b.y, this.x - b.x);
  3568. },
  3569. /**
  3570. * Get the angle between this point and another point, in radians
  3571. * @param {Point} b the other point
  3572. * @return {Number} angle
  3573. */
  3574. angleWith: function(b) {
  3575. return this.angleWithSep(b.x, b.y);
  3576. },
  3577. /*
  3578. * Find the angle of the two vectors, solving the formula for
  3579. * the cross product a x b = |a||b|sin(θ) for θ.
  3580. * @param {Number} x the x-coordinate
  3581. * @param {Number} y the y-coordinate
  3582. * @return {Number} the angle in radians
  3583. */
  3584. angleWithSep: function(x, y) {
  3585. return Math.atan2(
  3586. this.x * y - this.y * x,
  3587. this.x * x + this.y * y);
  3588. },
  3589. _matMult: function(m) {
  3590. var x = m[0] * this.x + m[1] * this.y,
  3591. y = m[2] * this.x + m[3] * this.y;
  3592. this.x = x;
  3593. this.y = y;
  3594. return this;
  3595. },
  3596. _add: function(p) {
  3597. this.x += p.x;
  3598. this.y += p.y;
  3599. return this;
  3600. },
  3601. _sub: function(p) {
  3602. this.x -= p.x;
  3603. this.y -= p.y;
  3604. return this;
  3605. },
  3606. _mult: function(k) {
  3607. this.x *= k;
  3608. this.y *= k;
  3609. return this;
  3610. },
  3611. _div: function(k) {
  3612. this.x /= k;
  3613. this.y /= k;
  3614. return this;
  3615. },
  3616. _multByPoint: function(p) {
  3617. this.x *= p.x;
  3618. this.y *= p.y;
  3619. return this;
  3620. },
  3621. _divByPoint: function(p) {
  3622. this.x /= p.x;
  3623. this.y /= p.y;
  3624. return this;
  3625. },
  3626. _unit: function() {
  3627. this._div(this.mag());
  3628. return this;
  3629. },
  3630. _perp: function() {
  3631. var y = this.y;
  3632. this.y = this.x;
  3633. this.x = -y;
  3634. return this;
  3635. },
  3636. _rotate: function(angle) {
  3637. var cos = Math.cos(angle),
  3638. sin = Math.sin(angle),
  3639. x = cos * this.x - sin * this.y,
  3640. y = sin * this.x + cos * this.y;
  3641. this.x = x;
  3642. this.y = y;
  3643. return this;
  3644. },
  3645. _rotateAround: function(angle, p) {
  3646. var cos = Math.cos(angle),
  3647. sin = Math.sin(angle),
  3648. x = p.x + cos * (this.x - p.x) - sin * (this.y - p.y),
  3649. y = p.y + sin * (this.x - p.x) + cos * (this.y - p.y);
  3650. this.x = x;
  3651. this.y = y;
  3652. return this;
  3653. },
  3654. _round: function() {
  3655. this.x = Math.round(this.x);
  3656. this.y = Math.round(this.y);
  3657. return this;
  3658. }
  3659. };
  3660. /**
  3661. * Construct a point from an array if necessary, otherwise if the input
  3662. * is already a Point, or an unknown type, return it unchanged
  3663. * @param {Array<Number>|Point|*} a any kind of input value
  3664. * @return {Point} constructed point, or passed-through value.
  3665. * @example
  3666. * // this
  3667. * var point = Point.convert([0, 1]);
  3668. * // is equivalent to
  3669. * var point = new Point(0, 1);
  3670. */
  3671. Point.convert = function (a) {
  3672. if (a instanceof Point) {
  3673. return a;
  3674. }
  3675. if (Array.isArray(a)) {
  3676. return new Point(a[0], a[1]);
  3677. }
  3678. return a;
  3679. };
  3680. },{}],19:[function(require,module,exports){
  3681. // shim for using process in browser
  3682. var process = module.exports = {};
  3683. // cached from whatever global is present so that test runners that stub it
  3684. // don't break things. But we need to wrap it in a try catch in case it is
  3685. // wrapped in strict mode code which doesn't define any globals. It's inside a
  3686. // function because try/catches deoptimize in certain engines.
  3687. var cachedSetTimeout;
  3688. var cachedClearTimeout;
  3689. function defaultSetTimout() {
  3690. throw new Error('setTimeout has not been defined');
  3691. }
  3692. function defaultClearTimeout () {
  3693. throw new Error('clearTimeout has not been defined');
  3694. }
  3695. (function () {
  3696. try {
  3697. if (typeof setTimeout === 'function') {
  3698. cachedSetTimeout = setTimeout;
  3699. } else {
  3700. cachedSetTimeout = defaultSetTimout;
  3701. }
  3702. } catch (e) {
  3703. cachedSetTimeout = defaultSetTimout;
  3704. }
  3705. try {
  3706. if (typeof clearTimeout === 'function') {
  3707. cachedClearTimeout = clearTimeout;
  3708. } else {
  3709. cachedClearTimeout = defaultClearTimeout;
  3710. }
  3711. } catch (e) {
  3712. cachedClearTimeout = defaultClearTimeout;
  3713. }
  3714. } ())
  3715. function runTimeout(fun) {
  3716. if (cachedSetTimeout === setTimeout) {
  3717. //normal enviroments in sane situations
  3718. return setTimeout(fun, 0);
  3719. }
  3720. // if setTimeout wasn't available but was latter defined
  3721. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  3722. cachedSetTimeout = setTimeout;
  3723. return setTimeout(fun, 0);
  3724. }
  3725. try {
  3726. // when when somebody has screwed with setTimeout but no I.E. maddness
  3727. return cachedSetTimeout(fun, 0);
  3728. } catch(e){
  3729. try {
  3730. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  3731. return cachedSetTimeout.call(null, fun, 0);
  3732. } catch(e){
  3733. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  3734. return cachedSetTimeout.call(this, fun, 0);
  3735. }
  3736. }
  3737. }
  3738. function runClearTimeout(marker) {
  3739. if (cachedClearTimeout === clearTimeout) {
  3740. //normal enviroments in sane situations
  3741. return clearTimeout(marker);
  3742. }
  3743. // if clearTimeout wasn't available but was latter defined
  3744. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  3745. cachedClearTimeout = clearTimeout;
  3746. return clearTimeout(marker);
  3747. }
  3748. try {
  3749. // when when somebody has screwed with setTimeout but no I.E. maddness
  3750. return cachedClearTimeout(marker);
  3751. } catch (e){
  3752. try {
  3753. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  3754. return cachedClearTimeout.call(null, marker);
  3755. } catch (e){
  3756. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  3757. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  3758. return cachedClearTimeout.call(this, marker);
  3759. }
  3760. }
  3761. }
  3762. var queue = [];
  3763. var draining = false;
  3764. var currentQueue;
  3765. var queueIndex = -1;
  3766. function cleanUpNextTick() {
  3767. if (!draining || !currentQueue) {
  3768. return;
  3769. }
  3770. draining = false;
  3771. if (currentQueue.length) {
  3772. queue = currentQueue.concat(queue);
  3773. } else {
  3774. queueIndex = -1;
  3775. }
  3776. if (queue.length) {
  3777. drainQueue();
  3778. }
  3779. }
  3780. function drainQueue() {
  3781. if (draining) {
  3782. return;
  3783. }
  3784. var timeout = runTimeout(cleanUpNextTick);
  3785. draining = true;
  3786. var len = queue.length;
  3787. while(len) {
  3788. currentQueue = queue;
  3789. queue = [];
  3790. while (++queueIndex < len) {
  3791. if (currentQueue) {
  3792. currentQueue[queueIndex].run();
  3793. }
  3794. }
  3795. queueIndex = -1;
  3796. len = queue.length;
  3797. }
  3798. currentQueue = null;
  3799. draining = false;
  3800. runClearTimeout(timeout);
  3801. }
  3802. process.nextTick = function (fun) {
  3803. var args = new Array(arguments.length - 1);
  3804. if (arguments.length > 1) {
  3805. for (var i = 1; i < arguments.length; i++) {
  3806. args[i - 1] = arguments[i];
  3807. }
  3808. }
  3809. queue.push(new Item(fun, args));
  3810. if (queue.length === 1 && !draining) {
  3811. runTimeout(drainQueue);
  3812. }
  3813. };
  3814. // v8 likes predictible objects
  3815. function Item(fun, array) {
  3816. this.fun = fun;
  3817. this.array = array;
  3818. }
  3819. Item.prototype.run = function () {
  3820. this.fun.apply(null, this.array);
  3821. };
  3822. process.title = 'browser';
  3823. process.browser = true;
  3824. process.env = {};
  3825. process.argv = [];
  3826. process.version = ''; // empty string to avoid regexp issues
  3827. process.versions = {};
  3828. function noop() {}
  3829. process.on = noop;
  3830. process.addListener = noop;
  3831. process.once = noop;
  3832. process.off = noop;
  3833. process.removeListener = noop;
  3834. process.removeAllListeners = noop;
  3835. process.emit = noop;
  3836. process.prependListener = noop;
  3837. process.prependOnceListener = noop;
  3838. process.listeners = function (name) { return [] }
  3839. process.binding = function (name) {
  3840. throw new Error('process.binding is not supported');
  3841. };
  3842. process.cwd = function () { return '/' };
  3843. process.chdir = function (dir) {
  3844. throw new Error('process.chdir is not supported');
  3845. };
  3846. process.umask = function() { return 0; };
  3847. },{}],20:[function(require,module,exports){
  3848. var traverse = module.exports = function (obj) {
  3849. return new Traverse(obj);
  3850. };
  3851. function Traverse (obj) {
  3852. this.value = obj;
  3853. }
  3854. Traverse.prototype.get = function (ps) {
  3855. var node = this.value;
  3856. for (var i = 0; i < ps.length; i ++) {
  3857. var key = ps[i];
  3858. if (!node || !hasOwnProperty.call(node, key)) {
  3859. node = undefined;
  3860. break;
  3861. }
  3862. node = node[key];
  3863. }
  3864. return node;
  3865. };
  3866. Traverse.prototype.has = function (ps) {
  3867. var node = this.value;
  3868. for (var i = 0; i < ps.length; i ++) {
  3869. var key = ps[i];
  3870. if (!node || !hasOwnProperty.call(node, key)) {
  3871. return false;
  3872. }
  3873. node = node[key];
  3874. }
  3875. return true;
  3876. };
  3877. Traverse.prototype.set = function (ps, value) {
  3878. var node = this.value;
  3879. for (var i = 0; i < ps.length - 1; i ++) {
  3880. var key = ps[i];
  3881. if (!hasOwnProperty.call(node, key)) node[key] = {};
  3882. node = node[key];
  3883. }
  3884. node[ps[i]] = value;
  3885. return value;
  3886. };
  3887. Traverse.prototype.map = function (cb) {
  3888. return walk(this.value, cb, true);
  3889. };
  3890. Traverse.prototype.forEach = function (cb) {
  3891. this.value = walk(this.value, cb, false);
  3892. return this.value;
  3893. };
  3894. Traverse.prototype.reduce = function (cb, init) {
  3895. var skip = arguments.length === 1;
  3896. var acc = skip ? this.value : init;
  3897. this.forEach(function (x) {
  3898. if (!this.isRoot || !skip) {
  3899. acc = cb.call(this, acc, x);
  3900. }
  3901. });
  3902. return acc;
  3903. };
  3904. Traverse.prototype.paths = function () {
  3905. var acc = [];
  3906. this.forEach(function (x) {
  3907. acc.push(this.path);
  3908. });
  3909. return acc;
  3910. };
  3911. Traverse.prototype.nodes = function () {
  3912. var acc = [];
  3913. this.forEach(function (x) {
  3914. acc.push(this.node);
  3915. });
  3916. return acc;
  3917. };
  3918. Traverse.prototype.clone = function () {
  3919. var parents = [], nodes = [];
  3920. return (function clone (src) {
  3921. for (var i = 0; i < parents.length; i++) {
  3922. if (parents[i] === src) {
  3923. return nodes[i];
  3924. }
  3925. }
  3926. if (typeof src === 'object' && src !== null) {
  3927. var dst = copy(src);
  3928. parents.push(src);
  3929. nodes.push(dst);
  3930. forEach(objectKeys(src), function (key) {
  3931. dst[key] = clone(src[key]);
  3932. });
  3933. parents.pop();
  3934. nodes.pop();
  3935. return dst;
  3936. }
  3937. else {
  3938. return src;
  3939. }
  3940. })(this.value);
  3941. };
  3942. function walk (root, cb, immutable) {
  3943. var path = [];
  3944. var parents = [];
  3945. var alive = true;
  3946. return (function walker (node_) {
  3947. var node = immutable ? copy(node_) : node_;
  3948. var modifiers = {};
  3949. var keepGoing = true;
  3950. var state = {
  3951. node : node,
  3952. node_ : node_,
  3953. path : [].concat(path),
  3954. parent : parents[parents.length - 1],
  3955. parents : parents,
  3956. key : path.slice(-1)[0],
  3957. isRoot : path.length === 0,
  3958. level : path.length,
  3959. circular : null,
  3960. update : function (x, stopHere) {
  3961. if (!state.isRoot) {
  3962. state.parent.node[state.key] = x;
  3963. }
  3964. state.node = x;
  3965. if (stopHere) keepGoing = false;
  3966. },
  3967. 'delete' : function (stopHere) {
  3968. delete state.parent.node[state.key];
  3969. if (stopHere) keepGoing = false;
  3970. },
  3971. remove : function (stopHere) {
  3972. if (isArray(state.parent.node)) {
  3973. state.parent.node.splice(state.key, 1);
  3974. }
  3975. else {
  3976. delete state.parent.node[state.key];
  3977. }
  3978. if (stopHere) keepGoing = false;
  3979. },
  3980. keys : null,
  3981. before : function (f) { modifiers.before = f },
  3982. after : function (f) { modifiers.after = f },
  3983. pre : function (f) { modifiers.pre = f },
  3984. post : function (f) { modifiers.post = f },
  3985. stop : function () { alive = false },
  3986. block : function () { keepGoing = false }
  3987. };
  3988. if (!alive) return state;
  3989. function updateState() {
  3990. if (typeof state.node === 'object' && state.node !== null) {
  3991. if (!state.keys || state.node_ !== state.node) {
  3992. state.keys = objectKeys(state.node)
  3993. }
  3994. state.isLeaf = state.keys.length == 0;
  3995. for (var i = 0; i < parents.length; i++) {
  3996. if (parents[i].node_ === node_) {
  3997. state.circular = parents[i];
  3998. break;
  3999. }
  4000. }
  4001. }
  4002. else {
  4003. state.isLeaf = true;
  4004. state.keys = null;
  4005. }
  4006. state.notLeaf = !state.isLeaf;
  4007. state.notRoot = !state.isRoot;
  4008. }
  4009. updateState();
  4010. // use return values to update if defined
  4011. var ret = cb.call(state, state.node);
  4012. if (ret !== undefined && state.update) state.update(ret);
  4013. if (modifiers.before) modifiers.before.call(state, state.node);
  4014. if (!keepGoing) return state;
  4015. if (typeof state.node == 'object'
  4016. && state.node !== null && !state.circular) {
  4017. parents.push(state);
  4018. updateState();
  4019. forEach(state.keys, function (key, i) {
  4020. path.push(key);
  4021. if (modifiers.pre) modifiers.pre.call(state, state.node[key], key);
  4022. var child = walker(state.node[key]);
  4023. if (immutable && hasOwnProperty.call(state.node, key)) {
  4024. state.node[key] = child.node;
  4025. }
  4026. child.isLast = i == state.keys.length - 1;
  4027. child.isFirst = i == 0;
  4028. if (modifiers.post) modifiers.post.call(state, child);
  4029. path.pop();
  4030. });
  4031. parents.pop();
  4032. }
  4033. if (modifiers.after) modifiers.after.call(state, state.node);
  4034. return state;
  4035. })(root).node;
  4036. }
  4037. function copy (src) {
  4038. if (typeof src === 'object' && src !== null) {
  4039. var dst;
  4040. if (isArray(src)) {
  4041. dst = [];
  4042. }
  4043. else if (isDate(src)) {
  4044. dst = new Date(src.getTime ? src.getTime() : src);
  4045. }
  4046. else if (isRegExp(src)) {
  4047. dst = new RegExp(src);
  4048. }
  4049. else if (isError(src)) {
  4050. dst = { message: src.message };
  4051. }
  4052. else if (isBoolean(src)) {
  4053. dst = new Boolean(src);
  4054. }
  4055. else if (isNumber(src)) {
  4056. dst = new Number(src);
  4057. }
  4058. else if (isString(src)) {
  4059. dst = new String(src);
  4060. }
  4061. else if (Object.create && Object.getPrototypeOf) {
  4062. dst = Object.create(Object.getPrototypeOf(src));
  4063. }
  4064. else if (src.constructor === Object) {
  4065. dst = {};
  4066. }
  4067. else {
  4068. var proto =
  4069. (src.constructor && src.constructor.prototype)
  4070. || src.__proto__
  4071. || {}
  4072. ;
  4073. var T = function () {};
  4074. T.prototype = proto;
  4075. dst = new T;
  4076. }
  4077. forEach(objectKeys(src), function (key) {
  4078. dst[key] = src[key];
  4079. });
  4080. return dst;
  4081. }
  4082. else return src;
  4083. }
  4084. var objectKeys = Object.keys || function keys (obj) {
  4085. var res = [];
  4086. for (var key in obj) res.push(key)
  4087. return res;
  4088. };
  4089. function toS (obj) { return Object.prototype.toString.call(obj) }
  4090. function isDate (obj) { return toS(obj) === '[object Date]' }
  4091. function isRegExp (obj) { return toS(obj) === '[object RegExp]' }
  4092. function isError (obj) { return toS(obj) === '[object Error]' }
  4093. function isBoolean (obj) { return toS(obj) === '[object Boolean]' }
  4094. function isNumber (obj) { return toS(obj) === '[object Number]' }
  4095. function isString (obj) { return toS(obj) === '[object String]' }
  4096. var isArray = Array.isArray || function isArray (xs) {
  4097. return Object.prototype.toString.call(xs) === '[object Array]';
  4098. };
  4099. var forEach = function (xs, fn) {
  4100. if (xs.forEach) return xs.forEach(fn)
  4101. else for (var i = 0; i < xs.length; i++) {
  4102. fn(xs[i], i, xs);
  4103. }
  4104. };
  4105. forEach(objectKeys(Traverse.prototype), function (key) {
  4106. traverse[key] = function (obj) {
  4107. var args = [].slice.call(arguments, 1);
  4108. var t = new Traverse(obj);
  4109. return t[key].apply(t, args);
  4110. };
  4111. });
  4112. var hasOwnProperty = Object.hasOwnProperty || function (obj, key) {
  4113. return key in obj;
  4114. };
  4115. },{}],21:[function(require,module,exports){
  4116. module.exports.RADIUS = 6378137;
  4117. module.exports.FLATTENING = 1/298.257223563;
  4118. module.exports.POLAR_RADIUS = 6356752.3142;
  4119. },{}],22:[function(require,module,exports){
  4120. module.exports = extend
  4121. var hasOwnProperty = Object.prototype.hasOwnProperty;
  4122. function extend() {
  4123. var target = {}
  4124. for (var i = 0; i < arguments.length; i++) {
  4125. var source = arguments[i]
  4126. for (var key in source) {
  4127. if (hasOwnProperty.call(source, key)) {
  4128. target[key] = source[key]
  4129. }
  4130. }
  4131. }
  4132. return target
  4133. }
  4134. },{}],23:[function(require,module,exports){
  4135. 'use strict';
  4136. var isEqual = require('lodash.isequal');
  4137. var normalize = require('@mapbox/geojson-normalize');
  4138. var hat = require('hat');
  4139. var featuresAt = require('./lib/features_at');
  4140. var stringSetsAreEqual = require('./lib/string_sets_are_equal');
  4141. var geojsonhint = require('@mapbox/geojsonhint');
  4142. var Constants = require('./constants');
  4143. var StringSet = require('./lib/string_set');
  4144. var featureTypes = {
  4145. Polygon: require('./feature_types/polygon'),
  4146. LineString: require('./feature_types/line_string'),
  4147. Point: require('./feature_types/point'),
  4148. MultiPolygon: require('./feature_types/multi_feature'),
  4149. MultiLineString: require('./feature_types/multi_feature'),
  4150. MultiPoint: require('./feature_types/multi_feature')
  4151. };
  4152. module.exports = function (ctx, api) {
  4153. api.modes = Constants.modes;
  4154. api.getFeatureIdsAt = function (point) {
  4155. var features = featuresAt.click({ point: point }, null, ctx);
  4156. return features.map(function (feature) {
  4157. return feature.properties.id;
  4158. });
  4159. };
  4160. api.getSelectedIds = function () {
  4161. return ctx.store.getSelectedIds();
  4162. };
  4163. api.getSelected = function () {
  4164. return {
  4165. type: Constants.geojsonTypes.FEATURE_COLLECTION,
  4166. features: ctx.store.getSelectedIds().map(function (id) {
  4167. return ctx.store.get(id);
  4168. }).map(function (feature) {
  4169. return feature.toGeoJSON();
  4170. })
  4171. };
  4172. };
  4173. api.getSelectedPoints = function () {
  4174. return {
  4175. type: Constants.geojsonTypes.FEATURE_COLLECTION,
  4176. features: ctx.store.getSelectedCoordinates().map(function (coordinate) {
  4177. return {
  4178. type: Constants.geojsonTypes.FEATURE,
  4179. properties: {},
  4180. geometry: {
  4181. type: Constants.geojsonTypes.POINT,
  4182. coordinates: coordinate.coordinates
  4183. }
  4184. };
  4185. })
  4186. };
  4187. };
  4188. api.set = function (featureCollection) {
  4189. if (featureCollection.type === undefined || featureCollection.type !== Constants.geojsonTypes.FEATURE_COLLECTION || !Array.isArray(featureCollection.features)) {
  4190. throw new Error('Invalid FeatureCollection');
  4191. }
  4192. var renderBatch = ctx.store.createRenderBatch();
  4193. var toDelete = ctx.store.getAllIds().slice();
  4194. var newIds = api.add(featureCollection);
  4195. var newIdsLookup = new StringSet(newIds);
  4196. toDelete = toDelete.filter(function (id) {
  4197. return !newIdsLookup.has(id);
  4198. });
  4199. if (toDelete.length) {
  4200. api.delete(toDelete);
  4201. }
  4202. renderBatch();
  4203. return newIds;
  4204. };
  4205. api.add = function (geojson) {
  4206. var errors = geojsonhint.hint(geojson, { precisionWarning: false }).filter(function (e) {
  4207. return e.level !== 'message';
  4208. });
  4209. if (errors.length) {
  4210. throw new Error(errors[0].message);
  4211. }
  4212. var featureCollection = JSON.parse(JSON.stringify(normalize(geojson)));
  4213. var ids = featureCollection.features.map(function (feature) {
  4214. feature.id = feature.id || hat();
  4215. if (feature.geometry === null) {
  4216. throw new Error('Invalid geometry: null');
  4217. }
  4218. if (ctx.store.get(feature.id) === undefined || ctx.store.get(feature.id).type !== feature.geometry.type) {
  4219. // If the feature has not yet been created ...
  4220. var Model = featureTypes[feature.geometry.type];
  4221. if (Model === undefined) {
  4222. throw new Error('Invalid geometry type: ' + feature.geometry.type + '.');
  4223. }
  4224. var internalFeature = new Model(ctx, feature);
  4225. ctx.store.add(internalFeature);
  4226. } else {
  4227. // If a feature of that id has already been created, and we are swapping it out ...
  4228. var _internalFeature = ctx.store.get(feature.id);
  4229. _internalFeature.properties = feature.properties;
  4230. if (!isEqual(_internalFeature.getCoordinates(), feature.geometry.coordinates)) {
  4231. _internalFeature.incomingCoords(feature.geometry.coordinates);
  4232. }
  4233. }
  4234. return feature.id;
  4235. });
  4236. ctx.store.render();
  4237. return ids;
  4238. };
  4239. api.get = function (id) {
  4240. var feature = ctx.store.get(id);
  4241. if (feature) {
  4242. return feature.toGeoJSON();
  4243. }
  4244. };
  4245. api.getAll = function () {
  4246. return {
  4247. type: Constants.geojsonTypes.FEATURE_COLLECTION,
  4248. features: ctx.store.getAll().map(function (feature) {
  4249. return feature.toGeoJSON();
  4250. })
  4251. };
  4252. };
  4253. api.delete = function (featureIds) {
  4254. ctx.store.delete(featureIds, { silent: true });
  4255. // If we were in direct select mode and our selected feature no longer exists
  4256. // (because it was deleted), we need to get out of that mode.
  4257. if (api.getMode() === Constants.modes.DIRECT_SELECT && !ctx.store.getSelectedIds().length) {
  4258. ctx.events.changeMode(Constants.modes.SIMPLE_SELECT, undefined, { silent: true });
  4259. } else {
  4260. ctx.store.render();
  4261. }
  4262. return api;
  4263. };
  4264. api.deleteAll = function () {
  4265. ctx.store.delete(ctx.store.getAllIds(), { silent: true });
  4266. // If we were in direct select mode, now our selected feature no longer exists,
  4267. // so escape that mode.
  4268. if (api.getMode() === Constants.modes.DIRECT_SELECT) {
  4269. ctx.events.changeMode(Constants.modes.SIMPLE_SELECT, undefined, { silent: true });
  4270. } else {
  4271. ctx.store.render();
  4272. }
  4273. return api;
  4274. };
  4275. api.changeMode = function (mode) {
  4276. var modeOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  4277. // Avoid changing modes just to re-select what's already selected
  4278. if (mode === Constants.modes.SIMPLE_SELECT && api.getMode() === Constants.modes.SIMPLE_SELECT) {
  4279. if (stringSetsAreEqual(modeOptions.featureIds || [], ctx.store.getSelectedIds())) return api;
  4280. // And if we are changing the selection within simple_select mode, just change the selection,
  4281. // instead of stopping and re-starting the mode
  4282. ctx.store.setSelected(modeOptions.featureIds, { silent: true });
  4283. ctx.store.render();
  4284. return api;
  4285. }
  4286. if (mode === Constants.modes.DIRECT_SELECT && api.getMode() === Constants.modes.DIRECT_SELECT && modeOptions.featureId === ctx.store.getSelectedIds()[0]) {
  4287. return api;
  4288. }
  4289. ctx.events.changeMode(mode, modeOptions, { silent: true });
  4290. return api;
  4291. };
  4292. api.getMode = function () {
  4293. return ctx.events.getMode();
  4294. };
  4295. api.addMode = function(modeName, modeObj){
  4296. ctx.events.addMode(modeName, modeObj);
  4297. };
  4298. api.trash = function () {
  4299. ctx.events.trash({ silent: true });
  4300. return api;
  4301. };
  4302. api.combineFeatures = function () {
  4303. ctx.events.combineFeatures({ silent: true });
  4304. return api;
  4305. };
  4306. api.uncombineFeatures = function () {
  4307. ctx.events.uncombineFeatures({ silent: true });
  4308. return api;
  4309. };
  4310. api.setFeatureProperty = function (featureId, property, value) {
  4311. ctx.store.setFeatureProperty(featureId, property, value);
  4312. return api;
  4313. };
  4314. return api;
  4315. };
  4316. },{"./constants":24,"./feature_types/line_string":27,"./feature_types/multi_feature":28,"./feature_types/point":29,"./feature_types/polygon":30,"./lib/features_at":38,"./lib/string_set":48,"./lib/string_sets_are_equal":49,"@mapbox/geojson-normalize":3,"@mapbox/geojsonhint":4,"hat":14,"lodash.isequal":16}],24:[function(require,module,exports){
  4317. 'use strict';
  4318. module.exports = {
  4319. classes: {
  4320. CONTROL_BASE: 'mapboxgl-ctrl',
  4321. CONTROL_PREFIX: 'mapboxgl-ctrl-',
  4322. CONTROL_BUTTON: 'mapbox-gl-draw_ctrl-draw-btn',
  4323. CONTROL_BUTTON_LINE: 'mapbox-gl-draw_line',
  4324. CONTROL_BUTTON_POLYGON: 'mapbox-gl-draw_polygon',
  4325. CONTROL_BUTTON_POINT: 'mapbox-gl-draw_point',
  4326. CONTROL_BUTTON_TRASH: 'mapbox-gl-draw_trash',
  4327. CONTROL_BUTTON_COMBINE_FEATURES: 'mapbox-gl-draw_combine',
  4328. CONTROL_BUTTON_UNCOMBINE_FEATURES: 'mapbox-gl-draw_uncombine',
  4329. CONTROL_GROUP: 'mapboxgl-ctrl-group',
  4330. ATTRIBUTION: 'mapboxgl-ctrl-attrib',
  4331. ACTIVE_BUTTON: 'active',
  4332. BOX_SELECT: 'mapbox-gl-draw_boxselect'
  4333. },
  4334. sources: {
  4335. HOT: 'mapbox-gl-draw-hot',
  4336. COLD: 'mapbox-gl-draw-cold'
  4337. },
  4338. cursors: {
  4339. ADD: 'add',
  4340. MOVE: 'move',
  4341. DRAG: 'drag',
  4342. POINTER: 'pointer',
  4343. NONE: 'none'
  4344. },
  4345. types: {
  4346. POLYGON: 'polygon',
  4347. LINE: 'line_string',
  4348. POINT: 'point'
  4349. },
  4350. geojsonTypes: {
  4351. FEATURE: 'Feature',
  4352. POLYGON: 'Polygon',
  4353. LINE_STRING: 'LineString',
  4354. POINT: 'Point',
  4355. FEATURE_COLLECTION: 'FeatureCollection',
  4356. MULTI_PREFIX: 'Multi',
  4357. MULTI_POINT: 'MultiPoint',
  4358. MULTI_LINE_STRING: 'MultiLineString',
  4359. MULTI_POLYGON: 'MultiPolygon'
  4360. },
  4361. modes: {
  4362. DRAW_LINE_STRING: 'draw_line_string',
  4363. DRAW_POLYGON: 'draw_polygon',
  4364. DRAW_POINT: 'draw_point',
  4365. SIMPLE_SELECT: 'simple_select',
  4366. DIRECT_SELECT: 'direct_select',
  4367. STATIC: 'static'
  4368. },
  4369. events: {
  4370. CREATE: 'draw.create',
  4371. DELETE: 'draw.delete',
  4372. UPDATE: 'draw.update',
  4373. SELECTION_CHANGE: 'draw.selectionchange',
  4374. MODE_CHANGE: 'draw.modechange',
  4375. ACTIONABLE: 'draw.actionable',
  4376. RENDER: 'draw.render',
  4377. COMBINE_FEATURES: 'draw.combine',
  4378. UNCOMBINE_FEATURES: 'draw.uncombine'
  4379. },
  4380. updateActions: {
  4381. MOVE: 'move',
  4382. CHANGE_COORDINATES: 'change_coordinates'
  4383. },
  4384. meta: {
  4385. FEATURE: 'feature',
  4386. MIDPOINT: 'midpoint',
  4387. VERTEX: 'vertex'
  4388. },
  4389. activeStates: {
  4390. ACTIVE: 'true',
  4391. INACTIVE: 'false'
  4392. },
  4393. LAT_MIN: -90,
  4394. LAT_RENDERED_MIN: -85,
  4395. LAT_MAX: 90,
  4396. LAT_RENDERED_MAX: 85,
  4397. LNG_MIN: -270,
  4398. LNG_MAX: 270
  4399. };
  4400. },{}],25:[function(require,module,exports){
  4401. 'use strict';
  4402. var _modes;
  4403. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  4404. var setupModeHandler = require('./lib/mode_handler');
  4405. var getFeaturesAndSetCursor = require('./lib/get_features_and_set_cursor');
  4406. var featuresAt = require('./lib/features_at');
  4407. var isClick = require('./lib/is_click');
  4408. var isTap = require('./lib/is_tap');
  4409. var Constants = require('./constants');
  4410. var objectToMode = require('./modes/object_to_mode');
  4411. var modes = (_modes = {}, _defineProperty(_modes, Constants.modes.SIMPLE_SELECT, require('./modes/simple_select')), _defineProperty(_modes, Constants.modes.DIRECT_SELECT, require('./modes/direct_select')), _defineProperty(_modes, Constants.modes.DRAW_POINT, require('./modes/draw_point')), _defineProperty(_modes, Constants.modes.DRAW_LINE_STRING, require('./modes/draw_line_string')), _defineProperty(_modes, Constants.modes.DRAW_POLYGON, require('./modes/draw_polygon')), _defineProperty(_modes, Constants.modes.STATIC, require('./modes/static')), _modes);
  4412. module.exports = function (ctx) {
  4413. var mouseDownInfo = {};
  4414. var touchStartInfo = {};
  4415. var events = {};
  4416. var _currentModeName = Constants.modes.SIMPLE_SELECT;
  4417. var currentMode = setupModeHandler(modes.simple_select(ctx), ctx);
  4418. events.drag = function (event, isDrag) {
  4419. if (isDrag({
  4420. point: event.point,
  4421. time: new Date().getTime()
  4422. })) {
  4423. ctx.ui.queueMapClasses({ mouse: Constants.cursors.DRAG });
  4424. currentMode.drag(event);
  4425. } else {
  4426. event.originalEvent.stopPropagation();
  4427. }
  4428. };
  4429. events.mousedrag = function (event) {
  4430. events.drag(event, function (endInfo) {
  4431. return !isClick(mouseDownInfo, endInfo);
  4432. });
  4433. };
  4434. events.touchdrag = function (event) {
  4435. events.drag(event, function (endInfo) {
  4436. return !isTap(touchStartInfo, endInfo);
  4437. });
  4438. };
  4439. events.mousemove = function (event) {
  4440. var button = event.originalEvent.buttons !== undefined ? event.originalEvent.buttons : event.originalEvent.which;
  4441. if (button === 1) {
  4442. return events.mousedrag(event);
  4443. }
  4444. var target = getFeaturesAndSetCursor(event, ctx);
  4445. event.featureTarget = target;
  4446. currentMode.mousemove(event);
  4447. };
  4448. events.mousedown = function (event) {
  4449. mouseDownInfo = {
  4450. time: new Date().getTime(),
  4451. point: event.point
  4452. };
  4453. var target = getFeaturesAndSetCursor(event, ctx);
  4454. event.featureTarget = target;
  4455. currentMode.mousedown(event);
  4456. };
  4457. events.mouseup = function (event) {
  4458. var target = getFeaturesAndSetCursor(event, ctx);
  4459. event.featureTarget = target;
  4460. if (isClick(mouseDownInfo, {
  4461. point: event.point,
  4462. time: new Date().getTime()
  4463. })) {
  4464. currentMode.click(event);
  4465. } else {
  4466. currentMode.mouseup(event);
  4467. }
  4468. };
  4469. events.mouseout = function (event) {
  4470. currentMode.mouseout(event);
  4471. };
  4472. events.touchstart = function (event) {
  4473. // Prevent emulated mouse events because we will fully handle the touch here.
  4474. // This does not stop the touch events from propogating to mapbox though.
  4475. event.originalEvent.preventDefault();
  4476. if (!ctx.options.touchEnabled) {
  4477. return;
  4478. }
  4479. touchStartInfo = {
  4480. time: new Date().getTime(),
  4481. point: event.point
  4482. };
  4483. var target = featuresAt.touch(event, null, ctx)[0];
  4484. event.featureTarget = target;
  4485. currentMode.touchstart(event);
  4486. };
  4487. events.touchmove = function (event) {
  4488. event.originalEvent.preventDefault();
  4489. if (!ctx.options.touchEnabled) {
  4490. return;
  4491. }
  4492. currentMode.touchmove(event);
  4493. return events.touchdrag(event);
  4494. };
  4495. events.touchend = function (event) {
  4496. event.originalEvent.preventDefault();
  4497. if (!ctx.options.touchEnabled) {
  4498. return;
  4499. }
  4500. var target = featuresAt.touch(event, null, ctx)[0];
  4501. event.featureTarget = target;
  4502. if (isTap(touchStartInfo, {
  4503. time: new Date().getTime(),
  4504. point: event.point
  4505. })) {
  4506. currentMode.tap(event);
  4507. } else {
  4508. currentMode.touchend(event);
  4509. }
  4510. };
  4511. // 8 - Backspace
  4512. // 46 - Delete
  4513. var isKeyModeValid = function isKeyModeValid(code) {
  4514. return !(code === 8 || code === 46 || code >= 48 && code <= 57);
  4515. };
  4516. events.keydown = function (event) {
  4517. if ((event.keyCode === 8 || event.keyCode === 46) && ctx.options.controls.trash) {
  4518. event.preventDefault();
  4519. currentMode.trash();
  4520. } else if (isKeyModeValid(event.keyCode)) {
  4521. currentMode.keydown(event);
  4522. } else if (event.keyCode === 49 && ctx.options.controls.point) {
  4523. changeMode(Constants.modes.DRAW_POINT);
  4524. } else if (event.keyCode === 50 && ctx.options.controls.line_string) {
  4525. changeMode(Constants.modes.DRAW_LINE_STRING);
  4526. } else if (event.keyCode === 51 && ctx.options.controls.polygon) {
  4527. changeMode(Constants.modes.DRAW_POLYGON);
  4528. }
  4529. };
  4530. events.keyup = function (event) {
  4531. if (isKeyModeValid(event.keyCode)) {
  4532. currentMode.keyup(event);
  4533. }
  4534. };
  4535. events.zoomend = function () {
  4536. ctx.store.changeZoom();
  4537. };
  4538. events.data = function (event) {
  4539. if (event.dataType === 'style') {
  4540. var setup = ctx.setup,
  4541. map = ctx.map,
  4542. options = ctx.options,
  4543. store = ctx.store;
  4544. var hasLayers = options.styles.some(function (style) {
  4545. return map.getLayer(style.id);
  4546. });
  4547. if (!hasLayers) {
  4548. setup.addLayers();
  4549. store.setDirty();
  4550. store.render();
  4551. }
  4552. }
  4553. };
  4554. function changeMode(modename, nextModeOptions) {
  4555. var eventOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  4556. currentMode.stop();
  4557. var modebuilder = modes[modename];
  4558. if (modebuilder === undefined) {
  4559. throw new Error(modename + ' is not valid');
  4560. }
  4561. _currentModeName = modename;
  4562. var mode = modebuilder(ctx, nextModeOptions);
  4563. currentMode = setupModeHandler(mode, ctx);
  4564. if (!eventOptions.silent) {
  4565. ctx.map.fire(Constants.events.MODE_CHANGE, { mode: modename });
  4566. }
  4567. ctx.store.setDirty();
  4568. ctx.store.render();
  4569. }
  4570. var actionState = {
  4571. trash: false,
  4572. combineFeatures: false,
  4573. uncombineFeatures: false
  4574. };
  4575. function actionable(actions) {
  4576. var changed = false;
  4577. Object.keys(actions).forEach(function (action) {
  4578. if (actionState[action] === undefined) throw new Error('Invalid action type');
  4579. if (actionState[action] !== actions[action]) changed = true;
  4580. actionState[action] = actions[action];
  4581. });
  4582. if (changed) ctx.map.fire(Constants.events.ACTIONABLE, { actions: actionState });
  4583. }
  4584. var api = {
  4585. changeMode: changeMode,
  4586. actionable: actionable,
  4587. currentModeName: function currentModeName() {
  4588. return _currentModeName;
  4589. },
  4590. currentModeRender: function currentModeRender(geojson, push) {
  4591. return currentMode.render(geojson, push);
  4592. },
  4593. fire: function fire(name, event) {
  4594. if (events[name]) {
  4595. events[name](event);
  4596. }
  4597. },
  4598. addEventListeners: function addEventListeners() {
  4599. ctx.map.on('mousemove', events.mousemove);
  4600. ctx.map.on('mousedown', events.mousedown);
  4601. ctx.map.on('mouseup', events.mouseup);
  4602. ctx.map.on('data', events.data);
  4603. ctx.map.on('touchmove', events.touchmove);
  4604. ctx.map.on('touchstart', events.touchstart);
  4605. ctx.map.on('touchend', events.touchend);
  4606. ctx.container.addEventListener('mouseout', events.mouseout);
  4607. if (ctx.options.keybindings) {
  4608. ctx.container.addEventListener('keydown', events.keydown);
  4609. ctx.container.addEventListener('keyup', events.keyup);
  4610. }
  4611. },
  4612. removeEventListeners: function removeEventListeners() {
  4613. ctx.map.off('mousemove', events.mousemove);
  4614. ctx.map.off('mousedown', events.mousedown);
  4615. ctx.map.off('mouseup', events.mouseup);
  4616. ctx.map.off('data', events.data);
  4617. ctx.map.off('touchmove', events.touchmove);
  4618. ctx.map.off('touchstart', events.touchstart);
  4619. ctx.map.off('touchend', events.touchend);
  4620. ctx.container.removeEventListener('mouseout', events.mouseout);
  4621. if (ctx.options.keybindings) {
  4622. ctx.container.removeEventListener('keydown', events.keydown);
  4623. ctx.container.removeEventListener('keyup', events.keyup);
  4624. }
  4625. },
  4626. trash: function trash(options) {
  4627. currentMode.trash(options);
  4628. },
  4629. combineFeatures: function combineFeatures() {
  4630. currentMode.combineFeatures();
  4631. },
  4632. uncombineFeatures: function uncombineFeatures() {
  4633. currentMode.uncombineFeatures();
  4634. },
  4635. getMode: function getMode() {
  4636. return _currentModeName;
  4637. },
  4638. addMode: function(modeName, modeObj){
  4639. _modes[modeName] = objectToMode(modeObj);
  4640. }
  4641. };
  4642. return api;
  4643. };
  4644. },{"./constants":24,"./lib/features_at":38,"./lib/get_features_and_set_cursor":39,"./lib/is_click":40,"./lib/is_tap":42,"./lib/mode_handler":44,"./modes/direct_select":53,"./modes/draw_line_string":54,"./modes/draw_point":55,"./modes/draw_polygon":56,"./modes/simple_select":57,"./modes/static":58,"./modes/object_to_mode":160}],26:[function(require,module,exports){
  4645. 'use strict';
  4646. var hat = require('hat');
  4647. var Constants = require('../constants');
  4648. var Feature = function Feature(ctx, geojson) {
  4649. this.ctx = ctx;
  4650. this.properties = geojson.properties || {};
  4651. this.coordinates = geojson.geometry.coordinates;
  4652. this.id = geojson.id || hat();
  4653. this.type = geojson.geometry.type;
  4654. };
  4655. Feature.prototype.changed = function () {
  4656. this.ctx.store.featureChanged(this.id);
  4657. };
  4658. Feature.prototype.incomingCoords = function (coords) {
  4659. this.setCoordinates(coords);
  4660. };
  4661. Feature.prototype.setCoordinates = function (coords) {
  4662. this.coordinates = coords;
  4663. this.changed();
  4664. };
  4665. Feature.prototype.getCoordinates = function () {
  4666. return JSON.parse(JSON.stringify(this.coordinates));
  4667. };
  4668. Feature.prototype.setProperty = function (property, value) {
  4669. this.properties[property] = value;
  4670. };
  4671. Feature.prototype.toGeoJSON = function () {
  4672. return JSON.parse(JSON.stringify({
  4673. id: this.id,
  4674. type: Constants.geojsonTypes.FEATURE,
  4675. properties: this.properties,
  4676. geometry: {
  4677. coordinates: this.getCoordinates(),
  4678. type: this.type
  4679. }
  4680. }));
  4681. };
  4682. Feature.prototype.internal = function (mode) {
  4683. var properties = {
  4684. id: this.id,
  4685. meta: Constants.meta.FEATURE,
  4686. 'meta:type': this.type,
  4687. active: Constants.activeStates.INACTIVE,
  4688. mode: mode
  4689. };
  4690. if (this.ctx.options.userProperties) {
  4691. for (var name in this.properties) {
  4692. properties['user_' + name] = this.properties[name];
  4693. }
  4694. }
  4695. return {
  4696. type: Constants.geojsonTypes.FEATURE,
  4697. properties: properties,
  4698. geometry: {
  4699. coordinates: this.getCoordinates(),
  4700. type: this.type
  4701. }
  4702. };
  4703. };
  4704. module.exports = Feature;
  4705. },{"../constants":24,"hat":14}],27:[function(require,module,exports){
  4706. 'use strict';
  4707. var Feature = require('./feature');
  4708. var LineString = function LineString(ctx, geojson) {
  4709. Feature.call(this, ctx, geojson);
  4710. };
  4711. LineString.prototype = Object.create(Feature.prototype);
  4712. LineString.prototype.isValid = function () {
  4713. return this.coordinates.length > 1;
  4714. };
  4715. LineString.prototype.addCoordinate = function (path, lng, lat) {
  4716. this.changed();
  4717. var id = parseInt(path, 10);
  4718. this.coordinates.splice(id, 0, [lng, lat]);
  4719. };
  4720. LineString.prototype.getCoordinate = function (path) {
  4721. var id = parseInt(path, 10);
  4722. return JSON.parse(JSON.stringify(this.coordinates[id]));
  4723. };
  4724. LineString.prototype.removeCoordinate = function (path) {
  4725. this.changed();
  4726. this.coordinates.splice(parseInt(path, 10), 1);
  4727. };
  4728. LineString.prototype.updateCoordinate = function (path, lng, lat) {
  4729. var id = parseInt(path, 10);
  4730. this.coordinates[id] = [lng, lat];
  4731. this.changed();
  4732. };
  4733. module.exports = LineString;
  4734. },{"./feature":26}],28:[function(require,module,exports){
  4735. 'use strict';
  4736. var Feature = require('./feature');
  4737. var Constants = require('../constants');
  4738. var hat = require('hat');
  4739. var models = {
  4740. MultiPoint: require('./point'),
  4741. MultiLineString: require('./line_string'),
  4742. MultiPolygon: require('./polygon')
  4743. };
  4744. var takeAction = function takeAction(features, action, path, lng, lat) {
  4745. var parts = path.split('.');
  4746. var idx = parseInt(parts[0], 10);
  4747. var tail = !parts[1] ? null : parts.slice(1).join('.');
  4748. return features[idx][action](tail, lng, lat);
  4749. };
  4750. var MultiFeature = function MultiFeature(ctx, geojson) {
  4751. Feature.call(this, ctx, geojson);
  4752. delete this.coordinates;
  4753. this.model = models[geojson.geometry.type];
  4754. if (this.model === undefined) throw new TypeError(geojson.geometry.type + ' is not a valid type');
  4755. this.features = this._coordinatesToFeatures(geojson.geometry.coordinates);
  4756. };
  4757. MultiFeature.prototype = Object.create(Feature.prototype);
  4758. MultiFeature.prototype._coordinatesToFeatures = function (coordinates) {
  4759. var _this = this;
  4760. var Model = this.model.bind(this);
  4761. return coordinates.map(function (coords) {
  4762. return new Model(_this.ctx, {
  4763. id: hat(),
  4764. type: Constants.geojsonTypes.FEATURE,
  4765. properties: {},
  4766. geometry: {
  4767. coordinates: coords,
  4768. type: _this.type.replace('Multi', '')
  4769. }
  4770. });
  4771. });
  4772. };
  4773. MultiFeature.prototype.isValid = function () {
  4774. return this.features.every(function (f) {
  4775. return f.isValid();
  4776. });
  4777. };
  4778. MultiFeature.prototype.setCoordinates = function (coords) {
  4779. this.features = this._coordinatesToFeatures(coords);
  4780. this.changed();
  4781. };
  4782. MultiFeature.prototype.getCoordinate = function (path) {
  4783. return takeAction(this.features, 'getCoordinate', path);
  4784. };
  4785. MultiFeature.prototype.getCoordinates = function () {
  4786. return JSON.parse(JSON.stringify(this.features.map(function (f) {
  4787. if (f.type === Constants.geojsonTypes.POLYGON) return f.getCoordinates();
  4788. return f.coordinates;
  4789. })));
  4790. };
  4791. MultiFeature.prototype.updateCoordinate = function (path, lng, lat) {
  4792. takeAction(this.features, 'updateCoordinate', path, lng, lat);
  4793. this.changed();
  4794. };
  4795. MultiFeature.prototype.addCoordinate = function (path, lng, lat) {
  4796. takeAction(this.features, 'addCoordinate', path, lng, lat);
  4797. this.changed();
  4798. };
  4799. MultiFeature.prototype.removeCoordinate = function (path) {
  4800. takeAction(this.features, 'removeCoordinate', path);
  4801. this.changed();
  4802. };
  4803. MultiFeature.prototype.getFeatures = function () {
  4804. return this.features;
  4805. };
  4806. module.exports = MultiFeature;
  4807. },{"../constants":24,"./feature":26,"./line_string":27,"./point":29,"./polygon":30,"hat":14}],29:[function(require,module,exports){
  4808. 'use strict';
  4809. var Feature = require('./feature');
  4810. var Point = function Point(ctx, geojson) {
  4811. Feature.call(this, ctx, geojson);
  4812. };
  4813. Point.prototype = Object.create(Feature.prototype);
  4814. Point.prototype.isValid = function () {
  4815. return typeof this.coordinates[0] === 'number' && typeof this.coordinates[1] === 'number';
  4816. };
  4817. Point.prototype.updateCoordinate = function (pathOrLng, lngOrLat, lat) {
  4818. if (arguments.length === 3) {
  4819. this.coordinates = [lngOrLat, lat];
  4820. } else {
  4821. this.coordinates = [pathOrLng, lngOrLat];
  4822. }
  4823. this.changed();
  4824. };
  4825. Point.prototype.getCoordinate = function () {
  4826. return this.getCoordinates();
  4827. };
  4828. module.exports = Point;
  4829. },{"./feature":26}],30:[function(require,module,exports){
  4830. 'use strict';
  4831. var Feature = require('./feature');
  4832. var Polygon = function Polygon(ctx, geojson) {
  4833. Feature.call(this, ctx, geojson);
  4834. this.coordinates = this.coordinates.map(function (ring) {
  4835. return ring.slice(0, -1);
  4836. });
  4837. };
  4838. Polygon.prototype = Object.create(Feature.prototype);
  4839. Polygon.prototype.isValid = function () {
  4840. if (this.coordinates.length === 0) return false;
  4841. return this.coordinates.every(function (ring) {
  4842. return ring.length > 2;
  4843. });
  4844. };
  4845. // Expects valid geoJSON polygon geometry: first and last positions must be equivalent.
  4846. Polygon.prototype.incomingCoords = function (coords) {
  4847. this.coordinates = coords.map(function (ring) {
  4848. return ring.slice(0, -1);
  4849. });
  4850. this.changed();
  4851. };
  4852. // Does NOT expect valid geoJSON polygon geometry: first and last positions should not be equivalent.
  4853. Polygon.prototype.setCoordinates = function (coords) {
  4854. this.coordinates = coords;
  4855. this.changed();
  4856. };
  4857. Polygon.prototype.addCoordinate = function (path, lng, lat) {
  4858. this.changed();
  4859. var ids = path.split('.').map(function (x) {
  4860. return parseInt(x, 10);
  4861. });
  4862. var ring = this.coordinates[ids[0]];
  4863. ring.splice(ids[1], 0, [lng, lat]);
  4864. };
  4865. Polygon.prototype.removeCoordinate = function (path) {
  4866. this.changed();
  4867. var ids = path.split('.').map(function (x) {
  4868. return parseInt(x, 10);
  4869. });
  4870. var ring = this.coordinates[ids[0]];
  4871. if (ring) {
  4872. ring.splice(ids[1], 1);
  4873. if (ring.length < 3) {
  4874. this.coordinates.splice(ids[0], 1);
  4875. }
  4876. }
  4877. };
  4878. Polygon.prototype.getCoordinate = function (path) {
  4879. var ids = path.split('.').map(function (x) {
  4880. return parseInt(x, 10);
  4881. });
  4882. var ring = this.coordinates[ids[0]];
  4883. return JSON.parse(JSON.stringify(ring[ids[1]]));
  4884. };
  4885. Polygon.prototype.getCoordinates = function () {
  4886. return this.coordinates.map(function (coords) {
  4887. return coords.concat([coords[0]]);
  4888. });
  4889. };
  4890. Polygon.prototype.updateCoordinate = function (path, lng, lat) {
  4891. this.changed();
  4892. var parts = path.split('.');
  4893. var ringId = parseInt(parts[0], 10);
  4894. var coordId = parseInt(parts[1], 10);
  4895. if (this.coordinates[ringId] === undefined) {
  4896. this.coordinates[ringId] = [];
  4897. }
  4898. this.coordinates[ringId][coordId] = [lng, lat];
  4899. };
  4900. module.exports = Polygon;
  4901. },{"./feature":26}],31:[function(require,module,exports){
  4902. 'use strict';
  4903. var Constants = require('../constants');
  4904. module.exports = {
  4905. isOfMetaType: function isOfMetaType(type) {
  4906. return function (e) {
  4907. var featureTarget = e.featureTarget;
  4908. if (!featureTarget) return false;
  4909. if (!featureTarget.properties) return false;
  4910. return featureTarget.properties.meta === type;
  4911. };
  4912. },
  4913. isShiftMousedown: function isShiftMousedown(e) {
  4914. if (!e.originalEvent) return false;
  4915. if (!e.originalEvent.shiftKey) return false;
  4916. return e.originalEvent.button === 0;
  4917. },
  4918. isActiveFeature: function isActiveFeature(e) {
  4919. if (!e.featureTarget) return false;
  4920. if (!e.featureTarget.properties) return false;
  4921. return e.featureTarget.properties.active === Constants.activeStates.ACTIVE && e.featureTarget.properties.meta === Constants.meta.FEATURE;
  4922. },
  4923. isInactiveFeature: function isInactiveFeature(e) {
  4924. if (!e.featureTarget) return false;
  4925. if (!e.featureTarget.properties) return false;
  4926. return e.featureTarget.properties.active === Constants.activeStates.INACTIVE && e.featureTarget.properties.meta === Constants.meta.FEATURE;
  4927. },
  4928. noTarget: function noTarget(e) {
  4929. return e.featureTarget === undefined;
  4930. },
  4931. isFeature: function isFeature(e) {
  4932. if (!e.featureTarget) return false;
  4933. if (!e.featureTarget.properties) return false;
  4934. return e.featureTarget.properties.meta === Constants.meta.FEATURE;
  4935. },
  4936. isVertex: function isVertex(e) {
  4937. var featureTarget = e.featureTarget;
  4938. if (!featureTarget) return false;
  4939. if (!featureTarget.properties) return false;
  4940. return featureTarget.properties.meta === Constants.meta.VERTEX;
  4941. },
  4942. isShiftDown: function isShiftDown(e) {
  4943. if (!e.originalEvent) return false;
  4944. return e.originalEvent.shiftKey === true;
  4945. },
  4946. isEscapeKey: function isEscapeKey(e) {
  4947. return e.keyCode === 27;
  4948. },
  4949. isEnterKey: function isEnterKey(e) {
  4950. return e.keyCode === 13;
  4951. },
  4952. true: function _true() {
  4953. return true;
  4954. }
  4955. };
  4956. },{"../constants":24}],32:[function(require,module,exports){
  4957. 'use strict';
  4958. var extent = require('geojson-extent');
  4959. var Constants = require('../constants');
  4960. var LAT_MIN = Constants.LAT_MIN,
  4961. LAT_MAX = Constants.LAT_MAX,
  4962. LAT_RENDERED_MIN = Constants.LAT_RENDERED_MIN,
  4963. LAT_RENDERED_MAX = Constants.LAT_RENDERED_MAX,
  4964. LNG_MIN = Constants.LNG_MIN,
  4965. LNG_MAX = Constants.LNG_MAX;
  4966. // Ensure that we do not drag north-south far enough for
  4967. // - any part of any feature to exceed the poles
  4968. // - any feature to be completely lost in the space between the projection's
  4969. // edge and the poles, such that it couldn't be re-selected and moved back
  4970. module.exports = function (geojsonFeatures, delta) {
  4971. // "inner edge" = a feature's latitude closest to the equator
  4972. var northInnerEdge = LAT_MIN;
  4973. var southInnerEdge = LAT_MAX;
  4974. // "outer edge" = a feature's latitude furthest from the equator
  4975. var northOuterEdge = LAT_MIN;
  4976. var southOuterEdge = LAT_MAX;
  4977. var westEdge = LNG_MAX;
  4978. var eastEdge = LNG_MIN;
  4979. geojsonFeatures.forEach(function (feature) {
  4980. var bounds = extent(feature);
  4981. var featureSouthEdge = bounds[1];
  4982. var featureNorthEdge = bounds[3];
  4983. var featureWestEdge = bounds[0];
  4984. var featureEastEdge = bounds[2];
  4985. if (featureSouthEdge > northInnerEdge) northInnerEdge = featureSouthEdge;
  4986. if (featureNorthEdge < southInnerEdge) southInnerEdge = featureNorthEdge;
  4987. if (featureNorthEdge > northOuterEdge) northOuterEdge = featureNorthEdge;
  4988. if (featureSouthEdge < southOuterEdge) southOuterEdge = featureSouthEdge;
  4989. if (featureWestEdge < westEdge) westEdge = featureWestEdge;
  4990. if (featureEastEdge > eastEdge) eastEdge = featureEastEdge;
  4991. });
  4992. // These changes are not mutually exclusive: we might hit the inner
  4993. // edge but also have hit the outer edge and therefore need
  4994. // another readjustment
  4995. var constrainedDelta = delta;
  4996. if (northInnerEdge + constrainedDelta.lat > LAT_RENDERED_MAX) {
  4997. constrainedDelta.lat = LAT_RENDERED_MAX - northInnerEdge;
  4998. }
  4999. if (northOuterEdge + constrainedDelta.lat > LAT_MAX) {
  5000. constrainedDelta.lat = LAT_MAX - northOuterEdge;
  5001. }
  5002. if (southInnerEdge + constrainedDelta.lat < LAT_RENDERED_MIN) {
  5003. constrainedDelta.lat = LAT_RENDERED_MIN - southInnerEdge;
  5004. }
  5005. if (southOuterEdge + constrainedDelta.lat < LAT_MIN) {
  5006. constrainedDelta.lat = LAT_MIN - southOuterEdge;
  5007. }
  5008. if (westEdge + constrainedDelta.lng <= LNG_MIN) {
  5009. constrainedDelta.lng += Math.ceil(Math.abs(constrainedDelta.lng) / 360) * 360;
  5010. }
  5011. if (eastEdge + constrainedDelta.lng >= LNG_MAX) {
  5012. constrainedDelta.lng -= Math.ceil(Math.abs(constrainedDelta.lng) / 360) * 360;
  5013. }
  5014. return constrainedDelta;
  5015. };
  5016. },{"../constants":24,"geojson-extent":11}],33:[function(require,module,exports){
  5017. 'use strict';
  5018. var Constants = require('../constants');
  5019. module.exports = function (parent, startVertex, endVertex, map) {
  5020. var startCoord = startVertex.geometry.coordinates;
  5021. var endCoord = endVertex.geometry.coordinates;
  5022. // If a coordinate exceeds the projection, we can't calculate a midpoint,
  5023. // so run away
  5024. if (startCoord[1] > Constants.LAT_RENDERED_MAX || startCoord[1] < Constants.LAT_RENDERED_MIN || endCoord[1] > Constants.LAT_RENDERED_MAX || endCoord[1] < Constants.LAT_RENDERED_MIN) {
  5025. return null;
  5026. }
  5027. var ptA = map.project([startCoord[0], startCoord[1]]);
  5028. var ptB = map.project([endCoord[0], endCoord[1]]);
  5029. var mid = map.unproject([(ptA.x + ptB.x) / 2, (ptA.y + ptB.y) / 2]);
  5030. return {
  5031. type: Constants.geojsonTypes.FEATURE,
  5032. properties: {
  5033. meta: Constants.meta.MIDPOINT,
  5034. parent: parent,
  5035. lng: mid.lng,
  5036. lat: mid.lat,
  5037. coord_path: endVertex.properties.coord_path
  5038. },
  5039. geometry: {
  5040. type: Constants.geojsonTypes.POINT,
  5041. coordinates: [mid.lng, mid.lat]
  5042. }
  5043. };
  5044. };
  5045. },{"../constants":24}],34:[function(require,module,exports){
  5046. 'use strict';
  5047. var createVertex = require('./create_vertex');
  5048. var createMidpoint = require('./create_midpoint');
  5049. var Constants = require('../constants');
  5050. function createSupplementaryPoints(geojson) {
  5051. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  5052. var basePath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  5053. var _geojson$geometry = geojson.geometry,
  5054. type = _geojson$geometry.type,
  5055. coordinates = _geojson$geometry.coordinates;
  5056. var featureId = geojson.properties && geojson.properties.id;
  5057. var supplementaryPoints = [];
  5058. if (type === Constants.geojsonTypes.POINT) {
  5059. // For points, just create a vertex
  5060. supplementaryPoints.push(createVertex(featureId, coordinates, basePath, isSelectedPath(basePath)));
  5061. } else if (type === Constants.geojsonTypes.POLYGON) {
  5062. // Cycle through a Polygon's rings and
  5063. // process each line
  5064. coordinates.forEach(function (line, lineIndex) {
  5065. processLine(line, basePath !== null ? basePath + '.' + lineIndex : String(lineIndex));
  5066. });
  5067. } else if (type === Constants.geojsonTypes.LINE_STRING) {
  5068. processLine(coordinates, basePath);
  5069. } else if (type.indexOf(Constants.geojsonTypes.MULTI_PREFIX) === 0) {
  5070. processMultiGeometry();
  5071. }
  5072. function processLine(line, lineBasePath) {
  5073. var firstPointString = '';
  5074. var lastVertex = null;
  5075. line.forEach(function (point, pointIndex) {
  5076. var pointPath = lineBasePath !== undefined && lineBasePath !== null ? lineBasePath + '.' + pointIndex : String(pointIndex);
  5077. var vertex = createVertex(featureId, point, pointPath, isSelectedPath(pointPath));
  5078. // If we're creating midpoints, check if there was a
  5079. // vertex before this one. If so, add a midpoint
  5080. // between that vertex and this one.
  5081. if (options.midpoints && lastVertex) {
  5082. var midpoint = createMidpoint(featureId, lastVertex, vertex, options.map);
  5083. if (midpoint) {
  5084. supplementaryPoints.push(midpoint);
  5085. }
  5086. }
  5087. lastVertex = vertex;
  5088. // A Polygon line's last point is the same as the first point. If we're on the last
  5089. // point, we want to draw a midpoint before it but not another vertex on it
  5090. // (since we already a vertex there, from the first point).
  5091. var stringifiedPoint = JSON.stringify(point);
  5092. if (firstPointString !== stringifiedPoint) {
  5093. supplementaryPoints.push(vertex);
  5094. }
  5095. if (pointIndex === 0) {
  5096. firstPointString = stringifiedPoint;
  5097. }
  5098. });
  5099. }
  5100. function isSelectedPath(path) {
  5101. if (!options.selectedPaths) return false;
  5102. return options.selectedPaths.indexOf(path) !== -1;
  5103. }
  5104. // Split a multi-geometry into constituent
  5105. // geometries, and accumulate the supplementary points
  5106. // for each of those constituents
  5107. function processMultiGeometry() {
  5108. var subType = type.replace(Constants.geojsonTypes.MULTI_PREFIX, '');
  5109. coordinates.forEach(function (subCoordinates, index) {
  5110. var subFeature = {
  5111. type: Constants.geojsonTypes.FEATURE,
  5112. properties: geojson.properties,
  5113. geometry: {
  5114. type: subType,
  5115. coordinates: subCoordinates
  5116. }
  5117. };
  5118. supplementaryPoints = supplementaryPoints.concat(createSupplementaryPoints(subFeature, options, index));
  5119. });
  5120. }
  5121. return supplementaryPoints;
  5122. }
  5123. module.exports = createSupplementaryPoints;
  5124. },{"../constants":24,"./create_midpoint":33,"./create_vertex":35}],35:[function(require,module,exports){
  5125. 'use strict';
  5126. var Constants = require('../constants');
  5127. /**
  5128. * Returns GeoJSON for a Point representing the
  5129. * vertex of another feature.
  5130. *
  5131. * @param {string} parentId
  5132. * @param {Array<number>} coordinates
  5133. * @param {string} path - Dot-separated numbers indicating exactly
  5134. * where the point exists within its parent feature's coordinates.
  5135. * @param {boolean} selected
  5136. * @return {GeoJSON} Point
  5137. */
  5138. module.exports = function (parentId, coordinates, path, selected) {
  5139. return {
  5140. type: Constants.geojsonTypes.FEATURE,
  5141. properties: {
  5142. meta: Constants.meta.VERTEX,
  5143. parent: parentId,
  5144. coord_path: path,
  5145. active: selected ? Constants.activeStates.ACTIVE : Constants.activeStates.INACTIVE
  5146. },
  5147. geometry: {
  5148. type: Constants.geojsonTypes.POINT,
  5149. coordinates: coordinates
  5150. }
  5151. };
  5152. };
  5153. },{"../constants":24}],36:[function(require,module,exports){
  5154. "use strict";
  5155. module.exports = {
  5156. enable: function enable(ctx) {
  5157. setTimeout(function () {
  5158. if (!ctx.map || !ctx.map.doubleClickZoom) return;
  5159. ctx.map.doubleClickZoom.enable();
  5160. }, 0);
  5161. },
  5162. disable: function disable(ctx) {
  5163. setTimeout(function () {
  5164. if (!ctx.map || !ctx.map.doubleClickZoom) return;
  5165. ctx.map.doubleClickZoom.disable();
  5166. }, 0);
  5167. }
  5168. };
  5169. },{}],37:[function(require,module,exports){
  5170. "use strict";
  5171. module.exports = function (a, b) {
  5172. var x = a.x - b.x;
  5173. var y = a.y - b.y;
  5174. return Math.sqrt(x * x + y * y);
  5175. };
  5176. },{}],38:[function(require,module,exports){
  5177. 'use strict';
  5178. var sortFeatures = require('./sort_features');
  5179. var mapEventToBoundingBox = require('./map_event_to_bounding_box');
  5180. var Constants = require('../constants');
  5181. var StringSet = require('./string_set');
  5182. var META_TYPES = [Constants.meta.FEATURE, Constants.meta.MIDPOINT, Constants.meta.VERTEX];
  5183. // Requires either event or bbox
  5184. module.exports = {
  5185. click: featuresAtClick,
  5186. touch: featuresAtTouch
  5187. };
  5188. function featuresAtClick(event, bbox, ctx) {
  5189. return featuresAt(event, bbox, ctx, ctx.options.clickBuffer);
  5190. }
  5191. function featuresAtTouch(event, bbox, ctx) {
  5192. return featuresAt(event, bbox, ctx, ctx.options.touchBuffer);
  5193. }
  5194. function featuresAt(event, bbox, ctx, buffer) {
  5195. if (ctx.map === null) return [];
  5196. var box = event ? mapEventToBoundingBox(event, buffer) : bbox;
  5197. var queryParams = {};
  5198. if (ctx.options.styles) queryParams.layers = ctx.options.styles.map(function (s) {
  5199. return s.id;
  5200. });
  5201. var features = ctx.map.queryRenderedFeatures(box, queryParams).filter(function (feature) {
  5202. return META_TYPES.indexOf(feature.properties.meta) !== -1;
  5203. });
  5204. var featureIds = new StringSet();
  5205. var uniqueFeatures = [];
  5206. features.forEach(function (feature) {
  5207. var featureId = feature.properties.id;
  5208. if (featureIds.has(featureId)) return;
  5209. featureIds.add(featureId);
  5210. uniqueFeatures.push(feature);
  5211. });
  5212. return sortFeatures(uniqueFeatures);
  5213. }
  5214. },{"../constants":24,"./map_event_to_bounding_box":43,"./sort_features":47,"./string_set":48}],39:[function(require,module,exports){
  5215. 'use strict';
  5216. var featuresAt = require('./features_at');
  5217. var Constants = require('../constants');
  5218. module.exports = function getFeatureAtAndSetCursors(event, ctx) {
  5219. var features = featuresAt.click(event, null, ctx);
  5220. var classes = { mouse: Constants.cursors.NONE };
  5221. if (features[0]) {
  5222. classes.mouse = features[0].properties.active === Constants.activeStates.ACTIVE ? Constants.cursors.MOVE : Constants.cursors.POINTER;
  5223. classes.feature = features[0].properties.meta;
  5224. }
  5225. if (ctx.events.currentModeName().indexOf('draw') !== -1) {
  5226. classes.mouse = Constants.cursors.ADD;
  5227. }
  5228. ctx.ui.queueMapClasses(classes);
  5229. ctx.ui.updateMapClasses();
  5230. return features[0];
  5231. };
  5232. },{"../constants":24,"./features_at":38}],40:[function(require,module,exports){
  5233. 'use strict';
  5234. var euclideanDistance = require('./euclidean_distance');
  5235. var FINE_TOLERANCE = 4;
  5236. var GROSS_TOLERANCE = 12;
  5237. var INTERVAL = 500;
  5238. module.exports = function isClick(start, end) {
  5239. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  5240. var fineTolerance = options.fineTolerance != null ? options.fineTolerance : FINE_TOLERANCE;
  5241. var grossTolerance = options.grossTolerance != null ? options.grossTolerance : GROSS_TOLERANCE;
  5242. var interval = options.interval != null ? options.interval : INTERVAL;
  5243. start.point = start.point || end.point;
  5244. start.time = start.time || end.time;
  5245. var moveDistance = euclideanDistance(start.point, end.point);
  5246. return moveDistance < fineTolerance || moveDistance < grossTolerance && end.time - start.time < interval;
  5247. };
  5248. },{"./euclidean_distance":37}],41:[function(require,module,exports){
  5249. "use strict";
  5250. function isEventAtCoordinates(event, coordinates) {
  5251. if (!event.lngLat) return false;
  5252. var flag = event.lngLat.lng === coordinates[0] && event.lngLat.lat === coordinates[1];
  5253. //TODO
  5254. return flag;
  5255. }
  5256. module.exports = isEventAtCoordinates;
  5257. },{}],42:[function(require,module,exports){
  5258. 'use strict';
  5259. var euclideanDistance = require('./euclidean_distance');
  5260. var TOLERANCE = 25;
  5261. var INTERVAL = 250;
  5262. module.exports = function isTap(start, end) {
  5263. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  5264. var tolerance = options.tolerance != null ? options.tolerance : TOLERANCE;
  5265. var interval = options.interval != null ? options.interval : INTERVAL;
  5266. start.point = start.point || end.point;
  5267. start.time = start.time || end.time;
  5268. var moveDistance = euclideanDistance(start.point, end.point);
  5269. return moveDistance < tolerance && end.time - start.time < interval;
  5270. };
  5271. },{"./euclidean_distance":37}],43:[function(require,module,exports){
  5272. "use strict";
  5273. /**
  5274. * Returns a bounding box representing the event's location.
  5275. *
  5276. * @param {Event} mapEvent - Mapbox GL JS map event, with a point properties.
  5277. * @return {Array<Array<number>>} Bounding box.
  5278. */
  5279. function mapEventToBoundingBox(mapEvent) {
  5280. var buffer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  5281. return [[mapEvent.point.x - buffer, mapEvent.point.y - buffer], [mapEvent.point.x + buffer, mapEvent.point.y + buffer]];
  5282. }
  5283. module.exports = mapEventToBoundingBox;
  5284. },{}],44:[function(require,module,exports){
  5285. 'use strict';
  5286. var ModeHandler = function ModeHandler(mode, DrawContext) {
  5287. var handlers = {
  5288. drag: [],
  5289. click: [],
  5290. mousemove: [],
  5291. mousedown: [],
  5292. mouseup: [],
  5293. mouseout: [],
  5294. keydown: [],
  5295. keyup: [],
  5296. touchstart: [],
  5297. touchmove: [],
  5298. touchend: [],
  5299. tap: []
  5300. };
  5301. var ctx = {
  5302. on: function on(event, selector, fn) {
  5303. if (handlers[event] === undefined) {
  5304. throw new Error('Invalid event type: ' + event);
  5305. }
  5306. handlers[event].push({
  5307. selector: selector,
  5308. fn: fn
  5309. });
  5310. },
  5311. render: function render(id) {
  5312. DrawContext.store.featureChanged(id);
  5313. }
  5314. };
  5315. var delegate = function delegate(eventName, event) {
  5316. var handles = handlers[eventName];
  5317. var iHandle = handles.length;
  5318. while (iHandle--) {
  5319. var handle = handles[iHandle];
  5320. if (handle.selector(event)) {
  5321. handle.fn.call(ctx, event);
  5322. DrawContext.store.render();
  5323. DrawContext.ui.updateMapClasses();
  5324. // ensure an event is only handled once
  5325. // we do this to let modes have multiple overlapping selectors
  5326. // and relay on order of oppertations to filter
  5327. break;
  5328. }
  5329. }
  5330. };
  5331. mode.start.call(ctx);
  5332. return {
  5333. render: mode.render,
  5334. stop: function stop() {
  5335. if (mode.stop) mode.stop();
  5336. },
  5337. trash: function trash() {
  5338. if (mode.trash) {
  5339. mode.trash();
  5340. DrawContext.store.render();
  5341. }
  5342. },
  5343. combineFeatures: function combineFeatures() {
  5344. if (mode.combineFeatures) {
  5345. mode.combineFeatures();
  5346. }
  5347. },
  5348. uncombineFeatures: function uncombineFeatures() {
  5349. if (mode.uncombineFeatures) {
  5350. mode.uncombineFeatures();
  5351. }
  5352. },
  5353. drag: function drag(event) {
  5354. delegate('drag', event);
  5355. },
  5356. click: function click(event) {
  5357. delegate('click', event);
  5358. },
  5359. mousemove: function mousemove(event) {
  5360. delegate('mousemove', event);
  5361. },
  5362. mousedown: function mousedown(event) {
  5363. delegate('mousedown', event);
  5364. },
  5365. mouseup: function mouseup(event) {
  5366. delegate('mouseup', event);
  5367. },
  5368. mouseout: function mouseout(event) {
  5369. delegate('mouseout', event);
  5370. },
  5371. keydown: function keydown(event) {
  5372. delegate('keydown', event);
  5373. },
  5374. keyup: function keyup(event) {
  5375. delegate('keyup', event);
  5376. },
  5377. touchstart: function touchstart(event) {
  5378. delegate('touchstart', event);
  5379. },
  5380. touchmove: function touchmove(event) {
  5381. delegate('touchmove', event);
  5382. },
  5383. touchend: function touchend(event) {
  5384. delegate('touchend', event);
  5385. },
  5386. tap: function tap(event) {
  5387. delegate('tap', event);
  5388. }
  5389. };
  5390. };
  5391. module.exports = ModeHandler;
  5392. },{}],45:[function(require,module,exports){
  5393. 'use strict';
  5394. var Point = require('point-geometry');
  5395. /**
  5396. * Returns a Point representing a mouse event's position
  5397. * relative to a containing element.
  5398. *
  5399. * @param {MouseEvent} mouseEvent
  5400. * @param {Node} container
  5401. * @returns {Point}
  5402. */
  5403. function mouseEventPoint(mouseEvent, container) {
  5404. var rect = container.getBoundingClientRect();
  5405. return new Point(mouseEvent.clientX - rect.left - (container.clientLeft || 0), mouseEvent.clientY - rect.top - (container.clientTop || 0));
  5406. }
  5407. module.exports = mouseEventPoint;
  5408. },{"point-geometry":18}],46:[function(require,module,exports){
  5409. 'use strict';
  5410. var constrainFeatureMovement = require('./constrain_feature_movement');
  5411. var Constants = require('../constants');
  5412. module.exports = function (features, delta) {
  5413. var constrainedDelta = constrainFeatureMovement(features.map(function (feature) {
  5414. return feature.toGeoJSON();
  5415. }), delta);
  5416. features.forEach(function (feature) {
  5417. var currentCoordinates = feature.getCoordinates();
  5418. var moveCoordinate = function moveCoordinate(coord) {
  5419. var point = {
  5420. lng: coord[0] + constrainedDelta.lng,
  5421. lat: coord[1] + constrainedDelta.lat
  5422. };
  5423. return [point.lng, point.lat];
  5424. };
  5425. var moveRing = function moveRing(ring) {
  5426. return ring.map(function (coord) {
  5427. return moveCoordinate(coord);
  5428. });
  5429. };
  5430. var moveMultiPolygon = function moveMultiPolygon(multi) {
  5431. return multi.map(function (ring) {
  5432. return moveRing(ring);
  5433. });
  5434. };
  5435. var nextCoordinates = void 0;
  5436. if (feature.type === Constants.geojsonTypes.POINT) {
  5437. nextCoordinates = moveCoordinate(currentCoordinates);
  5438. } else if (feature.type === Constants.geojsonTypes.LINE_STRING || feature.type === Constants.geojsonTypes.MULTI_POINT) {
  5439. nextCoordinates = currentCoordinates.map(moveCoordinate);
  5440. } else if (feature.type === Constants.geojsonTypes.POLYGON || feature.type === Constants.geojsonTypes.MULTI_LINE_STRING) {
  5441. nextCoordinates = currentCoordinates.map(moveRing);
  5442. } else if (feature.type === Constants.geojsonTypes.MULTI_POLYGON) {
  5443. nextCoordinates = currentCoordinates.map(moveMultiPolygon);
  5444. }
  5445. feature.incomingCoords(nextCoordinates);
  5446. });
  5447. };
  5448. },{"../constants":24,"./constrain_feature_movement":32}],47:[function(require,module,exports){
  5449. 'use strict';
  5450. var area = require('@mapbox/geojson-area');
  5451. var Constants = require('../constants');
  5452. var FEATURE_SORT_RANKS = {
  5453. Point: 0,
  5454. LineString: 1,
  5455. Polygon: 2
  5456. };
  5457. function comparator(a, b) {
  5458. var score = FEATURE_SORT_RANKS[a.geometry.type] - FEATURE_SORT_RANKS[b.geometry.type];
  5459. if (score === 0 && a.geometry.type === Constants.geojsonTypes.POLYGON) {
  5460. return a.area - b.area;
  5461. }
  5462. return score;
  5463. }
  5464. // Sort in the order above, then sort polygons by area ascending.
  5465. function sortFeatures(features) {
  5466. return features.map(function (feature) {
  5467. if (feature.geometry.type === Constants.geojsonTypes.POLYGON) {
  5468. feature.area = area.geometry({
  5469. type: Constants.geojsonTypes.FEATURE,
  5470. property: {},
  5471. geometry: feature.geometry
  5472. });
  5473. }
  5474. return feature;
  5475. }).sort(comparator).map(function (feature) {
  5476. delete feature.area;
  5477. return feature;
  5478. });
  5479. }
  5480. module.exports = sortFeatures;
  5481. },{"../constants":24,"@mapbox/geojson-area":2}],48:[function(require,module,exports){
  5482. "use strict";
  5483. function StringSet(items) {
  5484. this._items = {};
  5485. this._length = items ? items.length : 0;
  5486. if (!items) return;
  5487. for (var i = 0, l = items.length; i < l; i++) {
  5488. if (items[i] === undefined) continue;
  5489. this._items[items[i]] = i;
  5490. }
  5491. }
  5492. StringSet.prototype.add = function (x) {
  5493. this._length = this._items[x] ? this._length : this._length + 1;
  5494. this._items[x] = this._items[x] ? this._items[x] : this._length;
  5495. return this;
  5496. };
  5497. StringSet.prototype.delete = function (x) {
  5498. this._length = this._items[x] ? this._length - 1 : this._length;
  5499. delete this._items[x];
  5500. return this;
  5501. };
  5502. StringSet.prototype.has = function (x) {
  5503. return this._items[x] !== undefined;
  5504. };
  5505. StringSet.prototype.values = function () {
  5506. var _this = this;
  5507. var orderedKeys = Object.keys(this._items).sort(function (a, b) {
  5508. return _this._items[a] - _this._items[b];
  5509. });
  5510. return orderedKeys;
  5511. };
  5512. StringSet.prototype.clear = function () {
  5513. this._length = 0;
  5514. this._items = {};
  5515. return this;
  5516. };
  5517. module.exports = StringSet;
  5518. },{}],49:[function(require,module,exports){
  5519. "use strict";
  5520. module.exports = function (a, b) {
  5521. if (a.length !== b.length) return false;
  5522. return JSON.stringify(a.map(function (id) {
  5523. return id;
  5524. }).sort()) === JSON.stringify(b.map(function (id) {
  5525. return id;
  5526. }).sort());
  5527. };
  5528. },{}],50:[function(require,module,exports){
  5529. 'use strict';
  5530. module.exports = [{
  5531. 'id': 'gl-draw-polygon-fill-inactive',
  5532. 'type': 'fill',
  5533. 'filter': ['all', ['==', 'active', 'false'], ['==', '$type', 'Polygon'], ['!=', 'mode', 'static']],
  5534. 'paint': {
  5535. 'fill-color': '#3bb2d0',
  5536. 'fill-outline-color': '#3bb2d0',
  5537. 'fill-opacity': 0.1
  5538. }
  5539. }, {
  5540. 'id': 'gl-draw-polygon-fill-active',
  5541. 'type': 'fill',
  5542. 'filter': ['all', ['==', 'active', 'true'], ['==', '$type', 'Polygon']],
  5543. 'paint': {
  5544. 'fill-color': '#fbb03b',
  5545. 'fill-outline-color': '#fbb03b',
  5546. 'fill-opacity': 0.1
  5547. }
  5548. }, {
  5549. 'id': 'gl-draw-polygon-midpoint',
  5550. 'type': 'circle',
  5551. 'filter': ['all', ['==', '$type', 'Point'], ['==', 'meta', 'midpoint']],
  5552. 'paint': {
  5553. 'circle-radius': 3,
  5554. 'circle-color': '#fbb03b'
  5555. }
  5556. }, {
  5557. 'id': 'gl-draw-polygon-stroke-inactive',
  5558. 'type': 'line',
  5559. 'filter': ['all', ['==', 'active', 'false'], ['==', '$type', 'Polygon'], ['!=', 'mode', 'static']],
  5560. 'layout': {
  5561. 'line-cap': 'round',
  5562. 'line-join': 'round'
  5563. },
  5564. 'paint': {
  5565. 'line-color': '#3bb2d0',
  5566. 'line-width': 2
  5567. }
  5568. }, {
  5569. 'id': 'gl-draw-polygon-stroke-active',
  5570. 'type': 'line',
  5571. 'filter': ['all', ['==', 'active', 'true'], ['==', '$type', 'Polygon']],
  5572. 'layout': {
  5573. 'line-cap': 'round',
  5574. 'line-join': 'round'
  5575. },
  5576. 'paint': {
  5577. 'line-color': '#fbb03b',
  5578. 'line-dasharray': [0.2, 2],
  5579. 'line-width': 2
  5580. }
  5581. }, {
  5582. 'id': 'gl-draw-line-inactive',
  5583. 'type': 'line',
  5584. 'filter': ['all', ['==', 'active', 'false'], ['==', '$type', 'LineString'], ['!=', 'mode', 'static']],
  5585. 'layout': {
  5586. 'line-cap': 'round',
  5587. 'line-join': 'round'
  5588. },
  5589. 'paint': {
  5590. 'line-color': '#3bb2d0',
  5591. 'line-width': 2
  5592. }
  5593. }, {
  5594. 'id': 'gl-draw-line-active',
  5595. 'type': 'line',
  5596. 'filter': ['all', ['==', '$type', 'LineString'], ['==', 'active', 'true']],
  5597. 'layout': {
  5598. 'line-cap': 'round',
  5599. 'line-join': 'round'
  5600. },
  5601. 'paint': {
  5602. 'line-color': '#fbb03b',
  5603. 'line-dasharray': [0.2, 2],
  5604. 'line-width': 2
  5605. }
  5606. }, {
  5607. 'id': 'gl-draw-polygon-and-line-vertex-stroke-inactive',
  5608. 'type': 'circle',
  5609. 'filter': ['all', ['==', 'meta', 'vertex'], ['==', '$type', 'Point'], ['!=', 'mode', 'static']],
  5610. 'paint': {
  5611. 'circle-radius': 5,
  5612. 'circle-color': '#fff'
  5613. }
  5614. }, {
  5615. 'id': 'gl-draw-polygon-and-line-vertex-inactive',
  5616. 'type': 'circle',
  5617. 'filter': ['all', ['==', 'meta', 'vertex'], ['==', '$type', 'Point'], ['!=', 'mode', 'static']],
  5618. 'paint': {
  5619. 'circle-radius': 3,
  5620. 'circle-color': '#fbb03b'
  5621. }
  5622. }, {
  5623. 'id': 'gl-draw-point-point-stroke-inactive',
  5624. 'type': 'circle',
  5625. 'filter': ['all', ['==', 'active', 'false'], ['==', '$type', 'Point'], ['==', 'meta', 'feature'], ['!=', 'mode', 'static']],
  5626. 'paint': {
  5627. 'circle-radius': 5,
  5628. 'circle-opacity': 1,
  5629. 'circle-color': '#fff'
  5630. }
  5631. }, {
  5632. 'id': 'gl-draw-point-inactive',
  5633. 'type': 'circle',
  5634. 'filter': ['all', ['==', 'active', 'false'], ['==', '$type', 'Point'], ['==', 'meta', 'feature'], ['!=', 'mode', 'static']],
  5635. 'paint': {
  5636. 'circle-radius': 3,
  5637. 'circle-color': '#3bb2d0'
  5638. }
  5639. }, {
  5640. 'id': 'gl-draw-point-stroke-active',
  5641. 'type': 'circle',
  5642. 'filter': ['all', ['==', '$type', 'Point'], ['==', 'active', 'true'], ['!=', 'meta', 'midpoint']],
  5643. 'paint': {
  5644. 'circle-radius': 7,
  5645. 'circle-color': '#fff'
  5646. }
  5647. }, {
  5648. 'id': 'gl-draw-point-active',
  5649. 'type': 'circle',
  5650. 'filter': ['all', ['==', '$type', 'Point'], ['!=', 'meta', 'midpoint'], ['==', 'active', 'true']],
  5651. 'paint': {
  5652. 'circle-radius': 5,
  5653. 'circle-color': '#fbb03b'
  5654. }
  5655. }, {
  5656. 'id': 'gl-draw-polygon-fill-static',
  5657. 'type': 'fill',
  5658. 'filter': ['all', ['==', 'mode', 'static'], ['==', '$type', 'Polygon']],
  5659. 'paint': {
  5660. 'fill-color': '#404040',
  5661. 'fill-outline-color': '#404040',
  5662. 'fill-opacity': 0.1
  5663. }
  5664. }, {
  5665. 'id': 'gl-draw-polygon-stroke-static',
  5666. 'type': 'line',
  5667. 'filter': ['all', ['==', 'mode', 'static'], ['==', '$type', 'Polygon']],
  5668. 'layout': {
  5669. 'line-cap': 'round',
  5670. 'line-join': 'round'
  5671. },
  5672. 'paint': {
  5673. 'line-color': '#404040',
  5674. 'line-width': 2
  5675. }
  5676. }, {
  5677. 'id': 'gl-draw-line-static',
  5678. 'type': 'line',
  5679. 'filter': ['all', ['==', 'mode', 'static'], ['==', '$type', 'LineString']],
  5680. 'layout': {
  5681. 'line-cap': 'round',
  5682. 'line-join': 'round'
  5683. },
  5684. 'paint': {
  5685. 'line-color': '#404040',
  5686. 'line-width': 2
  5687. }
  5688. }, {
  5689. 'id': 'gl-draw-point-static',
  5690. 'type': 'circle',
  5691. 'filter': ['all', ['==', 'mode', 'static'], ['==', '$type', 'Point']],
  5692. 'paint': {
  5693. 'circle-radius': 5,
  5694. 'circle-color': '#404040'
  5695. }
  5696. }];
  5697. },{}],51:[function(require,module,exports){
  5698. "use strict";
  5699. function throttle(fn, time, context) {
  5700. var lock = void 0,
  5701. args = void 0;
  5702. function later() {
  5703. // reset lock and call if queued
  5704. lock = false;
  5705. if (args) {
  5706. wrapperFn.apply(context, args);
  5707. args = false;
  5708. }
  5709. }
  5710. function wrapperFn() {
  5711. if (lock) {
  5712. // called too soon, queue to call later
  5713. args = arguments;
  5714. } else {
  5715. // lock until later then call
  5716. lock = true;
  5717. fn.apply(context, arguments);
  5718. setTimeout(later, time);
  5719. }
  5720. }
  5721. return wrapperFn;
  5722. }
  5723. module.exports = throttle;
  5724. },{}],52:[function(require,module,exports){
  5725. "use strict";
  5726. /**
  5727. * Derive a dense array (no `undefined`s) from a single value or array.
  5728. *
  5729. * @param {any} x
  5730. * @return {Array<any>}
  5731. */
  5732. function toDenseArray(x) {
  5733. return [].concat(x).filter(function (y) {
  5734. return y !== undefined;
  5735. });
  5736. }
  5737. module.exports = toDenseArray;
  5738. },{}],53:[function(require,module,exports){
  5739. 'use strict';
  5740. var _require = require('../lib/common_selectors'),
  5741. noTarget = _require.noTarget,
  5742. isOfMetaType = _require.isOfMetaType,
  5743. isInactiveFeature = _require.isInactiveFeature,
  5744. isShiftDown = _require.isShiftDown;
  5745. var createSupplementaryPoints = require('../lib/create_supplementary_points');
  5746. var constrainFeatureMovement = require('../lib/constrain_feature_movement');
  5747. var doubleClickZoom = require('../lib/double_click_zoom');
  5748. var Constants = require('../constants');
  5749. var CommonSelectors = require('../lib/common_selectors');
  5750. var moveFeatures = require('../lib/move_features');
  5751. var isVertex = isOfMetaType(Constants.meta.VERTEX);
  5752. var isMidpoint = isOfMetaType(Constants.meta.MIDPOINT);
  5753. module.exports = function (ctx, opts) {
  5754. var featureId = opts.featureId;
  5755. var feature = ctx.store.get(featureId);
  5756. if (!feature) {
  5757. throw new Error('You must provide a featureId to enter direct_select mode');
  5758. }
  5759. if (feature.type === Constants.geojsonTypes.POINT) {
  5760. throw new TypeError('direct_select mode doesn\'t handle point features');
  5761. }
  5762. var dragMoveLocation = opts.startPos || null;
  5763. var dragMoving = false;
  5764. var canDragMove = false;
  5765. var selectedCoordPaths = opts.coordPath ? [opts.coordPath] : [];
  5766. var selectedCoordinates = pathsToCoordinates(featureId, selectedCoordPaths);
  5767. ctx.store.setSelectedCoordinates(selectedCoordinates);
  5768. var fireUpdate = function fireUpdate() {
  5769. ctx.map.fire(Constants.events.UPDATE, {
  5770. action: Constants.updateActions.CHANGE_COORDINATES,
  5771. features: ctx.store.getSelected().map(function (f) {
  5772. return f.toGeoJSON();
  5773. })
  5774. });
  5775. };
  5776. var fireActionable = function fireActionable() {
  5777. return ctx.events.actionable({
  5778. combineFeatures: false,
  5779. uncombineFeatures: false,
  5780. trash: selectedCoordPaths.length > 0
  5781. });
  5782. };
  5783. var startDragging = function startDragging(e) {
  5784. ctx.map.dragPan.disable();
  5785. canDragMove = true;
  5786. dragMoveLocation = e.lngLat;
  5787. };
  5788. var stopDragging = function stopDragging() {
  5789. ctx.map.dragPan.enable();
  5790. dragMoving = false;
  5791. canDragMove = false;
  5792. dragMoveLocation = null;
  5793. };
  5794. var onVertex = function onVertex(e) {
  5795. startDragging(e);
  5796. var about = e.featureTarget.properties;
  5797. var selectedIndex = selectedCoordPaths.indexOf(about.coord_path);
  5798. if (!isShiftDown(e) && selectedIndex === -1) {
  5799. selectedCoordPaths = [about.coord_path];
  5800. } else if (isShiftDown(e) && selectedIndex === -1) {
  5801. selectedCoordPaths.push(about.coord_path);
  5802. }
  5803. var selectedCoordinates = pathsToCoordinates(featureId, selectedCoordPaths);
  5804. ctx.store.setSelectedCoordinates(selectedCoordinates);
  5805. feature.changed();
  5806. };
  5807. var onMidpoint = function onMidpoint(e) {
  5808. startDragging(e);
  5809. var about = e.featureTarget.properties;
  5810. feature.addCoordinate(about.coord_path, about.lng, about.lat);
  5811. fireUpdate();
  5812. selectedCoordPaths = [about.coord_path];
  5813. };
  5814. function pathsToCoordinates(featureId, paths) {
  5815. return paths.map(function (coord_path) {
  5816. return { feature_id: featureId, coord_path: coord_path };
  5817. });
  5818. }
  5819. var onFeature = function onFeature(e) {
  5820. if (selectedCoordPaths.length === 0) startDragging(e);else stopDragging();
  5821. };
  5822. var dragFeature = function dragFeature(e, delta) {
  5823. moveFeatures(ctx.store.getSelected(), delta);
  5824. dragMoveLocation = e.lngLat;
  5825. };
  5826. var dragVertex = function dragVertex(e, delta) {
  5827. var selectedCoords = selectedCoordPaths.map(function (coord_path) {
  5828. return feature.getCoordinate(coord_path);
  5829. });
  5830. var selectedCoordPoints = selectedCoords.map(function (coords) {
  5831. return {
  5832. type: Constants.geojsonTypes.FEATURE,
  5833. properties: {},
  5834. geometry: {
  5835. type: Constants.geojsonTypes.POINT,
  5836. coordinates: coords
  5837. }
  5838. };
  5839. });
  5840. var constrainedDelta = constrainFeatureMovement(selectedCoordPoints, delta);
  5841. for (var i = 0; i < selectedCoords.length; i++) {
  5842. var coord = selectedCoords[i];
  5843. feature.updateCoordinate(selectedCoordPaths[i], coord[0] + constrainedDelta.lng, coord[1] + constrainedDelta.lat);
  5844. }
  5845. };
  5846. return {
  5847. start: function start() {
  5848. ctx.store.setSelected(featureId);
  5849. doubleClickZoom.disable(ctx);
  5850. // On mousemove that is not a drag, stop vertex movement.
  5851. this.on('mousemove', CommonSelectors.true, function (e) {
  5852. var isFeature = CommonSelectors.isActiveFeature(e);
  5853. var onVertex = isVertex(e);
  5854. var noCoords = selectedCoordPaths.length === 0;
  5855. if (isFeature && noCoords) ctx.ui.queueMapClasses({ mouse: Constants.cursors.MOVE });else if (onVertex && !noCoords) ctx.ui.queueMapClasses({ mouse: Constants.cursors.MOVE });else ctx.ui.queueMapClasses({ mouse: Constants.cursors.NONE });
  5856. stopDragging(e);
  5857. });
  5858. // As soon as you mouse leaves the canvas, update the feature
  5859. this.on('mouseout', function () {
  5860. return dragMoving;
  5861. }, fireUpdate);
  5862. this.on('mousedown', isVertex, onVertex);
  5863. this.on('touchstart', isVertex, onVertex);
  5864. this.on('mousedown', CommonSelectors.isActiveFeature, onFeature);
  5865. this.on('touchstart', CommonSelectors.isActiveFeature, onFeature);
  5866. this.on('mousedown', isMidpoint, onMidpoint);
  5867. this.on('touchstart', isMidpoint, onMidpoint);
  5868. this.on('drag', function () {
  5869. return canDragMove;
  5870. }, function (e) {
  5871. dragMoving = true;
  5872. e.originalEvent.stopPropagation();
  5873. var delta = {
  5874. lng: e.lngLat.lng - dragMoveLocation.lng,
  5875. lat: e.lngLat.lat - dragMoveLocation.lat
  5876. };
  5877. if (selectedCoordPaths.length > 0) dragVertex(e, delta);else dragFeature(e, delta);
  5878. dragMoveLocation = e.lngLat;
  5879. });
  5880. this.on('click', CommonSelectors.true, stopDragging);
  5881. this.on('mouseup', CommonSelectors.true, function () {
  5882. if (dragMoving) {
  5883. fireUpdate();
  5884. }
  5885. stopDragging();
  5886. });
  5887. this.on('touchend', CommonSelectors.true, function () {
  5888. if (dragMoving) {
  5889. fireUpdate();
  5890. }
  5891. stopDragging();
  5892. });
  5893. this.on('click', noTarget, clickNoTarget);
  5894. this.on('tap', noTarget, clickNoTarget);
  5895. this.on('click', isInactiveFeature, clickInactive);
  5896. this.on('tap', isInactiveFeature, clickInactive);
  5897. this.on('click', CommonSelectors.isActiveFeature, clickActiveFeature);
  5898. this.on('tap', CommonSelectors.isActiveFeature, clickActiveFeature);
  5899. function clickNoTarget() {
  5900. ctx.events.changeMode(Constants.modes.SIMPLE_SELECT);
  5901. }
  5902. function clickInactive() {
  5903. ctx.events.changeMode(Constants.modes.SIMPLE_SELECT);
  5904. }
  5905. function clickActiveFeature() {
  5906. selectedCoordPaths = [];
  5907. ctx.store.clearSelectedCoordinates();
  5908. feature.changed();
  5909. }
  5910. },
  5911. stop: function stop() {
  5912. doubleClickZoom.enable(ctx);
  5913. ctx.store.clearSelectedCoordinates();
  5914. },
  5915. render: function render(geojson, push) {
  5916. if (featureId === geojson.properties.id) {
  5917. geojson.properties.active = Constants.activeStates.ACTIVE;
  5918. push(geojson);
  5919. createSupplementaryPoints(geojson, {
  5920. map: ctx.map,
  5921. midpoints: true,
  5922. selectedPaths: selectedCoordPaths
  5923. }).forEach(push);
  5924. } else {
  5925. geojson.properties.active = Constants.activeStates.INACTIVE;
  5926. push(geojson);
  5927. }
  5928. fireActionable();
  5929. },
  5930. trash: function trash() {
  5931. selectedCoordPaths.sort().reverse().forEach(function (id) {
  5932. return feature.removeCoordinate(id);
  5933. });
  5934. ctx.map.fire(Constants.events.UPDATE, {
  5935. action: Constants.updateActions.CHANGE_COORDINATES,
  5936. features: ctx.store.getSelected().map(function (f) {
  5937. return f.toGeoJSON();
  5938. })
  5939. });
  5940. selectedCoordPaths = [];
  5941. ctx.store.clearSelectedCoordinates();
  5942. fireActionable();
  5943. if (feature.isValid() === false) {
  5944. ctx.store.delete([featureId]);
  5945. ctx.events.changeMode(Constants.modes.SIMPLE_SELECT, {});
  5946. }
  5947. }
  5948. };
  5949. };
  5950. },{"../constants":24,"../lib/common_selectors":31,"../lib/constrain_feature_movement":32,"../lib/create_supplementary_points":34,"../lib/double_click_zoom":36,"../lib/move_features":46}],54:[function(require,module,exports){
  5951. 'use strict';
  5952. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  5953. var CommonSelectors = require('../lib/common_selectors');
  5954. var LineString = require('../feature_types/line_string');
  5955. var isEventAtCoordinates = require('../lib/is_event_at_coordinates');
  5956. var doubleClickZoom = require('../lib/double_click_zoom');
  5957. var Constants = require('../constants');
  5958. var createVertex = require('../lib/create_vertex');
  5959. module.exports = function (ctx, opts) {
  5960. opts = opts || {};
  5961. var featureId = opts.featureId;
  5962. var line = void 0,
  5963. currentVertexPosition = void 0;
  5964. var direction = 'forward';
  5965. if (featureId) {
  5966. line = ctx.store.get(featureId);
  5967. if (!line) {
  5968. throw new Error('Could not find a feature with the provided featureId');
  5969. }
  5970. var from = opts.from;
  5971. if (from && from.type === 'Feature' && from.geometry && from.geometry.type === 'Point') {
  5972. from = from.geometry;
  5973. }
  5974. if (from && from.type === 'Point' && from.coordinates && from.coordinates.length === 2) {
  5975. from = from.coordinates;
  5976. }
  5977. if (!from || !Array.isArray(from)) {
  5978. throw new Error('Please use the `from` property to indicate which point to continue the line from');
  5979. }
  5980. var lastCoord = line.coordinates.length - 1;
  5981. if (line.coordinates[lastCoord][0] === from[0] && line.coordinates[lastCoord][1] === from[1]) {
  5982. var _line;
  5983. currentVertexPosition = lastCoord + 1;
  5984. // add one new coordinate to continue from
  5985. (_line = line).addCoordinate.apply(_line, [currentVertexPosition].concat(_toConsumableArray(line.coordinates[lastCoord])));
  5986. } else if (line.coordinates[0][0] === from[0] && line.coordinates[0][1] === from[1]) {
  5987. var _line2;
  5988. direction = 'backwards';
  5989. currentVertexPosition = 0;
  5990. // add one new coordinate to continue from
  5991. (_line2 = line).addCoordinate.apply(_line2, [currentVertexPosition].concat(_toConsumableArray(line.coordinates[0])));
  5992. } else {
  5993. throw new Error('`from` should match the point at either the start or the end of the provided LineString');
  5994. }
  5995. } else {
  5996. line = new LineString(ctx, {
  5997. type: Constants.geojsonTypes.FEATURE,
  5998. properties: {},
  5999. geometry: {
  6000. type: Constants.geojsonTypes.LINE_STRING,
  6001. coordinates: []
  6002. }
  6003. });
  6004. currentVertexPosition = 0;
  6005. ctx.store.add(line);
  6006. }
  6007. if (ctx._test) ctx._test.line = line;
  6008. return {
  6009. start: function start() {
  6010. ctx.store.clearSelected();
  6011. doubleClickZoom.disable(ctx);
  6012. ctx.ui.queueMapClasses({ mouse: Constants.cursors.ADD });
  6013. ctx.ui.setActiveButton(Constants.types.LINE);
  6014. this.on('mousemove', CommonSelectors.true, function (e) {
  6015. line.updateCoordinate(currentVertexPosition, e.lngLat.lng, e.lngLat.lat);
  6016. if (CommonSelectors.isVertex(e)) {
  6017. ctx.ui.queueMapClasses({ mouse: Constants.cursors.POINTER });
  6018. }
  6019. });
  6020. this.on('click', CommonSelectors.true, clickAnywhere);
  6021. this.on('tap', CommonSelectors.true, clickAnywhere);
  6022. this.on('click', CommonSelectors.isVertex, clickOnVertex);
  6023. this.on('tap', CommonSelectors.isVertex, clickOnVertex);
  6024. function clickAnywhere(e) {
  6025. if (currentVertexPosition > 0 && isEventAtCoordinates(e, line.coordinates[currentVertexPosition - 1]) || direction === 'backwards' && isEventAtCoordinates(e, line.coordinates[currentVertexPosition + 1])) {
  6026. //解决双击起点只出现起点文字就结束测量的问题
  6027. if(currentVertexPosition==1){
  6028. return;
  6029. }else{
  6030. return ctx.events.changeMode(Constants.modes.SIMPLE_SELECT, { featureIds: [line.id] });
  6031. };
  6032. }
  6033. ctx.ui.queueMapClasses({ mouse: Constants.cursors.ADD });
  6034. line.updateCoordinate(currentVertexPosition, e.lngLat.lng, e.lngLat.lat);
  6035. var data = ctx.draw.getAll();
  6036. if (data.features.length > 0) {
  6037. var leng = data.features.length;
  6038. var mark_fea =data.features[leng -1];
  6039. var bigImg_mea = document.createElement("div"); //创建一个div元素
  6040. if(mark_fea.geometry.coordinates.length === 1){
  6041. var htmlStr = '<p style="border:1px solid #ADADAD;background-color: white"><strong style="color: red">起点</strong></p>';
  6042. bigImg_mea.innerHTML = htmlStr;
  6043. bigImg_mea.className = 'marker_mea';
  6044. new GeoGlobe.Marker(bigImg_mea,{offset:[18,5]})
  6045. .setLngLat(mark_fea.geometry.coordinates[mark_fea.geometry.coordinates.length - 1])
  6046. .addTo(ctx.map);
  6047. }else{
  6048. //var rounded_distance = turf.lineDistance(mark_fea);
  6049. var lineDistance = turf.lineDistance(mark_fea);
  6050. var rounded_distance = Math.round(lineDistance * 100) / 100;
  6051. if(rounded_distance >= 1){
  6052. var htmlStr = '<p style="border:1px solid #ADADAD;background-color: white">距离:<strong style="color: red">' + rounded_distance.toFixed(1) + '</strong> 公里</p>';
  6053. }else if(rounded_distance < 1){
  6054. rounded_distance = rounded_distance * 1000;
  6055. var htmlStr = '<p style="border:1px solid #ADADAD;background-color: white">距离:<strong style="color: red">' + rounded_distance.toFixed(1) + '</strong> 米</p>';
  6056. }
  6057. bigImg_mea.innerHTML = htmlStr;
  6058. bigImg_mea.className = 'marker_mea';
  6059. new GeoGlobe.Marker(bigImg_mea,{offset:[45,10]})
  6060. .setLngLat(mark_fea.geometry.coordinates[mark_fea.geometry.coordinates.length - 1])
  6061. .addTo(ctx.map);
  6062. }
  6063. }
  6064. if (direction === 'forward') {
  6065. currentVertexPosition++;
  6066. } else {
  6067. line.addCoordinate(0, e.lngLat.lng, e.lngLat.lat);
  6068. }
  6069. }
  6070. function clickOnVertex() {
  6071. return ctx.events.changeMode(Constants.modes.SIMPLE_SELECT, { featureIds: [line.id] });
  6072. }
  6073. this.on('keyup', CommonSelectors.isEscapeKey, function () {
  6074. ctx.store.delete([line.id], { silent: true });
  6075. ctx.events.changeMode(Constants.modes.SIMPLE_SELECT);
  6076. });
  6077. this.on('keyup', CommonSelectors.isEnterKey, function () {
  6078. ctx.events.changeMode(Constants.modes.SIMPLE_SELECT, { featureIds: [line.id] });
  6079. });
  6080. ctx.events.actionable({
  6081. combineFeatures: false,
  6082. uncombineFeatures: false,
  6083. trash: true
  6084. });
  6085. },
  6086. stop: function stop() {
  6087. doubleClickZoom.enable(ctx);
  6088. ctx.ui.setActiveButton();
  6089. // check to see if we've deleted this feature
  6090. if (ctx.store.get(line.id) === undefined) return;
  6091. //remove last added coordinate
  6092. line.removeCoordinate('' + currentVertexPosition);
  6093. if (line.isValid()) {
  6094. ctx.map.fire(Constants.events.CREATE, {
  6095. features: [line.toGeoJSON()]
  6096. });
  6097. } else {
  6098. ctx.store.delete([line.id], { silent: true });
  6099. var length=ctx.container.firstElementChild.nextSibling.childNodes.length;
  6100. //解决点击起点后再点击结束绘制而出现的起点名称仍显示的问题
  6101. ctx.container.firstElementChild.nextSibling.childNodes[length-1].innerText="";
  6102. ctx.events.changeMode(Constants.modes.SIMPLE_SELECT, {}, { silent: true });
  6103. }
  6104. },
  6105. render: function render(geojson, callback) {
  6106. var isActiveLine = geojson.properties.id === line.id;
  6107. geojson.properties.active = isActiveLine ? Constants.activeStates.ACTIVE : Constants.activeStates.INACTIVE;
  6108. if (!isActiveLine) return callback(geojson);
  6109. // Only render the line if it has at least one real coordinate
  6110. if (geojson.geometry.coordinates.length < 2) return;
  6111. geojson.properties.meta = Constants.meta.FEATURE;
  6112. if (geojson.geometry.coordinates.length >= 3) {
  6113. callback(createVertex(line.id, geojson.geometry.coordinates[direction === 'forward' ? geojson.geometry.coordinates.length - 2 : 1], '' + (direction === 'forward' ? geojson.geometry.coordinates.length - 2 : 1), false));
  6114. }
  6115. callback(geojson);
  6116. },
  6117. trash: function trash() {
  6118. ctx.store.delete([line.id], { silent: true });
  6119. ctx.events.changeMode(Constants.modes.SIMPLE_SELECT);
  6120. }
  6121. };
  6122. };
  6123. },{"../constants":24,"../feature_types/line_string":27,"../lib/common_selectors":31,"../lib/create_vertex":35,"../lib/double_click_zoom":36,"../lib/is_event_at_coordinates":41}],55:[function(require,module,exports){
  6124. 'use strict';
  6125. var CommonSelectors = require('../lib/common_selectors');
  6126. var Point = require('../feature_types/point');
  6127. var Constants = require('../constants');
  6128. module.exports = function (ctx) {
  6129. var point = new Point(ctx, {
  6130. type: Constants.geojsonTypes.FEATURE,
  6131. properties: {},
  6132. geometry: {
  6133. type: Constants.geojsonTypes.POINT,
  6134. coordinates: []
  6135. }
  6136. });
  6137. if (ctx._test) ctx._test.point = point;
  6138. ctx.store.add(point);
  6139. function stopDrawingAndRemove() {
  6140. ctx.events.changeMode(Constants.modes.SIMPLE_SELECT);
  6141. ctx.store.delete([point.id], { silent: true });
  6142. }
  6143. function handleClick(e) {
  6144. ctx.ui.queueMapClasses({ mouse: Constants.cursors.MOVE });
  6145. point.updateCoordinate('', e.lngLat.lng, e.lngLat.lat);
  6146. ctx.map.fire(Constants.events.CREATE, {
  6147. features: [point.toGeoJSON()]
  6148. });
  6149. ctx.events.changeMode(Constants.modes.SIMPLE_SELECT, { featureIds: [point.id] });
  6150. }
  6151. return {
  6152. start: function start() {
  6153. ctx.store.clearSelected();
  6154. ctx.ui.queueMapClasses({ mouse: Constants.cursors.ADD });
  6155. ctx.ui.setActiveButton(Constants.types.POINT);
  6156. this.on('click', CommonSelectors.true, handleClick);
  6157. this.on('tap', CommonSelectors.true, handleClick);
  6158. this.on('keyup', CommonSelectors.isEscapeKey, stopDrawingAndRemove);
  6159. this.on('keyup', CommonSelectors.isEnterKey, stopDrawingAndRemove);
  6160. ctx.events.actionable({
  6161. combineFeatures: false,
  6162. uncombineFeatures: false,
  6163. trash: true
  6164. });
  6165. },
  6166. stop: function stop() {
  6167. ctx.ui.setActiveButton();
  6168. if (!point.getCoordinate().length) {
  6169. ctx.store.delete([point.id], { silent: true });
  6170. }
  6171. },
  6172. render: function render(geojson, callback) {
  6173. var isActivePoint = geojson.properties.id === point.id;
  6174. geojson.properties.active = isActivePoint ? Constants.activeStates.ACTIVE : Constants.activeStates.INACTIVE;
  6175. if (!isActivePoint) return callback(geojson);
  6176. // Never render the point we're drawing
  6177. },
  6178. trash: function trash() {
  6179. stopDrawingAndRemove();
  6180. }
  6181. };
  6182. };
  6183. },{"../constants":24,"../feature_types/point":29,"../lib/common_selectors":31}],56:[function(require,module,exports){
  6184. 'use strict';
  6185. var CommonSelectors = require('../lib/common_selectors');
  6186. var Polygon = require('../feature_types/polygon');
  6187. var doubleClickZoom = require('../lib/double_click_zoom');
  6188. var Constants = require('../constants');
  6189. var isEventAtCoordinates = require('../lib/is_event_at_coordinates');
  6190. var createVertex = require('../lib/create_vertex');
  6191. module.exports = function (ctx) {
  6192. var polygon = new Polygon(ctx, {
  6193. type: Constants.geojsonTypes.FEATURE,
  6194. properties: {},
  6195. geometry: {
  6196. type: Constants.geojsonTypes.POLYGON,
  6197. coordinates: [[]]
  6198. }
  6199. });
  6200. var currentVertexPosition = 0;
  6201. if (ctx._test) ctx._test.polygon = polygon;
  6202. ctx.store.add(polygon);
  6203. return {
  6204. start: function start() {
  6205. ctx.store.clearSelected();
  6206. doubleClickZoom.disable(ctx);
  6207. ctx.ui.queueMapClasses({ mouse: Constants.cursors.ADD });
  6208. ctx.ui.setActiveButton(Constants.types.POLYGON);
  6209. this.on('mousemove', CommonSelectors.true, function (e) {
  6210. polygon.updateCoordinate('0.' + currentVertexPosition, e.lngLat.lng, e.lngLat.lat);
  6211. if (CommonSelectors.isVertex(e)) {
  6212. ctx.ui.queueMapClasses({ mouse: Constants.cursors.POINTER });
  6213. }
  6214. });
  6215. this.on('click', CommonSelectors.true, clickAnywhere);//TODO
  6216. this.on('click', CommonSelectors.isVertex, clickOnVertex);
  6217. this.on('tap', CommonSelectors.true, clickAnywhere);
  6218. this.on('tap', CommonSelectors.isVertex, clickOnVertex);
  6219. function clickAnywhere(e) {//TODO
  6220. if (currentVertexPosition > 0 && isEventAtCoordinates(e, polygon.coordinates[0][currentVertexPosition - 1])) {
  6221. return ctx.events.changeMode(Constants.modes.SIMPLE_SELECT, { featureIds: [polygon.id] });
  6222. }
  6223. ctx.ui.queueMapClasses({ mouse: Constants.cursors.ADD });
  6224. polygon.updateCoordinate('0.' + currentVertexPosition, e.lngLat.lng, e.lngLat.lat);
  6225. currentVertexPosition++;
  6226. }
  6227. function clickOnVertex() {
  6228. return ctx.events.changeMode(Constants.modes.SIMPLE_SELECT, { featureIds: [polygon.id] });
  6229. }
  6230. this.on('keyup', CommonSelectors.isEscapeKey, function () {
  6231. ctx.store.delete([polygon.id], { silent: true });
  6232. ctx.events.changeMode(Constants.modes.SIMPLE_SELECT);
  6233. });
  6234. this.on('keyup', CommonSelectors.isEnterKey, function () {
  6235. ctx.events.changeMode(Constants.modes.SIMPLE_SELECT, { featureIds: [polygon.id] });
  6236. });
  6237. ctx.events.actionable({
  6238. combineFeatures: false,
  6239. uncombineFeatures: false,
  6240. trash: true
  6241. });
  6242. },
  6243. stop: function stop() {//TODO
  6244. ctx.ui.queueMapClasses({ mouse: Constants.cursors.NONE });
  6245. doubleClickZoom.enable(ctx);
  6246. ctx.ui.setActiveButton();
  6247. // check to see if we've deleted this feature
  6248. if (ctx.store.get(polygon.id) === undefined) return;
  6249. //remove last added coordinate
  6250. polygon.removeCoordinate('0.' + currentVertexPosition);
  6251. if (polygon.isValid()) {
  6252. ctx.map.fire(Constants.events.CREATE, {
  6253. features: [polygon.toGeoJSON()]
  6254. });
  6255. } else {
  6256. ctx.store.delete([polygon.id], { silent: true });
  6257. ctx.events.changeMode(Constants.modes.SIMPLE_SELECT, {}, { silent: true });
  6258. }
  6259. },
  6260. render: function render(geojson, callback) {
  6261. var isActivePolygon = geojson.properties.id === polygon.id;
  6262. geojson.properties.active = isActivePolygon ? Constants.activeStates.ACTIVE : Constants.activeStates.INACTIVE;
  6263. if (!isActivePolygon) return callback(geojson);
  6264. // Don't render a polygon until it has two positions
  6265. // (and a 3rd which is just the first repeated)
  6266. if (geojson.geometry.coordinates.length === 0) return;
  6267. var coordinateCount = geojson.geometry.coordinates[0].length;
  6268. // If we have fewer than two positions (plus the closer),
  6269. // it's not yet a shape to render
  6270. if (coordinateCount < 3) return;
  6271. geojson.properties.meta = Constants.meta.FEATURE;
  6272. if (coordinateCount > 4) {
  6273. // Add a start position marker to the map, clicking on this will finish the feature
  6274. // This should only be shown when we're in a valid spot
  6275. callback(createVertex(polygon.id, geojson.geometry.coordinates[0][0], '0.0', false));
  6276. var endPos = geojson.geometry.coordinates[0].length - 3;
  6277. callback(createVertex(polygon.id, geojson.geometry.coordinates[0][endPos], '0.' + endPos, false));
  6278. }
  6279. // If we have more than two positions (plus the closer),
  6280. // render the Polygon
  6281. if (coordinateCount > 3) {
  6282. return callback(geojson);
  6283. }
  6284. // If we've only drawn two positions (plus the closer),
  6285. // make a LineString instead of a Polygon
  6286. var lineCoordinates = [[geojson.geometry.coordinates[0][0][0], geojson.geometry.coordinates[0][0][1]], [geojson.geometry.coordinates[0][1][0], geojson.geometry.coordinates[0][1][1]]];
  6287. return callback({
  6288. type: Constants.geojsonTypes.FEATURE,
  6289. properties: geojson.properties,
  6290. geometry: {
  6291. coordinates: lineCoordinates,
  6292. type: Constants.geojsonTypes.LINE_STRING
  6293. }
  6294. });
  6295. },
  6296. trash: function trash() {
  6297. ctx.store.delete([polygon.id], { silent: true });
  6298. ctx.events.changeMode(Constants.modes.SIMPLE_SELECT);
  6299. }
  6300. };
  6301. };
  6302. },{"../constants":24,"../feature_types/polygon":30,"../lib/common_selectors":31,"../lib/create_vertex":35,"../lib/double_click_zoom":36,"../lib/is_event_at_coordinates":41}],57:[function(require,module,exports){
  6303. 'use strict';
  6304. var CommonSelectors = require('../lib/common_selectors');
  6305. var mouseEventPoint = require('../lib/mouse_event_point');
  6306. var featuresAt = require('../lib/features_at');
  6307. var createSupplementaryPoints = require('../lib/create_supplementary_points');
  6308. var StringSet = require('../lib/string_set');
  6309. var doubleClickZoom = require('../lib/double_click_zoom');
  6310. var moveFeatures = require('../lib/move_features');
  6311. var Constants = require('../constants');
  6312. var MultiFeature = require('../feature_types/multi_feature');
  6313. module.exports = function (ctx) {
  6314. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  6315. var dragMoveLocation = null;
  6316. var boxSelectStartLocation = null;
  6317. var boxSelectElement = void 0;
  6318. var boxSelecting = false;
  6319. var canBoxSelect = false;
  6320. var dragMoving = false;
  6321. var canDragMove = false;
  6322. var initiallySelectedFeatureIds = options.featureIds || [];
  6323. var fireUpdate = function fireUpdate() {
  6324. ctx.map.fire(Constants.events.UPDATE, {
  6325. action: Constants.updateActions.MOVE,
  6326. features: ctx.store.getSelected().map(function (f) {
  6327. return f.toGeoJSON();
  6328. })
  6329. });
  6330. };
  6331. var fireActionable = function fireActionable() {
  6332. var selectedFeatures = ctx.store.getSelected();
  6333. var multiFeatures = selectedFeatures.filter(function (feature) {
  6334. return feature instanceof MultiFeature;
  6335. });
  6336. var combineFeatures = false;
  6337. if (selectedFeatures.length > 1) {
  6338. combineFeatures = true;
  6339. var featureType = selectedFeatures[0].type.replace('Multi', '');
  6340. selectedFeatures.forEach(function (feature) {
  6341. if (feature.type.replace('Multi', '') !== featureType) {
  6342. combineFeatures = false;
  6343. }
  6344. });
  6345. }
  6346. var uncombineFeatures = multiFeatures.length > 0;
  6347. var trash = selectedFeatures.length > 0;
  6348. ctx.events.actionable({
  6349. combineFeatures: combineFeatures, uncombineFeatures: uncombineFeatures, trash: trash
  6350. });
  6351. };
  6352. var getUniqueIds = function getUniqueIds(allFeatures) {
  6353. if (!allFeatures.length) return [];
  6354. var ids = allFeatures.map(function (s) {
  6355. return s.properties.id;
  6356. }).filter(function (id) {
  6357. return id !== undefined;
  6358. }).reduce(function (memo, id) {
  6359. memo.add(id);
  6360. return memo;
  6361. }, new StringSet());
  6362. return ids.values();
  6363. };
  6364. var stopExtendedInteractions = function stopExtendedInteractions() {
  6365. if (boxSelectElement) {
  6366. if (boxSelectElement.parentNode) boxSelectElement.parentNode.removeChild(boxSelectElement);
  6367. boxSelectElement = null;
  6368. }
  6369. ctx.map.dragPan.enable();
  6370. boxSelecting = false;
  6371. canBoxSelect = false;
  6372. dragMoving = false;
  6373. canDragMove = false;
  6374. };
  6375. return {
  6376. stop: function stop() {
  6377. doubleClickZoom.enable(ctx);
  6378. },
  6379. start: function start() {
  6380. // Select features that should start selected,
  6381. // probably passed in from a `draw_*` mode
  6382. if (ctx.store) {
  6383. ctx.store.setSelected(initiallySelectedFeatureIds.filter(function (id) {
  6384. return ctx.store.get(id) !== undefined;
  6385. }));
  6386. fireActionable();
  6387. }
  6388. // Any mouseup should stop box selecting and dragMoving
  6389. this.on('mouseup', CommonSelectors.true, stopExtendedInteractions);
  6390. // On mousemove that is not a drag, stop extended interactions.
  6391. // This is useful if you drag off the canvas, release the button,
  6392. // then move the mouse back over the canvas --- we don't allow the
  6393. // interaction to continue then, but we do let it continue if you held
  6394. // the mouse button that whole time
  6395. this.on('mousemove', CommonSelectors.true, stopExtendedInteractions);
  6396. // As soon as you mouse leaves the canvas, update the feature
  6397. this.on('mouseout', function () {
  6398. return dragMoving;
  6399. }, fireUpdate);
  6400. // Click (with or without shift) on no feature
  6401. this.on('click', CommonSelectors.noTarget, clickAnywhere);
  6402. this.on('tap', CommonSelectors.noTarget, clickAnywhere);
  6403. // Click (with or without shift) on a vertex
  6404. this.on('click', CommonSelectors.isOfMetaType(Constants.meta.VERTEX), clickOnVertex);
  6405. this.on('tap', CommonSelectors.isOfMetaType(Constants.meta.VERTEX), clickOnVertex);
  6406. function clickAnywhere() {
  6407. var _this = this;
  6408. // Clear the re-render selection
  6409. var wasSelected = ctx.store.getSelectedIds();
  6410. if (wasSelected.length) {
  6411. ctx.store.clearSelected();
  6412. wasSelected.forEach(function (id) {
  6413. return _this.render(id);
  6414. });
  6415. }
  6416. doubleClickZoom.enable(ctx);
  6417. stopExtendedInteractions();
  6418. }
  6419. function clickOnVertex(e) {
  6420. // Enter direct select mode
  6421. ctx.events.changeMode(Constants.modes.DIRECT_SELECT, {
  6422. featureId: e.featureTarget.properties.parent,
  6423. coordPath: e.featureTarget.properties.coord_path,
  6424. startPos: e.lngLat
  6425. });
  6426. ctx.ui.queueMapClasses({ mouse: Constants.cursors.MOVE });
  6427. }
  6428. // Mousedown on a selected feature
  6429. this.on('mousedown', CommonSelectors.isActiveFeature, startOnActiveFeature);
  6430. this.on('touchstart', CommonSelectors.isActiveFeature, startOnActiveFeature);
  6431. function startOnActiveFeature(e) {
  6432. // Stop any already-underway extended interactions
  6433. stopExtendedInteractions();
  6434. // Disable map.dragPan immediately so it can't start
  6435. ctx.map.dragPan.disable();
  6436. // Re-render it and enable drag move
  6437. this.render(e.featureTarget.properties.id);
  6438. // Set up the state for drag moving
  6439. canDragMove = true;
  6440. dragMoveLocation = e.lngLat;
  6441. }
  6442. // Click (with or without shift) on any feature
  6443. this.on('click', CommonSelectors.isFeature, clickOnFeature);
  6444. this.on('tap', CommonSelectors.isFeature, clickOnFeature);
  6445. function clickOnFeature(e) {
  6446. // Stop everything
  6447. doubleClickZoom.disable(ctx);
  6448. stopExtendedInteractions();
  6449. var isShiftClick = CommonSelectors.isShiftDown(e);
  6450. var selectedFeatureIds = ctx.store.getSelectedIds();
  6451. var featureId = e.featureTarget.properties.id;
  6452. var isFeatureSelected = ctx.store.isSelected(featureId);
  6453. // Click (without shift) on any selected feature but a point
  6454. if (!isShiftClick && isFeatureSelected && ctx.store.get(featureId).type !== Constants.geojsonTypes.POINT) {
  6455. // Enter direct select mode
  6456. return ctx.events.changeMode(Constants.modes.DIRECT_SELECT, {
  6457. featureId: featureId
  6458. });
  6459. }
  6460. // Shift-click on a selected feature
  6461. if (isFeatureSelected && isShiftClick) {
  6462. // Deselect it
  6463. ctx.store.deselect(featureId);
  6464. ctx.ui.queueMapClasses({ mouse: Constants.cursors.POINTER });
  6465. if (selectedFeatureIds.length === 1) {
  6466. doubleClickZoom.enable(ctx);
  6467. }
  6468. // Shift-click on an unselected feature
  6469. } else if (!isFeatureSelected && isShiftClick) {
  6470. // Add it to the selection
  6471. ctx.store.select(featureId);
  6472. ctx.ui.queueMapClasses({ mouse: Constants.cursors.MOVE });
  6473. // Click (without shift) on an unselected feature
  6474. } else if (!isFeatureSelected && !isShiftClick) {
  6475. // Make it the only selected feature
  6476. selectedFeatureIds.forEach(this.render);
  6477. ctx.store.setSelected(featureId);
  6478. ctx.ui.queueMapClasses({ mouse: Constants.cursors.MOVE });
  6479. }
  6480. // No matter what, re-render the clicked feature
  6481. this.render(featureId);
  6482. }
  6483. // Dragging when drag move is enabled
  6484. this.on('drag', function () {
  6485. return canDragMove;
  6486. }, function (e) {
  6487. dragMoving = true;
  6488. e.originalEvent.stopPropagation();
  6489. var delta = {
  6490. lng: e.lngLat.lng - dragMoveLocation.lng,
  6491. lat: e.lngLat.lat - dragMoveLocation.lat
  6492. };
  6493. moveFeatures(ctx.store.getSelected(), delta);
  6494. dragMoveLocation = e.lngLat;
  6495. });
  6496. // Mouseup, always
  6497. this.on('mouseup', CommonSelectors.true, function (e) {
  6498. // End any extended interactions
  6499. if (dragMoving) {
  6500. fireUpdate();
  6501. } else if (boxSelecting) {
  6502. var bbox = [boxSelectStartLocation, mouseEventPoint(e.originalEvent, ctx.container)];
  6503. var featuresInBox = featuresAt.click(null, bbox, ctx);
  6504. var idsToSelect = getUniqueIds(featuresInBox).filter(function (id) {
  6505. return !ctx.store.isSelected(id);
  6506. });
  6507. if (idsToSelect.length) {
  6508. ctx.store.select(idsToSelect);
  6509. idsToSelect.forEach(this.render);
  6510. ctx.ui.queueMapClasses({ mouse: Constants.cursors.MOVE });
  6511. }
  6512. }
  6513. stopExtendedInteractions();
  6514. });
  6515. if (ctx.options.boxSelect) {
  6516. // Shift-mousedown anywhere
  6517. this.on('mousedown', CommonSelectors.isShiftMousedown, function (e) {
  6518. stopExtendedInteractions();
  6519. ctx.map.dragPan.disable();
  6520. // Enable box select
  6521. boxSelectStartLocation = mouseEventPoint(e.originalEvent, ctx.container);
  6522. canBoxSelect = true;
  6523. });
  6524. // Drag when box select is enabled
  6525. this.on('drag', function () {
  6526. return canBoxSelect;
  6527. }, function (e) {
  6528. boxSelecting = true;
  6529. ctx.ui.queueMapClasses({ mouse: Constants.cursors.ADD });
  6530. // Create the box node if it doesn't exist
  6531. if (!boxSelectElement) {
  6532. boxSelectElement = document.createElement('div');
  6533. boxSelectElement.classList.add(Constants.classes.BOX_SELECT);
  6534. ctx.container.appendChild(boxSelectElement);
  6535. }
  6536. // Adjust the box node's width and xy position
  6537. var current = mouseEventPoint(e.originalEvent, ctx.container);
  6538. var minX = Math.min(boxSelectStartLocation.x, current.x);
  6539. var maxX = Math.max(boxSelectStartLocation.x, current.x);
  6540. var minY = Math.min(boxSelectStartLocation.y, current.y);
  6541. var maxY = Math.max(boxSelectStartLocation.y, current.y);
  6542. var translateValue = 'translate(' + minX + 'px, ' + minY + 'px)';
  6543. boxSelectElement.style.transform = translateValue;
  6544. boxSelectElement.style.WebkitTransform = translateValue;
  6545. boxSelectElement.style.width = maxX - minX + 'px';
  6546. boxSelectElement.style.height = maxY - minY + 'px';
  6547. });
  6548. }
  6549. },
  6550. render: function render(geojson, push) {
  6551. geojson.properties.active = ctx.store.isSelected(geojson.properties.id) ? Constants.activeStates.ACTIVE : Constants.activeStates.INACTIVE;
  6552. push(geojson);
  6553. fireActionable();
  6554. if (geojson.properties.active !== Constants.activeStates.ACTIVE || geojson.geometry.type === Constants.geojsonTypes.POINT) return;
  6555. createSupplementaryPoints(geojson).forEach(push);
  6556. },
  6557. trash: function trash() {
  6558. ctx.store.delete(ctx.store.getSelectedIds());
  6559. fireActionable();
  6560. },
  6561. combineFeatures: function combineFeatures() {
  6562. var selectedFeatures = ctx.store.getSelected();
  6563. if (selectedFeatures.length === 0 || selectedFeatures.length < 2) return;
  6564. var coordinates = [],
  6565. featuresCombined = [];
  6566. var featureType = selectedFeatures[0].type.replace('Multi', '');
  6567. for (var i = 0; i < selectedFeatures.length; i++) {
  6568. var feature = selectedFeatures[i];
  6569. if (feature.type.replace('Multi', '') !== featureType) {
  6570. return;
  6571. }
  6572. if (feature.type.includes('Multi')) {
  6573. feature.getCoordinates().forEach(function (subcoords) {
  6574. coordinates.push(subcoords);
  6575. });
  6576. } else {
  6577. coordinates.push(feature.getCoordinates());
  6578. }
  6579. featuresCombined.push(feature.toGeoJSON());
  6580. }
  6581. if (featuresCombined.length > 1) {
  6582. var multiFeature = new MultiFeature(ctx, {
  6583. type: Constants.geojsonTypes.FEATURE,
  6584. properties: featuresCombined[0].properties,
  6585. geometry: {
  6586. type: 'Multi' + featureType,
  6587. coordinates: coordinates
  6588. }
  6589. });
  6590. ctx.store.add(multiFeature);
  6591. ctx.store.delete(ctx.store.getSelectedIds(), { silent: true });
  6592. ctx.store.setSelected([multiFeature.id]);
  6593. ctx.map.fire(Constants.events.COMBINE_FEATURES, {
  6594. createdFeatures: [multiFeature.toGeoJSON()],
  6595. deletedFeatures: featuresCombined
  6596. });
  6597. }
  6598. fireActionable();
  6599. },
  6600. uncombineFeatures: function uncombineFeatures() {
  6601. var selectedFeatures = ctx.store.getSelected();
  6602. if (selectedFeatures.length === 0) return;
  6603. var createdFeatures = [];
  6604. var featuresUncombined = [];
  6605. var _loop = function _loop(i) {
  6606. var feature = selectedFeatures[i];
  6607. if (feature instanceof MultiFeature) {
  6608. feature.getFeatures().forEach(function (subFeature) {
  6609. ctx.store.add(subFeature);
  6610. subFeature.properties = feature.properties;
  6611. createdFeatures.push(subFeature.toGeoJSON());
  6612. ctx.store.select([subFeature.id]);
  6613. });
  6614. ctx.store.delete(feature.id, { silent: true });
  6615. featuresUncombined.push(feature.toGeoJSON());
  6616. }
  6617. };
  6618. for (var i = 0; i < selectedFeatures.length; i++) {
  6619. _loop(i);
  6620. }
  6621. if (createdFeatures.length > 1) {
  6622. ctx.map.fire(Constants.events.UNCOMBINE_FEATURES, {
  6623. createdFeatures: createdFeatures,
  6624. deletedFeatures: featuresUncombined
  6625. });
  6626. }
  6627. fireActionable();
  6628. }
  6629. };
  6630. };
  6631. },{"../constants":24,"../feature_types/multi_feature":28,"../lib/common_selectors":31,"../lib/create_supplementary_points":34,"../lib/double_click_zoom":36,"../lib/features_at":38,"../lib/mouse_event_point":45,"../lib/move_features":46,"../lib/string_set":48}],58:[function(require,module,exports){
  6632. "use strict";
  6633. module.exports = function (ctx) {
  6634. return {
  6635. stop: function stop() {},
  6636. start: function start() {
  6637. ctx.events.actionable({
  6638. combineFeatures: false,
  6639. uncombineFeatures: false,
  6640. trash: false
  6641. });
  6642. },
  6643. render: function render(geojson, push) {
  6644. push(geojson);
  6645. }
  6646. };
  6647. };
  6648. },{}],59:[function(require,module,exports){
  6649. 'use strict';
  6650. var xtend = require('xtend');
  6651. var Constants = require('./constants');
  6652. var defaultOptions = {
  6653. defaultMode: Constants.modes.SIMPLE_SELECT,
  6654. keybindings: true,
  6655. touchEnabled: true,
  6656. clickBuffer: 2,
  6657. touchBuffer: 25,
  6658. boxSelect: true,
  6659. displayControlsDefault: true,
  6660. styles: require('./lib/theme'),
  6661. controls: {},
  6662. userProperties: false
  6663. };
  6664. var showControls = {
  6665. point: true,
  6666. line_string: true,
  6667. polygon: true,
  6668. trash: true,
  6669. combine_features: true,
  6670. uncombine_features: true
  6671. };
  6672. var hideControls = {
  6673. point: false,
  6674. line_string: false,
  6675. polygon: false,
  6676. trash: false,
  6677. combine_features: false,
  6678. uncombine_features: false
  6679. };
  6680. function addSources(styles, sourceBucket) {
  6681. return styles.map(function (style) {
  6682. if (style.source) return style;
  6683. return xtend(style, {
  6684. id: style.id + '.' + sourceBucket,
  6685. source: sourceBucket === 'hot' ? Constants.sources.HOT : Constants.sources.COLD
  6686. });
  6687. });
  6688. }
  6689. module.exports = function () {
  6690. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  6691. var withDefaults = xtend(options);
  6692. if (!options.controls) {
  6693. withDefaults.controls = {};
  6694. }
  6695. if (options.displayControlsDefault === false) {
  6696. withDefaults.controls = xtend(hideControls, options.controls);
  6697. } else {
  6698. withDefaults.controls = xtend(showControls, options.controls);
  6699. }
  6700. withDefaults = xtend(defaultOptions, withDefaults);
  6701. // Layers with a shared source should be adjacent for performance reasons
  6702. withDefaults.styles = addSources(withDefaults.styles, 'cold').concat(addSources(withDefaults.styles, 'hot'));
  6703. return withDefaults;
  6704. };
  6705. },{"./constants":24,"./lib/theme":50,"xtend":22}],60:[function(require,module,exports){
  6706. 'use strict';
  6707. var Constants = require('./constants');
  6708. module.exports = function render() {
  6709. var store = this;
  6710. var mapExists = store.ctx.map && store.ctx.map.getSource(Constants.sources.HOT) !== undefined;
  6711. if (!mapExists) return cleanup();
  6712. var mode = store.ctx.events.currentModeName();
  6713. store.ctx.ui.queueMapClasses({ mode: mode });
  6714. var newHotIds = [];
  6715. var newColdIds = [];
  6716. if (store.isDirty) {
  6717. newColdIds = store.getAllIds();
  6718. } else {
  6719. newHotIds = store.getChangedIds().filter(function (id) {
  6720. return store.get(id) !== undefined;
  6721. });
  6722. newColdIds = store.sources.hot.filter(function (geojson) {
  6723. return geojson.properties.id && newHotIds.indexOf(geojson.properties.id) === -1 && store.get(geojson.properties.id) !== undefined;
  6724. }).map(function (geojson) {
  6725. return geojson.properties.id;
  6726. });
  6727. }
  6728. store.sources.hot = [];
  6729. var lastColdCount = store.sources.cold.length;
  6730. store.sources.cold = store.isDirty ? [] : store.sources.cold.filter(function (geojson) {
  6731. var id = geojson.properties.id || geojson.properties.parent;
  6732. return newHotIds.indexOf(id) === -1;
  6733. });
  6734. var coldChanged = lastColdCount !== store.sources.cold.length || newColdIds.length > 0;
  6735. newHotIds.forEach(function (id) {
  6736. return renderFeature(id, 'hot');
  6737. });
  6738. newColdIds.forEach(function (id) {
  6739. return renderFeature(id, 'cold');
  6740. });
  6741. function renderFeature(id, source) {
  6742. var feature = store.get(id);
  6743. var featureInternal = feature.internal(mode);
  6744. store.ctx.events.currentModeRender(featureInternal, function (geojson) {
  6745. store.sources[source].push(geojson);
  6746. });
  6747. }
  6748. if (coldChanged) {
  6749. store.ctx.map.getSource(Constants.sources.COLD).setData({
  6750. type: Constants.geojsonTypes.FEATURE_COLLECTION,
  6751. features: store.sources.cold
  6752. });
  6753. }
  6754. store.ctx.map.getSource(Constants.sources.HOT).setData({
  6755. type: Constants.geojsonTypes.FEATURE_COLLECTION,
  6756. features: store.sources.hot
  6757. });
  6758. if (store._emitSelectionChange) {
  6759. store.ctx.map.fire(Constants.events.SELECTION_CHANGE, {
  6760. features: store.getSelected().map(function (feature) {
  6761. return feature.toGeoJSON();
  6762. }),
  6763. points: store.getSelectedCoordinates().map(function (coordinate) {
  6764. return {
  6765. type: Constants.geojsonTypes.FEATURE,
  6766. properties: {},
  6767. geometry: {
  6768. type: Constants.geojsonTypes.POINT,
  6769. coordinates: coordinate.coordinates
  6770. }
  6771. };
  6772. })
  6773. });
  6774. store._emitSelectionChange = false;
  6775. }
  6776. if (store._deletedFeaturesToEmit.length) {
  6777. var geojsonToEmit = store._deletedFeaturesToEmit.map(function (feature) {
  6778. return feature.toGeoJSON();
  6779. });
  6780. store._deletedFeaturesToEmit = [];
  6781. store.ctx.map.fire(Constants.events.DELETE, {
  6782. features: geojsonToEmit
  6783. });
  6784. }
  6785. store.ctx.map.fire(Constants.events.RENDER, {});
  6786. cleanup();
  6787. function cleanup() {
  6788. store.isDirty = false;
  6789. store.clearChangedIds();
  6790. }
  6791. };
  6792. },{"./constants":24}],61:[function(require,module,exports){
  6793. 'use strict';
  6794. var events = require('./events');
  6795. var Store = require('./store');
  6796. var ui = require('./ui');
  6797. var Constants = require('./constants');
  6798. module.exports = function (ctx) {
  6799. ctx.events = events(ctx);
  6800. ctx.map = null;
  6801. ctx.container = null;
  6802. ctx.store = null;
  6803. ctx.ui = ui(ctx);
  6804. var controlContainer = null;
  6805. var setup = {
  6806. onRemove: function onRemove() {
  6807. setup.removeLayers();
  6808. ctx.ui.removeButtons();
  6809. ctx.events.removeEventListeners();
  6810. ctx.map = null;
  6811. ctx.container = null;
  6812. ctx.store = null;
  6813. if (controlContainer && controlContainer.parentNode) controlContainer.parentNode.removeChild(controlContainer);
  6814. controlContainer = null;
  6815. return this;
  6816. },
  6817. onAdd: function onAdd(map) {
  6818. ctx.draw = this;
  6819. ctx.map = map;
  6820. ctx.container = map.getContainer();
  6821. ctx.store = new Store(ctx);
  6822. controlContainer = ctx.ui.addButtons();
  6823. if (ctx.options.boxSelect) {
  6824. map.boxZoom.disable();
  6825. // Need to toggle dragPan on and off or else first
  6826. // dragPan disable attempt in simple_select doesn't work
  6827. map.dragPan.disable();
  6828. map.dragPan.enable();
  6829. }
  6830. var intervalId = null;
  6831. var connect = function connect() {
  6832. map.off('load', connect);
  6833. clearInterval(intervalId);
  6834. setup.addLayers();
  6835. ctx.events.addEventListeners();
  6836. };
  6837. if (map.loaded()) {
  6838. connect();
  6839. } else {
  6840. map.on('load', connect);
  6841. intervalId = setInterval(function () {
  6842. if (map.loaded()) connect();
  6843. }, 16);
  6844. }
  6845. return controlContainer;
  6846. },
  6847. addLayers: function addLayers() {
  6848. // drawn features style
  6849. ctx.map.addSource(Constants.sources.COLD, {
  6850. data: {
  6851. type: Constants.geojsonTypes.FEATURE_COLLECTION,
  6852. features: []
  6853. },
  6854. type: 'geojson'
  6855. });
  6856. // hot features style
  6857. ctx.map.addSource(Constants.sources.HOT, {
  6858. data: {
  6859. type: Constants.geojsonTypes.FEATURE_COLLECTION,
  6860. features: []
  6861. },
  6862. type: 'geojson'
  6863. });
  6864. ctx.options.styles.forEach(function (style) {
  6865. ctx.map.addLayer(style);
  6866. });
  6867. ctx.store.render();
  6868. },
  6869. removeLayers: function removeLayers() {
  6870. ctx.options.styles.forEach(function (style) {
  6871. ctx.map.removeLayer(style.id);
  6872. });
  6873. ctx.map.removeSource(Constants.sources.COLD);
  6874. ctx.map.removeSource(Constants.sources.HOT);
  6875. }
  6876. };
  6877. ctx.setup = setup;
  6878. return setup;
  6879. };
  6880. },{"./constants":24,"./events":25,"./store":62,"./ui":63}],62:[function(require,module,exports){
  6881. 'use strict';
  6882. var throttle = require('./lib/throttle');
  6883. var toDenseArray = require('./lib/to_dense_array');
  6884. var StringSet = require('./lib/string_set');
  6885. var render = require('./render');
  6886. var Store = module.exports = function (ctx) {
  6887. this._features = {};
  6888. this._featureIds = new StringSet();
  6889. this._selectedFeatureIds = new StringSet();
  6890. this._selectedCoordinates = [];
  6891. this._changedFeatureIds = new StringSet();
  6892. this._deletedFeaturesToEmit = [];
  6893. this._emitSelectionChange = false;
  6894. this.ctx = ctx;
  6895. this.sources = {
  6896. hot: [],
  6897. cold: []
  6898. };
  6899. this.render = throttle(render, 16, this);
  6900. this.isDirty = false;
  6901. };
  6902. /**
  6903. * Delays all rendering until the returned function is invoked
  6904. * @return {Function} renderBatch
  6905. */
  6906. Store.prototype.createRenderBatch = function () {
  6907. var _this = this;
  6908. var holdRender = this.render;
  6909. var numRenders = 0;
  6910. this.render = function () {
  6911. numRenders++;
  6912. };
  6913. return function () {
  6914. _this.render = holdRender;
  6915. if (numRenders > 0) {
  6916. _this.render();
  6917. }
  6918. };
  6919. };
  6920. /**
  6921. * Sets the store's state to dirty.
  6922. * @return {Store} this
  6923. */
  6924. Store.prototype.setDirty = function () {
  6925. this.isDirty = true;
  6926. return this;
  6927. };
  6928. /**
  6929. * Sets a feature's state to changed.
  6930. * @param {string} featureId
  6931. * @return {Store} this
  6932. */
  6933. Store.prototype.featureChanged = function (featureId) {
  6934. this._changedFeatureIds.add(featureId);
  6935. return this;
  6936. };
  6937. /**
  6938. * Gets the ids of all features currently in changed state.
  6939. * @return {Store} this
  6940. */
  6941. Store.prototype.getChangedIds = function () {
  6942. return this._changedFeatureIds.values();
  6943. };
  6944. /**
  6945. * Sets all features to unchanged state.
  6946. * @return {Store} this
  6947. */
  6948. Store.prototype.clearChangedIds = function () {
  6949. this._changedFeatureIds.clear();
  6950. return this;
  6951. };
  6952. /**
  6953. * Gets the ids of all features in the store.
  6954. * @return {Store} this
  6955. */
  6956. Store.prototype.getAllIds = function () {
  6957. return this._featureIds.values();
  6958. };
  6959. /**
  6960. * Adds a feature to the store.
  6961. * @param {Object} feature
  6962. *
  6963. * @return {Store} this
  6964. */
  6965. Store.prototype.add = function (feature) {
  6966. this.featureChanged(feature.id);
  6967. this._features[feature.id] = feature;
  6968. this._featureIds.add(feature.id);
  6969. return this;
  6970. };
  6971. /**
  6972. * Deletes a feature or array of features from the store.
  6973. * Cleans up after the deletion by deselecting the features.
  6974. * If changes were made, sets the state to the dirty
  6975. * and fires an event.
  6976. * @param {string | Array<string>} featureIds
  6977. * @param {Object} [options]
  6978. * @param {Object} [options.silent] - If `true`, this invocation will not fire an event.
  6979. * @return {Store} this
  6980. */
  6981. Store.prototype.delete = function (featureIds) {
  6982. var _this2 = this;
  6983. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  6984. toDenseArray(featureIds).forEach(function (id) {
  6985. if (!_this2._featureIds.has(id)) return;
  6986. _this2._featureIds.delete(id);
  6987. _this2._selectedFeatureIds.delete(id);
  6988. if (!options.silent) {
  6989. if (_this2._deletedFeaturesToEmit.indexOf(_this2._features[id]) === -1) {
  6990. _this2._deletedFeaturesToEmit.push(_this2._features[id]);
  6991. }
  6992. }
  6993. delete _this2._features[id];
  6994. _this2.isDirty = true;
  6995. });
  6996. refreshSelectedCoordinates.call(this, options);
  6997. return this;
  6998. };
  6999. /**
  7000. * Returns a feature in the store matching the specified value.
  7001. * @return {Object | undefined} feature
  7002. */
  7003. Store.prototype.get = function (id) {
  7004. return this._features[id];
  7005. };
  7006. /**
  7007. * Returns all features in the store.
  7008. * @return {Array<Object>}
  7009. */
  7010. Store.prototype.getAll = function () {
  7011. var _this3 = this;
  7012. return Object.keys(this._features).map(function (id) {
  7013. return _this3._features[id];
  7014. });
  7015. };
  7016. /**
  7017. * Adds features to the current selection.
  7018. * @param {string | Array<string>} featureIds
  7019. * @param {Object} [options]
  7020. * @param {Object} [options.silent] - If `true`, this invocation will not fire an event.
  7021. * @return {Store} this
  7022. */
  7023. Store.prototype.select = function (featureIds) {
  7024. var _this4 = this;
  7025. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  7026. toDenseArray(featureIds).forEach(function (id) {
  7027. if (_this4._selectedFeatureIds.has(id)) return;
  7028. _this4._selectedFeatureIds.add(id);
  7029. _this4._changedFeatureIds.add(id);
  7030. if (!options.silent) {
  7031. _this4._emitSelectionChange = true;
  7032. }
  7033. });
  7034. return this;
  7035. };
  7036. /**
  7037. * Deletes features from the current selection.
  7038. * @param {string | Array<string>} featureIds
  7039. * @param {Object} [options]
  7040. * @param {Object} [options.silent] - If `true`, this invocation will not fire an event.
  7041. * @return {Store} this
  7042. */
  7043. Store.prototype.deselect = function (featureIds) {
  7044. var _this5 = this;
  7045. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  7046. toDenseArray(featureIds).forEach(function (id) {
  7047. if (!_this5._selectedFeatureIds.has(id)) return;
  7048. _this5._selectedFeatureIds.delete(id);
  7049. _this5._changedFeatureIds.add(id);
  7050. if (!options.silent) {
  7051. _this5._emitSelectionChange = true;
  7052. }
  7053. });
  7054. refreshSelectedCoordinates.call(this, options);
  7055. return this;
  7056. };
  7057. /**
  7058. * Clears the current selection.
  7059. * @param {Object} [options]
  7060. * @param {Object} [options.silent] - If `true`, this invocation will not fire an event.
  7061. * @return {Store} this
  7062. */
  7063. Store.prototype.clearSelected = function () {
  7064. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  7065. this.deselect(this._selectedFeatureIds.values(), { silent: options.silent });
  7066. return this;
  7067. };
  7068. /**
  7069. * Sets the store's selection, clearing any prior values.
  7070. * If no feature ids are passed, the store is just cleared.
  7071. * @param {string | Array<string> | undefined} featureIds
  7072. * @param {Object} [options]
  7073. * @param {Object} [options.silent] - If `true`, this invocation will not fire an event.
  7074. * @return {Store} this
  7075. */
  7076. Store.prototype.setSelected = function (featureIds) {
  7077. var _this6 = this;
  7078. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  7079. featureIds = toDenseArray(featureIds);
  7080. // Deselect any features not in the new selection
  7081. this.deselect(this._selectedFeatureIds.values().filter(function (id) {
  7082. return featureIds.indexOf(id) === -1;
  7083. }), { silent: options.silent });
  7084. // Select any features in the new selection that were not already selected
  7085. this.select(featureIds.filter(function (id) {
  7086. return !_this6._selectedFeatureIds.has(id);
  7087. }), { silent: options.silent });
  7088. return this;
  7089. };
  7090. /**
  7091. * Sets the store's coordinates selection, clearing any prior values.
  7092. * @param {Array<Array<string>>} coordinates
  7093. * @return {Store} this
  7094. */
  7095. Store.prototype.setSelectedCoordinates = function (coordinates) {
  7096. this._selectedCoordinates = coordinates;
  7097. this._emitSelectionChange = true;
  7098. return this;
  7099. };
  7100. /**
  7101. * Clears the current coordinates selection.
  7102. * @param {Object} [options]
  7103. * @return {Store} this
  7104. */
  7105. Store.prototype.clearSelectedCoordinates = function () {
  7106. this._selectedCoordinates = [];
  7107. this._emitSelectionChange = true;
  7108. return this;
  7109. };
  7110. /**
  7111. * Returns the ids of features in the current selection.
  7112. * @return {Array<string>} Selected feature ids.
  7113. */
  7114. Store.prototype.getSelectedIds = function () {
  7115. return this._selectedFeatureIds.values();
  7116. };
  7117. /**
  7118. * Returns features in the current selection.
  7119. * @return {Array<Object>} Selected features.
  7120. */
  7121. Store.prototype.getSelected = function () {
  7122. var _this7 = this;
  7123. return this._selectedFeatureIds.values().map(function (id) {
  7124. return _this7.get(id);
  7125. });
  7126. };
  7127. /**
  7128. * Returns selected coordinates in the currently selected feature.
  7129. * @return {Array<Object>} Selected coordinates.
  7130. */
  7131. Store.prototype.getSelectedCoordinates = function () {
  7132. var _this8 = this;
  7133. var selected = this._selectedCoordinates.map(function (coordinate) {
  7134. var feature = _this8.get(coordinate.feature_id);
  7135. return {
  7136. coordinates: feature.getCoordinate(coordinate.coord_path)
  7137. };
  7138. });
  7139. return selected;
  7140. };
  7141. /**
  7142. * Indicates whether a feature is selected.
  7143. * @param {string} featureId
  7144. * @return {boolean} `true` if the feature is selected, `false` if not.
  7145. */
  7146. Store.prototype.isSelected = function (featureId) {
  7147. return this._selectedFeatureIds.has(featureId);
  7148. };
  7149. /**
  7150. * Sets a property on the given feature
  7151. * @param {string} featureId
  7152. * @param {string} property property
  7153. * @param {string} property value
  7154. */
  7155. Store.prototype.setFeatureProperty = function (featureId, property, value) {
  7156. this.get(featureId).setProperty(property, value);
  7157. this.featureChanged(featureId);
  7158. };
  7159. function refreshSelectedCoordinates(options) {
  7160. var _this9 = this;
  7161. var newSelectedCoordinates = this._selectedCoordinates.filter(function (point) {
  7162. return _this9._selectedFeatureIds.has(point.feature_id);
  7163. });
  7164. if (this._selectedCoordinates.length !== newSelectedCoordinates.length && !options.silent) {
  7165. this._emitSelectionChange = true;
  7166. }
  7167. this._selectedCoordinates = newSelectedCoordinates;
  7168. }
  7169. },{"./lib/string_set":48,"./lib/throttle":51,"./lib/to_dense_array":52,"./render":60}],63:[function(require,module,exports){
  7170. 'use strict';
  7171. var xtend = require('xtend');
  7172. var Constants = require('./constants');
  7173. var classTypes = ['mode', 'feature', 'mouse'];
  7174. module.exports = function (ctx) {
  7175. var buttonElements = {};
  7176. var activeButton = null;
  7177. var currentMapClasses = {
  7178. mode: null, // e.g. mode-direct_select
  7179. feature: null, // e.g. feature-vertex
  7180. mouse: null // e.g. mouse-move
  7181. };
  7182. var nextMapClasses = {
  7183. mode: null,
  7184. feature: null,
  7185. mouse: null
  7186. };
  7187. function queueMapClasses(options) {
  7188. nextMapClasses = xtend(nextMapClasses, options);
  7189. }
  7190. function updateMapClasses() {
  7191. if (!ctx.container) return;
  7192. var classesToRemove = [];
  7193. var classesToAdd = [];
  7194. classTypes.forEach(function (type) {
  7195. if (nextMapClasses[type] === currentMapClasses[type]) return;
  7196. classesToRemove.push(type + '-' + currentMapClasses[type]);
  7197. if (nextMapClasses[type] !== null) {
  7198. classesToAdd.push(type + '-' + nextMapClasses[type]);
  7199. }
  7200. });
  7201. if (classesToRemove.length > 0) {
  7202. ctx.container.classList.remove.apply(ctx.container.classList, classesToRemove);
  7203. }
  7204. if (classesToAdd.length > 0) {
  7205. ctx.container.classList.add.apply(ctx.container.classList, classesToAdd);
  7206. }
  7207. currentMapClasses = xtend(currentMapClasses, nextMapClasses);
  7208. }
  7209. function createControlButton(id) {
  7210. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  7211. var button = document.createElement('button');
  7212. button.className = Constants.classes.CONTROL_BUTTON + ' ' + options.className;
  7213. button.setAttribute('title', options.title);
  7214. options.container.appendChild(button);
  7215. button.addEventListener('click', function (e) {
  7216. e.preventDefault();
  7217. e.stopPropagation();
  7218. var clickedButton = e.target;
  7219. if (clickedButton === activeButton) {
  7220. deactivateButtons();
  7221. return;
  7222. }
  7223. setActiveButton(id);
  7224. options.onActivate();
  7225. }, true);
  7226. return button;
  7227. }
  7228. function deactivateButtons() {
  7229. if (!activeButton) return;
  7230. activeButton.classList.remove(Constants.classes.ACTIVE_BUTTON);
  7231. activeButton = null;
  7232. }
  7233. function setActiveButton(id) {
  7234. deactivateButtons();
  7235. var button = buttonElements[id];
  7236. if (!button) return;
  7237. if (button && id !== 'trash') {
  7238. button.classList.add(Constants.classes.ACTIVE_BUTTON);
  7239. activeButton = button;
  7240. }
  7241. }
  7242. function addButtons() {
  7243. var controls = ctx.options.controls;
  7244. var controlGroup = document.createElement('div');
  7245. controlGroup.className = Constants.classes.CONTROL_GROUP + ' ' + Constants.classes.CONTROL_BASE;
  7246. if (!controls) return controlGroup;
  7247. if (controls[Constants.types.LINE]) {
  7248. buttonElements[Constants.types.LINE] = createControlButton(Constants.types.LINE, {
  7249. container: controlGroup,
  7250. className: Constants.classes.CONTROL_BUTTON_LINE,
  7251. title: 'LineString tool ' + (ctx.options.keybindings ? '(l)' : ''),
  7252. onActivate: function onActivate() {
  7253. return ctx.events.changeMode(Constants.modes.DRAW_LINE_STRING);
  7254. }
  7255. });
  7256. }
  7257. if (controls[Constants.types.POLYGON]) {
  7258. buttonElements[Constants.types.POLYGON] = createControlButton(Constants.types.POLYGON, {
  7259. container: controlGroup,
  7260. className: Constants.classes.CONTROL_BUTTON_POLYGON,
  7261. title: 'Polygon tool ' + (ctx.options.keybindings ? '(p)' : ''),
  7262. onActivate: function onActivate() {
  7263. return ctx.events.changeMode(Constants.modes.DRAW_POLYGON);
  7264. }
  7265. });
  7266. }
  7267. if (controls[Constants.types.POINT]) {
  7268. buttonElements[Constants.types.POINT] = createControlButton(Constants.types.POINT, {
  7269. container: controlGroup,
  7270. className: Constants.classes.CONTROL_BUTTON_POINT,
  7271. title: 'Marker tool ' + (ctx.options.keybindings ? '(m)' : ''),
  7272. onActivate: function onActivate() {
  7273. return ctx.events.changeMode(Constants.modes.DRAW_POINT);
  7274. }
  7275. });
  7276. }
  7277. if (controls.trash) {
  7278. buttonElements.trash = createControlButton('trash', {
  7279. container: controlGroup,
  7280. className: Constants.classes.CONTROL_BUTTON_TRASH,
  7281. title: 'Delete',
  7282. onActivate: function onActivate() {
  7283. ctx.events.trash();
  7284. }
  7285. });
  7286. }
  7287. if (controls.combine_features) {
  7288. buttonElements.combine_features = createControlButton('combineFeatures', {
  7289. container: controlGroup,
  7290. className: Constants.classes.CONTROL_BUTTON_COMBINE_FEATURES,
  7291. title: 'Combine',
  7292. onActivate: function onActivate() {
  7293. ctx.events.combineFeatures();
  7294. }
  7295. });
  7296. }
  7297. if (controls.uncombine_features) {
  7298. buttonElements.uncombine_features = createControlButton('uncombineFeatures', {
  7299. container: controlGroup,
  7300. className: Constants.classes.CONTROL_BUTTON_UNCOMBINE_FEATURES,
  7301. title: 'Uncombine',
  7302. onActivate: function onActivate() {
  7303. ctx.events.uncombineFeatures();
  7304. }
  7305. });
  7306. }
  7307. return controlGroup;
  7308. }
  7309. function removeButtons() {
  7310. Object.keys(buttonElements).forEach(function (buttonId) {
  7311. var button = buttonElements[buttonId];
  7312. if (button.parentNode) {
  7313. button.parentNode.removeChild(button);
  7314. }
  7315. delete buttonElements[buttonId];
  7316. });
  7317. }
  7318. return {
  7319. setActiveButton: setActiveButton,
  7320. queueMapClasses: queueMapClasses,
  7321. updateMapClasses: updateMapClasses,
  7322. addButtons: addButtons,
  7323. removeButtons: removeButtons
  7324. };
  7325. };
  7326. },{"./constants":24,"xtend":22}],158:[function(require,module,exports){
  7327. 'use strict';
  7328. var ModeInterface = module.exports = require('./mode_interface_accessors');
  7329. /**
  7330. * Triggered while a mode is being transitioned into.
  7331. * @param opts {Object} - this is the object passed via `draw.changeMode('mode', opts)`;
  7332. * @name MODE.onSetup
  7333. * @returns {Object} - this object will be passed to all other life cycle functions
  7334. */
  7335. ModeInterface.prototype.onSetup = function () {};
  7336. /**
  7337. * Triggered when a drag event is detected on the map
  7338. * @name MODE.onDrag
  7339. * @param state {Object} - a mutible state object created by onSetup
  7340. * @param e {Object} - the captured event that is triggering this life cycle event
  7341. */
  7342. ModeInterface.prototype.onDrag = function () {};
  7343. /**
  7344. * Triggered when the mouse is clicked
  7345. * @name MODE.onClick
  7346. * @param state {Object} - a mutible state object created by onSetup
  7347. * @param e {Object} - the captured event that is triggering this life cycle event
  7348. */
  7349. ModeInterface.prototype.onClick = function () {};
  7350. /**
  7351. * Triggered with the mouse is moved
  7352. * @name MODE.onMouseMove
  7353. * @param state {Object} - a mutible state object created by onSetup
  7354. * @param e {Object} - the captured event that is triggering this life cycle event
  7355. */
  7356. ModeInterface.prototype.onMouseMove = function () {};
  7357. /**
  7358. * Triggered when the mouse button is pressed down
  7359. * @name MODE.onMouseDown
  7360. * @param state {Object} - a mutible state object created by onSetup
  7361. * @param e {Object} - the captured event that is triggering this life cycle event
  7362. */
  7363. ModeInterface.prototype.onMouseDown = function () {};
  7364. /**
  7365. * Triggered when the mouse button is released
  7366. * @name MODE.onMouseUp
  7367. * @param state {Object} - a mutible state object created by onSetup
  7368. * @param e {Object} - the captured event that is triggering this life cycle event
  7369. */
  7370. ModeInterface.prototype.onMouseUp = function () {};
  7371. /**
  7372. * Triggered when the mouse leaves the map's container
  7373. * @name MODE.onMouseOut
  7374. * @param state {Object} - a mutible state object created by onSetup
  7375. * @param e {Object} - the captured event that is triggering this life cycle event
  7376. */
  7377. ModeInterface.prototype.onMouseOut = function () {};
  7378. /**
  7379. * Triggered when a key up event is detected
  7380. * @name MODE.onKeyUp
  7381. * @param state {Object} - a mutible state object created by onSetup
  7382. * @param e {Object} - the captured event that is triggering this life cycle event
  7383. */
  7384. ModeInterface.prototype.onKeyUp = function () {};
  7385. /**
  7386. * Triggered when a key down event is detected
  7387. * @name MODE.onKeyDown
  7388. * @param state {Object} - a mutible state object created by onSetup
  7389. * @param e {Object} - the captured event that is triggering this life cycle event
  7390. */
  7391. ModeInterface.prototype.onKeyDown = function () {};
  7392. /**
  7393. * Triggered when a touch event is started
  7394. * @name MODE.onTouchStart
  7395. * @param state {Object} - a mutible state object created by onSetup
  7396. * @param e {Object} - the captured event that is triggering this life cycle event
  7397. */
  7398. ModeInterface.prototype.onTouchStart = function () {};
  7399. /**
  7400. * Triggered when one drags thier finger on a mobile device
  7401. * @name MODE.onTouchMove
  7402. * @param state {Object} - a mutible state object created by onSetup
  7403. * @param e {Object} - the captured event that is triggering this life cycle event
  7404. */
  7405. ModeInterface.prototype.onTouchMove = function () {};
  7406. /**
  7407. * Triggered when one removes their finger from the map
  7408. * @name MODE.onTouchEnd
  7409. * @param state {Object} - a mutible state object created by onSetup
  7410. * @param e {Object} - the captured event that is triggering this life cycle event
  7411. */
  7412. ModeInterface.prototype.onTouchEnd = function () {};
  7413. /**
  7414. * Triggered when one quicly taps the map
  7415. * @name MODE.onTap
  7416. * @param state {Object} - a mutible state object created by onSetup
  7417. * @param e {Object} - the captured event that is triggering this life cycle event
  7418. */
  7419. ModeInterface.prototype.onTap = function () {};
  7420. /**
  7421. * Triggered when the mode is being exited, to be used for cleaning up artifacts such as invalid features
  7422. * @name MODE.onStop
  7423. * @param state {Object} - a mutible state object created by onSetup
  7424. */
  7425. ModeInterface.prototype.onStop = function () {};
  7426. /**
  7427. * Triggered when [draw.trash()](https://github.com/mapbox/mapbox-gl-draw/blob/master/API.md#trash-draw) is called.
  7428. * @name MODE.onTrash
  7429. * @param state {Object} - a mutible state object created by onSetup
  7430. */
  7431. ModeInterface.prototype.onTrash = function () {};
  7432. /**
  7433. * Triggered when [draw.combineFeatures()](https://github.com/mapbox/mapbox-gl-draw/blob/master/API.md#combinefeatures-draw) is called.
  7434. * @name MODE.onCombineFeature
  7435. * @param state {Object} - a mutible state object created by onSetup
  7436. */
  7437. ModeInterface.prototype.onCombineFeature = function () {};
  7438. /**
  7439. * Triggered when [draw.uncombineFeatures()](https://github.com/mapbox/mapbox-gl-draw/blob/master/API.md#uncombinefeatures-draw) is called.
  7440. * @name MODE.onUncombineFeature
  7441. * @param state {Object} - a mutible state object created by onSetup
  7442. */
  7443. ModeInterface.prototype.onUncombineFeature = function () {};
  7444. /**
  7445. * Triggered per feature on render to convert raw features into set of features for display on the map
  7446. * See [styling draw](https://github.com/mapbox/mapbox-gl-draw/blob/master/API.md#styling-draw) for information about what geojson properties Draw uses as part of rendering.
  7447. * @name MODE.toDisplayFeatures
  7448. * @param state {Object} - a mutible state object created by onSetup
  7449. * @param geojson {Object} - a geojson being evaulated. To render, pass to `display`.
  7450. * @param display {Function} - all geojson objects passed to this be rendered onto the map
  7451. */
  7452. ModeInterface.prototype.toDisplayFeatures = function () {
  7453. throw new Error('You must overwrite toDisplayFeatures');
  7454. };
  7455. },{"./mode_interface_accessors":159}],159:[function(require,module,exports){
  7456. 'use strict';
  7457. var Constants = require('../constants');
  7458. var featuresAt = require('../lib/features_at');
  7459. var Point = require('../feature_types/point');
  7460. var LineString = require('../feature_types/line_string');
  7461. var Polygon = require('../feature_types/polygon');
  7462. var MultiFeature = require('../feature_types/multi_feature');
  7463. var ModeInterface = module.exports = function (ctx) {
  7464. this.map = ctx.map;
  7465. this.drawConfig = JSON.parse(JSON.stringify(ctx.options || {}));
  7466. this._ctx = ctx;
  7467. };
  7468. /**
  7469. * Sets Draw's interal selected state
  7470. * @name this.setSelected
  7471. * @param {DrawFeature[]} - whats selected as a [DrawFeature](https://github.com/mapbox/mapbox-gl-draw/blob/master/src/feature_types/feature.js)
  7472. */
  7473. ModeInterface.prototype.setSelected = function (features) {
  7474. return this._ctx.store.setSelected(features);
  7475. };
  7476. /**
  7477. * Sets Draw's internal selected coordinate state
  7478. * @name this.setSelectedCoordinates
  7479. * @param {Object[]} coords - a array of {coord_path: 'string', featureId: 'string'}
  7480. */
  7481. ModeInterface.prototype.setSelectedCoordinates = function (coords) {
  7482. var _this = this;
  7483. this._ctx.store.setSelectedCoordinates(coords);
  7484. coords.reduce(function (m, c) {
  7485. if (m[c.feature_id] === undefined) {
  7486. m[c.feature_id] = true;
  7487. _this._ctx.store.get(c.feature_id).changed();
  7488. }
  7489. return m;
  7490. }, {});
  7491. };
  7492. /**
  7493. * Get all selected features as a [DrawFeature](https://github.com/mapbox/mapbox-gl-draw/blob/master/src/feature_types/feature.js)
  7494. * @name this.getSelected
  7495. * @returns {DrawFeature[]}
  7496. */
  7497. ModeInterface.prototype.getSelected = function () {
  7498. return this._ctx.store.getSelected();
  7499. };
  7500. /**
  7501. * Get the ids of all currently selected features
  7502. * @name this.getSelectedIds
  7503. * @returns {String[]}
  7504. */
  7505. ModeInterface.prototype.getSelectedIds = function () {
  7506. return this._ctx.store.getSelectedIds();
  7507. };
  7508. /**
  7509. * Check if a feature is selected
  7510. * @name this.isSelected
  7511. * @param {String} id - a feature id
  7512. * @returns {Boolean}
  7513. */
  7514. ModeInterface.prototype.isSelected = function (id) {
  7515. return this._ctx.store.isSelected(id);
  7516. };
  7517. /**
  7518. * Get a [DrawFeature](https://github.com/mapbox/mapbox-gl-draw/blob/master/src/feature_types/feature.js) by its id
  7519. * @name this.getFeature
  7520. * @param {String} id - a feature id
  7521. * @returns {DrawFeature}
  7522. */
  7523. ModeInterface.prototype.getFeature = function (id) {
  7524. return this._ctx.store.get(id);
  7525. };
  7526. /**
  7527. * Add a feature to draw's internal selected state
  7528. * @name this.select
  7529. * @param {String} id
  7530. */
  7531. ModeInterface.prototype.select = function (id) {
  7532. return this._ctx.store.select(id);
  7533. };
  7534. /**
  7535. * Remove a feature from draw's internal selected state
  7536. * @name this.delete
  7537. * @param {String} id
  7538. */
  7539. ModeInterface.prototype.deselect = function (id) {
  7540. return this._ctx.store.deselect(id);
  7541. };
  7542. /**
  7543. * Delete a feature from draw
  7544. * @name this.deleteFeature
  7545. * @param {String} id - a feature id
  7546. */
  7547. ModeInterface.prototype.deleteFeature = function (id) {
  7548. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  7549. return this._ctx.store.delete(id, opts);
  7550. };
  7551. /**
  7552. * Add a [DrawFeature](https://github.com/mapbox/mapbox-gl-draw/blob/master/src/feature_types/feature.js) to draw.
  7553. * See `this.newFeature` for converting geojson into a DrawFeature
  7554. * @name this.addFeature
  7555. * @param {DrawFeature} feature - the feature to add
  7556. */
  7557. ModeInterface.prototype.addFeature = function (feature) {
  7558. return this._ctx.store.add(feature);
  7559. };
  7560. /**
  7561. * Clear all selected features
  7562. */
  7563. ModeInterface.prototype.clearSelectedFeatures = function () {
  7564. return this._ctx.store.clearSelected();
  7565. };
  7566. /**
  7567. * Clear all selected coordinates
  7568. */
  7569. ModeInterface.prototype.clearSelectedCoordinates = function () {
  7570. return this._ctx.store.clearSelectedCoordinates();
  7571. };
  7572. /**
  7573. * Indicate if the different action are currently possible with your mode
  7574. * See [draw.actionalbe](https://github.com/mapbox/mapbox-gl-draw/blob/master/API.md#drawactionable) for a list of possible actions. All undefined actions are set to **false** by default
  7575. * @name this.setActionableState
  7576. * @param {Object} actions
  7577. */
  7578. ModeInterface.prototype.setActionableState = function () {
  7579. var actions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  7580. var newSet = {
  7581. trash: actions.trash || false,
  7582. combineFeatures: actions.combineFeatures || false,
  7583. uncombineFeatures: actions.uncombineFeatures || false
  7584. };
  7585. return this._ctx.events.actionable(newSet);
  7586. };
  7587. /**
  7588. * Trigger a mode change
  7589. * @name this.changeMode
  7590. * @param {String} mode - the mode to transition into
  7591. * @param {Object} opts - the options object to pass to the new mode
  7592. * @param {Object} eventOpts - used to control what kind of events are emitted.
  7593. */
  7594. ModeInterface.prototype.changeMode = function (mode) {
  7595. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  7596. var eventOpts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  7597. return this._ctx.events.changeMode(mode, opts, eventOpts);
  7598. };
  7599. /**
  7600. * Update the state of draw map classes
  7601. * @name this.updateUIClasses
  7602. * @param {Object} opts
  7603. */
  7604. ModeInterface.prototype.updateUIClasses = function (opts) {
  7605. return this._ctx.ui.queueMapClasses(opts);
  7606. };
  7607. /**
  7608. * If a name is provided it makes that button active, else if makes all buttons inactive
  7609. * @name this.activateUIButton
  7610. * @param {String?} name - name of the button to make active, leave as undefined to set buttons to be inactive
  7611. */
  7612. ModeInterface.prototype.activateUIButton = function (name) {
  7613. return this._ctx.ui.setActiveButton(name);
  7614. };
  7615. /**
  7616. * Get the features at the location of an event object or in a bbox
  7617. * @name this.featuresAt
  7618. * @param {Event||NULL} event - a mapbox-gl event object
  7619. * @param {BBOX||NULL} bbox - the area to get features from
  7620. * @param {String} bufferType - is this `click` or `tap` event, defaults to click
  7621. */
  7622. ModeInterface.prototype.featuresAt = function (event, bbox) {
  7623. var bufferType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'click';
  7624. if (bufferType !== 'click' && bufferType !== 'touch') throw new Error('invalid buffer type');
  7625. return featuresAt[bufferType](event, bbox, this._ctx);
  7626. };
  7627. /**
  7628. * Create a new [DrawFeature](https://github.com/mapbox/mapbox-gl-draw/blob/master/src/feature_types/feature.js) from geojson
  7629. * @name this.newFeature
  7630. * @param {GeoJSONFeature} geojson
  7631. * @returns {DrawFeature}
  7632. */
  7633. ModeInterface.prototype.newFeature = function (geojson) {
  7634. var type = geojson.geometry.type;
  7635. if (type === Constants.geojsonTypes.POINT) return new Point(this._ctx, geojson);
  7636. if (type === Constants.geojsonTypes.LINE_STRING) return new LineString(this._ctx, geojson);
  7637. if (type === Constants.geojsonTypes.POLYGON) return new Polygon(this._ctx, geojson);
  7638. return new MultiFeature(this._ctx, geojson);
  7639. };
  7640. /**
  7641. * Check is an object is an instance of a [DrawFeature](https://github.com/mapbox/mapbox-gl-draw/blob/master/src/feature_types/feature.js)
  7642. * @name this.isInstanceOf
  7643. * @param {String} type - `Point`, `LineString`, `Polygon`, `MultiFeature`
  7644. * @param {Object} feature - the object that needs to be checked
  7645. * @returns {Boolean}
  7646. */
  7647. ModeInterface.prototype.isInstanceOf = function (type, feature) {
  7648. if (type === Constants.geojsonTypes.POINT) return feature instanceof Point;
  7649. if (type === Constants.geojsonTypes.LINE_STRING) return feature instanceof LineString;
  7650. if (type === Constants.geojsonTypes.POLYGON) return feature instanceof Polygon;
  7651. if (type === 'MultiFeature') return feature instanceof MultiFeature;
  7652. throw new Error('Unknown feature class: ' + type);
  7653. };
  7654. /**
  7655. * Force draw to rerender the feature of the provided id
  7656. * @name this.doRender
  7657. * @param {String} id - a feature id
  7658. */
  7659. ModeInterface.prototype.doRender = function (id) {
  7660. return this._ctx.store.featureChanged(id);
  7661. };
  7662. },{"../constants":24,"../feature_types/line_string":27,"../feature_types/multi_feature":28,"../feature_types/point":29,"../feature_types/polygon":30,"../lib/features_at":38}],160:[function(require,module,exports){
  7663. 'use strict';
  7664. var ModeInterface = require('./mode_interface');
  7665. module.exports = function (modeObject) {
  7666. var modeObjectKeys = Object.keys(modeObject);
  7667. return function (ctx) {
  7668. var startOpts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  7669. var state = {};
  7670. var mode = modeObjectKeys.reduce(function (m, k) {
  7671. m[k] = modeObject[k];
  7672. return m;
  7673. }, new ModeInterface(ctx));
  7674. function wrapper(eh) {
  7675. return function (e) {
  7676. mode[eh](state, e);
  7677. };
  7678. }
  7679. return {
  7680. start: function start() {
  7681. state = mode.onSetup(startOpts); // this should set ui buttons
  7682. this.on('drag', function () {
  7683. return true;
  7684. }, wrapper('onDrag'));
  7685. this.on('click', function () {
  7686. return true;
  7687. }, wrapper('onClick'));
  7688. this.on('mousemove', function () {
  7689. return true;
  7690. }, wrapper('onMouseMove'));
  7691. this.on('mousedown', function () {
  7692. return true;
  7693. }, wrapper('onMouseDown'));
  7694. this.on('mouseup', function () {
  7695. return true;
  7696. }, wrapper('onMouseUp'));
  7697. this.on('mouseout', function () {
  7698. return true;
  7699. }, wrapper('onMouseOut'));
  7700. this.on('keyup', function () {
  7701. return true;
  7702. }, wrapper('onKeyUp'));
  7703. this.on('keydown', function () {
  7704. return true;
  7705. }, wrapper('onKeyDown'));
  7706. this.on('touchstart', function () {
  7707. return true;
  7708. }, wrapper('onTouchStart'));
  7709. this.on('touchmove', function () {
  7710. return true;
  7711. }, wrapper('onTouchMove'));
  7712. this.on('touchend', function () {
  7713. return true;
  7714. }, wrapper('onTouchEnd'));
  7715. this.on('tap', function () {
  7716. return true;
  7717. }, wrapper('onTap'));
  7718. },
  7719. stop: function stop() {
  7720. mode.onStop(state);
  7721. },
  7722. trash: function trash() {
  7723. mode.onTrash(state);
  7724. },
  7725. combineFeatures: function combineFeatures() {
  7726. mode.onCombineFeatures(state);
  7727. },
  7728. uncombineFeatures: function uncombineFeatures() {
  7729. mode.onUncombineFeatures(state);
  7730. },
  7731. render: function render(geojson, push) {
  7732. mode.toDisplayFeatures(state, geojson, push);
  7733. }
  7734. };
  7735. };
  7736. };
  7737. },{"./mode_interface":158}]},{},[1])(1)
  7738. });